[][src]Module magical::wallet::signer

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 Signer for CustomSigner {
    fn sign(
        &self,
        psbt: &mut psbt::PartiallySignedTransaction,
        input_index: Option<usize>,
    ) -> Result<(), SignerError> {
        let input_index = input_index.ok_or(SignerError::InputIndexOutOfRange)?;
        self.device.sign_input(psbt, input_index)?;

        Ok(())
    }

    fn sign_whole_tx(&self) -> bool {
        false
    }
}

let custom_signer = CustomSigner::connect();

let descriptor = "wpkh(tpubD6NzVbkrYhZ4Xferm7Pz4VnjdcDPFyjVu5K4iZXQ4pVN8Cks4pHVowTBXBKRhX64pkRyJZJN5xAKj4UDNnLPb5p2sSKXhewoYx5GbTdUFWq/*)";
let mut wallet: OfflineWallet<_> = Wallet::new_offline(descriptor, None, Network::Testnet, MemoryDatabase::default())?;
wallet.add_signer(
    ScriptType::External,
    Fingerprint::from_str("e30f11b8").unwrap().into(),
    SignerOrdering(200),
    Arc::new(Box::new(custom_signer))
);

Structs

SignerOrdering

Defines the order in which signers are called

SignersContainer

Container for multiple signers

Enums

SignerError

Signing error

SignerId

Identifier of a signer in the SignersContainers. Used as a key to find the right signer among multiple of them

Traits

Signer

Trait for signers