Expand description
§Quorum Vault Client
A Rust client for the Quorum Vault Plugin API.
This client based on the Vault Client.
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
:
[dependencies]
quorum-vault-client = "0.1.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 for communicating to Vault.
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.
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:
> 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.
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:
> result: EthereumAccountsResponse { keys: [0x1a669bad7bda1f553087df8568b8782bcb0023ac, 0x8d3113e29cb92f44f1762e52d2a0276509b36b82] }
Read Ethereum Wallet
The following example gets the Ethereum Wallet by address.
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:
> result: EthereumAccountResponse { address: 0x8d3113e29cb92f44f1762e52d2a0276509b36b82, compressed_public_key: "0x03b1c069a45b14697567661e6426ab0639f73762d7526765b2bd6891a73d84ebb5", public_key: "0x04b1c069a45b14697567661e6426ab0639f73762d7526765b2bd6891a73d84ebb57e6abbec4c9738a025d1a611e431ecf006227dbf6ca400f85518df70e5d101cb", namespace: "" }
Sign Ethereum Transaction
The following example signs the Ethereum Transaction.
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 mut tx: TransactionRequest = TransactionRequest::builder()
.from(address)
.to(address)
.value(U256::from_dec_str("1000000000000000000").unwrap())
.gas(U256::from(21000))
.nonce(U256::from(0))
.build();
tx.gas_price = Some(U256::from(1));
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:
> signature: EthereumSignTransactionResponse { signature: "0xf29001752503d05ae83874193a8d866d49fc897c1a2fcb6229a0c61e4b5663f7097817a26f4c6014bbfd24c484bad9587c9c627c6f70d020f8638a4067bb78e801" }
§Keys
Create Key
The following example creates a new key in the Vault.
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:
> 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": "value0"}, updated_at: "2023-01-30T09:08:22.217224856Z", version: 1 }
Read Key
The following example reads the key by id.
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:
> 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": "value0"}, updated_at: "2023-01-30T09:08:22.217224856Z", version: 1 }
List Keys
The following example lists all keys in the Vault.
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:
> result: KeysResponse { keys: ["some-id"] }
Delete Key
The following example deletes the key by id.
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.
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:
> signature: SignResponse { signature: "Z1ibkBIGjMLh5pSR5mFZ5NbesrM57g-FGkFr0sbIyIlI_M0BYVN_LD-Nt7x1wUo6AoLQyL0I-z7PD8MsdgmkhQ==" }
Modules§
Structs§
- Access
List Item - Access list item
- Account
Diff - Serde-friendly
AccountDiff
shadow. - Block
- The block type returned from RPC calls.
This is generic over a
TX
type. - Block
Header - The block header type returned from RPC calls.
- Block
Trace - Ad-Hoc trace API type
- Bytes
- Raw bytes wrapper
- Bytes
Array - A wrapper type for array of bytes.
- Call
- Call response
- Call
Request - Call contract request (eth_call / eth_estimateGas)
- Call
Result - Call Result
- Changed
Type - Aux type for Diff::Changed.
- Create
- Create response
- Create
Result - Craete Result
- EthProtocol
Info - eth chain version, difficulty, and head of chain which soft fork? Olympic, Frontier, Homestead, Metropolis, Serenity, etc.
- FeeHistory
- The fee history type returned from
eth_feeHistory
call. - Filter
- Filter
- Filter
Builder - Filter Builder
- H64
- H128
- H160
- Fixed-size uninterpreted hash type with 20 bytes (160 bits) size.
- H256
- Fixed-size uninterpreted hash type with 32 bytes (256 bits) size.
- H512
- Fixed-size uninterpreted hash type with 64 bytes (512 bits) size.
- H520
- H2048
- Bloom hash type with 256 bytes (2048 bits) size.
- Log
- A log produced by a transaction.
- Memory
Diff - A diff of some chunk of memory.
- Parity
Peer Info - details of a peer
- Parity
Peer Type - Stores active peer count, connected count, max connected peers and a list of peers for parity node
- Parity
Pending Transaction Filter - Filter for pending transactions (only openethereum/Parity)
- Parity
Pending Transaction Filter Builder - Filter Builder
- Parse
Signature Error - An error parsing a raw signature.
- Peer
Network Info - ip address of both local and remote
- Peer
Protocols Info - chain protocol info
- PipProtocol
Info - pip version, difficulty, and head
- Proof
- Proof struct returned by eth_getProof method
- RawTransaction
- Raw bytes of a signed, but not yet sent transaction
- Recovery
- Data for recovering the public address of signed data.
- Reward
- Reward action
- Signed
Data - Struct representing signed data returned from
Accounts::sign
method. - Signed
Transaction - Data for offline signed transaction
- State
Diff - Serde-friendly
StateDiff
shadow. - Storage
Diff - A diff of some storage value.
- Suicide
- Suicide
- Sync
Info - Information about current blockchain syncing operations.
- Trace
- Trace-Filtering API trace type
- Trace
Filter - Trace filter
- Trace
Filter Builder - Trace Filter Builder
- Transaction
- Description of a Transaction, pending or in the chain.
- Transaction
Parameters - Transaction data for signing.
- Transaction
Receipt - “Receipt” of an executed transaction: details of its execution.
- Transaction
Request - Send Transaction Parameters
- Transaction
Trace - Trace
- Txpool
Content Info - Transaction Pool Content Info
- Txpool
Inspect Info - Transaction Pool Inspect Info
- Txpool
Status - Transaction Pool Status
- U64
- Little-endian large integer type Unsigned 64-bit integer.
- U128
- Little-endian large integer type 128-bit unsigned integer.
- U256
- Little-endian large integer type 256-bit unsigned integer.
- VMExecuted
Operation - A record of an executed VM operation.
- VMOperation
- A record of the execution of a single VM operation.
- VMTrace
- A record of a full VM trace for a CALL/CREATE.
- Vault
Client - A client which can be used to execute calls against a Vault server.
- Vault
Client Settings Builder - Builder for
VaultClientSettings
. - Work
- Miner’s work package
Enums§
- Action
- Action
- Action
Type - An external action type.
- BlockId
- Block Identifier
- Block
Number - Block Number
- Call
Type - Call type.
- Diff
- Serde-friendly
Diff
shadow. - Filter
Condition - Condition to filter pending transactions
- Recovery
Message - Recovery message data.
- Res
- Response
- Reward
Type - Reward type.
- Sync
State - The current state of blockchain syncing operations.
- ToFilter
- To Filter
- Trace
Type - Description of the type of trace to make
- Transaction
Condition - Represents condition on minimum block number or block timestamp.
- Transaction
Id - Transaction Identifier
Traits§
- Client
- The client interface capabale of interacting with API functions
Type Aliases§
- Access
List - Access list
- Address
- Address
- Index
- Index in block