res.insert("crate::c_types::EightU16s".to_owned());
res.insert("crate::c_types::SecretKey".to_owned());
res.insert("crate::c_types::PublicKey".to_owned());
+ res.insert("crate::c_types::TweakedPublicKey".to_owned());
res.insert("crate::c_types::Transaction".to_owned());
res.insert("crate::c_types::Witness".to_owned());
res.insert("crate::c_types::WitnessVersion".to_owned());
"core::num::NonZeroU8" => Some("u8"),
"secp256k1::PublicKey"|"bitcoin::secp256k1::PublicKey" => Some("crate::c_types::PublicKey"),
+ "bitcoin::key::TweakedPublicKey" => Some("crate::c_types::TweakedPublicKey"),
"bitcoin::secp256k1::ecdsa::Signature" => Some("crate::c_types::ECDSASignature"),
"bitcoin::secp256k1::schnorr::Signature" => Some("crate::c_types::SchnorrSignature"),
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature"),
"bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" if is_ref => Some("&"),
"bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" => Some(""),
+ "bitcoin::key::TweakedPublicKey" if is_ref => Some("&"),
+ "bitcoin::key::TweakedPublicKey" => Some(""),
"bitcoin::secp256k1::ecdsa::Signature"|"bitcoin::secp256k1::schnorr::Signature" if is_ref => Some("&"),
"bitcoin::secp256k1::ecdsa::Signature"|"bitcoin::secp256k1::schnorr::Signature" => Some(""),
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(""),
"core::num::NonZeroU8" => Some(").expect(\"Value must be non-zero\")"),
"bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" => Some(".into_rust()"),
+ "bitcoin::key::TweakedPublicKey" => Some(".into_rust()"),
"bitcoin::secp256k1::ecdsa::Signature"|"bitcoin::secp256k1::schnorr::Signature" => Some(".into_rust()"),
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(".into_rust()"),
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(".into_rust()"),
"u128" => Some(""),
"bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" => Some("crate::c_types::PublicKey::from_rust(&"),
+ "bitcoin::key::TweakedPublicKey" => Some("crate::c_types::TweakedPublicKey::from_rust(&"),
"bitcoin::secp256k1::ecdsa::Signature" => Some("crate::c_types::ECDSASignature::from_rust(&"),
"bitcoin::secp256k1::schnorr::Signature" => Some("crate::c_types::SchnorrSignature::from_rust(&"),
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some("crate::c_types::RecoverableSignature::from_rust(&"),
"u128" => Some(".into()"),
"bitcoin::secp256k1::PublicKey"|"secp256k1::PublicKey" => Some(")"),
+ "bitcoin::key::TweakedPublicKey" => Some(")"),
"bitcoin::secp256k1::ecdsa::Signature"|"bitcoin::secp256k1::schnorr::Signature" => Some(")"),
"bitcoin::secp256k1::ecdsa::RecoverableSignature" => Some(")"),
"bitcoin::secp256k1::SecretKey" if !is_ref => Some(")"),
use bitcoin::Witness as BitcoinWitness;
use bitcoin::address;
use bitcoin::address::WitnessProgram as BitcoinWitnessProgram;
+use bitcoin::key::TweakedPublicKey as BitcoinTweakedPublicKey;
+use bitcoin::key::XOnlyPublicKey;
use bitcoin::hashes::Hash;
use bitcoin::secp256k1::PublicKey as SecpPublicKey;
use bitcoin::secp256k1::SecretKey as SecpSecretKey;
pub(crate) fn null() -> Self { Self { compressed_form: [0; 33] } }
}
+#[derive(Clone)]
+#[repr(C)]
+/// Represents a tweaked X-only public key as required for BIP 340 (Taproot).
+pub struct TweakedPublicKey {
+ /// The bytes of the public key X coordinate
+ pub x_coordinate: [u8; 32],
+}
+impl TweakedPublicKey {
+ pub(crate) fn from_rust(pk: &BitcoinTweakedPublicKey) -> Self {
+ Self {
+ x_coordinate: pk.serialize(),
+ }
+ }
+ pub(crate) fn into_rust(&self) -> BitcoinTweakedPublicKey {
+ let xonly_key = XOnlyPublicKey::from_slice(&self.x_coordinate).unwrap();
+ BitcoinTweakedPublicKey::dangerous_assume_tweaked(xonly_key)
+ }
+}
+
#[repr(C)]
#[derive(Clone)]
/// Represents a valid secp256k1 secret key serialized as a 32 byte array.