1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
//! A Ledger hardware wallet communication library
//!
//! [Device] provides a high-level API for exchanging APDUs with Ledger devices using the [ledger_proto] traits.
//! This is suitable for extension with application-specific interface traits, and automatically
//! implemented over [Exchange] for low-level byte exchange with devices.
//!
//! [LedgerProvider] and [LedgerHandle] provide a high-level tokio-compatible [Transport]
//! for application integration, supporting connecting to and interacting with ledger devices.
//! This uses a pinned thread to avoid thread safety issues with `hidapi` and async executors.
//!
//! Low-level [Transport] implementations are provided for [USB/HID](transport::UsbTransport),
//! [BLE](transport::BleTransport) and [TCP](transport::TcpTransport), with a [Generic](transport::GenericTransport)
//! implementation providing a common interface over all enabled transports.
//!
//! ## Safety
//!
//! Transports are currently marked as `Send` due to limitations of [async_trait] and are NOT all
//! thread safe. If you're calling this from an async context, please use [LedgerProvider].
//!
//! This will be corrected when the unstable async trait feature is stabilised,
//! which until then can be opted-into using the `unstable_async_trait` feature
//!
//! ## Examples
//!
//! ```no_run
//! use ledger_lib::{LedgerProvider, Filters, Transport, Device, DEFAULT_TIMEOUT};
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//! // Fetch provider handle
//! let mut provider = LedgerProvider::init().await;
//!
//! // List available devices
//! let devices = provider.list(Filters::Any).await?;
//!
//! // Check we have -a- device to connect to
//! if devices.is_empty() {
//! return Err(anyhow::anyhow!("No devices found"));
//! }
//!
//! // Connect to the first device
//! let mut ledger = provider.connect(devices[0].clone()).await?;
//!
//! // Request device information
//! let info = ledger.app_info(DEFAULT_TIMEOUT).await?;
//! println!("info: {info:?}");
//!
//! Ok(())
//! }
//! ```
use Duration;
pub use LedgerInfo;
pub use Error;
pub use Transport;
pub use ;
pub use Device;
/// Default timeout helper for use with [Device] and [Exchange]
pub const DEFAULT_TIMEOUT: Duration = from_secs;
/// Device discovery filter
/// [Exchange] trait provides a low-level interface for byte-wise exchange of APDU commands with a ledger devices
/// Blanket [Exchange] impl for mutable references