Struct hwi::interface::HWIClient

source ·
pub struct HWIClient { /* private fields */ }

Implementations§

source§

impl HWIClient

source

pub fn enumerate() -> Result<Vec<Result<HWIDevice, Error>>, Error>

Lists all HW devices currently connected.

let devices = HWIClient::enumerate()?;
for device in devices {
    match device {
        Ok(d) => println!("I can see a {} here 😄", d.model),
        Err(e) => println!("Uh oh, something went wrong when opening the device: {}", e),
    }
}
source

pub fn get_client( device: &HWIDevice, expert: bool, chain: HWIChain ) -> Result<HWIClient, Error>

Returns the HWIClient for a certain device. You can list all the available devices using enumerate.

Setting expert to true will enable additional output for some commands.

let devices = HWIClient::enumerate()?;
for device in devices {
    let device = device?;
    let client = HWIClient::get_client(&device, false, bitcoin::Network::Testnet.into())?;
    let xpub = client.get_master_xpub(HWIAddressType::Tap, 0)?;
    println!(
        "I can see a {} here, and its xpub is {}",
        device.model,
        xpub.to_string()
    );
}
source

pub fn find_device( password: Option<&str>, device_type: Option<HWIDeviceType>, fingerprint: Option<&str>, expert: bool, chain: Network ) -> Result<HWIClient, Error>

Returns the HWIClient for a certain device_type or fingerprint. You can list all the available devices using enumerate.

Setting expert to true will enable additional output for some commands.

let client = HWIClient::find_device(
    None,
    Some(HWIDeviceType::Trezor),
    None,
    false,
    bitcoin::Network::Testnet,
)?;
let xpub = client.get_master_xpub(HWIAddressType::Tap, 0)?;
println!("Trezor's xpub is {}", xpub.to_string());
source

pub fn get_master_xpub( &self, addrtype: HWIAddressType, account: u32 ) -> Result<HWIExtendedPubKey, Error>

Returns the master xpub of a device, given the address type and the account number.

source

pub fn sign_tx( &self, psbt: &Psbt ) -> Result<HWIPartiallySignedTransaction, Error>

Signs a PSBT.

source

pub fn get_xpub( &self, path: &DerivationPath, expert: bool ) -> Result<HWIExtendedPubKey, Error>

Returns the xpub of a device. If expert is set, additional output is returned.

source

pub fn sign_message( &self, message: &str, path: &DerivationPath ) -> Result<HWISignature, Error>

Signs a message.

source

pub fn get_keypool( &self, keypool: bool, internal: bool, addr_type: HWIAddressType, addr_all: bool, account: Option<u32>, path: Option<&DerivationPath>, start: u32, end: u32 ) -> Result<Vec<HWIKeyPoolElement>, Error>

Returns an array of keys that can be imported in Bitcoin core using importmulti

  • keypool - keypool value in result. Check bitcoin core importmulti documentation for further information
  • internal - Whether to use internal (change) or external keys
  • addr_type - Address type to use
  • addr_all - Whether to return a multiple descriptors for every address type
  • account - Optional BIP43 account to use
  • path - The derivation path to derive the keys.
  • start - Keypool start
  • end - Keypool end
source

pub fn get_descriptors<T>( &self, account: Option<u32> ) -> Result<HWIDescriptor<T>, Error>

Returns device descriptors. You can optionally specify a BIP43 account to use.

source

pub fn display_address_with_desc<T>( &self, descriptor: &T ) -> Result<HWIAddress, Error>

Returns an address given a descriptor.

source

pub fn display_address_with_path( &self, path: &DerivationPath, address_type: HWIAddressType ) -> Result<HWIAddress, Error>

Returns an address given path and address type.

source

pub fn install_udev_rules( source: Option<&str>, location: Option<&str> ) -> Result<(), Error>

Install the udev rules to the local machine.

The rules will be copied from the source to the location; the default source location is ./udev, the default destination location is /lib/udev/rules.d

source

pub fn set_log_level(level: LogLevel) -> Result<(), Error>

Set logging level

§Arguments
  • level - Log level.
source

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

Toggle whether the device is using a BIP 39 passphrase.

source

pub fn setup_device( &self, label: Option<&str>, passphrase: Option<&str> ) -> Result<(), Error>

Setup a device

source

pub fn restore_device( &self, label: Option<&str>, word_count: Option<HWIWordCount> ) -> Result<(), Error>

Restore a device

source

pub fn backup_device( &self, label: Option<&str>, backup_passphrase: Option<&str> ) -> Result<(), Error>

Create a backup of the device

source

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

Wipe a device

source

pub fn get_version() -> Option<String>

Get the installed version of hwilib. Returns None if hwi is not installed.

source

pub fn install_hwilib(version: Option<&str>) -> Result<(), Error>

Install hwi for the current user via pip. If no version is specified, the default version from pip will be installed.

Trait Implementations§

source§

impl Debug for HWIClient

source§

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

Formats the value using the given formatter. Read more
source§

impl Deref for HWIClient

§

type Target = Py<PyAny>

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.

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, U> TryFrom<U> for T
where U: Into<T>,

§

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>,

§

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.