Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update to bdk v0.19.0 #5

Merged
merged 1 commit into from
Jun 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ license = "MIT OR Apache-2.0"
repository = "https://github.com/weareseba/bdk-reserves"

[dependencies]
bdk = { version = "^0.18", default-features = false }
bdk = { version = "0.19", default-features = false }
bitcoinconsensus = "0.19.0-3"
base64 = "^0.11"
log = "^0.4"

[dev-dependencies]
rstest = "^0.11"
bdk-testutils = "^0.4"
bdk = { version = "^0.18", default-features = true }
bdk = { version = "0.19", default-features = true }
14 changes: 7 additions & 7 deletions src/reserves.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

use bdk::bitcoin::blockdata::opcodes;
use bdk::bitcoin::blockdata::script::{Builder, Script};
use bdk::bitcoin::blockdata::transaction::{OutPoint, SigHashType, TxIn, TxOut};
use bdk::bitcoin::blockdata::transaction::{EcdsaSighashType, OutPoint, TxIn, TxOut};
use bdk::bitcoin::consensus::encode::serialize;
use bdk::bitcoin::hash_types::{PubkeyHash, Txid};
use bdk::bitcoin::hashes::{hash160, sha256d, Hash};
Expand Down Expand Up @@ -232,7 +232,7 @@ pub fn verify_proof(

// Verify the SIGHASH
if let Some((i, _psbt_in)) = psbt.inputs.iter().enumerate().find(|(_i, psbt_in)| {
psbt_in.sighash_type.is_some() && psbt_in.sighash_type != Some(SigHashType::All)
psbt_in.sighash_type.is_some() && psbt_in.sighash_type != Some(EcdsaSighashType::All.into())
}) {
return Err(ProofError::UnsupportedSighashType(i));
}
Expand Down Expand Up @@ -446,7 +446,7 @@ mod test {

let message = "This belongs to me.";
let mut psbt = get_signed_proof();
psbt.global.unsigned_tx.input.truncate(1);
psbt.unsigned_tx.input.truncate(1);
psbt.inputs.truncate(1);

wallet.verify_proof(&psbt, message, None).unwrap();
Expand All @@ -460,7 +460,7 @@ mod test {

let message = "This belongs to me.";
let mut psbt = get_signed_proof();
psbt.global.unsigned_tx.output.clear();
psbt.unsigned_tx.output.clear();
psbt.inputs.clear();

wallet.verify_proof(&psbt, message, None).unwrap();
Expand Down Expand Up @@ -488,7 +488,7 @@ mod test {

let message = "This belongs to me.";
let mut psbt = get_signed_proof();
psbt.inputs[1].sighash_type = Some(SigHashType::SinglePlusAnyoneCanPay);
psbt.inputs[1].sighash_type = Some(EcdsaSighashType::SinglePlusAnyoneCanPay.into());

wallet.verify_proof(&psbt, message, None).unwrap();
}
Expand All @@ -508,7 +508,7 @@ mod test {
network: Network::Testnet,
}
.script_pubkey();
psbt.global.unsigned_tx.output[0].script_pubkey = out_script_unspendable;
psbt.unsigned_tx.output[0].script_pubkey = out_script_unspendable;

wallet.verify_proof(&psbt, message, None).unwrap();
}
Expand All @@ -521,7 +521,7 @@ mod test {

let message = "This belongs to me.";
let mut psbt = get_signed_proof();
psbt.global.unsigned_tx.output[0].value = 123;
psbt.unsigned_tx.output[0].value = 123;

wallet.verify_proof(&psbt, message, None).unwrap();
}
Expand Down
9 changes: 4 additions & 5 deletions tests/tampering.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use bdk::bitcoin::blockdata::transaction::SigHashType;
use bdk::bitcoin::blockdata::transaction::EcdsaSighashType;
use bdk::wallet::get_funded_wallet;
use bdk::SignOptions;
use bdk_reserves::reserves::*;
Expand Down Expand Up @@ -27,8 +27,7 @@ fn tampered_proof_message() {
// change the message
let message_bob = "This belongs to Bob.";
let psbt_bob = wallet.create_proof(message_bob).unwrap();
psbt_alice.global.unsigned_tx.input[0].previous_output =
psbt_bob.global.unsigned_tx.input[0].previous_output;
psbt_alice.unsigned_tx.input[0].previous_output = psbt_bob.unsigned_tx.input[0].previous_output;
psbt_alice.inputs[0].witness_utxo = psbt_bob.inputs[0].witness_utxo.clone();

let res_alice = wallet.verify_proof(&psbt_alice, message_alice, None);
Expand All @@ -55,7 +54,7 @@ fn tampered_proof_sighash_tx() {
};

// set an unsupported sighash
psbt.inputs[1].sighash_type = Some(SigHashType::Single);
psbt.inputs[1].sighash_type = Some(EcdsaSighashType::Single.into());

let _finalized = wallet.sign(&mut psbt, signopt).unwrap();

Expand All @@ -78,7 +77,7 @@ fn tampered_proof_miner_fee() {
};

// reduce the output value to grant a miner fee
psbt.global.unsigned_tx.output[0].value -= 100;
psbt.unsigned_tx.output[0].value -= 100;

let _finalized = wallet.sign(&mut psbt, signopt).unwrap();

Expand Down