From d20baf2af8b2753a375ad246ed2489fb0c21e5e5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 20 Jul 2021 08:05:30 +0000 Subject: [PATCH 1/2] Update libsecp256k1 requirement from 0.3.5 to 0.6.0 Updates the requirements on [libsecp256k1](https://github.com/paritytech/libsecp256k1) to permit the latest version. - [Release notes](https://github.com/paritytech/libsecp256k1/releases) - [Changelog](https://github.com/paritytech/libsecp256k1/blob/master/CHANGELOG.md) - [Commits](https://github.com/paritytech/libsecp256k1/commits) --- updated-dependencies: - dependency-name: libsecp256k1 dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- keys/Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keys/Cargo.toml b/keys/Cargo.toml index 12e8f95..fa7444a 100644 --- a/keys/Cargo.toml +++ b/keys/Cargo.toml @@ -23,7 +23,7 @@ std = [ bs58 = { version = "0.4", default-features = false, features = ["alloc"] } codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } hex = { version = "0.4", default-features = false } -libsecp256k1 = { version = "0.3.5", default-features = false, features = ["hmac"] } +libsecp256k1 = { version = "0.6.0", default-features = false, features = ["hmac"] } serde = { version = "1.0", features = ["derive"], optional = true } light-bitcoin-crypto = { path = "../crypto", default-features = false } From ea40549a85407b2904971bffb3159f78bef2ae4e Mon Sep 17 00:00:00 2001 From: hacpy Date: Wed, 25 Aug 2021 18:11:17 +0800 Subject: [PATCH 2/2] Bump libsecp256k1 to 0.6.0 --- keys/Cargo.toml | 2 +- keys/src/error.rs | 12 ++++++------ keys/src/keypair.rs | 10 +++++----- keys/src/private.rs | 12 ++++++------ keys/src/public.rs | 28 ++++++++++++++-------------- 5 files changed, 32 insertions(+), 32 deletions(-) diff --git a/keys/Cargo.toml b/keys/Cargo.toml index fa7444a..005829a 100644 --- a/keys/Cargo.toml +++ b/keys/Cargo.toml @@ -23,7 +23,7 @@ std = [ bs58 = { version = "0.4", default-features = false, features = ["alloc"] } codec = { package = "parity-scale-codec", version = "2.0.0", default-features = false, features = ["derive"] } hex = { version = "0.4", default-features = false } -libsecp256k1 = { version = "0.6.0", default-features = false, features = ["hmac"] } +libsecp256k1 = { version = "0.6.0", default-features = false, features = ["hmac", "static-context"] } serde = { version = "1.0", features = ["derive"], optional = true } light-bitcoin-crypto = { path = "../crypto", default-features = false } diff --git a/keys/src/error.rs b/keys/src/error.rs index 5c8b6cc..cbfe225 100644 --- a/keys/src/error.rs +++ b/keys/src/error.rs @@ -32,13 +32,13 @@ impl core::fmt::Display for Error { } } -impl From for Error { - fn from(e: secp256k1::Error) -> Self { +impl From for Error { + fn from(e: libsecp256k1::Error) -> Self { match e { - secp256k1::Error::InvalidSignature => Error::InvalidSignature, - secp256k1::Error::InvalidPublicKey => Error::InvalidPublic, - secp256k1::Error::InvalidSecretKey => Error::InvalidSecret, - secp256k1::Error::InvalidMessage => Error::InvalidMessage, + libsecp256k1::Error::InvalidSignature => Error::InvalidSignature, + libsecp256k1::Error::InvalidPublicKey => Error::InvalidPublic, + libsecp256k1::Error::InvalidSecretKey => Error::InvalidSecret, + libsecp256k1::Error::InvalidMessage => Error::InvalidMessage, _ => Error::InvalidSignature, } } diff --git a/keys/src/keypair.rs b/keys/src/keypair.rs index 8b87f25..2b4ba96 100644 --- a/keys/src/keypair.rs +++ b/keys/src/keypair.rs @@ -32,8 +32,8 @@ impl KeyPair { } pub fn from_private(private: Private) -> Result { - let secret_key = secp256k1::SecretKey::parse(private.secret.as_fixed_bytes())?; - let pub_key = secp256k1::PublicKey::from_secret_key(&secret_key); + let secret_key = libsecp256k1::SecretKey::parse(private.secret.as_fixed_bytes())?; + let pub_key = libsecp256k1::PublicKey::from_secret_key(&secret_key); let public = if private.compressed { let public = H264::from_slice(&pub_key.serialize_compressed()); Public::Compressed(public) @@ -46,11 +46,11 @@ impl KeyPair { } pub fn from_keypair( - sec: secp256k1::SecretKey, - public: secp256k1::PublicKey, + sec: libsecp256k1::SecretKey, + public: libsecp256k1::PublicKey, network: Network, ) -> Self { - let sec: secp256k1::curve::Scalar = sec.into(); + let sec: libsecp256k1::curve::Scalar = sec.into(); let sec = sec.b32(); let secret = Secret::from_slice(&sec[..]); let serialized = public.serialize(); diff --git a/keys/src/private.rs b/keys/src/private.rs index cd54fc8..6e2d9f0 100644 --- a/keys/src/private.rs +++ b/keys/src/private.rs @@ -43,16 +43,16 @@ impl str::FromStr for Private { impl Private { pub fn sign(&self, message: &Message) -> Result { - let secret = secp256k1::SecretKey::parse(self.secret.as_fixed_bytes())?; - let message = secp256k1::Message::parse(message.as_fixed_bytes()); - let (signature, _recovery_id) = secp256k1::sign(&message, &secret); + let secret = libsecp256k1::SecretKey::parse(self.secret.as_fixed_bytes())?; + let message = libsecp256k1::Message::parse(message.as_fixed_bytes()); + let (signature, _recovery_id) = libsecp256k1::sign(&message, &secret); Ok(signature.serialize_der().as_ref().to_vec().into()) } pub fn sign_compact(&self, message: &Message) -> Result { - let secret = secp256k1::SecretKey::parse(self.secret.as_fixed_bytes())?; - let message = secp256k1::Message::parse(message.as_fixed_bytes()); - let (signature, recovery_id) = secp256k1::sign(&message, &secret); + let secret = libsecp256k1::SecretKey::parse(self.secret.as_fixed_bytes())?; + let message = libsecp256k1::Message::parse(message.as_fixed_bytes()); + let (signature, recovery_id) = libsecp256k1::sign(&message, &secret); let recovery_id = recovery_id.serialize(); let data = signature.serialize(); diff --git a/keys/src/public.rs b/keys/src/public.rs index df97fdd..6c44c12 100644 --- a/keys/src/public.rs +++ b/keys/src/public.rs @@ -73,37 +73,37 @@ impl Public { pub fn verify(&self, message: &Message, signature: &Signature) -> Result { let public = match self { - Public::Normal(pubkey) => secp256k1::PublicKey::parse(pubkey.as_fixed_bytes())?, + Public::Normal(pubkey) => libsecp256k1::PublicKey::parse(pubkey.as_fixed_bytes())?, Public::Compressed(pubkey) => { - secp256k1::PublicKey::parse_compressed(pubkey.as_fixed_bytes())? + libsecp256k1::PublicKey::parse_compressed(pubkey.as_fixed_bytes())? } }; - let mut signature = secp256k1::Signature::parse_der_lax(&**signature)?; + let mut signature = libsecp256k1::Signature::parse_der_lax(&**signature)?; signature.normalize_s(); - let message = secp256k1::Message::parse(message.as_fixed_bytes()); - Ok(secp256k1::verify(&message, &signature, &public)) + let message = libsecp256k1::Message::parse(message.as_fixed_bytes()); + Ok(libsecp256k1::verify(&message, &signature, &public)) } pub fn verify_compact(&self, message: &Message, signature: &[u8; 64]) -> Result { let public = match self { - Public::Normal(pubkey) => secp256k1::PublicKey::parse(pubkey.as_fixed_bytes())?, + Public::Normal(pubkey) => libsecp256k1::PublicKey::parse(pubkey.as_fixed_bytes())?, Public::Compressed(pubkey) => { - secp256k1::PublicKey::parse_compressed(pubkey.as_fixed_bytes())? + libsecp256k1::PublicKey::parse_compressed(pubkey.as_fixed_bytes())? } }; - let signature = secp256k1::Signature::parse(signature); - let message = secp256k1::Message::parse(message.as_fixed_bytes()); - Ok(secp256k1::verify(&message, &signature, &public)) + let signature = libsecp256k1::Signature::parse_standard(signature)?; + let message = libsecp256k1::Message::parse(message.as_fixed_bytes()); + Ok(libsecp256k1::verify(&message, &signature, &public)) } pub fn recover_compact(message: &Message, signature: &CompactSignature) -> Result { let recovery_id = (signature[0] - 27) & 3; let compressed = (signature[0] - 27) & 4 != 0; - let recovery_id = secp256k1::RecoveryId::parse(recovery_id)?; + let recovery_id = libsecp256k1::RecoveryId::parse(recovery_id)?; let sign = H512::from_slice(&signature[1..65]); - let signature = secp256k1::Signature::parse(sign.as_fixed_bytes()); - let message = secp256k1::Message::parse(message.as_fixed_bytes()); - let pub_key = secp256k1::recover(&message, &signature, &recovery_id)?; + let signature = libsecp256k1::Signature::parse_standard(sign.as_fixed_bytes())?; + let message = libsecp256k1::Message::parse(message.as_fixed_bytes()); + let pub_key = libsecp256k1::recover(&message, &signature, &recovery_id)?; let public = if compressed { let public = H264::from_slice(&pub_key.serialize_compressed());