@audren-xyz/sdk 0.0.0-stage → 1.3.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 +202 -0
- package/README.md +102 -2
- package/dist/constants.d.ts +229 -0
- package/dist/constants.js +301 -0
- package/dist/crypto.d.ts +85 -0
- package/dist/crypto.js +520 -0
- package/dist/idl.d.ts +4291 -0
- package/dist/idl.js +5608 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +13 -0
- package/dist/instructions.d.ts +398 -0
- package/dist/instructions.js +1139 -0
- package/dist/keys.d.ts +67 -0
- package/dist/keys.js +194 -0
- package/dist/layout.d.ts +153 -0
- package/dist/layout.js +535 -0
- package/dist/pda.d.ts +65 -0
- package/dist/pda.js +508 -0
- package/dist/poseidon-constants.d.ts +13 -0
- package/dist/poseidon-constants.js +1401 -0
- package/dist/poseidon.d.ts +46 -0
- package/dist/poseidon.js +214 -0
- package/dist/prover-entry.d.ts +1 -0
- package/dist/prover-entry.js +1 -0
- package/dist/prover.d.ts +100 -0
- package/dist/prover.js +515 -0
- package/dist/relayer.d.ts +336 -0
- package/dist/relayer.js +258 -0
- package/dist/scanner.d.ts +262 -0
- package/dist/scanner.js +3119 -0
- package/dist/store.d.ts +186 -0
- package/dist/store.js +1403 -0
- package/dist/swap.d.ts +105 -0
- package/dist/swap.js +156 -0
- package/dist/token2022.d.ts +29 -0
- package/dist/token2022.js +168 -0
- package/dist/tx-v1.d.ts +63 -0
- package/dist/tx-v1.js +249 -0
- package/idl/audren.anchor.json +1750 -0
- package/idl/audren.codama.json +3856 -0
- package/package.json +76 -4
- package/wasm/audren_circuits.wasm +0 -0
- package/wasm/audren_joinsplit.pk +0 -0
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure TypeScript Circom / Solana `sol_poseidon` BN254 x^5 Poseidon hash and
|
|
3
|
+
* canonical Audren field/note primitives (zero WASM required — runs natively
|
|
4
|
+
* in Node.js, Browsers, and Cloudflare Workers).
|
|
5
|
+
*/
|
|
6
|
+
export declare function modFr(x: bigint): bigint;
|
|
7
|
+
export declare function isCanonicalFr(bytes: Uint8Array): boolean;
|
|
8
|
+
export declare function bytesToBigIntBe(bytes: Uint8Array): bigint;
|
|
9
|
+
export declare function frToBeBytes(v: bigint): Uint8Array;
|
|
10
|
+
export declare function frFromBeBytesStrict(bytes: Uint8Array): bigint;
|
|
11
|
+
export declare function maskToFrBe(bytes: Uint8Array): Uint8Array;
|
|
12
|
+
export declare function bytes32ToFrMasked(bytes: Uint8Array): bigint;
|
|
13
|
+
/**
|
|
14
|
+
* Exact Circom / Solana `sol_poseidon` BN254 x^5 Poseidon hash for 1..=5 inputs.
|
|
15
|
+
*/
|
|
16
|
+
export declare function poseidonHash(inputs: readonly bigint[]): bigint;
|
|
17
|
+
export declare function poseidon2(a: bigint, b: bigint): bigint;
|
|
18
|
+
export declare function poseidon3(a: bigint, b: bigint, c: bigint): bigint;
|
|
19
|
+
export declare function poseidon4(a: bigint, b: bigint, c: bigint, d: bigint): bigint;
|
|
20
|
+
export declare function poseidon5(a: bigint, b: bigint, c: bigint, d: bigint, e: bigint): bigint;
|
|
21
|
+
/** `asset_id = mask_to_fr_be(SHA-256("audren/v1/asset" || mint_32))`. */
|
|
22
|
+
export declare function deriveAssetId(mintBytes: Uint8Array): bigint;
|
|
23
|
+
export declare function deriveAssetIdBytes(mintBytes: Uint8Array): Uint8Array;
|
|
24
|
+
export declare function deriveSpendPk(spendSk: bigint): bigint;
|
|
25
|
+
export declare function deriveNullifierKey(spendSk: bigint): bigint;
|
|
26
|
+
export declare function deriveStealthOwner(spendPk: bigint, tweak: bigint): bigint;
|
|
27
|
+
export declare function computeNoteCommitment(stealthOwner: bigint, assetId: bigint, amount: bigint, blinding: bigint): bigint;
|
|
28
|
+
export declare function computeRealNullifier(nk: bigint, noteCm: bigint, globalLeafIndex: bigint): bigint;
|
|
29
|
+
export declare function computeDummyNullifier(nk: bigint, blinding: bigint): bigint;
|
|
30
|
+
export declare function packPublicAmounts(publicAmountOut: bigint, relayerFeeAmount: bigint): bigint;
|
|
31
|
+
export declare function computePublicInputHash(params: {
|
|
32
|
+
superRoot: bigint;
|
|
33
|
+
nf0: bigint;
|
|
34
|
+
nf1: bigint;
|
|
35
|
+
cm0: bigint;
|
|
36
|
+
cm1: bigint;
|
|
37
|
+
cm2: bigint;
|
|
38
|
+
publicAssetId: bigint;
|
|
39
|
+
publicAmountOut: bigint;
|
|
40
|
+
relayerFeeAmount: bigint;
|
|
41
|
+
ctxHash: bigint;
|
|
42
|
+
}): bigint;
|
|
43
|
+
/** Compute the global 16-lane super-root (2-level 4-ary Poseidon4 tree). */
|
|
44
|
+
export declare function computeSuperRoot4Ary(laneRoots: readonly bigint[]): bigint;
|
|
45
|
+
/** Compute level-4 root of a 256-leaf subtree truncated at `activeLen` leaves (rest = Z[0]). */
|
|
46
|
+
export declare function computeSubtree256Root(leaves: readonly bigint[], activeLen: number): bigint;
|
package/dist/poseidon.js
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure TypeScript Circom / Solana `sol_poseidon` BN254 x^5 Poseidon hash and
|
|
3
|
+
* canonical Audren field/note primitives (zero WASM required — runs natively
|
|
4
|
+
* in Node.js, Browsers, and Cloudflare Workers).
|
|
5
|
+
*/
|
|
6
|
+
import { sha256 } from '@noble/hashes/sha2.js';
|
|
7
|
+
import { ASSET_ID_DOMAIN, BN254_FR_MODULUS, DOMAIN_DUMMY_NF, DOMAIN_NK, DOMAIN_NOTE, DOMAIN_NULLIFIER, DOMAIN_PK, DOMAIN_PUB_HASH_A, DOMAIN_PUB_HASH_B, DOMAIN_PUB_HASH_FINAL, DOMAIN_STEALTH, NUM_LANES, ZERO_HASHES_4ARY, } from './constants.js';
|
|
8
|
+
import { POSEIDON_PARAMS, POSEIDON_PARAMS_3, POSEIDON_PARAMS_4, POSEIDON_PARAMS_5, POSEIDON_PARAMS_6, } from './poseidon-constants.js';
|
|
9
|
+
const utf8Encoder = new TextEncoder();
|
|
10
|
+
const ASSET_ID_DOMAIN_BYTES = utf8Encoder.encode(ASSET_ID_DOMAIN);
|
|
11
|
+
export function modFr(x) {
|
|
12
|
+
if (typeof x !== 'bigint') {
|
|
13
|
+
throw new RangeError(`Expected bigint field element, got ${typeof x}`);
|
|
14
|
+
}
|
|
15
|
+
const r = x % BN254_FR_MODULUS;
|
|
16
|
+
return r >= 0n ? r : r + BN254_FR_MODULUS;
|
|
17
|
+
}
|
|
18
|
+
export function isCanonicalFr(bytes) {
|
|
19
|
+
if (!(bytes instanceof Uint8Array) || bytes.byteLength !== 32)
|
|
20
|
+
return false;
|
|
21
|
+
return bytesToBigIntBe(bytes) < BN254_FR_MODULUS;
|
|
22
|
+
}
|
|
23
|
+
export function bytesToBigIntBe(bytes) {
|
|
24
|
+
if (!(bytes instanceof Uint8Array)) {
|
|
25
|
+
throw new RangeError(`Expected Uint8Array, got ${String(bytes)}`);
|
|
26
|
+
}
|
|
27
|
+
let acc = 0n;
|
|
28
|
+
for (let i = 0; i < bytes.byteLength; i++) {
|
|
29
|
+
acc = (acc << 8n) | BigInt(bytes[i]);
|
|
30
|
+
}
|
|
31
|
+
return acc;
|
|
32
|
+
}
|
|
33
|
+
export function frToBeBytes(v) {
|
|
34
|
+
let x = modFr(v);
|
|
35
|
+
const out = new Uint8Array(32);
|
|
36
|
+
for (let i = 31; i >= 0; i--) {
|
|
37
|
+
out[i] = Number(x & 0xffn);
|
|
38
|
+
x >>= 8n;
|
|
39
|
+
}
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
42
|
+
export function frFromBeBytesStrict(bytes) {
|
|
43
|
+
if (!(bytes instanceof Uint8Array) || bytes.byteLength !== 32) {
|
|
44
|
+
throw new RangeError(`Expected 32-byte BN254 Fr Uint8Array, got ${bytes instanceof Uint8Array ? bytes.byteLength : String(bytes)}`);
|
|
45
|
+
}
|
|
46
|
+
const v = bytesToBigIntBe(bytes);
|
|
47
|
+
if (v >= BN254_FR_MODULUS) {
|
|
48
|
+
throw new RangeError('Non-canonical BN254 scalar field element (>= r)');
|
|
49
|
+
}
|
|
50
|
+
return v;
|
|
51
|
+
}
|
|
52
|
+
export function maskToFrBe(bytes) {
|
|
53
|
+
if (!(bytes instanceof Uint8Array) || bytes.byteLength !== 32) {
|
|
54
|
+
throw new RangeError(`Expected 32-byte Uint8Array, got ${bytes instanceof Uint8Array ? bytes.byteLength : String(bytes)}`);
|
|
55
|
+
}
|
|
56
|
+
const out = new Uint8Array(32);
|
|
57
|
+
out.set(bytes);
|
|
58
|
+
out[0] = out[0] & 0x1f;
|
|
59
|
+
return out;
|
|
60
|
+
}
|
|
61
|
+
export function bytes32ToFrMasked(bytes) {
|
|
62
|
+
return bytesToBigIntBe(maskToFrBe(bytes));
|
|
63
|
+
}
|
|
64
|
+
function sbox5(x) {
|
|
65
|
+
const x2 = (x * x) % BN254_FR_MODULUS;
|
|
66
|
+
const x4 = (x2 * x2) % BN254_FR_MODULUS;
|
|
67
|
+
return (x4 * x) % BN254_FR_MODULUS;
|
|
68
|
+
}
|
|
69
|
+
function poseidonPermuteWithParams(params, inputs) {
|
|
70
|
+
const width = params.width;
|
|
71
|
+
const state = new Array(width);
|
|
72
|
+
state[0] = 0n;
|
|
73
|
+
for (let i = 0; i < inputs.length; i++) {
|
|
74
|
+
state[i + 1] = modFr(inputs[i]);
|
|
75
|
+
}
|
|
76
|
+
const half = params.fullRounds >>> 1;
|
|
77
|
+
const totalRounds = params.fullRounds + params.partialRounds;
|
|
78
|
+
const { ark, mds } = params;
|
|
79
|
+
const next = new Array(width);
|
|
80
|
+
for (let r = 0; r < totalRounds; r++) {
|
|
81
|
+
const base = r * width;
|
|
82
|
+
for (let i = 0; i < width; i++) {
|
|
83
|
+
let s = state[i] + ark[base + i];
|
|
84
|
+
if (s >= BN254_FR_MODULUS)
|
|
85
|
+
s -= BN254_FR_MODULUS;
|
|
86
|
+
state[i] = s;
|
|
87
|
+
}
|
|
88
|
+
if (r < half || r >= half + params.partialRounds) {
|
|
89
|
+
for (let i = 0; i < width; i++) {
|
|
90
|
+
state[i] = sbox5(state[i]);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
else {
|
|
94
|
+
state[0] = sbox5(state[0]);
|
|
95
|
+
}
|
|
96
|
+
for (let row = 0; row < width; row++) {
|
|
97
|
+
const mdsRow = mds[row];
|
|
98
|
+
let acc = 0n;
|
|
99
|
+
for (let col = 0; col < width; col++) {
|
|
100
|
+
acc += state[col] * mdsRow[col];
|
|
101
|
+
}
|
|
102
|
+
next[row] = acc % BN254_FR_MODULUS;
|
|
103
|
+
}
|
|
104
|
+
for (let i = 0; i < width; i++) {
|
|
105
|
+
state[i] = next[i];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return state[0];
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Exact Circom / Solana `sol_poseidon` BN254 x^5 Poseidon hash for 1..=5 inputs.
|
|
112
|
+
*/
|
|
113
|
+
export function poseidonHash(inputs) {
|
|
114
|
+
if (!Array.isArray(inputs)) {
|
|
115
|
+
throw new RangeError('Expected array of bigint inputs for poseidonHash');
|
|
116
|
+
}
|
|
117
|
+
const width = inputs.length + 1;
|
|
118
|
+
const params = POSEIDON_PARAMS[width];
|
|
119
|
+
if (!params) {
|
|
120
|
+
throw new RangeError(`Unsupported Poseidon arity ${inputs.length} (expected 1..=5)`);
|
|
121
|
+
}
|
|
122
|
+
return poseidonPermuteWithParams(params, inputs);
|
|
123
|
+
}
|
|
124
|
+
export function poseidon2(a, b) {
|
|
125
|
+
return poseidonPermuteWithParams(POSEIDON_PARAMS_3, [a, b]);
|
|
126
|
+
}
|
|
127
|
+
export function poseidon3(a, b, c) {
|
|
128
|
+
return poseidonPermuteWithParams(POSEIDON_PARAMS_4, [a, b, c]);
|
|
129
|
+
}
|
|
130
|
+
export function poseidon4(a, b, c, d) {
|
|
131
|
+
return poseidonPermuteWithParams(POSEIDON_PARAMS_5, [a, b, c, d]);
|
|
132
|
+
}
|
|
133
|
+
export function poseidon5(a, b, c, d, e) {
|
|
134
|
+
return poseidonPermuteWithParams(POSEIDON_PARAMS_6, [a, b, c, d, e]);
|
|
135
|
+
}
|
|
136
|
+
/** `asset_id = mask_to_fr_be(SHA-256("audren/v1/asset" || mint_32))`. */
|
|
137
|
+
export function deriveAssetId(mintBytes) {
|
|
138
|
+
if (!(mintBytes instanceof Uint8Array) || mintBytes.byteLength !== 32) {
|
|
139
|
+
throw new RangeError(`mintBytes must be a 32-byte Uint8Array, got ${mintBytes instanceof Uint8Array ? mintBytes.byteLength : String(mintBytes)}`);
|
|
140
|
+
}
|
|
141
|
+
const preimage = new Uint8Array(ASSET_ID_DOMAIN_BYTES.byteLength + 32);
|
|
142
|
+
preimage.set(ASSET_ID_DOMAIN_BYTES, 0);
|
|
143
|
+
preimage.set(mintBytes, ASSET_ID_DOMAIN_BYTES.byteLength);
|
|
144
|
+
return bytes32ToFrMasked(sha256(preimage));
|
|
145
|
+
}
|
|
146
|
+
export function deriveAssetIdBytes(mintBytes) {
|
|
147
|
+
return frToBeBytes(deriveAssetId(mintBytes));
|
|
148
|
+
}
|
|
149
|
+
export function deriveSpendPk(spendSk) {
|
|
150
|
+
return poseidon2(DOMAIN_PK, spendSk);
|
|
151
|
+
}
|
|
152
|
+
export function deriveNullifierKey(spendSk) {
|
|
153
|
+
return poseidon2(DOMAIN_NK, spendSk);
|
|
154
|
+
}
|
|
155
|
+
export function deriveStealthOwner(spendPk, tweak) {
|
|
156
|
+
return poseidon3(DOMAIN_STEALTH, spendPk, tweak);
|
|
157
|
+
}
|
|
158
|
+
export function computeNoteCommitment(stealthOwner, assetId, amount, blinding) {
|
|
159
|
+
return poseidon5(DOMAIN_NOTE, stealthOwner, assetId, amount, blinding);
|
|
160
|
+
}
|
|
161
|
+
export function computeRealNullifier(nk, noteCm, globalLeafIndex) {
|
|
162
|
+
return poseidon4(DOMAIN_NULLIFIER, nk, noteCm, globalLeafIndex);
|
|
163
|
+
}
|
|
164
|
+
export function computeDummyNullifier(nk, blinding) {
|
|
165
|
+
return poseidon3(DOMAIN_DUMMY_NF, nk, blinding);
|
|
166
|
+
}
|
|
167
|
+
const U64_MAX = 0xffffffffffffffffn;
|
|
168
|
+
export function packPublicAmounts(publicAmountOut, relayerFeeAmount) {
|
|
169
|
+
if (typeof publicAmountOut !== 'bigint' ||
|
|
170
|
+
publicAmountOut < 0n ||
|
|
171
|
+
publicAmountOut > U64_MAX) {
|
|
172
|
+
throw new RangeError(`publicAmountOut must be a u64 bigint in 0..=2^64-1, got ${String(publicAmountOut)}`);
|
|
173
|
+
}
|
|
174
|
+
if (typeof relayerFeeAmount !== 'bigint' ||
|
|
175
|
+
relayerFeeAmount < 0n ||
|
|
176
|
+
relayerFeeAmount > U64_MAX) {
|
|
177
|
+
throw new RangeError(`relayerFeeAmount must be a u64 bigint in 0..=2^64-1, got ${String(relayerFeeAmount)}`);
|
|
178
|
+
}
|
|
179
|
+
return modFr(publicAmountOut + (relayerFeeAmount << 64n));
|
|
180
|
+
}
|
|
181
|
+
export function computePublicInputHash(params) {
|
|
182
|
+
const hA = poseidon5(DOMAIN_PUB_HASH_A, params.superRoot, params.nf0, params.nf1, params.cm0);
|
|
183
|
+
const hB = poseidon5(DOMAIN_PUB_HASH_B, params.cm1, params.cm2, params.publicAssetId, packPublicAmounts(params.publicAmountOut, params.relayerFeeAmount));
|
|
184
|
+
return poseidon4(DOMAIN_PUB_HASH_FINAL, hA, hB, params.ctxHash);
|
|
185
|
+
}
|
|
186
|
+
/** Compute the global 16-lane super-root (2-level 4-ary Poseidon4 tree). */
|
|
187
|
+
export function computeSuperRoot4Ary(laneRoots) {
|
|
188
|
+
if (!Array.isArray(laneRoots) || laneRoots.length !== NUM_LANES) {
|
|
189
|
+
throw new RangeError(`Expected ${NUM_LANES} lane roots, got ${Array.isArray(laneRoots) ? laneRoots.length : String(laneRoots)}`);
|
|
190
|
+
}
|
|
191
|
+
const mid = [
|
|
192
|
+
poseidon4(laneRoots[0], laneRoots[1], laneRoots[2], laneRoots[3]),
|
|
193
|
+
poseidon4(laneRoots[4], laneRoots[5], laneRoots[6], laneRoots[7]),
|
|
194
|
+
poseidon4(laneRoots[8], laneRoots[9], laneRoots[10], laneRoots[11]),
|
|
195
|
+
poseidon4(laneRoots[12], laneRoots[13], laneRoots[14], laneRoots[15]),
|
|
196
|
+
];
|
|
197
|
+
return poseidon4(mid[0], mid[1], mid[2], mid[3]);
|
|
198
|
+
}
|
|
199
|
+
/** Compute level-4 root of a 256-leaf subtree truncated at `activeLen` leaves (rest = Z[0]). */
|
|
200
|
+
export function computeSubtree256Root(leaves, activeLen) {
|
|
201
|
+
let layer = new Array(256);
|
|
202
|
+
for (let i = 0; i < 256; i++) {
|
|
203
|
+
layer[i] = i < activeLen && i < leaves.length ? leaves[i] : ZERO_HASHES_4ARY[0];
|
|
204
|
+
}
|
|
205
|
+
for (let level = 0; level < 4; level++) {
|
|
206
|
+
const nextLen = layer.length >>> 2;
|
|
207
|
+
const next = new Array(nextLen);
|
|
208
|
+
for (let i = 0; i < nextLen; i++) {
|
|
209
|
+
next[i] = poseidon4(layer[i * 4], layer[i * 4 + 1], layer[i * 4 + 2], layer[i * 4 + 3]);
|
|
210
|
+
}
|
|
211
|
+
layer = next;
|
|
212
|
+
}
|
|
213
|
+
return layer[0];
|
|
214
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './prover.ts';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './prover.js';
|
package/dist/prover.d.ts
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@audren-xyz/sdk/prover` — Exact BN254 Groth16 WASM prover backed by `crates/audren-circuits`
|
|
3
|
+
* (`JoinSplit4AryCircuit`, `DEPTH = 20`, `17,861` R1CS, `2^15` FFT domain, `192 B` proof).
|
|
4
|
+
*
|
|
5
|
+
* Works identically in Node.js and Browser Web Workers with zero `wasm-bindgen` glue
|
|
6
|
+
* using the fixed `4,611 B` binary witness -> `384 B` proof+public-outputs ABI.
|
|
7
|
+
*/
|
|
8
|
+
import { type MerklePath4Ary } from './store.ts';
|
|
9
|
+
export interface JoinSplitInputWitness {
|
|
10
|
+
spendSk: bigint;
|
|
11
|
+
tweak: bigint;
|
|
12
|
+
assetId: bigint;
|
|
13
|
+
amount: bigint;
|
|
14
|
+
blinding: bigint;
|
|
15
|
+
isDummy: boolean;
|
|
16
|
+
merklePath: MerklePath4Ary;
|
|
17
|
+
}
|
|
18
|
+
export interface JoinSplitOutputWitness {
|
|
19
|
+
stealthOwner: bigint;
|
|
20
|
+
assetId: bigint;
|
|
21
|
+
amount: bigint;
|
|
22
|
+
blinding: bigint;
|
|
23
|
+
}
|
|
24
|
+
export interface JoinSplitWitness {
|
|
25
|
+
superRoot: bigint;
|
|
26
|
+
txAssetId: bigint;
|
|
27
|
+
publicAssetId: bigint;
|
|
28
|
+
publicAmountOut: bigint;
|
|
29
|
+
relayerFeeAmount: bigint;
|
|
30
|
+
ctxHash: bigint;
|
|
31
|
+
omitNf1: boolean;
|
|
32
|
+
inputs: [JoinSplitInputWitness, JoinSplitInputWitness];
|
|
33
|
+
outputs: [JoinSplitOutputWitness, JoinSplitOutputWitness, JoinSplitOutputWitness];
|
|
34
|
+
}
|
|
35
|
+
export interface JoinSplitProofResult {
|
|
36
|
+
proof192: Uint8Array;
|
|
37
|
+
nf0: Uint8Array;
|
|
38
|
+
nf1: Uint8Array;
|
|
39
|
+
cm0: Uint8Array;
|
|
40
|
+
cm1: Uint8Array;
|
|
41
|
+
cm2: Uint8Array;
|
|
42
|
+
publicInputHash: Uint8Array;
|
|
43
|
+
}
|
|
44
|
+
export declare function dummyInputWitness(spendSk: bigint, assetId: bigint, blinding: bigint): JoinSplitInputWitness;
|
|
45
|
+
export declare function dummyOutputWitness(assetId: bigint, blinding: bigint): JoinSplitOutputWitness;
|
|
46
|
+
/**
|
|
47
|
+
* Encode `JoinSplitWitness` into the exact `4,611 B` binary witness ABI consumed by
|
|
48
|
+
* `audren_circuits.wasm` (`encode_joinsplit_witness_bytes` in `crates/audren-circuits`).
|
|
49
|
+
*/
|
|
50
|
+
export declare function encodeJoinsplitWitness(w: JoinSplitWitness): Uint8Array;
|
|
51
|
+
export interface AudrenWasmProverInitOptions {
|
|
52
|
+
/** Pre-fetched `audren_circuits.wasm` binary (Browser/Worker or custom loader). */
|
|
53
|
+
wasmBytes?: Uint8Array | ArrayBuffer;
|
|
54
|
+
/** URL to fetch `audren_circuits.wasm` (Browser/Worker, e.g. `/wasm/audren_circuits.wasm`). */
|
|
55
|
+
wasmUrl?: string;
|
|
56
|
+
/** Pre-fetched compressed ceremony proving key (`audren_joinsplit.pk`, 3,927,280 B). */
|
|
57
|
+
pkCompressed?: Uint8Array | ArrayBuffer;
|
|
58
|
+
/** URL to fetch `audren_joinsplit.pk` (Browser/Worker, defaults to sibling `/wasm/audren_joinsplit.pk`). */
|
|
59
|
+
pkUrl?: string;
|
|
60
|
+
/** Skip loading the proving key during `init()` (caller will call `loadProvingKeyCompressed()`). */
|
|
61
|
+
deferPk?: boolean;
|
|
62
|
+
/** Verify loaded proving key SHA-256 against `CANONICAL_PK_SHA256` (default: true). */
|
|
63
|
+
verifyPkHash?: boolean;
|
|
64
|
+
/** Verify loaded WASM binary SHA-256 against `CANONICAL_WASM_SHA256` (default: true). */
|
|
65
|
+
verifyWasmHash?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Stateful handle to the loaded `audren_circuits.wasm` BN254 Groth16 prover instance.
|
|
69
|
+
* Reuse one instance per Worker/process to keep the deserialized ceremony proving key warm in WASM RAM.
|
|
70
|
+
*/
|
|
71
|
+
export declare class AudrenWasmProver {
|
|
72
|
+
private exports;
|
|
73
|
+
private pkReady;
|
|
74
|
+
private disposed;
|
|
75
|
+
private poisoned;
|
|
76
|
+
private constructor();
|
|
77
|
+
private assertUsable;
|
|
78
|
+
/**
|
|
79
|
+
* Release this prover handle, zeroize WASM linear memory, and drop the `WebAssembly.Instance`
|
|
80
|
+
* reference so residual witness secrets and proving-key buffers can be garbage-collected.
|
|
81
|
+
* Subsequent calls throw immediately instead of reusing freed or stale WASM state.
|
|
82
|
+
*/
|
|
83
|
+
dispose(): void;
|
|
84
|
+
static init(options?: AudrenWasmProverInitOptions): Promise<AudrenWasmProver>;
|
|
85
|
+
/**
|
|
86
|
+
* Load a compressed `ProvingKey<Bn254>` (`audren_joinsplit.pk`, curve-validated inside WASM).
|
|
87
|
+
* Enforces `CANONICAL_PK_SHA256` by default (even when `init({ deferPk: true })` was used);
|
|
88
|
+
* pass `{ allowCustomPk: true }` to opt out explicitly for custom circuits/testing.
|
|
89
|
+
*/
|
|
90
|
+
loadProvingKeyCompressed(pkCompressed: Uint8Array, options?: {
|
|
91
|
+
allowCustomPk?: boolean;
|
|
92
|
+
}): void;
|
|
93
|
+
/** Compute canonical Circom / `sol_poseidon` BN254 hash directly inside WASM (1..=12 inputs). */
|
|
94
|
+
poseidonHashWasm(inputsBe32: readonly Uint8Array[]): Uint8Array;
|
|
95
|
+
/**
|
|
96
|
+
* Generate a canonical `192 B` Solana-compressed BN254 Groth16 proof + public outputs.
|
|
97
|
+
* Uses cryptographic randomness from `crypto.getRandomValues` unless an explicit `seed32` is passed.
|
|
98
|
+
*/
|
|
99
|
+
proveJoinsplit(witness: JoinSplitWitness, seed32?: Uint8Array): JoinSplitProofResult;
|
|
100
|
+
}
|