Skip to content

Commit

Permalink
fix: Bump k256 to ^0.13.3 (cherry-picking 9a6b365c352283119d78ed9f5ad…
Browse files Browse the repository at this point in the history
…715533fe8c3ae)
  • Loading branch information
webmaster128 authored and loloicci committed Feb 1, 2024
1 parent 2a0972b commit a179310
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 39 deletions.
83 changes: 47 additions & 36 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion packages/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ backtraces = []
bench = false

[dependencies]
k256 = { version = "0.13.1", features = ["ecdsa"] }
k256 = { version = "0.13.3", features = ["ecdsa"] }
ed25519-zebra = "3"
digest = "0.10"
rand_core = { version = "0.6", features = ["getrandom"] }
Expand Down
10 changes: 8 additions & 2 deletions packages/crypto/src/secp256k1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,18 +105,24 @@ pub fn secp256k1_recover_pubkey(
let signature = read_signature(signature)?;

// params other than 0 and 1 are explicitly not supported
let id = match recovery_param {
let mut id = match recovery_param {
0 => RecoveryId::new(false, false),
1 => RecoveryId::new(true, false),
_ => return Err(CryptoError::invalid_recovery_param()),
};

// Compose extended signature
let signature = Signature::from_bytes(&signature.into())
let mut signature = Signature::from_bytes(&signature.into())
.map_err(|e| CryptoError::generic_err(e.to_string()))?;

// Recover
let message_digest = Identity256::new().chain(message_hash);

if let Some(normalized) = signature.normalize_s() {
signature = normalized;
id = RecoveryId::new(!id.is_y_odd(), id.is_x_reduced());
}

let pubkey = VerifyingKey::recover_from_digest(message_digest, &signature, id)
.map_err(|e| CryptoError::generic_err(e.to_string()))?;
let encoded: Vec<u8> = pubkey.to_encoded_point(false).as_bytes().into();
Expand Down

0 comments on commit a179310

Please sign in to comment.