Module bdk::wallet::signer

source ·
Expand description

Generalized signers

This module provides the ability to add customized signers to a Wallet through the Wallet::add_signer function.

#[derive(Debug)]
struct CustomSigner {
    device: CustomHSM,
}

impl CustomSigner {
    fn connect() -> Self {
        CustomSigner { device: CustomHSM::connect() }
    }
}

impl SignerCommon for CustomSigner {
    fn id(&self, _secp: &Secp256k1<All>) -> SignerId {
        self.device.get_id()
    }
}

impl InputSigner for CustomSigner {
    fn sign_input(
        &self,
        psbt: &mut Psbt,
        input_index: usize,
        _sign_options: &SignOptions,
        _secp: &Secp256k1<All>,
    ) -> Result<(), SignerError> {
        self.device.hsm_sign_input(psbt, input_index)?;

        Ok(())
    }
}

let custom_signer = CustomSigner::connect();

let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)";
let mut wallet = Wallet::new_no_persist(descriptor, None, Network::Testnet)?;
wallet.add_signer(
    KeychainKind::External,
    SignerOrdering(200),
    Arc::new(custom_signer)
);

Structs

Options for a software signer
Defines the order in which signers are called
Wrapper to pair a signer with its context
Container for multiple signers

Enums

Signing context
Signing error
Identifier of a signer in the SignersContainers. Used as a key to find the right signer among multiple of them
Customize which taproot script-path leaves the signer should sign.

Traits

PSBT Input signer
Common signer methods