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
use std::fmt;
use super::*;
pub const ADDR_PREFIX_SIZE: usize = 1;
pub const BIP32_VERSION_PREFIX_SIZE: usize = 4;
pub trait Subtree {
type Suite: KeyDerivationCrypto;
fn name(&self) -> &'static str;
fn master(
&self, seed: &Seed,
) -> <<Self as Subtree>::Suite as KeyDerivationCrypto>::ExtendedPrivateKey;
fn key_id(
&self, pk: &<<Self as Subtree>::Suite as AsymmetricCrypto>::PublicKey,
) -> <<Self as Subtree>::Suite as AsymmetricCrypto>::KeyId;
}
impl<C: KeyDerivationCrypto + 'static> fmt::Debug for &dyn Subtree<Suite = C> {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> Result<(), fmt::Error> {
formatter.write_str(self.name())
}
}
pub trait Network: Subtree {
fn p2pkh_addr(&self) -> &'static [u8; ADDR_PREFIX_SIZE];
fn p2sh_addr(&self) -> &'static [u8; ADDR_PREFIX_SIZE];
fn wif(&self) -> &'static [u8; ADDR_PREFIX_SIZE];
fn bip32_xprv(&self) -> &'static [u8; BIP32_VERSION_PREFIX_SIZE];
fn bip32_xpub(&self) -> &'static [u8; BIP32_VERSION_PREFIX_SIZE];
fn message_prefix(&self) -> &'static str;
fn slip44(&self) -> i32;
fn subtree(&self) -> &dyn Subtree<Suite = <Self as Subtree>::Suite>;
}
impl<C: KeyDerivationCrypto + 'static> fmt::Debug for &dyn Network<Suite = C> {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> Result<(), fmt::Error> {
formatter.write_str(self.name())
}
}