/* tslint:disable */ /* eslint-disable */ /** * Split a u64 amount into (lo, hi) u32 pair matching the circuit representation. * * Returns `[amount_lo, amount_hi]` as a `Uint32Array` of length 2. * * ```js * const [lo, hi] = amount_split(123456789n); * ``` */ export function amount_split(amount: bigint): Uint32Array; /** * Backward-compatible alias for `crash_rtp_percent`. */ export function aviato_rtp_percent(): number; /** * Reconstruct the 30 dealt Blackjack rank codes from the fairness seeds. * * This is the SINGLE client/backend-side mirror of the native shoe unfold in * `tx_validator::blackjack::unfold_shoe` and the in-circuit shuffle: it computes * `mix = Poseidon2(server_seed ‖ user_secret_random)` and the per-step swap * randomness `low32(Poseidon2(mix ‖ k))`, then defers the deterministic * 30-swap partial Fisher–Yates over the fixed 416-card layout to the pure * `rolly_game_core::blackjack::deal_shoe`. Mixing the player-chosen * `user_secret_random` into the seed makes the shuffle a mutual commit–reveal, * so neither the operator nor the player can pre-grind a shoe. * * `server_seed` must be 8 elements (the full fairness preimage); `user_secret_random` * must be 4 elements (`string_to_user_seed(user_seed_source)`). * * **Output**: `Uint8Array` of length 30 — rank codes `0..=12` (Ace=0, 2..9=1..8, * 10/J/Q/K=9..12). Suits are cosmetic and restored off-engine. * * ```js * const shoe = blackjack_deal_shoe(serverSeed8, userSecret4); // length 30 * ``` */ export function blackjack_deal_shoe(server_seed: BigUint64Array, user_secret_random: BigUint64Array): Uint8Array; /** * Pack a Blackjack action sequence into the two base-8 halves the rollup records * as `prediction_lo` / `prediction_hi` (`actions[0..10]` → lo, `actions[10..20]` * → hi). Single-sources `rolly_game_core::blackjack::pack_actions` so the * backend feeds the WitnessEngine exactly what the circuit re-derives. * * `actions` are the `ACTION_*` codes (1..=6). **Output**: `Uint32Array` of * length 2 = `[prediction_lo, prediction_hi]`. */ export function blackjack_pack_actions(actions: Uint8Array): Uint32Array; /** * CoinFlip multiplier × 10000 (19800 = 1.98×). Canonical source for backend/frontend. */ export function coinflip_multiplier_x10000(): number; /** * CoinFlip RTP percent (99). Canonical source for backend/frontend. */ export function coinflip_rtp_percent(): number; /** * Compute address_hash = Poseidon2(addr_byte_0, ..., addr_byte_19). * Takes a hex address string (with or without 0x prefix), returns [u64; 4]. */ export function compute_address_hash(address_hex: string): BigUint64Array; /** * Backward-compatible alias for `compute_crash_point`. */ export function compute_aviato_point(random: BigUint64Array): number; /** * Extract crash point (×100) from raw server seed fields. * * `random` must be exactly 4 elements (first 4 fields of server_seed). * Returns the clamped crash multiplier ×100 (100..=1_000_000, i.e. 1.00x..10000.00x). */ export function compute_crash_point(random: BigUint64Array): number; /** * Extract the 10 drawn numbers from Poseidon2 random output using * the combinatorial number system: `combo_index = random[0] % C(40,10)`. * * `random` must be exactly 4 elements. * Returns `Uint8Array` of length 10 (sorted ascending, each in [0, 39]). */ export function compute_drawn_keno(random: BigUint64Array): Uint8Array; /** * Compute dice multiplier × 10000 from win_numbers count. * * Formula: `9_900_000 / win_numbers` (integer division = floor). * `win_numbers` must be in [1, 950]. */ export function compute_multi_dice(win_numbers: number): bigint; /** * Backward-compatible alias for `compute_payout_crash`. */ export function compute_payout_aviato(random: BigUint64Array, bet_atomic: bigint, cashout_x100: number): BigUint64Array; /** * Client-side provably-fair verification of a full Blackjack round. * * Reconstructs the fair shoe from `(server_seed ‖ user_secret_random)` (see * [`blackjack_deal_shoe`]), decodes the base-8 `prediction_lo` / `prediction_hi` * action halves, and replays the exact same state machine the circuit and the * tx-validator run (`rolly_game_core::blackjack::replay_full`). This lets a * player independently confirm the settled `win`/`bet` off-chain; it is NOT on * the tx/settlement path. * * `server_seed` must be 8 elements (the revealed fairness preimage); * `user_secret_random` must be 4 elements (`string_to_user_seed(...)`). * `base_bet` is the base stake in atomic units. The returned `total_staked` * grows with double/split/insurance exactly as the engine books them. * * **Output**: a JS object matching [`BlackjackVerifyResult`]. * * Returns an error if the decoded action list contains an invalid code * (outside `1..=6`), mirroring the tx-validator's typed rejection. * * ```js * const res = compute_payout_blackjack(serverSeed8, userSecret4, lo, hi, betAtomic); * // res.win_amount, res.total_staked, res.shoe (length 30), * // res.first_cards / res.second_cards / res.dealer_cards (rank codes), * // res.first_kind / res.second_kind (per-hand type: 0=bet,1=hit,2=stand, * // 3=double,4=split,5=insurance; a closed hand reports 2), * // res.first_amount / res.second_amount (per-hand staked, atomic), * // res.first_win / res.second_win (per-hand win, atomic, pre-cap), ... * ``` */ export function compute_payout_blackjack(server_seed: BigUint64Array, user_secret_random: BigUint64Array, prediction_lo: number, prediction_hi: number, base_bet: bigint): any; /** * Full coinflip payout computation — pure integer arithmetic, zero floats. * * `random`: 4 Goldilocks field elements (Poseidon2 output). * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000). * `prediction`: 0 or 1. * * Returns `BigUint64Array[4]`: `[win_amount, roll (0|1), is_win (0|1), multiplier×10000]`. */ export function compute_payout_coinflip(random: BigUint64Array, bet_atomic: bigint, prediction: number): BigUint64Array; /** * Full crash payout computation — pure integer arithmetic, zero floats. * * `random`: 4 Goldilocks field elements (first 4 fields of raw server_seed). * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000). * `cashout_x100`: multiplier at which the user cashed out (×100). * - 0 = user did NOT cash out (loss). * - 100..=1_000_000 = user stopped at this multiplier. * * Returns `BigUint64Array[4]`: `[win_amount, crash_x100, is_win (0|1), multiplier×10000]`. */ export function compute_payout_crash(random: BigUint64Array, bet_atomic: bigint, cashout_x100: number): BigUint64Array; /** * Full dice payout computation — pure integer arithmetic, zero floats. * * `random`: 4 Goldilocks field elements (Poseidon2 output). * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000). * `game_mode`: 0=Under, 1=Over, 2=In, 3=Out. * `prediction_lo` / `prediction_hi`: prediction range bounds (0..999). * * Returns `BigUint64Array[4]`: `[win_amount, roll_number, is_win (0|1), multiplier×10000]`. */ export function compute_payout_dice(random: BigUint64Array, bet_atomic: bigint, game_mode: number, prediction_lo: number, prediction_hi: number): BigUint64Array; /** * Full keno payout computation — pure integer arithmetic, zero floats. * * `random`: 4 Goldilocks field elements (Poseidon2 output). * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000). * `risk`: 0=low, 1=medium, 2=high. * `selected`: player-chosen numbers (0-indexed, each in [0, 39]). * * Returns `BigUint64Array[4]`: `[win_amount, match_count, is_win (0|1), multiplier×10000]`. */ export function compute_payout_keno(random: BigUint64Array, bet_atomic: bigint, risk: number, selected: Uint8Array): BigUint64Array; /** * Full limbo payout computation — pure integer arithmetic, zero floats. * * `random`: 4 Goldilocks field elements (Poseidon2 output). * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000). * `prediction_x100`: target multiplier x 100 (101..999999, i.e. 1.01x-9999.99x). * * Returns `BigUint64Array[4]`: `[win_amount, multiplier_x100, is_win (0|1), payout_multiplier x10000]`. */ export function compute_payout_limbo(random: BigUint64Array, bet_atomic: bigint, prediction_x100: number): BigUint64Array; /** * Full plinko payout computation — pure integer arithmetic, zero floats. * * `random`: 4 Goldilocks field elements (Poseidon2 output). * `bet_atomic`: bet in atomic units (1 USDT = 1_000_000). * `sector`: risk profile (0=low, 1=medium, 2=high). * `rows`: number of pin rows (8..16). * `is_extreme`: whether extreme mode is active. * * Returns `BigUint64Array[4]`: `[win_amount, bucket_index, is_win (0|1), multiplier×10000]`. */ export function compute_payout_plinko(random: BigUint64Array, bet_atomic: bigint, sector: number, rows: number, is_extreme: boolean): BigUint64Array; /** * Compute prediction hash: `Poseidon2(game_id, p0, p1, p2)` → 4 field elements. * * Matches `compute_prediction_hash_native` in the circuit (`games/shared.rs`) * and the in-circuit `build_prediction_hash`. * * Semantics of p0–p2 depend on the game: * Limbo: `(98, prediction_x100, 0)` — RTP hardcoded at 98 * Dice: `(mode, pred_lo, pred_hi)` * Plinko: `(sector, rows, is_extreme)` * CoinFlip: `(prediction, 0, 0)` */ export function compute_prediction_hash(game_id: number, p0: number, p1: number, p2: number): BigUint64Array; /** * Compute Keno prediction hash with extended 13-input format: * `Poseidon2(game_id, risk, pick_count, selected[0], …, selected[9])`. * * Selected numbers are sorted internally for deterministic output. * Unused slots (when pick_count < 10) are filled with 0. * * Returns `BigUint64Array` of length 4 (one `HashOut`). */ export function compute_prediction_hash_keno(game_id: number, risk: number, pick_count: number, selected: Uint8Array): BigUint64Array; /** * Extract coinflip roll (0 or 1) from Poseidon2 random output. * * `random` must be exactly 4 elements. Returns `random[0] % 2`. */ export function compute_roll_coinflip(random: BigUint64Array): number; /** * Extract dice roll number [0, 1000) from Poseidon2 random output. * * `random` must be exactly 4 elements. Returns `random[0] % 1000`. */ export function compute_roll_dice(random: BigUint64Array): number; /** * Extract limbo result multiplier x 100 from Poseidon2 random output. * * `random` must be exactly 4 elements. * Returns the clamped multiplier x 100 (101..999999). */ export function compute_roll_limbo(random: BigUint64Array): number; /** * Extract plinko bucket index from Poseidon2 random output. * * `random` must be exactly 4 elements. * `rows` must be in [8, 16]. * Returns the bucket index (0..=rows) = popcount of first `rows` bits of random[0]. */ export function compute_roll_plinko(random: BigUint64Array, rows: number): number; /** * Full Poseidon2 hash of an 8-element server seed. * * Returns all 4 hash elements. Note: the circuit stores only the * **first 3 elements** as the leaf commitment (see `seed_hash_truncated`). * This full variant is useful for client-side verification where all * 4 elements may be needed. * * `server_seed` must be exactly 8 elements. */ export function compute_server_seed_hash(server_seed: BigUint64Array): BigUint64Array; /** * Compute user seed with bet-parameter binding: * `Poseidon2(game_id, bet, pred_hash[4], secret[4])` → 4 field elements. * * Matches the circuit constraint in `slot/fairness.rs`. * Prevents the operator from swapping bet parameters after the user commits. * * `bet` is the full bet amount in atomic units (u64). * `pred_hash` must be 4 elements (output of `compute_prediction_hash`). * `secret` must be 4 elements (output of `generate_user_secret`). */ export function compute_user_seed_binding(game_id: number, bet: bigint, pred_hash: BigUint64Array, secret: BigUint64Array): BigUint64Array; /** * Crash RTP percent (99). Canonical source for backend/frontend. */ export function crash_rtp_percent(): number; /** * Derive a session key from 32 bytes of entropy (e.g. MetaMask signature). * * **Algorithm**: split 32 bytes into 4 × 8 bytes, interpret each chunk as * little-endian u64, reduce mod p, then hash: * `session_key = Poseidon2(reduced_chunks)` * * The reduction via `from_noncanonical_u64` is necessary because raw * signature bytes can produce values >= p. * * ```js * const sig = ethers.getBytes(metaMaskSignature).slice(0, 32); * const sk = derive_session_key(new Uint8Array(sig)); * // sk.length === 4 * ``` */ export function derive_session_key(sig_bytes: Uint8Array): BigUint64Array; /** * Dice RTP percent (99). Canonical source for backend/frontend. */ export function dice_rtp_percent(): number; /** * Encode 1-indexed Keno selected numbers into a bitmask pair `[lo, hi]`. * * `selected_1indexed`: player-chosen numbers as they come from the frontend (1..40). * Returns `Uint32Array[2]`: `[lo, hi]` where `lo` covers numbers 0..29 and `hi` covers 30..39 * (0-indexed bit positions). */ export function encode_keno_selected(selected_1indexed: Uint8Array): Uint32Array; /** * Generate a cryptographically random user secret — 4 Goldilocks field elements. * * Each element is reduced mod p for canonical representation (safe for circuit use). * Uses `getrandom` (`crypto.getRandomValues` in browser, OS entropy in Node.js). * * ```js * const secret = generate_user_secret(); * // secret.length === 4, each < GOLDILOCKS_P * ``` */ export function generate_user_secret(): BigUint64Array; /** * Generate a random user seed — 10 alphanumeric characters. * * Uses `getrandom` (backed by `crypto.getRandomValues` in the browser * and OS entropy on Node.js) for cryptographically secure randomness. * * ```js * const seed = generate_user_seed(); * // e.g. "k7Qm2xW9aB" * ``` */ export function generate_user_seed(): string; /** * Convert any Goldilocks field elements to a hex string. * * Each u64 is encoded as 8 little-endian bytes → 16 hex chars. * For 4 elements: 64 hex chars (32 bytes). * * ```js * const hex = goldilocks_fields_to_hex(BigUint64Array.from([1n, 2n, 3n, 4n])); * ``` */ export function goldilocks_fields_to_hex(fields: BigUint64Array): string; /** * Returns the Goldilocks prime: p = 2^64 - 2^32 + 1. */ export function goldilocks_modulus(): bigint; /** * Reduce an arbitrary u64 to its canonical representative mod p. * * Values already < p are returned unchanged. Values >= p are reduced. * This uses `from_noncanonical_u64` internally (no panic on large values). */ export function goldilocks_reduce(value: bigint): bigint; /** * Hash a raw 7-element balance leaf → 4-element Merkle node. * * Raw layout: `[balance_lo, balance_hi, seed_hash_0, seed_hash_1, seed_hash_2, credit_lo, credit_hi]` * * Identical to `hash_balance_leaf` in `prover/circuit/src/helpers/leaf_ops.rs`. * * **Input** : `BigUint64Array` of exactly 7 elements (each < `GOLDILOCKS_P`). * **Output**: `BigUint64Array` of length 4 (one `HashOut`). * * ```js * const raw = BigUint64Array.from([balLo, balHi, seed0, seed1, seed2, credLo, credHi]); * const balanceHash = hash_balance_leaf(raw); // length 4 * ``` */ export function hash_balance_leaf(raw: BigUint64Array): BigUint64Array; /** * RTP × 100 for ALL valid Keno configs. * Returns JS object: `{ "0_1": 9450, "0_2": 9712, ..., "2_10": 9580 }` * Keys: `"{risk}_{pick_count}"`. */ export function keno_all_rtp_x100(): any; export function keno_draw_count(): number; /** * Whether a (risk, pick_count) pair is a valid Keno config. */ export function keno_is_valid_config(risk: number, pick_count: number): boolean; export function keno_max_picks(): number; /** * Returns the multiplier table (×10000) for the given Keno config. * `risk`: 0=low, 1=medium, 2=high. `pick_count`: 1..10. * Length = pick_count + 1. Returns empty vec for invalid combos. */ export function keno_multiplier_table(risk: number, pick_count: number): BigUint64Array; export function keno_numbers_range(): number; /** * RTP × 100 for a Keno config (e.g. 9800 = 98.00%). Returns 0 for invalid combos. */ export function keno_rtp_x100(risk: number, pick_count: number): bigint; /** * Limbo RTP percent (98). Canonical source for backend/frontend. */ export function limbo_rtp_percent(): number; /** * Build a main Merkle tree leaf from balance_hash, pk_hash, and address_hash. * * `main_leaf = Poseidon2(balance_hash[4] || pk_hash[0..2] || address_hash[0..2])` * * Uses truncated (128-bit) pk/address hashes to keep the preimage at 8 elements * (single Poseidon2 permutation round). Identical to `make_main_leaf` in * `prover/circuit/src/helpers/leaf_ops.rs`. * * All three inputs must be exactly 4 elements. * **Output**: `BigUint64Array` of length 4 (the Merkle leaf hash). * * ```js * const leaf = make_main_leaf(balanceHash, pkHash, addressHash); * ``` */ export function make_main_leaf(balance_hash: BigUint64Array, pk_hash: BigUint64Array, address_hash: BigUint64Array): BigUint64Array; /** * RTP × 100 for ALL valid Plinko configs. * Returns JS object: `{ "0_8_normal": 9799, "1_12_extreme": 9881, ... }` */ export function plinko_all_rtp_x100(): any; /** * Whether a (sector, rows, is_extreme) triple is a valid Plinko config. */ export function plinko_is_valid_config(sector: number, rows: number, is_extreme: boolean): boolean; /** * Whether rows is within the valid Plinko range [8, 16]. */ export function plinko_is_valid_rows(rows: number): boolean; export function plinko_max_rows(): number; export function plinko_min_rows(): number; /** * Returns the multiplier table (×10000) for the given Plinko config. * Length = rows + 1. Returns empty vec for invalid combos. */ export function plinko_multiplier_table(sector: number, rows: number, is_extreme: boolean): BigUint64Array; export function plinko_num_sectors(): number; /** * RTP × 100 for a Plinko config (e.g. 9799 = 97.99%). Returns 0 for invalid combos. */ export function plinko_rtp_x100(sector: number, rows: number, is_extreme: boolean): bigint; /** * Poseidon2 hash of an arbitrary number of Goldilocks field elements. * * Mirrors `builder.hash_n_to_hash_no_pad::(...)` inside * the circuit and `Poseidon2Hash::hash_no_pad` in `src/block_builder`. * * **Input** : `BigUint64Array` — each element must be < `GOLDILOCKS_P`. * **Output**: `BigUint64Array` of length 4 (one `HashOut`). * * ```js * const h = poseidon2_hash(BigUint64Array.from([1n, 2n, 3n])); * // h.length === 4 * ``` */ export function poseidon2_hash(input: BigUint64Array): BigUint64Array; /** * Merkle-tree hash: Poseidon2(left[4] ‖ right[4]). * * Identical to `poseidon_hash(left, right)` in `src/merkletree/hash.rs`. * Input ordering is critical — `left` concatenated before `right`. * * Both arrays **must** have exactly 4 elements (one `HashOut` each). */ export function poseidon2_two_to_one(left: BigUint64Array, right: BigUint64Array): BigUint64Array; /** * Truncated seed hash — first 3 elements of `Poseidon2(server_seed)`. * * 192 bits of commitment → ~96-bit collision resistance, which closes the * multi-preimage grinding vector that an earlier 128-bit truncation left open. * This is the exact format stored in the Merkle-tree leaf and verified * by the circuit. Matches `seed_hash_truncated` in * `src/block_builder/builder.rs` and `src/circuit/slot/fairness.rs`. * * Returns `BigUint64Array` of length 3: `[h[0], h[1], h[2]]`. */ export function seed_hash_truncated(server_seed: BigUint64Array): BigUint64Array; /** * Compute the public key for a session: `pk_hash = Poseidon2(session_key[4], expiry)`. * * The public key hash is stored in the user-asset Merkle leaf and verified * inside the circuit (the prover must know the preimage `session_key` + `expiry`). * * `session_key` must be exactly 4 elements (output of `derive_session_key`). * `session_expiry` is the Unix timestamp after which the session is invalid. */ export function session_public_key(session_key: BigUint64Array, session_expiry: bigint): BigUint64Array; /** * Convert a user seed string to 4 Goldilocks field elements. * * `SHA-256(str)` → split into 4 × 8 LE bytes → reduce each mod p. * * This matches the backend's `stringToUserSeed` and produces the exact * field elements used in the provably-fair random computation: * `random = Poseidon2(server_seed ‖ user_seed)` * * ```js * const fields = string_to_user_seed("my-seed-123"); * // fields.length === 4, each < GOLDILOCKS_P * ``` */ export function string_to_user_seed(input: string): BigUint64Array; /** * Convert a user seed string directly to a hex representation. * * Equivalent to `goldiLocksFieldsToHex(stringToUserSeed(str))`. * Returns a 64-character lowercase hex string (32 bytes). * * ```js * const hex = string_to_user_seed_hex("my-seed-123"); * // hex === "a1b2c3..." (64 chars) * ``` */ export function string_to_user_seed_hex(input: string): string; /** * Re-check every per-slot circuit constraint on a candidate witness, returning * the post-tx effects on success or a typed rejection reason on failure. * * Input: a JS object matching `tx_validator::SlotInput` (serde-compatible). * Output on success: `{ ok: true, effects: SlotEffects }`. * Output on failure: `{ ok: false, reason: string }`. */ export function validate_slot(input: any): any;