@permissionless-technologies/upp-sdk 0.2.0 → 0.3.0

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 (72) hide show
  1. package/dist/chunk-3YZSIYJC.cjs +154 -0
  2. package/dist/chunk-3YZSIYJC.cjs.map +1 -0
  3. package/dist/{chunk-5AKBSMEQ.cjs → chunk-4N5BH43P.cjs} +2 -2
  4. package/dist/{chunk-5AKBSMEQ.cjs.map → chunk-4N5BH43P.cjs.map} +1 -1
  5. package/dist/{chunk-C7QQOJ7T.cjs → chunk-52PPS4AT.cjs} +4 -22
  6. package/dist/chunk-52PPS4AT.cjs.map +1 -0
  7. package/dist/{chunk-NUIQHTSA.js → chunk-7F75NGNB.js} +76 -3
  8. package/dist/chunk-7F75NGNB.js.map +1 -0
  9. package/dist/{chunk-SGZZL5AC.js → chunk-GS4UCMW4.js} +4 -20
  10. package/dist/chunk-GS4UCMW4.js.map +1 -0
  11. package/dist/{chunk-OQDSHMXU.js → chunk-IU5P5VDV.js} +2 -2
  12. package/dist/{chunk-OQDSHMXU.js.map → chunk-IU5P5VDV.js.map} +1 -1
  13. package/dist/{chunk-GXZ3MTCQ.cjs → chunk-IYOR5TCO.cjs} +77 -2
  14. package/dist/chunk-IYOR5TCO.cjs.map +1 -0
  15. package/dist/{chunk-GQV47S3N.cjs → chunk-PTDVGWHU.cjs} +2 -2
  16. package/dist/{chunk-GQV47S3N.cjs.map → chunk-PTDVGWHU.cjs.map} +1 -1
  17. package/dist/{chunk-PWHOUQOZ.js → chunk-QBCLFGMV.js} +16 -16
  18. package/dist/{chunk-PWHOUQOZ.js.map → chunk-QBCLFGMV.js.map} +1 -1
  19. package/dist/{chunk-NCW4AE7L.js → chunk-UAVWYXDN.js} +2 -2
  20. package/dist/chunk-UAVWYXDN.js.map +1 -0
  21. package/dist/{chunk-KIKBPJXJ.cjs → chunk-X4DLTVOG.cjs} +16 -16
  22. package/dist/{chunk-KIKBPJXJ.cjs.map → chunk-X4DLTVOG.cjs.map} +1 -1
  23. package/dist/chunk-XBNYAAMU.js +140 -0
  24. package/dist/chunk-XBNYAAMU.js.map +1 -0
  25. package/dist/core/index.cjs +67 -61
  26. package/dist/core/index.d.cts +3 -2
  27. package/dist/core/index.d.ts +3 -2
  28. package/dist/core/index.js +5 -3
  29. package/dist/{index-BGvapsJy.d.cts → index-B45-okum.d.cts} +19 -3
  30. package/dist/{index-ChGaGPzP.d.ts → index-BIcvNMPt.d.ts} +19 -3
  31. package/dist/{index-BBzvvrhG.d.ts → index-DwAJBoU7.d.ts} +122 -96
  32. package/dist/{index-C-jSNw6j.d.cts → index-o-Ds3YAq.d.cts} +122 -96
  33. package/dist/index.cjs +123 -70
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +4 -3
  36. package/dist/index.d.ts +4 -3
  37. package/dist/index.js +6 -5
  38. package/dist/index.js.map +1 -1
  39. package/dist/indexer/index.cjs +6 -6
  40. package/dist/indexer/index.d.cts +6 -5
  41. package/dist/indexer/index.d.ts +6 -5
  42. package/dist/indexer/index.js +1 -1
  43. package/dist/react/index.cjs +107 -102
  44. package/dist/react/index.cjs.map +1 -1
  45. package/dist/react/index.d.cts +2 -2
  46. package/dist/react/index.d.ts +2 -2
  47. package/dist/react/index.js +100 -95
  48. package/dist/react/index.js.map +1 -1
  49. package/dist/stark-BcTD1OaJ.d.cts +185 -0
  50. package/dist/stark-BcTD1OaJ.d.ts +185 -0
  51. package/dist/{transfer-2UDHDS7Q.cjs → transfer-6ZIVZ6JY.cjs} +9 -9
  52. package/dist/{transfer-2UDHDS7Q.cjs.map → transfer-6ZIVZ6JY.cjs.map} +1 -1
  53. package/dist/{transfer-DKZuJnRM.d.cts → transfer-BzyernBd.d.cts} +1 -3
  54. package/dist/{transfer-KTCXKHS4.js → transfer-CDXC3OQW.js} +3 -3
  55. package/dist/{transfer-KTCXKHS4.js.map → transfer-CDXC3OQW.js.map} +1 -1
  56. package/dist/{transfer-BlmbO-Rd.d.ts → transfer-sqS6mJko.d.ts} +1 -3
  57. package/dist/utils/index.cjs +54 -1
  58. package/dist/utils/index.d.cts +2 -0
  59. package/dist/utils/index.d.ts +2 -0
  60. package/dist/utils/index.js +2 -1
  61. package/package.json +3 -2
  62. package/src/deployments/11155111.json +13 -13
  63. package/src/deployments/31337.json +1 -1
  64. package/stwo-prover/pkg/upp_stwo_prover.d.ts +79 -0
  65. package/stwo-prover/pkg/upp_stwo_prover.js +293 -0
  66. package/stwo-prover/pkg/upp_stwo_prover_bg.wasm +0 -0
  67. package/stwo-prover/pkg/upp_stwo_prover_bg.wasm.d.ts +13 -0
  68. package/dist/chunk-C7QQOJ7T.cjs.map +0 -1
  69. package/dist/chunk-GXZ3MTCQ.cjs.map +0 -1
  70. package/dist/chunk-NCW4AE7L.js.map +0 -1
  71. package/dist/chunk-NUIQHTSA.js.map +0 -1
  72. package/dist/chunk-SGZZL5AC.js.map +0 -1
