Skip to content

Commit

Permalink
Testcase support dogecoin and tron prefix
Browse files Browse the repository at this point in the history
  • Loading branch information
joii2020 committed Jan 10, 2024
1 parent 72b4b1d commit f57947e
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions tests/omni_lock_rust/tests/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1262,12 +1262,15 @@ impl DogecoinConfig {
}

pub fn convert_message(&self, message: &[u8; 32]) -> CkbH256 {
let message_magic = b"\x19Dogecoin Signed Message:\n\x40";
let message_magic = b"\x19Dogecoin Signed Message:\n";
let msg_hex = hex::encode(message);
assert_eq!(msg_hex.len(), 64);

let mut temp2: BytesMut = BytesMut::with_capacity(message_magic.len() + msg_hex.len());
let mut temp2: BytesMut =
BytesMut::with_capacity(message_magic.len() + 1 + COMMON_PREFIX.len() + msg_hex.len());
temp2.put(Bytes::from(message_magic.to_vec()));
temp2.put_u8(0x40 + COMMON_PREFIX.len() as u8);
temp2.put(COMMON_PREFIX.as_bytes());
temp2.put(Bytes::from(hex::encode(message)));

let msg = calculate_sha256(&temp2.to_vec());
Expand Down Expand Up @@ -1340,10 +1343,16 @@ impl TronConfig {
}

pub fn convert_message(&self, message: &[u8; 32]) -> CkbH256 {
let eth_prefix: &[u8; 24] = b"\x19TRON Signed Message:\n32";
let eth_prefix = b"\x19TRON Signed Message:\n32";

let mut temp =
BytesMut::with_capacity(eth_prefix.len() + 1 + COMMON_PREFIX.len() + message.len());
temp.put(Bytes::from(eth_prefix.to_vec()));
temp.put(COMMON_PREFIX.as_bytes());
temp.put(Bytes::from(message.to_vec()));

let mut hasher = Keccak256::new();
hasher.update(eth_prefix);
hasher.update(message);
hasher.update(temp.to_vec());
let r = hasher.finalize();
let rr = CkbH256::from_slice(r.as_slice()).expect("convert_keccak256_hash");
rr
Expand Down

0 comments on commit f57947e

Please sign in to comment.