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 = "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 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 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:
> result: 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": "value"}, 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": "value"}, 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==" }Re-exports§
pub use alloy_primitives::B64;pub use alloy_primitives::B128;pub use alloy_primitives::B256;pub use alloy_primitives::B512;pub use alloy_primitives::BlockHash;pub use alloy_primitives::BlockNumber;pub use alloy_primitives::BlockTimestamp;pub use alloy_primitives::ChainId;pub use alloy_primitives::I8;pub use alloy_primitives::I16;pub use alloy_primitives::I32;pub use alloy_primitives::I64;pub use alloy_primitives::I128;pub use alloy_primitives::I160;pub use alloy_primitives::I256;pub use alloy_primitives::Selector;pub use alloy_primitives::StorageKey;pub use alloy_primitives::StorageValue;pub use alloy_primitives::TxHash;pub use alloy_primitives::TxIndex;pub use alloy_primitives::TxNonce;pub use alloy_primitives::TxNumber;pub use alloy_primitives::U8;pub use alloy_primitives::U16;pub use alloy_primitives::U32;pub use alloy_primitives::U64;pub use alloy_primitives::U128;pub use alloy_primitives::U160;pub use alloy_primitives::U256;pub use alloy_primitives::U512;pub use alloy_primitives::bytes;pub use alloy_primitives::const_hex as hex;pub use alloy_primitives::ruint;pub use alloy_primitives::Uint;pub use alloy_primitives::serde as serde_hex;
Modules§
- aliases
- Type aliases for common primitive types.
- api
- error
- map
- Re-exports of map types and utilities.
- utils
- Common Ethereum utilities.
Macros§
- address
- Converts a sequence of string literals containing hex-encoded data
into a new
Addressat compile time. - b64
- Converts a sequence of string literals containing hex-encoded data
into a new
B64at compile time. - b128
- Converts a sequence of string literals containing hex-encoded data
into a new
B128at compile time. - b256
- Converts a sequence of string literals containing hex-encoded data
into a new
B256at compile time. - b512
- Converts a sequence of string literals containing hex-encoded data
into a new
B512at compile time. - bloom
- Converts a sequence of string literals containing hex-encoded data
into a new
Bloomat compile time. - bytes
- Converts a sequence of string literals containing hex-encoded data into a
new
Bytesat compile time. - fixed_
bytes - Converts a sequence of string literals containing hex-encoded data
into a new
FixedBytesat compile time. - hex
- Macro for converting sequence of string literals containing hex-encoded data into an array of bytes.
- try_vec
- Tries to create a
Veccontaining the arguments. - wrap_
fixed_ bytes - Wrap a fixed-size byte array in a newtype, delegating all methods to the
underlying
crate::FixedBytes.
Structs§
- Address
- An Ethereum address, 20 bytes in length.
- Address
Checksum Buffer - Stack-allocated buffer for efficiently computing address checksums.
- BigInt
Conversion Error - The error type that is returned when conversion to or from a integer fails.
- Bloom
- Ethereum 256 byte bloom filter.
- Bytes
- Wrapper type around
bytes::Bytesto support “0x” prefixed hex strings. - Fixed
Bytes - A byte array of fixed length (
[u8; N]). - Function
- An Ethereum ABI function pointer, 24 bytes in length.
- Keccak256
- Simple
Keccak-256hasher. - Log
- A log consists of an address, and some log data.
- LogData
- An Ethereum event log object.
- Sealed
- A consensus hashable item, with its memoized hash.
- Signature
- An Ethereum ECDSA signature.
- Signed
- Signed integer wrapping a
ruint::Uint. - Transaction
Request - Represents all transaction requests to/from RPC.
- Vault
Client - A client which can be used to execute calls against a Vault server.
- Vault
Client Settings Builder - Builder for
VaultClientSettings.
Enums§
- Address
Error - Error type for address checksum validation.
- Bloom
Input - Input to the
Bloom::accruemethod. - Parse
Signed Error - The error type that is returned when parsing a signed integer.
- Sign
- Enum to represent the sign of a 256-bit signed integer.
- Signature
Error - Errors in signature parsing or verification.
- TxKind
- The
tofield of a transaction. Either a target address, or empty for a contract creation.
Constants§
- BLOOM_
BITS_ PER_ ITEM - Number of bits to set per input in Ethereum bloom filter.
- BLOOM_
SIZE_ BITS - Size of the bloom filter in bits
- BLOOM_
SIZE_ BYTES - Size of the bloom filter in bytes.
- KECCA
K256_ EMPTY - The Keccak-256 hash of the empty string
"".
Traits§
- Client
- The client interface capabale of interacting with API functions
- Fixed
Bytes Slice Ext - Extension trait for flattening a slice of
FixedBytesto a byte slice. - Fixed
Bytes VecExt - Extension trait for flattening a
VecofFixedBytesto aVec<u8>. - Into
LogData - Trait for an object that can be converted into a log data object.
- Sealable
- Sealeable objects.
Functions§
- eip191_
hash_ message - Hash a message according to EIP-191 (version
0x01). - keccak256
- Simple interface to the
Keccak-256hash function. - keccak256_
uncached - Simple interface to the
Keccak-256hash function. - logs_
bloom - Compute the logs bloom filter for the given logs.
- normalize_
v - Attempts to normalize the v value to a boolean parity value.
- to_
eip155_ v - Applies EIP-155.