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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
//! # Quorum Vault Client
//!
//! ---
//!
//! A Rust client for the [Quorum Vault Plugin](https://github.com/ConsenSys/quorum-hashicorp-vault-plugin) API.
//!
//! > This client based on the [Vault Client](https://github.com/jmgilman/vaultrs).
//!
//! The following backends are supported:
//! * Ethereum
//! * Create Ethereum Account
//! * List Ethereum Accounts
//! * Read Ethereum Account by Address
//! * Sign Ethereum Transaction (only Legacy)
//! * Keys
//! * Create Key
//! * List Keys
//! * Read Key
//! * Delete Key
//! * Sign Data
//! * Import Private Key
//!
//! ## Installation
//! Add the following to your `Cargo.toml`:
//! ```toml
//! [dependencies]
//! quorum-vault-client = "2.0.0"
//! ```
//!
//! ## Usage
//!
//! ### Basic
//!
//! The client is used to configure the connection to Vault and is required to
//! be passed to all API calls for execution. Behind the scenes it uses an
//! asynchronous client from [Reqwest](https://docs.rs/reqwest/) for
//! communicating to Vault.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder};
//!
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//! ```
//!
//! ### Ethereum
//!
//! **Create new Ethereum Wallet**
//!
//! The following example creates a new Ethereum Wallet in the Vault.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder};
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! // By default the plugin mounts the Ethereum backend at the path "quorum"
//! let created_account = quorum_vault_client::api::ethereum::create_account(&client, "quorum").await.unwrap();
//! println!("result: {:?}", created_account);
//! }
//!
//! ```
//!
//! Result of the execution is the following:
//! ```bash
//! > result: EthereumAccountResponse { address: 0x1a669bad7bda1f553087df8568b8782bcb0023ac, compressed_public_key: "0x020e44fde7435da96f8260788a89d4c37f2b3d96fd936dd978b886de6872d73062", public_key: "0x040e44fde7435da96f8260788a89d4c37f2b3d96fd936dd978b886de6872d730629c94a4803d3073b0bbe9a3d46f201eef5beec04d0e6f464e07704c159edd2c64", namespace: "" }
//! ```
//!
//! **List all Ethereum Wallets**
//!
//! The following example gets list of all Ethereum Wallets in the Vault.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder};
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! let list_accounts = quorum_vault_client::api::ethereum::list_accounts(&client, "quorum").await.unwrap();
//! println!("result: {:?}", list_accounts);
//! }
//!
//! ```
//!
//! Result of the execution is the following:
//!
//! ```bash
//! > result: EthereumAccountsResponse { keys: [0x1a669bad7bda1f553087df8568b8782bcb0023ac, 0x8d3113e29cb92f44f1762e52d2a0276509b36b82] }
//! ```
//!
//! **Read Ethereum Wallet**
//!
//! The following example gets the Ethereum Wallet by address.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder, Address};
//! use std::str::FromStr;
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! let address = Address::from_str("0x8d3113e29CB92F44F1762E52D2a0276509b36b82").unwrap();
//! let read_account = quorum_vault_client::api::ethereum::read_account(&client, "quorum", address).await.unwrap();
//! println!("result: {:?}", read_account);
//! }
//!
//! ```
//!
//! Result of the execution is the following:
//!
//! ```bash
//! > result: EthereumAccountResponse { address: 0x8d3113e29cb92f44f1762e52d2a0276509b36b82, compressed_public_key: "0x03b1c069a45b14697567661e6426ab0639f73762d7526765b2bd6891a73d84ebb5", public_key: "0x04b1c069a45b14697567661e6426ab0639f73762d7526765b2bd6891a73d84ebb57e6abbec4c9738a025d1a611e431ecf006227dbf6ca400f85518df70e5d101cb", namespace: "" }
//! ```
//!
//! **Sign Ethereum Transaction**
//!
//! The following example signs the Ethereum Transaction.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder, TransactionRequest, Address, U256};
//! use std::str::FromStr;
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! let address = Address::from_str("0x8d3113e29CB92F44F1762E52D2a0276509b36b82").unwrap();
//! let tx: TransactionRequest = TransactionRequest::default()
//! .from(address)
//! .to(address)
//! .value(U256::from_str("1000000000000000000").unwrap())
//! .gas_limit(21000)
//! .gas_price(1)
//! .nonce(0);
//!
//! let sign_transaction = quorum_vault_client::api::ethereum::sign_transaction(&client, "quorum", 1, tx).await.unwrap();
//! println!("result: {:?}", sign_transaction);
//! }
//!
//! ```
//!
//! Result of the execution is the following:
//!
//! ```bash
//! > result: EthereumSignTransactionResponse { signature: "0xf29001752503d05ae83874193a8d866d49fc897c1a2fcb6229a0c61e4b5663f7097817a26f4c6014bbfd24c484bad9587c9c627c6f70d020f8638a4067bb78e801" }
//! ```
//!
//! ### Keys
//!
//! **Create Key**
//!
//! The following example creates a new key in the Vault.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder};
//! use quorum_vault_client::api::keys::KeyCryptoAlgorithm;
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! let created_key = quorum_vault_client::api::keys::create_key(&client, "quorum", "some-id", KeyCryptoAlgorithm::Secp256k1, [("tag".to_string(), "value".to_string())].into_iter().collect()).await.unwrap();
//!
//! println!("result: {:?}", created_key);
//! }
//! ```
//!
//! Result of the execution is the following:
//!
//! ```bash
//! > result: KeyResponse { created_at: "2023-01-30T09:08:22.217224856Z", curve: "secp256k1", id: "some-id", namespace: "", public_key: "BIwm5UiSGTiXVRlB_rS7qYSzQ6XZbaWfUOJKVicU85q-N7zuAak2JQfAHUs2Sm2WAA7YyWdN7_4UFJFggEa6AKw=", signing_algorithm: "ecdsa", tags: {"tag": "value"}, updated_at: "2023-01-30T09:08:22.217224856Z", version: 1 }
//! ```
//!
//! **Read Key**
//!
//! The following example reads the key by id.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder};
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! let key = quorum_vault_client::api::keys::read_key(&client, "quorum", "some-id").await.unwrap();
//! println!("result: {:?}", key);
//! }
//! ```
//!
//! Result of the execution is the following:
//!
//! ```bash
//! > result: KeyResponse { created_at: "2023-01-30T09:08:22.217224856Z", curve: "secp256k1", id: "some-id", namespace: "", public_key: "BIwm5UiSGTiXVRlB_rS7qYSzQ6XZbaWfUOJKVicU85q-N7zuAak2JQfAHUs2Sm2WAA7YyWdN7_4UFJFggEa6AKw=", signing_algorithm: "ecdsa", tags: {"tag": "value"}, updated_at: "2023-01-30T09:08:22.217224856Z", version: 1 }
//! ```
//!
//! **List Keys**
//!
//! The following example lists all keys in the Vault.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder};
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! let keys = quorum_vault_client::api::keys::list_keys(&client, "quorum").await.unwrap();
//! println!("result: {:?}", keys);
//! }
//! ```
//!
//! Result of the execution is the following:
//!
//! ```bash
//! > result: KeysResponse { keys: ["some-id"] }
//! ```
//!
//! **Delete Key**
//!
//! The following example deletes the key by id.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder};
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! quorum_vault_client::api::keys::destroy_key(&client, "quorum", "some-id").await.unwrap();
//! }
//! ```
//!
//! **Sign data**
//!
//! The following example signs the data by key id.
//!
//! ```no_run
//! use quorum_vault_client::{Client, VaultClient, VaultClientSettingsBuilder};
//!
//! #[tokio::main]
//! async fn main() {
//! // Create a client
//! let client = VaultClient::new(
//! VaultClientSettingsBuilder::default()
//! .address("https://127.0.0.1:8200")
//! .token("TOKEN")
//! .build()
//! .unwrap()
//! ).unwrap();
//!
//! let signature = quorum_vault_client::api::keys::sign(&client, "quorum", "some-id", "some-data".as_bytes()).await.unwrap();
//! println!("signature: {:?}", signature);
//! }
//! ```
//!
//! Result of the execution is the following:
//!
//! ```bash
//! > signature: SignResponse { signature: "Z1ibkBIGjMLh5pSR5mFZ5NbesrM57g-FGkFr0sbIyIlI_M0BYVN_LD-Nt7x1wUo6AoLQyL0I-z7PD8MsdgmkhQ==" }
//! ```
extern crate derive_builder;
// re-export
pub use *;
pub use TransactionRequest;
pub use ;