setRustApi method
void
setRustApi({})
Selects the Rust backend via Bu.
Cross-platform safe: each platform reads only its own fields.
- Native VM:
libraryPathselects the dynamic library (DynamicLibrary.open);nulluses the platform default name. The wasm fields are ignored. - Web:
wasmGlueUrlselects the wasm-bindgen glue ES module (defaultwasm_assets/bu.js, relative to the page), loaded with a dynamicimport();wasmModuleUrloverrides the.wasmlocation (nulldefaults tobu_bg.wasmnext to the glue via the module'simport.meta.url, or a pre-setglobalThis.__bu_wasm_url).libraryPathis ignored. The glue must be a--target webbuild (seetool/build_backends.dart --wasmin blockchain_utils_connector): a--target no-modulesclassic script has no exports and fails to load — no companion files are needed. AwaitBu.ensureWasmLoaded(seeBlockchainUtilsTestApi.initWasmBrowser) before calling this on web, asBu.initalone does not fetch the module.
Implementation
void setRustApi({
String? libraryPath,
String? wasmGlueUrl,
String? wasmModuleUrl,
/// Route [QuickCrypto.generateRandom] through the backend RNG
/// (seeded from Fortuna on first use). Pass `false` to keep the
/// current generator (e.g. a custom one from `setupRandom`).
bool randomFromBackend = true,
bool seal = false,
}) {
_checkNotSealed('setRustApi');
final bu = Bu.init(
BuConfig(
libraryPath: libraryPath,
wasmGlueUrl: wasmGlueUrl,
wasmModuleUrl: wasmModuleUrl,
),
);
final frostApi = NativeFrostApi(bu.frost);
blockchainUtils.setApi(
DefaultBlockchainUtilsApi(
hash: NativeHashApi(bu.hash),
blockCipher: NativeBlockCipherApi(bu.blockCipher),
ff1: ValidatedFf1Api(NativeFf1Api(bu.ff1)),
ed25519: NativeEd25519CurveApi(bu.curves.ed25519()),
secp256k1: NativeSecp256k1CurveApi(bu.curves.secp256k1()),
secp256r1: NativeSecp256r1CurveApi(bu.curves.secp256r1()),
jubjub: NativeJubJubCurveApi(bu.curves.jubjub()),
signing: DefaultBlockchainUtilsSigningApi(
secp256k1: ValidatedSecp256k1SigningApi(
NativeSecp256k1SigningApi(bu.secp256k1Signing),
),
ed25519: NativeED25519SigningApi(bu.ed25519Signing),
secp256r1: NativeSecp256r1SigningApi(bu.secp256r1Signing),
bls: NativeBlsSigningApi(bu.blsSigning),
mldsa: NativeMLDSASigningApi(bu.mlDsa),
jubjub: NativeRedJubJubSigningApi(bu.reddsa),
pallas: NativeRedPallasSigningApi(bu.reddsa),
sr25519: NativeSr25519SigningApi(bu.sr25519),
),
aed: NativeAEADApi(bu.aead),
streamCipher: NativeStreamCipherApi(bu.streamCipher),
keyDerivation: NativeKeyDerivationApi(bu.bindings),
g1: NativeG1ProjectiveCurveApi(bu.curves.g1()),
g2: NativeG2ProjectiveCurveApi(bu.curves.g2()),
bn254G1: NativeBn254G1CurveApi(bu.curves.bn254G1()),
bn254G2: NativeBn254G2CurveApi(bu.curves.bn254G2()),
muSig2: NativeMuSig2Api(bu.musig2),
frost: frostApi,
dkls23: ValidatedDkls23KeysApi(NativeDkls23KeysApi(bu.dkls23)),
pallas: NativePallasCurveApi(bu.curves.pallas()),
vesta: NativeVestaCurveApi(bu.curves.vesta()),
ristretto: NativeRistrettoCurveApi(bu.curves.ristretto()),
x25519: NativeX25519Api(bu.x25519),
monero: NativeMoneroApi(bu.monero),
hw: NativeHwApi(bu.hw),
sapling: NativeSaplingApi(bu.sapling),
orchard: NativeOrchardApi(bu.orchard),
merkle: NativeMerkleApi(bu.merkle),
rng: NativeRngApi(bu.rng),
),
);
_backend = bu;
// Wire the RNG before sealing: once sealed, setupBackendRng throws.
if (randomFromBackend) QuickCrypto.setupBackendRng();
if (seal) this.seal();
}