@permissionless-technologies/upp-sdk 0.5.6 → 0.5.7

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.
Files changed (43) hide show
  1. package/dist/{chunk-CRUJLZV7.js → chunk-N2VHE47N.js} +72 -7
  2. package/dist/chunk-N2VHE47N.js.map +1 -0
  3. package/dist/{chunk-UHMHZQZV.js → chunk-OG6TNEAT.js} +2 -2
  4. package/dist/{chunk-UHMHZQZV.js.map → chunk-OG6TNEAT.js.map} +1 -1
  5. package/dist/{chunk-HVSP62AH.cjs → chunk-TKUOY2PQ.cjs} +2 -2
  6. package/dist/{chunk-HVSP62AH.cjs.map → chunk-TKUOY2PQ.cjs.map} +1 -1
  7. package/dist/{chunk-P6E3LE7T.cjs → chunk-Y3VL3LOE.cjs} +72 -4
  8. package/dist/chunk-Y3VL3LOE.cjs.map +1 -0
  9. package/dist/core/index.cjs +63 -63
  10. package/dist/core/index.d.cts +2 -2
  11. package/dist/core/index.d.ts +2 -2
  12. package/dist/core/index.js +3 -3
  13. package/dist/{index-DLvLv3mg.d.ts → index-2eL8ZLD0.d.ts} +1 -1
  14. package/dist/{index-DY0XAmFw.d.ts → index-B31tBTbC.d.ts} +2 -2
  15. package/dist/{index-DOiHUft6.d.cts → index-CzmvOht6.d.cts} +2 -2
  16. package/dist/{index-KTJgQUxb.d.cts → index-a_f935pS.d.cts} +1 -1
  17. package/dist/index.cjs +113 -113
  18. package/dist/index.d.cts +3 -3
  19. package/dist/index.d.ts +3 -3
  20. package/dist/index.js +5 -5
  21. package/dist/indexer/index.cjs +11 -11
  22. package/dist/indexer/index.d.cts +5 -5
  23. package/dist/indexer/index.d.ts +5 -5
  24. package/dist/indexer/index.js +1 -1
  25. package/dist/react/index.cjs +52 -90
  26. package/dist/react/index.cjs.map +1 -1
  27. package/dist/react/index.d.cts +6 -2
  28. package/dist/react/index.d.ts +6 -2
  29. package/dist/react/index.js +44 -82
  30. package/dist/react/index.js.map +1 -1
  31. package/dist/transfer-27GZNGCI.js +9 -0
  32. package/dist/{transfer-2UYFZMIK.js.map → transfer-27GZNGCI.js.map} +1 -1
  33. package/dist/{transfer-6OW3XKVC.cjs → transfer-TJNDCZF2.cjs} +13 -9
  34. package/dist/{transfer-6OW3XKVC.cjs.map → transfer-TJNDCZF2.cjs.map} +1 -1
  35. package/dist/{transfer-C1XU_z-6.d.cts → transfer-_qaZXsv7.d.cts} +1 -0
  36. package/dist/{transfer-DgjxZlR7.d.ts → transfer-x7UChjh7.d.ts} +1 -0
  37. package/dist/utils/index.cjs +21 -21
  38. package/dist/utils/index.js +1 -1
  39. package/package.json +1 -1
  40. package/src/deployments/31337.json +2 -2
  41. package/dist/chunk-CRUJLZV7.js.map +0 -1
  42. package/dist/chunk-P6E3LE7T.cjs.map +0 -1
  43. package/dist/transfer-2UYFZMIK.js +0 -9
@@ -1,8 +1,11 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkC3HXJ5A6_cjs = require('../chunk-C3HXJ5A6.cjs');
4
+ var chunkY3VL3LOE_cjs = require('../chunk-Y3VL3LOE.cjs');
5
+ require('../chunk-IX7HV5TE.cjs');
4
6
  var chunkXVIICZKW_cjs = require('../chunk-XVIICZKW.cjs');
5
7
  var chunkVVW5VVY3_cjs = require('../chunk-VVW5VVY3.cjs');
8
+ require('../chunk-IIUKM5VE.cjs');
6
9
  var chunkPGIV2GDM_cjs = require('../chunk-PGIV2GDM.cjs');
