@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.
- package/dist/chunk-3YZSIYJC.cjs +154 -0
- package/dist/chunk-3YZSIYJC.cjs.map +1 -0
- package/dist/{chunk-5AKBSMEQ.cjs → chunk-4N5BH43P.cjs} +2 -2
- package/dist/{chunk-5AKBSMEQ.cjs.map → chunk-4N5BH43P.cjs.map} +1 -1
- package/dist/{chunk-C7QQOJ7T.cjs → chunk-52PPS4AT.cjs} +4 -22
- package/dist/chunk-52PPS4AT.cjs.map +1 -0
- package/dist/{chunk-NUIQHTSA.js → chunk-7F75NGNB.js} +76 -3
- package/dist/chunk-7F75NGNB.js.map +1 -0
- package/dist/{chunk-SGZZL5AC.js → chunk-GS4UCMW4.js} +4 -20
- package/dist/chunk-GS4UCMW4.js.map +1 -0
- package/dist/{chunk-OQDSHMXU.js → chunk-IU5P5VDV.js} +2 -2
- package/dist/{chunk-OQDSHMXU.js.map → chunk-IU5P5VDV.js.map} +1 -1
- package/dist/{chunk-GXZ3MTCQ.cjs → chunk-IYOR5TCO.cjs} +77 -2
- package/dist/chunk-IYOR5TCO.cjs.map +1 -0
- package/dist/{chunk-GQV47S3N.cjs → chunk-PTDVGWHU.cjs} +2 -2
- package/dist/{chunk-GQV47S3N.cjs.map → chunk-PTDVGWHU.cjs.map} +1 -1
- package/dist/{chunk-PWHOUQOZ.js → chunk-QBCLFGMV.js} +16 -16
- package/dist/{chunk-PWHOUQOZ.js.map → chunk-QBCLFGMV.js.map} +1 -1
- package/dist/{chunk-NCW4AE7L.js → chunk-UAVWYXDN.js} +2 -2
- package/dist/chunk-UAVWYXDN.js.map +1 -0
- package/dist/{chunk-KIKBPJXJ.cjs → chunk-X4DLTVOG.cjs} +16 -16
- package/dist/{chunk-KIKBPJXJ.cjs.map → chunk-X4DLTVOG.cjs.map} +1 -1
- package/dist/chunk-XBNYAAMU.js +140 -0
- package/dist/chunk-XBNYAAMU.js.map +1 -0
- package/dist/core/index.cjs +67 -61
- package/dist/core/index.d.cts +3 -2
- package/dist/core/index.d.ts +3 -2
- package/dist/core/index.js +5 -3
- package/dist/{index-BGvapsJy.d.cts → index-B45-okum.d.cts} +19 -3
- package/dist/{index-ChGaGPzP.d.ts → index-BIcvNMPt.d.ts} +19 -3
- package/dist/{index-BBzvvrhG.d.ts → index-DwAJBoU7.d.ts} +122 -96
- package/dist/{index-C-jSNw6j.d.cts → index-o-Ds3YAq.d.cts} +122 -96
- package/dist/index.cjs +123 -70
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -3
- package/dist/index.d.ts +4 -3
- package/dist/index.js +6 -5
- package/dist/index.js.map +1 -1
- package/dist/indexer/index.cjs +6 -6
- package/dist/indexer/index.d.cts +6 -5
- package/dist/indexer/index.d.ts +6 -5
- package/dist/indexer/index.js +1 -1
- package/dist/react/index.cjs +107 -102
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +2 -2
- package/dist/react/index.d.ts +2 -2
- package/dist/react/index.js +100 -95
- package/dist/react/index.js.map +1 -1
- package/dist/stark-BcTD1OaJ.d.cts +185 -0
- package/dist/stark-BcTD1OaJ.d.ts +185 -0
- package/dist/{transfer-2UDHDS7Q.cjs → transfer-6ZIVZ6JY.cjs} +9 -9
- package/dist/{transfer-2UDHDS7Q.cjs.map → transfer-6ZIVZ6JY.cjs.map} +1 -1
- package/dist/{transfer-DKZuJnRM.d.cts → transfer-BzyernBd.d.cts} +1 -3
- package/dist/{transfer-KTCXKHS4.js → transfer-CDXC3OQW.js} +3 -3
- package/dist/{transfer-KTCXKHS4.js.map → transfer-CDXC3OQW.js.map} +1 -1
- package/dist/{transfer-BlmbO-Rd.d.ts → transfer-sqS6mJko.d.ts} +1 -3
- package/dist/utils/index.cjs +54 -1
- package/dist/utils/index.d.cts +2 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -1
- package/package.json +3 -2
- package/src/deployments/11155111.json +13 -13
- package/src/deployments/31337.json +1 -1
- package/stwo-prover/pkg/upp_stwo_prover.d.ts +79 -0
- package/stwo-prover/pkg/upp_stwo_prover.js +293 -0
- package/stwo-prover/pkg/upp_stwo_prover_bg.wasm +0 -0
- package/stwo-prover/pkg/upp_stwo_prover_bg.wasm.d.ts +13 -0
- package/dist/chunk-C7QQOJ7T.cjs.map +0 -1
- package/dist/chunk-GXZ3MTCQ.cjs.map +0 -1
- package/dist/chunk-NCW4AE7L.js.map +0 -1
- package/dist/chunk-NUIQHTSA.js.map +0 -1
- package/dist/chunk-SGZZL5AC.js.map +0 -1
package/dist/react/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as ASPProof,
|
|
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';
|
package/dist/react/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export { A as ASPProof,
|
|
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';
|
package/dist/react/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
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 {
|
|
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
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
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
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
257
|
+
try {
|
|
258
|
+
localStorage.removeItem(notesKey);
|
|
259
|
+
} catch {
|
|
260
|
+
}
|
|
259
261
|
}
|
|
260
262
|
if (ethAddress) {
|
|
261
|
-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
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-
|
|
2483
|
+
import('../transfer-CDXC3OQW.js'),
|
|
2479
2484
|
import('../proof-C4YBP6RY.js'),
|
|
2480
2485
|
import('../asp-ZA3RGN7G.js')
|
|
2481
2486
|
]);
|