whisky_wallet/wallet/
derivation_indices.rs1use crate::wallet_constants::HARDENED_KEY_START;
2
3pub struct DerivationIndices(pub Vec<u32>);
4
5impl Default for DerivationIndices {
6 fn default() -> Self {
7 DerivationIndices(vec![
8 HARDENED_KEY_START + 1852, HARDENED_KEY_START + 1815, HARDENED_KEY_START, 0, 0, ])
14 }
15}
16
17impl DerivationIndices {
18 pub fn payment(account_index: u32, key_index: u32) -> Self {
19 DerivationIndices(vec![
20 HARDENED_KEY_START + 1852, HARDENED_KEY_START + 1815, HARDENED_KEY_START + account_index, 0, key_index, ])
26 }
27
28 pub fn stake(account_index: u32, key_index: u32) -> Self {
29 DerivationIndices(vec![
30 HARDENED_KEY_START + 1852, HARDENED_KEY_START + 1815, HARDENED_KEY_START + account_index, 2, key_index, ])
36 }
37
38 pub fn drep(account_index: u32, key_index: u32) -> Self {
39 DerivationIndices(vec![
40 HARDENED_KEY_START + 1852, HARDENED_KEY_START + 1815, HARDENED_KEY_START + account_index, 3, key_index, ])
46 }
47
48 pub fn from_str(derivation_path_str: &str) -> Self {
49 let derivation_path_vec: Vec<&str> = derivation_path_str.split('/').collect();
50 let derivation_path_vec_u32: Vec<u32> = derivation_path_vec
51 .iter()
52 .skip(1)
53 .map(|&s| {
54 if s.ends_with("'") {
55 let path_str = s.strip_suffix("'").unwrap();
57 path_str.parse::<u32>().unwrap() + 0x80000000
59 } else {
60 s.parse::<u32>().unwrap()
61 }
62 })
63 .collect();
64 DerivationIndices(derivation_path_vec_u32)
65 }
66}