Skip to content

Commit

Permalink
Merge branch 'dev' into feat_tezos
Browse files Browse the repository at this point in the history
  • Loading branch information
XuNeal committed Dec 4, 2020
2 parents 9003603 + b6f8306 commit c26e745
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
11 changes: 6 additions & 5 deletions tcx-filecoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ num_bigint_chainsafe = { package = "forest_bigint", version = "0.1.0"}
hex = "0.4.0"
lazy_static = "1.4.0"

forest_vm = "0.2.1"
forest_message = "0.5.0"
forest_address = "0.2.3"
forest_encoding = "0.1.2"
forest_cid = "0.1.1"
forest_vm = "0.3.0"
forest_message = "0.6.0"
forest_address = "0.3.0"
forest_encoding = "0.2.0"
forest_cid = "0.2.0"
forest_crypto = "0.4.0"
2 changes: 2 additions & 0 deletions tcx-filecoin/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ mod utils;
pub use crate::address::FilecoinAddress;
pub use crate::key_info::KeyInfo;
pub use crate::transaction::{SignedMessage, UnsignedMessage};
#[macro_use]
extern crate failure;

#[derive(Fail, Debug, PartialEq)]
pub enum Error {
Expand Down
17 changes: 16 additions & 1 deletion tcx-filecoin/src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::transaction::{Signature, SignedMessage, UnsignedMessage};
use crate::utils::{digest, HashSize};
use crate::Error;
use forest_address::Address;
use forest_cid::Cid;
use forest_encoding::Cbor;
use forest_message::UnsignedMessage as ForestUnsignedMessage;
use forest_vm::Serialized;
Expand Down Expand Up @@ -55,7 +56,6 @@ impl TransactionSigner<UnsignedMessage, SignedMessage> for Keystore {
tx: &UnsignedMessage,
) -> Result<SignedMessage> {
let unsigned_message = forest_message::UnsignedMessage::try_from(tx)?;
let cid = unsigned_message.cid()?;

let account = self.account(symbol, address);
let signature_type;
Expand All @@ -65,6 +65,7 @@ impl TransactionSigner<UnsignedMessage, SignedMessage> for Keystore {
}

let signature;
let mut cid: Cid = unsigned_message.cid()?;
match account.unwrap().curve {
CurveType::SECP256k1 => {
signature_type = 1;
Expand All @@ -74,10 +75,20 @@ impl TransactionSigner<UnsignedMessage, SignedMessage> for Keystore {
address,
None,
)?;

let forest_sig = forest_crypto::Signature::new_secp256k1(signature.clone());
let forest_signed_msg = forest_message::SignedMessage {
message: unsigned_message,
signature: forest_sig,
};
cid = forest_signed_msg
.cid()
.map_err(|_e| format_err!("{}", "forest_message cid error"))?;
}
CurveType::BLS => {
signature_type = 2;
signature = self.sign_hash(&cid.to_bytes(), symbol, address, None)?;
cid = unsigned_message.cid()?;
}
_ => return Err(Error::InvalidCurveType.into()),
}
Expand Down Expand Up @@ -139,6 +150,10 @@ mod tests {
.unwrap();
let signature = signed_message.signature.unwrap();

assert_eq!(
"bafy2bzacec6nqhpi35nwfmdc2two6gs6khs3cgxe7ao2ks6xdwz53qvp2boyu",
signed_message.cid
);
assert_eq!(signature.r#type, 1);
assert_eq!(signature.data, "MCTI+WjYRozaU/7gYWAwSeOixkSmIHDWHwsU1NVPTrtH4IkXPUrgRcZh4DduJqvHLzoek31LYZxhWkGAzd0j9wA=");
}
Expand Down

0 comments on commit c26e745

Please sign in to comment.