Skip to main content

rust_hdwallet/hdwallet/cryptocurrencies/
pinetwork.rs

1use crate::hdwallet::slip44::coin_types;
2
3use super::icryptocurrency::{
4    AddressTypes, CryptocurrencyDescriptor, Info, InfoItem, InfoValue, NetworkDescriptor, Params,
5    XPrivateKeyVersions, XPublicKeyVersions,
6};
7use super::NetworkName;
8
9pub struct Mainnet;
10
11impl Mainnet {
12    pub const NAME: &'static str = "mainnet";
13    pub const XPRIVATE_KEY_VERSIONS: XPrivateKeyVersions = &[("P2PKH", 0x0488ade4)];
14    pub const XPUBLIC_KEY_VERSIONS: XPublicKeyVersions = &[("P2PKH", 0x0488b21e)];
15}
16
17pub static MAINNET: NetworkDescriptor = NetworkDescriptor {
18    name: Mainnet::NAME,
19    public_key_address_prefix: None,
20    script_address_prefix: None,
21    hrp: None,
22    witness_versions: None,
23    xprivate_key_versions: Some(Mainnet::XPRIVATE_KEY_VERSIONS),
24    xpublic_key_versions: Some(Mainnet::XPUBLIC_KEY_VERSIONS),
25    message_prefix: None,
26    wif_prefix: None,
27    legacy_public_key_address_prefix: None,
28    std_public_key_address_prefix: None,
29    legacy_script_address_prefix: None,
30    std_script_address_prefix: None,
31    standard: None,
32    integrated: None,
33    sub_address: None,
34    network_type: None,
35    payment_address_hrp: None,
36    reward_address_hrp: None,
37};
38
39pub static NETWORKS: &[(&'static str, &'static NetworkDescriptor)] = &[("MAINNET", &MAINNET)];
40
41pub static ADDRESS_TYPE_LABELS: AddressTypes = &[
42    ("STELLAR", "Stellar"),
43    ("PRIVATE_KEY", "private_key"),
44    ("PUBLIC_KEY", "public_key"),
45];
46
47pub static PI_NETWORK_PARAMS: Params = Params {
48    checksum_length: Some(2),
49    payment_id_length: None,
50    suffix: None,
51    address_prefix: None,
52    chain_prefixes_by_address_type: None,
53    alphabet: None,
54    field_size_hex: None,
55    tap_tweak_sha256: None,
56    cardano_wallet_types: None,
57    cardano_payment_prefix: None,
58    cardano_reward_prefix: None,
59    cardano_public_key_address: None,
60    cardano_redemption_address: None,
61    address_type_codes: Some(&[
62        ("PRIVATE_KEY", (18 << 3) as u8),
63        ("PUBLIC_KEY", (6 << 3) as u8),
64    ]),
65    address_prefix_byte: None,
66    address_version_byte: None,
67    key_type: None,
68    address_type_prefix_bytes: None,
69};
70
71pub struct PiNetwork {
72    pub network: NetworkName,
73}
74
75impl PiNetwork {
76    pub const NAME: &'static str = "Pi-Network";
77    pub const SYMBOL: &'static str = "PI";
78    pub const COIN_TYPE: u32 = coin_types::PI_NETWORK;
79    pub const ECC: &'static str = "SLIP10Ed25519ECC";
80    pub const SUPPORT_BIP38: bool = false;
81    pub const DEFAULT_HD: &'static str = "BIP44";
82    pub const DEFAULT_PATH: &'static str = "m/44'/314159'/0'/0/0";
83    pub const DEFAULT_ADDRESS: &'static str = "STELLAR";
84    pub const ENTROPIES: &'static [&'static str] = &["BIP39"];
85    pub const MNEMONICS: &'static [&'static str] = &["BIP39"];
86    pub const SEEDS: &'static [&'static str] = &["BIP39"];
87    pub const HDS: &'static [&'static str] = &["BIP32", "BIP44"];
88    pub const ADDRESSES: &'static [&'static str] = &["STELLAR"];
89    pub const SEMANTICS: &'static [&'static str] = &["p2pkh"];
90    pub const DEFAULT_SEMANTIC: Option<&'static str> = Some("p2pkh");
91
92    pub const INFO: Info<'static> = Info(&[
93        InfoItem {
94            key: "SOURCE_CODE",
95            value: InfoValue::Str("https://github.com/pi-apps"),
96        },
97        InfoItem {
98            key: "WHITEPAPER",
99            value: InfoValue::Str("https://minepi.com/white-paper"),
100        },
101        InfoItem {
102            key: "WEBSITES",
103            value: InfoValue::List(&["https://minepi.com"]),
104        },
105    ]);
106
107    #[must_use]
108    pub fn network_descriptor(&self) -> &'static NetworkDescriptor {
109        match self.network {
110            NetworkName::Mainnet => &MAINNET,
111            NetworkName::Testnet | NetworkName::Regtest => &MAINNET,
112        }
113    }
114}
115
116pub static DESCRIPTOR: CryptocurrencyDescriptor = CryptocurrencyDescriptor {
117    name: PiNetwork::NAME,
118    symbol: PiNetwork::SYMBOL,
119    info: PiNetwork::INFO,
120    ecc: PiNetwork::ECC,
121    coin_type: PiNetwork::COIN_TYPE,
122    support_bip38: PiNetwork::SUPPORT_BIP38,
123    networks: NETWORKS,
124    default_network: &MAINNET,
125    entropies: PiNetwork::ENTROPIES,
126    mnemonics: PiNetwork::MNEMONICS,
127    seeds: PiNetwork::SEEDS,
128    hds: PiNetwork::HDS,
129    default_hd: PiNetwork::DEFAULT_HD,
130    default_path: PiNetwork::DEFAULT_PATH,
131    addresses: PiNetwork::ADDRESSES,
132    default_address: PiNetwork::DEFAULT_ADDRESS,
133    address_types: Some(ADDRESS_TYPE_LABELS),
134    default_address_type: Some("PUBLIC_KEY"),
135    address_prefixes: None,
136    default_address_prefix: None,
137    semantics: PiNetwork::SEMANTICS,
138    default_semantic: PiNetwork::DEFAULT_SEMANTIC,
139    params: Some(PI_NETWORK_PARAMS),
140};