Skip to content

Commit

Permalink
Amend
Browse files Browse the repository at this point in the history
  • Loading branch information
raphjaph committed Aug 10, 2024
1 parent 4dc6d20 commit 21704cc
Showing 1 changed file with 13 additions and 14 deletions.
27 changes: 13 additions & 14 deletions src/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ pub fn simple_verify(address: &str, message: &str, signature: &str) -> Result<()
simple_verify_inner(&address, message.as_bytes(), witness)
}

/// Meant to be consumed by Rust applications
pub fn simple_verify_inner(address: &Address, message: &[u8], signature: Witness) -> Result<()> {
full_verify_inner(
address,
message,
create_to_sign(&create_to_spend(address, message), Some(signature))
.extract_tx()
.unwrap(),
)
}

/// This completely outward facing function is meant to be consumed by very naive users like when
/// compiling this library to WASM, where Javascript has no type safety. If you'd like to use the
/// more type safe / Rust variant use `fn full_verify_inner`.
Expand All @@ -42,16 +53,7 @@ pub fn full_verify(address: &str, message: &str, to_sign: &str) -> Result<()> {
full_verify_inner(&address, message.as_bytes(), to_sign)
}

pub fn simple_verify_inner(address: &Address, message: &[u8], signature: Witness) -> Result<()> {
full_verify_inner(
address,
message,
create_to_sign(&create_to_spend(address, message), Some(signature))
.extract_tx()
.unwrap(),
)
}

/// Meant to be consumed by Rust applications
pub fn full_verify_inner(address: &Address, message: &[u8], to_sign: Transaction) -> Result<()> {
if address
.address_type()
Expand All @@ -78,8 +80,6 @@ pub fn full_verify_inner(address: &Address, message: &[u8], to_sign: Transaction

let to_spend = create_to_spend(address, message);

let witness = to_sign.input[0].witness.clone();

let to_spend_outpoint = OutPoint {
txid: to_spend.txid(),
vout: 0,
Expand All @@ -89,8 +89,7 @@ pub fn full_verify_inner(address: &Address, message: &[u8], to_sign: Transaction
return Err(Error::Invalid);
}

let mut to_sign = create_to_sign(&to_spend, None);
to_sign.inputs[0].final_script_witness = Some(witness);
let to_sign = create_to_sign(&to_spend, Some(to_sign.input[0].witness.clone()));

if to_spend_outpoint != to_sign.unsigned_tx.input[0].previous_output {
return Err(Error::Invalid);
Expand Down

0 comments on commit 21704cc

Please sign in to comment.