diff --git a/Cargo.lock b/Cargo.lock index 7ae6d5f2..0f79c3d0 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -25,6 +25,12 @@ version = "1.0.31" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85bb70cc08ec97ca5450e6eba421deeea5f172c0fc61f78b5357b2a8e8be195f" +[[package]] +name = "arrayref" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4c527152e37cf757a3f78aae5a06fbeefdb07ccc535c980a3208ee3060dd544" + [[package]] name = "arrayvec" version = "0.5.1" @@ -42,12 +48,6 @@ dependencies = [ "syn", ] -[[package]] -name = "autocfg" -version = "0.1.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1d49d90015b3c36167a20fe2810c5cd875ad504b39cff3d4eae7977e6b7c1cb2" - [[package]] name = "autocfg" version = "1.0.0" @@ -92,6 +92,27 @@ dependencies = [ "radium", ] +[[package]] +name = "block-buffer" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c0940dc441f31689269e10ac70eb1002a3a1d3ad1390e030043662eb7fe4688b" +dependencies = [ + "block-padding", + "byte-tools", + "byteorder", + "generic-array", +] + +[[package]] +name = "block-padding" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fa79dedbb091f449f1f39e53edf88d5dbe95f895dae6135a8d7b881fb5af73f5" +dependencies = [ + "byte-tools", +] + [[package]] name = "bumpalo" version = "3.3.0" @@ -104,6 +125,12 @@ version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b0a5e3906bcbf133e33c1d4d95afc664ad37fbdb9f6568d8043e7ea8c27d93d3" +[[package]] +name = "byte-tools" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7" + [[package]] name = "byteorder" version = "1.3.4" @@ -128,21 +155,22 @@ version = "0.1.10" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822" -[[package]] -name = "cloudabi" -version = "0.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ddfc5b9aa5d4507acaf872de71051dfd0e309860e88966e1051e462a077aac4f" -dependencies = [ - "bitflags", -] - [[package]] name = "crunchy" version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7" +[[package]] +name = "crypto-mac" +version = "0.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4434400df11d95d556bac068ddfedd482915eb18fe8bea89bc80b6e4b1c179e5" +dependencies = [ + "generic-array", + "subtle 1.0.0", +] + [[package]] name = "curl" version = "0.4.29" @@ -173,6 +201,15 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "digest" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5" +dependencies = [ + "generic-array", +] + [[package]] name = "dtoa" version = "0.4.5" @@ -244,7 +281,7 @@ dependencies = [ "ethers-core", "ethers-providers", "ethers-signers", - "rand 0.5.6", + "rand", "serde", "serde_json", "tokio", @@ -304,15 +341,14 @@ dependencies = [ "ethabi", "ethereum-types", "glob", - "rand 0.5.6", + "libsecp256k1", + "rand", "rlp", "rustc-hex", - "secp256k1", "serde", "serde_json", "thiserror", "tiny-keccak 2.0.2", - "zeroize", ] [[package]] @@ -338,6 +374,12 @@ dependencies = [ "ethers-providers", ] +[[package]] +name = "fake-simd" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e88a8acf291dafb59c2d96e8f59828f3838bb1a70398823ade51a84de6a6deed" + [[package]] name = "fixed-hash" version = "0.6.1" @@ -345,7 +387,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "11498d382790b7a8f2fd211780bec78619bba81cdad3a283997c0c41f836759c" dependencies = [ "byteorder", - "rand 0.7.3", + "rand", "rustc-hex", "static_assertions", ] @@ -356,12 +398,6 @@ version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "fuchsia-zircon" version = "0.3.3" @@ -436,6 +472,15 @@ dependencies = [ "slab", ] +[[package]] +name = "generic-array" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c68f0274ae0e023facc3c97b2e00f076be70e254bc851d972503b328db79b2ec" +dependencies = [ + "typenum", +] + [[package]] name = "getrandom" version = "0.1.14" @@ -472,6 +517,27 @@ dependencies = [ "tokio-util", ] +[[package]] +name = "hmac" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5dcb5e64cda4c23119ab41ba960d1e170a774c8e4b9d9e6a9bc18aabf5e59695" +dependencies = [ + "crypto-mac", + "digest", +] + +[[package]] +name = "hmac-drbg" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6e570451493f10f6581b48cdd530413b63ea9e780f544bfd3bdcaa0d89d1a7b" +dependencies = [ + "digest", + "generic-array", + "hmac", +] + [[package]] name = "http" version = "0.2.1" @@ -583,7 +649,7 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "076f042c5b7b98f31d205f1249267e12a6518c1481e9dae9764af19b707d2292" dependencies = [ - "autocfg 1.0.0", + "autocfg", ] [[package]] @@ -632,6 +698,22 @@ version = "0.2.71" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9457b06509d27052635f90d6466700c65095fdf75409b3fbdd903e988b886f49" +[[package]] +name = "libsecp256k1" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fc1e2c808481a63dc6da2074752fdd4336a3c8fcc68b83db6f1fd5224ae7962" +dependencies = [ + "arrayref", + "crunchy", + "digest", + "hmac-drbg", + "rand", + "sha2", + "subtle 2.2.3", + "typenum", +] + [[package]] name = "libz-sys" version = "1.0.25" @@ -729,6 +811,12 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b631f7e854af39a1739f401cf34a8a013dfe09eac4fa4dba91e9768bd28168d" +[[package]] +name = "opaque-debug" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2839e79665f131bdb5782e51f2c6c9599c133c6098982a54c794358bf432529c" + [[package]] name = "openssl-probe" version = "0.1.2" @@ -741,7 +829,7 @@ version = "0.9.57" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7410fef80af8ac071d4f63755c0ab89ac3df0fd1ea91f1d1f37cf5cec4395990" dependencies = [ - "autocfg 1.0.0", + "autocfg", "cc", "libc", "pkg-config", @@ -859,37 +947,6 @@ version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "def50a86306165861203e7f84ecffbbdfdea79f0e51039b33de1e952358c47ac" -[[package]] -name = "rand" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c618c47cd3ebd209790115ab837de41425723956ad3ce2e6a7f09890947cacb9" -dependencies = [ - "cloudabi", - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "winapi 0.3.8", -] - -[[package]] -name = "rand" -version = "0.6.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6d71dacdc3c88c1fde3885a3be3fbab9f35724e6ce99467f7d9c5026132184ca" -dependencies = [ - "autocfg 0.1.7", - "libc", - "rand_chacha 0.1.1", - "rand_core 0.4.2", - "rand_hc 0.1.0", - "rand_isaac", - "rand_jitter", - "rand_pcg", - "rand_xorshift", - "winapi 0.3.8", -] - [[package]] name = "rand" version = "0.7.3" @@ -898,19 +955,9 @@ checksum = "6a6b1679d49b24bbfe0c803429aa1874472f50d9b363131f0e89fc356b544d03" dependencies = [ "getrandom", "libc", - "rand_chacha 0.2.2", - "rand_core 0.5.1", - "rand_hc 0.2.0", -] - -[[package]] -name = "rand_chacha" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "556d3a1ca6600bfcbab7c7c91ccb085ac7fbbcd70e008a98742e7847f4f7bcef" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.3.1", + "rand_chacha", + "rand_core", + "rand_hc", ] [[package]] @@ -920,24 +967,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f4c8ed856279c9737206bf725bf36935d8666ead7aa69b52be55af369d193402" dependencies = [ "ppv-lite86", - "rand_core 0.5.1", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.5.1" @@ -947,61 +979,13 @@ dependencies = [ "getrandom", ] -[[package]] -name = "rand_hc" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b40677c7be09ae76218dc623efbf7b18e34bced3f38883af07bb75630a21bc4" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "rand_hc" version = "0.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ca3129af7b92a17112d59ad498c6f81eaf463253766b90396d39ea7a39d6613c" dependencies = [ - "rand_core 0.5.1", -] - -[[package]] -name = "rand_isaac" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ded997c9d5f13925be2a6fd7e66bf1872597f759fd9dd93513dd7e92e5a5ee08" -dependencies = [ - "rand_core 0.3.1", -] - -[[package]] -name = "rand_jitter" -version = "0.1.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1166d5c91dc97b88d1decc3285bb0a99ed84b05cfd0bc2341bdf2d43fc41e39b" -dependencies = [ - "libc", - "rand_core 0.4.2", - "winapi 0.3.8", -] - -[[package]] -name = "rand_pcg" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "abf9b09b01790cfe0364f52bf32995ea3c39f4d2dd011eac241d2914146d0b44" -dependencies = [ - "autocfg 0.1.7", - "rand_core 0.4.2", -] - -[[package]] -name = "rand_xorshift" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cbf7e9e623549b0e21f6e97cf8ecf247c1a8fd2e8a992ae265314300b2455d5c" -dependencies = [ - "rand_core 0.3.1", + "rand_core", ] [[package]] @@ -1133,25 +1117,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "secp256k1" -version = "0.17.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2932dc07acd2066ff2e3921a4419606b220ba6cd03a9935123856cc534877056" -dependencies = [ - "rand 0.6.5", - "secp256k1-sys", -] - -[[package]] -name = "secp256k1-sys" -version = "0.1.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ab2c26f0d3552a0f12e639ae8a64afc2e3db9c52fe32f5fc6c289d38519f220" -dependencies = [ - "cc", -] - [[package]] name = "serde" version = "1.0.111" @@ -1195,6 +1160,18 @@ dependencies = [ "url", ] +[[package]] +name = "sha2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a256f46ea78a0c0d9ff00077504903ac881a1dafdc20da66545699e7776b3e69" +dependencies = [ + "block-buffer", + "digest", + "fake-simd", + "opaque-debug", +] + [[package]] name = "slab" version = "0.4.2" @@ -1231,6 +1208,18 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" +[[package]] +name = "subtle" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2d67a5a62ba6e01cb2192ff309324cb4875d0c451d55fe2319433abe7a05a8ee" + +[[package]] +name = "subtle" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502d53007c02d7605a05df1c1a73ee436952781653da5d0bf57ad608f66932c1" + [[package]] name = "syn" version = "1.0.29" @@ -1366,6 +1355,12 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e604eb7b43c06650e854be16a2a03155743d3752dd1c943f6829e26b7a36e382" +[[package]] +name = "typenum" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "373c8a200f9e67a0c95e62a4f52fbf80c23b4381c05a17845531982fa99e6b33" + [[package]] name = "uint" version = "0.8.3" @@ -1605,9 +1600,3 @@ dependencies = [ "winapi 0.2.8", "winapi-build", ] - -[[package]] -name = "zeroize" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3cbac2ed2ba24cc90f5e06485ac8c7c1e5449fe8911aef4d8877218af021a5b8" diff --git a/crates/ethers-core/Cargo.toml b/crates/ethers-core/Cargo.toml index a63b0152..ca9305a7 100644 --- a/crates/ethers-core/Cargo.toml +++ b/crates/ethers-core/Cargo.toml @@ -11,9 +11,8 @@ rlp = { version = "0.4.5", default-features = false } ethabi = { version = "12.0.0", default-features = false, optional = true } # crypto -secp256k1 = { version = "0.17.2", default-features = false, features = ["std", "recovery", "rand"] } -rand = { version = "0.5.1", default-features = false } # this should be the same rand crate version as the one in secp -zeroize = { version = "1.1.0", default-features = false } +secp256k1 = { package = "libsecp256k1", version = "0.3.5" } +rand = "0.7.2" tiny-keccak = { version = "2.0.2", default-features = false } @@ -27,7 +26,6 @@ glob = "0.3.0" [dev-dependencies] serde_json = { version = "1.0.53", default-features = false } -rand = { version = "0.5.1" } bincode = "1.2.1" [features] diff --git a/crates/ethers-core/src/lib.rs b/crates/ethers-core/src/lib.rs index 3cd15588..31098ce1 100644 --- a/crates/ethers-core/src/lib.rs +++ b/crates/ethers-core/src/lib.rs @@ -7,8 +7,7 @@ pub mod abi; /// Various utilities pub mod utils; -// re-export the non-standard rand version so that other crates don't use the -// wrong one by accident +// re-export rand to avoid potential confusion when there's rand version mismatches pub use rand; // re-export libsecp diff --git a/crates/ethers-core/src/types/crypto/keys.rs b/crates/ethers-core/src/types/crypto/keys.rs index c2a1ad0f..11e40b71 100644 --- a/crates/ethers-core/src/types/crypto/keys.rs +++ b/crates/ethers-core/src/types/crypto/keys.rs @@ -4,24 +4,26 @@ use crate::{ }; use rand::Rng; +use rustc_hex::FromHex; use secp256k1::{ - key::ONE_KEY, recovery::RecoveryId, Error as SecpError, Message, PublicKey as PubKey, - Secp256k1, SecretKey, + self as Secp256k1, Error as SecpError, Message, PublicKey as PubKey, RecoveryId, SecretKey, }; use std::ops::Deref; use std::str::FromStr; use thiserror::Error; -use zeroize::DefaultIsZeroes; /// A private key on Secp256k1 -#[derive(Copy, Clone, Debug, PartialEq, Eq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct PrivateKey(pub(super) SecretKey); impl FromStr for PrivateKey { type Err = SecpError; fn from_str(src: &str) -> Result { - let sk = SecretKey::from_str(src)?; + let src = src + .from_hex::>() + .expect("invalid hex when reading PrivateKey"); + let sk = SecretKey::parse_slice(&src)?; Ok(PrivateKey(sk)) } } @@ -43,7 +45,7 @@ pub enum TxError { impl PrivateKey { pub fn new(rng: &mut R) -> Self { - PrivateKey(SecretKey::new(rng)) + PrivateKey(SecretKey::random(rng)) } /// Sign arbitrary string data. @@ -61,7 +63,7 @@ impl PrivateKey { let message_hash = hash_message(message); let sig_message = - Message::from_slice(message_hash.as_bytes()).expect("hash is non-zero 32-bytes; qed"); + Message::parse_slice(message_hash.as_bytes()).expect("hash is non-zero 32-bytes; qed"); self.sign_with_eip155(&sig_message, None) } @@ -88,7 +90,8 @@ impl PrivateKey { // Hash the transaction's RLP encoding let hash = tx.hash(chain_id); - let message = Message::from_slice(hash.as_bytes()).expect("hash is non-zero 32-bytes; qed"); + let message = + Message::parse_slice(hash.as_bytes()).expect("hash is non-zero 32-bytes; qed"); // Sign it (with replay protection if applicable) let signature = self.sign_with_eip155(&message, chain_id); @@ -124,13 +127,11 @@ impl PrivateKey { } fn sign_with_eip155(&self, message: &Message, chain_id: Option) -> Signature { - let (recovery_id, signature) = Secp256k1::signing_only() - .sign_recoverable(message, &self.0) - .serialize_compact(); + let (signature, recovery_id) = Secp256k1::sign(message, &self.0); let v = to_eip155_v(recovery_id, chain_id); - let r = H256::from_slice(&signature[..32]); - let s = H256::from_slice(&signature[32..]); + let r = H256::from_slice(&signature.r.b32()); + let s = H256::from_slice(&signature.s.b32()); // TODO: Check what happens when using the 1337 Geth chain id Signature { v: v as u8, r, s } @@ -139,7 +140,7 @@ impl PrivateKey { /// Applies [EIP155](https://github.com/ethereum/EIPs/blob/master/EIPS/eip-155.md) fn to_eip155_v(recovery_id: RecoveryId, chain_id: Option) -> u64 { - let standard_v = recovery_id.to_i32() as u64; + let standard_v = recovery_id.serialize() as u64; if let Some(chain_id) = chain_id { // When signing with a chain ID, add chain replay protection. standard_v + 35 + chain_id.as_u64() * 2 @@ -149,12 +150,6 @@ fn to_eip155_v(recovery_id: RecoveryId, chain_id: Option) -> u64 { } } -impl Default for PrivateKey { - fn default() -> Self { - PrivateKey(ONE_KEY) - } -} - impl Deref for PrivateKey { type Target = SecretKey; @@ -163,21 +158,10 @@ impl Deref for PrivateKey { } } -impl DefaultIsZeroes for PrivateKey {} - /// A secp256k1 Public Key #[derive(Clone, Debug, PartialEq, Eq)] pub struct PublicKey(pub(super) PubKey); -impl FromStr for PublicKey { - type Err = SecpError; - - fn from_str(src: &str) -> Result { - let sk = PubKey::from_str(src)?; - Ok(PublicKey(sk)) - } -} - impl From for PublicKey { /// Gets the public address of a private key. fn from(src: PubKey) -> PublicKey { @@ -188,8 +172,7 @@ impl From for PublicKey { impl From<&PrivateKey> for PublicKey { /// Gets the public address of a private key. fn from(src: &PrivateKey) -> PublicKey { - let secp = Secp256k1::signing_only(); - let public_key = PubKey::from_secret_key(&secp, src); + let public_key = PubKey::from_secret_key(src); PublicKey(public_key) } } @@ -203,7 +186,7 @@ impl From<&PrivateKey> for PublicKey { /// computing the hash. impl From<&PublicKey> for Address { fn from(src: &PublicKey) -> Address { - let public_key = src.0.serialize_uncompressed(); + let public_key = src.0.serialize(); debug_assert_eq!(public_key[0], 0x04); let hash = keccak256(&public_key[1..]); diff --git a/crates/ethers-core/src/types/crypto/signature.rs b/crates/ethers-core/src/types/crypto/signature.rs index 6676194e..a5f420fc 100644 --- a/crates/ethers-core/src/types/crypto/signature.rs +++ b/crates/ethers-core/src/types/crypto/signature.rs @@ -6,8 +6,8 @@ use crate::{ use rustc_hex::ToHex; use secp256k1::{ - recovery::{RecoverableSignature, RecoveryId}, - Error as Secp256k1Error, Message, Secp256k1, + self as Secp256k1, Error as Secp256k1Error, Message, RecoveryId, + Signature as RecoverableSignature, }; use serde::{Deserialize, Serialize}; use std::{convert::TryFrom, fmt}; @@ -69,25 +69,25 @@ impl Signature { RecoveryMessage::Data(ref message) => hash_message(message), RecoveryMessage::Hash(hash) => hash, }; - let signature = self.as_signature()?; + let message = Message::parse_slice(message_hash.as_bytes())?; - let message = Message::from_slice(message_hash.as_bytes())?; - let public_key = Secp256k1::verification_only().recover(&message, &signature)?; + let (signature, recovery_id) = self.as_signature()?; + let public_key = Secp256k1::recover(&message, &signature, &recovery_id)?; Ok(PublicKey::from(public_key).into()) } /// Retrieves the recovery signature. - fn as_signature(&self) -> Result { + fn as_signature(&self) -> Result<(RecoverableSignature, RecoveryId), SignatureError> { let recovery_id = self.recovery_id()?; let signature = { let mut sig = [0u8; 64]; sig[..32].copy_from_slice(self.r.as_bytes()); sig[32..].copy_from_slice(self.s.as_bytes()); - sig + RecoverableSignature::parse(&sig) }; - Ok(RecoverableSignature::from_compact(&signature, recovery_id)?) + Ok((signature, recovery_id)) } /// Retrieve the recovery ID. @@ -99,7 +99,7 @@ impl Signature { _ => 4, }; - Ok(RecoveryId::from_i32(standard_v)?) + Ok(RecoveryId::parse(standard_v)?) } /// Copies and serializes `self` into a new `Vec` with the recovery id included @@ -201,7 +201,7 @@ mod tests { let message = "Some data"; let hash = hash_message(message); let key = PrivateKey::new(&mut rand::thread_rng()); - let address = Address::from(key); + let address = Address::from(&key); // sign a message let signature = key.sign(message); diff --git a/crates/ethers/Cargo.toml b/crates/ethers/Cargo.toml index 8d255473..f5f71106 100644 --- a/crates/ethers/Cargo.toml +++ b/crates/ethers/Cargo.toml @@ -35,7 +35,7 @@ ethers-core = { version = "0.1.0", path = "../ethers-core", optional = true } anyhow = "1.0.31" tokio = { version = "0.2.21", features = ["macros"] } serde_json = "1.0.53" -rand = "0.5.1" # note: when passing RNGs, they must be with version 0.5.1 +rand = "0.7" serde = { version = "1.0.110", features = ["derive"] } [package.metadata.docs.rs]