@@ -1,5 +1,5 @@
1
- import { ay as NoteCreationResult, az as ShieldedNote, Q as TransferStage, J as SwapOrderEvent } from '../transfer-DKZuJnRM.cjs';
2
- export { A as ASPProof, aG as ASP_TREE_DEPTH, aE as IndexerConfig, aD as ProofSystemType, aF as SignTypedDataFn, aC as UPPAccountContextType, aB as UPPAccountProvider, Z as buildASPTree, a3 as computeMultiOriginASPRoot, a6 as computeSingleOriginASPRoot, af as generateASPProof, ah as generateMultiOriginASPProof, aj as generateSingleOriginASPProof, aA as useUPPAccount } from '../transfer-DKZuJnRM.cjs';
1
+ import { ax as NoteCreationResult, ay as ShieldedNote, O as TransferStage, I as SwapOrderEvent } from '../transfer-BzyernBd.cjs';
2
+ export { A as ASPProof, aF as ASP_TREE_DEPTH, aD as IndexerConfig, aC as ProofSystemType, aE as SignTypedDataFn, aB as UPPAccountContextType, aA as UPPAccountProvider, Y as buildASPTree, a2 as computeMultiOriginASPRoot, a5 as computeSingleOriginASPRoot, ae as generateASPProof, ag as generateMultiOriginASPProof, ai as generateSingleOriginASPProof, az as useUPPAccount } from '../transfer-BzyernBd.cjs';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import { CSSProperties } from 'react';
@@ -1,5 +1,5 @@
1
- import { ay as NoteCreationResult, az as ShieldedNote, Q as TransferStage, J as SwapOrderEvent } from '../transfer-BlmbO-Rd.js';
2
- export { A as ASPProof, aG as ASP_TREE_DEPTH, aE as IndexerConfig, aD as ProofSystemType, aF as SignTypedDataFn, aC as UPPAccountContextType, aB as UPPAccountProvider, Z as buildASPTree, a3 as computeMultiOriginASPRoot, a6 as computeSingleOriginASPRoot, af as generateASPProof, ah as generateMultiOriginASPProof, aj as generateSingleOriginASPProof, aA as useUPPAccount } from '../transfer-BlmbO-Rd.js';
1
+ import { ax as NoteCreationResult, ay as ShieldedNote, O as TransferStage, I as SwapOrderEvent } from '../transfer-sqS6mJko.js';
2
+ export { A as ASPProof, aF as ASP_TREE_DEPTH, aD as IndexerConfig, aC as ProofSystemType, aE as SignTypedDataFn, aB as UPPAccountContextType, aA as UPPAccountProvider, Y as buildASPTree, a2 as computeMultiOriginASPRoot, a5 as computeSingleOriginASPRoot, ae as generateASPProof, ag as generateMultiOriginASPProof, ai as generateSingleOriginASPProof, az as useUPPAccount } from '../transfer-sqS6mJko.js';
3
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
4
4
  import * as react from 'react';
