1mod address;
7mod amount;
8mod atomic_swap;
9mod conditions;
10mod error;
11mod hash;
12mod keys;
13mod mnemonic;
14pub mod pq;
15pub mod tx;
16
17pub use address::Address;
18pub use amount::{Amount, NIBBLES_PER_BYTE};
19pub use atomic_swap::{
20 AtomicSwap, AtomicSwapParams, ChainClock, SwapLeg, SwapLocks, SwapSecret, SwapTimeouts,
21};
22pub use conditions::{
23 Condition, ConditionTemplates, EscrowRefundTemplate, HtlcTemplate, PaymentChannelTemplate,
24};
25pub use error::{Error, Result};
26pub use keys::{PrivateKey, PublicKey, Signature};
27pub use mnemonic::{mnemonic_from_private_key, private_key_from_mnemonic};
28pub use pq::{PQAddress, PQKeypair, PQNetwork, PQSignature};
29
30pub const MAINNET_CHAIN_ID: &str = "torvyon-mainnet";
32
33pub const TESTNET_CHAIN_ID: &str = "torvyon-testnet-1";
35
36#[derive(Debug, Clone, Copy, PartialEq, Eq)]
38pub enum Network {
39 Mainnet,
41 Testnet,
43}
44
45impl Network {
46 pub const fn chain_id(self) -> &'static str {
48 match self {
49 Self::Mainnet => MAINNET_CHAIN_ID,
50 Self::Testnet => TESTNET_CHAIN_ID,
51 }
52 }
53
54 pub const fn address_prefix(self) -> &'static str {
56 match self {
57 Self::Mainnet => "bt1",
58 Self::Testnet => "tbt1",
59 }
60 }
61
62 pub fn from_chain_id(chain_id: &str) -> Self {
65 match chain_id {
66 TESTNET_CHAIN_ID => Self::Testnet,
67 _ => Self::Mainnet,
68 }
69 }
70
71 pub fn from_address(address: &str) -> Self {
73 if address.starts_with(Self::Testnet.address_prefix()) {
74 Self::Testnet
75 } else {
76 Self::Mainnet
77 }
78 }
79}