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
use crate::client::BitGoClient;
use crate::error::Result;
use async_trait::async_trait;
use serde_json::json;
#[async_trait]
pub trait BitGoWalletAPI {
async fn generate_wallet(
&self,
name: &str,
identifier: &str,
passphrase: &str,
) -> Result<serde_json::Value>;
async fn generate_enterprise_wallet(
&self,
name: &str,
identifier: &str,
passphrase: &str,
enterprise_id: &str,
) -> Result<serde_json::Value>;
async fn create_address(
&self,
wallet_id: &str,
identifier: &str,
forwarder_version: i32,
) -> Result<serde_json::Value>;
async fn get_wallet_list(&self) -> Result<serde_json::Value>;
}
#[async_trait]
impl BitGoWalletAPI for BitGoClient {
/// This API call creates a new wallet. Under the hood, the SDK (or BitGo Express) does the following:
///
/// 1.Creates the user keychain locally on the machine, and encrypts it with the provided passphrase (skipped if userKey is provided).
/// 2.Creates the backup keychain locally on the machine.
/// 3.Uploads the encrypted user keychain and public backup keychain.
/// 4.Creates the BitGo key (and the backup key if backupXpubProvider is set) on the service.
/// 5.Creates the wallet on BitGo with the 3 public keys above.
async fn generate_wallet(
&self,
name: &str,
identifier: &str,
passphrase: &str,
) -> Result<serde_json::Value> {
let request_url = format!(
"{url}/api/v2/{coin_type}/wallet/generate",
url = self.endpoint,
coin_type = identifier,
);
self.post_api(
&request_url,
&json!({
"label": name,
"passphrase": passphrase,
}),
)
.await
}
/// This API call creates a new wallet. Under the hood, the SDK (or BitGo Express) does the following:
///
/// 1.Creates the user keychain locally on the machine, and encrypts it with the provided passphrase (skipped if userKey is provided).
/// 2.Creates the backup keychain locally on the machine.
/// 3.Uploads the encrypted user keychain and public backup keychain.
/// 4.Creates the BitGo key (and the backup key if backupXpubProvider is set) on the service.
/// 5.Creates the wallet on BitGo with the 3 public keys above.
async fn generate_enterprise_wallet(
&self,
name: &str,
identifier: &str,
passphrase: &str,
enterprise_id: &str,
) -> Result<serde_json::Value> {
let request_url = format!(
"{url}/api/v2/{coin_type}/wallet/generate",
url = self.endpoint,
coin_type = identifier,
);
self.post_api(
&request_url,
&json!({
"label": name,
"passphrase": passphrase,
"enterprise":enterprise_id,
}),
)
.await
}
/// This API call is used to create a new receive address for your wallet.
/// You may choose to call this API whenever a deposit is made.
/// The BitGo API supports millions of addresses.
async fn create_address(
&self,
wallet_id: &str,
identifier: &str,
forwarder_version: i32,
) -> Result<serde_json::Value> {
let request_url = format!(
"{url}/api/v2/{coin_type}/wallet/{wallet_id}/address",
url = self.endpoint,
coin_type = identifier,
wallet_id = wallet_id,
);
self.post_api(
&request_url,
&json!({
"forwarderVersion":forwarder_version,
}),
)
.await
}
async fn get_wallet_list(&self) -> Result<serde_json::Value> {
let request_url = format!("{url}/api/v2/wallets/", url = self.endpoint,);
self.get_api(&request_url, &json!({})).await
}
}