Skip to content

Commit

Permalink
expose ecdsa_sign_prehashed in sp-io (paritytech#10119)
Browse files Browse the repository at this point in the history
* expose ecdsa_sign_prehashed in sp-io

* add ecdsa_verify_prehashed to host functions for completeness

* cargo fmt
  • Loading branch information
dt665m authored and grishasobol committed Mar 28, 2022
1 parent 1991876 commit af8e60f
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions primitives/io/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -709,6 +709,22 @@ pub trait Crypto {
.map(|sig| ecdsa::Signature::from_slice(sig.as_slice()))
}

/// Sign the given a pre-hashed `msg` with the `ecdsa` key that corresponds to the given public
/// key and key type in the keystore.
///
/// Returns the signature.
fn ecdsa_sign_prehashed(
&mut self,
id: KeyTypeId,
pub_key: &ecdsa::Public,
msg: &[u8; 32],
) -> Option<ecdsa::Signature> {
let keystore = &***self
.extension::<KeystoreExt>()
.expect("No `keystore` associated for the current context!");
SyncCryptoStore::ecdsa_sign_prehashed(keystore, id, pub_key, msg).ok().flatten()
}

/// Verify `ecdsa` signature.
///
/// Returns `true` when the verification was successful.
Expand All @@ -724,6 +740,17 @@ pub trait Crypto {
ecdsa::Pair::verify(sig, msg, pub_key)
}

/// Verify `ecdsa` signature with pre-hashed `msg`.
///
/// Returns `true` when the verification was successful.
fn ecdsa_verify_prehashed(
sig: &ecdsa::Signature,
msg: &[u8; 32],
pub_key: &ecdsa::Public,
) -> bool {
ecdsa::Pair::verify_prehashed(sig, msg, pub_key)
}

/// Register a `ecdsa` signature for batch verification.
///
/// Batch verification must be enabled by calling [`start_batch_verify`].
Expand Down

0 comments on commit af8e60f

Please sign in to comment.