rust_hdwallet/hdwallet/
consts.rs1use std::collections::HashMap;
2
3#[derive(Debug, Clone)]
4pub struct NestedNamespace {
5 pub data: HashMap<String, NestedValue>,
6}
7
8#[derive(Debug, Clone)]
9pub enum NestedValue {
10 String(String),
11 Nested(Box<NestedNamespace>),
12}
13
14impl NestedNamespace {
15 pub fn new_from_dict(data: HashMap<String, serde_json::Value>) -> Self {
16 let mut ns = NestedNamespace { data: HashMap::new() };
17 for (k, v) in data {
18 let value = match v {
19 serde_json::Value::Object(obj) => NestedValue::Nested(Box::new(
20 NestedNamespace::new_from_dict(
21 obj.into_iter()
22 .map(|(k, v)| (k, v))
23 .collect(),
24 ),
25 )),
26 _ => NestedValue::String(v.to_string()),
27 };
28 ns.data.insert(k, value);
29 }
30 ns
31 }
32
33 pub fn get_keys(&self) -> Vec<String> {
34 self.data.keys().cloned().collect()
35 }
36
37 pub fn get_values(&self) -> Vec<NestedValue> {
38 self.data.values().cloned().collect()
39 }
40}
41
42pub struct SLIP10Ed25519Const;
43impl SLIP10Ed25519Const {
44 pub const PRIVATE_KEY_BYTE_LENGTH: usize = 32;
45 pub const PUBLIC_KEY_PREFIX: u8 = 0x00;
46 pub const PUBLIC_KEY_BYTE_LENGTH: usize = 32;
47}
48
49pub struct KholawEd25519Const;
50impl KholawEd25519Const {
51 pub const PRIVATE_KEY_BYTE_LENGTH: usize = 64;
52 pub const PUBLIC_KEY_PREFIX: u8 = 0x00;
53 pub const PUBLIC_KEY_BYTE_LENGTH: usize = 32;
54}
55
56pub struct SLIP10Secp256k1Const;
57impl SLIP10Secp256k1Const {
58 pub const USE: &'static str = "coincurve";
59 pub const POINT_COORDINATE_BYTE_LENGTH: usize = 32;
60 pub const PRIVATE_KEY_BYTE_LENGTH: usize = 32;
61 pub const PRIVATE_KEY_UNCOMPRESSED_PREFIX: u8 = 0x00;
62 pub const PRIVATE_KEY_COMPRESSED_PREFIX: u8 = 0x01;
63 pub const PUBLIC_KEY_UNCOMPRESSED_PREFIX: u8 = 0x04;
64 pub const PUBLIC_KEY_COMPRESSED_BYTE_LENGTH: usize = 33;
65 pub const PUBLIC_KEY_UNCOMPRESSED_BYTE_LENGTH: usize = 65;
66 pub const CHECKSUM_BYTE_LENGTH: usize = 4;
67}
68
69pub struct PublicKeyTypes;
70impl PublicKeyTypes {
71 pub const UNCOMPRESSED: &'static str = "uncompressed";
72 pub const COMPRESSED: &'static str = "compressed";
73 pub fn get_types() -> Vec<&'static str> {
74 vec![Self::UNCOMPRESSED, Self::COMPRESSED]
75 }
76}
77
78pub struct WifTypes;
79impl WifTypes {
80 pub const WIF: &'static str = "wif";
81 pub const WIF_COMPRESSED: &'static str = "wif-compressed";
82 pub fn get_types() -> Vec<&'static str> {
83 vec![Self::WIF, Self::WIF_COMPRESSED]
84 }
85}
86
87pub struct Semantics;
88impl Semantics {
89 pub const P2WPKH: &'static str = "p2wpkh";
90 pub const P2WPKH_IN_P2SH: &'static str = "p2wpkh-in-p2sh";
91 pub const P2WSH: &'static str = "p2wsh";
92 pub const P2WSH_IN_P2SH: &'static str = "p2wsh-in-p2sh";
93 pub fn get_types() -> Vec<&'static str> {
94 vec![
95 Self::P2WPKH,
96 Self::P2WPKH_IN_P2SH,
97 Self::P2WSH,
98 Self::P2WSH_IN_P2SH,
99 ]
100 }
101}
102
103pub struct Modes;
104impl Modes {
105 pub const STANDARD: &'static str = "standard";
106 pub const SEGWIT: &'static str = "segwit";
107 pub fn get_modes() -> Vec<&'static str> {
108 vec![Self::STANDARD, Self::SEGWIT]
109 }
110}
111
112pub mod semantics {
113 pub const P2PKH: &str = "p2pkh";
114 pub const P2SH: &str = "p2sh";
115 pub const P2WPKH: &str = "p2wpkh";
116 pub const P2WPKH_IN_P2SH: &str = "p2wpkh-in-p2sh";
117 pub const P2WSH: &str = "p2wsh";
118 pub const P2WSH_IN_P2SH: &str = "p2wsh-in-p2sh";
119 pub const P2TR: &str = "p2tr";
120}