@permissionless-technologies/upp-sdk 0.3.3 → 0.3.5

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.
@@ -595,7 +595,41 @@ function UPPAccountProvider({
595
595
  }
596
596
  try {
597
597
  const currentNotes = store ? store.getNotes() : notes;
598
- const spentSnarkNotes = currentNotes.filter((n) => n.status === "spent" && n.proofSystem !== "stark");
598
+ const snarkNotes = currentNotes.filter((n) => n.proofSystem !== "stark");
599
+ const unspentSnarkNotes = snarkNotes.filter((n) => n.status !== "spent");
600
+ if (unspentSnarkNotes.length > 0) {
601
+ const sdk2 = await loadSDK();
602
+ for (const note of unspentSnarkNotes) {
603
+ const correctLeaf = commitmentLeafMap.get(note.commitment.toLowerCase());
604
+ if (correctLeaf === void 0) continue;
605
+ const ownerSecret = BigInt(note.ownerSecret);
606
+ const commitment = BigInt(note.commitment);
607
+ const nullifier = await sdk2.poseidon([
608
+ ownerSecret % 2736030358979909402780800718157159386076813972158567259200215660948447373041n,
609
+ BigInt(correctLeaf),
610
+ commitment
611
+ ]);
612
+ const nullifierHex = viem.toHex(nullifier, { size: 32 });
613
+ const isUsed = await client.readContract({
614
+ address: contractAddress,
615
+ abi: [{
616
+ type: "function",
617
+ name: "nullifierUsed",
618
+ inputs: [{ name: "", type: "bytes32" }],
619
+ outputs: [{ name: "", type: "bool" }],
620
+ stateMutability: "view"
621
+ }],
622
+ functionName: "nullifierUsed",
623
+ args: [nullifierHex]
624
+ });
625
+ if (isUsed) {
626
+ console.log(`[syncNotes] Marking note ${note.commitment.slice(0, 12)} as spent \u2014 nullifier found on-chain`);
627
+ if (store) store.markSpent(note.commitment);
628
+ repaired++;
629
+ }
630
+ }
631
+ }
632
+ const spentSnarkNotes = snarkNotes.filter((n) => n.status === "spent");
599
633
  if (spentSnarkNotes.length > 0) {
600
634
  const sdk2 = await loadSDK();
601
635
  for (const note of spentSnarkNotes) {
@@ -1568,7 +1602,7 @@ function usePoolTransfer(config) {
1568
1602
  const recipientNote = await createNoteForSelf(amount, origin, token);
1569
1603
  const changeNote = await createNoteForSelf(changeAmount, origin, token);
1570
1604
  const [transferModule, proofModule, aspModule] = await Promise.all([
1571
- import('../transfer-USRM46JZ.cjs'),
1605
+ import('../transfer-XCVVZ7FF.cjs'),
1572
1606
  import('../proof-5OECB3RQ.cjs'),
1573
1607
  import('../asp-TXSAFFD3.cjs')
1574
1608
  ]);
@@ -1727,7 +1761,7 @@ function useWithdraw(config) {
1727
1761
  const token = BigInt(selectedNote.token);
1728
1762
  setStage("creating_outputs");
1729
1763
  const [transferModule, proofModule, sdk] = await Promise.all([
1730
- import('../transfer-USRM46JZ.cjs'),
1764
+ import('../transfer-XCVVZ7FF.cjs'),
1731
1765
  import('../proof-5OECB3RQ.cjs'),
1732
1766
  import('../index.cjs')
1733
1767
  ]);
@@ -2106,7 +2140,7 @@ function useSwap(config) {
2106
2140
  }
2107
2141
  setStage("creating_outputs");
2108
2142
  const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
2109
- import('../transfer-USRM46JZ.cjs'),
2143
+ import('../transfer-XCVVZ7FF.cjs'),
2110
2144
  import('../proof-5OECB3RQ.cjs'),
2111
2145
  import('../index.cjs'),
2112
2146
  import('../asp-TXSAFFD3.cjs')
@@ -2153,7 +2187,7 @@ function useSwap(config) {
2153
2187
  BigInt(actualLeafIndex),
2154
2188
  storedCommitment
2155
2189
  ]);
2156
- const aspProofData = await generateASPProof2(aspId, origin, cfg.aspApprovedOrigins);
2190
+ const aspProofData = params.aspProof ? { aspId, aspRoot: params.aspProof.root, aspPathElements: params.aspProof.pathElements, aspPathIndices: params.aspProof.pathIndices } : await generateASPProof2(aspId, origin, cfg.aspApprovedOrigins);
2157
2191
  const circuitInputs = {
2158
2192
  stateRoot: stateRootBI.toString(),
2159
2193
  aspRoot: aspProofData.aspRoot.toString(),
@@ -2258,7 +2292,7 @@ function useSwap(config) {
2258
2292
  }
2259
2293
  setStage("creating_outputs");
2260
2294
  const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
2261
- import('../transfer-USRM46JZ.cjs'),
2295
+ import('../transfer-XCVVZ7FF.cjs'),
2262
2296
  import('../proof-5OECB3RQ.cjs'),
2263
2297
  import('../index.cjs'),
2264
2298
  import('../asp-TXSAFFD3.cjs')
@@ -2311,7 +2345,7 @@ function useSwap(config) {
2311
2345
  BigInt(actualLeafIndex),
2312
2346
  storedCommitmentF
2313
2347
  ]);
2314
- const aspProofData = await generateASPProof2(aspId, origin, cfg.aspApprovedOrigins);
2348
+ const aspProofData = params.aspProof ? { aspId, aspRoot: params.aspProof.root, aspPathElements: params.aspProof.pathElements, aspPathIndices: params.aspProof.pathIndices } : await generateASPProof2(aspId, origin, cfg.aspApprovedOrigins);
2315
2349
  const circuitInputs = {
2316
2350
  stateRoot: stateRootBI.toString(),
2317
2351
  aspRoot: aspProofData.aspRoot.toString(),
@@ -2488,7 +2522,7 @@ function useSwap(config) {
2488
2522
  createNoteForSelf(changeAmount, origin, token)
2489
2523
  ]);
2490
2524
  const [transferModule, proofModule, aspModule] = await Promise.all([
2491
- import('../transfer-USRM46JZ.cjs'),
2525
+ import('../transfer-XCVVZ7FF.cjs'),
2492
2526
  import('../proof-5OECB3RQ.cjs'),
2493
2527
  import('../asp-TXSAFFD3.cjs')
2494
2528
  ]);
@@ -2508,7 +2542,7 @@ function useSwap(config) {
2508
2542
  token
2509
2543
  };
2510
2544
  const [noteProof] = await getMerkleProofsForNotes([spendableNote], leaves, tree);
2511
- const aspProof = await generateASPProof2(splitAspId ?? DEMO_ASP_ID, origin, cfg.aspApprovedOrigins);
2545
+ const aspProof = params.aspProof ? { aspId: splitAspId ?? DEMO_ASP_ID, aspRoot: params.aspProof.root, aspPathElements: params.aspProof.pathElements, aspPathIndices: params.aspProof.pathIndices } : await generateASPProof2(splitAspId ?? DEMO_ASP_ID, origin, cfg.aspApprovedOrigins);
2512
2546
  setStage("generating_proof");
2513
2547
  const exactNoteWithAmount = { ...exactNoteData, amount: targetAmount };
2514
2548
  const changeNoteWithAmount = { ...changeNoteData, amount: changeAmount };