Coldcard

Struct Coldcard 

Source
pub struct Coldcard { /* private fields */ }
Expand description

Connected and initialized Coldcard device ready for use.

Implementations§

Source§

impl Coldcard

Source

pub fn open( api: impl AsRef<HidApi>, sn: impl AsRef<str>, opts: Option<Options>, ) -> Result<(Self, Option<XpubInfo>), Error>

Opens a Coldcard with a particular serial number and optionally some options. If no serial number is known, use the Api::detect() method to detect connected Coldcard devices. Returns an optional XpubInfo in case the device is already initialized with a secret.

Source

pub fn check_mitm(&mut self, expected_xpub: &str) -> Result<bool, Error>

Checks if the communication line is undergoing a MITM attack. Returns Ok(true) if MITM is in progress or Ok(false) if not.

Source

pub fn upload<F: FnMut(usize, usize)>( &mut self, data: &[u8], progress: F, ) -> Result<[u8; 32], Error>

Uploads a file and verifies the checksum. Returns the checksum calculated by the device. Fails on checksum verification failure.

progress is a closure whose first argument is the number of bytes that have been uploaded and the second one is the total number of bytes.

Source

pub fn download( &mut self, length: u32, checksum: &[u8], file_number: FileNo, ) -> Result<Vec<u8>, Error>

Downloads a single file with a known checksum. Fails on checksum verification failure.

Source

pub fn resync(&mut self) -> Result<(), Error>

Resyncs the Coldcard by sending a magic packet and discarding data until it is ready for use again. Normally no need to use this.

Source

pub fn address( &mut self, subpath: DerivationPath, addr_fmt: AddressFormat, ) -> Result<String, Error>

Gets an address given a derivation path and address format.

Source

pub fn bag_number(&mut self) -> Result<String, Error>

Gets the bag number the Coldcard arrived in.

Source

pub fn bip388_policy_get( &mut self, descriptor_name: DescriptorName, ) -> Result<Option<String>, Error>

Gets the BIP-0388 wallet policy of a given wallet

Source

pub fn blockchain(&mut self) -> Result<String, Error>

Gets the name of the blockchain the Colcard is set to operate on.

Source

pub fn create_username( &mut self, username: Username, auth_mode: AuthMode, show_qr: bool, ) -> Result<Option<String>, Error>

Creates a new username on the Coldcard. If a QR code is requested, the generated secret is displayed only on the device. Otherwise it is returned in the Ok(...) variant.

Source

pub fn delete_miniscript( &mut self, descriptor_name: DescriptorName, ) -> Result<(), Error>

Delete a registered miniscript descriptor

Source

pub fn delete_username(&mut self, username: Username) -> Result<(), Error>

Deletes a username, if one exists on the Coldcard. Returns Ok(()) even if one did not exist.

Source

pub fn get_backup(&mut self) -> Result<Option<Backup>, Error>

Gets a backup from the Coldcard, if one was previously initiated. If the result is Ok(None), it can mean that the user has not approved yet or the backup has not completed.

Source

pub fn get_passphrase_done(&mut self) -> Result<Option<String>, Error>

Gets the new xpub from the Coldcard, upon setting a passphrase. If the result is Ok(None), it can mean that the user has not approved yet.

Source

pub fn get_signed_message(&mut self) -> Result<Option<SignedMessage>, Error>

Gets a signed message from the Coldcard, if any. If the result is Ok(None), it can mean that the user has not approved yet.

Source

pub fn get_signed_tx(&mut self) -> Result<Option<Vec<u8>>, Error>

Gets a signed transaction from the Coldcard, if one was previously created. If the result is Ok(None), it can mean that the user has not approved yet or the signing has not completed.

Source

pub fn hsm_start(&mut self, policy: Option<&[u8]>) -> Result<(), Error>

Starts the HSM mode given a policy. If the policy is None, starts the existing policy already on the device.

Source

pub fn hsm_policy(&mut self) -> Result<String, Error>

Gets the HSM policy file in the JSON format.

Source

pub fn locker(&mut self) -> Result<Vec<u8>, Error>

Gets the value in the storage locker (HSM use).

Source

