Merge rust-bitcoin/rust-bitcoin#1276: Fix deprecated v0.28.0

3f275f7f2b Remove code deprecated in v0.28.0 (Tobin C. Harding)
c4eb218cd0 schnorr:: Remove incorrect deprecated (Tobin C. Harding)

Pull request description:

  We have a bunch of things deprecated since v0.28.0, I believe we agreed to deprecate for two release cycles so this stuff can all be deleted now.

  - Patch one does the `schnorr` module; the deprecated attribute usage is just plain wrong (see https://github.com/rust-bitcoin/rust-bitcoin/discussions/1275). Also, in an attempt to make the API more ergonomic, patch one adds re-exports of secp types.

  - Patch 2 deletes all other code deprecated since v0.28.0

ACKs for top commit:
  Kixunil:
    ACK 3f275f7f2b
  apoelstra:
    ACK 3f275f7f2b

Tree-SHA512: 501d792c48830d28c9ad04335a56d75cf31e0bd8dc1f4e184d7d6906dbf2468369d809954709014ee5ec32ac330b56008d4be14d5f3cc89226032e642556e945
This commit is contained in:
Andrew Poelstra 2022-09-15 13:37:44 +00:00
commit 5e83c602fd
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
10 changed files with 15 additions and 255 deletions

View File

@ -298,12 +298,6 @@ impl Block {
bitcoin_merkle_root(hashes).map(|h| h.into()) bitcoin_merkle_root(hashes).map(|h| h.into())
} }
/// Calculate the transaction merkle root.
#[deprecated(since = "0.28.0", note = "Please use `block::compute_merkle_root` instead.")]
pub fn merkle_root(&self) -> Option<TxMerkleNode> {
self.compute_merkle_root()
}
/// Computes the witness commitment for the block's transaction list. /// Computes the witness commitment for the block's transaction list.
pub fn compute_witness_commitment(witness_root: &WitnessMerkleNode, witness_reserved_value: &[u8]) -> WitnessCommitment { pub fn compute_witness_commitment(witness_root: &WitnessMerkleNode, witness_reserved_value: &[u8]) -> WitnessCommitment {
let mut encoder = WitnessCommitment::engine(); let mut encoder = WitnessCommitment::engine();
@ -330,12 +324,6 @@ impl Block {
80 + VarInt(self.txdata.len() as u64).len() 80 + VarInt(self.txdata.len() as u64).len()
} }
/// Returns the size of the block.
#[deprecated(since = "0.28.0", note = "Please use `block::size` instead.")]
pub fn get_size(&self) -> usize {
self.size()
}
/// Returns the size of the block. /// Returns the size of the block.
/// ///
/// size == size of header + size of encoded transaction count + total size of transactions. /// size == size of header + size of encoded transaction count + total size of transactions.
@ -344,24 +332,12 @@ impl Block {
self.base_size() + txs_size self.base_size() + txs_size
} }
/// Returns the strippedsize of the block.
#[deprecated(since = "0.28.0", note = "Please use `transaction::strippedsize` instead.")]
pub fn get_strippedsize(&self) -> usize {
self.strippedsize()
}
/// Returns the strippedsize of the block. /// Returns the strippedsize of the block.
pub fn strippedsize(&self) -> usize { pub fn strippedsize(&self) -> usize {
let txs_size: usize = self.txdata.iter().map(Transaction::strippedsize).sum(); let txs_size: usize = self.txdata.iter().map(Transaction::strippedsize).sum();
self.base_size() + txs_size self.base_size() + txs_size
} }
/// Returns the weight of the block.
#[deprecated(since = "0.28.0", note = "Please use `transaction::weight` instead.")]
pub fn get_weight(&self) -> usize {
self.weight()
}
/// Returns the weight of the block. /// Returns the weight of the block.
pub fn weight(&self) -> usize { pub fn weight(&self) -> usize {
let base_weight = WITNESS_SCALE_FACTOR * self.base_size(); let base_weight = WITNESS_SCALE_FACTOR * self.base_size();

View File

@ -382,23 +382,11 @@ impl Script {
.into_script() .into_script()
} }
/// Generates P2WPKH-type of scriptPubkey.
#[deprecated(since = "0.28.0", note = "use Script::new_v0_p2wpkh method instead")]
pub fn new_v0_wpkh(pubkey_hash: &WPubkeyHash) -> Script {
Script::new_v0_p2wpkh(pubkey_hash)
}
/// Generates P2WPKH-type of scriptPubkey. /// Generates P2WPKH-type of scriptPubkey.
pub fn new_v0_p2wpkh(pubkey_hash: &WPubkeyHash) -> Script { pub fn new_v0_p2wpkh(pubkey_hash: &WPubkeyHash) -> Script {
Script::new_witness_program(WitnessVersion::V0, &pubkey_hash[..]) Script::new_witness_program(WitnessVersion::V0, &pubkey_hash[..])
} }
/// Generates P2WSH-type of scriptPubkey with a given hash of the redeem script.
#[deprecated(since = "0.28.0", note = "use Script::new_v0_p2wsh method instead")]
pub fn new_v0_wsh(script_hash: &WScriptHash) -> Script {
Script::new_v0_p2wsh(script_hash)
}
/// Generates P2WSH-type of scriptPubkey with a given hash of the redeem script. /// Generates P2WSH-type of scriptPubkey with a given hash of the redeem script.
pub fn new_v0_p2wsh(script_hash: &WScriptHash) -> Script { pub fn new_v0_p2wsh(script_hash: &WScriptHash) -> Script {
Script::new_witness_program(WitnessVersion::V0, &script_hash[..]) Script::new_witness_program(WitnessVersion::V0, &script_hash[..])

View File

@ -712,13 +712,6 @@ impl Transaction {
.expect("cache method doesn't error") .expect("cache method doesn't error")
} }
/// Returns the "weight" of this transaction, as defined by BIP141.
#[inline]
#[deprecated(since = "0.28.0", note = "Please use `transaction::weight` instead.")]
pub fn get_weight(&self) -> usize {
self.weight()
}
/// Returns the "weight" of this transaction, as defined by BIP141. /// Returns the "weight" of this transaction, as defined by BIP141.
/// ///
/// For transactions with an empty witness, this is simply the consensus-serialized size times /// For transactions with an empty witness, this is simply the consensus-serialized size times
@ -729,26 +722,12 @@ impl Transaction {
self.scaled_size(WITNESS_SCALE_FACTOR) self.scaled_size(WITNESS_SCALE_FACTOR)
} }
/// Returns the regular byte-wise consensus-serialized size of this transaction.
#[inline]
#[deprecated(since = "0.28.0", note = "Please use `transaction::size` instead.")]
pub fn get_size(&self) -> usize {
self.size()
}
/// Returns the regular byte-wise consensus-serialized size of this transaction. /// Returns the regular byte-wise consensus-serialized size of this transaction.
#[inline] #[inline]
pub fn size(&self) -> usize { pub fn size(&self) -> usize {
self.scaled_size(1) self.scaled_size(1)
} }
/// Returns the "virtual size" (vsize) of this transaction.
#[inline]
#[deprecated(since = "0.28.0", note = "Please use `transaction::vsize` instead.")]
pub fn get_vsize(&self) -> usize {
self.vsize()
}
/// Returns the "virtual size" (vsize) of this transaction. /// Returns the "virtual size" (vsize) of this transaction.
/// ///
/// Will be `ceil(weight / 4.0)`. Note this implements the virtual size as per [`BIP141`], which /// Will be `ceil(weight / 4.0)`. Note this implements the virtual size as per [`BIP141`], which
@ -764,12 +743,6 @@ impl Transaction {
(weight + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR (weight + WITNESS_SCALE_FACTOR - 1) / WITNESS_SCALE_FACTOR
} }
/// Returns the size of this transaction excluding the witness data.
#[deprecated(since = "0.28.0", note = "Please use `transaction::strippedsize` instead.")]
pub fn get_strippedsize(&self) -> usize {
self.strippedsize()
}
/// Returns the size of this transaction excluding the witness data. /// Returns the size of this transaction excluding the witness data.
pub fn strippedsize(&self) -> usize { pub fn strippedsize(&self) -> usize {
let mut input_size = 0; let mut input_size = 0;
@ -1017,10 +990,6 @@ impl Decodable for Transaction {
} }
} }
/// Legacy Hashtype of an input's signature
#[deprecated(since = "0.28.0", note = "Please use [`EcdsaSighashType`] instead")]
pub type SigHashType = EcdsaSighashType;
#[deprecated(since = "0.30.0", note = "use crate::NonStandardSighashType instead")] #[deprecated(since = "0.30.0", note = "use crate::NonStandardSighashType instead")]
pub use crate::util::sighash::NonStandardSighashType; pub use crate::util::sighash::NonStandardSighashType;
#[deprecated(since = "0.30.0", note = "use crate::EcdsaSighashType instead")] #[deprecated(since = "0.30.0", note = "use crate::EcdsaSighashType instead")]
@ -1043,7 +1012,6 @@ mod tests {
use crate::hashes::hex::FromHex; use crate::hashes::hex::FromHex;
use crate::hash_types::*; use crate::hash_types::*;
use crate::util::sighash::NonStandardSighashType;
const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000"; const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000";
@ -1346,16 +1314,6 @@ mod tests {
} }
} }
#[test]
#[allow(deprecated)]
fn test_sighashtype_standard() {
let nonstandard_hashtype = 0x04;
// This type is not well defined, by consensus it becomes ALL
assert_eq!(EcdsaSighashType::from_u32_consensus(nonstandard_hashtype), EcdsaSighashType::All);
// But it's policy-invalid to use it!
assert_eq!(EcdsaSighashType::from_u32_standard(nonstandard_hashtype), Err(NonStandardSighashType(0x04)));
}
#[test] #[test]
#[cfg(feature="bitcoinconsensus")] #[cfg(feature="bitcoinconsensus")]
fn test_transaction_verify () { fn test_transaction_verify () {

View File

@ -98,8 +98,6 @@ pub use crate::address::{Address, AddressType};
pub use crate::blockdata::block::{self, Block, BlockHeader, BlockVersion}; pub use crate::blockdata::block::{self, Block, BlockHeader, BlockVersion};
pub use crate::blockdata::locktime::{self, absolute, relative}; pub use crate::blockdata::locktime::{self, absolute, relative};
pub use crate::blockdata::script::{self, Script}; pub use crate::blockdata::script::{self, Script};
#[allow(deprecated)]
pub use crate::blockdata::transaction::SigHashType;
pub use crate::blockdata::transaction::{self, OutPoint, Sequence, Transaction, TxIn, TxOut}; pub use crate::blockdata::transaction::{self, OutPoint, Sequence, Transaction, TxIn, TxOut};
pub use crate::blockdata::witness::{self, Witness}; pub use crate::blockdata::witness::{self, Witness};
pub use crate::blockdata::{constants, opcodes}; pub use crate::blockdata::{constants, opcodes};

View File

@ -1,134 +0,0 @@
// Written in 2018 by Andrew Poelstra <apoelstra@wpsoftware.net>
// SPDX-License-Identifier: CC0-1.0
//! BIP143 implementation.
//!
//! Implementation of BIP143 Segwit-style signatures. Should be sufficient
//! to create signatures for Segwit transactions (which should be pushed into
//! the appropriate place in the `Transaction::witness` array) or bcash
//! signatures, which are placed in the scriptSig.
//!
use core::ops::{Deref, DerefMut};
use crate::io;
use crate::hashes::Hash;
use crate::hash_types::Sighash;
use crate::blockdata::script::Script;
use crate::blockdata::transaction::Transaction;
use crate::blockdata::witness::Witness;
use crate::consensus::encode;
use crate::util::sighash::{self, EcdsaSighashType};
/// A replacement for SigHashComponents which supports all sighash modes
#[deprecated(since = "0.28.0", note = "please use [sighash::SighashCache] instead")]
pub struct SigHashCache<R: Deref<Target = Transaction>> {
cache: sighash::SighashCache<R>,
}
#[allow(deprecated)]
impl<R: Deref<Target = Transaction>> SigHashCache<R> {
/// Compute the sighash components from an unsigned transaction and auxiliary
/// in a lazy manner when required.
/// For the generated sighashes to be valid, no fields in the transaction may change except for
/// script_sig and witnesses.
pub fn new(tx: R) -> Self {
Self { cache: sighash::SighashCache::new(tx) }
}
/// Encode the BIP143 signing data for any flag type into a given object implementing a
/// std::io::Write trait.
pub fn encode_signing_data_to<Write: io::Write>(
&mut self,
writer: Write,
input_index: usize,
script_code: &Script,
value: u64,
sighash_type: EcdsaSighashType,
) -> Result<(), encode::Error> {
self.cache
.segwit_encode_signing_data_to(writer, input_index, script_code, value, sighash_type)
.expect("input_index greater than tx input len");
Ok(())
}
/// Compute the BIP143 sighash for any flag type.
pub fn signature_hash(
&mut self,
input_index: usize,
script_code: &Script,
value: u64,
sighash_type: EcdsaSighashType
) -> Sighash {
let mut enc = Sighash::engine();
self.encode_signing_data_to(&mut enc, input_index, script_code, value, sighash_type)
.expect("engines don't error");
Sighash::from_engine(enc)
}
}
#[allow(deprecated)]
impl<R: DerefMut<Target = Transaction>> SigHashCache<R> {
/// When the SigHashCache is initialized with a mutable reference to a transaction instead of a
/// regular reference, this method is available to allow modification to the witnesses.
///
/// This allows in-line signing such as
///
/// panics if `input_index` is out of bounds with respect of the number of inputs
///
/// ```
/// use bitcoin::util::bip143::SigHashCache;
/// use bitcoin::{absolute, EcdsaSighashType, Script, Transaction};
///
/// let mut tx_to_sign = Transaction { version: 2, lock_time: absolute::PackedLockTime::ZERO, input: Vec::new(), output: Vec::new() };
/// let input_count = tx_to_sign.input.len();
///
/// let mut sig_hasher = SigHashCache::new(&mut tx_to_sign);
/// for inp in 0..input_count {
/// let prevout_script = Script::new();
/// let _sighash = sig_hasher.signature_hash(inp, &prevout_script, 42, EcdsaSighashType::All);
/// // ... sign the sighash
/// sig_hasher.access_witness(inp).push(&[]);
/// }
/// ```
pub fn access_witness(&mut self, input_index: usize) -> &mut Witness {
self.cache.witness_mut(input_index).unwrap()
}
}
#[cfg(test)]
#[allow(deprecated)]
mod tests {
use crate::hash_types::Sighash;
use crate::blockdata::script::Script;
use crate::blockdata::transaction::Transaction;
use crate::consensus::encode::deserialize;
use crate::hashes::hex::FromHex;
use crate::util::sighash::SighashCache;
use super::*;
fn run_test_sighash_bip143(tx: &str, script: &str, input_index: usize, value: u64, hash_type: u32, expected_result: &str) {
let tx: Transaction = deserialize(&Vec::<u8>::from_hex(tx).unwrap()[..]).unwrap();
let script = Script::from(Vec::<u8>::from_hex(script).unwrap());
let raw_expected = Sighash::from_hex(expected_result).unwrap();
let expected_result = Sighash::from_slice(&raw_expected[..]).unwrap();
let mut cache = SighashCache::new(&tx);
let sighash_type = EcdsaSighashType::from_u32_consensus(hash_type);
let actual_result = cache.segwit_signature_hash(input_index, &script, value, sighash_type).unwrap();
assert_eq!(actual_result, expected_result);
}
#[test]
fn bip143_sighash_flags() {
// All examples generated via Bitcoin Core RPC using signrawtransactionwithwallet
// with additional debug printing
run_test_sighash_bip143("0200000001cf309ee0839b8aaa3fbc84f8bd32e9c6357e99b49bf6a3af90308c68e762f1d70100000000feffffff0288528c61000000001600146e8d9e07c543a309dcdeba8b50a14a991a658c5be0aebb0000000000160014698d8419804a5d5994704d47947889ff7620c004db000000", "76a91462744660c6b5133ddeaacbc57d2dc2d7b14d0b0688ac", 0, 1648888940, 0x01, "0a1bc2758dbb5b3a56646f8cafbf63f410cc62b77a482f8b87552683300a7711");
run_test_sighash_bip143("0200000001cf309ee0839b8aaa3fbc84f8bd32e9c6357e99b49bf6a3af90308c68e762f1d70100000000feffffff0288528c61000000001600146e8d9e07c543a309dcdeba8b50a14a991a658c5be0aebb0000000000160014698d8419804a5d5994704d47947889ff7620c004db000000", "76a91462744660c6b5133ddeaacbc57d2dc2d7b14d0b0688ac", 0, 1648888940, 0x02, "3e275ac8b084f79f756dcd535bffb615cc94a685eefa244d9031eaf22e4cec12");
run_test_sighash_bip143("0200000001cf309ee0839b8aaa3fbc84f8bd32e9c6357e99b49bf6a3af90308c68e762f1d70100000000feffffff0288528c61000000001600146e8d9e07c543a309dcdeba8b50a14a991a658c5be0aebb0000000000160014698d8419804a5d5994704d47947889ff7620c004db000000", "76a91462744660c6b5133ddeaacbc57d2dc2d7b14d0b0688ac", 0, 1648888940, 0x03, "191a08165ffacc3ea55753b225f323c35fd00d9cc0268081a4a501921fc6ec14");
run_test_sighash_bip143("0200000001cf309ee0839b8aaa3fbc84f8bd32e9c6357e99b49bf6a3af90308c68e762f1d70100000000feffffff0288528c61000000001600146e8d9e07c543a309dcdeba8b50a14a991a658c5be0aebb0000000000160014698d8419804a5d5994704d47947889ff7620c004db000000", "76a91462744660c6b5133ddeaacbc57d2dc2d7b14d0b0688ac", 0, 1648888940, 0x81, "4b6b612530f94470bbbdef18f57f2990d56b239f41b8728b9a49dc8121de4559");
run_test_sighash_bip143("0200000001cf309ee0839b8aaa3fbc84f8bd32e9c6357e99b49bf6a3af90308c68e762f1d70100000000feffffff0288528c61000000001600146e8d9e07c543a309dcdeba8b50a14a991a658c5be0aebb0000000000160014698d8419804a5d5994704d47947889ff7620c004db000000", "76a91462744660c6b5133ddeaacbc57d2dc2d7b14d0b0688ac", 0, 1648888940, 0x82, "a7e916d3acd4bb97a21e6793828279aeab02162adf8099ea4f309af81f3d5adb");
run_test_sighash_bip143("0200000001cf309ee0839b8aaa3fbc84f8bd32e9c6357e99b49bf6a3af90308c68e762f1d70100000000feffffff0288528c61000000001600146e8d9e07c543a309dcdeba8b50a14a991a658c5be0aebb0000000000160014698d8419804a5d5994704d47947889ff7620c004db000000", "76a91462744660c6b5133ddeaacbc57d2dc2d7b14d0b0688ac", 0, 1648888940, 0x83, "d9276e2a48648ddb53a4aaa58314fc2b8067c13013e1913ffb67e0988ce82c78");
}
}

View File

@ -659,12 +659,6 @@ impl ExtendedPrivKey {
} }
impl ExtendedPubKey { impl ExtendedPubKey {
/// Derives a public key from a private key
#[deprecated(since = "0.28.0", note = "use ExtendedPubKey::from_priv")]
pub fn from_private<C: secp256k1::Signing>(secp: &Secp256k1<C>, sk: &ExtendedPrivKey) -> ExtendedPubKey {
ExtendedPubKey::from_priv(secp, sk)
}
/// Derives a public key from a private key /// Derives a public key from a private key
pub fn from_priv<C: secp256k1::Signing>(secp: &Secp256k1<C>, sk: &ExtendedPrivKey) -> ExtendedPubKey { pub fn from_priv<C: secp256k1::Signing>(secp: &Secp256k1<C>, sk: &ExtendedPrivKey) -> ExtendedPubKey {
ExtendedPubKey { ExtendedPubKey {

View File

@ -12,7 +12,6 @@ pub mod schnorr;
pub mod amount; pub mod amount;
pub mod base58; pub mod base58;
pub mod bip32; pub mod bip32;
pub mod bip143;
pub mod bip152; pub mod bip152;
pub mod hash; pub mod hash;
pub mod merkleblock; pub mod merkleblock;

View File

@ -11,29 +11,22 @@ use core::fmt;
use bitcoin_internals::write_err; use bitcoin_internals::write_err;
pub use secp256k1::{self, constants, Secp256k1, KeyPair, XOnlyPublicKey, Verification};
use crate::prelude::*; use crate::prelude::*;
use secp256k1::{self, Secp256k1, Verification, constants};
use crate::util::taproot::{TapBranchHash, TapTweakHash}; use crate::util::taproot::{TapBranchHash, TapTweakHash};
use crate::SchnorrSighashType; use crate::SchnorrSighashType;
/// Deprecated re-export of [`secp256k1::XOnlyPublicKey`]
#[deprecated(since = "0.28.0", note = "Please use `util::key::XOnlyPublicKey` instead")]
pub type XOnlyPublicKey = secp256k1::XOnlyPublicKey;
/// Deprecated re-export of [`secp256k1::KeyPair`]
#[deprecated(since = "0.28.0", note = "Please use `util::key::KeyPair` instead")]
pub type KeyPair = secp256k1::KeyPair;
/// Untweaked BIP-340 X-coord-only public key /// Untweaked BIP-340 X-coord-only public key
pub type UntweakedPublicKey = crate::XOnlyPublicKey; pub type UntweakedPublicKey = XOnlyPublicKey;
/// Tweaked BIP-340 X-coord-only public key /// Tweaked BIP-340 X-coord-only public key
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
#[cfg_attr(feature = "serde", serde(transparent))] #[cfg_attr(feature = "serde", serde(transparent))]
pub struct TweakedPublicKey(crate::XOnlyPublicKey); pub struct TweakedPublicKey(XOnlyPublicKey);
impl fmt::LowerHex for TweakedPublicKey { impl fmt::LowerHex for TweakedPublicKey {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
@ -48,14 +41,14 @@ impl fmt::Display for TweakedPublicKey {
} }
/// Untweaked BIP-340 key pair /// Untweaked BIP-340 key pair
pub type UntweakedKeyPair = crate::KeyPair; pub type UntweakedKeyPair = KeyPair;
/// Tweaked BIP-340 key pair /// Tweaked BIP-340 key pair
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] #[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
#[cfg_attr(feature = "serde", serde(crate = "actual_serde"))] #[cfg_attr(feature = "serde", serde(crate = "actual_serde"))]
#[cfg_attr(feature = "serde", serde(transparent))] #[cfg_attr(feature = "serde", serde(transparent))]
pub struct TweakedKeyPair(crate::KeyPair); pub struct TweakedKeyPair(KeyPair);
/// A trait for tweaking BIP340 key types (x-only public keys and key pairs). /// A trait for tweaking BIP340 key types (x-only public keys and key pairs).
pub trait TapTweak { pub trait TapTweak {
@ -131,7 +124,7 @@ impl TapTweak for UntweakedKeyPair {
/// # Returns /// # Returns
/// The tweaked key and its parity. /// The tweaked key and its parity.
fn tap_tweak<C: Verification>(self, secp: &Secp256k1<C>, merkle_root: Option<TapBranchHash>) -> TweakedKeyPair { fn tap_tweak<C: Verification>(self, secp: &Secp256k1<C>, merkle_root: Option<TapBranchHash>) -> TweakedKeyPair {
let (pubkey, _parity) = crate::XOnlyPublicKey::from_keypair(&self); let (pubkey, _parity) = XOnlyPublicKey::from_keypair(&self);
let tweak = TapTweakHash::from_key_and_tweak(pubkey, merkle_root).to_scalar(); let tweak = TapTweakHash::from_key_and_tweak(pubkey, merkle_root).to_scalar();
let tweaked = self.add_xonly_tweak(secp, &tweak).expect("Tap tweak failed"); let tweaked = self.add_xonly_tweak(secp, &tweak).expect("Tap tweak failed");
TweakedKeyPair(tweaked) TweakedKeyPair(tweaked)
@ -149,12 +142,12 @@ impl TweakedPublicKey {
/// This method is dangerous and can lead to loss of funds if used incorrectly. /// This method is dangerous and can lead to loss of funds if used incorrectly.
/// Specifically, in multi-party protocols a peer can provide a value that allows them to steal. /// Specifically, in multi-party protocols a peer can provide a value that allows them to steal.
#[inline] #[inline]
pub fn dangerous_assume_tweaked(key: crate::XOnlyPublicKey) -> TweakedPublicKey { pub fn dangerous_assume_tweaked(key: XOnlyPublicKey) -> TweakedPublicKey {
TweakedPublicKey(key) TweakedPublicKey(key)
} }
/// Returns the underlying public key. /// Returns the underlying public key.
pub fn to_inner(self) -> crate::XOnlyPublicKey { pub fn to_inner(self) -> XOnlyPublicKey {
self.0 self.0
} }
@ -174,32 +167,32 @@ impl TweakedKeyPair {
/// This method is dangerous and can lead to loss of funds if used incorrectly. /// This method is dangerous and can lead to loss of funds if used incorrectly.
/// Specifically, in multi-party protocols a peer can provide a value that allows them to steal. /// Specifically, in multi-party protocols a peer can provide a value that allows them to steal.
#[inline] #[inline]
pub fn dangerous_assume_tweaked(pair: crate::KeyPair) -> TweakedKeyPair { pub fn dangerous_assume_tweaked(pair: KeyPair) -> TweakedKeyPair {
TweakedKeyPair(pair) TweakedKeyPair(pair)
} }
/// Returns the underlying key pair /// Returns the underlying key pair
#[inline] #[inline]
#[deprecated(since = "0.29.0", note = "use to_inner instead")] #[deprecated(since = "0.29.0", note = "use to_inner instead")]
pub fn into_inner(self) -> crate::KeyPair { pub fn into_inner(self) -> KeyPair {
self.0 self.0
} }
/// Returns the underlying key pair. /// Returns the underlying key pair.
#[inline] #[inline]
pub fn to_inner(self) -> crate::KeyPair { pub fn to_inner(self) -> KeyPair {
self.0 self.0
} }
} }
impl From<TweakedPublicKey> for crate::XOnlyPublicKey { impl From<TweakedPublicKey> for XOnlyPublicKey {
#[inline] #[inline]
fn from(pair: TweakedPublicKey) -> Self { fn from(pair: TweakedPublicKey) -> Self {
pair.0 pair.0
} }
} }
impl From<TweakedKeyPair> for crate::KeyPair { impl From<TweakedKeyPair> for KeyPair {
#[inline] #[inline]
fn from(pair: TweakedKeyPair) -> Self { fn from(pair: TweakedKeyPair) -> Self {
pair.0 pair.0

View File

@ -363,12 +363,6 @@ impl EcdsaSighashType {
} }
} }
/// Creates a [`EcdsaSighashType`] from a raw `u32`.
#[deprecated(since="0.28.0", note="please use `from_consensus`")]
pub fn from_u32_consensus(n: u32) -> EcdsaSighashType {
EcdsaSighashType::from_consensus(n)
}
/// Creates a [`EcdsaSighashType`] from a raw `u32`. /// Creates a [`EcdsaSighashType`] from a raw `u32`.
/// ///
/// **Note**: this replicates consensus behaviour, for current standardness rules correctness /// **Note**: this replicates consensus behaviour, for current standardness rules correctness
@ -398,12 +392,6 @@ impl EcdsaSighashType {
} }
} }
/// Creates a [`EcdsaSighashType`] from a raw `u32`.
#[deprecated(since="0.28.0", note="please use `from_standard`")]
pub fn from_u32_standard(n: u32) -> Result<EcdsaSighashType, NonStandardSighashType> {
EcdsaSighashType::from_standard(n)
}
/// Creates a [`EcdsaSighashType`] from a raw `u32`. /// Creates a [`EcdsaSighashType`] from a raw `u32`.
/// ///
/// # Errors /// # Errors

View File

@ -8,7 +8,7 @@ fn do_test(data: &[u8]) {
let ser = bitcoin::consensus::encode::serialize(&tx); let ser = bitcoin::consensus::encode::serialize(&tx);
assert_eq!(&ser[..], data); assert_eq!(&ser[..], data);
let len = ser.len(); let len = ser.len();
let calculated_weight = tx.get_weight(); let calculated_weight = tx.weight();
for input in &mut tx.input { for input in &mut tx.input {
input.witness = bitcoin::blockdata::witness::Witness::default(); input.witness = bitcoin::blockdata::witness::Witness::default();
} }