@permissionless-technologies/upp-sdk 0.3.3 → 0.3.4

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.
@@ -594,7 +594,41 @@ function UPPAccountProvider({
594
594
  }
595
595
  try {
596
596
  const currentNotes = store ? store.getNotes() : notes;
597
- const spentSnarkNotes = currentNotes.filter((n) => n.status === "spent" && n.proofSystem !== "stark");
597
+ const snarkNotes = currentNotes.filter((n) => n.proofSystem !== "stark");
598
+ const unspentSnarkNotes = snarkNotes.filter((n) => n.status !== "spent");
599
+ if (unspentSnarkNotes.length > 0) {
600
+ const sdk2 = await loadSDK();
601
+ for (const note of unspentSnarkNotes) {
602
+ const correctLeaf = commitmentLeafMap.get(note.commitment.toLowerCase());
603
+ if (correctLeaf === void 0) continue;
604
+ const ownerSecret = BigInt(note.ownerSecret);
605
+ const commitment = BigInt(note.commitment);
606
+ const nullifier = await sdk2.poseidon([
607
+ ownerSecret % 2736030358979909402780800718157159386076813972158567259200215660948447373041n,
608
+ BigInt(correctLeaf),
609
+ commitment
610
+ ]);
611
+ const nullifierHex = toHex(nullifier, { size: 32 });
612
+ const isUsed = await client.readContract({
613
+ address: contractAddress,
614
+ abi: [{
615
+ type: "function",
616
+ name: "nullifierUsed",
617
+ inputs: [{ name: "", type: "bytes32" }],
618
+ outputs: [{ name: "", type: "bool" }],
619
+ stateMutability: "view"
620
+ }],
621
+ functionName: "nullifierUsed",
622
+ args: [nullifierHex]
623
+ });
624
+ if (isUsed) {
625
+ console.log(`[syncNotes] Marking note ${note.commitment.slice(0, 12)} as spent \u2014 nullifier found on-chain`);
626
+ if (store) store.markSpent(note.commitment);
627
+ repaired++;
628
+ }
629
+ }
630
+ }
631
+ const spentSnarkNotes = snarkNotes.filter((n) => n.status === "spent");
598
632
  if (spentSnarkNotes.length > 0) {
599
633
  const sdk2 = await loadSDK();
600
634
  for (const note of spentSnarkNotes) {
@@ -1567,7 +1601,7 @@ function usePoolTransfer(config) {
1567
1601
  const recipientNote = await createNoteForSelf(amount, origin, token);
1568
1602
  const changeNote = await createNoteForSelf(changeAmount, origin, token);
1569
1603
  const [transferModule, proofModule, aspModule] = await Promise.all([
1570
- import('../transfer-3QFLYTOI.js'),
1604
+ import('../transfer-QK3QUIA3.js'),
1571
1605
  import('../proof-C4YBP6RY.js'),
1572
1606
  import('../asp-ZA3RGN7G.js')
1573
1607
  ]);
@@ -1726,7 +1760,7 @@ function useWithdraw(config) {
1726
1760
  const token = BigInt(selectedNote.token);
1727
1761
  setStage("creating_outputs");
1728
1762
  const [transferModule, proofModule, sdk] = await Promise.all([
1729
- import('../transfer-3QFLYTOI.js'),
1763
+ import('../transfer-QK3QUIA3.js'),
1730
1764
  import('../proof-C4YBP6RY.js'),
1731
1765
  import('../index.js')
1732
1766
  ]);
@@ -2105,7 +2139,7 @@ function useSwap(config) {
2105
2139
  }
2106
2140
  setStage("creating_outputs");
2107
2141
  const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
2108
- import('../transfer-3QFLYTOI.js'),
2142
+ import('../transfer-QK3QUIA3.js'),
2109
2143
  import('../proof-C4YBP6RY.js'),
2110
2144
  import('../index.js'),
2111
2145
  import('../asp-ZA3RGN7G.js')
@@ -2257,7 +2291,7 @@ function useSwap(config) {
2257
2291
  }
2258
2292
  setStage("creating_outputs");
2259
2293
  const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
2260
- import('../transfer-3QFLYTOI.js'),
2294
+ import('../transfer-QK3QUIA3.js'),
2261
2295
  import('../proof-C4YBP6RY.js'),
2262
2296
  import('../index.js'),
2263
2297
  import('../asp-ZA3RGN7G.js')
@@ -2487,7 +2521,7 @@ function useSwap(config) {
2487
2521
  createNoteForSelf(changeAmount, origin, token)
2488
2522
  ]);
2489
2523
  const [transferModule, proofModule, aspModule] = await Promise.all([
2490
- import('../transfer-3QFLYTOI.js'),
2524
+ import('../transfer-QK3QUIA3.js'),
2491
2525
  import('../proof-C4YBP6RY.js'),
2492
2526
  import('../asp-ZA3RGN7G.js')
2493
2527
  ]);