Expand description
stellar-vrf-sdk — Rust SDK for the Stellar VRF Oracle
Provides a high-level async client for interacting with the Stellar VRF Oracle contract via the Soroban JSON-RPC API.
§Example
use stellar_vrf_sdk::{VrfClient, VrfClientConfig, Network};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = VrfClient::new(VrfClientConfig {
contract_id: "CD5K4NNYNG3ZFCET24F3SL6MSYYRD5I2BSWW5K3LFQVIKYHRY2ICVIVX".into(),
network: Network::Testnet,
secret_key: String::new(), // unused: read-only client
});
// Check if request #1 is fulfilled
let fulfilled = client.is_fulfilled(1).await?;
println!("Fulfilled: {}", fulfilled);
// Derive a uniform roll in [1, 100] (exact, no modulo bias)
let roll = client.derive_random_in_range(1, 1, 100).await?;
println!("Roll: {}", roll);
// Or reproduce it offline from the verified beta:
let beta = client.get_beta(1).await?;
let span = 100;
assert_eq!(roll, 1 + stellar_vrf_sdk::derive_range_from_beta(&beta, 1, span)?);
Ok(())
}Structs§
- VrfClient
- High-level async client for the Stellar VRF Oracle.
- VrfClient
Config - Configuration for the VRF client.
- VrfProof
- A fulfilled VRF proof retrieved from the contract.
- VrfRequest
Event - A VRF request event from the contract.
Enums§
Constants§
- DERIVE_
DOMAIN - Domain prefix of every contract derivation (
DERIVE_DOMAIN). - MAX_
DERIVE_ DOMAIN_ LEN - Longest domain accepted by
derive_range_for_domain(MAX_DERIVE_DOMAIN_LEN).
Functions§
- derive_
random_ from_ beta Deprecated - Derive a random number in the inclusive range
[min, max]client-side from a beta output, without a contract call. - derive_
range_ for_ domain_ from_ beta - Offline equivalent of the contract’s
derive_range_for_domain(request_id, domain, max). - derive_
range_ from_ beta - Offline equivalent of the contract’s
derive_random_in_range(request_id, max): an exactly uniform value in[0, max). - derive_
u64_ from_ beta - Offline equivalent of the contract’s
derive_random(request_id). - reduce_
uniform - Exact-uniform reduction of a 32-byte hash into
[0, max), identical to the contract’sreduce_uniform(). - strkey_
encode_ contract - Encode a 32-byte contract hash as a
C...contract address (version byte 2 << 3). - strkey_
encode_ ed25519 - Encode an ed25519 public key as a
G...account address. - to_hex
- Convert bytes to hex string.