Use Keypair instead of KeyPair in identifiers
In preparation for updating the secp dependency to v0.28.0, which includes a change of `KeyPair` to `Keypair`, change our identifier usage to indicate that "keypair" is a single word. Deprecate the old forms.
This commit is contained in:
parent
2095faed71
commit
818a3c5424
|
@ -507,17 +507,27 @@ impl fmt::Display for TweakedPublicKey {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Untweaked BIP-340 key pair
|
/// Untweaked BIP-340 key pair
|
||||||
pub type UntweakedKeyPair = KeyPair;
|
#[deprecated(since = "0.31.0", note = "use UntweakedKeypair instead")]
|
||||||
|
#[allow(deprecated)]
|
||||||
|
pub type UntweakedKeyPair = UntweakedKeypair;
|
||||||
|
|
||||||
|
/// Untweaked BIP-340 key pair
|
||||||
|
pub type UntweakedKeypair = KeyPair;
|
||||||
|
|
||||||
|
/// Tweaked BIP-340 key pair
|
||||||
|
#[deprecated(since = "0.31.0", note = "use TweakedKeypair instead")]
|
||||||
|
#[allow(deprecated)]
|
||||||
|
pub type TweakedKeyPair = TweakedKeypair;
|
||||||
|
|
||||||
/// Tweaked BIP-340 key pair
|
/// Tweaked BIP-340 key pair
|
||||||
///
|
///
|
||||||
/// # Examples
|
/// # Examples
|
||||||
/// ```
|
/// ```
|
||||||
/// # #[cfg(feature = "rand-std")] {
|
/// # #[cfg(feature = "rand-std")] {
|
||||||
/// # use bitcoin::key::{KeyPair, TweakedKeyPair, TweakedPublicKey};
|
/// # use bitcoin::key::{KeyPair, TweakedKeypair, TweakedPublicKey};
|
||||||
/// # use bitcoin::secp256k1::{rand, Secp256k1};
|
/// # use bitcoin::secp256k1::{rand, Secp256k1};
|
||||||
/// # let secp = Secp256k1::new();
|
/// # let secp = Secp256k1::new();
|
||||||
/// # let keypair = TweakedKeyPair::dangerous_assume_tweaked(KeyPair::new(&secp, &mut rand::thread_rng()));
|
/// # let keypair = TweakedKeypair::dangerous_assume_tweaked(KeyPair::new(&secp, &mut rand::thread_rng()));
|
||||||
/// // There are various conversion methods available to get a tweaked pubkey from a tweaked keypair.
|
/// // There are various conversion methods available to get a tweaked pubkey from a tweaked keypair.
|
||||||
/// let (_pk, _parity) = keypair.public_parts();
|
/// let (_pk, _parity) = keypair.public_parts();
|
||||||
/// let _pk = TweakedPublicKey::from_keypair(keypair);
|
/// let _pk = TweakedPublicKey::from_keypair(keypair);
|
||||||
|
@ -528,7 +538,7 @@ pub type UntweakedKeyPair = KeyPair;
|
||||||
#[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(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 {
|
||||||
|
@ -593,9 +603,9 @@ impl TapTweak for UntweakedPublicKey {
|
||||||
fn dangerous_assume_tweaked(self) -> TweakedPublicKey { TweakedPublicKey(self) }
|
fn dangerous_assume_tweaked(self) -> TweakedPublicKey { TweakedPublicKey(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TapTweak for UntweakedKeyPair {
|
impl TapTweak for UntweakedKeypair {
|
||||||
type TweakedAux = TweakedKeyPair;
|
type TweakedAux = TweakedKeypair;
|
||||||
type TweakedKey = TweakedKeyPair;
|
type TweakedKey = TweakedKeypair;
|
||||||
|
|
||||||
/// Tweaks private and public keys within an untweaked [`KeyPair`] with corresponding public key
|
/// Tweaks private and public keys within an untweaked [`KeyPair`] with corresponding public key
|
||||||
/// value and optional script tree merkle root.
|
/// value and optional script tree merkle root.
|
||||||
|
@ -613,20 +623,20 @@ impl TapTweak for UntweakedKeyPair {
|
||||||
self,
|
self,
|
||||||
secp: &Secp256k1<C>,
|
secp: &Secp256k1<C>,
|
||||||
merkle_root: Option<TapNodeHash>,
|
merkle_root: Option<TapNodeHash>,
|
||||||
) -> TweakedKeyPair {
|
) -> TweakedKeypair {
|
||||||
let (pubkey, _parity) = 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn dangerous_assume_tweaked(self) -> TweakedKeyPair { TweakedKeyPair(self) }
|
fn dangerous_assume_tweaked(self) -> TweakedKeypair { TweakedKeypair(self) }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TweakedPublicKey {
|
impl TweakedPublicKey {
|
||||||
/// Returns the [`TweakedPublicKey`] for `keypair`.
|
/// Returns the [`TweakedPublicKey`] for `keypair`.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn from_keypair(keypair: TweakedKeyPair) -> Self {
|
pub fn from_keypair(keypair: TweakedKeypair) -> Self {
|
||||||
let (xonly, _parity) = keypair.0.x_only_public_key();
|
let (xonly, _parity) = keypair.0.x_only_public_key();
|
||||||
TweakedPublicKey(xonly)
|
TweakedPublicKey(xonly)
|
||||||
}
|
}
|
||||||
|
@ -651,20 +661,20 @@ impl TweakedPublicKey {
|
||||||
pub fn serialize(&self) -> [u8; constants::SCHNORR_PUBLIC_KEY_SIZE] { self.0.serialize() }
|
pub fn serialize(&self) -> [u8; constants::SCHNORR_PUBLIC_KEY_SIZE] { self.0.serialize() }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TweakedKeyPair {
|
impl TweakedKeypair {
|
||||||
/// Creates a new [`TweakedKeyPair`] from a [`KeyPair`]. No tweak is applied, consider
|
/// Creates a new [`TweakedKeypair`] from a [`KeyPair`]. No tweak is applied, consider
|
||||||
/// calling `tap_tweak` on an [`UntweakedKeyPair`] instead of using this constructor.
|
/// calling `tap_tweak` on an [`UntweakedKeyPair`] instead of using this constructor.
|
||||||
///
|
///
|
||||||
/// 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: KeyPair) -> TweakedKeyPair { TweakedKeyPair(pair) }
|
pub fn dangerous_assume_tweaked(pair: KeyPair) -> TweakedKeypair { TweakedKeypair(pair) }
|
||||||
|
|
||||||
/// Returns the underlying key pair.
|
/// Returns the underlying key pair.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn to_inner(self) -> KeyPair { self.0 }
|
pub fn to_inner(self) -> KeyPair { self.0 }
|
||||||
|
|
||||||
/// Returns the [`TweakedPublicKey`] and its [`Parity`] for this [`TweakedKeyPair`].
|
/// Returns the [`TweakedPublicKey`] and its [`Parity`] for this [`TweakedKeypair`].
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn public_parts(&self) -> (TweakedPublicKey, Parity) {
|
pub fn public_parts(&self) -> (TweakedPublicKey, Parity) {
|
||||||
let (xonly, parity) = self.0.x_only_public_key();
|
let (xonly, parity) = self.0.x_only_public_key();
|
||||||
|
@ -677,14 +687,14 @@ impl From<TweakedPublicKey> for XOnlyPublicKey {
|
||||||
fn from(pair: TweakedPublicKey) -> Self { pair.0 }
|
fn from(pair: TweakedPublicKey) -> Self { pair.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TweakedKeyPair> for KeyPair {
|
impl From<TweakedKeypair> for KeyPair {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(pair: TweakedKeyPair) -> Self { pair.0 }
|
fn from(pair: TweakedKeypair) -> Self { pair.0 }
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<TweakedKeyPair> for TweakedPublicKey {
|
impl From<TweakedKeypair> for TweakedPublicKey {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn from(pair: TweakedKeyPair) -> Self { TweakedPublicKey::from_keypair(pair) }
|
fn from(pair: TweakedKeypair) -> Self { TweakedPublicKey::from_keypair(pair) }
|
||||||
}
|
}
|
||||||
/// A key-related error.
|
/// A key-related error.
|
||||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||||
|
|
Loading…
Reference in New Issue