Skip to content

Commit

Permalink
Update secp256k1 dependency to use PR rust-bitcoin/rust-secp256k1#721
Browse files Browse the repository at this point in the history
  • Loading branch information
jlest01 committed Aug 20, 2024
1 parent c061d93 commit 9bf8dfc
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
4 changes: 2 additions & 2 deletions bitcoin/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ exclude = ["tests", "contrib"]
[features]
default = [ "std", "secp-recovery" ]
std = ["base58/std", "bech32/std", "hashes/std", "hex/std", "internals/std", "io/std", "primitives/std", "secp256k1/std", "units/std", "bitcoinconsensus?/std"]
rand-std = ["secp256k1/rand-std", "std"]
rand-std = ["secp256k1/std", "secp256k1/rand", "std"]
rand = ["secp256k1/rand"]
serde = ["dep:serde", "hashes/serde", "internals/serde", "primitives/serde", "secp256k1/serde", "units/serde"]
secp-lowmemory = ["secp256k1/lowmemory"]
Expand All @@ -31,7 +31,7 @@ hex = { package = "hex-conservative", version = "0.2.0", default-features = fals
internals = { package = "bitcoin-internals", version = "0.3.0", features = ["alloc"] }
io = { package = "bitcoin-io", version = "0.1.1", default-features = false, features = ["alloc"] }
primitives = { package = "bitcoin-primitives", version = "0.100.0", default-features = false, features = ["alloc"] }
secp256k1 = { version = "0.29.0", default-features = false, features = ["hashes", "alloc"] }
secp256k1 = { git = "https://github.com/rust-bitcoin/rust-secp256k1.git", rev = "refs/pull/721/head", default-features = false, features = ["alloc", "hashes", "rand", "std"] }
units = { package = "bitcoin-units", version = "0.1.0", default-features = false, features = ["alloc"] }

base64 = { version = "0.22.0", optional = true }
Expand Down
4 changes: 2 additions & 2 deletions bitcoin/examples/sign-tx-taproot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::str::FromStr;
use bitcoin::address::script_pubkey::ScriptBufExt as _;
use bitcoin::key::{Keypair, TapTweak, TweakedKeypair, UntweakedPublicKey};
use bitcoin::locktime::absolute;
use bitcoin::secp256k1::{rand, Message, Secp256k1, SecretKey, Signing, Verification};
use bitcoin::secp256k1::{rand, Secp256k1, SecretKey, Signing, Verification};
use bitcoin::sighash::{Prevouts, SighashCache, TapSighashType};
use bitcoin::{
transaction, Address, Amount, Network, OutPoint, ScriptBuf, Sequence, Transaction, TxIn, TxOut,
Expand Down Expand Up @@ -71,7 +71,7 @@ fn main() {

// Sign the sighash using the secp256k1 library (exported by rust-bitcoin).
let tweaked: TweakedKeypair = keypair.tap_tweak(&secp, None);
let msg = Message::from(sighash);
let msg = sighash.to_byte_array();
let signature = secp.sign_schnorr(&msg, &tweaked.to_inner());

// Update the witness stack.
Expand Down
2 changes: 1 addition & 1 deletion bitcoin/examples/taproot-psbt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ fn sign_psbt_taproot(
Some(_) => keypair, // no tweak for script spend
};

let msg = secp256k1::Message::from(hash);
let msg = hash.to_byte_array();
let signature = secp.sign_schnorr(&msg, &keypair);

let final_signature = taproot::Signature { signature, sighash_type };
Expand Down
10 changes: 7 additions & 3 deletions bitcoin/src/psbt/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::prelude::{btree_map, BTreeMap, BTreeSet, Borrow, Box, Vec};
use crate::script::ScriptExt as _;
use crate::sighash::{self, EcdsaSighashType, Prevouts, SighashCache};
use crate::transaction::{self, Transaction, TxOut};
use crate::{Amount, FeeRate, TapLeafHash, TapSighashType};
use crate::{Amount, FeeRate, TapLeafHash, TapSighash, TapSighashType};

#[rustfmt::skip] // Keep public re-exports separate.
#[doc(inline)]
Expand Down Expand Up @@ -443,6 +443,8 @@ impl Psbt {
.tap_tweak(secp, input.tap_merkle_root)
.to_inner();

let msg = msg.to_byte_array();

#[cfg(feature = "rand-std")]
let signature = secp.sign_schnorr(&msg, &key_pair);
#[cfg(not(feature = "rand-std"))]
Expand Down Expand Up @@ -470,6 +472,8 @@ impl Psbt {
let (msg, sighash_type) =
self.sighash_taproot(input_index, cache, Some(lh))?;

let msg = msg.to_byte_array();

#[cfg(feature = "rand-std")]
let signature = secp.sign_schnorr(&msg, &key_pair);
#[cfg(not(feature = "rand-std"))]
Expand Down Expand Up @@ -560,7 +564,7 @@ impl Psbt {
input_index: usize,
cache: &mut SighashCache<T>,
leaf_hash: Option<TapLeafHash>,
) -> Result<(Message, TapSighashType), SignError> {
) -> Result<(TapSighash, TapSighashType), SignError> {
use OutputType::*;

if self.signing_algorithm(input_index)? != SigningAlgorithm::Schnorr {
Expand Down Expand Up @@ -605,7 +609,7 @@ impl Psbt {
} else {
cache.taproot_key_spend_signature_hash(input_index, &prev_outs, hash_ty)?
};
Ok((Message::from(sighash), hash_ty))
Ok((sighash, hash_ty))
}
_ => Err(SignError::Unsupported),
}
Expand Down

0 comments on commit 9bf8dfc

Please sign in to comment.