5
5
  import { CSSProperties } from 'react';
@@ -1,4 +1,4 @@
1
- import { NoteStore, init_stealth, stealth_exports, SWAP_ORDER_PLACED_EVENT, filterOrdersByTokenPair, filterOrdersByASP, generateCancelSecret, computeCancelKeyHash, computeGiveAmount } from '../chunk-NUIQHTSA.js';
1
+ import { StorableAccountAdapter, init_stealth, stealth_exports, SWAP_ORDER_PLACED_EVENT, filterOrdersByTokenPair, filterOrdersByASP, generateCancelSecret, computeCancelKeyHash, computeGiveAmount, NoteStore } from '../chunk-7F75NGNB.js';
2
2
  import { computeSingleOriginASPRoot } from '../chunk-P37MRZ73.js';
3
3
  export { ASP_TREE_DEPTH, buildASPTree, computeMultiOriginASPRoot, computeSingleOriginASPRoot, generateASPProof, generateMultiOriginASPProof, generateSingleOriginASPProof } from '../chunk-P37MRZ73.js';
4
4
  import { createAutoAdapter } from '../chunk-XV72HNHN.js';
@@ -6,7 +6,7 @@ import '../chunk-W77GRBO4.js';
6
6
  import { init_poseidon, BABYJUBJUB_SUBORDER } from '../chunk-V23OSL25.js';
7
7
  import { __toCommonJS } from '../chunk-Z6ZWNWWR.js';
8
8
  import { createContext, useState, useRef, useEffect, useCallback, useMemo, useContext } from 'react';
9
- import { toHex, keccak256, toBytes, getAddress, encodePacked } from 'viem';
9
+ import { keccak256, toBytes, toHex, getAddress, encodePacked } from 'viem';
10
10
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
11
  import { createPortal } from 'react-dom';
12
12
  import { ASP_REGISTRY_HUB_ABI } from '@permissionless-technologies/upc-sdk';
