Integrate a signing device
Add your signing device to Liana through async-hwi and liana-gui, or through files on an SD card, then test it and submit it.
Liana 16.0 drives USB signing devices through version 0.0.35 of the
async-hwi Rust crate. A device
that signs from an SD card needs no code in either repository.
Check what your firmware must support
Liana requires Miniscript support, as the Miniscript page explains. Your firmware must:
- Parse Miniscript: In
wsh()for SegWit (P2WSH) and intr()for Taproot (P2TR), the two script types. - Register the descriptor: As a
BIP 388 wallet policy or in full, under
the name Liana sends:
Liana-and the checksum, for a new wallet. - Serve keys at Liana's path: Liana asks for
m/48'/0'/0'/2'on mainnet andm/48'/1'/0'/2'on test networks, for the default account0'. - Accept a key on several paths: Each time a key appears again, Liana
gives it the next pair of branches:
/<0;1>/*, then/<2;3>/*. - Sign on every path: Including a recovery path whose script holds
older(). - Display an address: Derived from the registered policy and an index alone.
wsh(or_d(multi(2,@0/<0;1>/*,@1/<0;1>/*),and_v(v:thresh(2,pkh(@0/<2;3>/*),a:pkh(@1/<2;3>/*),a:pkh(@2/<0;1>/*)),older(300))))Implement the HWI trait in async-hwi
Discuss it first
Raise your device in a GitHub issue or on Discord, as Contribute to Liana shows.
In a fork of async-hwi, add a module for your device behind its own Cargo
feature, like ledger. List the feature in default, which the hwi
command-line tool builds with. Add a variant to the DeviceKind enum, then
implement the trait:
#[async_trait]
pub trait HWI: Debug {
fn device_kind(&self) -> DeviceKind;
async fn get_version(&self) -> Result<Version, Error>;
async fn get_master_fingerprint(&self) -> Result<Fingerprint, Error>;
async fn get_extended_pubkey(&self, path: &DerivationPath) -> Result<Xpub, Error>;
fn display(&self, _display: bool) {}
async fn register_wallet(&self, name: &str, policy: &str) -> Result<Option<[u8; 32]>, Error>;
async fn is_wallet_registered(&self, name: &str, policy: &str) -> Result<bool, Error>;
async fn display_address(&self, script: &AddressScript) -> Result<(), Error>;
async fn sign_tx(&self, tx: &mut Psbt) -> Result<(), Error>;
}| Method | Liana calls it | Your implementation |
|---|---|---|
device_kind | On detection | Returns your new variant. |
get_version | On detection | Returns the firmware or app version. |
get_master_fingerprint | On detection | Returns the fingerprint Liana matches against the wallet's keys. |
get_extended_pubkey | When the installer fetches a key | Returns the xpub at path. |
display | Before get_extended_pubkey, when the installer decrypts a backup | Optional: the default does nothing. Sets whether the following get_extended_pubkey calls also show the xpub on the screen. The Ledger and BitBox02 modules implement it. Liana passes true to a Ledger only, for a path outside the common ones or with purpose 87'. |
register_wallet | When you register the descriptor | Receives the name and full descriptor. Returns a proof of registration if the device stores nothing, like a Ledger, else None. |
is_wallet_registered | On detection, for a Blockstream Jade | Returns true only if the device holds this policy under this name. |
display_address | When you verify a receive address | Receives AddressScript::Miniscript { index, change: false }. |
sign_tx | When you sign a draft | Receives Liana's version 0 PSBT. Adds signatures to partial_sigs (P2WSH), tap_script_sigs or tap_key_sig (Taproot), the only fields Liana merges. |
Map a rejection on the device to Error::UserRefused, which Liana does not
report when you sign or register. Return Error::UnimplementedMethod for a
method your device lacks, as the Specter DIY module does for
display_address. If your firmware reads only version 2 PSBTs, convert them
in your module, as the Ledger module does through ledger_bitcoin_client.
Make Liana detect the device
liana-gui does not use the service module of async-hwi. It scans for
devices in its own loop in liana-gui/src/hw.rs, with one branch per device.
Change liana-gui in these places:
- Detection: A branch in
refreshthat pushes aHardwareWallet::Supported. - Minimum version: A check like the one in
handle_ledger_device, which returnsHardwareWallet::Unsupportedwith the version your firmware needs. - Wallet context: The step that hands the device the open wallet. A Coldcard or a Blockstream Jade gets its name, a BitBox02 its descriptor, and a Ledger its name, descriptor and stored proof. With Liana Connect, Liana syncs Ledger proofs only.
- Taproot: Your first Taproot version in
DEVICES_COMPATIBLE_WITH_TAPMINISCRIPT. From Liana 16.0, the installer selects Taproot by default. Liana refuses a device missing from the list, or older than your version, in a Taproot wallet. Pick the descriptor type shows what the user sees. - Address display: For a device that cannot display an address, the
Specter DIY exclusion in
liana-gui/src/app/view/hw.rs.
Test the device against Liana
Call each method with the hwi CLI
In async-hwi, add your device to the list function of cli/src/lib.rs. On
Linux, install libudev-dev and pkg-config. Install the hwi tool from the
repository root, then call it with your device set to a test network:
cargo install --path cli
hwi --network signet device list
hwi --network signet xpub get --path "m/48'/1'/0'/2'"
hwi --network signet wallet register --name "Liana-<checksum>" --policy "<descriptor>"Its other commands are address display, wallet is-registered and
psbt sign, each with --help.
Build Liana against your fork
In the root Cargo.toml of Liana, add your feature to the features list of
async-hwi, because Liana turns off its default features. Add your checkout to
the [patch.crates-io] section already there:
[workspace.dependencies]
async-hwi = { version = "0.0.35", default-features = false, features = ["ledger", "specter", "coldcard", "bitbox", "jade", "service", "rustls-no-provider", "<your feature>"] }
[patch.crates-io]
# the iced entries already there
async-hwi = { path = "../async-hwi" }Keep version 0.0.35 in your fork. Cargo uses a patch only if its version
matches the one Liana requires. Build liana-gui as
Build from source shows.
Rehearse a signet wallet
Follow Try Liana on signet with your device in place
of the hot key, on both paths, so that its key also takes /<2;3>/*. Until
your device is in DEVICES_COMPATIBLE_WITH_TAPMINISCRIPT, select Segwit
under Descriptor type. Register the descriptor on the device when the
installer asks.
Exercise every method
Verify a receive address on the device. Sign a spend through the primary path,
then one through the recovery path once its timelock expires. If your firmware
supports Taproot, list it in DEVICES_COMPATIBLE_WITH_TAPMINISCRIPT and repeat
with Taproot (recommended).
Support an air-gapped device with files
A device that signs from an SD card works with Liana as it ships, as Krux does. Your firmware must handle three files:
- The xpub: The installer loads it with Other options >
Import extended public key file (xpub). It takes one key on the
wallet's network, with its origin and nothing after it:
[fingerprint/48'/0'/0'/2']xpub…. It also takes a Coldcard JSON export. - The descriptor: Liana exports it as one line of text, in
liana-<checksum>.txt, for your device to register. - The PSBT: Liana exports a version 0 PSBT as base64 text, in
psbt.psbt. It imports the signed file back only in that format, and into a draft only if the transaction matches.
Sign air-gapped shows each exchange as an end user performs it.
Open the pull requests
- The device module: Open a pull request on wizardsardine/async-hwi. Run its CI checks, below, before you push.
- The
liana-guichanges: Open a pull request on wizardsardine/liana. It needs an async-hwi release with your module, because Liana takes async-hwi from crates.io. - The device notes: Add your device and its firmware floors to
doc/SIGNING_DEVICES.md, beside the other devices. - The AI policy: The same rules as Liana's AI policy apply to async-hwi.
cargo fmt -- --check
cargo clippy --all-features --all-targets -- -D warnings
cargo test