@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.
@@ -638,6 +638,8 @@ interface SplitNoteParams {
638
638
  targetAmount: bigint;
639
639
  /** ASP ID to use for the proof (defaults to DEMO_ASP_ID if not provided) */
640
640
  aspId?: bigint;
641
+ /** Pre-fetched ASP proof from the service */
642
+ aspProof?: ASPProofParam;
641
643
  }
642
644
  interface SplitNoteBuildData {
643
645
  /** Transfer proof for contract call */
@@ -689,6 +691,12 @@ interface UseSwapReturn {
689
691
  /** Reset state */
690
692
  reset: () => void;
691
693
  }
694
+ /** Pre-fetched ASP proof from the platform's ASP service */
695
+ interface ASPProofParam {
696
+ root: bigint;
697
+ pathElements: bigint[];
698
+ pathIndices: number[];
699
+ }
692
700
  interface PlaceOrderParams {
693
701
  /** Token to sell */
694
702
  sellToken: Address;
@@ -702,8 +710,10 @@ interface PlaceOrderParams {
702
710
  requiredFillerAspId?: bigint;
703
711
  /** Number of blocks until expiry */
704
712
  expiryBlocks: bigint;
705
- /** ASP ID — must be a registered personal ASP */
713
+ /** ASP ID */
706
714
  aspId: bigint;
715
+ /** Pre-fetched ASP proof from the service. If omitted, falls back to local computation. */
716
+ aspProof?: ASPProofParam;
707
717
  /** Explicit note to spend (skips note selection). Used after auto-split. */
708
718
  noteOverride?: ShieldedNote;
709
719
  }
@@ -718,8 +728,10 @@ interface FillOrderParams {
718
728
  sellToken: Address;
719
729
  /** The order's buyToken (filler pays this) */
720
730
  buyToken: Address;
721
- /** ASP ID — must be a registered personal ASP */
731
+ /** ASP ID */
722
732
  aspId: bigint;
733
+ /** Pre-fetched ASP proof from the service. If omitted, falls back to local computation. */
734
+ aspProof?: ASPProofParam;
723
735
  /** Explicit note to spend (skips note selection). Used after auto-split. */
724
736
  noteOverride?: ShieldedNote;
725
737
  }
@@ -638,6 +638,8 @@ interface SplitNoteParams {
638
638
  targetAmount: bigint;
639
639
  /** ASP ID to use for the proof (defaults to DEMO_ASP_ID if not provided) */
640
640
  aspId?: bigint;
641
+ /** Pre-fetched ASP proof from the service */
642
+ aspProof?: ASPProofParam;
641
643
  }
642
644
  interface SplitNoteBuildData {
643
645
  /** Transfer proof for contract call */
@@ -689,6 +691,12 @@ interface UseSwapReturn {
689
691
  /** Reset state */
690
692
  reset: () => void;
691
693
  }
694
+ /** Pre-fetched ASP proof from the platform's ASP service */
695
+ interface ASPProofParam {
696
+ root: bigint;
697
+ pathElements: bigint[];
698
+ pathIndices: number[];
699
+ }
692
700
  interface PlaceOrderParams {
693
701
  /** Token to sell */
694
702
  sellToken: Address;
@@ -702,8 +710,10 @@ interface PlaceOrderParams {
702
710
  requiredFillerAspId?: bigint;
703
711
  /** Number of blocks until expiry */
704
712
  expiryBlocks: bigint;
705
- /** ASP ID — must be a registered personal ASP */
713
+ /** ASP ID */
706
714
  aspId: bigint;
715
+ /** Pre-fetched ASP proof from the service. If omitted, falls back to local computation. */
716
+ aspProof?: ASPProofParam;
707
717
  /** Explicit note to spend (skips note selection). Used after auto-split. */
708
718
  noteOverride?: ShieldedNote;
709
719
  }
@@ -718,8 +728,10 @@ interface FillOrderParams {
718
728
  sellToken: Address;
719
729
  /** The order's buyToken (filler pays this) */
720
730
  buyToken: Address;
721
- /** ASP ID — must be a registered personal ASP */
731
+ /** ASP ID */
722
732
  aspId: bigint;
733
+ /** Pre-fetched ASP proof from the service. If omitted, falls back to local computation. */
734
+ aspProof?: ASPProofParam;
723
735
  /** Explicit note to spend (skips note selection). Used after auto-split. */
724
736
  noteOverride?: ShieldedNote;
725
737
  }
@@ -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-P4D57KJ5.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-P4D57KJ5.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-P4D57KJ5.js'),
2109
2143
  import('../proof-C4YBP6RY.js'),
2110
2144
  import('../index.js'),
2111
2145
  import('../asp-ZA3RGN7G.js')
@@ -2152,7 +2186,7 @@ function useSwap(config) {
2152
2186
  BigInt(actualLeafIndex),
2153
2187
  storedCommitment
2154
2188
  ]);
2155
- const aspProofData = await generateASPProof2(aspId, origin, cfg.aspApprovedOrigins);
2189
+ const aspProofData = params.aspProof ? { aspId, aspRoot: params.aspProof.root, aspPathElements: params.aspProof.pathElements, aspPathIndices: params.aspProof.pathIndices } : await generateASPProof2(aspId, origin, cfg.aspApprovedOrigins);
2156
2190
  const circuitInputs = {
2157
2191
  stateRoot: stateRootBI.toString(),
2158
2192
  aspRoot: aspProofData.aspRoot.toString(),
@@ -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-P4D57KJ5.js'),
2261
2295
  import('../proof-C4YBP6RY.js'),
2262
2296
  import('../index.js'),
2263
2297
  import('../asp-ZA3RGN7G.js')
@@ -2310,7 +2344,7 @@ function useSwap(config) {
2310
2344
  BigInt(actualLeafIndex),
2311
2345
  storedCommitmentF
2312
2346
  ]);
2313
- const aspProofData = await generateASPProof2(aspId, origin, cfg.aspApprovedOrigins);
2347
+ const aspProofData = params.aspProof ? { aspId, aspRoot: params.aspProof.root, aspPathElements: params.aspProof.pathElements, aspPathIndices: params.aspProof.pathIndices } : await generateASPProof2(aspId, origin, cfg.aspApprovedOrigins);
2314
2348
  const circuitInputs = {
2315
2349
  stateRoot: stateRootBI.toString(),
2316
2350
  aspRoot: aspProofData.aspRoot.toString(),
@@ -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-P4D57KJ5.js'),
2491
2525
  import('../proof-C4YBP6RY.js'),
2492
2526
  import('../asp-ZA3RGN7G.js')
2493
2527
  ]);
@@ -2507,7 +2541,7 @@ function useSwap(config) {
2507
2541
  token
2508
2542
  };
2509
2543
  const [noteProof] = await getMerkleProofsForNotes([spendableNote], leaves, tree);
2510
- const aspProof = await generateASPProof2(splitAspId ?? DEMO_ASP_ID, origin, cfg.aspApprovedOrigins);
2544
+ 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);
2511
2545
  setStage("generating_proof");
2512
2546
  const exactNoteWithAmount = { ...exactNoteData, amount: targetAmount };
2513
2547
  const changeNoteWithAmount = { ...changeNoteData, amount: changeAmount };