Skip to content

Commit

Permalink
add methods to wasm
Browse files Browse the repository at this point in the history
  • Loading branch information
blocksurf committed Nov 27, 2023
1 parent 1372a34 commit 87beabb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions packages/bsv-wasm/src/ecdsa.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,19 @@ 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<Signature, wasm_bindgen::JsError> {
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<Signature, wasm_bindgen::JsError> {
Ok(Signature(BSVECDSA::sign_with_k(&private_key.0, &ephemeral_key.0, preimage, hash_algo.into())?))
}

pub fn verify_digest(message: &[u8], pub_key: &PublicKey, signature: &Signature, hash_algo: SigningHash) -> Result<bool, wasm_bindgen::JsError> {
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<bool, wasm_bindgen::JsError> {
Ok(BSVECDSA::verify_hashbuf(digest, &pub_key.0, &signature.0)?)
}
}
4 changes: 4 additions & 0 deletions packages/bsv-wasm/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<PublicKey, wasm_bindgen::JsError> {
Ok(PublicKey(self.0.recover_public_key_from_digest(digest)?))
}

pub fn to_der_hex(&self) -> String {
BSVSignature::to_der_hex(&self.0)
}
Expand Down
4 changes: 4 additions & 0 deletions packages/bsv-wasm/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 87beabb

Please sign in to comment.