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
#![allow(clippy::upper_case_acronyms)]
use std::fmt;
use thiserror::Error;
#[derive(Clone, Debug)]
pub enum DerivationType {
LedgerLive(usize),
Legacy(usize),
Other(String),
}
impl fmt::Display for DerivationType {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> {
write!(
f,
"{}",
match self {
DerivationType::Legacy(index) => format!("m/44'/60'/0'/{index}"),
DerivationType::LedgerLive(index) => format!("m/44'/60'/{index}'/0/0"),
DerivationType::Other(inner) => inner.to_owned(),
}
)
}
}
#[derive(Error, Debug)]
pub enum LedgerError {
#[error(transparent)]
LedgerError(#[from] coins_ledger::errors::LedgerError),
#[error("Received unexpected response from device. Expected data in response, found none.")]
UnexpectedNullResponse,
#[error(transparent)]
HexError(#[from] hex::FromHexError),
#[error(transparent)]
SemVerError(#[from] semver::Error),
#[error("error encoding eip712 struct: {0:?}")]
Eip712Error(String),
#[error("Ledger ethereum app requires at least version: {0:?}")]
UnsupportedAppVersion(String),
}
pub const P1_FIRST: u8 = 0x00;
#[repr(u8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum INS {
GET_PUBLIC_KEY = 0x02,
SIGN = 0x04,
GET_APP_CONFIGURATION = 0x06,
SIGN_PERSONAL_MESSAGE = 0x08,
SIGN_ETH_EIP_712 = 0x0C,
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum P1 {
NON_CONFIRM = 0x00,
MORE = 0x80,
}
#[repr(u8)]
#[derive(Debug, Copy, Clone, Eq, PartialEq)]
#[allow(non_camel_case_types)]
pub enum P2 {
NO_CHAINCODE = 0x00,
}