@miden-sdk/react 0.14.4 → 0.14.8
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/CLAUDE.md +66 -47
- package/LICENSE +21 -0
- package/README.md +67 -12
- package/dist/index.d.ts +3 -3
- package/dist/index.mjs +63 -26
- package/dist/lazy.d.ts +3 -3
- package/dist/lazy.mjs +63 -26
- package/dist/{lazy.d.mts → mt/lazy.d.ts} +3 -3
- package/dist/{index.js → mt/lazy.mjs} +466 -464
- package/dist/{index.d.mts → mt.d.ts} +3 -3
- package/dist/{lazy.js → mt.mjs} +466 -464
- package/lazy/package.json +5 -0
- package/mt/lazy/package.json +5 -0
- package/mt/package.json +5 -0
- package/package.json +36 -33
|
@@ -1,100 +1,16 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.ts
|
|
31
|
-
var src_exports = {};
|
|
32
|
-
__export(src_exports, {
|
|
33
|
-
AuthScheme: () => import_lazy4.AuthScheme,
|
|
34
|
-
DEFAULTS: () => DEFAULTS,
|
|
35
|
-
MidenError: () => MidenError,
|
|
36
|
-
MidenProvider: () => MidenProvider,
|
|
37
|
-
MultiSignerProvider: () => MultiSignerProvider,
|
|
38
|
-
SignerContext: () => SignerContext,
|
|
39
|
-
SignerSlot: () => SignerSlot,
|
|
40
|
-
accountIdsEqual: () => accountIdsEqual,
|
|
41
|
-
bigIntToBytes: () => bigIntToBytes,
|
|
42
|
-
bytesToBigInt: () => bytesToBigInt,
|
|
43
|
-
clearMidenStorage: () => clearMidenStorage,
|
|
44
|
-
concatBytes: () => concatBytes,
|
|
45
|
-
createMidenStorage: () => createMidenStorage,
|
|
46
|
-
createNoteAttachment: () => createNoteAttachment,
|
|
47
|
-
formatAssetAmount: () => formatAssetAmount,
|
|
48
|
-
formatNoteSummary: () => formatNoteSummary,
|
|
49
|
-
getNoteSummary: () => getNoteSummary,
|
|
50
|
-
migrateStorage: () => migrateStorage,
|
|
51
|
-
normalizeAccountId: () => normalizeAccountId,
|
|
52
|
-
parseAssetAmount: () => parseAssetAmount,
|
|
53
|
-
readNoteAttachment: () => readNoteAttachment,
|
|
54
|
-
toBech32AccountId: () => toBech32AccountId,
|
|
55
|
-
useAccount: () => useAccount,
|
|
56
|
-
useAccounts: () => useAccounts,
|
|
57
|
-
useAssetMetadata: () => useAssetMetadata,
|
|
58
|
-
useCompile: () => useCompile,
|
|
59
|
-
useConsume: () => useConsume,
|
|
60
|
-
useCreateFaucet: () => useCreateFaucet,
|
|
61
|
-
useCreateWallet: () => useCreateWallet,
|
|
62
|
-
useExecuteProgram: () => useExecuteProgram,
|
|
63
|
-
useExportNote: () => useExportNote,
|
|
64
|
-
useExportStore: () => useExportStore,
|
|
65
|
-
useImportAccount: () => useImportAccount,
|
|
66
|
-
useImportNote: () => useImportNote,
|
|
67
|
-
useImportStore: () => useImportStore,
|
|
68
|
-
useMiden: () => useMiden,
|
|
69
|
-
useMidenClient: () => useMidenClient,
|
|
70
|
-
useMint: () => useMint,
|
|
71
|
-
useMultiSend: () => useMultiSend,
|
|
72
|
-
useMultiSigner: () => useMultiSigner,
|
|
73
|
-
useNoteStream: () => useNoteStream,
|
|
74
|
-
useNotes: () => useNotes,
|
|
75
|
-
useSend: () => useSend,
|
|
76
|
-
useSessionAccount: () => useSessionAccount,
|
|
77
|
-
useSigner: () => useSigner,
|
|
78
|
-
useSwap: () => useSwap,
|
|
79
|
-
useSyncControl: () => useSyncControl,
|
|
80
|
-
useSyncState: () => useSyncState,
|
|
81
|
-
useTransaction: () => useTransaction,
|
|
82
|
-
useTransactionHistory: () => useTransactionHistory,
|
|
83
|
-
useWaitForCommit: () => useWaitForCommit,
|
|
84
|
-
useWaitForNotes: () => useWaitForNotes,
|
|
85
|
-
waitForWalletDetection: () => waitForWalletDetection,
|
|
86
|
-
wrapWasmError: () => wrapWasmError
|
|
87
|
-
});
|
|
88
|
-
module.exports = __toCommonJS(src_exports);
|
|
89
|
-
|
|
90
1
|
// src/types/augmentations.ts
|
|
91
|
-
|
|
2
|
+
import "@miden-sdk/miden-sdk/mt/lazy";
|
|
92
3
|
|
|
93
4
|
// src/utils/accountBech32.ts
|
|
94
|
-
|
|
5
|
+
import {
|
|
6
|
+
Account,
|
|
7
|
+
AccountInterface,
|
|
8
|
+
Address as Address2,
|
|
9
|
+
NetworkId
|
|
10
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
95
11
|
|
|
96
12
|
// src/store/MidenStore.ts
|
|
97
|
-
|
|
13
|
+
import { create } from "zustand";
|
|
98
14
|
var initialSyncState = {
|
|
99
15
|
syncHeight: 0,
|
|
100
16
|
isSyncing: false,
|
|
@@ -126,7 +42,7 @@ function freshState() {
|
|
|
126
42
|
...freshCachedState()
|
|
127
43
|
};
|
|
128
44
|
}
|
|
129
|
-
var useMidenStore =
|
|
45
|
+
var useMidenStore = create()((set) => ({
|
|
130
46
|
...freshState(),
|
|
131
47
|
setClient: (client) => set({
|
|
132
48
|
client,
|
|
@@ -238,19 +154,19 @@ var useAssetMetadataStore = () => useMidenStore((state) => state.assetMetadata);
|
|
|
238
154
|
var useNoteFirstSeenStore = () => useMidenStore((state) => state.noteFirstSeen);
|
|
239
155
|
|
|
240
156
|
// src/utils/accountParsing.ts
|
|
241
|
-
|
|
157
|
+
import { AccountId, Address } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
242
158
|
var normalizeAccountIdInput = (value) => value.trim().replace(/^miden:/i, "");
|
|
243
159
|
var isBech32Input = (value) => value.startsWith("m") || value.startsWith("M");
|
|
244
160
|
var normalizeHexInput = (value) => value.startsWith("0x") || value.startsWith("0X") ? value : `0x${value}`;
|
|
245
161
|
var parseAccountIdFromString = (value) => {
|
|
246
162
|
if (isBech32Input(value)) {
|
|
247
163
|
try {
|
|
248
|
-
return
|
|
164
|
+
return Address.fromBech32(value).accountId();
|
|
249
165
|
} catch {
|
|
250
|
-
return
|
|
166
|
+
return AccountId.fromBech32(value);
|
|
251
167
|
}
|
|
252
168
|
}
|
|
253
|
-
return
|
|
169
|
+
return AccountId.fromHex(normalizeHexInput(value));
|
|
254
170
|
};
|
|
255
171
|
var parseAccountId = (value) => {
|
|
256
172
|
if (typeof value === "string") {
|
|
@@ -277,49 +193,49 @@ function isFaucetId(accountId) {
|
|
|
277
193
|
var parseAddress = (value, accountId) => {
|
|
278
194
|
if (typeof value !== "string") {
|
|
279
195
|
const resolvedId = accountId ?? parseAccountId(value);
|
|
280
|
-
return
|
|
196
|
+
return Address.fromAccountId(resolvedId, "BasicWallet");
|
|
281
197
|
}
|
|
282
198
|
const normalized = normalizeAccountIdInput(value);
|
|
283
199
|
if (isBech32Input(normalized)) {
|
|
284
200
|
try {
|
|
285
|
-
return
|
|
201
|
+
return Address.fromBech32(normalized);
|
|
286
202
|
} catch {
|
|
287
|
-
const resolvedAccountId2 = accountId ??
|
|
288
|
-
return
|
|
203
|
+
const resolvedAccountId2 = accountId ?? AccountId.fromBech32(normalized);
|
|
204
|
+
return Address.fromAccountId(resolvedAccountId2, "BasicWallet");
|
|
289
205
|
}
|
|
290
206
|
}
|
|
291
|
-
const resolvedAccountId = accountId ??
|
|
292
|
-
return
|
|
207
|
+
const resolvedAccountId = accountId ?? AccountId.fromHex(normalizeHexInput(normalized));
|
|
208
|
+
return Address.fromAccountId(resolvedAccountId, "BasicWallet");
|
|
293
209
|
};
|
|
294
210
|
|
|
295
211
|
// src/utils/accountBech32.ts
|
|
296
212
|
var inferNetworkId = () => {
|
|
297
213
|
const { rpcUrl } = useMidenStore.getState().config;
|
|
298
214
|
if (!rpcUrl) {
|
|
299
|
-
return
|
|
215
|
+
return NetworkId.testnet();
|
|
300
216
|
}
|
|
301
217
|
const url = rpcUrl.toLowerCase();
|
|
302
218
|
if (url.includes("devnet") || url.includes("mdev")) {
|
|
303
|
-
return
|
|
219
|
+
return NetworkId.devnet();
|
|
304
220
|
}
|
|
305
221
|
if (url.includes("mainnet")) {
|
|
306
|
-
return
|
|
222
|
+
return NetworkId.mainnet();
|
|
307
223
|
}
|
|
308
224
|
if (url.includes("testnet") || url.includes("mtst")) {
|
|
309
|
-
return
|
|
225
|
+
return NetworkId.testnet();
|
|
310
226
|
}
|
|
311
|
-
return
|
|
227
|
+
return NetworkId.testnet();
|
|
312
228
|
};
|
|
313
229
|
var toBech32FromAccountId = (id) => {
|
|
314
230
|
try {
|
|
315
|
-
const address =
|
|
231
|
+
const address = Address2.fromAccountId(id, "BasicWallet");
|
|
316
232
|
return address.toBech32(inferNetworkId());
|
|
317
233
|
} catch {
|
|
318
234
|
}
|
|
319
235
|
try {
|
|
320
236
|
const maybeBech32 = id.toBech32?.(
|
|
321
237
|
inferNetworkId(),
|
|
322
|
-
|
|
238
|
+
AccountInterface.BasicWallet
|
|
323
239
|
);
|
|
324
240
|
if (typeof maybeBech32 === "string") {
|
|
325
241
|
return maybeBech32;
|
|
@@ -349,7 +265,7 @@ var defineBech32 = (target) => {
|
|
|
349
265
|
}
|
|
350
266
|
};
|
|
351
267
|
var installAccountBech32 = () => {
|
|
352
|
-
const proto =
|
|
268
|
+
const proto = Account.prototype;
|
|
353
269
|
if (proto.bech32id) {
|
|
354
270
|
return;
|
|
355
271
|
}
|
|
@@ -381,18 +297,26 @@ var toBech32AccountId = (accountId) => {
|
|
|
381
297
|
};
|
|
382
298
|
|
|
383
299
|
// src/context/MidenProvider.tsx
|
|
384
|
-
|
|
385
|
-
|
|
300
|
+
import {
|
|
301
|
+
createContext as createContext2,
|
|
302
|
+
useContext as useContext2,
|
|
303
|
+
useEffect,
|
|
304
|
+
useRef,
|
|
305
|
+
useCallback,
|
|
306
|
+
useMemo,
|
|
307
|
+
useState
|
|
308
|
+
} from "react";
|
|
309
|
+
import { WasmWebClient as WebClient } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
386
310
|
|
|
387
311
|
// src/types/index.ts
|
|
388
|
-
|
|
312
|
+
import { AuthScheme } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
389
313
|
var DEFAULTS = {
|
|
390
314
|
RPC_URL: void 0,
|
|
391
315
|
// Will use SDK's testnet default
|
|
392
316
|
AUTO_SYNC_INTERVAL: 15e3,
|
|
393
317
|
STORAGE_MODE: "private",
|
|
394
318
|
WALLET_MUTABLE: true,
|
|
395
|
-
AUTH_SCHEME:
|
|
319
|
+
AUTH_SCHEME: AuthScheme.Falcon,
|
|
396
320
|
NOTE_TYPE: "private",
|
|
397
321
|
FAUCET_DECIMALS: 8
|
|
398
322
|
};
|
|
@@ -436,7 +360,7 @@ function resolveRpcUrl(rpcUrl) {
|
|
|
436
360
|
}
|
|
437
361
|
|
|
438
362
|
// src/utils/prover.ts
|
|
439
|
-
|
|
363
|
+
import { TransactionProver } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
440
364
|
var DEFAULT_PROVER_URLS = {
|
|
441
365
|
devnet: "https://tx-prover.devnet.miden.io",
|
|
442
366
|
testnet: "https://tx-prover.testnet.miden.io"
|
|
@@ -475,19 +399,19 @@ function resolveProverTarget(target, config) {
|
|
|
475
399
|
if (typeof target === "string") {
|
|
476
400
|
const normalized = target.trim().toLowerCase();
|
|
477
401
|
if (normalized === "local" || normalized === "localhost") {
|
|
478
|
-
return
|
|
402
|
+
return TransactionProver.newLocalProver();
|
|
479
403
|
}
|
|
480
404
|
if (normalized === "devnet" || normalized === "testnet") {
|
|
481
405
|
const url = config.proverUrls?.[normalized] ?? DEFAULT_PROVER_URLS[normalized] ?? null;
|
|
482
406
|
if (!url) {
|
|
483
407
|
throw new Error(`Missing ${normalized} prover URL`);
|
|
484
408
|
}
|
|
485
|
-
return
|
|
409
|
+
return TransactionProver.newRemoteProver(
|
|
486
410
|
url,
|
|
487
411
|
normalizeTimeout(config.proverTimeoutMs)
|
|
488
412
|
);
|
|
489
413
|
}
|
|
490
|
-
return
|
|
414
|
+
return TransactionProver.newRemoteProver(
|
|
491
415
|
target,
|
|
492
416
|
normalizeTimeout(config.proverTimeoutMs)
|
|
493
417
|
);
|
|
@@ -499,8 +423,9 @@ function createRemoteProver(config, fallbackTimeout) {
|
|
|
499
423
|
if (!url) {
|
|
500
424
|
throw new Error("Remote prover requires a URL");
|
|
501
425
|
}
|
|
502
|
-
return
|
|
426
|
+
return TransactionProver.newRemoteProver(
|
|
503
427
|
url,
|
|
428
|
+
/* v8 ignore next 1 — timeoutMs is always provided in tests; ?? fallbackTimeout path unreachable */
|
|
504
429
|
normalizeTimeout(timeoutMs ?? fallbackTimeout)
|
|
505
430
|
);
|
|
506
431
|
}
|
|
@@ -515,10 +440,10 @@ function normalizeTimeout(timeoutMs) {
|
|
|
515
440
|
}
|
|
516
441
|
|
|
517
442
|
// src/context/SignerContext.ts
|
|
518
|
-
|
|
519
|
-
var SignerContext =
|
|
443
|
+
import { createContext, useContext } from "react";
|
|
444
|
+
var SignerContext = createContext(null);
|
|
520
445
|
function useSigner() {
|
|
521
|
-
return
|
|
446
|
+
return useContext(SignerContext);
|
|
522
447
|
}
|
|
523
448
|
|
|
524
449
|
// src/utils/signerAccount.ts
|
|
@@ -535,7 +460,13 @@ function isPrivateStorageMode(storageMode) {
|
|
|
535
460
|
return storageMode.toString() === "private";
|
|
536
461
|
}
|
|
537
462
|
async function initializeSignerAccount(client, config) {
|
|
538
|
-
const {
|
|
463
|
+
const {
|
|
464
|
+
AccountBuilder,
|
|
465
|
+
AccountComponent,
|
|
466
|
+
AuthScheme: AuthScheme2,
|
|
467
|
+
Word: Word2,
|
|
468
|
+
resolveAuthScheme: resolveAuthScheme5
|
|
469
|
+
} = await import("@miden-sdk/miden-sdk/mt/lazy");
|
|
539
470
|
await client.syncState();
|
|
540
471
|
if (config.importAccountId) {
|
|
541
472
|
const accountId2 = parseAccountId(config.importAccountId);
|
|
@@ -556,7 +487,7 @@ async function initializeSignerAccount(client, config) {
|
|
|
556
487
|
let builder = new AccountBuilder(seed).withAuthComponent(
|
|
557
488
|
AccountComponent.createAuthComponentFromCommitment(
|
|
558
489
|
commitmentWord,
|
|
559
|
-
AuthScheme2.
|
|
490
|
+
resolveAuthScheme5(AuthScheme2.ECDSA)
|
|
560
491
|
)
|
|
561
492
|
).accountType(accountType).storageMode(config.storageMode).withBasicWalletComponent();
|
|
562
493
|
if (config.customComponents?.length) {
|
|
@@ -594,8 +525,8 @@ async function initializeSignerAccount(client, config) {
|
|
|
594
525
|
}
|
|
595
526
|
|
|
596
527
|
// src/context/MidenProvider.tsx
|
|
597
|
-
|
|
598
|
-
var MidenContext = (
|
|
528
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
529
|
+
var MidenContext = createContext2(null);
|
|
599
530
|
function MidenProvider({
|
|
600
531
|
children,
|
|
601
532
|
config = {},
|
|
@@ -615,22 +546,22 @@ function MidenProvider({
|
|
|
615
546
|
setSyncState,
|
|
616
547
|
setSignerConnected
|
|
617
548
|
} = useMidenStore();
|
|
618
|
-
const syncIntervalRef =
|
|
619
|
-
const isInitializedRef =
|
|
620
|
-
const clientLockRef =
|
|
621
|
-
const currentStoreNameRef =
|
|
622
|
-
const signCbRef =
|
|
549
|
+
const syncIntervalRef = useRef(null);
|
|
550
|
+
const isInitializedRef = useRef(false);
|
|
551
|
+
const clientLockRef = useRef(new AsyncLock());
|
|
552
|
+
const currentStoreNameRef = useRef(null);
|
|
553
|
+
const signCbRef = useRef(null);
|
|
623
554
|
const signerContext = useSigner();
|
|
624
|
-
const [signerAccountId, setSignerAccountId] =
|
|
625
|
-
const resolvedConfig =
|
|
555
|
+
const [signerAccountId, setSignerAccountId] = useState(null);
|
|
556
|
+
const resolvedConfig = useMemo(
|
|
626
557
|
() => ({
|
|
627
558
|
...config,
|
|
628
559
|
rpcUrl: resolveRpcUrl(config.rpcUrl)
|
|
629
560
|
}),
|
|
630
561
|
[config]
|
|
631
562
|
);
|
|
632
|
-
const [defaultProver, setDefaultProver] =
|
|
633
|
-
|
|
563
|
+
const [defaultProver, setDefaultProver] = useState(null);
|
|
564
|
+
useEffect(() => {
|
|
634
565
|
if (!isReady) {
|
|
635
566
|
setDefaultProver(null);
|
|
636
567
|
return;
|
|
@@ -640,14 +571,16 @@ function MidenProvider({
|
|
|
640
571
|
isReady,
|
|
641
572
|
resolvedConfig.prover,
|
|
642
573
|
resolvedConfig.proverTimeoutMs,
|
|
574
|
+
/* v8 ignore next 2 — optional chain on proverUrls; tests don't pass proverUrls config */
|
|
643
575
|
resolvedConfig.proverUrls?.devnet,
|
|
644
576
|
resolvedConfig.proverUrls?.testnet
|
|
645
577
|
]);
|
|
646
|
-
const runExclusive =
|
|
578
|
+
const runExclusive = useCallback(
|
|
579
|
+
/* v8 ignore next 3 — runExclusive callback body; only called by advanced consumers, not directly in tests */
|
|
647
580
|
async (fn) => clientLockRef.current.runExclusive(fn),
|
|
648
581
|
[]
|
|
649
582
|
);
|
|
650
|
-
const sync =
|
|
583
|
+
const sync = useCallback(async () => {
|
|
651
584
|
if (!client || !isReady) return;
|
|
652
585
|
const store = useMidenStore.getState();
|
|
653
586
|
if (store.sync.isSyncing) return;
|
|
@@ -674,10 +607,12 @@ function MidenProvider({
|
|
|
674
607
|
const signerStoreName = signerContext?.storeName ?? null;
|
|
675
608
|
const signerAccountType = signerContext?.accountConfig?.accountType ?? null;
|
|
676
609
|
const signerStorageMode = signerContext?.accountConfig?.storageMode?.toString() ?? null;
|
|
677
|
-
|
|
610
|
+
useEffect(() => {
|
|
678
611
|
signCbRef.current = signerContext?.signCb ?? null;
|
|
679
612
|
}, [signerContext?.signCb]);
|
|
680
|
-
const wrappedSignCb =
|
|
613
|
+
const wrappedSignCb = useCallback(
|
|
614
|
+
/* v8 ignore next 11 — wrappedSignCb body is only called during external signer operations;
|
|
615
|
+
* tests don't exercise the full signing flow through MidenProvider directly. */
|
|
681
616
|
async (pubKey, signingInputs) => {
|
|
682
617
|
const cb = signCbRef.current;
|
|
683
618
|
if (!cb) {
|
|
@@ -687,7 +622,7 @@ function MidenProvider({
|
|
|
687
622
|
},
|
|
688
623
|
[]
|
|
689
624
|
);
|
|
690
|
-
|
|
625
|
+
useEffect(() => {
|
|
691
626
|
if (signerIsConnected === null && isInitializedRef.current) return;
|
|
692
627
|
if (signerIsConnected === false) {
|
|
693
628
|
const store = useMidenStore.getState();
|
|
@@ -721,7 +656,7 @@ function MidenProvider({
|
|
|
721
656
|
if (signerContext && signerIsConnected === true) {
|
|
722
657
|
const storeName = `MidenClientDB_${signerContext.storeName}`;
|
|
723
658
|
signCbRef.current = signerContext.signCb;
|
|
724
|
-
webClient = await
|
|
659
|
+
webClient = await WebClient.createClientWithExternalKeystore(
|
|
725
660
|
resolvedConfig.rpcUrl,
|
|
726
661
|
resolvedConfig.noteTransportUrl,
|
|
727
662
|
resolvedConfig.seed,
|
|
@@ -741,7 +676,7 @@ function MidenProvider({
|
|
|
741
676
|
currentStoreNameRef.current = signerContext.storeName;
|
|
742
677
|
} else {
|
|
743
678
|
const seed = resolvedConfig.seed;
|
|
744
|
-
webClient = await
|
|
679
|
+
webClient = await WebClient.createClient(
|
|
745
680
|
resolvedConfig.rpcUrl,
|
|
746
681
|
resolvedConfig.noteTransportUrl,
|
|
747
682
|
seed
|
|
@@ -810,7 +745,7 @@ function MidenProvider({
|
|
|
810
745
|
// signCb changes are handled by the dedicated useEffect + signCbRef above,
|
|
811
746
|
// not by this effect.
|
|
812
747
|
]);
|
|
813
|
-
|
|
748
|
+
useEffect(() => {
|
|
814
749
|
if (!isReady || !client) return;
|
|
815
750
|
const interval = config.autoSyncInterval ?? DEFAULTS.AUTO_SYNC_INTERVAL;
|
|
816
751
|
if (interval <= 0) return;
|
|
@@ -826,7 +761,7 @@ function MidenProvider({
|
|
|
826
761
|
}
|
|
827
762
|
};
|
|
828
763
|
}, [isReady, client, config.autoSyncInterval, sync]);
|
|
829
|
-
|
|
764
|
+
useEffect(() => {
|
|
830
765
|
if (!isReady || !client) return;
|
|
831
766
|
const unsubscribe = client.onStateChanged?.(async () => {
|
|
832
767
|
try {
|
|
@@ -841,13 +776,13 @@ function MidenProvider({
|
|
|
841
776
|
};
|
|
842
777
|
}, [isReady, client, setSyncState]);
|
|
843
778
|
if (isInitializing && loadingComponent) {
|
|
844
|
-
return /* @__PURE__ */
|
|
779
|
+
return /* @__PURE__ */ jsx(Fragment, { children: loadingComponent });
|
|
845
780
|
}
|
|
846
781
|
if (initError && errorComponent) {
|
|
847
782
|
if (typeof errorComponent === "function") {
|
|
848
|
-
return /* @__PURE__ */
|
|
783
|
+
return /* @__PURE__ */ jsx(Fragment, { children: errorComponent(initError) });
|
|
849
784
|
}
|
|
850
|
-
return /* @__PURE__ */
|
|
785
|
+
return /* @__PURE__ */ jsx(Fragment, { children: errorComponent });
|
|
851
786
|
}
|
|
852
787
|
const contextValue = {
|
|
853
788
|
client,
|
|
@@ -860,10 +795,10 @@ function MidenProvider({
|
|
|
860
795
|
signerAccountId,
|
|
861
796
|
signerConnected
|
|
862
797
|
};
|
|
863
|
-
return /* @__PURE__ */
|
|
798
|
+
return /* @__PURE__ */ jsx(MidenContext.Provider, { value: contextValue, children });
|
|
864
799
|
}
|
|
865
800
|
function useMiden() {
|
|
866
|
-
const context = (
|
|
801
|
+
const context = useContext2(MidenContext);
|
|
867
802
|
if (!context) {
|
|
868
803
|
throw new Error("useMiden must be used within a MidenProvider");
|
|
869
804
|
}
|
|
@@ -880,22 +815,30 @@ function useMidenClient() {
|
|
|
880
815
|
}
|
|
881
816
|
|
|
882
817
|
// src/context/MultiSignerProvider.tsx
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
818
|
+
import {
|
|
819
|
+
createContext as createContext3,
|
|
820
|
+
useContext as useContext3,
|
|
821
|
+
useEffect as useEffect2,
|
|
822
|
+
useRef as useRef2,
|
|
823
|
+
useState as useState2,
|
|
824
|
+
useCallback as useCallback2,
|
|
825
|
+
useMemo as useMemo2
|
|
826
|
+
} from "react";
|
|
827
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
828
|
+
var MultiSignerRegistryContext = createContext3(null);
|
|
829
|
+
var MultiSignerContext = createContext3(null);
|
|
887
830
|
function MultiSignerProvider({ children }) {
|
|
888
|
-
const signersRef = (
|
|
889
|
-
const [signersSnapshot, setSignersSnapshot] = (
|
|
831
|
+
const signersRef = useRef2(/* @__PURE__ */ new Map());
|
|
832
|
+
const [signersSnapshot, setSignersSnapshot] = useState2(
|
|
890
833
|
[]
|
|
891
834
|
);
|
|
892
|
-
const [activeSignerName, setActiveSignerName] = (
|
|
893
|
-
const activeSignerNameRef = (
|
|
894
|
-
const generationRef = (0
|
|
895
|
-
const updateSnapshot = (
|
|
835
|
+
const [activeSignerName, setActiveSignerName] = useState2(null);
|
|
836
|
+
const activeSignerNameRef = useRef2(null);
|
|
837
|
+
const generationRef = useRef2(0);
|
|
838
|
+
const updateSnapshot = useCallback2(() => {
|
|
896
839
|
setSignersSnapshot(Array.from(signersRef.current.values()));
|
|
897
840
|
}, []);
|
|
898
|
-
const register = (
|
|
841
|
+
const register = useCallback2(
|
|
899
842
|
(value) => {
|
|
900
843
|
const prev = signersRef.current.get(value.name);
|
|
901
844
|
signersRef.current.set(value.name, value);
|
|
@@ -905,7 +848,7 @@ function MultiSignerProvider({ children }) {
|
|
|
905
848
|
},
|
|
906
849
|
[updateSnapshot]
|
|
907
850
|
);
|
|
908
|
-
const unregister = (
|
|
851
|
+
const unregister = useCallback2(
|
|
909
852
|
(name) => {
|
|
910
853
|
signersRef.current.delete(name);
|
|
911
854
|
setActiveSignerName((current) => current === name ? null : current);
|
|
@@ -913,12 +856,15 @@ function MultiSignerProvider({ children }) {
|
|
|
913
856
|
},
|
|
914
857
|
[updateSnapshot]
|
|
915
858
|
);
|
|
916
|
-
const registry = (
|
|
859
|
+
const registry = useMemo2(
|
|
917
860
|
() => ({ register, unregister }),
|
|
918
861
|
[register, unregister]
|
|
919
862
|
);
|
|
920
|
-
const activeSigner = activeSignerName ?
|
|
921
|
-
|
|
863
|
+
const activeSigner = activeSignerName ? (
|
|
864
|
+
/* v8 ignore next 1 — ?? null fallback; find() returns undefined only when the signer was unregistered between renders */
|
|
865
|
+
signersSnapshot.find((s) => s.name === activeSignerName) ?? null
|
|
866
|
+
) : null;
|
|
867
|
+
const stableSignCb = useCallback2(
|
|
922
868
|
async (pubKey, signingInputs) => {
|
|
923
869
|
const name = activeSignerName;
|
|
924
870
|
if (!name) throw new Error("No active signer (signer was disconnected)");
|
|
@@ -928,21 +874,21 @@ function MultiSignerProvider({ children }) {
|
|
|
928
874
|
},
|
|
929
875
|
[activeSignerName]
|
|
930
876
|
);
|
|
931
|
-
const stableConnect = (
|
|
877
|
+
const stableConnect = useCallback2(async () => {
|
|
932
878
|
const name = activeSignerName;
|
|
933
879
|
if (!name) throw new Error("No active signer (signer was disconnected)");
|
|
934
880
|
const signer = signersRef.current.get(name);
|
|
935
881
|
if (!signer) throw new Error(`Signer "${name}" not found in registry`);
|
|
936
882
|
return signer.connect();
|
|
937
883
|
}, [activeSignerName]);
|
|
938
|
-
const stableDisconnect = (
|
|
884
|
+
const stableDisconnect = useCallback2(async () => {
|
|
939
885
|
const name = activeSignerName;
|
|
940
886
|
if (!name) throw new Error("No active signer (signer was disconnected)");
|
|
941
887
|
const signer = signersRef.current.get(name);
|
|
942
888
|
if (!signer) throw new Error(`Signer "${name}" not found in registry`);
|
|
943
889
|
return signer.disconnect();
|
|
944
890
|
}, [activeSignerName]);
|
|
945
|
-
const forwardedValue = (
|
|
891
|
+
const forwardedValue = useMemo2(() => {
|
|
946
892
|
if (!activeSigner) return null;
|
|
947
893
|
return {
|
|
948
894
|
name: activeSigner.name,
|
|
@@ -962,11 +908,11 @@ function MultiSignerProvider({ children }) {
|
|
|
962
908
|
stableConnect,
|
|
963
909
|
stableDisconnect
|
|
964
910
|
]);
|
|
965
|
-
const setActiveName = (
|
|
911
|
+
const setActiveName = useCallback2((name) => {
|
|
966
912
|
activeSignerNameRef.current = name;
|
|
967
913
|
setActiveSignerName(name);
|
|
968
914
|
}, []);
|
|
969
|
-
const connectSigner = (
|
|
915
|
+
const connectSigner = useCallback2(
|
|
970
916
|
async (name) => {
|
|
971
917
|
const currentName = activeSignerNameRef.current;
|
|
972
918
|
const currentSigner = currentName ? signersRef.current.get(currentName) : null;
|
|
@@ -991,7 +937,7 @@ function MultiSignerProvider({ children }) {
|
|
|
991
937
|
},
|
|
992
938
|
[setActiveName]
|
|
993
939
|
);
|
|
994
|
-
const disconnectSigner = (
|
|
940
|
+
const disconnectSigner = useCallback2(async () => {
|
|
995
941
|
++generationRef.current;
|
|
996
942
|
const currentName = activeSignerNameRef.current;
|
|
997
943
|
const signer = currentName ? signersRef.current.get(currentName) : null;
|
|
@@ -1002,7 +948,7 @@ function MultiSignerProvider({ children }) {
|
|
|
1002
948
|
});
|
|
1003
949
|
}
|
|
1004
950
|
}, [setActiveName]);
|
|
1005
|
-
const multiSignerValue = (
|
|
951
|
+
const multiSignerValue = useMemo2(
|
|
1006
952
|
() => ({
|
|
1007
953
|
signers: signersSnapshot,
|
|
1008
954
|
activeSigner,
|
|
@@ -1011,18 +957,18 @@ function MultiSignerProvider({ children }) {
|
|
|
1011
957
|
}),
|
|
1012
958
|
[signersSnapshot, activeSigner, connectSigner, disconnectSigner]
|
|
1013
959
|
);
|
|
1014
|
-
return /* @__PURE__ */ (
|
|
960
|
+
return /* @__PURE__ */ jsx2(SignerContext.Provider, { value: forwardedValue, children: /* @__PURE__ */ jsx2(MultiSignerRegistryContext.Provider, { value: registry, children: /* @__PURE__ */ jsx2(MultiSignerContext.Provider, { value: multiSignerValue, children }) }) });
|
|
1015
961
|
}
|
|
1016
962
|
function SignerSlot() {
|
|
1017
963
|
const signerValue = useSigner();
|
|
1018
|
-
const registry = (
|
|
1019
|
-
const nameRef = (
|
|
1020
|
-
(
|
|
964
|
+
const registry = useContext3(MultiSignerRegistryContext);
|
|
965
|
+
const nameRef = useRef2();
|
|
966
|
+
useEffect2(() => {
|
|
1021
967
|
if (!signerValue || !registry) return;
|
|
1022
968
|
nameRef.current = signerValue.name;
|
|
1023
969
|
registry.register(signerValue);
|
|
1024
970
|
}, [signerValue, registry]);
|
|
1025
|
-
(
|
|
971
|
+
useEffect2(() => {
|
|
1026
972
|
return () => {
|
|
1027
973
|
if (nameRef.current && registry) {
|
|
1028
974
|
registry.unregister(nameRef.current);
|
|
@@ -1032,18 +978,18 @@ function SignerSlot() {
|
|
|
1032
978
|
return null;
|
|
1033
979
|
}
|
|
1034
980
|
function useMultiSigner() {
|
|
1035
|
-
return (
|
|
981
|
+
return useContext3(MultiSignerContext);
|
|
1036
982
|
}
|
|
1037
983
|
|
|
1038
984
|
// src/hooks/useAccounts.ts
|
|
1039
|
-
|
|
985
|
+
import { useCallback as useCallback3, useEffect as useEffect3 } from "react";
|
|
1040
986
|
function useAccounts() {
|
|
1041
987
|
const { client, isReady } = useMiden();
|
|
1042
988
|
const accounts = useAccountsStore();
|
|
1043
989
|
const isLoadingAccounts = useMidenStore((state) => state.isLoadingAccounts);
|
|
1044
990
|
const setLoadingAccounts = useMidenStore((state) => state.setLoadingAccounts);
|
|
1045
991
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1046
|
-
const refetch = (
|
|
992
|
+
const refetch = useCallback3(async () => {
|
|
1047
993
|
if (!client || !isReady) return;
|
|
1048
994
|
setLoadingAccounts(true);
|
|
1049
995
|
try {
|
|
@@ -1055,7 +1001,7 @@ function useAccounts() {
|
|
|
1055
1001
|
setLoadingAccounts(false);
|
|
1056
1002
|
}
|
|
1057
1003
|
}, [client, isReady, setAccounts, setLoadingAccounts]);
|
|
1058
|
-
(
|
|
1004
|
+
useEffect3(() => {
|
|
1059
1005
|
if (isReady && accounts.length === 0) {
|
|
1060
1006
|
refetch();
|
|
1061
1007
|
}
|
|
@@ -1081,11 +1027,15 @@ function useAccounts() {
|
|
|
1081
1027
|
}
|
|
1082
1028
|
|
|
1083
1029
|
// src/hooks/useAccount.ts
|
|
1084
|
-
|
|
1030
|
+
import { useCallback as useCallback4, useEffect as useEffect5, useState as useState3, useMemo as useMemo4 } from "react";
|
|
1085
1031
|
|
|
1086
1032
|
// src/hooks/useAssetMetadata.ts
|
|
1087
|
-
|
|
1088
|
-
|
|
1033
|
+
import { useEffect as useEffect4, useMemo as useMemo3 } from "react";
|
|
1034
|
+
import {
|
|
1035
|
+
BasicFungibleFaucetComponent,
|
|
1036
|
+
Endpoint,
|
|
1037
|
+
RpcClient
|
|
1038
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1089
1039
|
var inflight = /* @__PURE__ */ new Map();
|
|
1090
1040
|
var rpcClients = /* @__PURE__ */ new Map();
|
|
1091
1041
|
var getRpcClient = (rpcUrl) => {
|
|
@@ -1093,8 +1043,8 @@ var getRpcClient = (rpcUrl) => {
|
|
|
1093
1043
|
const existing = rpcClients.get(key);
|
|
1094
1044
|
if (existing) return existing;
|
|
1095
1045
|
try {
|
|
1096
|
-
const endpoint = rpcUrl ? new
|
|
1097
|
-
const client = new
|
|
1046
|
+
const endpoint = rpcUrl ? new Endpoint(rpcUrl) : Endpoint.testnet();
|
|
1047
|
+
const client = new RpcClient(endpoint);
|
|
1098
1048
|
rpcClients.set(key, client);
|
|
1099
1049
|
return client;
|
|
1100
1050
|
} catch {
|
|
@@ -1108,7 +1058,7 @@ var fetchAssetMetadata = async (rpcClient, assetId) => {
|
|
|
1108
1058
|
const fetched = await rpcClient.getAccountDetails(accountId);
|
|
1109
1059
|
const account = fetched.account?.();
|
|
1110
1060
|
if (!account) return null;
|
|
1111
|
-
const faucet =
|
|
1061
|
+
const faucet = BasicFungibleFaucetComponent.fromAccount(account);
|
|
1112
1062
|
const symbol = faucet.symbol().toString();
|
|
1113
1063
|
const decimals = faucet.decimals();
|
|
1114
1064
|
return { assetId, symbol, decimals };
|
|
@@ -1120,12 +1070,12 @@ function useAssetMetadata(assetIds = []) {
|
|
|
1120
1070
|
const assetMetadata = useAssetMetadataStore();
|
|
1121
1071
|
const setAssetMetadata = useMidenStore((state) => state.setAssetMetadata);
|
|
1122
1072
|
const rpcUrl = useMidenStore((state) => state.config.rpcUrl);
|
|
1123
|
-
const rpcClient = (
|
|
1124
|
-
const uniqueAssetIds = (
|
|
1073
|
+
const rpcClient = useMemo3(() => getRpcClient(rpcUrl), [rpcUrl]);
|
|
1074
|
+
const uniqueAssetIds = useMemo3(
|
|
1125
1075
|
() => Array.from(new Set(assetIds.filter(Boolean))),
|
|
1126
1076
|
[assetIds]
|
|
1127
1077
|
);
|
|
1128
|
-
(
|
|
1078
|
+
useEffect4(() => {
|
|
1129
1079
|
if (!rpcClient || uniqueAssetIds.length === 0) return;
|
|
1130
1080
|
uniqueAssetIds.forEach((assetId) => {
|
|
1131
1081
|
const existing = assetMetadata.get(assetId);
|
|
@@ -1148,15 +1098,15 @@ function useAccount(accountId) {
|
|
|
1148
1098
|
const accountDetails = useMidenStore((state) => state.accountDetails);
|
|
1149
1099
|
const setAccountDetails = useMidenStore((state) => state.setAccountDetails);
|
|
1150
1100
|
const { lastSyncTime } = useSyncStateStore();
|
|
1151
|
-
const [isLoading, setIsLoading] = (
|
|
1152
|
-
const [error, setError] = (
|
|
1153
|
-
const accountIdStr = (
|
|
1101
|
+
const [isLoading, setIsLoading] = useState3(false);
|
|
1102
|
+
const [error, setError] = useState3(null);
|
|
1103
|
+
const accountIdStr = useMemo4(() => {
|
|
1154
1104
|
if (!accountId) return void 0;
|
|
1155
1105
|
if (typeof accountId === "string") return accountId;
|
|
1156
1106
|
return parseAccountId(accountId).toString();
|
|
1157
1107
|
}, [accountId]);
|
|
1158
1108
|
const account = accountIdStr ? accountDetails.get(accountIdStr) ?? null : null;
|
|
1159
|
-
const refetch = (
|
|
1109
|
+
const refetch = useCallback4(async () => {
|
|
1160
1110
|
if (!client || !isReady || !accountIdStr) return;
|
|
1161
1111
|
setIsLoading(true);
|
|
1162
1112
|
setError(null);
|
|
@@ -1173,16 +1123,16 @@ function useAccount(accountId) {
|
|
|
1173
1123
|
setIsLoading(false);
|
|
1174
1124
|
}
|
|
1175
1125
|
}, [client, isReady, accountIdStr, setAccountDetails]);
|
|
1176
|
-
(
|
|
1126
|
+
useEffect5(() => {
|
|
1177
1127
|
if (isReady && accountIdStr && !account) {
|
|
1178
1128
|
refetch();
|
|
1179
1129
|
}
|
|
1180
1130
|
}, [isReady, accountIdStr, account, refetch]);
|
|
1181
|
-
(
|
|
1131
|
+
useEffect5(() => {
|
|
1182
1132
|
if (!isReady || !accountIdStr || !lastSyncTime) return;
|
|
1183
1133
|
refetch();
|
|
1184
1134
|
}, [isReady, accountIdStr, lastSyncTime, refetch]);
|
|
1185
|
-
const rawAssets = (
|
|
1135
|
+
const rawAssets = useMemo4(() => {
|
|
1186
1136
|
if (!account) return [];
|
|
1187
1137
|
try {
|
|
1188
1138
|
const vault = account.vault();
|
|
@@ -1199,12 +1149,12 @@ function useAccount(accountId) {
|
|
|
1199
1149
|
return [];
|
|
1200
1150
|
}
|
|
1201
1151
|
}, [account]);
|
|
1202
|
-
const assetIds = (
|
|
1152
|
+
const assetIds = useMemo4(
|
|
1203
1153
|
() => rawAssets.map((asset) => asset.assetId),
|
|
1204
1154
|
[rawAssets]
|
|
1205
1155
|
);
|
|
1206
1156
|
const { assetMetadata } = useAssetMetadata(assetIds);
|
|
1207
|
-
const assets = (
|
|
1157
|
+
const assets = useMemo4(
|
|
1208
1158
|
() => rawAssets.map((asset) => {
|
|
1209
1159
|
const metadata = assetMetadata.get(asset.assetId);
|
|
1210
1160
|
return {
|
|
@@ -1215,7 +1165,7 @@ function useAccount(accountId) {
|
|
|
1215
1165
|
}),
|
|
1216
1166
|
[rawAssets, assetMetadata]
|
|
1217
1167
|
);
|
|
1218
|
-
const getBalance = (
|
|
1168
|
+
const getBalance = useCallback4(
|
|
1219
1169
|
(assetId) => {
|
|
1220
1170
|
const asset = assets.find((a) => a.assetId === assetId);
|
|
1221
1171
|
return asset?.amount ?? 0n;
|
|
@@ -1233,8 +1183,8 @@ function useAccount(accountId) {
|
|
|
1233
1183
|
}
|
|
1234
1184
|
|
|
1235
1185
|
// src/hooks/useNotes.ts
|
|
1236
|
-
|
|
1237
|
-
|
|
1186
|
+
import { useCallback as useCallback5, useEffect as useEffect6, useMemo as useMemo5, useState as useState4 } from "react";
|
|
1187
|
+
import { NoteFilter } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1238
1188
|
|
|
1239
1189
|
// src/utils/amounts.ts
|
|
1240
1190
|
var formatAssetAmount = (amount, decimals) => {
|
|
@@ -1339,30 +1289,35 @@ function accountIdsEqual(a, b) {
|
|
|
1339
1289
|
}
|
|
1340
1290
|
|
|
1341
1291
|
// src/utils/noteFilters.ts
|
|
1342
|
-
|
|
1292
|
+
import {
|
|
1293
|
+
NoteFilterTypes,
|
|
1294
|
+
NoteType,
|
|
1295
|
+
TransactionFilter
|
|
1296
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1343
1297
|
function getNoteFilterType(status) {
|
|
1344
1298
|
switch (status) {
|
|
1345
1299
|
case "consumed":
|
|
1346
|
-
return
|
|
1300
|
+
return NoteFilterTypes.Consumed;
|
|
1347
1301
|
case "committed":
|
|
1348
|
-
return
|
|
1302
|
+
return NoteFilterTypes.Committed;
|
|
1349
1303
|
case "expected":
|
|
1350
|
-
return
|
|
1304
|
+
return NoteFilterTypes.Expected;
|
|
1351
1305
|
case "processing":
|
|
1352
|
-
return
|
|
1306
|
+
return NoteFilterTypes.Processing;
|
|
1353
1307
|
case "all":
|
|
1354
1308
|
default:
|
|
1355
|
-
return
|
|
1309
|
+
return NoteFilterTypes.All;
|
|
1356
1310
|
}
|
|
1357
1311
|
}
|
|
1358
1312
|
function getNoteType(type) {
|
|
1359
1313
|
switch (type) {
|
|
1360
1314
|
case "private":
|
|
1361
|
-
return
|
|
1315
|
+
return NoteType.Private;
|
|
1362
1316
|
case "public":
|
|
1363
|
-
return
|
|
1317
|
+
return NoteType.Public;
|
|
1318
|
+
/* v8 ignore next 2 — TypeScript type ensures only "private"|"public"; default is unreachable */
|
|
1364
1319
|
default:
|
|
1365
|
-
return
|
|
1320
|
+
return NoteType.Private;
|
|
1366
1321
|
}
|
|
1367
1322
|
}
|
|
1368
1323
|
async function waitForTransactionCommit(client, runExclusiveSafe, txIdHex, maxWaitMs = 1e4, delayMs = 1e3) {
|
|
@@ -1371,7 +1326,7 @@ async function waitForTransactionCommit(client, runExclusiveSafe, txIdHex, maxWa
|
|
|
1371
1326
|
while (Date.now() < deadline) {
|
|
1372
1327
|
await runExclusiveSafe(() => client.syncState());
|
|
1373
1328
|
const records = await runExclusiveSafe(
|
|
1374
|
-
() => client.getTransactions(
|
|
1329
|
+
() => client.getTransactions(TransactionFilter.all())
|
|
1375
1330
|
);
|
|
1376
1331
|
const record = records.find(
|
|
1377
1332
|
(r) => normalizeHex(r.id().toHex()) === targetHex
|
|
@@ -1407,14 +1362,14 @@ function useNotes(options) {
|
|
|
1407
1362
|
(state) => state.setConsumableNotesIfChanged
|
|
1408
1363
|
);
|
|
1409
1364
|
const { lastSyncTime } = useSyncStateStore();
|
|
1410
|
-
const [error, setError] = (
|
|
1411
|
-
const refetch = (
|
|
1365
|
+
const [error, setError] = useState4(null);
|
|
1366
|
+
const refetch = useCallback5(async () => {
|
|
1412
1367
|
if (!client || !isReady) return;
|
|
1413
1368
|
setLoadingNotes(true);
|
|
1414
1369
|
setError(null);
|
|
1415
1370
|
try {
|
|
1416
1371
|
const filterType = getNoteFilterType(options?.status);
|
|
1417
|
-
const filter = new
|
|
1372
|
+
const filter = new NoteFilter(filterType);
|
|
1418
1373
|
const fetchedNotes = await client.getInputNotes(filter);
|
|
1419
1374
|
let fetchedConsumable;
|
|
1420
1375
|
if (options?.accountId) {
|
|
@@ -1439,16 +1394,16 @@ function useNotes(options) {
|
|
|
1439
1394
|
setNotesIfChanged,
|
|
1440
1395
|
setConsumableNotesIfChanged
|
|
1441
1396
|
]);
|
|
1442
|
-
(
|
|
1397
|
+
useEffect6(() => {
|
|
1443
1398
|
if (isReady && notes.length === 0) {
|
|
1444
1399
|
refetch();
|
|
1445
1400
|
}
|
|
1446
1401
|
}, [isReady, notes.length, refetch]);
|
|
1447
|
-
(
|
|
1402
|
+
useEffect6(() => {
|
|
1448
1403
|
if (!isReady || !lastSyncTime) return;
|
|
1449
1404
|
refetch();
|
|
1450
1405
|
}, [isReady, lastSyncTime, refetch]);
|
|
1451
|
-
const noteAssetIds = (
|
|
1406
|
+
const noteAssetIds = useMemo5(() => {
|
|
1452
1407
|
const ids = /* @__PURE__ */ new Set();
|
|
1453
1408
|
const collect = (note) => {
|
|
1454
1409
|
const summary = getNoteSummary(note);
|
|
@@ -1460,11 +1415,11 @@ function useNotes(options) {
|
|
|
1460
1415
|
return Array.from(ids);
|
|
1461
1416
|
}, [notes, consumableNotes]);
|
|
1462
1417
|
const { assetMetadata } = useAssetMetadata(noteAssetIds);
|
|
1463
|
-
const getMetadata = (
|
|
1418
|
+
const getMetadata = useCallback5(
|
|
1464
1419
|
(assetId) => assetMetadata.get(assetId),
|
|
1465
1420
|
[assetMetadata]
|
|
1466
1421
|
);
|
|
1467
|
-
const normalizedSender = (
|
|
1422
|
+
const normalizedSender = useMemo5(() => {
|
|
1468
1423
|
if (!options?.sender) return null;
|
|
1469
1424
|
try {
|
|
1470
1425
|
return normalizeAccountId(options.sender);
|
|
@@ -1472,11 +1427,11 @@ function useNotes(options) {
|
|
|
1472
1427
|
return options.sender;
|
|
1473
1428
|
}
|
|
1474
1429
|
}, [options?.sender]);
|
|
1475
|
-
const excludeIdsKey = (
|
|
1430
|
+
const excludeIdsKey = useMemo5(() => {
|
|
1476
1431
|
if (!options?.excludeIds || options.excludeIds.length === 0) return "";
|
|
1477
1432
|
return [...options.excludeIds].sort().join("\0");
|
|
1478
1433
|
}, [options?.excludeIds]);
|
|
1479
|
-
const filterBySender = (
|
|
1434
|
+
const filterBySender = useCallback5(
|
|
1480
1435
|
(summaries, target) => {
|
|
1481
1436
|
const cache = /* @__PURE__ */ new Map();
|
|
1482
1437
|
return summaries.filter((s) => {
|
|
@@ -1495,7 +1450,7 @@ function useNotes(options) {
|
|
|
1495
1450
|
},
|
|
1496
1451
|
[]
|
|
1497
1452
|
);
|
|
1498
|
-
const noteSummaries = (
|
|
1453
|
+
const noteSummaries = useMemo5(() => {
|
|
1499
1454
|
let summaries = notes.map((note) => getNoteSummary(note, getMetadata)).filter(Boolean);
|
|
1500
1455
|
if (normalizedSender) {
|
|
1501
1456
|
summaries = filterBySender(summaries, normalizedSender);
|
|
@@ -1506,7 +1461,7 @@ function useNotes(options) {
|
|
|
1506
1461
|
}
|
|
1507
1462
|
return summaries;
|
|
1508
1463
|
}, [notes, getMetadata, normalizedSender, excludeIdsKey, filterBySender]);
|
|
1509
|
-
const consumableNoteSummaries = (
|
|
1464
|
+
const consumableNoteSummaries = useMemo5(() => {
|
|
1510
1465
|
let summaries = consumableNotes.map((note) => getNoteSummary(note, getMetadata)).filter(Boolean);
|
|
1511
1466
|
if (normalizedSender) {
|
|
1512
1467
|
summaries = filterBySender(summaries, normalizedSender);
|
|
@@ -1535,11 +1490,16 @@ function useNotes(options) {
|
|
|
1535
1490
|
}
|
|
1536
1491
|
|
|
1537
1492
|
// src/hooks/useNoteStream.ts
|
|
1538
|
-
|
|
1539
|
-
|
|
1493
|
+
import { useCallback as useCallback6, useEffect as useEffect7, useMemo as useMemo6, useRef as useRef3, useState as useState5 } from "react";
|
|
1494
|
+
import { NoteFilter as NoteFilter2 } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1540
1495
|
|
|
1541
1496
|
// src/utils/noteAttachment.ts
|
|
1542
|
-
|
|
1497
|
+
import {
|
|
1498
|
+
NoteAttachment,
|
|
1499
|
+
NoteAttachmentKind,
|
|
1500
|
+
NoteAttachmentScheme,
|
|
1501
|
+
Word
|
|
1502
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1543
1503
|
function readNoteAttachment(note) {
|
|
1544
1504
|
try {
|
|
1545
1505
|
const metadata = note.metadata?.();
|
|
@@ -1548,8 +1508,8 @@ function readNoteAttachment(note) {
|
|
|
1548
1508
|
if (!attachment) return null;
|
|
1549
1509
|
const kind = attachment.kind?.();
|
|
1550
1510
|
if (!kind) return null;
|
|
1551
|
-
if (kind ===
|
|
1552
|
-
if (kind ===
|
|
1511
|
+
if (kind === NoteAttachmentKind.None) return null;
|
|
1512
|
+
if (kind === NoteAttachmentKind.Word) {
|
|
1553
1513
|
const word = attachment.asWord?.();
|
|
1554
1514
|
if (!word) return null;
|
|
1555
1515
|
const u64s = word.toU64s();
|
|
@@ -1558,7 +1518,7 @@ function readNoteAttachment(note) {
|
|
|
1558
1518
|
);
|
|
1559
1519
|
return { values, kind: "word" };
|
|
1560
1520
|
}
|
|
1561
|
-
if (kind ===
|
|
1521
|
+
if (kind === NoteAttachmentKind.Array) {
|
|
1562
1522
|
const arr = attachment.asArray?.();
|
|
1563
1523
|
if (!arr) return null;
|
|
1564
1524
|
const u64s = arr.toU64s();
|
|
@@ -1578,30 +1538,30 @@ function createNoteAttachment(values) {
|
|
|
1578
1538
|
bigints.push(BigInt(values[i]));
|
|
1579
1539
|
}
|
|
1580
1540
|
if (bigints.length === 0) {
|
|
1581
|
-
return new
|
|
1541
|
+
return new NoteAttachment();
|
|
1582
1542
|
}
|
|
1583
|
-
const scheme =
|
|
1543
|
+
const scheme = NoteAttachmentScheme.none();
|
|
1584
1544
|
if (bigints.length <= 4) {
|
|
1585
1545
|
while (bigints.length < 4) {
|
|
1586
1546
|
bigints.push(0n);
|
|
1587
1547
|
}
|
|
1588
|
-
const word = new
|
|
1589
|
-
return
|
|
1548
|
+
const word = new Word(BigUint64Array.from(bigints));
|
|
1549
|
+
return NoteAttachment.newWord(scheme, word);
|
|
1590
1550
|
}
|
|
1591
1551
|
while (bigints.length % 4 !== 0) {
|
|
1592
1552
|
bigints.push(0n);
|
|
1593
1553
|
}
|
|
1594
1554
|
const words = [];
|
|
1595
1555
|
for (let i = 0; i < bigints.length; i += 4) {
|
|
1596
|
-
words.push(new
|
|
1556
|
+
words.push(new Word(BigUint64Array.from(bigints.slice(i, i + 4))));
|
|
1597
1557
|
}
|
|
1598
|
-
const newArray =
|
|
1558
|
+
const newArray = NoteAttachment["newArray"];
|
|
1599
1559
|
if (typeof newArray !== "function") {
|
|
1600
1560
|
throw new Error(
|
|
1601
1561
|
"NoteAttachment.newArray is not available. Ensure @miden-sdk/miden-sdk >= 0.13.1."
|
|
1602
1562
|
);
|
|
1603
1563
|
}
|
|
1604
|
-
return newArray.call(
|
|
1564
|
+
return newArray.call(NoteAttachment, scheme, words);
|
|
1605
1565
|
}
|
|
1606
1566
|
|
|
1607
1567
|
// src/hooks/useNoteStream.ts
|
|
@@ -1611,32 +1571,32 @@ function useNoteStream(options = {}) {
|
|
|
1611
1571
|
const noteFirstSeen = useNoteFirstSeenStore();
|
|
1612
1572
|
const { lastSyncTime } = useSyncStateStore();
|
|
1613
1573
|
const setNotesIfChanged = useMidenStore((state) => state.setNotesIfChanged);
|
|
1614
|
-
const [isLoading, setIsLoading] = (
|
|
1615
|
-
const [error, setError] = (
|
|
1616
|
-
const handledIdsRef = (
|
|
1617
|
-
const [handledVersion, setHandledVersion] = (0
|
|
1574
|
+
const [isLoading, setIsLoading] = useState5(false);
|
|
1575
|
+
const [error, setError] = useState5(null);
|
|
1576
|
+
const handledIdsRef = useRef3(/* @__PURE__ */ new Set());
|
|
1577
|
+
const [handledVersion, setHandledVersion] = useState5(0);
|
|
1618
1578
|
const status = options.status ?? "committed";
|
|
1619
1579
|
const sender = options.sender ?? null;
|
|
1620
1580
|
const since = options.since;
|
|
1621
|
-
const amountFilterRef = (
|
|
1581
|
+
const amountFilterRef = useRef3(options.amountFilter);
|
|
1622
1582
|
amountFilterRef.current = options.amountFilter;
|
|
1623
|
-
const excludeIdsKey = (
|
|
1583
|
+
const excludeIdsKey = useMemo6(() => {
|
|
1624
1584
|
if (!options.excludeIds) return "";
|
|
1625
1585
|
if (options.excludeIds instanceof Set)
|
|
1626
1586
|
return Array.from(options.excludeIds).sort().join("\0");
|
|
1627
1587
|
return [...options.excludeIds].sort().join("\0");
|
|
1628
1588
|
}, [options.excludeIds]);
|
|
1629
|
-
const excludeIdSet = (
|
|
1589
|
+
const excludeIdSet = useMemo6(() => {
|
|
1630
1590
|
if (!excludeIdsKey) return null;
|
|
1631
1591
|
return new Set(excludeIdsKey.split("\0"));
|
|
1632
1592
|
}, [excludeIdsKey]);
|
|
1633
|
-
const refetch = (
|
|
1593
|
+
const refetch = useCallback6(async () => {
|
|
1634
1594
|
if (!client || !isReady) return;
|
|
1635
1595
|
setIsLoading(true);
|
|
1636
1596
|
setError(null);
|
|
1637
1597
|
try {
|
|
1638
1598
|
const filterType = getNoteFilterType(status);
|
|
1639
|
-
const filter = new
|
|
1599
|
+
const filter = new NoteFilter2(filterType);
|
|
1640
1600
|
const fetched = await client.getInputNotes(filter);
|
|
1641
1601
|
setNotesIfChanged(fetched);
|
|
1642
1602
|
} catch (err) {
|
|
@@ -1645,12 +1605,12 @@ function useNoteStream(options = {}) {
|
|
|
1645
1605
|
setIsLoading(false);
|
|
1646
1606
|
}
|
|
1647
1607
|
}, [client, isReady, status, setNotesIfChanged]);
|
|
1648
|
-
(
|
|
1608
|
+
useEffect7(() => {
|
|
1649
1609
|
if (isReady) {
|
|
1650
1610
|
refetch();
|
|
1651
1611
|
}
|
|
1652
1612
|
}, [isReady, lastSyncTime, refetch]);
|
|
1653
|
-
const streamedNotes = (
|
|
1613
|
+
const streamedNotes = useMemo6(() => {
|
|
1654
1614
|
void handledVersion;
|
|
1655
1615
|
const result = [];
|
|
1656
1616
|
let normalizedSender = null;
|
|
@@ -1675,15 +1635,15 @@ function useNoteStream(options = {}) {
|
|
|
1675
1635
|
result.sort((a, b) => a.firstSeenAt - b.firstSeenAt);
|
|
1676
1636
|
return result;
|
|
1677
1637
|
}, [allNotes, noteFirstSeen, excludeIdSet, sender, since, handledVersion]);
|
|
1678
|
-
const latest = (
|
|
1638
|
+
const latest = useMemo6(
|
|
1679
1639
|
() => streamedNotes.length > 0 ? streamedNotes[streamedNotes.length - 1] : null,
|
|
1680
1640
|
[streamedNotes]
|
|
1681
1641
|
);
|
|
1682
|
-
const markHandled = (
|
|
1642
|
+
const markHandled = useCallback6((noteId) => {
|
|
1683
1643
|
handledIdsRef.current = new Set(handledIdsRef.current).add(noteId);
|
|
1684
1644
|
setHandledVersion((v) => v + 1);
|
|
1685
1645
|
}, []);
|
|
1686
|
-
const markAllHandled = (
|
|
1646
|
+
const markAllHandled = useCallback6(() => {
|
|
1687
1647
|
const newSet = new Set(handledIdsRef.current);
|
|
1688
1648
|
for (const note of streamedNotes) {
|
|
1689
1649
|
newSet.add(note.id);
|
|
@@ -1691,7 +1651,7 @@ function useNoteStream(options = {}) {
|
|
|
1691
1651
|
handledIdsRef.current = newSet;
|
|
1692
1652
|
setHandledVersion((v) => v + 1);
|
|
1693
1653
|
}, [streamedNotes]);
|
|
1694
|
-
const snapshot = (
|
|
1654
|
+
const snapshot = useCallback6(() => {
|
|
1695
1655
|
const ids = /* @__PURE__ */ new Set();
|
|
1696
1656
|
for (const note of streamedNotes) {
|
|
1697
1657
|
ids.add(note.id);
|
|
@@ -1747,20 +1707,20 @@ function buildStreamedNote(record, noteFirstSeen) {
|
|
|
1747
1707
|
}
|
|
1748
1708
|
|
|
1749
1709
|
// src/hooks/useTransactionHistory.ts
|
|
1750
|
-
|
|
1751
|
-
|
|
1710
|
+
import { useCallback as useCallback7, useEffect as useEffect8, useMemo as useMemo7, useState as useState6 } from "react";
|
|
1711
|
+
import { TransactionFilter as TransactionFilter2 } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1752
1712
|
function useTransactionHistory(options = {}) {
|
|
1753
1713
|
const { client, isReady } = useMiden();
|
|
1754
1714
|
const { lastSyncTime } = useSyncStateStore();
|
|
1755
|
-
const [records, setRecords] = (
|
|
1756
|
-
const [isLoading, setIsLoading] = (
|
|
1757
|
-
const [error, setError] = (
|
|
1758
|
-
const rawIds = (
|
|
1715
|
+
const [records, setRecords] = useState6([]);
|
|
1716
|
+
const [isLoading, setIsLoading] = useState6(false);
|
|
1717
|
+
const [error, setError] = useState6(null);
|
|
1718
|
+
const rawIds = useMemo7(() => {
|
|
1759
1719
|
if (options.id) return [options.id];
|
|
1760
1720
|
if (options.ids && options.ids.length > 0) return options.ids;
|
|
1761
1721
|
return null;
|
|
1762
1722
|
}, [options.id, options.ids]);
|
|
1763
|
-
const idsHex = (
|
|
1723
|
+
const idsHex = useMemo7(() => {
|
|
1764
1724
|
if (!rawIds) return null;
|
|
1765
1725
|
return rawIds.map(
|
|
1766
1726
|
(id) => normalizeHex2(typeof id === "string" ? id : id.toHex())
|
|
@@ -1768,7 +1728,7 @@ function useTransactionHistory(options = {}) {
|
|
|
1768
1728
|
}, [rawIds]);
|
|
1769
1729
|
const filter = options.filter;
|
|
1770
1730
|
const refreshOnSync = options.refreshOnSync !== false;
|
|
1771
|
-
const refetch = (
|
|
1731
|
+
const refetch = useCallback7(async () => {
|
|
1772
1732
|
if (!client || !isReady) return;
|
|
1773
1733
|
setIsLoading(true);
|
|
1774
1734
|
setError(null);
|
|
@@ -1789,19 +1749,19 @@ function useTransactionHistory(options = {}) {
|
|
|
1789
1749
|
setIsLoading(false);
|
|
1790
1750
|
}
|
|
1791
1751
|
}, [client, isReady, filter, rawIds, idsHex]);
|
|
1792
|
-
(
|
|
1752
|
+
useEffect8(() => {
|
|
1793
1753
|
if (!isReady) return;
|
|
1794
1754
|
refetch();
|
|
1795
1755
|
}, [isReady, refetch]);
|
|
1796
|
-
(
|
|
1756
|
+
useEffect8(() => {
|
|
1797
1757
|
if (!isReady || !refreshOnSync || !lastSyncTime) return;
|
|
1798
1758
|
refetch();
|
|
1799
1759
|
}, [isReady, lastSyncTime, refreshOnSync, refetch]);
|
|
1800
|
-
const record = (
|
|
1760
|
+
const record = useMemo7(() => {
|
|
1801
1761
|
if (!idsHex || idsHex.length !== 1) return null;
|
|
1802
1762
|
return records.find((item) => normalizeHex2(item.id().toHex()) === idsHex[0]) ?? null;
|
|
1803
1763
|
}, [records, idsHex]);
|
|
1804
|
-
const status = (
|
|
1764
|
+
const status = useMemo7(() => {
|
|
1805
1765
|
if (!record) return null;
|
|
1806
1766
|
const current = record.transactionStatus();
|
|
1807
1767
|
if (current.isCommitted()) return "committed";
|
|
@@ -1823,14 +1783,15 @@ function buildFilter(filter, ids, idsHex) {
|
|
|
1823
1783
|
return { filter };
|
|
1824
1784
|
}
|
|
1825
1785
|
if (!ids || ids.length === 0) {
|
|
1826
|
-
return { filter:
|
|
1786
|
+
return { filter: TransactionFilter2.all() };
|
|
1827
1787
|
}
|
|
1828
1788
|
const allTransactionIds = ids.every((id) => typeof id !== "string");
|
|
1829
1789
|
if (allTransactionIds) {
|
|
1830
|
-
return { filter:
|
|
1790
|
+
return { filter: TransactionFilter2.ids(ids) };
|
|
1831
1791
|
}
|
|
1832
1792
|
return {
|
|
1833
|
-
filter:
|
|
1793
|
+
filter: TransactionFilter2.all(),
|
|
1794
|
+
/* v8 ignore next 1 — idsHex is always non-null when ids is non-empty; ?? [] is a safety net */
|
|
1834
1795
|
localFilterHexes: idsHex ?? []
|
|
1835
1796
|
};
|
|
1836
1797
|
}
|
|
@@ -1841,11 +1802,11 @@ function normalizeHex2(value) {
|
|
|
1841
1802
|
}
|
|
1842
1803
|
|
|
1843
1804
|
// src/hooks/useSyncState.ts
|
|
1844
|
-
|
|
1805
|
+
import { useCallback as useCallback8 } from "react";
|
|
1845
1806
|
function useSyncState() {
|
|
1846
1807
|
const { sync: triggerSync } = useMiden();
|
|
1847
1808
|
const syncState = useSyncStateStore();
|
|
1848
|
-
const sync = (
|
|
1809
|
+
const sync = useCallback8(async () => {
|
|
1849
1810
|
await triggerSync();
|
|
1850
1811
|
}, [triggerSync]);
|
|
1851
1812
|
return {
|
|
@@ -1855,8 +1816,11 @@ function useSyncState() {
|
|
|
1855
1816
|
}
|
|
1856
1817
|
|
|
1857
1818
|
// src/hooks/useCreateWallet.ts
|
|
1858
|
-
|
|
1859
|
-
|
|
1819
|
+
import { useCallback as useCallback9, useState as useState7 } from "react";
|
|
1820
|
+
import {
|
|
1821
|
+
AccountStorageMode,
|
|
1822
|
+
resolveAuthScheme
|
|
1823
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1860
1824
|
|
|
1861
1825
|
// src/utils/runExclusive.ts
|
|
1862
1826
|
var runExclusiveDirect = async (fn) => fn();
|
|
@@ -1866,10 +1830,10 @@ function useCreateWallet() {
|
|
|
1866
1830
|
const { client, isReady, runExclusive } = useMiden();
|
|
1867
1831
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1868
1832
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1869
|
-
const [wallet, setWallet] = (
|
|
1870
|
-
const [isCreating, setIsCreating] = (
|
|
1871
|
-
const [error, setError] = (
|
|
1872
|
-
const createWallet = (
|
|
1833
|
+
const [wallet, setWallet] = useState7(null);
|
|
1834
|
+
const [isCreating, setIsCreating] = useState7(false);
|
|
1835
|
+
const [error, setError] = useState7(null);
|
|
1836
|
+
const createWallet = useCallback9(
|
|
1873
1837
|
async (options = {}) => {
|
|
1874
1838
|
if (!client || !isReady) {
|
|
1875
1839
|
throw new Error("Miden client is not ready");
|
|
@@ -1881,7 +1845,9 @@ function useCreateWallet() {
|
|
|
1881
1845
|
options.storageMode ?? DEFAULTS.STORAGE_MODE
|
|
1882
1846
|
);
|
|
1883
1847
|
const mutable = options.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
1884
|
-
const authScheme =
|
|
1848
|
+
const authScheme = resolveAuthScheme(
|
|
1849
|
+
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
1850
|
+
);
|
|
1885
1851
|
const newWallet = await runExclusiveSafe(async () => {
|
|
1886
1852
|
const createdWallet = await client.newWallet(
|
|
1887
1853
|
storageMode,
|
|
@@ -1906,7 +1872,7 @@ function useCreateWallet() {
|
|
|
1906
1872
|
},
|
|
1907
1873
|
[client, isReady, runExclusive, setAccounts]
|
|
1908
1874
|
);
|
|
1909
|
-
const reset = (
|
|
1875
|
+
const reset = useCallback9(() => {
|
|
1910
1876
|
setWallet(null);
|
|
1911
1877
|
setIsCreating(false);
|
|
1912
1878
|
setError(null);
|
|
@@ -1922,27 +1888,30 @@ function useCreateWallet() {
|
|
|
1922
1888
|
function getStorageMode(mode) {
|
|
1923
1889
|
switch (mode) {
|
|
1924
1890
|
case "private":
|
|
1925
|
-
return
|
|
1891
|
+
return AccountStorageMode.private();
|
|
1926
1892
|
case "public":
|
|
1927
|
-
return
|
|
1893
|
+
return AccountStorageMode.public();
|
|
1928
1894
|
case "network":
|
|
1929
|
-
return
|
|
1895
|
+
return AccountStorageMode.network();
|
|
1930
1896
|
default:
|
|
1931
|
-
return
|
|
1897
|
+
return AccountStorageMode.private();
|
|
1932
1898
|
}
|
|
1933
1899
|
}
|
|
1934
1900
|
|
|
1935
1901
|
// src/hooks/useCreateFaucet.ts
|
|
1936
|
-
|
|
1937
|
-
|
|
1902
|
+
import { useCallback as useCallback10, useState as useState8 } from "react";
|
|
1903
|
+
import {
|
|
1904
|
+
AccountStorageMode as AccountStorageMode2,
|
|
1905
|
+
resolveAuthScheme as resolveAuthScheme2
|
|
1906
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1938
1907
|
function useCreateFaucet() {
|
|
1939
1908
|
const { client, isReady, runExclusive } = useMiden();
|
|
1940
1909
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1941
1910
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1942
|
-
const [faucet, setFaucet] = (
|
|
1943
|
-
const [isCreating, setIsCreating] = (
|
|
1944
|
-
const [error, setError] = (
|
|
1945
|
-
const createFaucet = (
|
|
1911
|
+
const [faucet, setFaucet] = useState8(null);
|
|
1912
|
+
const [isCreating, setIsCreating] = useState8(false);
|
|
1913
|
+
const [error, setError] = useState8(null);
|
|
1914
|
+
const createFaucet = useCallback10(
|
|
1946
1915
|
async (options) => {
|
|
1947
1916
|
if (!client || !isReady) {
|
|
1948
1917
|
throw new Error("Miden client is not ready");
|
|
@@ -1954,7 +1923,9 @@ function useCreateFaucet() {
|
|
|
1954
1923
|
options.storageMode ?? DEFAULTS.STORAGE_MODE
|
|
1955
1924
|
);
|
|
1956
1925
|
const decimals = options.decimals ?? DEFAULTS.FAUCET_DECIMALS;
|
|
1957
|
-
const authScheme =
|
|
1926
|
+
const authScheme = resolveAuthScheme2(
|
|
1927
|
+
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
1928
|
+
);
|
|
1958
1929
|
const newFaucet = await runExclusiveSafe(async () => {
|
|
1959
1930
|
const createdFaucet = await client.newFaucet(
|
|
1960
1931
|
storageMode,
|
|
@@ -1981,7 +1952,7 @@ function useCreateFaucet() {
|
|
|
1981
1952
|
},
|
|
1982
1953
|
[client, isReady, runExclusive, setAccounts]
|
|
1983
1954
|
);
|
|
1984
|
-
const reset = (
|
|
1955
|
+
const reset = useCallback10(() => {
|
|
1985
1956
|
setFaucet(null);
|
|
1986
1957
|
setIsCreating(false);
|
|
1987
1958
|
setError(null);
|
|
@@ -1997,19 +1968,19 @@ function useCreateFaucet() {
|
|
|
1997
1968
|
function getStorageMode2(mode) {
|
|
1998
1969
|
switch (mode) {
|
|
1999
1970
|
case "private":
|
|
2000
|
-
return
|
|
1971
|
+
return AccountStorageMode2.private();
|
|
2001
1972
|
case "public":
|
|
2002
|
-
return
|
|
1973
|
+
return AccountStorageMode2.public();
|
|
2003
1974
|
case "network":
|
|
2004
|
-
return
|
|
1975
|
+
return AccountStorageMode2.network();
|
|
2005
1976
|
default:
|
|
2006
|
-
return
|
|
1977
|
+
return AccountStorageMode2.private();
|
|
2007
1978
|
}
|
|
2008
1979
|
}
|
|
2009
1980
|
|
|
2010
1981
|
// src/hooks/useImportAccount.ts
|
|
2011
|
-
|
|
2012
|
-
|
|
1982
|
+
import { useCallback as useCallback11, useState as useState9 } from "react";
|
|
1983
|
+
import { AccountFile, resolveAuthScheme as resolveAuthScheme3 } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2013
1984
|
|
|
2014
1985
|
// src/utils/errors.ts
|
|
2015
1986
|
var MidenError = class extends Error {
|
|
@@ -2067,10 +2038,10 @@ function wrapWasmError(e) {
|
|
|
2067
2038
|
function useImportAccount() {
|
|
2068
2039
|
const { client, isReady, signerConnected } = useMiden();
|
|
2069
2040
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
2070
|
-
const [account, setAccount] = (
|
|
2071
|
-
const [isImporting, setIsImporting] = (
|
|
2072
|
-
const [error, setError] = (
|
|
2073
|
-
const importAccount = (
|
|
2041
|
+
const [account, setAccount] = useState9(null);
|
|
2042
|
+
const [isImporting, setIsImporting] = useState9(false);
|
|
2043
|
+
const [error, setError] = useState9(null);
|
|
2044
|
+
const importAccount = useCallback11(
|
|
2074
2045
|
async (options) => {
|
|
2075
2046
|
if (!client || !isReady) {
|
|
2076
2047
|
throw new Error("Miden client is not ready");
|
|
@@ -2142,7 +2113,9 @@ function useImportAccount() {
|
|
|
2142
2113
|
}
|
|
2143
2114
|
case "seed": {
|
|
2144
2115
|
const mutable = options.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
2145
|
-
const authScheme =
|
|
2116
|
+
const authScheme = resolveAuthScheme3(
|
|
2117
|
+
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
2118
|
+
);
|
|
2146
2119
|
return await client.importPublicAccountFromSeed(
|
|
2147
2120
|
options.seed,
|
|
2148
2121
|
mutable,
|
|
@@ -2166,7 +2139,7 @@ function useImportAccount() {
|
|
|
2166
2139
|
},
|
|
2167
2140
|
[client, isReady, setAccounts, signerConnected]
|
|
2168
2141
|
);
|
|
2169
|
-
const reset = (
|
|
2142
|
+
const reset = useCallback11(() => {
|
|
2170
2143
|
setAccount(null);
|
|
2171
2144
|
setIsImporting(false);
|
|
2172
2145
|
setError(null);
|
|
@@ -2181,10 +2154,10 @@ function useImportAccount() {
|
|
|
2181
2154
|
}
|
|
2182
2155
|
async function resolveAccountFile(file) {
|
|
2183
2156
|
if (file instanceof Uint8Array) {
|
|
2184
|
-
return
|
|
2157
|
+
return AccountFile.deserialize(file);
|
|
2185
2158
|
}
|
|
2186
2159
|
if (file instanceof ArrayBuffer) {
|
|
2187
|
-
return
|
|
2160
|
+
return AccountFile.deserialize(new Uint8Array(file));
|
|
2188
2161
|
}
|
|
2189
2162
|
return file;
|
|
2190
2163
|
}
|
|
@@ -2213,17 +2186,25 @@ function bytesEqual(left, right) {
|
|
|
2213
2186
|
}
|
|
2214
2187
|
|
|
2215
2188
|
// src/hooks/useSend.ts
|
|
2216
|
-
|
|
2217
|
-
|
|
2189
|
+
import { useCallback as useCallback12, useRef as useRef4, useState as useState10 } from "react";
|
|
2190
|
+
import {
|
|
2191
|
+
FungibleAsset,
|
|
2192
|
+
Note,
|
|
2193
|
+
NoteAssets,
|
|
2194
|
+
NoteAttachment as NoteAttachment2,
|
|
2195
|
+
NoteType as NoteType2,
|
|
2196
|
+
NoteArray,
|
|
2197
|
+
TransactionRequestBuilder
|
|
2198
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2218
2199
|
function useSend() {
|
|
2219
2200
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2220
2201
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2221
|
-
const isBusyRef = (
|
|
2222
|
-
const [result, setResult] = (
|
|
2223
|
-
const [isLoading, setIsLoading] = (
|
|
2224
|
-
const [stage, setStage] = (
|
|
2225
|
-
const [error, setError] = (
|
|
2226
|
-
const send = (
|
|
2202
|
+
const isBusyRef = useRef4(false);
|
|
2203
|
+
const [result, setResult] = useState10(null);
|
|
2204
|
+
const [isLoading, setIsLoading] = useState10(false);
|
|
2205
|
+
const [stage, setStage] = useState10("idle");
|
|
2206
|
+
const [error, setError] = useState10(null);
|
|
2207
|
+
const send = useCallback12(
|
|
2227
2208
|
async (options) => {
|
|
2228
2209
|
if (!client || !isReady) {
|
|
2229
2210
|
throw new Error("Miden client is not ready");
|
|
@@ -2281,26 +2262,26 @@ function useSend() {
|
|
|
2281
2262
|
const fromId = parseAccountId(options.from);
|
|
2282
2263
|
const toId = parseAccountId(options.to);
|
|
2283
2264
|
const assetObj = parseAccountId(assetId);
|
|
2284
|
-
const assets = new
|
|
2285
|
-
new
|
|
2265
|
+
const assets = new NoteAssets([
|
|
2266
|
+
new FungibleAsset(assetObj, BigInt(amount))
|
|
2286
2267
|
]);
|
|
2287
|
-
const p2idNote =
|
|
2268
|
+
const p2idNote = Note.createP2IDNote(
|
|
2288
2269
|
fromId,
|
|
2289
2270
|
toId,
|
|
2290
2271
|
assets,
|
|
2291
2272
|
noteType,
|
|
2292
|
-
new
|
|
2273
|
+
new NoteAttachment2()
|
|
2293
2274
|
);
|
|
2294
|
-
const ownOutputs = new
|
|
2275
|
+
const ownOutputs = new NoteArray();
|
|
2295
2276
|
ownOutputs.push(p2idNote);
|
|
2296
|
-
const txRequest = new
|
|
2277
|
+
const txRequest = new TransactionRequestBuilder().withOwnOutputNotes(ownOutputs).build();
|
|
2297
2278
|
const execFromId = parseAccountId(options.from);
|
|
2298
2279
|
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
2299
2280
|
execFromId,
|
|
2300
2281
|
txRequest,
|
|
2301
2282
|
prover
|
|
2302
2283
|
) : await client.submitNewTransaction(execFromId, txRequest);
|
|
2303
|
-
return { txId: txId.
|
|
2284
|
+
return { txId: txId.toHex(), note: p2idNote };
|
|
2304
2285
|
});
|
|
2305
2286
|
setStage("complete");
|
|
2306
2287
|
setResult(returnResult);
|
|
@@ -2314,17 +2295,17 @@ function useSend() {
|
|
|
2314
2295
|
let txRequest;
|
|
2315
2296
|
if (hasAttachment) {
|
|
2316
2297
|
const attachment = createNoteAttachment(options.attachment);
|
|
2317
|
-
const assets = new
|
|
2318
|
-
new
|
|
2298
|
+
const assets = new NoteAssets([
|
|
2299
|
+
new FungibleAsset(assetIdObj, amount)
|
|
2319
2300
|
]);
|
|
2320
|
-
const note =
|
|
2301
|
+
const note = Note.createP2IDNote(
|
|
2321
2302
|
fromAccountId,
|
|
2322
2303
|
toAccountId,
|
|
2323
2304
|
assets,
|
|
2324
2305
|
noteType,
|
|
2325
2306
|
attachment
|
|
2326
2307
|
);
|
|
2327
|
-
txRequest = new
|
|
2308
|
+
txRequest = new TransactionRequestBuilder().withOwnOutputNotes(new NoteArray([note])).build();
|
|
2328
2309
|
} else {
|
|
2329
2310
|
txRequest = client.newSendTransactionRequest(
|
|
2330
2311
|
fromAccountId,
|
|
@@ -2352,15 +2333,14 @@ function useSend() {
|
|
|
2352
2333
|
() => client.submitProvenTransaction(provenTransaction, txResult)
|
|
2353
2334
|
);
|
|
2354
2335
|
const txIdHex = txResult.id().toHex();
|
|
2355
|
-
const txIdString = txResult.id().toString();
|
|
2356
2336
|
let fullNote = null;
|
|
2357
|
-
if (noteType ===
|
|
2337
|
+
if (noteType === NoteType2.Private) {
|
|
2358
2338
|
fullNote = extractFullNote(txResult);
|
|
2359
2339
|
}
|
|
2360
2340
|
await runExclusiveSafe(
|
|
2361
2341
|
() => client.applyTransaction(txResult, submissionHeight)
|
|
2362
2342
|
);
|
|
2363
|
-
if (noteType ===
|
|
2343
|
+
if (noteType === NoteType2.Private) {
|
|
2364
2344
|
if (!fullNote) {
|
|
2365
2345
|
throw new Error("Missing full note for private send");
|
|
2366
2346
|
}
|
|
@@ -2376,7 +2356,7 @@ function useSend() {
|
|
|
2376
2356
|
);
|
|
2377
2357
|
}
|
|
2378
2358
|
const sendResult = {
|
|
2379
|
-
txId:
|
|
2359
|
+
txId: txIdHex,
|
|
2380
2360
|
note: null
|
|
2381
2361
|
};
|
|
2382
2362
|
setStage("complete");
|
|
@@ -2395,7 +2375,7 @@ function useSend() {
|
|
|
2395
2375
|
},
|
|
2396
2376
|
[client, isReady, prover, runExclusive, sync]
|
|
2397
2377
|
);
|
|
2398
|
-
const reset = (
|
|
2378
|
+
const reset = useCallback12(() => {
|
|
2399
2379
|
setResult(null);
|
|
2400
2380
|
setIsLoading(false);
|
|
2401
2381
|
setStage("idle");
|
|
@@ -2422,16 +2402,24 @@ function extractFullNote(txResult) {
|
|
|
2422
2402
|
}
|
|
2423
2403
|
|
|
2424
2404
|
// src/hooks/useMultiSend.ts
|
|
2425
|
-
|
|
2426
|
-
|
|
2405
|
+
import { useCallback as useCallback13, useRef as useRef5, useState as useState11 } from "react";
|
|
2406
|
+
import {
|
|
2407
|
+
FungibleAsset as FungibleAsset2,
|
|
2408
|
+
Note as Note2,
|
|
2409
|
+
NoteAssets as NoteAssets2,
|
|
2410
|
+
NoteAttachment as NoteAttachment3,
|
|
2411
|
+
NoteType as NoteType3,
|
|
2412
|
+
NoteArray as NoteArray2,
|
|
2413
|
+
TransactionRequestBuilder as TransactionRequestBuilder2
|
|
2414
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2427
2415
|
function useMultiSend() {
|
|
2428
2416
|
const { client, isReady, sync, prover, signerConnected } = useMiden();
|
|
2429
|
-
const isBusyRef = (
|
|
2430
|
-
const [result, setResult] = (
|
|
2431
|
-
const [isLoading, setIsLoading] = (
|
|
2432
|
-
const [stage, setStage] = (
|
|
2433
|
-
const [error, setError] = (
|
|
2434
|
-
const sendMany = (
|
|
2417
|
+
const isBusyRef = useRef5(false);
|
|
2418
|
+
const [result, setResult] = useState11(null);
|
|
2419
|
+
const [isLoading, setIsLoading] = useState11(false);
|
|
2420
|
+
const [stage, setStage] = useState11("idle");
|
|
2421
|
+
const [error, setError] = useState11(null);
|
|
2422
|
+
const sendMany = useCallback13(
|
|
2435
2423
|
async (options) => {
|
|
2436
2424
|
if (!client || !isReady) {
|
|
2437
2425
|
throw new Error("Miden client is not ready");
|
|
@@ -2460,12 +2448,12 @@ function useMultiSend() {
|
|
|
2460
2448
|
const iterSenderId = parseAccountId(options.from);
|
|
2461
2449
|
const iterAssetId = parseAccountId(options.assetId);
|
|
2462
2450
|
const receiverId = parseAccountId(to);
|
|
2463
|
-
const assets = new
|
|
2464
|
-
new
|
|
2451
|
+
const assets = new NoteAssets2([
|
|
2452
|
+
new FungibleAsset2(iterAssetId, BigInt(amount))
|
|
2465
2453
|
]);
|
|
2466
2454
|
const resolvedNoteType = recipientNoteType ? getNoteType(recipientNoteType) : noteType;
|
|
2467
|
-
const noteAttachment = attachment !== void 0 && attachment !== null ? createNoteAttachment(attachment) : new
|
|
2468
|
-
const note =
|
|
2455
|
+
const noteAttachment = attachment !== void 0 && attachment !== null ? createNoteAttachment(attachment) : new NoteAttachment3();
|
|
2456
|
+
const note = Note2.createP2IDNote(
|
|
2469
2457
|
iterSenderId,
|
|
2470
2458
|
receiverId,
|
|
2471
2459
|
assets,
|
|
@@ -2480,7 +2468,11 @@ function useMultiSend() {
|
|
|
2480
2468
|
};
|
|
2481
2469
|
}
|
|
2482
2470
|
);
|
|
2483
|
-
const
|
|
2471
|
+
const ownOutputs = new NoteArray2();
|
|
2472
|
+
for (const o of outputs) {
|
|
2473
|
+
ownOutputs.push(o.note);
|
|
2474
|
+
}
|
|
2475
|
+
const txRequest = new TransactionRequestBuilder2().withOwnOutputNotes(ownOutputs).build();
|
|
2484
2476
|
const txSenderId = parseAccountId(options.from);
|
|
2485
2477
|
const txResult = await client.executeTransaction(txSenderId, txRequest);
|
|
2486
2478
|
setStage("proving");
|
|
@@ -2497,9 +2489,8 @@ function useMultiSend() {
|
|
|
2497
2489
|
txResult
|
|
2498
2490
|
);
|
|
2499
2491
|
const txIdHex = txResult.id().toHex();
|
|
2500
|
-
const txIdString = txResult.id().toString();
|
|
2501
2492
|
await client.applyTransaction(txResult, submissionHeight);
|
|
2502
|
-
const hasPrivate = outputs.some((o) => o.noteType ===
|
|
2493
|
+
const hasPrivate = outputs.some((o) => o.noteType === NoteType3.Private);
|
|
2503
2494
|
if (hasPrivate) {
|
|
2504
2495
|
await waitForTransactionCommit(
|
|
2505
2496
|
client,
|
|
@@ -2507,7 +2498,7 @@ function useMultiSend() {
|
|
|
2507
2498
|
txIdHex
|
|
2508
2499
|
);
|
|
2509
2500
|
for (const output of outputs) {
|
|
2510
|
-
if (output.noteType ===
|
|
2501
|
+
if (output.noteType === NoteType3.Private) {
|
|
2511
2502
|
await client.sendPrivateNote(
|
|
2512
2503
|
output.note,
|
|
2513
2504
|
output.recipientAddress
|
|
@@ -2515,7 +2506,7 @@ function useMultiSend() {
|
|
|
2515
2506
|
}
|
|
2516
2507
|
}
|
|
2517
2508
|
}
|
|
2518
|
-
const txSummary = { transactionId:
|
|
2509
|
+
const txSummary = { transactionId: txIdHex };
|
|
2519
2510
|
setStage("complete");
|
|
2520
2511
|
setResult(txSummary);
|
|
2521
2512
|
await sync();
|
|
@@ -2532,7 +2523,7 @@ function useMultiSend() {
|
|
|
2532
2523
|
},
|
|
2533
2524
|
[client, isReady, prover, signerConnected, sync]
|
|
2534
2525
|
);
|
|
2535
|
-
const reset = (
|
|
2526
|
+
const reset = useCallback13(() => {
|
|
2536
2527
|
setResult(null);
|
|
2537
2528
|
setIsLoading(false);
|
|
2538
2529
|
setStage("idle");
|
|
@@ -2549,11 +2540,11 @@ function useMultiSend() {
|
|
|
2549
2540
|
}
|
|
2550
2541
|
|
|
2551
2542
|
// src/hooks/useWaitForCommit.ts
|
|
2552
|
-
|
|
2553
|
-
|
|
2543
|
+
import { useCallback as useCallback14 } from "react";
|
|
2544
|
+
import { TransactionFilter as TransactionFilter3 } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2554
2545
|
function useWaitForCommit() {
|
|
2555
2546
|
const { client, isReady } = useMiden();
|
|
2556
|
-
const waitForCommit = (
|
|
2547
|
+
const waitForCommit = useCallback14(
|
|
2557
2548
|
async (txId, options) => {
|
|
2558
2549
|
if (!client || !isReady) {
|
|
2559
2550
|
throw new Error("Miden client is not ready");
|
|
@@ -2567,7 +2558,7 @@ function useWaitForCommit() {
|
|
|
2567
2558
|
while (Date.now() < deadline) {
|
|
2568
2559
|
await client.syncState();
|
|
2569
2560
|
const records = await client.getTransactions(
|
|
2570
|
-
typeof txId === "string" ?
|
|
2561
|
+
typeof txId === "string" ? TransactionFilter3.all() : TransactionFilter3.ids([txId])
|
|
2571
2562
|
);
|
|
2572
2563
|
const record = records.find(
|
|
2573
2564
|
(item) => normalizeHex3(item.id().toHex()) === targetHex
|
|
@@ -2596,11 +2587,11 @@ function normalizeHex3(value) {
|
|
|
2596
2587
|
}
|
|
2597
2588
|
|
|
2598
2589
|
// src/hooks/useWaitForNotes.ts
|
|
2599
|
-
|
|
2590
|
+
import { useCallback as useCallback15 } from "react";
|
|
2600
2591
|
function useWaitForNotes() {
|
|
2601
2592
|
const { client, isReady, runExclusive } = useMiden();
|
|
2602
2593
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2603
|
-
const waitForConsumableNotes = (
|
|
2594
|
+
const waitForConsumableNotes = useCallback15(
|
|
2604
2595
|
async (options) => {
|
|
2605
2596
|
if (!client || !isReady) {
|
|
2606
2597
|
throw new Error("Miden client is not ready");
|
|
@@ -2631,15 +2622,15 @@ function useWaitForNotes() {
|
|
|
2631
2622
|
}
|
|
2632
2623
|
|
|
2633
2624
|
// src/hooks/useMint.ts
|
|
2634
|
-
|
|
2625
|
+
import { useCallback as useCallback16, useState as useState12 } from "react";
|
|
2635
2626
|
function useMint() {
|
|
2636
2627
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2637
2628
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2638
|
-
const [result, setResult] = (
|
|
2639
|
-
const [isLoading, setIsLoading] = (
|
|
2640
|
-
const [stage, setStage] = (
|
|
2641
|
-
const [error, setError] = (
|
|
2642
|
-
const mint = (
|
|
2629
|
+
const [result, setResult] = useState12(null);
|
|
2630
|
+
const [isLoading, setIsLoading] = useState12(false);
|
|
2631
|
+
const [stage, setStage] = useState12("idle");
|
|
2632
|
+
const [error, setError] = useState12(null);
|
|
2633
|
+
const mint = useCallback16(
|
|
2643
2634
|
async (options) => {
|
|
2644
2635
|
if (!client || !isReady) {
|
|
2645
2636
|
throw new Error("Miden client is not ready");
|
|
@@ -2664,7 +2655,7 @@ function useMint() {
|
|
|
2664
2655
|
txRequest,
|
|
2665
2656
|
prover
|
|
2666
2657
|
) : await client.submitNewTransaction(faucetIdObj, txRequest);
|
|
2667
|
-
return { transactionId: txId.
|
|
2658
|
+
return { transactionId: txId.toHex() };
|
|
2668
2659
|
});
|
|
2669
2660
|
setStage("complete");
|
|
2670
2661
|
setResult(txResult);
|
|
@@ -2681,7 +2672,7 @@ function useMint() {
|
|
|
2681
2672
|
},
|
|
2682
2673
|
[client, isReady, prover, runExclusive, sync]
|
|
2683
2674
|
);
|
|
2684
|
-
const reset = (
|
|
2675
|
+
const reset = useCallback16(() => {
|
|
2685
2676
|
setResult(null);
|
|
2686
2677
|
setIsLoading(false);
|
|
2687
2678
|
setStage("idle");
|
|
@@ -2698,16 +2689,16 @@ function useMint() {
|
|
|
2698
2689
|
}
|
|
2699
2690
|
|
|
2700
2691
|
// src/hooks/useConsume.ts
|
|
2701
|
-
|
|
2702
|
-
|
|
2692
|
+
import { useCallback as useCallback17, useState as useState13 } from "react";
|
|
2693
|
+
import { NoteFilter as NoteFilter3, NoteFilterTypes as NoteFilterTypes2, NoteId } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2703
2694
|
function useConsume() {
|
|
2704
2695
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2705
2696
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2706
|
-
const [result, setResult] = (
|
|
2707
|
-
const [isLoading, setIsLoading] = (
|
|
2708
|
-
const [stage, setStage] = (
|
|
2709
|
-
const [error, setError] = (
|
|
2710
|
-
const consume = (
|
|
2697
|
+
const [result, setResult] = useState13(null);
|
|
2698
|
+
const [isLoading, setIsLoading] = useState13(false);
|
|
2699
|
+
const [stage, setStage] = useState13("idle");
|
|
2700
|
+
const [error, setError] = useState13(null);
|
|
2701
|
+
const consume = useCallback17(
|
|
2711
2702
|
async (options) => {
|
|
2712
2703
|
if (!client || !isReady) {
|
|
2713
2704
|
throw new Error("Miden client is not ready");
|
|
@@ -2729,7 +2720,7 @@ function useConsume() {
|
|
|
2729
2720
|
const item = options.notes[i];
|
|
2730
2721
|
if (typeof item === "string") {
|
|
2731
2722
|
lookupIndices.push(i);
|
|
2732
|
-
lookupIds.push(
|
|
2723
|
+
lookupIds.push(NoteId.fromHex(item));
|
|
2733
2724
|
} else if (item !== null && typeof item === "object" && typeof item.toNote === "function") {
|
|
2734
2725
|
resolved[i] = item.toNote();
|
|
2735
2726
|
} else if (item !== null && typeof item === "object" && typeof item.id === "function") {
|
|
@@ -2740,16 +2731,17 @@ function useConsume() {
|
|
|
2740
2731
|
}
|
|
2741
2732
|
}
|
|
2742
2733
|
if (lookupIds.length > 0) {
|
|
2743
|
-
const
|
|
2734
|
+
const lookupIdStrings = lookupIds.map((id) => id.toString());
|
|
2735
|
+
const filter = new NoteFilter3(NoteFilterTypes2.List, lookupIds);
|
|
2744
2736
|
const noteRecords = await client.getInputNotes(filter);
|
|
2745
|
-
if (noteRecords.length !==
|
|
2737
|
+
if (noteRecords.length !== lookupIdStrings.length) {
|
|
2746
2738
|
throw new Error("Some notes could not be found for provided IDs");
|
|
2747
2739
|
}
|
|
2748
2740
|
const recordById = new Map(
|
|
2749
2741
|
noteRecords.map((r) => [r.id().toString(), r])
|
|
2750
2742
|
);
|
|
2751
2743
|
for (let j = 0; j < lookupIndices.length; j++) {
|
|
2752
|
-
const record = recordById.get(
|
|
2744
|
+
const record = recordById.get(lookupIdStrings[j]);
|
|
2753
2745
|
if (!record) {
|
|
2754
2746
|
throw new Error(
|
|
2755
2747
|
"Some notes could not be found for provided IDs"
|
|
@@ -2771,7 +2763,7 @@ function useConsume() {
|
|
|
2771
2763
|
txRequest,
|
|
2772
2764
|
prover
|
|
2773
2765
|
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2774
|
-
return { transactionId: txId.
|
|
2766
|
+
return { transactionId: txId.toHex() };
|
|
2775
2767
|
});
|
|
2776
2768
|
setStage("complete");
|
|
2777
2769
|
setResult(txResult);
|
|
@@ -2788,7 +2780,7 @@ function useConsume() {
|
|
|
2788
2780
|
},
|
|
2789
2781
|
[client, isReady, prover, runExclusive, sync]
|
|
2790
2782
|
);
|
|
2791
|
-
const reset = (
|
|
2783
|
+
const reset = useCallback17(() => {
|
|
2792
2784
|
setResult(null);
|
|
2793
2785
|
setIsLoading(false);
|
|
2794
2786
|
setStage("idle");
|
|
@@ -2805,15 +2797,15 @@ function useConsume() {
|
|
|
2805
2797
|
}
|
|
2806
2798
|
|
|
2807
2799
|
// src/hooks/useSwap.ts
|
|
2808
|
-
|
|
2800
|
+
import { useCallback as useCallback18, useState as useState14 } from "react";
|
|
2809
2801
|
function useSwap() {
|
|
2810
2802
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2811
2803
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2812
|
-
const [result, setResult] = (
|
|
2813
|
-
const [isLoading, setIsLoading] = (
|
|
2814
|
-
const [stage, setStage] = (
|
|
2815
|
-
const [error, setError] = (
|
|
2816
|
-
const swap = (
|
|
2804
|
+
const [result, setResult] = useState14(null);
|
|
2805
|
+
const [isLoading, setIsLoading] = useState14(false);
|
|
2806
|
+
const [stage, setStage] = useState14("idle");
|
|
2807
|
+
const [error, setError] = useState14(null);
|
|
2808
|
+
const swap = useCallback18(
|
|
2817
2809
|
async (options) => {
|
|
2818
2810
|
if (!client || !isReady) {
|
|
2819
2811
|
throw new Error("Miden client is not ready");
|
|
@@ -2845,7 +2837,7 @@ function useSwap() {
|
|
|
2845
2837
|
txRequest,
|
|
2846
2838
|
prover
|
|
2847
2839
|
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2848
|
-
return { transactionId: txId.
|
|
2840
|
+
return { transactionId: txId.toHex() };
|
|
2849
2841
|
});
|
|
2850
2842
|
setStage("complete");
|
|
2851
2843
|
setResult(txResult);
|
|
@@ -2862,7 +2854,7 @@ function useSwap() {
|
|
|
2862
2854
|
},
|
|
2863
2855
|
[client, isReady, prover, runExclusive, sync]
|
|
2864
2856
|
);
|
|
2865
|
-
const reset = (
|
|
2857
|
+
const reset = useCallback18(() => {
|
|
2866
2858
|
setResult(null);
|
|
2867
2859
|
setIsLoading(false);
|
|
2868
2860
|
setStage("idle");
|
|
@@ -2879,16 +2871,16 @@ function useSwap() {
|
|
|
2879
2871
|
}
|
|
2880
2872
|
|
|
2881
2873
|
// src/hooks/useTransaction.ts
|
|
2882
|
-
|
|
2874
|
+
import { useCallback as useCallback19, useRef as useRef6, useState as useState15 } from "react";
|
|
2883
2875
|
|
|
2884
2876
|
// src/utils/transactions.ts
|
|
2885
|
-
|
|
2877
|
+
import { NoteType as NoteType4, TransactionFilter as TransactionFilter4 } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2886
2878
|
async function waitForTransactionCommit2(client, runExclusiveSafe, txId, maxWaitMs = 1e4, delayMs = 1e3) {
|
|
2887
2879
|
let waited = 0;
|
|
2888
2880
|
while (waited < maxWaitMs) {
|
|
2889
2881
|
await runExclusiveSafe(() => client.syncState());
|
|
2890
2882
|
const [record] = await runExclusiveSafe(
|
|
2891
|
-
() => client.getTransactions(
|
|
2883
|
+
() => client.getTransactions(TransactionFilter4.ids([txId]))
|
|
2892
2884
|
);
|
|
2893
2885
|
if (record) {
|
|
2894
2886
|
const status = record.transactionStatus();
|
|
@@ -2910,7 +2902,7 @@ function extractFullNotes(txResult) {
|
|
|
2910
2902
|
const notes = executedTx?.outputNotes?.().notes?.() ?? [];
|
|
2911
2903
|
const result = [];
|
|
2912
2904
|
for (const note of notes) {
|
|
2913
|
-
if (note.noteType?.() ===
|
|
2905
|
+
if (note.noteType?.() === NoteType4.Private) {
|
|
2914
2906
|
const full = note.intoFull?.();
|
|
2915
2907
|
if (full) result.push(full);
|
|
2916
2908
|
}
|
|
@@ -2925,12 +2917,12 @@ function extractFullNotes(txResult) {
|
|
|
2925
2917
|
function useTransaction() {
|
|
2926
2918
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
2927
2919
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2928
|
-
const isBusyRef = (
|
|
2929
|
-
const [result, setResult] = (
|
|
2930
|
-
const [isLoading, setIsLoading] = (
|
|
2931
|
-
const [stage, setStage] = (
|
|
2932
|
-
const [error, setError] = (
|
|
2933
|
-
const execute = (
|
|
2920
|
+
const isBusyRef = useRef6(false);
|
|
2921
|
+
const [result, setResult] = useState15(null);
|
|
2922
|
+
const [isLoading, setIsLoading] = useState15(false);
|
|
2923
|
+
const [stage, setStage] = useState15("idle");
|
|
2924
|
+
const [error, setError] = useState15(null);
|
|
2925
|
+
const execute = useCallback19(
|
|
2934
2926
|
async (options) => {
|
|
2935
2927
|
if (!client || !isReady) {
|
|
2936
2928
|
throw new Error("Miden client is not ready");
|
|
@@ -2980,7 +2972,7 @@ function useTransaction() {
|
|
|
2980
2972
|
);
|
|
2981
2973
|
}
|
|
2982
2974
|
}
|
|
2983
|
-
const txSummary = { transactionId: txId.
|
|
2975
|
+
const txSummary = { transactionId: txId.toHex() };
|
|
2984
2976
|
setStage("complete");
|
|
2985
2977
|
setResult(txSummary);
|
|
2986
2978
|
await sync();
|
|
@@ -2997,7 +2989,7 @@ function useTransaction() {
|
|
|
2997
2989
|
},
|
|
2998
2990
|
[client, isReady, runExclusive, sync]
|
|
2999
2991
|
);
|
|
3000
|
-
const reset = (
|
|
2992
|
+
const reset = useCallback19(() => {
|
|
3001
2993
|
setResult(null);
|
|
3002
2994
|
setIsLoading(false);
|
|
3003
2995
|
setStage("idle");
|
|
@@ -3020,19 +3012,24 @@ async function resolveRequest(request, client) {
|
|
|
3020
3012
|
}
|
|
3021
3013
|
|
|
3022
3014
|
// src/hooks/useExecuteProgram.ts
|
|
3023
|
-
|
|
3024
|
-
|
|
3015
|
+
import { useCallback as useCallback20, useRef as useRef7, useState as useState16 } from "react";
|
|
3016
|
+
import {
|
|
3017
|
+
AdviceInputs,
|
|
3018
|
+
ForeignAccount,
|
|
3019
|
+
ForeignAccountArray,
|
|
3020
|
+
AccountStorageRequirements
|
|
3021
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3025
3022
|
function isForeignAccountWrapper(fa) {
|
|
3026
3023
|
return fa !== null && typeof fa === "object" && "id" in fa && typeof fa.id !== "function";
|
|
3027
3024
|
}
|
|
3028
3025
|
function useExecuteProgram() {
|
|
3029
3026
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
3030
3027
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3031
|
-
const isBusyRef = (
|
|
3032
|
-
const [result, setResult] = (
|
|
3033
|
-
const [isLoading, setIsLoading] = (
|
|
3034
|
-
const [error, setError] = (
|
|
3035
|
-
const execute = (
|
|
3028
|
+
const isBusyRef = useRef7(false);
|
|
3029
|
+
const [result, setResult] = useState16(null);
|
|
3030
|
+
const [isLoading, setIsLoading] = useState16(false);
|
|
3031
|
+
const [error, setError] = useState16(null);
|
|
3032
|
+
const execute = useCallback20(
|
|
3036
3033
|
async (options) => {
|
|
3037
3034
|
if (!client || !isReady) {
|
|
3038
3035
|
throw new Error("Miden client is not ready");
|
|
@@ -3052,18 +3049,18 @@ function useExecuteProgram() {
|
|
|
3052
3049
|
}
|
|
3053
3050
|
const programResult = await runExclusiveSafe(async () => {
|
|
3054
3051
|
const accountIdObj = parseAccountId(options.accountId);
|
|
3055
|
-
const adviceInputs = options.adviceInputs ?? new
|
|
3052
|
+
const adviceInputs = options.adviceInputs ?? new AdviceInputs();
|
|
3056
3053
|
let foreignAccountsArray;
|
|
3057
3054
|
if (options.foreignAccounts?.length) {
|
|
3058
3055
|
const accounts = options.foreignAccounts.map((fa) => {
|
|
3059
3056
|
const wrapper = isForeignAccountWrapper(fa);
|
|
3060
3057
|
const id = parseAccountId(wrapper ? fa.id : fa);
|
|
3061
|
-
const storage = wrapper && fa.storage ? fa.storage : new
|
|
3062
|
-
return
|
|
3058
|
+
const storage = wrapper && fa.storage ? fa.storage : new AccountStorageRequirements();
|
|
3059
|
+
return ForeignAccount.public(id, storage);
|
|
3063
3060
|
});
|
|
3064
|
-
foreignAccountsArray = new
|
|
3061
|
+
foreignAccountsArray = new ForeignAccountArray(accounts);
|
|
3065
3062
|
} else {
|
|
3066
|
-
foreignAccountsArray = new
|
|
3063
|
+
foreignAccountsArray = new ForeignAccountArray();
|
|
3067
3064
|
}
|
|
3068
3065
|
const feltArray = await client.executeProgram(
|
|
3069
3066
|
accountIdObj,
|
|
@@ -3091,7 +3088,7 @@ function useExecuteProgram() {
|
|
|
3091
3088
|
},
|
|
3092
3089
|
[client, isReady, runExclusive, sync]
|
|
3093
3090
|
);
|
|
3094
|
-
const reset = (
|
|
3091
|
+
const reset = useCallback20(() => {
|
|
3095
3092
|
setResult(null);
|
|
3096
3093
|
setIsLoading(false);
|
|
3097
3094
|
setError(null);
|
|
@@ -3106,29 +3103,29 @@ function useExecuteProgram() {
|
|
|
3106
3103
|
}
|
|
3107
3104
|
|
|
3108
3105
|
// src/hooks/useCompile.ts
|
|
3109
|
-
|
|
3110
|
-
|
|
3106
|
+
import { useCallback as useCallback21, useMemo as useMemo8 } from "react";
|
|
3107
|
+
import { CompilerResource, getWasmOrThrow } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3111
3108
|
function useCompile() {
|
|
3112
3109
|
const { client, isReady } = useMiden();
|
|
3113
|
-
const resource = (
|
|
3114
|
-
() => client && isReady ? new
|
|
3110
|
+
const resource = useMemo8(
|
|
3111
|
+
() => client && isReady ? new CompilerResource(client, getWasmOrThrow) : null,
|
|
3115
3112
|
[client, isReady]
|
|
3116
3113
|
);
|
|
3117
|
-
const requireResource = (
|
|
3114
|
+
const requireResource = useCallback21(() => {
|
|
3118
3115
|
if (!resource) {
|
|
3119
3116
|
throw new Error("Miden client is not ready");
|
|
3120
3117
|
}
|
|
3121
3118
|
return resource;
|
|
3122
3119
|
}, [resource]);
|
|
3123
|
-
const component = (
|
|
3120
|
+
const component = useCallback21(
|
|
3124
3121
|
async (options) => requireResource().component(options),
|
|
3125
3122
|
[requireResource]
|
|
3126
3123
|
);
|
|
3127
|
-
const txScript = (
|
|
3124
|
+
const txScript = useCallback21(
|
|
3128
3125
|
async (options) => requireResource().txScript(options),
|
|
3129
3126
|
[requireResource]
|
|
3130
3127
|
);
|
|
3131
|
-
const noteScript = (
|
|
3128
|
+
const noteScript = useCallback21(
|
|
3132
3129
|
async (options) => requireResource().noteScript(options),
|
|
3133
3130
|
[requireResource]
|
|
3134
3131
|
);
|
|
@@ -3136,25 +3133,30 @@ function useCompile() {
|
|
|
3136
3133
|
}
|
|
3137
3134
|
|
|
3138
3135
|
// src/hooks/useSessionAccount.ts
|
|
3139
|
-
|
|
3140
|
-
|
|
3136
|
+
import { useCallback as useCallback22, useEffect as useEffect9, useRef as useRef8, useState as useState17 } from "react";
|
|
3137
|
+
import {
|
|
3138
|
+
AccountStorageMode as AccountStorageMode3,
|
|
3139
|
+
resolveAuthScheme as resolveAuthScheme4
|
|
3140
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3141
3141
|
function useSessionAccount(options) {
|
|
3142
3142
|
const { client, isReady, sync } = useMiden();
|
|
3143
3143
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
3144
|
-
const [sessionAccountId, setSessionAccountId] = (
|
|
3145
|
-
const [step, setStep] = (
|
|
3146
|
-
const [error, setError] = (
|
|
3147
|
-
const cancelledRef = (
|
|
3148
|
-
const isBusyRef = (
|
|
3144
|
+
const [sessionAccountId, setSessionAccountId] = useState17(null);
|
|
3145
|
+
const [step, setStep] = useState17("idle");
|
|
3146
|
+
const [error, setError] = useState17(null);
|
|
3147
|
+
const cancelledRef = useRef8(false);
|
|
3148
|
+
const isBusyRef = useRef8(false);
|
|
3149
3149
|
const storagePrefix = options.storagePrefix ?? "miden-session";
|
|
3150
3150
|
const pollIntervalMs = options.pollIntervalMs ?? 3e3;
|
|
3151
3151
|
const maxWaitMs = options.maxWaitMs ?? 6e4;
|
|
3152
3152
|
const storageMode = options.walletOptions?.storageMode ?? "public";
|
|
3153
3153
|
const mutable = options.walletOptions?.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
3154
|
-
const authScheme =
|
|
3155
|
-
|
|
3154
|
+
const authScheme = resolveAuthScheme4(
|
|
3155
|
+
options.walletOptions?.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
3156
|
+
);
|
|
3157
|
+
const fundRef = useRef8(options.fund);
|
|
3156
3158
|
fundRef.current = options.fund;
|
|
3157
|
-
(
|
|
3159
|
+
useEffect9(() => {
|
|
3158
3160
|
try {
|
|
3159
3161
|
const stored = localStorage.getItem(`${storagePrefix}:accountId`);
|
|
3160
3162
|
const storedReady = localStorage.getItem(`${storagePrefix}:ready`);
|
|
@@ -3171,7 +3173,7 @@ function useSessionAccount(options) {
|
|
|
3171
3173
|
localStorage.removeItem(`${storagePrefix}:ready`);
|
|
3172
3174
|
}
|
|
3173
3175
|
}, [storagePrefix]);
|
|
3174
|
-
const initialize = (
|
|
3176
|
+
const initialize = useCallback22(async () => {
|
|
3175
3177
|
if (!client || !isReady) {
|
|
3176
3178
|
throw new Error("Miden client is not ready");
|
|
3177
3179
|
}
|
|
@@ -3202,13 +3204,14 @@ function useSessionAccount(options) {
|
|
|
3202
3204
|
setSessionAccountId(walletId);
|
|
3203
3205
|
localStorage.setItem(`${storagePrefix}:accountId`, walletId);
|
|
3204
3206
|
}
|
|
3207
|
+
const resolvedWalletId = walletId;
|
|
3205
3208
|
setStep("funding");
|
|
3206
|
-
await fundRef.current(
|
|
3209
|
+
await fundRef.current(resolvedWalletId);
|
|
3207
3210
|
if (cancelledRef.current) return;
|
|
3208
3211
|
setStep("consuming");
|
|
3209
3212
|
await waitAndConsume(
|
|
3210
3213
|
client,
|
|
3211
|
-
|
|
3214
|
+
resolvedWalletId,
|
|
3212
3215
|
pollIntervalMs,
|
|
3213
3216
|
maxWaitMs,
|
|
3214
3217
|
cancelledRef
|
|
@@ -3240,7 +3243,7 @@ function useSessionAccount(options) {
|
|
|
3240
3243
|
maxWaitMs,
|
|
3241
3244
|
setAccounts
|
|
3242
3245
|
]);
|
|
3243
|
-
const reset = (
|
|
3246
|
+
const reset = useCallback22(() => {
|
|
3244
3247
|
cancelledRef.current = true;
|
|
3245
3248
|
isBusyRef.current = false;
|
|
3246
3249
|
setSessionAccountId(null);
|
|
@@ -3261,11 +3264,11 @@ function useSessionAccount(options) {
|
|
|
3261
3264
|
function getStorageMode3(mode) {
|
|
3262
3265
|
switch (mode) {
|
|
3263
3266
|
case "private":
|
|
3264
|
-
return
|
|
3267
|
+
return AccountStorageMode3.private();
|
|
3265
3268
|
case "public":
|
|
3266
|
-
return
|
|
3269
|
+
return AccountStorageMode3.public();
|
|
3267
3270
|
default:
|
|
3268
|
-
return
|
|
3271
|
+
return AccountStorageMode3.public();
|
|
3269
3272
|
}
|
|
3270
3273
|
}
|
|
3271
3274
|
async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cancelledRef) {
|
|
@@ -3289,13 +3292,13 @@ async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cance
|
|
|
3289
3292
|
}
|
|
3290
3293
|
|
|
3291
3294
|
// src/hooks/useExportStore.ts
|
|
3292
|
-
|
|
3293
|
-
|
|
3295
|
+
import { useCallback as useCallback23, useState as useState18 } from "react";
|
|
3296
|
+
import { exportStore as sdkExportStore } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3294
3297
|
function useExportStore() {
|
|
3295
3298
|
const { client, isReady, runExclusive } = useMiden();
|
|
3296
|
-
const [isExporting, setIsExporting] = (
|
|
3297
|
-
const [error, setError] = (
|
|
3298
|
-
const exportStore = (
|
|
3299
|
+
const [isExporting, setIsExporting] = useState18(false);
|
|
3300
|
+
const [error, setError] = useState18(null);
|
|
3301
|
+
const exportStore = useCallback23(async () => {
|
|
3299
3302
|
if (!client || !isReady) {
|
|
3300
3303
|
throw new Error("Miden client is not ready");
|
|
3301
3304
|
}
|
|
@@ -3303,7 +3306,7 @@ function useExportStore() {
|
|
|
3303
3306
|
setError(null);
|
|
3304
3307
|
try {
|
|
3305
3308
|
const storeName = client.storeIdentifier();
|
|
3306
|
-
const snapshot = await runExclusive(() => (
|
|
3309
|
+
const snapshot = await runExclusive(() => sdkExportStore(storeName));
|
|
3307
3310
|
return snapshot;
|
|
3308
3311
|
} catch (err) {
|
|
3309
3312
|
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
@@ -3313,7 +3316,7 @@ function useExportStore() {
|
|
|
3313
3316
|
setIsExporting(false);
|
|
3314
3317
|
}
|
|
3315
3318
|
}, [client, isReady, runExclusive]);
|
|
3316
|
-
const reset = (
|
|
3319
|
+
const reset = useCallback23(() => {
|
|
3317
3320
|
setIsExporting(false);
|
|
3318
3321
|
setError(null);
|
|
3319
3322
|
}, []);
|
|
@@ -3326,13 +3329,13 @@ function useExportStore() {
|
|
|
3326
3329
|
}
|
|
3327
3330
|
|
|
3328
3331
|
// src/hooks/useImportStore.ts
|
|
3329
|
-
|
|
3330
|
-
|
|
3332
|
+
import { useCallback as useCallback24, useState as useState19 } from "react";
|
|
3333
|
+
import { importStore as sdkImportStore } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3331
3334
|
function useImportStore() {
|
|
3332
3335
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3333
|
-
const [isImporting, setIsImporting] = (
|
|
3334
|
-
const [error, setError] = (
|
|
3335
|
-
const importStore = (
|
|
3336
|
+
const [isImporting, setIsImporting] = useState19(false);
|
|
3337
|
+
const [error, setError] = useState19(null);
|
|
3338
|
+
const importStore = useCallback24(
|
|
3336
3339
|
async (storeDump, storeName, options) => {
|
|
3337
3340
|
if (!client || !isReady) {
|
|
3338
3341
|
throw new Error("Miden client is not ready");
|
|
@@ -3340,7 +3343,7 @@ function useImportStore() {
|
|
|
3340
3343
|
setIsImporting(true);
|
|
3341
3344
|
setError(null);
|
|
3342
3345
|
try {
|
|
3343
|
-
await runExclusive(() => (
|
|
3346
|
+
await runExclusive(() => sdkImportStore(storeName, storeDump));
|
|
3344
3347
|
if (!options?.skipSync) {
|
|
3345
3348
|
await sync();
|
|
3346
3349
|
}
|
|
@@ -3354,7 +3357,7 @@ function useImportStore() {
|
|
|
3354
3357
|
},
|
|
3355
3358
|
[client, isReady, runExclusive, sync]
|
|
3356
3359
|
);
|
|
3357
|
-
const reset = (
|
|
3360
|
+
const reset = useCallback24(() => {
|
|
3358
3361
|
setIsImporting(false);
|
|
3359
3362
|
setError(null);
|
|
3360
3363
|
}, []);
|
|
@@ -3367,13 +3370,13 @@ function useImportStore() {
|
|
|
3367
3370
|
}
|
|
3368
3371
|
|
|
3369
3372
|
// src/hooks/useImportNote.ts
|
|
3370
|
-
|
|
3371
|
-
|
|
3373
|
+
import { useCallback as useCallback25, useState as useState20 } from "react";
|
|
3374
|
+
import { NoteFile } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3372
3375
|
function useImportNote() {
|
|
3373
3376
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3374
|
-
const [isImporting, setIsImporting] = (
|
|
3375
|
-
const [error, setError] = (
|
|
3376
|
-
const importNote = (
|
|
3377
|
+
const [isImporting, setIsImporting] = useState20(false);
|
|
3378
|
+
const [error, setError] = useState20(null);
|
|
3379
|
+
const importNote = useCallback25(
|
|
3377
3380
|
async (noteBytes) => {
|
|
3378
3381
|
if (!client || !isReady) {
|
|
3379
3382
|
throw new Error("Miden client is not ready");
|
|
@@ -3381,7 +3384,7 @@ function useImportNote() {
|
|
|
3381
3384
|
setIsImporting(true);
|
|
3382
3385
|
setError(null);
|
|
3383
3386
|
try {
|
|
3384
|
-
const noteFile =
|
|
3387
|
+
const noteFile = NoteFile.deserialize(noteBytes);
|
|
3385
3388
|
const noteId = await runExclusive(
|
|
3386
3389
|
() => client.importNoteFile(noteFile)
|
|
3387
3390
|
);
|
|
@@ -3397,7 +3400,7 @@ function useImportNote() {
|
|
|
3397
3400
|
},
|
|
3398
3401
|
[client, isReady, runExclusive, sync]
|
|
3399
3402
|
);
|
|
3400
|
-
const reset = (
|
|
3403
|
+
const reset = useCallback25(() => {
|
|
3401
3404
|
setIsImporting(false);
|
|
3402
3405
|
setError(null);
|
|
3403
3406
|
}, []);
|
|
@@ -3410,13 +3413,13 @@ function useImportNote() {
|
|
|
3410
3413
|
}
|
|
3411
3414
|
|
|
3412
3415
|
// src/hooks/useExportNote.ts
|
|
3413
|
-
|
|
3414
|
-
|
|
3416
|
+
import { useCallback as useCallback26, useState as useState21 } from "react";
|
|
3417
|
+
import { NoteExportFormat } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3415
3418
|
function useExportNote() {
|
|
3416
3419
|
const { client, isReady, runExclusive } = useMiden();
|
|
3417
|
-
const [isExporting, setIsExporting] = (
|
|
3418
|
-
const [error, setError] = (
|
|
3419
|
-
const exportNote = (
|
|
3420
|
+
const [isExporting, setIsExporting] = useState21(false);
|
|
3421
|
+
const [error, setError] = useState21(null);
|
|
3422
|
+
const exportNote = useCallback26(
|
|
3420
3423
|
async (noteId) => {
|
|
3421
3424
|
if (!client || !isReady) {
|
|
3422
3425
|
throw new Error("Miden client is not ready");
|
|
@@ -3425,7 +3428,7 @@ function useExportNote() {
|
|
|
3425
3428
|
setError(null);
|
|
3426
3429
|
try {
|
|
3427
3430
|
const noteFile = await runExclusive(
|
|
3428
|
-
() => client.exportNoteFile(noteId,
|
|
3431
|
+
() => client.exportNoteFile(noteId, NoteExportFormat.Full)
|
|
3429
3432
|
);
|
|
3430
3433
|
return noteFile.serialize();
|
|
3431
3434
|
} catch (err) {
|
|
@@ -3438,7 +3441,7 @@ function useExportNote() {
|
|
|
3438
3441
|
},
|
|
3439
3442
|
[client, isReady, runExclusive]
|
|
3440
3443
|
);
|
|
3441
|
-
const reset = (
|
|
3444
|
+
const reset = useCallback26(() => {
|
|
3442
3445
|
setIsExporting(false);
|
|
3443
3446
|
setError(null);
|
|
3444
3447
|
}, []);
|
|
@@ -3451,12 +3454,12 @@ function useExportNote() {
|
|
|
3451
3454
|
}
|
|
3452
3455
|
|
|
3453
3456
|
// src/hooks/useSyncControl.ts
|
|
3454
|
-
|
|
3457
|
+
import { useCallback as useCallback27 } from "react";
|
|
3455
3458
|
function useSyncControl() {
|
|
3456
3459
|
const isPaused = useMidenStore((state) => state.syncPaused);
|
|
3457
3460
|
const setSyncPaused = useMidenStore((state) => state.setSyncPaused);
|
|
3458
|
-
const pauseSync = (
|
|
3459
|
-
const resumeSync = (
|
|
3461
|
+
const pauseSync = useCallback27(() => setSyncPaused(true), [setSyncPaused]);
|
|
3462
|
+
const resumeSync = useCallback27(() => setSyncPaused(false), [setSyncPaused]);
|
|
3460
3463
|
return {
|
|
3461
3464
|
pauseSync,
|
|
3462
3465
|
resumeSync,
|
|
@@ -3613,8 +3616,7 @@ function createMidenStorage(prefix) {
|
|
|
3613
3616
|
|
|
3614
3617
|
// src/index.ts
|
|
3615
3618
|
installAccountBech32();
|
|
3616
|
-
|
|
3617
|
-
0 && (module.exports = {
|
|
3619
|
+
export {
|
|
3618
3620
|
AuthScheme,
|
|
3619
3621
|
DEFAULTS,
|
|
3620
3622
|
MidenError,
|
|
@@ -3669,4 +3671,4 @@ installAccountBech32();
|
|
|
3669
3671
|
useWaitForNotes,
|
|
3670
3672
|
waitForWalletDetection,
|
|
3671
3673
|
wrapWasmError
|
|
3672
|
-
}
|
|
3674
|
+
};
|