refactor(get_cid): accept `MessageTxAPI`
MODIFY
signer-npm/src/lib.rs
signer-npm/src/lib.rs
@@ -991,7 +991,7 @@ pub fn get_cid(message: JsValue) -> Result<String, JsValue> {
.into_serde()
.map_err(|e| JsValue::from(format!("Error parsing parameters: {}", e)))?;
- let result = filecoin_signer::get_cid(message_api.get_message())
+ let result = filecoin_signer::get_cid(message_api)
.map_err(|e| JsValue::from(format!("Error getting the cid: {}", e)))?;
Ok(result)

MODIFY
signer/src/lib.rs
signer/src/lib.rs
@@ -1231,20 +1231,29 @@ pub fn verify_voucher_signature(
}
}
-/// Return the CID of an unsigned message
+/// Return the CID of a message
///
/// # Arguments
///
-/// * `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)?;
+/// * `message_api` - The message;
+pub fn get_cid(message_api: MessageTxAPI) -> Result<String, SignerError> {
+ use forest_encoding::Cbor;
- 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");
+ match message_api {
+ MessageTxAPI::UnsignedMessageAPI(unsigned) => {
+ let unsigned_message = UnsignedMessage::try_from(&unsigned)?;
+ let cid = unsigned_message.cid()?;
Ok(cid.to_string())
}
+ MessageTxAPI::SignedMessageAPI(signed) => {
+ let signed_message = SignedMessage::try_from(&signed)?;
+ let cid = signed_message.cid()?;
+
+ Ok(cid.to_string())
+ }
+ }
+}
/// Return the bytes to sign of an unsigned message
///

refactor(get_cid): accept `MessageTxAPI`