/** * * Whitepaper §2.3 — Commitments (Poseidon Merkle tree). */ import type { DocumentCommitments, InclusionProof, LeafPreimage } from "@lemmaoracle/spec"; import type { Json } from "./internal.js"; export type PrepareOutput = Readonly<{ normalized: Norm; commitments: DocumentCommitments; /** Depth of the Merkle tree (0 for a single leaf, 1 for 2 leaves, etc.). */ depth: number; /** Inclusion proof for each leaf (same order as commitments.leaves) */ inclusionProofs: ReadonlyArray; /** Pre-image components for each leaf (same order as commitments.leaves) */ leafPreimages: ReadonlyArray; }>; /** * Convert an arbitrary value to a finite-field scalar. * * - `number` → `BigInt(value) % PRIME` * - `string` → `SHA-256(value) mod PRIME` (always — never BigInt) * * Strings are **always** hashed via SHA-256, even numeric strings like `"42"`. * This prevents `toScalar(42)` and `toScalar("42")` from mapping to the same * field element, which would break the binding property of commitments * (e.g. `{"price": 42}` and `{"price": "42"}` would produce the same leaf). * * Circuits that expect the raw numeric value (e.g. `task_bucket == 1`) should * pass the original number to the witness, **not** the output of this function. * Use this only when you need the same scalar the SDK used internally * (e.g. for `nameHash` / `valueHash` reconstruction). */ export declare const toScalar: (value: string | number) => bigint; /** * SNARK-friendly hash over field elements using Poseidon (BN254). * * - 2 inputs → Poseidon2 (binary node hash) * - 3 inputs → Poseidon3 (leaf: nameHash ‖ valueHash ‖ blinding) * - other → Poseidon2 applied iteratively (left-fold) * * Compose with `toScalar` for the same field-element pipeline the SDK * uses internally: * * ```ts * const commitment = poseidon([ * toScalar("approvalId"), toScalar("signerSet"), * BigInt(42161), BigInt(amount), * ]); * ``` */ export declare const poseidon: (inputs: ReadonlyArray) => bigint; export type CommitResult = Readonly<{ root: string; leaves: ReadonlyArray; randomness: string; /** Depth of the Merkle tree (0 for a single leaf, 1 for 2 leaves, etc.). */ depth: number; inclusionProofs: ReadonlyArray; leafPreimages: ReadonlyArray; }>; export declare const commit: (normalized: Json) => Promise; /** * Options for {@link commitDeep}. */ export type CommitDeepOptions = Readonly<{ /** 32-byte hex string (no `0x` prefix). If omitted, a new one is generated. */ randomness?: string; /** Fixed tree depth. Pads the tree to `2^maxDepth` leaves with zero leaves. */ maxDepth?: number; }>; /** * Compute a data-commitment-v1 commitment over arbitrary (possibly nested) JSON. * * Extracts path-value pairs recursively (e.g. `$["rates"]["JPY"] = 162.38`), * builds a Poseidon Merkle tree, and returns the root with inclusion proofs. * * Each leaf is `Poseidon3([toScalar(path), toScalar(valueForHash(value)), randomness])` * where `valueForHash` applies type tags (`s:`, `f:`, `z:`, `b:`) to prevent * number/string collisions. * * @param value Arbitrary JSON value (objects, arrays, primitives). * @param options Optional randomness and maxDepth. */ export declare const commitDeep: (value: Json, options?: CommitDeepOptions) => CommitResult; //# sourceMappingURL=commitments.d.ts.map