@zktable/prover-web 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 zkTable contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/index.cjs ADDED
@@ -0,0 +1,196 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ TREE_DEPTH: () => TREE_DEPTH,
24
+ buildEdgeTree: () => buildEdgeTree,
25
+ bytesToHex: () => bytesToHex,
26
+ canonicalEdges: () => canonicalEdges,
27
+ createWebProver: () => createWebProver,
28
+ initPoseidon: () => initPoseidon,
29
+ merklePath: () => merklePath,
30
+ poseidon2: () => poseidon2,
31
+ toBe32Blob: () => toBe32Blob,
32
+ toBe32Hex: () => toBe32Hex
33
+ });
34
+ module.exports = __toCommonJS(index_exports);
35
+
36
+ // src/prover.ts
37
+ var import_bb2 = require("@aztec/bb.js");
38
+ var import_noir_js = require("@noir-lang/noir_js");
39
+
40
+ // src/fields.ts
41
+ var import_bb = require("@aztec/bb.js");
42
+ var sync = null;
43
+ async function initPoseidon() {
44
+ if (sync) return;
45
+ sync = await import_bb.BarretenbergSync.initSingleton();
46
+ }
47
+ function toFr(value) {
48
+ return new import_bb.Fr(value);
49
+ }
50
+ function frToBigInt(fr) {
51
+ return BigInt(fr.toString());
52
+ }
53
+ function poseidon2(a, b) {
54
+ if (!sync) throw new Error("poseidon2: call initPoseidon() first");
55
+ return frToBigInt(sync.poseidon2Hash([toFr(a), toFr(b)]));
56
+ }
57
+ function bytesToHex(bytes) {
58
+ let out = "";
59
+ for (const b of bytes) out += b.toString(16).padStart(2, "0");
60
+ return out;
61
+ }
62
+ function toBe32Hex(value) {
63
+ if (value < 0n) throw new Error("toBe32Hex: value must be non-negative");
64
+ const hex = value.toString(16);
65
+ if (hex.length > 64) throw new Error("toBe32Hex: value does not fit in 32 bytes");
66
+ return hex.padStart(64, "0");
67
+ }
68
+ function toBe32Blob(values) {
69
+ const out = new Uint8Array(values.length * 32);
70
+ values.forEach((v, i) => {
71
+ const hex = toBe32Hex(v);
72
+ for (let j = 0; j < 32; j++) {
73
+ out[i * 32 + j] = parseInt(hex.slice(j * 2, j * 2 + 2), 16);
74
+ }
75
+ });
76
+ return out;
77
+ }
78
+
79
+ // src/graph.ts
80
+ var TREE_DEPTH = 10;
81
+ var N_LEAVES = 1 << TREE_DEPTH;
82
+ function canonicalEdges(graph) {
83
+ const set = [];
84
+ const bidirectional = graph.bidirectional ?? true;
85
+ for (const e of graph.edges) {
86
+ set.push([e.from, e.to, e.ticket]);
87
+ if (bidirectional) set.push([e.to, e.from, e.ticket]);
88
+ }
89
+ set.sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
90
+ return set.filter((e, i) => i === 0 || e[0] !== set[i - 1][0] || e[1] !== set[i - 1][1] || e[2] !== set[i - 1][2]);
91
+ }
92
+ function edgeLeaf(from, to, ticket) {
93
+ return poseidon2(poseidon2(from, to), ticket);
94
+ }
95
+ function edgeKey(e) {
96
+ return `${e[0]},${e[1]},${e[2]}`;
97
+ }
98
+ function buildEdgeTree(graph) {
99
+ const edges = canonicalEdges(graph);
100
+ if (edges.length > N_LEAVES) throw new Error("too many edges for TREE_DEPTH");
101
+ const indexByEdge = /* @__PURE__ */ new Map();
102
+ const leaves = [];
103
+ edges.forEach((e, i) => {
104
+ indexByEdge.set(edgeKey(e), i);
105
+ leaves.push(edgeLeaf(BigInt(e[0]), BigInt(e[1]), BigInt(e[2])));
106
+ });
107
+ while (leaves.length < N_LEAVES) leaves.push(0n);
108
+ const levels = [leaves];
109
+ for (let d = 0; d < TREE_DEPTH; d++) {
110
+ const prev = levels[d];
111
+ const next = [];
112
+ for (let i = 0; i < prev.length; i += 2) {
113
+ next.push(poseidon2(prev[i], prev[i + 1]));
114
+ }
115
+ levels.push(next);
116
+ }
117
+ return { levels, indexByEdge, root: levels[TREE_DEPTH][0] };
118
+ }
119
+ function merklePath(tree, edge) {
120
+ const idx = tree.indexByEdge.get(edgeKey(edge));
121
+ if (idx === void 0) {
122
+ throw new Error(`edge (${edge[0]},${edge[1]},ticket=${edge[2]}) not in graph`);
123
+ }
124
+ const siblings = [];
125
+ const bits = [];
126
+ let pos = idx;
127
+ for (let d = 0; d < TREE_DEPTH; d++) {
128
+ const bit = pos & 1;
129
+ const sib = bit === 0 ? pos + 1 : pos - 1;
130
+ siblings.push(tree.levels[d][sib]);
131
+ bits.push(bit);
132
+ pos >>= 1;
133
+ }
134
+ return { siblings, bits };
135
+ }
136
+
137
+ // src/prover.ts
138
+ async function createWebProver(artifacts) {
139
+ await initPoseidon();
140
+ const tree = buildEdgeTree(artifacts.graph);
141
+ const noir = new import_noir_js.Noir(artifacts.circuit);
142
+ const backend = new import_bb2.UltraHonkBackend(artifacts.circuit.bytecode);
143
+ return {
144
+ commit(node, salt) {
145
+ return toBe32Hex(poseidon2(BigInt(node), salt));
146
+ },
147
+ root() {
148
+ return toBe32Hex(tree.root);
149
+ },
150
+ async prove(move) {
151
+ const cOld = poseidon2(BigInt(move.from), move.saltOld);
152
+ const cNew = poseidon2(BigInt(move.to), move.saltNew);
153
+ const { siblings, bits } = merklePath(tree, [move.from, move.to, move.ticket]);
154
+ const { witness } = await noir.execute({
155
+ c_old: cOld.toString(),
156
+ c_new: cNew.toString(),
157
+ ticket: String(move.ticket),
158
+ root: tree.root.toString(),
159
+ from: String(move.from),
160
+ salt_old: move.saltOld.toString(),
161
+ to: String(move.to),
162
+ salt_new: move.saltNew.toString(),
163
+ path_siblings: siblings.map((s) => s.toString()),
164
+ path_bits: bits.map((b) => String(b))
165
+ });
166
+ const { proof } = await backend.generateProof(witness, { keccak: true });
167
+ return {
168
+ proof,
169
+ publicInputs: toBe32Blob([cOld, cNew, BigInt(move.ticket), tree.root]),
170
+ cOldHex: toBe32Hex(cOld),
171
+ cNewHex: toBe32Hex(cNew),
172
+ rootHex: toBe32Hex(tree.root),
173
+ ticket: move.ticket
174
+ };
175
+ },
176
+ async verifyLocally(p) {
177
+ const publicInputs = [p.cOldHex, p.cNewHex, toBe32Hex(BigInt(p.ticket)), p.rootHex].map(
178
+ (word) => `0x${word}`
179
+ );
180
+ return backend.verifyProof({ proof: p.proof, publicInputs }, { keccak: true });
181
+ }
182
+ };
183
+ }
184
+ // Annotate the CommonJS export names for ESM import in node:
185
+ 0 && (module.exports = {
186
+ TREE_DEPTH,
187
+ buildEdgeTree,
188
+ bytesToHex,
189
+ canonicalEdges,
190
+ createWebProver,
191
+ initPoseidon,
192
+ merklePath,
193
+ poseidon2,
194
+ toBe32Blob,
195
+ toBe32Hex
196
+ });
@@ -0,0 +1,80 @@
1
+ import { CompiledCircuit } from '@noir-lang/noir_js';
2
+
3
+ declare const TREE_DEPTH = 10;
4
+ type GraphData = {
5
+ nodes?: number[];
6
+ edges: Array<{
7
+ from: number;
8
+ to: number;
9
+ ticket: number;
10
+ }>;
11
+ /** If true (default), each listed edge is expanded to both directions. */
12
+ bidirectional?: boolean;
13
+ };
14
+ type Edge = [from: number, to: number, ticket: number];
15
+ /** Canonical directed edge list: expand bidirectional, dedupe, sort. */
16
+ declare function canonicalEdges(graph: GraphData): Edge[];
17
+ type EdgeTree = {
18
+ levels: bigint[][];
19
+ indexByEdge: Map<string, number>;
20
+ root: bigint;
21
+ };
22
+ /** Full depth-10 tree; levels[0] = leaves (zero-padded), levels[10] = [root]. */
23
+ declare function buildEdgeTree(graph: GraphData): EdgeTree;
24
+ type MerklePath = {
25
+ siblings: bigint[];
26
+ bits: number[];
27
+ };
28
+ /** Authentication path for the edge (from, to, ticket). bit=0 -> node is left. */
29
+ declare function merklePath(tree: EdgeTree, edge: Edge): MerklePath;
30
+
31
+ type WebBoardProof = {
32
+ /** UltraHonk proof bytes (14592) — hex these into `submit_hidden_move`. */
33
+ proof: Uint8Array;
34
+ /** c_old | c_new | ticket | root (128 bytes) — the verifier's public-inputs blob. */
35
+ publicInputs: Uint8Array;
36
+ cOldHex: string;
37
+ cNewHex: string;
38
+ rootHex: string;
39
+ ticket: number;
40
+ };
41
+ type WebProverArtifacts = {
42
+ /** The compiled `move_along` ACIR artifact (target/move_along.json, parsed). */
43
+ circuit: CompiledCircuit;
44
+ /** The public city graph (same JSON `zktable-graph` consumes). */
45
+ graph: GraphData;
46
+ };
47
+ type WebBoardProver = {
48
+ /** Poseidon2(node, salt) as 32-byte hex — hidden-position commitments. */
49
+ commit(node: number, salt: bigint): string;
50
+ /** The edge-tree root as 32-byte hex (per-map public constant). */
51
+ root(): string;
52
+ /** Prove one hidden move. The secret (from/to/salts) never leaves the caller. */
53
+ prove(move: {
54
+ from: number;
55
+ to: number;
56
+ ticket: 0 | 1 | 2;
57
+ saltOld: bigint;
58
+ saltNew: bigint;
59
+ }): Promise<WebBoardProof>;
60
+ /** Local verification against the circuit's own (keccak) verification key. */
61
+ verifyLocally(proof: WebBoardProof): Promise<boolean>;
62
+ };
63
+ /**
64
+ * Builds a browser prover: initializes the Poseidon2 WASM, precomputes the
65
+ * public edge tree, and holds a lazily-created UltraHonk backend.
66
+ */
67
+ declare function createWebProver(artifacts: WebProverArtifacts): Promise<WebBoardProver>;
68
+
69
+ /** One-time WASM init (idempotent). Call before any `poseidon2` use. */
70
+ declare function initPoseidon(): Promise<void>;
71
+ /** Poseidon2 over exactly two field elements — zkTable's universal `hash2`. */
72
+ declare function poseidon2(a: bigint, b: bigint): bigint;
73
+ /** Lowercase hex (no 0x prefix) for arbitrary bytes — proofs, salts, blobs. */
74
+ declare function bytesToHex(bytes: Uint8Array): string;
75
+ /** 32-byte big-endian hex (no 0x prefix) — the CLI/contract Bytes encoding. */
76
+ declare function toBe32Hex(value: bigint): string;
77
+ /** Concatenate values as 32-byte big-endian words (the public-inputs blob shape). */
78
+ declare function toBe32Blob(values: bigint[]): Uint8Array;
79
+
80
+ export { type Edge, type EdgeTree, type GraphData, type MerklePath, TREE_DEPTH, type WebBoardProof, type WebBoardProver, type WebProverArtifacts, buildEdgeTree, bytesToHex, canonicalEdges, createWebProver, initPoseidon, merklePath, poseidon2, toBe32Blob, toBe32Hex };
@@ -0,0 +1,80 @@
1
+ import { CompiledCircuit } from '@noir-lang/noir_js';
2
+
3
+ declare const TREE_DEPTH = 10;
4
+ type GraphData = {
5
+ nodes?: number[];
6
+ edges: Array<{
7
+ from: number;
8
+ to: number;
9
+ ticket: number;
10
+ }>;
11
+ /** If true (default), each listed edge is expanded to both directions. */
12
+ bidirectional?: boolean;
13
+ };
14
+ type Edge = [from: number, to: number, ticket: number];
15
+ /** Canonical directed edge list: expand bidirectional, dedupe, sort. */
16
+ declare function canonicalEdges(graph: GraphData): Edge[];
17
+ type EdgeTree = {
18
+ levels: bigint[][];
19
+ indexByEdge: Map<string, number>;
20
+ root: bigint;
21
+ };
22
+ /** Full depth-10 tree; levels[0] = leaves (zero-padded), levels[10] = [root]. */
23
+ declare function buildEdgeTree(graph: GraphData): EdgeTree;
24
+ type MerklePath = {
25
+ siblings: bigint[];
26
+ bits: number[];
27
+ };
28
+ /** Authentication path for the edge (from, to, ticket). bit=0 -> node is left. */
29
+ declare function merklePath(tree: EdgeTree, edge: Edge): MerklePath;
30
+
31
+ type WebBoardProof = {
32
+ /** UltraHonk proof bytes (14592) — hex these into `submit_hidden_move`. */
33
+ proof: Uint8Array;
34
+ /** c_old | c_new | ticket | root (128 bytes) — the verifier's public-inputs blob. */
35
+ publicInputs: Uint8Array;
36
+ cOldHex: string;
37
+ cNewHex: string;
38
+ rootHex: string;
39
+ ticket: number;
40
+ };
41
+ type WebProverArtifacts = {
42
+ /** The compiled `move_along` ACIR artifact (target/move_along.json, parsed). */
43
+ circuit: CompiledCircuit;
44
+ /** The public city graph (same JSON `zktable-graph` consumes). */
45
+ graph: GraphData;
46
+ };
47
+ type WebBoardProver = {
48
+ /** Poseidon2(node, salt) as 32-byte hex — hidden-position commitments. */
49
+ commit(node: number, salt: bigint): string;
50
+ /** The edge-tree root as 32-byte hex (per-map public constant). */
51
+ root(): string;
52
+ /** Prove one hidden move. The secret (from/to/salts) never leaves the caller. */
53
+ prove(move: {
54
+ from: number;
55
+ to: number;
56
+ ticket: 0 | 1 | 2;
57
+ saltOld: bigint;
58
+ saltNew: bigint;
59
+ }): Promise<WebBoardProof>;
60
+ /** Local verification against the circuit's own (keccak) verification key. */
61
+ verifyLocally(proof: WebBoardProof): Promise<boolean>;
62
+ };
63
+ /**
64
+ * Builds a browser prover: initializes the Poseidon2 WASM, precomputes the
65
+ * public edge tree, and holds a lazily-created UltraHonk backend.
66
+ */
67
+ declare function createWebProver(artifacts: WebProverArtifacts): Promise<WebBoardProver>;
68
+
69
+ /** One-time WASM init (idempotent). Call before any `poseidon2` use. */
70
+ declare function initPoseidon(): Promise<void>;
71
+ /** Poseidon2 over exactly two field elements — zkTable's universal `hash2`. */
72
+ declare function poseidon2(a: bigint, b: bigint): bigint;
73
+ /** Lowercase hex (no 0x prefix) for arbitrary bytes — proofs, salts, blobs. */
74
+ declare function bytesToHex(bytes: Uint8Array): string;
75
+ /** 32-byte big-endian hex (no 0x prefix) — the CLI/contract Bytes encoding. */
76
+ declare function toBe32Hex(value: bigint): string;
77
+ /** Concatenate values as 32-byte big-endian words (the public-inputs blob shape). */
78
+ declare function toBe32Blob(values: bigint[]): Uint8Array;
79
+
80
+ export { type Edge, type EdgeTree, type GraphData, type MerklePath, TREE_DEPTH, type WebBoardProof, type WebBoardProver, type WebProverArtifacts, buildEdgeTree, bytesToHex, canonicalEdges, createWebProver, initPoseidon, merklePath, poseidon2, toBe32Blob, toBe32Hex };
package/dist/index.js ADDED
@@ -0,0 +1,160 @@
1
+ // src/prover.ts
2
+ import { UltraHonkBackend } from "@aztec/bb.js";
3
+ import { Noir } from "@noir-lang/noir_js";
4
+
5
+ // src/fields.ts
6
+ import { BarretenbergSync, Fr } from "@aztec/bb.js";
7
+ var sync = null;
8
+ async function initPoseidon() {
9
+ if (sync) return;
10
+ sync = await BarretenbergSync.initSingleton();
11
+ }
12
+ function toFr(value) {
13
+ return new Fr(value);
14
+ }
15
+ function frToBigInt(fr) {
16
+ return BigInt(fr.toString());
17
+ }
18
+ function poseidon2(a, b) {
19
+ if (!sync) throw new Error("poseidon2: call initPoseidon() first");
20
+ return frToBigInt(sync.poseidon2Hash([toFr(a), toFr(b)]));
21
+ }
22
+ function bytesToHex(bytes) {
23
+ let out = "";
24
+ for (const b of bytes) out += b.toString(16).padStart(2, "0");
25
+ return out;
26
+ }
27
+ function toBe32Hex(value) {
28
+ if (value < 0n) throw new Error("toBe32Hex: value must be non-negative");
29
+ const hex = value.toString(16);
30
+ if (hex.length > 64) throw new Error("toBe32Hex: value does not fit in 32 bytes");
31
+ return hex.padStart(64, "0");
32
+ }
33
+ function toBe32Blob(values) {
34
+ const out = new Uint8Array(values.length * 32);
35
+ values.forEach((v, i) => {
36
+ const hex = toBe32Hex(v);
37
+ for (let j = 0; j < 32; j++) {
38
+ out[i * 32 + j] = parseInt(hex.slice(j * 2, j * 2 + 2), 16);
39
+ }
40
+ });
41
+ return out;
42
+ }
43
+
44
+ // src/graph.ts
45
+ var TREE_DEPTH = 10;
46
+ var N_LEAVES = 1 << TREE_DEPTH;
47
+ function canonicalEdges(graph) {
48
+ const set = [];
49
+ const bidirectional = graph.bidirectional ?? true;
50
+ for (const e of graph.edges) {
51
+ set.push([e.from, e.to, e.ticket]);
52
+ if (bidirectional) set.push([e.to, e.from, e.ticket]);
53
+ }
54
+ set.sort((a, b) => a[0] - b[0] || a[1] - b[1] || a[2] - b[2]);
55
+ return set.filter((e, i) => i === 0 || e[0] !== set[i - 1][0] || e[1] !== set[i - 1][1] || e[2] !== set[i - 1][2]);
56
+ }
57
+ function edgeLeaf(from, to, ticket) {
58
+ return poseidon2(poseidon2(from, to), ticket);
59
+ }
60
+ function edgeKey(e) {
61
+ return `${e[0]},${e[1]},${e[2]}`;
62
+ }
63
+ function buildEdgeTree(graph) {
64
+ const edges = canonicalEdges(graph);
65
+ if (edges.length > N_LEAVES) throw new Error("too many edges for TREE_DEPTH");
66
+ const indexByEdge = /* @__PURE__ */ new Map();
67
+ const leaves = [];
68
+ edges.forEach((e, i) => {
69
+ indexByEdge.set(edgeKey(e), i);
70
+ leaves.push(edgeLeaf(BigInt(e[0]), BigInt(e[1]), BigInt(e[2])));
71
+ });
72
+ while (leaves.length < N_LEAVES) leaves.push(0n);
73
+ const levels = [leaves];
74
+ for (let d = 0; d < TREE_DEPTH; d++) {
75
+ const prev = levels[d];
76
+ const next = [];
77
+ for (let i = 0; i < prev.length; i += 2) {
78
+ next.push(poseidon2(prev[i], prev[i + 1]));
79
+ }
80
+ levels.push(next);
81
+ }
82
+ return { levels, indexByEdge, root: levels[TREE_DEPTH][0] };
83
+ }
84
+ function merklePath(tree, edge) {
85
+ const idx = tree.indexByEdge.get(edgeKey(edge));
86
+ if (idx === void 0) {
87
+ throw new Error(`edge (${edge[0]},${edge[1]},ticket=${edge[2]}) not in graph`);
88
+ }
89
+ const siblings = [];
90
+ const bits = [];
91
+ let pos = idx;
92
+ for (let d = 0; d < TREE_DEPTH; d++) {
93
+ const bit = pos & 1;
94
+ const sib = bit === 0 ? pos + 1 : pos - 1;
95
+ siblings.push(tree.levels[d][sib]);
96
+ bits.push(bit);
97
+ pos >>= 1;
98
+ }
99
+ return { siblings, bits };
100
+ }
101
+
102
+ // src/prover.ts
103
+ async function createWebProver(artifacts) {
104
+ await initPoseidon();
105
+ const tree = buildEdgeTree(artifacts.graph);
106
+ const noir = new Noir(artifacts.circuit);
107
+ const backend = new UltraHonkBackend(artifacts.circuit.bytecode);
108
+ return {
109
+ commit(node, salt) {
110
+ return toBe32Hex(poseidon2(BigInt(node), salt));
111
+ },
112
+ root() {
113
+ return toBe32Hex(tree.root);
114
+ },
115
+ async prove(move) {
116
+ const cOld = poseidon2(BigInt(move.from), move.saltOld);
117
+ const cNew = poseidon2(BigInt(move.to), move.saltNew);
118
+ const { siblings, bits } = merklePath(tree, [move.from, move.to, move.ticket]);
119
+ const { witness } = await noir.execute({
120
+ c_old: cOld.toString(),
121
+ c_new: cNew.toString(),
122
+ ticket: String(move.ticket),
123
+ root: tree.root.toString(),
124
+ from: String(move.from),
125
+ salt_old: move.saltOld.toString(),
126
+ to: String(move.to),
127
+ salt_new: move.saltNew.toString(),
128
+ path_siblings: siblings.map((s) => s.toString()),
129
+ path_bits: bits.map((b) => String(b))
130
+ });
131
+ const { proof } = await backend.generateProof(witness, { keccak: true });
132
+ return {
133
+ proof,
134
+ publicInputs: toBe32Blob([cOld, cNew, BigInt(move.ticket), tree.root]),
135
+ cOldHex: toBe32Hex(cOld),
136
+ cNewHex: toBe32Hex(cNew),
137
+ rootHex: toBe32Hex(tree.root),
138
+ ticket: move.ticket
139
+ };
140
+ },
141
+ async verifyLocally(p) {
142
+ const publicInputs = [p.cOldHex, p.cNewHex, toBe32Hex(BigInt(p.ticket)), p.rootHex].map(
143
+ (word) => `0x${word}`
144
+ );
145
+ return backend.verifyProof({ proof: p.proof, publicInputs }, { keccak: true });
146
+ }
147
+ };
148
+ }
149
+ export {
150
+ TREE_DEPTH,
151
+ buildEdgeTree,
152
+ bytesToHex,
153
+ canonicalEdges,
154
+ createWebProver,
155
+ initPoseidon,
156
+ merklePath,
157
+ poseidon2,
158
+ toBe32Blob,
159
+ toBe32Hex
160
+ };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@zktable/prover-web",
3
+ "version": "0.1.0",
4
+ "description": "Browser-side UltraHonk prover helpers for zkTable board moves",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Philotheephilix/zkTable.git",
10
+ "directory": "packages/prover-web"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "main": "./dist/index.cjs",
16
+ "module": "./dist/index.js",
17
+ "types": "./dist/index.d.ts",
18
+ "exports": {
19
+ ".": {
20
+ "import": "./dist/index.js",
21
+ "require": "./dist/index.cjs",
22
+ "types": "./dist/index.d.ts"
23
+ }
24
+ },
25
+ "files": [
26
+ "dist"
27
+ ],
28
+ "dependencies": {
29
+ "@aztec/bb.js": "0.87.0",
30
+ "@noir-lang/noir_js": "1.0.0-beta.9"
31
+ },
32
+ "devDependencies": {
33
+ "typescript": "^5.8.3",
34
+ "vitest": "^3.2.6"
35
+ },
36
+ "engines": {
37
+ "node": ">=20"
38
+ },
39
+ "scripts": {
40
+ "build": "tsup src/index.ts --format esm,cjs --dts",
41
+ "test": "vitest run"
42
+ }
43
+ }