import { b as IHashFunction } from './types-EgAvBFvJ.js'; export { A as ASPClientConfig, a as ASPInfo, I as IASPProvider, M as MembershipProof, c as MerkleProof, P as PublishRootOptions, R as RegisterASPOptions } from './types-EgAvBFvJ.js'; export { x as AIRShapeProof, A as ASPClient, a as ASPEntry, b as ASPList, c as ASPSecurityLevel, d as ASPType, B as BLS12_381_FIELD_PRIME, e as BN254_FIELD_PRIME, D as DEFAULT_TREE_DEPTH, M as MAX_TREE_DEPTH, f as MerkleTree, P as PoseidonBLS12381, g as PoseidonBN254, h as buildMerkleTree, i as computeIdentityFromAddress, j as computeIdentityFromBabyJubJub, k as computeIdentityFromSecret, l as computeMerkleRoot, m as createASPClient, n as fetchASPProof, o as findASPById, p as generateMembershipProof, q as generateMultiMemberProof, r as generateSingleMemberProof, s as getActiveASPs, t as getDefaultHashFunction, y as padLeanIMTProofToDepth, u as parseASPList, v as verifyMembershipProof, w as verifyMerkleProof } from './asp-list-BkkL9EY9.js'; export { MemoryProvider, RESTProvider } from './providers/index.js'; export { L as LocalStorageProvider, l as loadPersonalASPId, s as storePersonalASPId } from './localStorage-CptisNFJ.js'; export { ASPAddressStatus, ASPAddressStatusResponse, ASPErrorResponse, ASPProofResponse, ASPRootResponse, ASPStarkProofData, ASPStarkProofResponse, ASPStarkRootResponse, ASPStatusResponse, ASP_EIP712_DOMAIN, ASP_EIP712_TYPES, ASP_SIGNATURE_MAX_AGE_SECONDS, EventSourceStatus, IEventSource, IMembershipGate, MembershipGateStats, appendSignatureParams, buildASPSignatureMessage, cacheSignature, fetchStarkASPProof, fetchStarkASPRoot, getCachedSignature } from './asp/index.js'; import 'viem'; /** * Poseidon2-Mersenne31 hash adapter — IHashFunction over M31. * * Field: Mersenne31 prime, P = 2^31 - 1. * Output: a single M31 element (first limb of the 4-element Poseidon31 * digest, matching the in-trace AIR convention). * * Used by the STARK side of the dual-root ASP service to maintain a * Merkle tree whose root binds 1:1 with the on-chain `pub_asp_root` that * the Poseidon31 STARK AIR consumes. * * Security: the digest is truncated to 31 bits, so collision security is * ~2^15.5 by birthday bound. This matches the original Keccak-M31 STARK * design's per-element collision resistance and the in-trace AIR's * single-limb Merkle chain. Higher-security applications should use * `PoseidonBLS12381` instead — Poseidon31 here is specifically for * STARK-side Merkle trees that the Poseidon31 AIR can verify. */ /** Mersenne31 prime: 2^31 - 1. */ declare const M31_FIELD_PRIME: bigint; declare class PoseidonM31 implements IHashFunction { readonly name = "Poseidon-M31"; readonly fieldPrime: bigint; /** * Effective collision security for the truncated single-limb digest. * Higher-security paths should use Poseidon-BLS12-381. */ readonly securityBits = 16; hash2(left: bigint, right: bigint): Promise; hashN(inputs: bigint[]): Promise; } /** Digest size in M31 elements. */ declare const DIGEST_SIZE = 4; /** Owner secret limb count. Matches the Rust `SECRET_LIMBS = 8`. */ declare const SECRET_LIMBS = 8; /** * Poseidon2-Mersenne31 sponge — off-circuit reference for the STARK side. * * Mirror of [poseidon31.rs](https://github.com/permissionless-technologies/universal-private-pool/blob/main/stwo-prover/src/poseidon31.rs) * — the in-circuit Poseidon31 AIR consumes the same round constants and * sponge convention. Outputs match the Rust reference byte-for-byte. * * Sponge construction (8-rate / 8-capacity): * - state[0..8] = absorbed elements (added to previous state, mod M31) * - state[8..16] = capacity, with `state[8]` initialised to the input * length to domain-separate variable-length inputs * - On absorb, add the input chunk to the rate portion and apply the perm. * - Squeeze: take the first DIGEST_SIZE elements after the final perm. */ /** * Hash an arbitrary number of M31 elements, returning a 4-element digest. * * Inputs must already be in canonical M31 form (non-negative `bigint < 2^31 - 1`). * Throws if any input is out of range. */ declare function hashM31(inputs: bigint[]): bigint[]; /** * Hash exactly two M31 elements and return only the first digest element. * Used for Merkle tree internal nodes. */ declare function hashTwo(left: bigint, right: bigint): bigint; /** * Compute the spender's owner_hash from an 8-limb owner_secret. * * owner_hash = Poseidon31(owner_secret[0..8]) */ declare function computeOwnerHash(ownerSecret: bigint[]): bigint[]; /** * Compute a note commitment. * * commitment = Poseidon31(amount, owner_hash[0..4], blinding, origin, token) */ declare function computeCommitment(amount: bigint, ownerHash: bigint[], blinding: bigint, origin: bigint, token: bigint): bigint[]; /** * Compute a nullifier. * * nullifier = Poseidon31(owner_secret[0..8], leaf_index, commitment[0..4]) */ declare function computeNullifier(ownerSecret: bigint[], leafIndex: bigint, commitment: bigint[]): bigint[]; /** * Verify a Poseidon31 Merkle proof path. Returns the computed root. * * Single-element chain: each level produces one M31 (the first element of * the 4-element digest). Matches the in-trace AIR's * `state_merkle_perm.state[N_ROUNDS][0]` chain. */ declare function verifyMerklePath(leaf: bigint, pathElements: bigint[], pathIndices: bigint[]): bigint; /** * AlwaysHashMerkleTree — fixed-depth Merkle tree under always-hash * semantics. Every internal node is `hashFn.hash2(left, right)` * regardless of whether either child is empty; empty subtrees are * represented by precomputed zero-subtree roots `ZSR(k)`. * * Use this for STARK-side ASP / state trees that the in-trace * Poseidon31 AIR consumes. The AIR has no propagation primitive * (every level hashes), so a tree built under always-hash semantics * is the only model where every member's depth-D proof verifies * against a single shared root. The LeanIMT-based [`MerkleTree`] is * still the right choice for SNARK-side trees whose verifying * circuit explicitly mirrors LeanIMT propagation. * * Cross-class relationship to [`padLeanIMTProofToDepth`]: * * - The padding helper is a *transitional* compatibility shim: it * takes a LeanIMT proof and produces a self-consistent * fixed-depth proof, but in sparse trees different leaves' * proofs land on different roots. Useful for verifying single- * membership end-to-end against a leaf-specific root, not for * publishing a shared `pub_asp_root`. * - This class is the *operational* fix: insert leaves once, get * a single root, get fixed-depth proofs that all verify against * it. This is what the asp-whitelist's STARK-side tree should * use, and what the SDK + zkdemo prover wiring should consume. * * @see padLeanIMTProofToDepth — compatibility shim for LeanIMT proofs. * @see verifyMerklePath — sync always-hash verifier in the * Poseidon31 module that mirrors the in-trace AIR. */ /** * Default depth for ASP-side STARK trees, matching the in-trace AIR's * `ASP_TREE_DEPTH = 20`. */ declare const DEFAULT_ALWAYS_HASH_DEPTH = 20; /** * Maximum supported depth. The tree's leaf capacity is `2^depth`, so * deeper trees are mostly a memory/proof-size concern. */ declare const MAX_ALWAYS_HASH_DEPTH = 32; /** * Proof shape returned by [`AlwaysHashMerkleTree.getProof`]. * * `pathIndices` are `bigint[]` so the result can be fed straight into * the Poseidon31 [`verifyMerklePath`] without conversion. Length of * both `pathElements` and `pathIndices` is exactly the tree's `depth`. */ interface AlwaysHashMerkleProof { /** Sibling at each level. Length equals the tree's `depth`. */ pathElements: bigint[]; /** Side bit at each level (0n = current is left, 1n = right). */ pathIndices: bigint[]; /** Index of the leaf being proven (0-based). */ leafIndex: number; /** Tree root the proof verifies against. */ root: bigint; /** Fixed depth — pinned alongside the proof so verifiers don't guess. */ depth: number; } /** * Fixed-depth Merkle tree where every internal node hashes its two * children regardless of fill. Empty subtrees are represented by * precomputed zero-subtree roots, and every member's proof verifies * against the same root. * * Capacity is `2^depth`. Inserting beyond capacity throws. * * Hash function defaults to Poseidon-M31 (matches the STARK AIR). Any * `IHashFunction` works in principle, but cross-leaf agreement only * matters for AIR-aligned trees today. */ declare class AlwaysHashMerkleTree { private leaves; private nodes; /** ZSR cache: `zsr[k]` is the root of an entirely-empty subtree of depth `k`. */ private zsrCache; private cachedRoot; readonly depth: number; readonly hashFn: IHashFunction; constructor(depth?: number, hashFn?: IHashFunction); /** Maximum number of leaves the tree can hold (`2^depth`). */ get capacity(): number; /** Number of leaves currently inserted. */ get size(): number; /** * Append a leaf and return its index. Rejects `0n` because the * tree uses `0n` as the empty-leaf sentinel that drives ZSR(0). * Rejects when at capacity. */ insert(leaf: bigint): number; /** Index of `leaf` in insertion order, or `-1` if absent. */ indexOf(leaf: bigint): number; /** Whether `leaf` was inserted. */ has(leaf: bigint): boolean; /** * Compute (or return cached) root. Always exactly one value per * tree state — the headline cross-leaf-agreement property holds by * construction. */ getRoot(): Promise; /** * Build a depth-D proof for the leaf at `index`. The returned * `pathElements` / `pathIndices` are length `this.depth`, and * `verifyMerklePath(leaf, pathElements, pathIndices) === root` * holds for every leaf in the tree. */ getProof(index: number): Promise; /** * Zero-subtree root at `level` — the value an entirely-empty * subtree of depth `level` would hash to. Exposed because the * asp-whitelist's HTTP layer benefits from sharing these constants * with the on-chain side without re-hashing them per request. * * ZSR(0) = 0n * ZSR(k) = hashFn(ZSR(k-1), ZSR(k-1)) */ getZeroSubtreeRoot(level: number): Promise; private ensureZsrCache; /** * Returns true when the subtree rooted at `(level, index)` is * entirely empty — i.e. holds no real leaves. Lets `getNodeHash` * short-circuit to ZSR(level) without redundantly recomputing * empty-subtree hashes. */ private isSubtreeEmpty; private getNodeHash; } /** Build an [`AlwaysHashMerkleTree`] from an array of leaves. */ declare function buildAlwaysHashMerkleTree(leaves: bigint[], depth?: number, hashFn?: IHashFunction): Promise; /** * ASPRegistryHub Contract ABI * * Copied from upp-sdk. This ABI is shared between UPC and UPP. */ declare const ASP_REGISTRY_HUB_ABI: readonly [{ readonly type: "function"; readonly name: "ROOT_HISTORY_SIZE"; readonly inputs: readonly []; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "aspRootHistory"; readonly inputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "aspRootIndex"; readonly inputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "asps"; readonly inputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: "id"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "operator"; readonly type: "address"; readonly internalType: "address"; }, { readonly name: "name"; readonly type: "string"; readonly internalType: "string"; }, { readonly name: "currentRoot"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "lastUpdated"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "currentStarkRoot"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "lastStarkUpdated"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "aspStarkRootHistory"; readonly inputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "aspStarkRootIndex"; readonly inputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "getASP"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "tuple"; readonly internalType: "struct ASPInfo"; readonly components: readonly [{ readonly name: "id"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "operator"; readonly type: "address"; readonly internalType: "address"; }, { readonly name: "name"; readonly type: "string"; readonly internalType: "string"; }, { readonly name: "currentRoot"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "lastUpdated"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "currentStarkRoot"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "lastStarkUpdated"; readonly type: "uint256"; readonly internalType: "uint256"; }]; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "getCurrentStarkRoot"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "isValidSTARKRoot"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "root"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "bool"; readonly internalType: "bool"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "updateStarkRoot"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "newRoot"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; }, { readonly type: "function"; readonly name: "getCurrentRoot"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "isValidASPRoot"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "root"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly [{ readonly name: ""; readonly type: "bool"; readonly internalType: "bool"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "nextASPId"; readonly inputs: readonly []; readonly outputs: readonly [{ readonly name: ""; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "view"; }, { readonly type: "function"; readonly name: "registerASP"; readonly inputs: readonly [{ readonly name: "name"; readonly type: "string"; readonly internalType: "string"; }]; readonly outputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly stateMutability: "nonpayable"; }, { readonly type: "function"; readonly name: "updateRoot"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly internalType: "uint256"; }, { readonly name: "newRoot"; readonly type: "uint256"; readonly internalType: "uint256"; }]; readonly outputs: readonly []; readonly stateMutability: "nonpayable"; }, { readonly type: "event"; readonly name: "ASPRegistered"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly indexed: true; readonly internalType: "uint256"; }, { readonly name: "operator"; readonly type: "address"; readonly indexed: true; readonly internalType: "address"; }, { readonly name: "name"; readonly type: "string"; readonly indexed: false; readonly internalType: "string"; }]; readonly anonymous: false; }, { readonly type: "event"; readonly name: "ASPRootUpdated"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly indexed: true; readonly internalType: "uint256"; }, { readonly name: "oldRoot"; readonly type: "uint256"; readonly indexed: false; readonly internalType: "uint256"; }, { readonly name: "newRoot"; readonly type: "uint256"; readonly indexed: false; readonly internalType: "uint256"; }]; readonly anonymous: false; }, { readonly type: "event"; readonly name: "ASPStarkRootUpdated"; readonly inputs: readonly [{ readonly name: "aspId"; readonly type: "uint256"; readonly indexed: true; readonly internalType: "uint256"; }, { readonly name: "oldRoot"; readonly type: "uint256"; readonly indexed: false; readonly internalType: "uint256"; }, { readonly name: "newRoot"; readonly type: "uint256"; readonly indexed: false; readonly internalType: "uint256"; }]; readonly anonymous: false; }]; export { ASP_REGISTRY_HUB_ABI, type AlwaysHashMerkleProof, AlwaysHashMerkleTree, DEFAULT_ALWAYS_HASH_DEPTH, IHashFunction, M31_FIELD_PRIME, MAX_ALWAYS_HASH_DEPTH, DIGEST_SIZE as POSEIDON31_DIGEST_SIZE, SECRET_LIMBS as POSEIDON31_SECRET_LIMBS, PoseidonM31, buildAlwaysHashMerkleTree, computeCommitment, computeNullifier, computeOwnerHash, hashM31, hashTwo, verifyMerklePath };