8 个版本 (4 个重大更新)
| 新 0.5.0 | 2024 年 8 月 23 日 |
|---|---|
| 0.4.1 | 2024 年 3 月 20 日 |
| 0.4.0 | 2024 年 1 月 22 日 |
| 0.3.2 | 2023 年 8 月 10 日 |
| 0.1.0 |
|
#1 在 #pubkey
每月 458 次下载
在 async-hwi 中使用
110KB
2.5K SLoC
Ledger Bitcoin 应用程序客户端
Rust 编写的 Ledger Bitcoin 应用程序客户端库,依赖最少。
如果您想为此库做出贡献,请阅读 CONTRIBUTING.md。
最低支持的 Rust 版本
bitcoin_client_rs 应始终使用 Rust 1.60 编译。
入门指南
client::BitcoinClient 结构体实现了调用和解释 Ledger 设备与您的软件之间命令的方法。
pub struct BitcoinClient<T: Transport> {...}
impl<T: Transport> BitcoinClient<T> {
pub fn get_extended_pubkey(
&self,
path: &bitcoin::util::bip32::DerivationPath,
display: bool,
) -> Result<bitcoin::util::bip32::ExtendedPubKey, BitcoinClientError<T::Error>>;
}
它需要一个实现 client::Transport Trait 的内部连接。
pub trait Transport {
type Error: Debug;
fn exchange(&self, command: &APDUCommand) -> Result<(StatusWord, Vec<u8>), Self::Error>;
}
为了满足此 Trait,可以从 https://github.com/Zondax/ledger-rs 导入 ledger-transport-hid crate。请阅读 examples/ledger_hwi/src/transport.rs 文件以查找示例。
async 功能
可选功能 async 将 async_client 模块添加到 crate,并导入 async_trait 库。 async_client::BitcoinClient 结构体是 BitcoinClient 结构体的异步等效。它需要一个实现 async_client::Transport Trait 的内部连接。
#[async_trait]
pub trait Transport {
type Error: Debug;
async fn exchange(&self, command: &APDUCommand) -> Result<(StatusWord, Vec<u8>), Self::Error>;
}
no-std 支持
进行中。
示例
一个简单工具的代码,用于与 Ledger 设备或 Speculos 模拟器进行通信,可以在 examples 目录中找到。
使用给定派生路径检索扩展公钥并在设备屏幕上显示的命令示例
cargo run --package ledger_hwi -- \
get-extended-pubkey --derivation-path "m/44'/0'/0'/0/0" --display
依赖项
~8.5MB
~100K SLoC