pub use utils::IsDust;
use address_validator::AddressValidator;
-use signer::{Signer, SignerId, SignerOrdering, SignersContainer};
+use signer::{Signer, SignerOrdering, SignersContainer};
use tx_builder::{BumpFee, CreateTx, FeePolicy, TxBuilder, TxBuilderContext};
use utils::{
check_nlocktime, check_nsequence_rbf, descriptor_to_pk_ctx, After, Older, SecpCtx,
pub fn add_signer(
&mut self,
keychain: KeychainKind,
- id: SignerId,
ordering: SignerOrdering,
signer: Arc<dyn Signer>,
) {
KeychainKind::Internal => Arc::make_mut(&mut self.change_signers),
};
- signers.add_external(id, ordering, signer);
+ signers.add_external(signer.id(&self.secp), ordering, signer);
}
/// Add an address validator
//! # use bitcoin::secp256k1::{Secp256k1, All};
//! # use bitcoin::*;
//! # use bitcoin::util::psbt;
-//! # use bitcoin::util::bip32::Fingerprint;
//! # use bdk::signer::*;
//! # use bdk::database::*;
//! # use bdk::*;
//! # fn connect() -> Self {
//! # CustomHSM
//! # }
+//! # fn get_id(&self) -> SignerId {
+//! # SignerId::Dummy(0)
+//! # }
//! # }
//! #[derive(Debug)]
//! struct CustomSigner {
//! Ok(())
//! }
//!
+//! fn id(&self, _secp: &Secp256k1<All>) -> SignerId {
+//! self.device.get_id()
+//! }
+//!
//! fn sign_whole_tx(&self) -> bool {
//! false
//! }
//! let mut wallet = Wallet::new_offline(descriptor, None, Network::Testnet, MemoryDatabase::default())?;
//! wallet.add_signer(
//! KeychainKind::External,
-//! Fingerprint::from_str("e30f11b8").unwrap().into(),
//! SignerOrdering(200),
//! Arc::new(custom_signer)
//! );
PkHash(hash160::Hash),
/// The fingerprint of a BIP32 extended key
Fingerprint(Fingerprint),
+ /// Dummy identifier
+ Dummy(u64),
}
impl From<hash160::Hash> for SignerId {
/// input individually
fn sign_whole_tx(&self) -> bool;
+ /// Return the [`SignerId`] for this signer
+ ///
+ /// The [`SignerId`] can be used to lookup a signer in the [`Wallet`](crate::Wallet)'s signers map or to
+ /// compare two signers.
+ fn id(&self, secp: &SecpCtx) -> SignerId;
+
/// Return the secret key for the signer
///
/// This is used internally to reconstruct the original descriptor that may contain secrets.
false
}
+ fn id(&self, secp: &SecpCtx) -> SignerId {
+ SignerId::from(self.root_fingerprint(&secp))
+ }
+
fn descriptor_secret_key(&self) -> Option<DescriptorSecretKey> {
Some(DescriptorSecretKey::XPrv(self.clone()))
}
false
}
+ fn id(&self, secp: &SecpCtx) -> SignerId {
+ SignerId::from(self.public_key(secp).to_pubkeyhash())
+ }
+
fn descriptor_secret_key(&self) -> Option<DescriptorSecretKey> {
Some(DescriptorSecretKey::SinglePriv(DescriptorSinglePriv {
key: *self,
for (_, secret) in keymap {
match secret {
DescriptorSecretKey::SinglePriv(private_key) => container.add_external(
- SignerId::from(
- private_key
- .key
- .public_key(&Secp256k1::signing_only())
- .to_pubkeyhash(),
- ),
+ SignerId::from(private_key.key.public_key(&secp).to_pubkeyhash()),
SignerOrdering::default(),
Arc::new(private_key.key),
),
Ok(())
}
+ fn id(&self, _secp: &SecpCtx) -> SignerId {
+ SignerId::Dummy(42)
+ }
+
fn sign_whole_tx(&self) -> bool {
true
}