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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//! # WalletD
//!
//! A cryptocurrency wallet library that encapsulates Rust-based functionality for various different cryptocurrencies and blockchains.
//! Contains features to handle creating and importing wallets, checking balances, and sending and receiving transactions.
//! Provides a common interface for interacting with different cryptocurrencies and blockchains.
//! Built to facilitate and simplify development and implementation of multi-cryptocurrency non-custodial wallets.
//!
//! ## Quickstart Guide
//!
//! A good way to access many of the different features of this walletD library is through the use of the [KeyPair] struct which can enable a user to create a HD (Hierarchical Deterministic) wallet from a mnemonic phrase that could be used with multiple cryptocurrencies.
//! The [KeyPairBuilder] struct which can be accessed with default settings through [`KeyPair::builder()`] is a versatile way to specify options for and build a [KeyPair] struct.
//!
//! You can use the [KeyPairBuilder] to specify the mnemonic phrase, mnemonic seed, passphrase, network type, and the mnemonic key pair type.
//! The default specifications for the [KeyPairBuilder] are: no mnemonic phrase, no mnemonic seed, no passphrase, mainnet network type, and BIP39 mnemonic key pair type.
//! To use the testnet network, specify the network type as [HDNetworkType::TestNet] using the [`network_type method`][KeyPairBuilder::network_type()] on a [KeyPairBuilder] object.
//! You need to either specify a mnemonic seed or a mnemonic phrase to build a [KeyPair] struct. If a mnemonic phrase is specified, the mnemonic seed is derived from the mnemonic phrase and the optional passphrase.
//! If the mnemonic seed is specified, any specifications for the mnemonic phrase and passphrase are ignored when deriving a HD wallet key, but any specifications given for these attributes are stored on the [KeyPair] struct.
//!
//! **Warning**:
//! The information in the [KeyPair] struct should be treated as sensitive information and should be stored and handled securely, especially if it is being used to store real funds.
//!
//! The [KeyPair] struct contains the mnemonic phrase, mnemonic seed, and passphrase if specified, as well as the network type and the mnemonic key pair type.
//!
//! ### Create HD KeyPair from Bip39 Mnemonic
//!
//! Here's how you can create a [KeyPair] from a [Bip39Mnemonic] using the [KeyPairBuilder].
//! ```
//! use walletd::prelude::*;
//! use walletd_bip39::prelude::*;
//! # fn main() -> Result<(), walletd::Error> {
//! let mnemonic_phrase = "outer ride neither foil glue number place usage ball shed dry point";
//! let bip39_mnemonic = Bip39Mnemonic::builder().mnemonic_phrase(mnemonic_phrase).build()?;
//! let seed = bip39_mnemonic.to_seed();
//! println!("seed_hex: {:x}", seed);
//! let master_hd_key = HDKey::new_master(seed, HDNetworkType::TestNet)?;
//! let keypair = KeyPair::builder().mnemonic_phrase(mnemonic_phrase.into()).network_type(HDNetworkType::TestNet).build()?;
//! assert_eq!(keypair.to_master_key(), master_hd_key);
//! # Ok(())
//! # }
//! ```
//!
//! ### Derive Wallets
//!
//! The [`KeyPair::derive_wallet`] method can be used to derive a [cryptowallet][CryptoWallet] for a specific cryptocurrency from a [KeyPair].
//! You can specify a concrete struct that implements the [CryptoWallet] trait such as [BitcoinWallet] or [EthereumWallet] to derive a cryptowallet from the `keypair` of the specified concrete type.
//! ```
//! # use walletd::prelude::*;
//! # use walletd_bip39::prelude::*;
//! use walletd_bitcoin::prelude::*;
//! use walletd_ethereum::prelude::*;
//! # fn main() -> Result<(), walletd::Error> {
//! # let mnemonic_phrase = "outer ride neither foil glue number place usage ball shed dry point";
//! # let bip39_mnemonic = Bip39Mnemonic::builder().mnemonic_phrase(mnemonic_phrase).build()?;
//! # let seed = bip39_mnemonic.to_seed();
//! # println!("seed_hex: {:x}", seed);
//! # let master_hd_key = HDKey::new_master(seed, HDNetworkType::TestNet)?;
//! # let keypair = KeyPair::builder().mnemonic_phrase(mnemonic_phrase.into()).network_type(HDNetworkType::TestNet).build()?;
//! let mut btc_wallet = keypair.derive_wallet::<BitcoinWallet>()?;
//! let mut eth_wallet = keypair.derive_wallet::<EthereumWallet>()?;
//! # Ok(())
//! # }
//! ```
//! ### Specify Blockchain Connectors
//!
//! A valid [blockchain client][BlockchainConnector] is a concrete instance of a struct that implements the [BlockchainConnector] trait.
//! You can setup a [Blockstream] blockchain client to access the Bitcoin blockchain and an [EthClient] blockchain client to access the Ethereum blockchain.
//! Specifying a valid endpoint url is required for the [Blockstream] and [EthClient] blockchain clients.
//! To associate an existing instance of a [cryptowallet][CryptoWallet] with a [blockchain client][BlockchainConnector], use the [`set_blockchain_client`][CryptoWallet::set_blockchain_client] method on the [cryptowallet][CryptoWallet] object.
//!
//! ```no_run
//! # use walletd::prelude::*;
//! # use walletd_bip39::prelude::*;
//! # use walletd_bitcoin::prelude::*;
//! # use walletd_ethereum::prelude::*;
//! # fn main() -> Result<(), walletd::Error> {
//! # let mnemonic_phrase = "outer ride neither foil glue number place usage ball shed dry point";
//! # let bip39_mnemonic = Bip39Mnemonic::builder().mnemonic_phrase(mnemonic_phrase).build()?;
//! # let seed = bip39_mnemonic.to_seed();
//! # println!("seed_hex: {:x}", seed);
//! # let master_hd_key = HDKey::new_master(seed, HDNetworkType::TestNet)?;
//! # let keypair = KeyPair::builder().mnemonic_phrase(mnemonic_phrase.into()).network_type(HDNetworkType::TestNet).build()?;
//! # let mut btc_wallet = keypair.derive_wallet::<BitcoinWallet>()?;
//! # let mut eth_wallet = keypair.derive_wallet::<EthereumWallet>()?;
//! btc_wallet.set_blockchain_client(Blockstream::new("https://blockstream.info/testnet/api")?);
//! eth_wallet.set_blockchain_client(EthClient::new("https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161")?);
//!
//! # Ok(())
//! # }
//! ```
//!
//! ### Use the CryptoWallets
//! Once you have a [cryptowallet][CryptoWallet] object associated with a [blockchain client] you can use the [cryptowallet][CryptoWallet] to access blockchain data.
//! Any object that implements the [CryptoWallet] trait must implement functions within the trait which include [`balance`][CryptoWallet::balance], and [`transfer`][CryptoWallet::transfer].
//!
//! ```no_run
//! # use walletd::prelude::*;
//! # use walletd_bip39::prelude::*;
//! # use walletd_bitcoin::prelude::*;
//! # use walletd_ethereum::prelude::*;
//! # async fn cryptowallets() -> Result<(), walletd::Error> {
//! # let mnemonic_phrase = "outer ride neither foil glue number place usage ball shed dry point";
//! # let bip39_mnemonic = Bip39Mnemonic::builder().mnemonic_phrase(mnemonic_phrase).build()?;
//! # let seed = bip39_mnemonic.to_seed();
//! # println!("seed_hex: {:x}", seed);
//! # let master_hd_key = HDKey::new_master(seed, HDNetworkType::TestNet)?;
//! # let keypair = KeyPair::builder().mnemonic_phrase(mnemonic_phrase.into()).network_type(HDNetworkType::TestNet).build()?;
//! # let mut btc_wallet = keypair.derive_wallet::<BitcoinWallet>()?;
//! # let mut eth_wallet = keypair.derive_wallet::<EthereumWallet>()?;
//! # btc_wallet.set_blockchain_client(Blockstream::new("https://blockstream.info/testnet/api")?);
//! # eth_wallet.set_blockchain_client(EthClient::new("https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161")?);
//! btc_wallet.sync().await?;
//! println!("btc_wallet balance: {} BTC", btc_wallet.balance().await?.btc());
//! let mut eth_wallet = keypair.derive_wallet::<EthereumWallet>()?;
//! print!("eth_wallet public address: {}", eth_wallet.public_address());
//! let eth_client = EthClient::new("https://goerli.infura.io/v3/9aa3d95b3bc440fa88ea12eaa4456161")?;
//! eth_wallet.set_blockchain_client(eth_client);
//! println!("eth_wallet balance: {} ETH", eth_wallet.balance().await?.eth());
//! # Ok(())
//! # }
//! ```
pub use ;
pub use ;
pub use ;
pub use blockstream;
pub use Blockstream;
pub use ;
pub use ConnectorType;
pub use ;
pub use ;
pub use ;
pub use ;
pub use CryptoCoin;
pub use Error;