pub struct HWIClient { /* private fields */ }
Implementations§
source§impl HWIClient
impl HWIClient
sourcepub fn enumerate() -> Result<Vec<Result<HWIDevice, Error>>, Error>
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),
}
}
sourcepub fn get_client(
device: &HWIDevice,
expert: bool,
chain: HWIChain
) -> Result<HWIClient, Error>
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()
);
}
sourcepub fn find_device(
password: Option<&str>,
device_type: Option<HWIDeviceType>,
fingerprint: Option<&str>,
expert: bool,
chain: Network
) -> Result<HWIClient, Error>
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());
sourcepub fn get_master_xpub(
&self,
addrtype: HWIAddressType,
account: u32
) -> Result<HWIExtendedPubKey, Error>
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.
sourcepub fn sign_tx(
&self,
psbt: &Psbt
) -> Result<HWIPartiallySignedTransaction, Error>
pub fn sign_tx( &self, psbt: &Psbt ) -> Result<HWIPartiallySignedTransaction, Error>
Signs a PSBT.
sourcepub fn get_xpub(
&self,
path: &DerivationPath,
expert: bool
) -> Result<HWIExtendedPubKey, Error>
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.
sourcepub fn sign_message(
&self,
message: &str,
path: &DerivationPath
) -> Result<HWISignature, Error>
pub fn sign_message( &self, message: &str, path: &DerivationPath ) -> Result<HWISignature, Error>
Signs a message.
sourcepub 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>
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 informationinternal
- Whether to use internal (change) or external keysaddr_type
- Address type to useaddr_all
- Whether to return a multiple descriptors for every address typeaccount
- Optional BIP43 account to usepath
- The derivation path to derive the keys.start
- Keypool startend
- Keypool end
sourcepub fn get_descriptors<T>(
&self,
account: Option<u32>
) -> Result<HWIDescriptor<T>, Error>where
T: ToDescriptor + DeserializeOwned,
pub fn get_descriptors<T>(
&self,
account: Option<u32>
) -> Result<HWIDescriptor<T>, Error>where
T: ToDescriptor + DeserializeOwned,
Returns device descriptors. You can optionally specify a BIP43 account to use.
sourcepub fn display_address_with_desc<T>(
&self,
descriptor: &T
) -> Result<HWIAddress, Error>where
T: ToDescriptor + ToString,
pub fn display_address_with_desc<T>(
&self,
descriptor: &T
) -> Result<HWIAddress, Error>where
T: ToDescriptor + ToString,
Returns an address given a descriptor.
sourcepub fn display_address_with_path(
&self,
path: &DerivationPath,
address_type: HWIAddressType
) -> Result<HWIAddress, Error>
pub fn display_address_with_path( &self, path: &DerivationPath, address_type: HWIAddressType ) -> Result<HWIAddress, Error>
Returns an address given path and address type.
sourcepub fn install_udev_rules(
source: Option<&str>,
location: Option<&str>
) -> Result<(), Error>
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
sourcepub fn toggle_passphrase(&self) -> Result<(), Error>
pub fn toggle_passphrase(&self) -> Result<(), Error>
Toggle whether the device is using a BIP 39 passphrase.
sourcepub fn setup_device(
&self,
label: Option<&str>,
passphrase: Option<&str>
) -> Result<(), Error>
pub fn setup_device( &self, label: Option<&str>, passphrase: Option<&str> ) -> Result<(), Error>
Setup a device
sourcepub fn restore_device(
&self,
label: Option<&str>,
word_count: Option<HWIWordCount>
) -> Result<(), Error>
pub fn restore_device( &self, label: Option<&str>, word_count: Option<HWIWordCount> ) -> Result<(), Error>
Restore a device
sourcepub fn backup_device(
&self,
label: Option<&str>,
backup_passphrase: Option<&str>
) -> Result<(), Error>
pub fn backup_device( &self, label: Option<&str>, backup_passphrase: Option<&str> ) -> Result<(), Error>
Create a backup of the device
sourcepub fn wipe_device(&self) -> Result<(), Error>
pub fn wipe_device(&self) -> Result<(), Error>
Wipe a device
sourcepub fn get_version() -> Option<String>
pub fn get_version() -> Option<String>
Get the installed version of hwilib. Returns None if hwi is not installed.