7
10
  var chunkARH2SJM3_cjs = require('../chunk-ARH2SJM3.cjs');
8
11
  var chunkBCSMUH4L_cjs = require('../chunk-BCSMUH4L.cjs');
@@ -180,7 +183,9 @@ function UPPAccountProvider({
180
183
  const [lastSyncedBlock, _setLastSyncedBlock] = react.useState(0);
181
184
  const [liveSyncInterval, setLiveSyncInterval] = react.useState(null);
182
185
  const noteStoreRef = react.useRef(null);
186
+ const [noteStoreReady, setNoteStoreReady] = react.useState(false);
183
187
  const accountAdapterRef = react.useRef(null);
188
+ const [initNonce, setInitNonce] = react.useState(0);
184
189
  react.useEffect(() => {
185
190
  loadSDK().then(() => setCryptoReady(true));
186
191
  }, []);
@@ -193,6 +198,7 @@ function UPPAccountProvider({
193
198
  setStarkMasterKeys(null);
194
199
  setNotes([]);
195
200
  noteStoreRef.current = null;
201
+ setNoteStoreReady(false);
196
202
  accountAdapterRef.current = null;
197
203
  return;
198
204
  }
@@ -240,6 +246,7 @@ function UPPAccountProvider({
240
246
  const noteStorage = chunkARH2SJM3_cjs.createIndexedDBAdapter(storagePrefix);
241
247
  const store = new chunkC3HXJ5A6_cjs.NoteStore(noteStorage, "notes");
242
248
  noteStoreRef.current = store;
249
+ setNoteStoreReady(true);
243
250
  noteStoreUnsub = store.onChange(() => {
244
251
  if (!cancelled) setNotes([...store.getNotes()]);
245
252
  });
@@ -279,7 +286,7 @@ function UPPAccountProvider({
279
286
  cancelled = true;
280
287
  if (noteStoreUnsub) noteStoreUnsub();
281
288
  };
282
- }, [ethAddress, cryptoReady, chainId, publicClientProp]);
289
+ }, [ethAddress, cryptoReady, chainId, publicClientProp, initNonce]);
283
290
  const setupAccount = react.useCallback(
284
291
  async (signature) => {
285
292
  if (!ethAddress || !cryptoReady) {
@@ -297,6 +304,7 @@ function UPPAccountProvider({
297
304
  if (adapter) {
298
305
  await adapter.save(keys, starkKeys);
299
306
  }
307
+ setInitNonce((n) => n + 1);
300
308
  } finally {
301
309
  setIsLoading(false);
302
310
  }
@@ -334,8 +342,8 @@ function UPPAccountProvider({
334
342
  const logout = react.useCallback(() => {
335
343
  noteStoreRef.current?.clear().catch(console.error);
336
344
  noteStoreRef.current = null;
345
+ setNoteStoreReady(false);
337
346
  accountAdapterRef.current?.clear().catch(console.error);
338
- accountAdapterRef.current = null;
339
347
  if (masterKeys) {
340
348
  const ownerHashHex2 = viem.toHex(masterKeys.ownerHash, { size: 32 });
341
349
  const notesKey = getNotesStorageKey(chainId, ownerHashHex2.slice(0, 12));
@@ -408,7 +416,7 @@ function UPPAccountProvider({
408
416
  );
409
417
  const syncEngineRef = react.useRef(null);
410
418
  react.useEffect(() => {
411
- if (!masterKeys || !cryptoReady || !publicClientProp || !indexerConfig?.contractAddress) {
419
+ if (!masterKeys || !cryptoReady || !publicClientProp || !indexerConfig?.contractAddress || !noteStoreReady) {
412
420
  syncEngineRef.current = null;
413
421
  return;
414
422
  }
@@ -432,7 +440,7 @@ function UPPAccountProvider({
432
440
  return () => {
433
441
  cancelled = true;
434
442
  };
435
- }, [masterKeys, cryptoReady, publicClientProp, indexerConfig?.contractAddress, indexerConfig?.swapModuleAddress, indexerConfig?.fromBlock]);
443
+ }, [masterKeys, cryptoReady, publicClientProp, noteStoreReady, indexerConfig?.contractAddress, indexerConfig?.swapModuleAddress, indexerConfig?.fromBlock]);
436
444
  const syncNotes = react.useCallback(
437
445
  async (_contractAddress, _client) => {
438
446
  const engine = syncEngineRef.current;
@@ -1145,18 +1153,6 @@ function useUPPCrypto() {
1145
1153
  getSubOrder
1146
1154
  };
1147
1155
  }
1148
- function packNoteData(note) {
1149
- return viem.encodePacked(
1150
- ["uint64", "uint256", "bytes"],
1151
- [note.searchTag, note.ownerHash, note.encryptedNote]
1152
- );
1153
- }
1154
- function padToDepth(arr, padValue, depth) {
1155
- if (arr.length >= depth) return arr.slice(0, depth);
1156
- return [...arr, ...Array(depth - arr.length).fill(padValue)];
1157
- }
1158
-
1159
- // src/react/use-shield.ts
1160
1156
  function useShield(config) {
1161
1157
  const { createNoteForSelf, isSetup, masterKeys } = useUPPAccount();
1162
1158
  const [isPending, setIsPending] = react.useState(false);
@@ -1186,7 +1182,7 @@ function useShield(config) {
1186
1182
  setStage("creating_note");
1187
1183
  const noteData = await createNoteForSelf(amount, origin, token);
1188
1184
  const commitment = viem.toHex(noteData.commitment, { size: 32 });
1189
- const encryptedNote = packNoteData(noteData);
1185
+ const encryptedNote = chunkY3VL3LOE_cjs.packNoteData(noteData);
1190
1186
  return {
1191
1187
  amount,
1192
1188
  token: cfg.tokenAddress,
@@ -1265,7 +1261,7 @@ function usePoolTransfer(config) {
1265
1261
  const recipientNote = await createNoteForSelf(amount, origin, token);
1266
1262
  const changeNote = await createNoteForSelf(changeAmount, origin, token);
1267
1263
  const [transferModule, proofModule, aspModule] = await Promise.all([
1268
- import('../transfer-6OW3XKVC.cjs'),
1264
+ import('../transfer-TJNDCZF2.cjs'),
1269
1265
  import('../proof-X3MVQFFZ.cjs'),
1270
1266
  import('../asp-CUE3NMBN.cjs')
1271
1267
  ]);
@@ -1324,8 +1320,8 @@ function usePoolTransfer(config) {
1324
1320
  token: cfg.tokenAddress,
1325
1321
  outputCommitment1: viem.toHex(recipientNote.commitment, { size: 32 }),
1326
1322
  outputCommitment2: viem.toHex(changeNote.commitment, { size: 32 }),
1327
- encryptedNote1: packNoteData(recipientNote),
1328
- encryptedNote2: packNoteData(changeNote),
1323
+ encryptedNote1: chunkY3VL3LOE_cjs.packNoteData(recipientNote),
1324
+ encryptedNote2: chunkY3VL3LOE_cjs.packNoteData(changeNote),
1329
1325
  spentNote: selectedNote,
1330
1326
  recipientNoteData: recipientNote,
1331
1327
  changeNoteData: changeNote
@@ -1351,9 +1347,6 @@ function usePoolTransfer(config) {
1351
1347
  reset
1352
1348
  };
1353
1349
  }
1354
- chunkHEHXSV47_cjs.init_poseidon();
1355
- var STATE_TREE_DEPTH = 32;
1356
- var ASP_TREE_DEPTH2 = 20;
1357
1350
  function useWithdraw(config) {
1358
1351
  const {
1359
1352
  isSetup,
@@ -1383,6 +1376,8 @@ function useWithdraw(config) {
1383
1376
  recipient,
1384
1377
  aspId = 0n,
1385
1378
  aspRoot = 0n,
1379
+ aspPathElements,
1380
+ aspPathIndices,
1386
1381
  isRagequit = false
1387
1382
  } = params;
1388
1383
  const cfg = configRef.current;
@@ -1416,10 +1411,9 @@ function useWithdraw(config) {
1416
1411
  const origin = BigInt(selectedNote.origin);
1417
1412
  const token = BigInt(selectedNote.token);
1418
1413
  setStage("creating_outputs");
1419
- const [transferModule, proofModule, sdk] = await Promise.all([
1420
- import('../transfer-6OW3XKVC.cjs'),
1421
- import('../proof-X3MVQFFZ.cjs'),
1422
- import('../index.cjs')
1414
+ const [transferModule, proofModule] = await Promise.all([
1415
+ import('../transfer-TJNDCZF2.cjs'),
1416
+ import('../proof-X3MVQFFZ.cjs')
1423
1417
  ]);
1424
1418
  const { syncMerkleTree, getMerkleProofsForNotes } = transferModule;
1425
1419
  const { formatPlonkProofForContract } = proofModule;
@@ -1437,50 +1431,18 @@ function useWithdraw(config) {
1437
1431
  };
1438
1432
  const [noteProof] = await getMerkleProofsForNotes([spendableNote], leaves, tree);
1439
1433
  setStage("generating_proof");
1440
- const merkleProof = noteProof.proof;
1441
- const stateRootBI = merkleProof.root;
1442
- const actualLeafIndex = merkleProof.leafIndex;
1443
- const inputOwnerHash = chunkHEHXSV47_cjs.computeOwnerHash(BigInt(selectedNote.ownerSecret));
1444
- const localCommitment = await sdk.poseidon([
1445
- selectedNote.amount,
1446
- inputOwnerHash,
1447
- selectedNote.blinding,
1448
- BigInt(selectedNote.origin),
1449
- BigInt(selectedNote.token)
1450
- ]);
1451
- const storedCommitment = BigInt(selectedNote.commitment);
1452
- if (localCommitment !== storedCommitment) {
1453
- throw new Error(
1454
- `Note commitment mismatch \u2014 this note was created with an outdated commitment formula. Clear your shielded account (localStorage) and re-shield tokens.`
1455
- );
1456
- }
1457
- const nullifier = await sdk.poseidon([
1458
- BigInt(selectedNote.ownerSecret),
1459
- BigInt(actualLeafIndex),
1460
- storedCommitment
1461
- ]);
1462
- const circuitInputs = {
1463
- // Public inputs
1464
- stateRoot: stateRootBI.toString(),
1465
- aspRoot: aspRoot.toString(),
1466
- nullifier: nullifier.toString(),
1467
- amount: selectedNote.amount.toString(),
1468
- recipient: BigInt(recipient).toString(),
1469
- token: BigInt(cfg.tokenAddress).toString(),
1470
- isRagequit: isRagequit ? "1" : "0",
1471
- // Private inputs - Input Note
1472
- // IMPORTANT: Use actualLeafIndex from Merkle proof, not stored leafIndex
1473
- inputAmount: selectedNote.amount.toString(),
1474
- inputOneTimeSecret: BigInt(selectedNote.ownerSecret).toString(),
1475
- inputBlinding: selectedNote.blinding.toString(),
1476
- inputOrigin: origin.toString(),
1477
- inputLeafIndex: actualLeafIndex.toString(),
1478
- inputPathElements: padToDepth(merkleProof.pathElements.map(String), "0", STATE_TREE_DEPTH),
1479
- inputPathIndices: padToDepth(merkleProof.pathIndices.map(String), "0", STATE_TREE_DEPTH),
1480
- // ASP membership proof (zeros for ragequit)
1481
- aspPathElements: Array(ASP_TREE_DEPTH2).fill("0"),
1482
- aspPathIndices: Array(ASP_TREE_DEPTH2).fill("0")
1483
- };
1434
+ const circuitInputs = await chunkY3VL3LOE_cjs.buildWithdrawCircuitInputs({
1435
+ selectedNote: spendableNote,
1436
+ merkleProof: noteProof.proof,
1437
+ recipient: BigInt(recipient),
1438
+ tokenAddress: BigInt(cfg.tokenAddress),
1439
+ aspRoot,
1440
+ aspPathElements,
1441
+ aspPathIndices,
1442
+ isRagequit
1443
+ });
1444
+ const stateRootBI = noteProof.proof.root;
1445
+ const nullifier = BigInt(circuitInputs.nullifier);
1484
1446
  setProvingProgress(null);
1485
1447
  const { proof } = await chunkC3HXJ5A6_cjs.generateUPPProofAsync(
1486
1448
  "withdraw",
@@ -1641,8 +1603,8 @@ function storePersonalASPId(chainId, address, aspId) {
1641
1603
  storeASPId(chainId, address, aspId);
1642
1604
  }
1643
1605
  chunkHEHXSV47_cjs.init_poseidon();
1644
- var STATE_TREE_DEPTH2 = 32;
1645
- var ASP_TREE_DEPTH3 = 20;
1606
+ var STATE_TREE_DEPTH = 32;
1607
+ var ASP_TREE_DEPTH2 = 20;
1646
1608
  var SWAP_ORDERS_ABI = [{
1647
1609
  type: "function",
1648
1610
  name: "swapOrders",
@@ -1791,7 +1753,7 @@ function useSwap(config) {
1791
1753
  }
1792
1754
  setStage("creating_outputs");
1793
1755
  const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
1794
- import('../transfer-6OW3XKVC.cjs'),
1756
+ import('../transfer-TJNDCZF2.cjs'),
1795
1757
  import('../proof-X3MVQFFZ.cjs'),
1796
1758
  import('../index.cjs'),
1797
1759
  import('../asp-CUE3NMBN.cjs')
@@ -1851,10 +1813,10 @@ function useSwap(config) {
1851
1813
  inputBlinding: selectedNote.blinding.toString(),
1852
1814
  inputOrigin: origin.toString(),
1853
1815
  inputLeafIndex: actualLeafIndex.toString(),
1854
- inputPathElements: padToDepth(merkleProof.pathElements.map(String), "0", STATE_TREE_DEPTH2),
1855
- inputPathIndices: padToDepth(merkleProof.pathIndices.map(String), "0", STATE_TREE_DEPTH2),
1856
- aspPathElements: padToDepth(aspProofData.aspPathElements.map(String), "0", ASP_TREE_DEPTH3),
1857
- aspPathIndices: padToDepth(aspProofData.aspPathIndices.map(String), "0", ASP_TREE_DEPTH3)
1816
+ inputPathElements: chunkY3VL3LOE_cjs.padToDepth(merkleProof.pathElements.map(String), "0", STATE_TREE_DEPTH),
1817
+ inputPathIndices: chunkY3VL3LOE_cjs.padToDepth(merkleProof.pathIndices.map(String), "0", STATE_TREE_DEPTH),
1818
+ aspPathElements: chunkY3VL3LOE_cjs.padToDepth(aspProofData.aspPathElements.map(String), "0", ASP_TREE_DEPTH2),
1819
+ aspPathIndices: chunkY3VL3LOE_cjs.padToDepth(aspProofData.aspPathIndices.map(String), "0", ASP_TREE_DEPTH2)
1858
1820
  };
1859
1821
  setProvingProgress(null);
1860
1822
  const { proof } = await chunkC3HXJ5A6_cjs.generateUPPProofAsync(
@@ -1939,7 +1901,7 @@ function useSwap(config) {
1939
1901
  }
1940
1902
  setStage("creating_outputs");
1941
1903
  const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
1942
- import('../transfer-6OW3XKVC.cjs'),
1904
+ import('../transfer-TJNDCZF2.cjs'),
1943
1905
  import('../proof-X3MVQFFZ.cjs'),
1944
1906
  import('../index.cjs'),
1945
1907
  import('../asp-CUE3NMBN.cjs')
@@ -2005,10 +1967,10 @@ function useSwap(config) {
2005
1967
  inputBlinding: selectedNote.blinding.toString(),
2006
1968
  inputOrigin: origin.toString(),
2007
1969
  inputLeafIndex: actualLeafIndex.toString(),
2008
- inputPathElements: padToDepth(merkleProof.pathElements.map(String), "0", STATE_TREE_DEPTH2),
2009
- inputPathIndices: padToDepth(merkleProof.pathIndices.map(String), "0", STATE_TREE_DEPTH2),
2010
- aspPathElements: padToDepth(aspProofData.aspPathElements.map(String), "0", ASP_TREE_DEPTH3),
2011
- aspPathIndices: padToDepth(aspProofData.aspPathIndices.map(String), "0", ASP_TREE_DEPTH3)
1970
+ inputPathElements: chunkY3VL3LOE_cjs.padToDepth(merkleProof.pathElements.map(String), "0", STATE_TREE_DEPTH),
1971
+ inputPathIndices: chunkY3VL3LOE_cjs.padToDepth(merkleProof.pathIndices.map(String), "0", STATE_TREE_DEPTH),
1972
+ aspPathElements: chunkY3VL3LOE_cjs.padToDepth(aspProofData.aspPathElements.map(String), "0", ASP_TREE_DEPTH2),
1973
+ aspPathIndices: chunkY3VL3LOE_cjs.padToDepth(aspProofData.aspPathIndices.map(String), "0", ASP_TREE_DEPTH2)
2012
1974
  };
2013
1975
  setProvingProgress(null);
2014
1976
  const { proof } = await chunkC3HXJ5A6_cjs.generateUPPProofAsync(
@@ -2022,7 +1984,7 @@ function useSwap(config) {
2022
1984
  }
2023
1985
  );
2024
1986
  const formattedProof = await formatPlonkProofForContract(proof);
2025
- const packedFillerNote = packNoteData(fillerNoteData);
1987
+ const packedFillerNote = chunkY3VL3LOE_cjs.packNoteData(fillerNoteData);
2026
1988
  return {
2027
1989
  proof: formattedProof,
2028
1990
  nullifier: viem.toHex(nullifier, { size: 32 }),
@@ -2087,8 +2049,8 @@ function useSwap(config) {
2087
2049
  cancelSecret,
2088
2050
  buyOutputCommitment: buyNoteData ? viem.toHex(buyNoteData.commitment, { size: 32 }) : zeroHex,
2089
2051
  refundCommitment: refundNoteData ? viem.toHex(refundNoteData.commitment, { size: 32 }) : zeroHex,
2090
- buyEncryptedNote: buyNoteData ? packNoteData(buyNoteData) : "0x",
2091
- refundEncryptedNote: refundNoteData ? packNoteData(refundNoteData) : "0x",
2052
+ buyEncryptedNote: buyNoteData ? chunkY3VL3LOE_cjs.packNoteData(buyNoteData) : "0x",
2053
+ refundEncryptedNote: refundNoteData ? chunkY3VL3LOE_cjs.packNoteData(refundNoteData) : "0x",
2092
2054
  buyNoteData,
2093
2055
  refundNoteData
2094
2056
  };
@@ -2119,7 +2081,7 @@ function useSwap(config) {
2119
2081
  cancelOrigin,
2120
2082
  BigInt(sellToken)
2121
2083
  );
2122
- const packedRefund = packNoteData(refundNoteData);
2084
+ const packedRefund = chunkY3VL3LOE_cjs.packNoteData(refundNoteData);
2123
2085
  return {
2124
2086
  orderId,
2125
2087
  cancelSecret,
@@ -2164,7 +2126,7 @@ function useSwap(config) {
2164
2126
  createNoteForSelf(changeAmount, origin, token)
2165
2127
  ]);
2166
2128
  const [transferModule, proofModule, aspModule] = await Promise.all([
2167
- import('../transfer-6OW3XKVC.cjs'),
2129
+ import('../transfer-TJNDCZF2.cjs'),
2168
2130
  import('../proof-X3MVQFFZ.cjs'),
2169
2131
  import('../asp-CUE3NMBN.cjs')
2170
2132
  ]);
@@ -2241,8 +2203,8 @@ function useSwap(config) {
2241
2203
  token: note.token,
2242
2204
  outputCommitment1: viem.toHex(exactNoteData.commitment, { size: 32 }),
2243
2205
  outputCommitment2: viem.toHex(changeNoteData.commitment, { size: 32 }),
2244
- encryptedNote1: packNoteData(exactNoteData),
2245
- encryptedNote2: packNoteData(changeNoteData),
2206
+ encryptedNote1: chunkY3VL3LOE_cjs.packNoteData(exactNoteData),
2207
+ encryptedNote2: chunkY3VL3LOE_cjs.packNoteData(changeNoteData),
2246
2208
  exactNote: exactShieldedNote,
2247
2209
  changeNote: changeShieldedNote,
2248
2210
  spentNote: note,