pub struct Coldcard { /* private fields */ }Expand description
Connected and initialized Coldcard device ready for use.
Implementations§
Source§impl Coldcard
impl Coldcard
Sourcepub fn open(
api: impl AsRef<HidApi>,
sn: impl AsRef<str>,
opts: Option<Options>,
) -> Result<(Self, Option<XpubInfo>), Error>
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.
Sourcepub fn check_mitm(&mut self, expected_xpub: &str) -> Result<bool, Error>
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.
Sourcepub fn upload<F: FnMut(usize, usize)>(
&mut self,
data: &[u8],
progress: F,
) -> Result<[u8; 32], Error>
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.
Sourcepub fn download(
&mut self,
length: u32,
checksum: &[u8],
file_number: FileNo,
) -> Result<Vec<u8>, Error>
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.
Sourcepub fn resync(&mut self) -> Result<(), Error>
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.
Sourcepub fn address(
&mut self,
subpath: DerivationPath,
addr_fmt: AddressFormat,
) -> Result<String, Error>
pub fn address( &mut self, subpath: DerivationPath, addr_fmt: AddressFormat, ) -> Result<String, Error>
Gets an address given a derivation path and address format.
Sourcepub fn bag_number(&mut self) -> Result<String, Error>
pub fn bag_number(&mut self) -> Result<String, Error>
Gets the bag number the Coldcard arrived in.
Sourcepub fn bip388_policy_get(
&mut self,
descriptor_name: DescriptorName,
) -> Result<Option<String>, Error>
pub fn bip388_policy_get( &mut self, descriptor_name: DescriptorName, ) -> Result<Option<String>, Error>
Gets the BIP-0388 wallet policy of a given wallet
Sourcepub fn blockchain(&mut self) -> Result<String, Error>
pub fn blockchain(&mut self) -> Result<String, Error>
Gets the name of the blockchain the Colcard is set to operate on.
Sourcepub fn create_username(
&mut self,
username: Username,
auth_mode: AuthMode,
show_qr: bool,
) -> Result<Option<String>, Error>
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.
Sourcepub fn delete_miniscript(
&mut self,
descriptor_name: DescriptorName,
) -> Result<(), Error>
pub fn delete_miniscript( &mut self, descriptor_name: DescriptorName, ) -> Result<(), Error>
Delete a registered miniscript descriptor
Sourcepub fn delete_username(&mut self, username: Username) -> Result<(), Error>
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.
Sourcepub fn get_backup(&mut self) -> Result<Option<Backup>, Error>
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.
Sourcepub fn get_passphrase_done(&mut self) -> Result<Option<String>, Error>
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.
Sourcepub fn get_signed_message(&mut self) -> Result<Option<SignedMessage>, Error>
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.
Sourcepub fn get_signed_tx(&mut self) -> Result<Option<Vec<u8>>, Error>
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.
Sourcepub fn hsm_start(&mut self, policy: Option<&[u8]>) -> Result<(), Error>
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.
Sourcepub fn hsm_policy(&mut self) -> Result<String, Error>
pub fn hsm_policy(&mut self) -> Result<String, Error>
Gets the HSM policy file in the JSON format.
Sourcepub fn locker(&mut self) -> Result<Vec<u8>, Error>
pub fn locker(&mut self) -> Result<Vec<u8>, Error>
Gets the value in the storage locker (HSM use).
Sourcepub fn logout(self) -> Result<(), Error>
pub fn logout(self) -> Result<(), Error>
Securely logs out of the Coldcard. Requires a power cycle to use again.
Sourcepub fn miniscript_address(
&mut self,
descriptor_name: DescriptorName,
change: bool,
index: u32,
) -> Result<String, Error>
pub fn miniscript_address( &mut self, descriptor_name: DescriptorName, change: bool, index: u32, ) -> Result<String, Error>
Show miniscript address.
Sourcepub fn miniscript_enroll(&mut self, descriptor: &[u8]) -> Result<(), Error>
pub fn miniscript_enroll(&mut self, descriptor: &[u8]) -> Result<(), Error>
Enroll miniscript file.
Sourcepub fn miniscript_get(
&mut self,
descriptor_name: DescriptorName,
) -> Result<Option<String>, Error>
pub fn miniscript_get( &mut self, descriptor_name: DescriptorName, ) -> Result<Option<String>, Error>
Get registered descriptor by name.
Sourcepub fn miniscript_list(&mut self) -> Result<Vec<String>, Error>
pub fn miniscript_list(&mut self) -> Result<Vec<String>, Error>
List miniscript descriptors registered on the device
Sourcepub fn multisig_check(
&mut self,
m: u32,
n: u32,
xfp_xor: u32,
) -> Result<bool, Error>
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)?
Sourcepub fn multisig_enroll(
&mut self,
length: u32,
file_sha: [u8; 32],
) -> Result<(), Error>
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).
Sourcepub fn restore_backup(
&mut self,
data: &[u8],
custom_pwd: bool,
plaintext: bool,
tmp: bool,
) -> Result<(), Error>
pub fn restore_backup( &mut self, data: &[u8], custom_pwd: bool, plaintext: bool, tmp: bool, ) -> Result<(), Error>
Restore a backup
Sourcepub fn serial_number(&self) -> &str
pub fn serial_number(&self) -> &str
Returns the serial number of this Coldcard.
Sourcepub fn set_passphrase(&mut self, passphrase: Passphrase) -> Result<(), Error>
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.
Sourcepub fn show_p2sh_address(
&mut self,
min_signers: u8,
xfp_paths: Vec<XfpPath>,
redeem_script: RedeemScript,
address_format: AddressFormat,
) -> Result<String, Error>
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.
Sourcepub fn sign_message(
&mut self,
raw_msg: Message,
subpath: Option<DerivationPath>,
addr_fmt: AddressFormat,
) -> Result<(), Error>
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.
Sourcepub fn sign_psbt(
&mut self,
psbt: &[u8],
sign_mode: SignMode,
) -> Result<(), Error>
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.
Sourcepub fn sign_psbt_miniscript(
&mut self,
psbt: &[u8],
sign_mode: SignMode,
descriptor_name: Option<DescriptorName>,
) -> Result<(), Error>
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.
Sourcepub fn start_backup(&mut self) -> Result<(), Error>
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.
Sourcepub fn test(&mut self) -> Result<(), Error>
pub fn test(&mut self) -> Result<(), Error>
Tests the Coldcard and the USB connection by sending predefined data packets.
Sourcepub fn upgrade<F: FnMut(usize, usize)>(
&mut self,
firmware: Firmware,
progress: F,
) -> Result<(), Error>
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.
Sourcepub fn user_auth(
&mut self,
username: Username,
token: AuthToken,
totp_time: u32,
) -> Result<(), Error>
pub fn user_auth( &mut self, username: Username, token: AuthToken, totp_time: u32, ) -> Result<(), Error>
Authenticates a user (for HSM).