@permissionless-technologies/upp-sdk 0.4.21 → 0.4.22
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/README.md +7 -3
- package/dist/chunk-2BSIUEPO.js +343 -0
- package/dist/chunk-2BSIUEPO.js.map +1 -0
- package/dist/{chunk-V6MW5VOF.cjs → chunk-632LPXPX.cjs} +4 -4
- package/dist/{chunk-V6MW5VOF.cjs.map → chunk-632LPXPX.cjs.map} +1 -1
- package/dist/{chunk-ND56VNCF.js → chunk-D4VCRPKS.js} +2 -2
- package/dist/{chunk-ND56VNCF.js.map → chunk-D4VCRPKS.js.map} +1 -1
- package/dist/{chunk-YHBUCKVS.cjs → chunk-DYSU7JYL.cjs} +23 -23
- package/dist/{chunk-YHBUCKVS.cjs.map → chunk-DYSU7JYL.cjs.map} +1 -1
- package/dist/{chunk-RYEYGGE7.cjs → chunk-IX7HV5TE.cjs} +18 -5
- package/dist/chunk-IX7HV5TE.cjs.map +1 -0
- package/dist/{chunk-5H27F6W6.cjs → chunk-IYRCJAME.cjs} +13 -9
- package/dist/chunk-IYRCJAME.cjs.map +1 -0
- package/dist/{chunk-KRLRJ3HN.js → chunk-KR4GB6VC.js} +18 -5
- package/dist/chunk-KR4GB6VC.js.map +1 -0
- package/dist/{chunk-C7DUABSG.js → chunk-Q6BLTPWV.js} +13 -9
- package/dist/chunk-Q6BLTPWV.js.map +1 -0
- package/dist/{chunk-7VPW5T5R.js → chunk-UMWY4ICQ.js} +3 -3
- package/dist/{chunk-7VPW5T5R.js.map → chunk-UMWY4ICQ.js.map} +1 -1
- package/dist/{chunk-PZAV2S5E.cjs → chunk-UYPIWBKM.cjs} +2 -2
- package/dist/{chunk-PZAV2S5E.cjs.map → chunk-UYPIWBKM.cjs.map} +1 -1
- package/dist/chunk-VVW5VVY3.cjs +347 -0
- package/dist/chunk-VVW5VVY3.cjs.map +1 -0
- package/dist/{chunk-OLJFKARA.js → chunk-XDWRMHLY.js} +15 -15
- package/dist/{chunk-OLJFKARA.js.map → chunk-XDWRMHLY.js.map} +1 -1
- package/dist/core/index.cjs +80 -67
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/core/index.js +5 -4
- package/dist/core/proof-worker-entry.cjs +8 -8
- package/dist/core/proof-worker-entry.cjs.map +1 -1
- package/dist/core/proof-worker-entry.js +8 -8
- package/dist/core/proof-worker-entry.js.map +1 -1
- package/dist/{index-PgqOAfcc.d.cts → index-AooYZ0kF.d.cts} +1 -1
- package/dist/{index-DsXMd8zh.d.ts → index-CpfUNGm9.d.ts} +1 -1
- package/dist/{index-DmowSsZb.d.ts → index-De5B4r0l.d.ts} +9 -3
- package/dist/{index-DcfqeWvk.d.cts → index-hNuffoCo.d.cts} +9 -3
- package/dist/index.cjs +88 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/indexer/index.cjs +6 -6
- package/dist/indexer/index.d.cts +5 -5
- package/dist/indexer/index.d.ts +5 -5
- package/dist/indexer/index.js +1 -1
- package/dist/{proof-VINVGL4F.cjs → proof-X3MVQFFZ.cjs} +14 -13
- package/dist/{proof-VINVGL4F.cjs.map → proof-X3MVQFFZ.cjs.map} +1 -1
- package/dist/{proof-XQG5DN5N.js → proof-YMXBL4D5.js} +4 -3
- package/dist/{proof-XQG5DN5N.js.map → proof-YMXBL4D5.js.map} +1 -1
- package/dist/react/index.cjs +123 -39
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +44 -6
- package/dist/react/index.d.ts +44 -6
- package/dist/react/index.js +90 -18
- package/dist/react/index.js.map +1 -1
- package/dist/{transfer-Cqg235q6.d.ts → transfer-BGzySIhC.d.ts} +124 -5
- package/dist/{transfer-B4q3ZTJK.d.cts → transfer-BhB-UuBP.d.cts} +124 -5
- package/dist/{transfer-7IFAXV5K.cjs → transfer-H6UWWUSN.cjs} +11 -10
- package/dist/{transfer-7IFAXV5K.cjs.map → transfer-H6UWWUSN.cjs.map} +1 -1
- package/dist/{transfer-FWCRUWWM.js → transfer-MLVRASM3.js} +5 -4
- package/dist/{transfer-FWCRUWWM.js.map → transfer-MLVRASM3.js.map} +1 -1
- package/package.json +1 -1
- package/src/deployments/11155111.json +12 -12
- package/dist/chunk-5H27F6W6.cjs.map +0 -1
- package/dist/chunk-C7DUABSG.js.map +0 -1
- package/dist/chunk-KRLRJ3HN.js.map +0 -1
- package/dist/chunk-RYEYGGE7.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -10,7 +10,8 @@ Privacy-preserving token operations for any ERC20 token.
|
|
|
10
10
|
- **Large anonymity set** — All token users share one Merkle tree
|
|
11
11
|
- **Compliance-ready** — Pluggable ASP (Association Set Provider) with ragequit fallback
|
|
12
12
|
- **Pluggable architecture** — Bring your own account adapter, ASP provider, storage backend
|
|
13
|
-
- **SNARK + STARK** — Dual proof system
|
|
13
|
+
- **SNARK + STARK** — Dual proof system: PLONK/BLS12-381 (128-bit, EIP-2537 precompiles) + Circle STARK (post-quantum)
|
|
14
|
+
- **Web Worker proving** — Off-main-thread proof generation keeps UI responsive
|
|
14
15
|
- **Modern stack** — Built on viem, TypeScript strict mode, ESM-first
|
|
15
16
|
|
|
16
17
|
## Installation
|
|
@@ -37,8 +38,11 @@ import { ... } from '@permissionless-technologies/upp-sdk/react'
|
|
|
37
38
|
// Indexer: note scanning, storage adapters
|
|
38
39
|
import { ... } from '@permissionless-technologies/upp-sdk/indexer'
|
|
39
40
|
|
|
40
|
-
// Utilities: poseidon
|
|
41
|
+
// Utilities: poseidon (BLS12-381), merkle trees
|
|
41
42
|
import { ... } from '@permissionless-technologies/upp-sdk/utils'
|
|
43
|
+
|
|
44
|
+
// Web Worker for off-main-thread proof generation
|
|
45
|
+
import '@permissionless-technologies/upp-sdk/worker'
|
|
42
46
|
```
|
|
43
47
|
|
|
44
48
|
## Quick Start
|
|
@@ -97,7 +101,7 @@ await noteStore.load()
|
|
|
97
101
|
├── keys/ # Key derivation (signature, direct, custom)
|
|
98
102
|
├── react/ # React hooks (useUPPAccount, useShield, etc.)
|
|
99
103
|
├── indexer/ # Note scanning + pluggable storage
|
|
100
|
-
├── utils/ # Poseidon
|
|
104
|
+
├── utils/ # Poseidon (BLS12-381), Merkle trees
|
|
101
105
|
├── contracts/ # ABIs + Solidity interfaces
|
|
102
106
|
└── deployments/ # Per-chain contract addresses
|
|
103
107
|
```
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
// src/core/circuit-cache.ts
|
|
2
|
+
var CIRCUIT_VERSION = "20260330";
|
|
3
|
+
var CIRCUIT_CDN_BASE = `https://circuits.upd.io/${CIRCUIT_VERSION}/`;
|
|
4
|
+
var DB_NAME = "upp-circuit-cache";
|
|
5
|
+
var DB_VERSION = 1;
|
|
6
|
+
var STORE_NAME = "artifacts";
|
|
7
|
+
function openDB() {
|
|
8
|
+
return new Promise((resolve, reject) => {
|
|
9
|
+
const request = indexedDB.open(DB_NAME, DB_VERSION);
|
|
10
|
+
request.onupgradeneeded = () => {
|
|
11
|
+
const db = request.result;
|
|
12
|
+
if (!db.objectStoreNames.contains(STORE_NAME)) {
|
|
13
|
+
db.createObjectStore(STORE_NAME, { keyPath: "key" });
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
request.onsuccess = () => resolve(request.result);
|
|
17
|
+
request.onerror = () => reject(request.error);
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async function idbGet(key) {
|
|
21
|
+
const db = await openDB();
|
|
22
|
+
return new Promise((resolve, reject) => {
|
|
23
|
+
const tx = db.transaction(STORE_NAME, "readonly");
|
|
24
|
+
const store = tx.objectStore(STORE_NAME);
|
|
25
|
+
const req = store.get(key);
|
|
26
|
+
req.onsuccess = () => resolve(req.result);
|
|
27
|
+
req.onerror = () => reject(req.error);
|
|
28
|
+
tx.oncomplete = () => db.close();
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
async function idbPut(entry) {
|
|
32
|
+
const db = await openDB();
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
const tx = db.transaction(STORE_NAME, "readwrite");
|
|
35
|
+
const store = tx.objectStore(STORE_NAME);
|
|
36
|
+
store.put(entry);
|
|
37
|
+
tx.oncomplete = () => {
|
|
38
|
+
db.close();
|
|
39
|
+
resolve();
|
|
40
|
+
};
|
|
41
|
+
tx.onerror = () => {
|
|
42
|
+
db.close();
|
|
43
|
+
reject(tx.error);
|
|
44
|
+
};
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
async function idbDelete(key) {
|
|
48
|
+
const db = await openDB();
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
const tx = db.transaction(STORE_NAME, "readwrite");
|
|
51
|
+
const store = tx.objectStore(STORE_NAME);
|
|
52
|
+
store.delete(key);
|
|
53
|
+
tx.oncomplete = () => {
|
|
54
|
+
db.close();
|
|
55
|
+
resolve();
|
|
56
|
+
};
|
|
57
|
+
tx.onerror = () => {
|
|
58
|
+
db.close();
|
|
59
|
+
reject(tx.error);
|
|
60
|
+
};
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
async function idbGetAllKeys() {
|
|
64
|
+
const db = await openDB();
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
const tx = db.transaction(STORE_NAME, "readonly");
|
|
67
|
+
const store = tx.objectStore(STORE_NAME);
|
|
68
|
+
const req = store.getAllKeys();
|
|
69
|
+
req.onsuccess = () => resolve(req.result);
|
|
70
|
+
req.onerror = () => reject(req.error);
|
|
71
|
+
tx.oncomplete = () => db.close();
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
async function idbGetAll() {
|
|
75
|
+
const db = await openDB();
|
|
76
|
+
return new Promise((resolve, reject) => {
|
|
77
|
+
const tx = db.transaction(STORE_NAME, "readonly");
|
|
78
|
+
const store = tx.objectStore(STORE_NAME);
|
|
79
|
+
const req = store.getAll();
|
|
80
|
+
req.onsuccess = () => resolve(req.result);
|
|
81
|
+
req.onerror = () => reject(req.error);
|
|
82
|
+
tx.oncomplete = () => db.close();
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
async function idbClear() {
|
|
86
|
+
const db = await openDB();
|
|
87
|
+
return new Promise((resolve, reject) => {
|
|
88
|
+
const tx = db.transaction(STORE_NAME, "readwrite");
|
|
89
|
+
const store = tx.objectStore(STORE_NAME);
|
|
90
|
+
store.clear();
|
|
91
|
+
tx.oncomplete = () => {
|
|
92
|
+
db.close();
|
|
93
|
+
resolve();
|
|
94
|
+
};
|
|
95
|
+
tx.onerror = () => {
|
|
96
|
+
db.close();
|
|
97
|
+
reject(tx.error);
|
|
98
|
+
};
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async function downloadWithProgress(url, circuitType, artifact, onProgress, signal) {
|
|
102
|
+
const response = await fetch(url, { signal });
|
|
103
|
+
if (!response.ok) {
|
|
104
|
+
throw new Error(`Failed to download ${artifact} for ${circuitType}: ${response.status} ${response.statusText}`);
|
|
105
|
+
}
|
|
106
|
+
const contentLength = parseInt(response.headers.get("Content-Length") ?? "0", 10);
|
|
107
|
+
if (response.body && contentLength > 0 && onProgress) {
|
|
108
|
+
const reader = response.body.getReader();
|
|
109
|
+
const chunks = [];
|
|
110
|
+
let bytesDownloaded = 0;
|
|
111
|
+
while (true) {
|
|
112
|
+
const { done, value } = await reader.read();
|
|
113
|
+
if (done) break;
|
|
114
|
+
chunks.push(value);
|
|
115
|
+
bytesDownloaded += value.length;
|
|
116
|
+
onProgress({
|
|
117
|
+
circuitType,
|
|
118
|
+
artifact,
|
|
119
|
+
bytesDownloaded,
|
|
120
|
+
totalBytes: contentLength,
|
|
121
|
+
percent: Math.round(bytesDownloaded / contentLength * 100)
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
const result = new Uint8Array(bytesDownloaded);
|
|
125
|
+
let offset = 0;
|
|
126
|
+
for (const chunk of chunks) {
|
|
127
|
+
result.set(chunk, offset);
|
|
128
|
+
offset += chunk.length;
|
|
129
|
+
}
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
const buffer = await response.arrayBuffer();
|
|
133
|
+
return new Uint8Array(buffer);
|
|
134
|
+
}
|
|
135
|
+
var ALL_CIRCUITS = [
|
|
136
|
+
"transfer",
|
|
137
|
+
"withdraw",
|
|
138
|
+
"merge",
|
|
139
|
+
"merge_transfer_2x2",
|
|
140
|
+
"merge_transfer_4x2",
|
|
141
|
+
"joinsplit"
|
|
142
|
+
];
|
|
143
|
+
var CircuitArtifactCache = class _CircuitArtifactCache {
|
|
144
|
+
// Lazy singleton per JS context (main thread and workers get their own)
|
|
145
|
+
static _instance = null;
|
|
146
|
+
static shared() {
|
|
147
|
+
if (!_CircuitArtifactCache._instance) {
|
|
148
|
+
_CircuitArtifactCache._instance = new _CircuitArtifactCache();
|
|
149
|
+
}
|
|
150
|
+
return _CircuitArtifactCache._instance;
|
|
151
|
+
}
|
|
152
|
+
/** In-flight download deduplication */
|
|
153
|
+
inflight = /* @__PURE__ */ new Map();
|
|
154
|
+
constructor() {
|
|
155
|
+
}
|
|
156
|
+
// --------------------------------------------------------------------------
|
|
157
|
+
// Key helpers
|
|
158
|
+
// --------------------------------------------------------------------------
|
|
159
|
+
key(circuit, artifact, version = CIRCUIT_VERSION) {
|
|
160
|
+
return `${version}_${circuit}_${artifact}`;
|
|
161
|
+
}
|
|
162
|
+
resolveBaseUrl(baseUrl) {
|
|
163
|
+
const url = baseUrl ?? CIRCUIT_CDN_BASE;
|
|
164
|
+
return url.endsWith("/") ? url : `${url}/`;
|
|
165
|
+
}
|
|
166
|
+
// --------------------------------------------------------------------------
|
|
167
|
+
// Public API
|
|
168
|
+
// --------------------------------------------------------------------------
|
|
169
|
+
/**
|
|
170
|
+
* Check if both wasm + zkey are cached for a circuit (current CIRCUIT_VERSION).
|
|
171
|
+
*/
|
|
172
|
+
async isCached(circuit) {
|
|
173
|
+
const [wasm, zkey] = await Promise.all([
|
|
174
|
+
idbGet(this.key(circuit, "wasm")),
|
|
175
|
+
idbGet(this.key(circuit, "zkey"))
|
|
176
|
+
]);
|
|
177
|
+
return wasm !== void 0 && zkey !== void 0;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Download and cache a circuit's artifacts. No-ops if already cached.
|
|
181
|
+
*
|
|
182
|
+
* @param circuit - Which circuit to preload
|
|
183
|
+
* @param baseUrl - CDN base URL (defaults to `https://circuits.upd.io/${CIRCUIT_VERSION}/`)
|
|
184
|
+
* @param onProgress - Byte-level download progress callback
|
|
185
|
+
* @param signal - AbortSignal for cancellation
|
|
186
|
+
*/
|
|
187
|
+
async preload(circuit, baseUrl, onProgress, signal) {
|
|
188
|
+
await this.getArtifacts(circuit, baseUrl, onProgress, signal);
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Get artifacts from cache, downloading if needed.
|
|
192
|
+
* Returns Uint8Array data ready to pass to snarkjs.plonk.fullProve().
|
|
193
|
+
*/
|
|
194
|
+
async getArtifacts(circuit, baseUrl, onProgress, signal) {
|
|
195
|
+
const [wasm, zkey] = await Promise.all([
|
|
196
|
+
this.getOrDownload(circuit, "wasm", baseUrl, onProgress, signal),
|
|
197
|
+
this.getOrDownload(circuit, "zkey", baseUrl, onProgress, signal)
|
|
198
|
+
]);
|
|
199
|
+
return { wasm, zkey };
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* List all cached circuit types (current version only).
|
|
203
|
+
*/
|
|
204
|
+
async getCachedCircuits() {
|
|
205
|
+
const keys = await idbGetAllKeys();
|
|
206
|
+
const prefix = `${CIRCUIT_VERSION}_`;
|
|
207
|
+
const cached = /* @__PURE__ */ new Set();
|
|
208
|
+
for (const k of keys) {
|
|
209
|
+
if (!k.startsWith(prefix)) continue;
|
|
210
|
+
const rest = k.slice(prefix.length);
|
|
211
|
+
const lastUnderscore = rest.lastIndexOf("_");
|
|
212
|
+
if (lastUnderscore > 0) {
|
|
213
|
+
cached.add(rest.slice(0, lastUnderscore));
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return ALL_CIRCUITS.filter((c) => cached.has(c));
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Get cache size information.
|
|
220
|
+
*/
|
|
221
|
+
async getCacheSize() {
|
|
222
|
+
const entries = await idbGetAll();
|
|
223
|
+
let total = 0;
|
|
224
|
+
const circuits = {};
|
|
225
|
+
for (const entry of entries) {
|
|
226
|
+
total += entry.size;
|
|
227
|
+
const parts = entry.key.split("_");
|
|
228
|
+
if (parts.length >= 3) {
|
|
229
|
+
const circuit = parts.slice(1, -1).join("_");
|
|
230
|
+
circuits[circuit] = (circuits[circuit] ?? 0) + entry.size;
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
return { total, circuits };
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
* Get cache status for all circuit types.
|
|
237
|
+
*/
|
|
238
|
+
async getStatus() {
|
|
239
|
+
const entries = await idbGetAll();
|
|
240
|
+
const result = /* @__PURE__ */ new Map();
|
|
241
|
+
const prefix = `${CIRCUIT_VERSION}_`;
|
|
242
|
+
for (const c of ALL_CIRCUITS) {
|
|
243
|
+
result.set(c, { cached: false });
|
|
244
|
+
}
|
|
245
|
+
const wasmMap = /* @__PURE__ */ new Map();
|
|
246
|
+
const zkeyMap = /* @__PURE__ */ new Map();
|
|
247
|
+
for (const entry of entries) {
|
|
248
|
+
if (!entry.key.startsWith(prefix)) continue;
|
|
249
|
+
const rest = entry.key.slice(prefix.length);
|
|
250
|
+
const lastUnderscore = rest.lastIndexOf("_");
|
|
251
|
+
const circuit = rest.slice(0, lastUnderscore);
|
|
252
|
+
const artifact = rest.slice(lastUnderscore + 1);
|
|
253
|
+
if (artifact === "wasm") wasmMap.set(circuit, entry.size);
|
|
254
|
+
else if (artifact === "zkey") zkeyMap.set(circuit, entry.size);
|
|
255
|
+
}
|
|
256
|
+
for (const c of ALL_CIRCUITS) {
|
|
257
|
+
const hasWasm = wasmMap.has(c);
|
|
258
|
+
const hasZkey = zkeyMap.has(c);
|
|
259
|
+
result.set(c, {
|
|
260
|
+
cached: hasWasm && hasZkey,
|
|
261
|
+
wasmSize: wasmMap.get(c),
|
|
262
|
+
zkeySize: zkeyMap.get(c)
|
|
263
|
+
});
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Evict a specific circuit from cache (current version).
|
|
269
|
+
*/
|
|
270
|
+
async evict(circuit) {
|
|
271
|
+
await Promise.all([
|
|
272
|
+
idbDelete(this.key(circuit, "wasm")),
|
|
273
|
+
idbDelete(this.key(circuit, "zkey"))
|
|
274
|
+
]);
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Evict all cached circuit artifacts (all versions).
|
|
278
|
+
*/
|
|
279
|
+
async evictAll() {
|
|
280
|
+
await idbClear();
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Evict all artifacts for a specific version (for cleaning up after SDK updates).
|
|
284
|
+
*/
|
|
285
|
+
async evictVersion(version) {
|
|
286
|
+
const keys = await idbGetAllKeys();
|
|
287
|
+
const prefix = `${version}_`;
|
|
288
|
+
const toDelete = keys.filter((k) => k.startsWith(prefix));
|
|
289
|
+
for (const k of toDelete) {
|
|
290
|
+
await idbDelete(k);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Request persistent storage to prevent browser from evicting the cache.
|
|
295
|
+
* Returns true if granted, false if denied or unavailable.
|
|
296
|
+
*/
|
|
297
|
+
async requestPersistence() {
|
|
298
|
+
if (typeof navigator !== "undefined" && navigator.storage?.persist) {
|
|
299
|
+
return navigator.storage.persist();
|
|
300
|
+
}
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
// --------------------------------------------------------------------------
|
|
304
|
+
// Internal
|
|
305
|
+
// --------------------------------------------------------------------------
|
|
306
|
+
async getOrDownload(circuit, artifact, baseUrl, onProgress, signal) {
|
|
307
|
+
const cacheKey = this.key(circuit, artifact);
|
|
308
|
+
const cached = await idbGet(cacheKey);
|
|
309
|
+
if (cached) {
|
|
310
|
+
return cached.data;
|
|
311
|
+
}
|
|
312
|
+
const inflightKey = `${cacheKey}_${this.resolveBaseUrl(baseUrl)}`;
|
|
313
|
+
const existing = this.inflight.get(inflightKey);
|
|
314
|
+
if (existing) {
|
|
315
|
+
return existing;
|
|
316
|
+
}
|
|
317
|
+
const downloadPromise = this.downloadAndStore(circuit, artifact, baseUrl, onProgress, signal);
|
|
318
|
+
this.inflight.set(inflightKey, downloadPromise);
|
|
319
|
+
try {
|
|
320
|
+
const data = await downloadPromise;
|
|
321
|
+
return data;
|
|
322
|
+
} finally {
|
|
323
|
+
this.inflight.delete(inflightKey);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
async downloadAndStore(circuit, artifact, baseUrl, onProgress, signal) {
|
|
327
|
+
const base = this.resolveBaseUrl(baseUrl);
|
|
328
|
+
const url = `${base}${circuit}.${artifact}`;
|
|
329
|
+
const data = await downloadWithProgress(url, circuit, artifact, onProgress, signal);
|
|
330
|
+
await idbPut({
|
|
331
|
+
key: this.key(circuit, artifact),
|
|
332
|
+
data,
|
|
333
|
+
size: data.byteLength,
|
|
334
|
+
cachedAt: Date.now(),
|
|
335
|
+
version: CIRCUIT_VERSION
|
|
336
|
+
});
|
|
337
|
+
return data;
|
|
338
|
+
}
|
|
339
|
+
};
|
|
340
|
+
|
|
341
|
+
export { CIRCUIT_CDN_BASE, CIRCUIT_VERSION, CircuitArtifactCache };
|
|
342
|
+
//# sourceMappingURL=chunk-2BSIUEPO.js.map
|
|
343
|
+
//# sourceMappingURL=chunk-2BSIUEPO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/core/circuit-cache.ts"],"names":[],"mappings":";AAqBO,IAAM,eAAA,GAAkB;AAGxB,IAAM,gBAAA,GAAmB,2BAA2B,eA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AK,QAAA,CAAS,GAAA,CAAI,WAAA,EAAa,eAAe,CAAA;AAC9C,IAAA,IAAI;AACF,MAAA,MAAM,OAAO,MAAM,eAAA;AACnB,MAAA,OAAO,IAAA;AAAA,IACT,CAAA,SAAE;AACA,MAAA,IAAA,CAAK,QAAA,CAAS,OAAO,WAAW,CAAA;AAAA,IAClC;AAAA,EACF;AAAA,EAEA,MAAc,gBAAA,CACZ,OAAA,EACA,QAAA,EACA,OAAA,EACA,YACA,MAAA,EACqB;AACrB,IAAA,MAAM,IAAA,GAAO,IAAA,CAAK,cAAA,CAAe,OAAO,CAAA;AACxC,IAAA,MAAM,MAAM,CAAA,EAAG,IAAI,CAAA,EAAG,OAAO,IAAI,QAAQ,CAAA,CAAA;AAEzC,IAAA,MAAM,OAAO,MAAM,oBAAA,CAAqB,KAAK,OAAA,EAAS,QAAA,EAAU,YAAY,MAAM,CAAA;AAGlF,IAAA,MAAM,MAAA,CAAO;AAAA,MACX,GAAA,EAAK,IAAA,CAAK,GAAA,CAAI,OAAA,EAAS,QAAQ,CAAA;AAAA,MAC/B,IAAA;AAAA,MACA,MAAM,IAAA,CAAK,UAAA;AAAA,MACX,QAAA,EAAU,KAAK,GAAA,EAAI;AAAA,MACnB,OAAA,EAAS;AAAA,KACV,CAAA;AAED,IAAA,OAAO,IAAA;AAAA,EACT;AACF","file":"chunk-2BSIUEPO.js","sourcesContent":["/**\n * Circuit Artifact Cache — IndexedDB-based caching for PLONK circuit files.\n *\n * Downloads circuit artifacts (wasm + zkey) with progress reporting via\n * ReadableStream, caches them in IndexedDB, and returns Uint8Array data\n * that can be passed directly to snarkjs.plonk.fullProve().\n *\n * Works in both main thread and Web Worker contexts.\n */\n\nimport type { UPPCircuitType } from './proof.js'\n\n// ============================================================================\n// Constants\n// ============================================================================\n\n/**\n * Current circuit artifact version (date-based).\n * Bump this when circuits are recompiled (new trusted setup, circuit changes).\n * Old cached artifacts are ignored (different key prefix in IndexedDB).\n */\nexport const CIRCUIT_VERSION = '20260330'\n\n/** Default CDN base URL for circuit artifacts */\nexport const CIRCUIT_CDN_BASE = `https://circuits.upd.io/${CIRCUIT_VERSION}/`\n\nconst DB_NAME = 'upp-circuit-cache'\nconst DB_VERSION = 1\nconst STORE_NAME = 'artifacts'\n\n// ============================================================================\n// Types\n// ============================================================================\n\n/** Progress report during circuit artifact download */\nexport interface DownloadProgress {\n circuitType: UPPCircuitType\n artifact: 'wasm' | 'zkey'\n bytesDownloaded: number\n totalBytes: number\n /** 0-100 */\n percent: number\n}\n\n/** Resolved (binary) circuit artifacts ready for snarkjs */\nexport interface ResolvedCircuitArtifacts {\n wasm: Uint8Array\n zkey: Uint8Array\n}\n\n/** Cache entry stored in IndexedDB */\ninterface CacheEntry {\n key: string\n data: Uint8Array\n size: number\n cachedAt: number\n version: string\n}\n\n/** Per-circuit cache status */\nexport interface CircuitCacheStatus {\n cached: boolean\n wasmSize?: number\n zkeySize?: number\n}\n\n// ============================================================================\n// IndexedDB Helpers (thin promise wrapper, no external deps)\n// ============================================================================\n\nfunction openDB(): Promise<IDBDatabase> {\n return new Promise((resolve, reject) => {\n const request = indexedDB.open(DB_NAME, DB_VERSION)\n\n request.onupgradeneeded = () => {\n const db = request.result\n if (!db.objectStoreNames.contains(STORE_NAME)) {\n db.createObjectStore(STORE_NAME, { keyPath: 'key' })\n }\n }\n\n request.onsuccess = () => resolve(request.result)\n request.onerror = () => reject(request.error)\n })\n}\n\nasync function idbGet(key: string): Promise<CacheEntry | undefined> {\n const db = await openDB()\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE_NAME, 'readonly')\n const store = tx.objectStore(STORE_NAME)\n const req = store.get(key)\n req.onsuccess = () => resolve(req.result as CacheEntry | undefined)\n req.onerror = () => reject(req.error)\n tx.oncomplete = () => db.close()\n })\n}\n\nasync function idbPut(entry: CacheEntry): Promise<void> {\n const db = await openDB()\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE_NAME, 'readwrite')\n const store = tx.objectStore(STORE_NAME)\n store.put(entry)\n tx.oncomplete = () => { db.close(); resolve() }\n tx.onerror = () => { db.close(); reject(tx.error) }\n })\n}\n\nasync function idbDelete(key: string): Promise<void> {\n const db = await openDB()\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE_NAME, 'readwrite')\n const store = tx.objectStore(STORE_NAME)\n store.delete(key)\n tx.oncomplete = () => { db.close(); resolve() }\n tx.onerror = () => { db.close(); reject(tx.error) }\n })\n}\n\nasync function idbGetAllKeys(): Promise<string[]> {\n const db = await openDB()\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE_NAME, 'readonly')\n const store = tx.objectStore(STORE_NAME)\n const req = store.getAllKeys()\n req.onsuccess = () => resolve(req.result as string[])\n req.onerror = () => reject(req.error)\n tx.oncomplete = () => db.close()\n })\n}\n\nasync function idbGetAll(): Promise<CacheEntry[]> {\n const db = await openDB()\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE_NAME, 'readonly')\n const store = tx.objectStore(STORE_NAME)\n const req = store.getAll()\n req.onsuccess = () => resolve(req.result as CacheEntry[])\n req.onerror = () => reject(req.error)\n tx.oncomplete = () => db.close()\n })\n}\n\nasync function idbClear(): Promise<void> {\n const db = await openDB()\n return new Promise((resolve, reject) => {\n const tx = db.transaction(STORE_NAME, 'readwrite')\n const store = tx.objectStore(STORE_NAME)\n store.clear()\n tx.oncomplete = () => { db.close(); resolve() }\n tx.onerror = () => { db.close(); reject(tx.error) }\n })\n}\n\n// ============================================================================\n// Download with progress\n// ============================================================================\n\nasync function downloadWithProgress(\n url: string,\n circuitType: UPPCircuitType,\n artifact: 'wasm' | 'zkey',\n onProgress?: (p: DownloadProgress) => void,\n signal?: AbortSignal,\n): Promise<Uint8Array> {\n const response = await fetch(url, { signal })\n\n if (!response.ok) {\n throw new Error(`Failed to download ${artifact} for ${circuitType}: ${response.status} ${response.statusText}`)\n }\n\n const contentLength = parseInt(response.headers.get('Content-Length') ?? '0', 10)\n\n // If ReadableStream is available and we have Content-Length, stream with progress\n if (response.body && contentLength > 0 && onProgress) {\n const reader = response.body.getReader()\n const chunks: Uint8Array[] = []\n let bytesDownloaded = 0\n\n while (true) {\n const { done, value } = await reader.read()\n if (done) break\n\n chunks.push(value)\n bytesDownloaded += value.length\n\n onProgress({\n circuitType,\n artifact,\n bytesDownloaded,\n totalBytes: contentLength,\n percent: Math.round((bytesDownloaded / contentLength) * 100),\n })\n }\n\n // Combine chunks into single Uint8Array\n const result = new Uint8Array(bytesDownloaded)\n let offset = 0\n for (const chunk of chunks) {\n result.set(chunk, offset)\n offset += chunk.length\n }\n return result\n }\n\n // Fallback: no progress (ReadableStream unavailable or no Content-Length)\n const buffer = await response.arrayBuffer()\n return new Uint8Array(buffer)\n}\n\n// ============================================================================\n// CircuitArtifactCache\n// ============================================================================\n\n/** All UPP circuit types */\nconst ALL_CIRCUITS: UPPCircuitType[] = [\n 'transfer', 'withdraw', 'merge',\n 'merge_transfer_2x2', 'merge_transfer_4x2', 'joinsplit',\n]\n\nexport class CircuitArtifactCache {\n // Lazy singleton per JS context (main thread and workers get their own)\n private static _instance: CircuitArtifactCache | null = null\n\n static shared(): CircuitArtifactCache {\n if (!CircuitArtifactCache._instance) {\n CircuitArtifactCache._instance = new CircuitArtifactCache()\n }\n return CircuitArtifactCache._instance\n }\n\n /** In-flight download deduplication */\n private inflight = new Map<string, Promise<Uint8Array>>()\n\n private constructor() {}\n\n // --------------------------------------------------------------------------\n // Key helpers\n // --------------------------------------------------------------------------\n\n private key(circuit: UPPCircuitType, artifact: 'wasm' | 'zkey', version = CIRCUIT_VERSION): string {\n return `${version}_${circuit}_${artifact}`\n }\n\n private resolveBaseUrl(baseUrl?: string): string {\n const url = baseUrl ?? CIRCUIT_CDN_BASE\n return url.endsWith('/') ? url : `${url}/`\n }\n\n // --------------------------------------------------------------------------\n // Public API\n // --------------------------------------------------------------------------\n\n /**\n * Check if both wasm + zkey are cached for a circuit (current CIRCUIT_VERSION).\n */\n async isCached(circuit: UPPCircuitType): Promise<boolean> {\n const [wasm, zkey] = await Promise.all([\n idbGet(this.key(circuit, 'wasm')),\n idbGet(this.key(circuit, 'zkey')),\n ])\n return wasm !== undefined && zkey !== undefined\n }\n\n /**\n * Download and cache a circuit's artifacts. No-ops if already cached.\n *\n * @param circuit - Which circuit to preload\n * @param baseUrl - CDN base URL (defaults to `https://circuits.upd.io/${CIRCUIT_VERSION}/`)\n * @param onProgress - Byte-level download progress callback\n * @param signal - AbortSignal for cancellation\n */\n async preload(\n circuit: UPPCircuitType,\n baseUrl?: string,\n onProgress?: (p: DownloadProgress) => void,\n signal?: AbortSignal,\n ): Promise<void> {\n await this.getArtifacts(circuit, baseUrl, onProgress, signal)\n }\n\n /**\n * Get artifacts from cache, downloading if needed.\n * Returns Uint8Array data ready to pass to snarkjs.plonk.fullProve().\n */\n async getArtifacts(\n circuit: UPPCircuitType,\n baseUrl?: string,\n onProgress?: (p: DownloadProgress) => void,\n signal?: AbortSignal,\n ): Promise<ResolvedCircuitArtifacts> {\n const [wasm, zkey] = await Promise.all([\n this.getOrDownload(circuit, 'wasm', baseUrl, onProgress, signal),\n this.getOrDownload(circuit, 'zkey', baseUrl, onProgress, signal),\n ])\n return { wasm, zkey }\n }\n\n /**\n * List all cached circuit types (current version only).\n */\n async getCachedCircuits(): Promise<UPPCircuitType[]> {\n const keys = await idbGetAllKeys()\n const prefix = `${CIRCUIT_VERSION}_`\n const cached = new Set<string>()\n\n for (const k of keys) {\n if (!k.startsWith(prefix)) continue\n const rest = k.slice(prefix.length)\n // rest = \"transfer_zkey\" or \"transfer_wasm\"\n const lastUnderscore = rest.lastIndexOf('_')\n if (lastUnderscore > 0) {\n cached.add(rest.slice(0, lastUnderscore))\n }\n }\n\n return ALL_CIRCUITS.filter(c => cached.has(c))\n }\n\n /**\n * Get cache size information.\n */\n async getCacheSize(): Promise<{ total: number; circuits: Record<string, number> }> {\n const entries = await idbGetAll()\n let total = 0\n const circuits: Record<string, number> = {}\n\n for (const entry of entries) {\n total += entry.size\n // Extract circuit name from key: \"{version}_{circuit}_{artifact}\"\n const parts = entry.key.split('_')\n // Reconstruct circuit name (may contain underscores like merge_transfer_2x2)\n if (parts.length >= 3) {\n const circuit = parts.slice(1, -1).join('_')\n circuits[circuit] = (circuits[circuit] ?? 0) + entry.size\n }\n }\n\n return { total, circuits }\n }\n\n /**\n * Get cache status for all circuit types.\n */\n async getStatus(): Promise<Map<UPPCircuitType, CircuitCacheStatus>> {\n const entries = await idbGetAll()\n const result = new Map<UPPCircuitType, CircuitCacheStatus>()\n const prefix = `${CIRCUIT_VERSION}_`\n\n // Initialize all circuits as not cached\n for (const c of ALL_CIRCUITS) {\n result.set(c, { cached: false })\n }\n\n // Check what's actually cached\n const wasmMap = new Map<string, number>()\n const zkeyMap = new Map<string, number>()\n\n for (const entry of entries) {\n if (!entry.key.startsWith(prefix)) continue\n const rest = entry.key.slice(prefix.length)\n const lastUnderscore = rest.lastIndexOf('_')\n const circuit = rest.slice(0, lastUnderscore)\n const artifact = rest.slice(lastUnderscore + 1)\n\n if (artifact === 'wasm') wasmMap.set(circuit, entry.size)\n else if (artifact === 'zkey') zkeyMap.set(circuit, entry.size)\n }\n\n for (const c of ALL_CIRCUITS) {\n const hasWasm = wasmMap.has(c)\n const hasZkey = zkeyMap.has(c)\n result.set(c, {\n cached: hasWasm && hasZkey,\n wasmSize: wasmMap.get(c),\n zkeySize: zkeyMap.get(c),\n })\n }\n\n return result\n }\n\n /**\n * Evict a specific circuit from cache (current version).\n */\n async evict(circuit: UPPCircuitType): Promise<void> {\n await Promise.all([\n idbDelete(this.key(circuit, 'wasm')),\n idbDelete(this.key(circuit, 'zkey')),\n ])\n }\n\n /**\n * Evict all cached circuit artifacts (all versions).\n */\n async evictAll(): Promise<void> {\n await idbClear()\n }\n\n /**\n * Evict all artifacts for a specific version (for cleaning up after SDK updates).\n */\n async evictVersion(version: string): Promise<void> {\n const keys = await idbGetAllKeys()\n const prefix = `${version}_`\n const toDelete = keys.filter(k => k.startsWith(prefix))\n for (const k of toDelete) {\n await idbDelete(k)\n }\n }\n\n /**\n * Request persistent storage to prevent browser from evicting the cache.\n * Returns true if granted, false if denied or unavailable.\n */\n async requestPersistence(): Promise<boolean> {\n if (typeof navigator !== 'undefined' && navigator.storage?.persist) {\n return navigator.storage.persist()\n }\n return false\n }\n\n // --------------------------------------------------------------------------\n // Internal\n // --------------------------------------------------------------------------\n\n private async getOrDownload(\n circuit: UPPCircuitType,\n artifact: 'wasm' | 'zkey',\n baseUrl?: string,\n onProgress?: (p: DownloadProgress) => void,\n signal?: AbortSignal,\n ): Promise<Uint8Array> {\n const cacheKey = this.key(circuit, artifact)\n\n // Check cache first\n const cached = await idbGet(cacheKey)\n if (cached) {\n return cached.data\n }\n\n // Deduplicate in-flight downloads\n const inflightKey = `${cacheKey}_${this.resolveBaseUrl(baseUrl)}`\n const existing = this.inflight.get(inflightKey)\n if (existing) {\n return existing\n }\n\n const downloadPromise = this.downloadAndStore(circuit, artifact, baseUrl, onProgress, signal)\n\n this.inflight.set(inflightKey, downloadPromise)\n try {\n const data = await downloadPromise\n return data\n } finally {\n this.inflight.delete(inflightKey)\n }\n }\n\n private async downloadAndStore(\n circuit: UPPCircuitType,\n artifact: 'wasm' | 'zkey',\n baseUrl?: string,\n onProgress?: (p: DownloadProgress) => void,\n signal?: AbortSignal,\n ): Promise<Uint8Array> {\n const base = this.resolveBaseUrl(baseUrl)\n const url = `${base}${circuit}.${artifact}`\n\n const data = await downloadWithProgress(url, circuit, artifact, onProgress, signal)\n\n // Store in IndexedDB\n await idbPut({\n key: this.key(circuit, artifact),\n data,\n size: data.byteLength,\n cachedAt: Date.now(),\n version: CIRCUIT_VERSION,\n })\n\n return data\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkIYRCJAME_cjs = require('./chunk-IYRCJAME.cjs');
|
|
4
4
|
|
|
5
5
|
// src/core/client.ts
|
|
6
6
|
function createUPPClient(_config) {
|
|
@@ -38,12 +38,12 @@ function generateRandomBlinding() {
|
|
|
38
38
|
}
|
|
39
39
|
|
|
40
40
|
// src/core/index.ts
|
|
41
|
-
|
|
41
|
+
chunkIYRCJAME_cjs.init_stealth();
|
|
42
42
|
|
|
43
43
|
exports.NOTE_VERSION = NOTE_VERSION;
|
|
44
44
|
exports.createNote = createNote;
|
|
45
45
|
exports.createUPPClient = createUPPClient;
|
|
46
46
|
exports.decryptNote = decryptNote;
|
|
47
47
|
exports.encryptNote = encryptNote;
|
|
48
|
-
//# sourceMappingURL=chunk-
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
48
|
+
//# sourceMappingURL=chunk-632LPXPX.cjs.map
|
|
49
|
+
//# sourceMappingURL=chunk-632LPXPX.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/core/client.ts","../src/core/types.ts","../src/core/note.ts","../src/core/index.ts"],"names":["init_stealth"],"mappings":";;;;;AAoFO,SAAS,gBAAgB,OAAA,EAAqC;AAEnE,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;;;AC9EO,IAAM,YAAA,GAAe;;;ACiCrB,SAAS,WAAW,MAAA,EAAgC;AACzD,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAO,QAAQ,MAAA,EAAQ,IAAA,EAAM,UAAS,GAAI,MAAA;AAG1D,EAAA,MAAM,YAAA,GAAe,YAAY,sBAAA,EAAuB;AAExD,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,YAAA;AAAA,IACT,MAAA;AAAA,IACA,QAAA,EAAU,YAAA;AAAA,IACV,MAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAW,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,KAAQ,GAAI;AAAA,GACzC;AACF;AASO,SAAS,WAAA,CAAY,OAAa,aAAA,EAA0C;AAEjF,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AASO,SAAS,WAAA,CAAY,YAA2B,aAAA,EAAwC;AAE7F,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAyBA,SAAS,sBAAA,GAAiC;AAExC,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAAE,CAAA;AAC/B,EAAA,MAAA,CAAO,gBAAgB,KAAK,CAAA;AAC5B,EAAA,OAAO,OAAO,IAAA,GAAO,KAAA,CAAM,KAAK,KAAK,CAAA,CAAE,IAAI,CAAA,CAAA,KAAK,CAAA,CAAE,SAAS,EAAE,CAAA,CAAE,SAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAE,IAAA,CAAK,EAAE,CAAC,CAAA;AAC3F;;;ACtGAA,8BAAA,EAAA","file":"chunk-V6MW5VOF.cjs","sourcesContent":["/**\n * Main UPP Client\n *\n * Provides high-level API for interacting with the Universal Private Pool.\n */\n\nimport type { Address, PublicClient, WalletClient } from 'viem'\nimport type {\n ShieldParams,\n TransferParams,\n MergeParams,\n WithdrawParams,\n Note,\n} from './types.js'\n\n/**\n * UPP Client configuration\n */\nexport interface UPPClientConfig {\n /** Viem public client for reading chain state */\n publicClient: PublicClient\n /** Viem wallet client for sending transactions */\n walletClient: WalletClient\n /** Universal Private Pool contract address */\n poolAddress: Address\n /** ASP Registry Hub contract address */\n aspHubAddress: Address\n /** Chain ID (optional, derived from clients if not provided) */\n chainId?: number\n}\n\n/**\n * UPP Client interface\n */\nexport interface UPPClient {\n /** Shield tokens into the private pool */\n shield(params: ShieldParams): Promise<{ commitment: `0x${string}`; note: Note }>\n\n /** Transfer tokens privately */\n transfer(params: TransferParams): Promise<{ nullifier: `0x${string}`; changeNote?: Note }>\n\n /** Merge multiple notes into one */\n merge(params: MergeParams): Promise<{ commitment: `0x${string}`; note: Note }>\n\n /** Withdraw tokens from the private pool */\n withdraw(params: WithdrawParams): Promise<{ txHash: `0x${string}` }>\n\n /** Scan for notes belonging to a viewing key */\n scanNotes(viewingKey: `0x${string}`): Promise<Note[]>\n\n /** Get the current state root */\n getStateRoot(): Promise<bigint>\n\n /** Check if a nullifier has been spent */\n isNullifierSpent(nullifier: `0x${string}`): Promise<boolean>\n}\n\n/**\n * Create a UPP client instance\n *\n * @example\n * ```ts\n * import { createUPPClient } from '@upp/sdk'\n * import { createPublicClient, createWalletClient, http } from 'viem'\n * import { sepolia } from 'viem/chains'\n *\n * const publicClient = createPublicClient({\n * chain: sepolia,\n * transport: http(),\n * })\n *\n * const walletClient = createWalletClient({\n * chain: sepolia,\n * transport: http(),\n * })\n *\n * const client = createUPPClient({\n * publicClient,\n * walletClient,\n * poolAddress: '0x...',\n * aspHubAddress: '0x...',\n * })\n * ```\n */\nexport function createUPPClient(_config: UPPClientConfig): UPPClient {\n // TODO: Implement client\n throw new Error('Not implemented')\n}\n","/**\n * Core type definitions for UPP SDK\n */\n\nimport type { Address, Hex } from 'viem'\n\n/**\n * Note version - increment when note structure changes\n */\nexport const NOTE_VERSION = 5\n\n/**\n * A private note in the Universal Private Pool\n */\nexport interface Note {\n /** Note format version */\n version: number\n /** Token amount (in wei) */\n amount: bigint\n /** Random blinding factor */\n blinding: bigint\n /** Current origin - who is responsible for these funds (updated on merge) */\n origin: Address\n /** Sender - who sent this specific note (for payment attribution) */\n sender: Address\n /** ERC20 token address */\n token: Address\n /** Optional memo/message */\n memo?: string\n /** Timestamp when note was created */\n timestamp?: number\n}\n\n/**\n * Encrypted note data stored on-chain (post-quantum, hash-based)\n */\nexport interface EncryptedNote {\n /** AES-GCM encrypted note data */\n ciphertext: Hex\n /** AES-GCM nonce */\n nonce: Hex\n}\n\n/**\n * Stealth meta-address (hash-based, post-quantum)\n * Published once, used by senders to encrypt notes to the recipient\n */\nexport interface StealthMetaAddress {\n /** Owner hash = Poseidon(spendingSecret) */\n ownerHash: bigint\n /** Viewing hash = Poseidon(viewingSecret) */\n viewingHash: bigint\n}\n\n/**\n * One-time address for a specific transaction (simplified for hash-based system)\n */\nexport interface StealthAddress {\n /** Owner hash for this note */\n ownerHash: bigint\n /** Search tag for efficient scanning */\n searchTag?: bigint\n}\n\n/**\n * On-chain merge record for audit trail\n */\nexport interface MergeRecord {\n /** Output commitment (the merged note) */\n outputCommitment: Hex\n /** First input nullifier */\n nullifier1: Hex\n /** Second input nullifier */\n nullifier2: Hex\n /** Who performed the merge (new origin) */\n merger: Address\n /** Token that was merged */\n token: Address\n /** Block timestamp */\n timestamp: number\n}\n\n/**\n * ASP (Association Set Provider) root\n */\nexport interface ASPRoot {\n /** Merkle root of approved addresses */\n root: bigint\n /** IPFS hash for off-chain data */\n ipfsHash: Hex\n /** When this root was published */\n timestamp: number\n /** Number of addresses in the set */\n leafCount: number\n}\n\n/**\n * Shield operation parameters\n */\nexport interface ShieldParams {\n /** ERC20 token to shield */\n token: Address\n /** Amount to shield (in wei) */\n amount: bigint\n /** Optional: recipient owner hash (defaults to self) */\n recipientOwnerHash?: bigint\n /** Optional: memo to include in note */\n memo?: string\n}\n\n/**\n * Transfer operation parameters\n */\nexport interface TransferParams {\n /** Note to spend */\n note: Note\n /** Recipient stealth address */\n recipient: StealthAddress\n /** Amount to send (remainder goes back to sender as change) */\n amount: bigint\n /** Optional: memo to include */\n memo?: string\n}\n\n/**\n * Merge operation parameters\n */\nexport interface MergeParams {\n /** Notes to merge (must be same token) */\n notes: [Note, Note]\n /** Optional: memo for the merged note */\n memo?: string\n}\n\n/**\n * Withdraw operation parameters\n */\nexport interface WithdrawParams {\n /** Note to withdraw */\n note: Note\n /** Amount to withdraw */\n amount: bigint\n /** Recipient address for the tokens */\n recipient: Address\n /** ASP ID to use for compliance check */\n aspId?: number\n /** Use ragequit (origin withdrawing own funds) */\n ragequit?: boolean\n}\n\n/**\n * Proof for ZK operations\n */\nexport interface Proof {\n /** Proof data (format depends on proof system: Groth16 has pi_a/pi_b/pi_c, PLONK has A/B/C/Z/T1-T3/evals/Wxi/Wxiw) */\n proof: Record<string, any>\n /** Public signals */\n publicSignals: string[]\n}\n\n/**\n * Note commitment (hash)\n */\nexport type Commitment = Hex\n\n/**\n * Nullifier (spent note identifier)\n */\nexport type Nullifier = Hex\n\n// =========================================================================\n// STARK Note Types (M31/Keccak-based, post-quantum)\n// =========================================================================\n\nimport type { M31Digest } from '../utils/keccak-m31.js'\n\n// STARK_AMOUNT_SCALE moved to utils/stark.ts\nexport { STARK_AMOUNT_SCALE } from '../utils/stark.js'\n\n/**\n * A private STARK note in the Universal Private Pool.\n *\n * All field values are M31 elements (< 2^31 - 1).\n * Commitment = keccak_m31(amount, ownerHash[0..4], blinding, origin, token).\n */\nexport interface StarkNote {\n /** Amount in STARK units (actual wei = amount * STARK_AMOUNT_SCALE) */\n amount: bigint\n /** Owner hash = keccak_m31(starkSecret) — 4 M31 elements */\n ownerHash: M31Digest\n /** Random blinding factor (M31) */\n blinding: bigint\n /** Origin address encoded as M31 (lower 31 bits of address) */\n origin: bigint\n /** Token address encoded as M31 (lower 31 bits of address) */\n token: bigint\n /** The leaf index in the STARK Keccak Merkle tree (set after shielding) */\n leafIndex?: number\n /** The commitment digest (set after computation) */\n commitment?: M31Digest\n /** Optional memo */\n memo?: string\n /** Timestamp when note was created */\n timestamp?: number\n}\n\n/**\n * STARK stealth meta-address (M31/Keccak-based)\n * Published once, used by senders to encrypt notes to the recipient\n */\nexport interface StarkStealthMetaAddress {\n /** Owner hash = keccak_m31(starkSecret) — 4 M31 elements */\n ownerHash: M31Digest\n /** Viewing hash = keccak_m31(starkViewingSecret) — 4 M31 elements */\n viewingHash: M31Digest\n}\n\n/**\n * STARK proof for ZK operations (serialized Circle STARK proof)\n */\nexport interface StarkProof {\n /** Raw serialized Stwo Circle STARK proof bytes */\n proofBytes: Hex\n /** Public inputs seed (keccak256 of public parameters) */\n publicInputsSeed: Hex\n}\n","/**\n * Note management utilities\n *\n * Create, encrypt, and decrypt private notes.\n */\n\nimport type { Address, Hex } from 'viem'\nimport type { Note, EncryptedNote } from './types.js'\nimport { NOTE_VERSION } from './types.js'\n\n/**\n * Parameters for creating a new note\n */\nexport interface CreateNoteParams {\n /** Token amount */\n amount: bigint\n /** ERC20 token address */\n token: Address\n /** Origin address (who is responsible) */\n origin: Address\n /** Sender address */\n sender: Address\n /** Optional memo */\n memo?: string\n /** Optional blinding factor (generated if not provided) */\n blinding?: bigint\n}\n\n/**\n * Create a new private note\n *\n * @example\n * ```ts\n * const note = createNote({\n * amount: 1000n * 10n ** 18n,\n * token: '0x...',\n * origin: '0xMyAddress...',\n * sender: '0xMyAddress...',\n * memo: 'Payment for services',\n * })\n * ```\n */\nexport function createNote(params: CreateNoteParams): Note {\n const { amount, token, origin, sender, memo, blinding } = params\n\n // Generate random blinding factor if not provided\n const noteBlinding = blinding ?? generateRandomBlinding()\n\n return {\n version: NOTE_VERSION,\n amount,\n blinding: noteBlinding,\n origin,\n sender,\n token,\n memo,\n timestamp: Math.floor(Date.now() / 1000),\n }\n}\n\n/**\n * Encrypt a note for a recipient\n *\n * @param note - The note to encrypt\n * @param sharedSecret - ECDH shared secret with recipient\n * @returns Encrypted note data\n */\nexport function encryptNote(_note: Note, _sharedSecret: Uint8Array): EncryptedNote {\n // TODO: Implement AES-GCM encryption\n throw new Error('Not implemented')\n}\n\n/**\n * Decrypt a received note\n *\n * @param encrypted - The encrypted note data\n * @param sharedSecret - ECDH shared secret\n * @returns Decrypted note or null if decryption fails\n */\nexport function decryptNote(_encrypted: EncryptedNote, _sharedSecret: Uint8Array): Note | null {\n // TODO: Implement AES-GCM decryption\n throw new Error('Not implemented')\n}\n\n/**\n * Compute the commitment hash for a note\n *\n * commitment = Poseidon(amount, blinding, origin, token)\n */\nexport function computeCommitment(_note: Note): Hex {\n // TODO: Implement Poseidon hash\n throw new Error('Not implemented')\n}\n\n/**\n * Compute the nullifier for spending a note\n *\n * nullifier = Poseidon(blinding, leafIndex)\n */\nexport function computeNullifier(_note: Note, _leafIndex: bigint): Hex {\n // TODO: Implement nullifier computation\n throw new Error('Not implemented')\n}\n\n/**\n * Generate a random blinding factor\n */\nfunction generateRandomBlinding(): bigint {\n // TODO: Use crypto.getRandomValues for secure randomness\n const bytes = new Uint8Array(31) // 31 bytes to stay in field\n crypto.getRandomValues(bytes)\n return BigInt('0x' + Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join(''))\n}\n","/**\n * Core UPP SDK functionality\n */\n\nexport { createUPPClient } from './client.js'\nexport type { UPPClient, UPPClientConfig } from './client.js'\n\nexport { createNote, encryptNote, decryptNote } from './note.js'\n\n// Stealth address utilities (post-quantum, hash-based)\nexport {\n STEALTH_ADDRESS_PREFIX,\n ADDRESS_VERSION,\n encodeStealthAddress,\n decodeStealthAddress,\n isValidStealthAddress,\n generateStealthAddress,\n createOneTimeKeys,\n verifyOwnership,\n computeNoteEncryptionKey,\n // STARK stealth addresses (0zs prefix)\n STARK_STEALTH_ADDRESS_PREFIX,\n STARK_ADDRESS_VERSION,\n encodeStarkStealthAddress,\n decodeStarkStealthAddress,\n isValidStarkStealthAddress,\n generateStarkStealthAddress,\n detectAddressType,\n} from './stealth.js'\n\n// Proof generation (UPP circuits)\nexport {\n generateUPPProof,\n formatProofForContract,\n getUPPCircuitArtifacts,\n STATE_TREE_DEPTH,\n ASP_TREE_DEPTH,\n} from './proof.js'\n\n// Proof worker (off-main-thread proving)\nexport {\n ProofWorkerManager,\n generateUPPProofAsync,\n} from './proof-worker.js'\nexport type {\n ProofWorkerRequest,\n ProofWorkerResponse,\n} from './proof-worker.js'\nexport type {\n UPPCircuitType,\n UPPTransferCircuitInputs,\n UPPWithdrawCircuitInputs,\n UPPCircuitInputs,\n CircuitArtifacts,\n ProofResult,\n PlonkProvingStage,\n} from './proof.js'\n\n// Legacy stealth proof exports (deprecated)\nexport {\n generateProof,\n verifyProof,\n generateStealthProof,\n getStealthCircuitArtifacts,\n} from './proof.js'\nexport type {\n CircuitType,\n StealthCircuitType,\n StealthCircuitInputs,\n Stealth1x2CircuitInputs,\n Stealth2x2CircuitInputs,\n} from './proof.js'\n\nexport * from './types.js'\n\n// Swap order book module\nexport {\n computeGiveAmount,\n computeTakeAmount,\n computeRate,\n formatRate,\n computeCancelKeyHash,\n generateCancelSecret,\n filterOrdersByASP,\n filterOrdersByTokenPair,\n isFillerASPAccepted,\n isOrderActive,\n computeTotalBuyAmount,\n computeFillPercentage,\n storeCancelSecret,\n getCancelSecret,\n removeCancelSecret,\n getOwnOrderIds,\n RATE_PRECISION,\n SWAP_EVENTS_ABI,\n SWAP_ORDER_PLACED_EVENT,\n SWAP_ORDER_FILLED_EVENT,\n SWAP_ORDER_CLAIMED_EVENT,\n SWAP_ORDER_CANCELLED_EVENT,\n} from './swap.js'\nexport type {\n SwapOrder,\n SwapOrderParams,\n SwapFillParams,\n SwapOrderEvent,\n SwapFillEvent,\n} from './swap.js'\n\n// Account adapter (pluggable key source + persistence)\nexport { DirectAccountAdapter, StorableAccountAdapter } from './account.js'\nexport type { IAccountAdapter } from './account.js'\n\n// ASP provider (pluggable compliance)\nexport type { IASPProvider, ASPMembershipProof } from './asp-provider.js'\n\n// Note store (single source of truth for note state)\nexport { NoteStore } from './note-store.js'\nexport type { INoteStore, ShieldedNote, NoteStatus, ProofSystem } from './note-store.js'\n\n// ASP (Association Set Provider) module\nexport {\n computeSingleOriginASPRoot,\n generateSingleOriginASPProof,\n verifyASPProof,\n DEMO_ASP_ID,\n DEMO_ASP_NAME,\n createDemoASPRoot,\n // Multi-origin ASP tree\n buildASPTree,\n computeMultiOriginASPRoot,\n generateMultiOriginASPProof,\n generateASPProof,\n} from './asp.js'\nexport type { ASPProof } from './asp.js'\n\n// Transfer module\nexport {\n syncMerkleTree,\n getMerkleProofsForNotes,\n computeNullifier,\n buildUPPTransferCircuitInputs,\n buildTransfer,\n formatOutputForContract,\n} from './transfer.js'\nexport type {\n TransferStage,\n SpendableNote,\n MerkleProofWithNote,\n TransferContext,\n TransferBuildResult,\n NoteWithAmount,\n} from './transfer.js'\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/core/client.ts","../src/core/types.ts","../src/core/note.ts","../src/core/index.ts"],"names":["init_stealth"],"mappings":";;;;;AAoFO,SAAS,gBAAgB,OAAA,EAAqC;AAEnE,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;;;AC9EO,IAAM,YAAA,GAAe;;;ACiCrB,SAAS,WAAW,MAAA,EAAgC;AACzD,EAAA,MAAM,EAAE,MAAA,EAAQ,KAAA,EAAO,QAAQ,MAAA,EAAQ,IAAA,EAAM,UAAS,GAAI,MAAA;AAG1D,EAAA,MAAM,YAAA,GAAe,YAAY,sBAAA,EAAuB;AAExD,EAAA,OAAO;AAAA,IACL,OAAA,EAAS,YAAA;AAAA,IACT,MAAA;AAAA,IACA,QAAA,EAAU,YAAA;AAAA,IACV,MAAA;AAAA,IACA,MAAA;AAAA,IACA,KAAA;AAAA,IACA,IAAA;AAAA,IACA,WAAW,IAAA,CAAK,KAAA,CAAM,IAAA,CAAK,GAAA,KAAQ,GAAI;AAAA,GACzC;AACF;AASO,SAAS,WAAA,CAAY,OAAa,aAAA,EAA0C;AAEjF,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AASO,SAAS,WAAA,CAAY,YAA2B,aAAA,EAAwC;AAE7F,EAAA,MAAM,IAAI,MAAM,iBAAiB,CAAA;AACnC;AAyBA,SAAS,sBAAA,GAAiC;AAExC,EAAA,MAAM,KAAA,GAAQ,IAAI,UAAA,CAAW,EAAE,CAAA;AAC/B,EAAA,MAAA,CAAO,gBAAgB,KAAK,CAAA;AAC5B,EAAA,OAAO,OAAO,IAAA,GAAO,KAAA,CAAM,KAAK,KAAK,CAAA,CAAE,IAAI,CAAA,CAAA,KAAK,CAAA,CAAE,SAAS,EAAE,CAAA,CAAE,SAAS,CAAA,EAAG,GAAG,CAAC,CAAA,CAAE,IAAA,CAAK,EAAE,CAAC,CAAA;AAC3F;;;ACtGAA,8BAAA,EAAA","file":"chunk-632LPXPX.cjs","sourcesContent":["/**\n * Main UPP Client\n *\n * Provides high-level API for interacting with the Universal Private Pool.\n */\n\nimport type { Address, PublicClient, WalletClient } from 'viem'\nimport type {\n ShieldParams,\n TransferParams,\n MergeParams,\n WithdrawParams,\n Note,\n} from './types.js'\n\n/**\n * UPP Client configuration\n */\nexport interface UPPClientConfig {\n /** Viem public client for reading chain state */\n publicClient: PublicClient\n /** Viem wallet client for sending transactions */\n walletClient: WalletClient\n /** Universal Private Pool contract address */\n poolAddress: Address\n /** ASP Registry Hub contract address */\n aspHubAddress: Address\n /** Chain ID (optional, derived from clients if not provided) */\n chainId?: number\n}\n\n/**\n * UPP Client interface\n */\nexport interface UPPClient {\n /** Shield tokens into the private pool */\n shield(params: ShieldParams): Promise<{ commitment: `0x${string}`; note: Note }>\n\n /** Transfer tokens privately */\n transfer(params: TransferParams): Promise<{ nullifier: `0x${string}`; changeNote?: Note }>\n\n /** Merge multiple notes into one */\n merge(params: MergeParams): Promise<{ commitment: `0x${string}`; note: Note }>\n\n /** Withdraw tokens from the private pool */\n withdraw(params: WithdrawParams): Promise<{ txHash: `0x${string}` }>\n\n /** Scan for notes belonging to a viewing key */\n scanNotes(viewingKey: `0x${string}`): Promise<Note[]>\n\n /** Get the current state root */\n getStateRoot(): Promise<bigint>\n\n /** Check if a nullifier has been spent */\n isNullifierSpent(nullifier: `0x${string}`): Promise<boolean>\n}\n\n/**\n * Create a UPP client instance\n *\n * @example\n * ```ts\n * import { createUPPClient } from '@upp/sdk'\n * import { createPublicClient, createWalletClient, http } from 'viem'\n * import { sepolia } from 'viem/chains'\n *\n * const publicClient = createPublicClient({\n * chain: sepolia,\n * transport: http(),\n * })\n *\n * const walletClient = createWalletClient({\n * chain: sepolia,\n * transport: http(),\n * })\n *\n * const client = createUPPClient({\n * publicClient,\n * walletClient,\n * poolAddress: '0x...',\n * aspHubAddress: '0x...',\n * })\n * ```\n */\nexport function createUPPClient(_config: UPPClientConfig): UPPClient {\n // TODO: Implement client\n throw new Error('Not implemented')\n}\n","/**\n * Core type definitions for UPP SDK\n */\n\nimport type { Address, Hex } from 'viem'\n\n/**\n * Note version - increment when note structure changes\n */\nexport const NOTE_VERSION = 5\n\n/**\n * A private note in the Universal Private Pool\n */\nexport interface Note {\n /** Note format version */\n version: number\n /** Token amount (in wei) */\n amount: bigint\n /** Random blinding factor */\n blinding: bigint\n /** Current origin - who is responsible for these funds (updated on merge) */\n origin: Address\n /** Sender - who sent this specific note (for payment attribution) */\n sender: Address\n /** ERC20 token address */\n token: Address\n /** Optional memo/message */\n memo?: string\n /** Timestamp when note was created */\n timestamp?: number\n}\n\n/**\n * Encrypted note data stored on-chain (post-quantum, hash-based)\n */\nexport interface EncryptedNote {\n /** AES-GCM encrypted note data */\n ciphertext: Hex\n /** AES-GCM nonce */\n nonce: Hex\n}\n\n/**\n * Stealth meta-address (hash-based, post-quantum)\n * Published once, used by senders to encrypt notes to the recipient\n */\nexport interface StealthMetaAddress {\n /** Owner hash = Poseidon(spendingSecret) */\n ownerHash: bigint\n /** Viewing hash = Poseidon(viewingSecret) */\n viewingHash: bigint\n}\n\n/**\n * One-time address for a specific transaction (simplified for hash-based system)\n */\nexport interface StealthAddress {\n /** Owner hash for this note */\n ownerHash: bigint\n /** Search tag for efficient scanning */\n searchTag?: bigint\n}\n\n/**\n * On-chain merge record for audit trail\n */\nexport interface MergeRecord {\n /** Output commitment (the merged note) */\n outputCommitment: Hex\n /** First input nullifier */\n nullifier1: Hex\n /** Second input nullifier */\n nullifier2: Hex\n /** Who performed the merge (new origin) */\n merger: Address\n /** Token that was merged */\n token: Address\n /** Block timestamp */\n timestamp: number\n}\n\n/**\n * ASP (Association Set Provider) root\n */\nexport interface ASPRoot {\n /** Merkle root of approved addresses */\n root: bigint\n /** IPFS hash for off-chain data */\n ipfsHash: Hex\n /** When this root was published */\n timestamp: number\n /** Number of addresses in the set */\n leafCount: number\n}\n\n/**\n * Shield operation parameters\n */\nexport interface ShieldParams {\n /** ERC20 token to shield */\n token: Address\n /** Amount to shield (in wei) */\n amount: bigint\n /** Optional: recipient owner hash (defaults to self) */\n recipientOwnerHash?: bigint\n /** Optional: memo to include in note */\n memo?: string\n}\n\n/**\n * Transfer operation parameters\n */\nexport interface TransferParams {\n /** Note to spend */\n note: Note\n /** Recipient stealth address */\n recipient: StealthAddress\n /** Amount to send (remainder goes back to sender as change) */\n amount: bigint\n /** Optional: memo to include */\n memo?: string\n}\n\n/**\n * Merge operation parameters\n */\nexport interface MergeParams {\n /** Notes to merge (must be same token) */\n notes: [Note, Note]\n /** Optional: memo for the merged note */\n memo?: string\n}\n\n/**\n * Withdraw operation parameters\n */\nexport interface WithdrawParams {\n /** Note to withdraw */\n note: Note\n /** Amount to withdraw */\n amount: bigint\n /** Recipient address for the tokens */\n recipient: Address\n /** ASP ID to use for compliance check */\n aspId?: number\n /** Use ragequit (origin withdrawing own funds) */\n ragequit?: boolean\n}\n\n/**\n * Proof for ZK operations\n */\nexport interface Proof {\n /** Proof data (format depends on proof system: Groth16 has pi_a/pi_b/pi_c, PLONK has A/B/C/Z/T1-T3/evals/Wxi/Wxiw) */\n proof: Record<string, any>\n /** Public signals */\n publicSignals: string[]\n}\n\n/**\n * Note commitment (hash)\n */\nexport type Commitment = Hex\n\n/**\n * Nullifier (spent note identifier)\n */\nexport type Nullifier = Hex\n\n// =========================================================================\n// STARK Note Types (M31/Keccak-based, post-quantum)\n// =========================================================================\n\nimport type { M31Digest } from '../utils/keccak-m31.js'\n\n// STARK_AMOUNT_SCALE moved to utils/stark.ts\nexport { STARK_AMOUNT_SCALE } from '../utils/stark.js'\n\n/**\n * A private STARK note in the Universal Private Pool.\n *\n * All field values are M31 elements (< 2^31 - 1).\n * Commitment = keccak_m31(amount, ownerHash[0..4], blinding, origin, token).\n */\nexport interface StarkNote {\n /** Amount in STARK units (actual wei = amount * STARK_AMOUNT_SCALE) */\n amount: bigint\n /** Owner hash = keccak_m31(starkSecret) — 4 M31 elements */\n ownerHash: M31Digest\n /** Random blinding factor (M31) */\n blinding: bigint\n /** Origin address encoded as M31 (lower 31 bits of address) */\n origin: bigint\n /** Token address encoded as M31 (lower 31 bits of address) */\n token: bigint\n /** The leaf index in the STARK Keccak Merkle tree (set after shielding) */\n leafIndex?: number\n /** The commitment digest (set after computation) */\n commitment?: M31Digest\n /** Optional memo */\n memo?: string\n /** Timestamp when note was created */\n timestamp?: number\n}\n\n/**\n * STARK stealth meta-address (M31/Keccak-based)\n * Published once, used by senders to encrypt notes to the recipient\n */\nexport interface StarkStealthMetaAddress {\n /** Owner hash = keccak_m31(starkSecret) — 4 M31 elements */\n ownerHash: M31Digest\n /** Viewing hash = keccak_m31(starkViewingSecret) — 4 M31 elements */\n viewingHash: M31Digest\n}\n\n/**\n * STARK proof for ZK operations (serialized Circle STARK proof)\n */\nexport interface StarkProof {\n /** Raw serialized Stwo Circle STARK proof bytes */\n proofBytes: Hex\n /** Public inputs seed (keccak256 of public parameters) */\n publicInputsSeed: Hex\n}\n","/**\n * Note management utilities\n *\n * Create, encrypt, and decrypt private notes.\n */\n\nimport type { Address, Hex } from 'viem'\nimport type { Note, EncryptedNote } from './types.js'\nimport { NOTE_VERSION } from './types.js'\n\n/**\n * Parameters for creating a new note\n */\nexport interface CreateNoteParams {\n /** Token amount */\n amount: bigint\n /** ERC20 token address */\n token: Address\n /** Origin address (who is responsible) */\n origin: Address\n /** Sender address */\n sender: Address\n /** Optional memo */\n memo?: string\n /** Optional blinding factor (generated if not provided) */\n blinding?: bigint\n}\n\n/**\n * Create a new private note\n *\n * @example\n * ```ts\n * const note = createNote({\n * amount: 1000n * 10n ** 18n,\n * token: '0x...',\n * origin: '0xMyAddress...',\n * sender: '0xMyAddress...',\n * memo: 'Payment for services',\n * })\n * ```\n */\nexport function createNote(params: CreateNoteParams): Note {\n const { amount, token, origin, sender, memo, blinding } = params\n\n // Generate random blinding factor if not provided\n const noteBlinding = blinding ?? generateRandomBlinding()\n\n return {\n version: NOTE_VERSION,\n amount,\n blinding: noteBlinding,\n origin,\n sender,\n token,\n memo,\n timestamp: Math.floor(Date.now() / 1000),\n }\n}\n\n/**\n * Encrypt a note for a recipient\n *\n * @param note - The note to encrypt\n * @param sharedSecret - ECDH shared secret with recipient\n * @returns Encrypted note data\n */\nexport function encryptNote(_note: Note, _sharedSecret: Uint8Array): EncryptedNote {\n // TODO: Implement AES-GCM encryption\n throw new Error('Not implemented')\n}\n\n/**\n * Decrypt a received note\n *\n * @param encrypted - The encrypted note data\n * @param sharedSecret - ECDH shared secret\n * @returns Decrypted note or null if decryption fails\n */\nexport function decryptNote(_encrypted: EncryptedNote, _sharedSecret: Uint8Array): Note | null {\n // TODO: Implement AES-GCM decryption\n throw new Error('Not implemented')\n}\n\n/**\n * Compute the commitment hash for a note\n *\n * commitment = Poseidon(amount, blinding, origin, token)\n */\nexport function computeCommitment(_note: Note): Hex {\n // TODO: Implement Poseidon hash\n throw new Error('Not implemented')\n}\n\n/**\n * Compute the nullifier for spending a note\n *\n * nullifier = Poseidon(blinding, leafIndex)\n */\nexport function computeNullifier(_note: Note, _leafIndex: bigint): Hex {\n // TODO: Implement nullifier computation\n throw new Error('Not implemented')\n}\n\n/**\n * Generate a random blinding factor\n */\nfunction generateRandomBlinding(): bigint {\n // TODO: Use crypto.getRandomValues for secure randomness\n const bytes = new Uint8Array(31) // 31 bytes to stay in field\n crypto.getRandomValues(bytes)\n return BigInt('0x' + Array.from(bytes).map(b => b.toString(16).padStart(2, '0')).join(''))\n}\n","/**\n * Core UPP SDK functionality\n */\n\nexport { createUPPClient } from './client.js'\nexport type { UPPClient, UPPClientConfig } from './client.js'\n\nexport { createNote, encryptNote, decryptNote } from './note.js'\n\n// Stealth address utilities (post-quantum, hash-based)\nexport {\n STEALTH_ADDRESS_PREFIX,\n ADDRESS_VERSION,\n encodeStealthAddress,\n decodeStealthAddress,\n isValidStealthAddress,\n generateStealthAddress,\n createOneTimeKeys,\n verifyOwnership,\n computeNoteEncryptionKey,\n // STARK stealth addresses (0zs prefix)\n STARK_STEALTH_ADDRESS_PREFIX,\n STARK_ADDRESS_VERSION,\n encodeStarkStealthAddress,\n decodeStarkStealthAddress,\n isValidStarkStealthAddress,\n generateStarkStealthAddress,\n detectAddressType,\n} from './stealth.js'\n\n// Proof generation (UPP circuits)\nexport {\n generateUPPProof,\n formatProofForContract,\n getUPPCircuitArtifacts,\n STATE_TREE_DEPTH,\n ASP_TREE_DEPTH,\n} from './proof.js'\n\n// Proof worker (off-main-thread proving)\nexport {\n ProofWorkerManager,\n generateUPPProofAsync,\n} from './proof-worker.js'\nexport type {\n ProofWorkerRequest,\n ProofWorkerResponse,\n} from './proof-worker.js'\n\n// Circuit artifact cache (IndexedDB-based, with download progress)\nexport {\n CircuitArtifactCache,\n CIRCUIT_VERSION,\n CIRCUIT_CDN_BASE,\n} from './circuit-cache.js'\nexport type {\n DownloadProgress,\n ResolvedCircuitArtifacts,\n CircuitCacheStatus,\n} from './circuit-cache.js'\nexport type {\n UPPCircuitType,\n UPPTransferCircuitInputs,\n UPPWithdrawCircuitInputs,\n UPPCircuitInputs,\n CircuitArtifacts,\n ProofResult,\n PlonkProvingStage,\n} from './proof.js'\n\n// Legacy stealth proof exports (deprecated)\nexport {\n generateProof,\n verifyProof,\n generateStealthProof,\n getStealthCircuitArtifacts,\n} from './proof.js'\nexport type {\n CircuitType,\n StealthCircuitType,\n StealthCircuitInputs,\n Stealth1x2CircuitInputs,\n Stealth2x2CircuitInputs,\n} from './proof.js'\n\nexport * from './types.js'\n\n// Swap order book module\nexport {\n computeGiveAmount,\n computeTakeAmount,\n computeRate,\n formatRate,\n computeCancelKeyHash,\n generateCancelSecret,\n filterOrdersByASP,\n filterOrdersByTokenPair,\n isFillerASPAccepted,\n isOrderActive,\n computeTotalBuyAmount,\n computeFillPercentage,\n storeCancelSecret,\n getCancelSecret,\n removeCancelSecret,\n getOwnOrderIds,\n RATE_PRECISION,\n SWAP_EVENTS_ABI,\n SWAP_ORDER_PLACED_EVENT,\n SWAP_ORDER_FILLED_EVENT,\n SWAP_ORDER_CLAIMED_EVENT,\n SWAP_ORDER_CANCELLED_EVENT,\n} from './swap.js'\nexport type {\n SwapOrder,\n SwapOrderParams,\n SwapFillParams,\n SwapOrderEvent,\n SwapFillEvent,\n} from './swap.js'\n\n// Account adapter (pluggable key source + persistence)\nexport { DirectAccountAdapter, StorableAccountAdapter } from './account.js'\nexport type { IAccountAdapter } from './account.js'\n\n// ASP provider (pluggable compliance)\nexport type { IASPProvider, ASPMembershipProof } from './asp-provider.js'\n\n// Note store (single source of truth for note state)\nexport { NoteStore } from './note-store.js'\nexport type { INoteStore, ShieldedNote, NoteStatus, ProofSystem } from './note-store.js'\n\n// ASP (Association Set Provider) module\nexport {\n computeSingleOriginASPRoot,\n generateSingleOriginASPProof,\n verifyASPProof,\n DEMO_ASP_ID,\n DEMO_ASP_NAME,\n createDemoASPRoot,\n // Multi-origin ASP tree\n buildASPTree,\n computeMultiOriginASPRoot,\n generateMultiOriginASPProof,\n generateASPProof,\n} from './asp.js'\nexport type { ASPProof } from './asp.js'\n\n// Transfer module\nexport {\n syncMerkleTree,\n getMerkleProofsForNotes,\n computeNullifier,\n buildUPPTransferCircuitInputs,\n buildTransfer,\n formatOutputForContract,\n} from './transfer.js'\nexport type {\n TransferStage,\n SpendableNote,\n MerkleProofWithNote,\n TransferContext,\n TransferBuildResult,\n NoteWithAmount,\n} from './transfer.js'\n"]}
|
|
@@ -988,5 +988,5 @@ function sleep(ms) {
|
|
|
988
988
|
}
|
|
989
989
|
|
|
990
990
|
export { computeSearchTag, makeRpcIndexer, matchesSearchTag, tryDecryptNote, unpackNoteData };
|
|
991
|
-
//# sourceMappingURL=chunk-
|
|
992
|
-
//# sourceMappingURL=chunk-
|
|
991
|
+
//# sourceMappingURL=chunk-D4VCRPKS.js.map
|
|
992
|
+
//# sourceMappingURL=chunk-D4VCRPKS.js.map
|