ledger_ethereum/
types.rs

1use ledger_zondax_generic::LedgerAppError;
2
3/// Ethereum Ledger Error
4#[derive(Debug, thiserror::Error)]
5pub enum EthError<E: std::error::Error> {
6    #[error("Ledger | {0}")]
7    /// Common Ledger errors
8    Ledger(#[from] LedgerAppError<E>),
9
10    /// Missing response data part
11    #[error("Missing response data: {0}")]
12    MissingResponseData(String),
13
14    /// Miscellaneous error
15    #[error("{0}")]
16    Other(String),
17}
18
19/// Chunk payload type
20pub enum ChunkPayloadType {
21    /// First chunk
22    First = 0x00,
23    /// Subsequent chunk
24    Subsequent = 0x80,
25}
26
27/// BIP44 Path
28#[derive(Debug)]
29pub struct BIP44Path {
30    /// Purpose
31    pub purpose: u32,
32    /// Coin
33    pub coin: u32,
34    /// Account
35    pub account: u32,
36    /// Change
37    pub change: u32,
38    /// Address Index
39    pub index: u32,
40}
41
42impl BIP44Path {
43    /// Serialize a [`BIP44Path`] in the format used in the app
44    pub fn serialize_bip44(&self) -> Vec<u8> {
45        use byteorder::{BigEndian, WriteBytesExt};
46        let mut m = Vec::new();
47
48        m.write_u8(5).unwrap(); // number of path components
49        m.write_u32::<BigEndian>(self.purpose).unwrap();
50        m.write_u32::<BigEndian>(self.coin).unwrap();
51        m.write_u32::<BigEndian>(self.account).unwrap();
52        m.write_u32::<BigEndian>(self.change).unwrap();
53        m.write_u32::<BigEndian>(self.index).unwrap();
54
55        m
56    }
57}
58
59#[derive(Debug)]
60pub struct LedgerEthTransactionResolution {
61    /// Device serialized data that contains ERC20 data (hex format)
62    pub erc20_tokens: Vec<String>,
63    /// Device serialized data that contains NFT data (hex format)
64    pub nfts: Vec<String>,
65    /// Device serialized data that contains external plugin data (hex format)
66    pub external_plugins: Vec<ExternalPluginData>,
67    /// Device serialized data that contains plugin data (hex format)
68    pub plugin: Vec<String>,
69}
70
71#[derive(Debug)]
72pub struct ExternalPluginData {
73    pub payload: String,
74    pub signature: String,
75}