Skip to main content

Crate stellar_vrf_sdk

Crate stellar_vrf_sdk 

Source
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.
VrfClientConfig
Configuration for the VRF client.
VrfProof
A fulfilled VRF proof retrieved from the contract.
VrfRequestEvent
A VRF request event from the contract.

Enums§

Network
Network selection for the VRF client.
VrfError

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_betaDeprecated
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’s reduce_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.