refactor(get_cid): use UnsignedMessageAPI
refactor(test): update `test_get_cid`
feat(get_cid): use MessageTxAPI
MODIFY
signer-npm/src/lib.rs
signer-npm/src/lib.rs
@@ -4,7 +4,7 @@ use std::convert::TryFrom;
use wasm_bindgen::prelude::*;
-use filecoin_signer::api::{MessageParams, SignedMessageAPI, UnsignedMessageAPI};
+use filecoin_signer::api::{MessageParams, MessageTxAPI, SignedMessageAPI, UnsignedMessageAPI};
use filecoin_signer::signature::Signature;
use filecoin_signer::{CborBuffer, PrivateKey};
@@ -984,14 +984,14 @@ pub fn verify_voucher_signature(
}
#[wasm_bindgen(js_name = getCid)]
-pub fn get_cid(signed_message: JsValue) -> Result<String, JsValue> {
+pub fn get_cid(message: JsValue) -> Result<String, JsValue> {
set_panic_hook();
- let signed_message_api: SignedMessageAPI = signed_message
+ let message_api: MessageTxAPI = message
.into_serde()
.map_err(|e| JsValue::from(format!("Error parsing parameters: {}", e)))?;
- let result = filecoin_signer::get_cid(signed_message_api)
+ let result = filecoin_signer::get_cid(message_api.get_message())
.map_err(|e| JsValue::from(format!("Error getting the cid: {}", e)))?;
Ok(result)

MODIFY
signer/src/lib.rs
signer/src/lib.rs
@@ -1231,16 +1231,17 @@ pub fn verify_voucher_signature(
}
}
-/// Return the CID of a signed message
+/// Return the CID of an unsigned message
///
/// # Arguments
///
-/// * `signed_message_api` - The signed message;
-pub fn get_cid(signed_message_api: SignedMessageAPI) -> Result<String, SignerError> {
- let signed_message = SignedMessage::try_from(&signed_message_api)?;
- let cbor_signed_message = to_vec(&signed_message)?;
+/// * `unsigned_message_api` - The unsigned message;
+pub fn get_cid(unsigned_message_api: UnsignedMessageAPI) -> Result<String, SignerError> {
+ let unsigned_message = UnsignedMessage::try_from(&unsigned_message_api)?;
- let cid = Cid::new_from_cbor(&cbor_signed_message, Blake2b256);
+ let raw_cid = unsigned_message.to_signing_bytes();
+ let cid = Cid::from_raw_cid(raw_cid)
+ .expect("FIX ME: to_signing_bytes is assumed to return ONLY the CID");
Ok(cid.to_string())
}

MODIFY
signer/tests/lib_test.rs
signer/tests/lib_test.rs
@@ -938,7 +938,7 @@ fn test_get_cid() {
serde_json::from_value(test_value["signed_message"].to_owned())
.expect("couldn't serialize signed message");
- let cid = get_cid(signed_message_api).unwrap();
+ let cid = get_cid(signed_message_api.message).unwrap();
assert_eq!(cid, expected_cid);
}

MODIFY
test_vectors/get_cid.json
test_vectors/get_cid.json
"data": "0wRrFJZFIVh8m0JD+f5C55YrxD6YAWtCXWYihrPTKdMfgMhYAy86MVhs43hSLXnV+47UReRIe8qFdHRJqFlreAE="
}
},
- "cid": "bafy2bzacebaiinljwwctblf7czp4zxwhz4747z6tpricgn5cumd4xhebftcvu"
+ "cid": "bafy2bzacedluvv7t2no5ujbuxtxi5mthioymz2wzorarxird736mz7wn3mucy"
}

refactor(get_cid): use UnsignedMessageAPI

refactor(test): update `test_get_cid`
feat(get_cid): use MessageTxAPI