@@ -89,98 +89,103 @@ function UPPAccountProvider({
89
89
  const unwatchRef = useRef(null);
90
90
  const syncPromiseRef = useRef(null);
91
91
  const noteStoreRef = useRef(null);
92
+ const accountAdapterRef = useRef(null);
92
93
  useEffect(() => {
93
94
  loadSDK().then(() => setCryptoReady(true));
94
95
  }, []);
95
96
  useEffect(() => {
96
97
  let noteStoreUnsub = null;
98
+ let cancelled = false;
97
99
  if (typeof window === "undefined") return;
98
100
  if (!ethAddress || !cryptoReady) {
99
101
  setMasterKeys(null);
100
102
  setStarkMasterKeys(null);
101
103
  setNotes([]);
102
104
  noteStoreRef.current = null;
105
+ accountAdapterRef.current = null;
103
106
  return;
104
107
  }
105
- const saved = localStorage.getItem(getStorageKey(ethAddress));
106
- if (saved) {
107
- try {
108
- const parsed = JSON.parse(saved);
109
- if (!parsed.starkSecret || !parsed.spendingSecret) {
110
- console.log("[UPPAccount] Invalid account data, clearing...");
111
- localStorage.removeItem(getStorageKey(ethAddress));
112
- setMasterKeys(null);
113
- setStarkMasterKeys(null);
114
- setNotes([]);
115
- return;
116
- }
117
- const keys = {
118
- spendingSecret: BigInt(parsed.spendingSecret),
119
- ownerHash: BigInt(parsed.ownerHash),
120
- viewingSecret: BigInt(parsed.viewingSecret),
121
- viewingHash: BigInt(parsed.viewingHash)
122
- };
123
- setMasterKeys(keys);
124
- if (parsed.starkSecret) {
125
- const starkKeys = {
126
- starkSecret: parsed.starkSecret.map((s) => BigInt(s)),
127
- starkOwnerHash: parsed.starkOwnerHash.map((s) => BigInt(s)),
128
- starkViewingSecret: parsed.starkViewingSecret.map((s) => BigInt(s)),
129
- starkViewingHash: parsed.starkViewingHash.map((s) => BigInt(s))
130
- };
131
- setStarkMasterKeys(starkKeys);
108
+ const accountStorage = createAutoAdapter(`upp_account`);
109
+ const adapter = new StorableAccountAdapter(accountStorage, ethAddress);
110
+ accountAdapterRef.current = adapter;
111
+ const legacyKey = getStorageKey(ethAddress);
112
+ const legacySaved = typeof window !== "undefined" ? localStorage.getItem(legacyKey) : null;
113
+ const init = async () => {
114
+ let account = await adapter.load();
115
+ if (!account && legacySaved) {
116
+ try {
117
+ const parsed = JSON.parse(legacySaved);
118
+ if (parsed.spendingSecret && parsed.starkSecret) {
119
+ const keys = {
120
+ spendingSecret: BigInt(parsed.spendingSecret),
121
+ ownerHash: BigInt(parsed.ownerHash),
122
+ viewingSecret: BigInt(parsed.viewingSecret),
123
+ viewingHash: BigInt(parsed.viewingHash)
124
+ };
125
+ const starkKeys = {
126
+ starkSecret: parsed.starkSecret.map((s) => BigInt(s)),
127
+ starkOwnerHash: parsed.starkOwnerHash.map((s) => BigInt(s)),
128
+ starkViewingSecret: parsed.starkViewingSecret.map((s) => BigInt(s)),
129
+ starkViewingHash: parsed.starkViewingHash.map((s) => BigInt(s))
130
+ };
131
+ await adapter.save(keys, starkKeys);
132
+ account = { keys, starkKeys };
133
+ console.log("[UPPAccount] Migrated account from legacy localStorage");
134
+ }
135
+ } catch {
132
136
  }
133
- const ownerHashHex2 = toHex(keys.ownerHash, { size: 32 });
134
- const storagePrefix = `upp_${chainId}_${ownerHashHex2.slice(0, 12)}`;
135
- const storage = createAutoAdapter(storagePrefix);
136
- const store = new NoteStore(storage, "notes");
137
- noteStoreRef.current = store;
138
- noteStoreUnsub = store.onChange(() => {
139
- setNotes([...store.getNotes()]);
140
- });
141
- store.load().then(() => {
142
- if (store.getNotes().length === 0) {
143
- const legacyKey = getNotesStorageKey(chainId, ownerHashHex2.slice(0, 12));
144
- const legacyNotes = localStorage.getItem(legacyKey);
145
- if (legacyNotes) {
146
- try {
147
- const parsed2 = JSON.parse(legacyNotes);
148
- const migrated = parsed2.map((n) => ({
149
- ...n,
150
- amount: BigInt(n.amount),
151
- blinding: BigInt(n.blinding),
152
- origin: n.origin ?? "0x0000000000000000000000000000000000000000",
153
- token: n.token ?? "0x0000000000000000000000000000000000000000",
154
- proofSystem: n.proofSystem ?? "snark"
155
- }));
156
- store.addNotes(migrated);
157
- store.persist();
158
- console.log(`[NoteStore] Migrated ${migrated.length} legacy notes`);
159
- } catch {
160
- }
161
- }
137
+ }
138
+ if (cancelled) return;
139
+ if (!account) {
140
+ setMasterKeys(null);
141
+ setStarkMasterKeys(null);
142
+ setNotes([]);
143
+ return;
144
+ }
145
+ setMasterKeys(account.keys);
146
+ if (account.starkKeys) setStarkMasterKeys(account.starkKeys);
147
+ const ownerHashHex2 = toHex(account.keys.ownerHash, { size: 32 });
148
+ const storagePrefix = `upp_${chainId}_${ownerHashHex2.slice(0, 12)}`;
149
+ const noteStorage = createAutoAdapter(storagePrefix);
150
+ const store = new NoteStore(noteStorage, "notes");
151
+ noteStoreRef.current = store;
152
+ noteStoreUnsub = store.onChange(() => {
153
+ if (!cancelled) setNotes([...store.getNotes()]);
154
+ });
155
+ await store.load();
156
+ if (store.getNotes().length === 0) {
157
+ const legacyNotesKey = getNotesStorageKey(chainId, ownerHashHex2.slice(0, 12));
158
+ const legacyNotes = typeof window !== "undefined" ? localStorage.getItem(legacyNotesKey) : null;
159
+ if (legacyNotes) {
160
+ try {
161
+ const parsed = JSON.parse(legacyNotes);
162
+ const migrated = parsed.map((n) => ({
163
+ ...n,
164
+ amount: BigInt(n.amount),
165
+ blinding: BigInt(n.blinding),
166
+ origin: n.origin ?? "0x0000000000000000000000000000000000000000",
167
+ token: n.token ?? "0x0000000000000000000000000000000000000000",
168
+ proofSystem: n.proofSystem ?? "snark"
169
+ }));
170
+ store.addNotes(migrated);
171
+ await store.persist();
172
+ console.log(`[NoteStore] Migrated ${migrated.length} legacy notes`);
173
+ } catch {
162
174
  }
163
- setNotes([...store.getNotes()]);
164
- });
165
- if (publicClientProp) {
166
- checkChainFingerprint(chainId, publicClientProp).then((valid) => {
167
- if (!valid) {
168
- console.log(`[UPPAccount] Chain ${chainId} was reset \u2014 clearing stale notes`);
169
- store.clear();
170
- const legacyKey = getNotesStorageKey(chainId, ownerHashHex2.slice(0, 12));
171
- localStorage.removeItem(legacyKey);
172
- }
173
- });
174
175
  }
175
- } catch (e) {
176
- console.error("Failed to load saved account:", e);
177
176
  }
178
- } else {
179
- setMasterKeys(null);
180
- setStarkMasterKeys(null);
181
- setNotes([]);
182
- }
177
+ if (!cancelled) setNotes([...store.getNotes()]);
178
+ if (publicClientProp) {
179
+ const valid = await checkChainFingerprint(chainId, publicClientProp);
180
+ if (!valid && !cancelled) {
181
+ console.log(`[UPPAccount] Chain ${chainId} was reset \u2014 clearing stale notes`);
182
+ await store.clear();
183
+ }
184
+ }
185
+ };
186
+ init().catch((e) => console.error("Failed to load account:", e));
183
187
  return () => {
188
+ cancelled = true;
184
189
  if (noteStoreUnsub) noteStoreUnsub();
185
190
  };
186
191
  }, [ethAddress, cryptoReady, chainId, publicClientProp]);
@@ -203,18 +208,10 @@ function UPPAccountProvider({
203
208
  setMasterKeys(keys);
204
209
  setStarkMasterKeys(starkKeys);
205
210
  setNotes([]);
206
- const serialized = {
207
- version: 3,
208
- spendingSecret: toHex(keys.spendingSecret, { size: 32 }),
209
- ownerHash: toHex(keys.ownerHash, { size: 32 }),
210
- viewingSecret: toHex(keys.viewingSecret, { size: 32 }),
211
- viewingHash: toHex(keys.viewingHash, { size: 32 }),
212
- starkSecret: starkKeys.starkSecret.map((v) => v.toString()),
213
- starkOwnerHash: starkKeys.starkOwnerHash.map((v) => v.toString()),
214
- starkViewingSecret: starkKeys.starkViewingSecret.map((v) => v.toString()),
215
- starkViewingHash: starkKeys.starkViewingHash.map((v) => v.toString())
216
- };
217
- localStorage.setItem(getStorageKey(ethAddress), JSON.stringify(serialized));
211
+ const adapter = accountAdapterRef.current;
212
+ if (adapter) {
213
+ await adapter.save(keys, starkKeys);
214
+ }
218
215
  } finally {
219
216
  setIsLoading(false);
220
217
  }
@@ -252,13 +249,21 @@ function UPPAccountProvider({
252
249
  const logout = useCallback(() => {
253
250
  noteStoreRef.current?.clear().catch(console.error);
254
251
  noteStoreRef.current = null;
252
+ accountAdapterRef.current?.clear().catch(console.error);
253
+ accountAdapterRef.current = null;
255
254
  if (masterKeys) {
256
255
  const ownerHashHex2 = toHex(masterKeys.ownerHash, { size: 32 });
257
256
  const notesKey = getNotesStorageKey(chainId, ownerHashHex2.slice(0, 12));
258
- localStorage.removeItem(notesKey);
257
+ try {
258
+ localStorage.removeItem(notesKey);
259
+ } catch {
260
+ }
259
261
  }
260
262
  if (ethAddress) {
261
- localStorage.removeItem(getStorageKey(ethAddress));
263
+ try {
264
+ localStorage.removeItem(getStorageKey(ethAddress));
265
+ } catch {
266
+ }
262
267
  }
263
268
  setMasterKeys(null);
264
269
  setStarkMasterKeys(null);
@@ -1555,7 +1560,7 @@ function usePoolTransfer(config) {
1555
1560
  const recipientNote = await createNoteForSelf(amount, origin, token);
1556
1561
  const changeNote = await createNoteForSelf(changeAmount, origin, token);
1557
1562
  const [transferModule, proofModule, aspModule] = await Promise.all([
1558
- import('../transfer-KTCXKHS4.js'),
1563
+ import('../transfer-CDXC3OQW.js'),
1559
1564
  import('../proof-C4YBP6RY.js'),
1560
1565
  import('../asp-ZA3RGN7G.js')
1561
1566
  ]);
@@ -1714,7 +1719,7 @@ function useWithdraw(config) {
1714
1719
  const token = BigInt(selectedNote.token);
1715
1720
  setStage("creating_outputs");
1716
1721
  const [transferModule, proofModule, sdk] = await Promise.all([
1717
- import('../transfer-KTCXKHS4.js'),
1722
+ import('../transfer-CDXC3OQW.js'),
1718
1723
  import('../proof-C4YBP6RY.js'),
1719
1724
  import('../index.js')
1720
1725
  ]);
@@ -2093,7 +2098,7 @@ function useSwap(config) {
2093
2098
  }
2094
2099
  setStage("creating_outputs");
2095
2100
  const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
2096
- import('../transfer-KTCXKHS4.js'),
2101
+ import('../transfer-CDXC3OQW.js'),
2097
2102
  import('../proof-C4YBP6RY.js'),
2098
2103
  import('../index.js'),
2099
2104
  import('../asp-ZA3RGN7G.js')
@@ -2245,7 +2250,7 @@ function useSwap(config) {
2245
2250
  }
2246
2251
  setStage("creating_outputs");
2247
2252
  const [transferModule, proofModule, sdk, aspModule] = await Promise.all([
2248
- import('../transfer-KTCXKHS4.js'),
2253
+ import('../transfer-CDXC3OQW.js'),
2249
2254
  import('../proof-C4YBP6RY.js'),
2250
2255
  import('../index.js'),
2251
2256
  import('../asp-ZA3RGN7G.js')
@@ -2475,7 +2480,7 @@ function useSwap(config) {
2475
2480
  createNoteForSelf(changeAmount, origin, token)
2476
2481
  ]);
2477
2482
  const [transferModule, proofModule, aspModule] = await Promise.all([
2478
- import('../transfer-KTCXKHS4.js'),
2483
+ import('../transfer-CDXC3OQW.js'),
2479
2484
  import('../proof-C4YBP6RY.js'),
2480
2485
  import('../asp-ZA3RGN7G.js')
2481
2486
  ]);