From 87beabbaf9b351a5cd87489ff037d5273edfed85 Mon Sep 17 00:00:00 2001 From: blocksurf Date: Mon, 27 Nov 2023 18:44:06 -0500 Subject: [PATCH] add methods to wasm --- packages/bsv-wasm/src/ecdsa.rs | 8 ++++++++ packages/bsv-wasm/src/signature.rs | 4 ++++ packages/bsv-wasm/src/transaction/mod.rs | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/packages/bsv-wasm/src/ecdsa.rs b/packages/bsv-wasm/src/ecdsa.rs index 54e5d97..8a65cba 100644 --- a/packages/bsv-wasm/src/ecdsa.rs +++ b/packages/bsv-wasm/src/ecdsa.rs @@ -51,6 +51,10 @@ impl ECDSA { Ok(Signature(BSVECDSA::sign_with_deterministic_k(&private_key.0, preimage, hash_algo.into(), reverse_k)?)) } + pub fn sign_digest_with_deterministic_k(private_key: &PrivateKey, digest: &[u8]) -> Result { + Ok(Signature(BSVECDSA::sign_digest_with_deterministic_k(&private_key.0, digest)?)) + } + pub fn sign_with_k(private_key: &PrivateKey, ephemeral_key: &PrivateKey, preimage: &[u8], hash_algo: SigningHash) -> Result { Ok(Signature(BSVECDSA::sign_with_k(&private_key.0, &ephemeral_key.0, preimage, hash_algo.into())?)) } @@ -58,4 +62,8 @@ impl ECDSA { pub fn verify_digest(message: &[u8], pub_key: &PublicKey, signature: &Signature, hash_algo: SigningHash) -> Result { Ok(BSVECDSA::verify_digest(message, &pub_key.0, &signature.0, hash_algo.into())?) } + + pub fn verify_hashbuf(digest: &[u8], pub_key: &PublicKey, signature: &Signature) -> Result { + Ok(BSVECDSA::verify_hashbuf(digest, &pub_key.0, &signature.0)?) + } } diff --git a/packages/bsv-wasm/src/signature.rs b/packages/bsv-wasm/src/signature.rs index b5edbf4..c58f2fa 100644 --- a/packages/bsv-wasm/src/signature.rs +++ b/packages/bsv-wasm/src/signature.rs @@ -56,6 +56,10 @@ impl Signature { Ok(PublicKey(self.0.recover_public_key(message, hash_algo.into())?)) } + pub fn recover_public_key_from_digest(&self, digest: &[u8]) -> Result { + Ok(PublicKey(self.0.recover_public_key_from_digest(digest)?)) + } + pub fn to_der_hex(&self) -> String { BSVSignature::to_der_hex(&self.0) } diff --git a/packages/bsv-wasm/src/transaction/mod.rs b/packages/bsv-wasm/src/transaction/mod.rs index 811f7b9..444e9b1 100644 --- a/packages/bsv-wasm/src/transaction/mod.rs +++ b/packages/bsv-wasm/src/transaction/mod.rs @@ -276,4 +276,8 @@ impl Transaction { pub fn verify(&self, pub_key: &PublicKey, sig: &SighashSignature) -> bool { self.0.verify(&pub_key.0, &sig.0) } + + pub fn _verify(&self, pub_key: &PublicKey, sig: &SighashSignature, reverse_digest: bool) -> bool { + self.0._verify(&pub_key.0, &sig.0, reverse_digest) + } }