vrf_wasm/rng/
mod.rs

1//! Random number generation implementations for different target environments.
2//!
3//! This module provides conditional compilation for RNG implementations:
4//! - Browser: Uses crypto.getRandomValues() via getrandom with "js" feature
5//! - NEAR: Uses env::random_seed() with enhanced entropy via ChaCha20
6
7// Always compile all available modules when their features are enabled
8#[cfg(feature = "browser")]
9pub mod browser;
10
11#[cfg(feature = "near")]
12pub mod near;
13
14// Export implementation-specific types
15#[cfg(feature = "browser")]
16pub use browser::{WasmRng as BrowserWasmRng, WasmRngFromSeed as BrowserWasmRngFromSeed};
17
18#[cfg(feature = "near")]
19pub use near::{WasmRng as NearWasmRng, WasmRngFromSeed as NearWasmRngFromSeed};
20
21// Default exports with priority system for backward compatibility
22#[cfg(feature = "browser")]
23pub use browser::{WasmRng, WasmRngFromSeed};
24
25#[cfg(all(feature = "near", not(feature = "browser")))]
26pub use near::{WasmRng, WasmRngFromSeed};
27
28// Re-export rand_core traits for consistency
29pub use rand_core::{CryptoRng, RngCore};
30
31/// Get the current default RNG implementation name
32pub fn get_rng_implementation() -> &'static str {
33    #[cfg(feature = "browser")]
34    {
35        "browser"
36    }
37    #[cfg(all(feature = "near", not(feature = "browser")))]
38    {
39        "near"
40    }
41}