From 2cf5f650b8fdbd1992f3d65ad6e102087e74f896 Mon Sep 17 00:00:00 2001 From: Nicholas Rodrigues Lordello Date: Tue, 3 May 2022 07:59:24 +0200 Subject: Use Rust Secp256k1 implementation from RustCrypto project (#92) This PR ports `hdwallet` to use the `k256` crate - a native Rust implementation of secp256k1 elliptic curve and ECDSA signing. The motivation for this change is that we can just use the `wasm32-wasi` Rust target without requiring a WASI C toolchain! Notice that the CI no longer requires installing the WASI SDK in order to build the WASI target. --- src/transaction/legacy.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/transaction/legacy.rs') diff --git a/src/transaction/legacy.rs b/src/transaction/legacy.rs index 6680c74..9e0f9bc 100644 --- a/src/transaction/legacy.rs +++ b/src/transaction/legacy.rs @@ -5,7 +5,7 @@ use crate::{ serialization, transaction::rlp, }; -use ethnum::{AsU256 as _, U256}; +use ethnum::U256; use serde::Deserialize; /// A Legacy Ethereum transaction. @@ -48,15 +48,7 @@ impl LegacyTransaction { ]; let tail = signature - .map(|signature| { - ( - self.chain_id.map_or(signature.v().as_u256(), |chain_id| { - signature.v_replay_protected(chain_id) - }), - U256::from_be_bytes(signature.r), - U256::from_be_bytes(signature.s), - ) - }) + .map(|signature| (signature.v(self.chain_id), signature.r(), signature.s())) .or_else(|| Some((self.chain_id?, U256::ZERO, U256::ZERO))) .map(|(v, r, s)| [rlp::uint(v), rlp::uint(r), rlp::uint(s)]); @@ -67,6 +59,7 @@ impl LegacyTransaction { #[cfg(test)] mod tests { use super::*; + use ethnum::AsU256 as _; use hex_literal::hex; use serde_json::json; -- cgit v1.2.3