iop_keyvault/
bip44path.rs1use super::*;
2
3pub struct Bip44Path;
5
6impl Bip44Path {
7 pub fn coin(slip44: i32) -> Bip44CoinPath {
10 Bip44CoinPath { slip44 }
11 }
12}
13
14#[derive(Clone, Debug)]
16pub struct Bip44CoinPath {
17 slip44: i32,
18}
19
20impl Bip44CoinPath {
21 pub fn slip44(&self) -> i32 {
23 self.slip44
24 }
25
26 pub fn account(self, idx: i32) -> Bip44AccountPath {
28 Bip44AccountPath { parent: self, account: idx }
29 }
30
31 pub fn bip32_path(&self) -> bip32::Path {
33 Bip43Path::purpose(44).bip32_path().append(ChildIndex::Hardened(self.slip44))
34 }
35}
36
37#[derive(Clone, Debug)]
39pub struct Bip44AccountPath {
40 parent: Bip44CoinPath,
41 account: i32,
42}
43
44impl Bip44AccountPath {
45 pub fn parent(&self) -> &Bip44CoinPath {
47 &self.parent
48 }
49
50 pub fn account(&self) -> i32 {
52 self.account
53 }
54
55 pub fn chain(self, chain: Chain) -> Bip44SubAccountPath {
59 Bip44SubAccountPath { parent: self, chain }
60 }
61
62 pub fn key(self, idx: i32) -> Bip44KeyPath {
65 self.chain(Chain::Receiving).key(idx)
66 }
67
68 pub fn bip32_path(&self) -> bip32::Path {
70 self.parent.bip32_path().append(ChildIndex::Hardened(self.account))
71 }
72}
73
74#[derive(Clone, Debug)]
75pub struct Bip44SubAccountPath {
77 parent: Bip44AccountPath,
78 chain: Chain,
79}
80
81impl Bip44SubAccountPath {
82 pub fn parent(&self) -> &Bip44AccountPath {
84 &self.parent
85 }
86
87 pub fn chain(&self) -> Chain {
89 self.chain
90 }
91
92 pub fn key(self, idx: i32) -> Bip44KeyPath {
94 Bip44KeyPath { parent: self, key: idx }
95 }
96
97 pub fn bip32_path(&self) -> bip32::Path {
99 self.parent.bip32_path().append(ChildIndex::Normal(self.chain() as i32))
100 }
101}
102
103#[derive(Clone, Debug)]
104pub struct Bip44KeyPath {
106 parent: Bip44SubAccountPath,
107 key: i32,
108}
109
110impl Bip44KeyPath {
111 pub fn parent(&self) -> &Bip44SubAccountPath {
113 &self.parent
114 }
115
116 pub fn key(&self) -> i32 {
118 self.key
119 }
120
121 pub fn bip32_path(&self) -> bip32::Path {
123 self.parent.bip32_path().append(ChildIndex::Normal(self.key()))
124 }
125}