pub fn logout(self) -> Result<(), Error>

Securely logs out of the Coldcard. Requires a power cycle to use again.

Source

pub fn miniscript_address( &mut self, descriptor_name: DescriptorName, change: bool, index: u32, ) -> Result<String, Error>

Show miniscript address.

Source

pub fn miniscript_enroll(&mut self, descriptor: &[u8]) -> Result<(), Error>

Enroll miniscript file.

Source

pub fn miniscript_get( &mut self, descriptor_name: DescriptorName, ) -> Result<Option<String>, Error>

Get registered descriptor by name.

Source

pub fn miniscript_list(&mut self) -> Result<Vec<String>, Error>

List miniscript descriptors registered on the device

Source

pub fn multisig_check( &mut self, m: u32, n: u32, xfp_xor: u32, ) -> Result<bool, Error>

Is there a wallet already that matches M+N and xor(*xfps)?

Source

pub fn multisig_enroll( &mut self, length: u32, file_sha: [u8; 32], ) -> Result<(), Error>

Start multisig enrollment (multisig details must already be uploaded, this just starts the approval process).

Source

pub fn reboot(self) -> Result<(), Error>

Reboots the Coldcard.

Source

pub fn restore_backup( &mut self, data: &[u8], custom_pwd: bool, plaintext: bool, tmp: bool, ) -> Result<(), Error>

Restore a backup

Source

pub fn serial_number(&self) -> &str

Returns the serial number of this Coldcard.

Source

pub fn set_passphrase(&mut self, passphrase: Passphrase) -> Result<(), Error>

Sets a BIP39 passphrase. Provide an empty passphrase to remove. This does not immediately return the new xpub, use get_passphrase_done for that.

Source

pub fn show_p2sh_address( &mut self, min_signers: u8, xfp_paths: Vec<XfpPath>, redeem_script: RedeemScript, address_format: AddressFormat, ) -> Result<String, Error>

Shows a P2SH address for a multisig scenario. The order of xfp paths must match the order of pubkeys in redeem script (after BIP67 sort). This allows for duplicate xfp values.

Source

pub fn sign_message( &mut self, raw_msg: Message, subpath: Option<DerivationPath>, addr_fmt: AddressFormat, ) -> Result<(), Error>

Initiates message signing and causes the Coldcard to prompt the user to confirm. This does not immediately return a signature, use get_signed_message for that.

Source

pub fn sign_psbt( &mut self, psbt: &[u8], sign_mode: SignMode, ) -> Result<(), Error>

Initiates PSBT signing and causes the Coldcard to prompt the user to confirm. This does not immediately return a signed tx, use get_signed_tx for that.

Source

pub fn sign_psbt_miniscript( &mut self, psbt: &[u8], sign_mode: SignMode, descriptor_name: Option<DescriptorName>, ) -> Result<(), Error>

Initiates PSBT signing for a miniscript wallet and causes the Coldcard to prompt the user to confirm. This does not immediately return a signed tx, use get_signed_tx for that.

Source

pub fn start_backup(&mut self) -> Result<(), Error>

Initiates a backup and causes the Coldcard to prompt the user to confirm. This does not immediately return a backup, use get_backup for that.

Source

pub fn test(&mut self) -> Result<(), Error>

Tests the Coldcard and the USB connection by sending predefined data packets.

Source

pub fn upgrade<F: FnMut(usize, usize)>( &mut self, firmware: Firmware, progress: F, ) -> Result<(), Error>

Upgrades the firmware on the Coldcard. It does not reboot automatically. Reboot must be called to finish the process.

progress is a closure whose first argument is the number of bytes that have been uploaded and the second one is the total number of bytes.

Source

pub fn user_auth( &mut self, username: Username, token: AuthToken, totp_time: u32, ) -> Result<(), Error>

Authenticates a user (for HSM).

Source

pub fn version(&mut self) -> Result<String, Error>

Gets the static version string from the Coldcard.

Source

pub fn xpub(&mut self, path: Option<DerivationPath>) -> Result<String, Error>

Gets a B58 encoded xpub at some derivation path. Master level if None.

Trait Implementations§

Source§

impl Debug for Coldcard

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V