@miden-sdk/react 0.14.5 → 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.mjs +29 -15
- package/dist/lazy.mjs +29 -15
- package/dist/{index.js → mt/lazy.mjs} +451 -463
- package/dist/{lazy.js → mt.mjs} +451 -463
- package/lazy/package.json +5 -0
- package/mt/lazy/package.json +5 -0
- package/mt/package.json +5 -0
- package/package.json +36 -33
- /package/dist/{lazy.d.mts → mt/lazy.d.ts} +0 -0
- /package/dist/{index.d.mts → mt.d.ts} +0 -0
|
@@ -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
|
|
@@ -541,7 +466,7 @@ async function initializeSignerAccount(client, config) {
|
|
|
541
466
|
AuthScheme: AuthScheme2,
|
|
542
467
|
Word: Word2,
|
|
543
468
|
resolveAuthScheme: resolveAuthScheme5
|
|
544
|
-
} = await import("@miden-sdk/miden-sdk");
|
|
469
|
+
} = await import("@miden-sdk/miden-sdk/mt/lazy");
|
|
545
470
|
await client.syncState();
|
|
546
471
|
if (config.importAccountId) {
|
|
547
472
|
const accountId2 = parseAccountId(config.importAccountId);
|
|
@@ -600,8 +525,8 @@ async function initializeSignerAccount(client, config) {
|
|
|
600
525
|
}
|
|
601
526
|
|
|
602
527
|
// src/context/MidenProvider.tsx
|
|
603
|
-
|
|
604
|
-
var MidenContext = (
|
|
528
|
+
import { Fragment, jsx } from "react/jsx-runtime";
|
|
529
|
+
var MidenContext = createContext2(null);
|
|
605
530
|
function MidenProvider({
|
|
606
531
|
children,
|
|
607
532
|
config = {},
|
|
@@ -621,22 +546,22 @@ function MidenProvider({
|
|
|
621
546
|
setSyncState,
|
|
622
547
|
setSignerConnected
|
|
623
548
|
} = useMidenStore();
|
|
624
|
-
const syncIntervalRef =
|
|
625
|
-
const isInitializedRef =
|
|
626
|
-
const clientLockRef =
|
|
627
|
-
const currentStoreNameRef =
|
|
628
|
-
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);
|
|
629
554
|
const signerContext = useSigner();
|
|
630
|
-
const [signerAccountId, setSignerAccountId] =
|
|
631
|
-
const resolvedConfig =
|
|
555
|
+
const [signerAccountId, setSignerAccountId] = useState(null);
|
|
556
|
+
const resolvedConfig = useMemo(
|
|
632
557
|
() => ({
|
|
633
558
|
...config,
|
|
634
559
|
rpcUrl: resolveRpcUrl(config.rpcUrl)
|
|
635
560
|
}),
|
|
636
561
|
[config]
|
|
637
562
|
);
|
|
638
|
-
const [defaultProver, setDefaultProver] =
|
|
639
|
-
|
|
563
|
+
const [defaultProver, setDefaultProver] = useState(null);
|
|
564
|
+
useEffect(() => {
|
|
640
565
|
if (!isReady) {
|
|
641
566
|
setDefaultProver(null);
|
|
642
567
|
return;
|
|
@@ -646,14 +571,16 @@ function MidenProvider({
|
|
|
646
571
|
isReady,
|
|
647
572
|
resolvedConfig.prover,
|
|
648
573
|
resolvedConfig.proverTimeoutMs,
|
|
574
|
+
/* v8 ignore next 2 — optional chain on proverUrls; tests don't pass proverUrls config */
|
|
649
575
|
resolvedConfig.proverUrls?.devnet,
|
|
650
576
|
resolvedConfig.proverUrls?.testnet
|
|
651
577
|
]);
|
|
652
|
-
const runExclusive =
|
|
578
|
+
const runExclusive = useCallback(
|
|
579
|
+
/* v8 ignore next 3 — runExclusive callback body; only called by advanced consumers, not directly in tests */
|
|
653
580
|
async (fn) => clientLockRef.current.runExclusive(fn),
|
|
654
581
|
[]
|
|
655
582
|
);
|
|
656
|
-
const sync =
|
|
583
|
+
const sync = useCallback(async () => {
|
|
657
584
|
if (!client || !isReady) return;
|
|
658
585
|
const store = useMidenStore.getState();
|
|
659
586
|
if (store.sync.isSyncing) return;
|
|
@@ -680,10 +607,12 @@ function MidenProvider({
|
|
|
680
607
|
const signerStoreName = signerContext?.storeName ?? null;
|
|
681
608
|
const signerAccountType = signerContext?.accountConfig?.accountType ?? null;
|
|
682
609
|
const signerStorageMode = signerContext?.accountConfig?.storageMode?.toString() ?? null;
|
|
683
|
-
|
|
610
|
+
useEffect(() => {
|
|
684
611
|
signCbRef.current = signerContext?.signCb ?? null;
|
|
685
612
|
}, [signerContext?.signCb]);
|
|
686
|
-
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. */
|
|
687
616
|
async (pubKey, signingInputs) => {
|
|
688
617
|
const cb = signCbRef.current;
|
|
689
618
|
if (!cb) {
|
|
@@ -693,7 +622,7 @@ function MidenProvider({
|
|
|
693
622
|
},
|
|
694
623
|
[]
|
|
695
624
|
);
|
|
696
|
-
|
|
625
|
+
useEffect(() => {
|
|
697
626
|
if (signerIsConnected === null && isInitializedRef.current) return;
|
|
698
627
|
if (signerIsConnected === false) {
|
|
699
628
|
const store = useMidenStore.getState();
|
|
@@ -727,7 +656,7 @@ function MidenProvider({
|
|
|
727
656
|
if (signerContext && signerIsConnected === true) {
|
|
728
657
|
const storeName = `MidenClientDB_${signerContext.storeName}`;
|
|
729
658
|
signCbRef.current = signerContext.signCb;
|
|
730
|
-
webClient = await
|
|
659
|
+
webClient = await WebClient.createClientWithExternalKeystore(
|
|
731
660
|
resolvedConfig.rpcUrl,
|
|
732
661
|
resolvedConfig.noteTransportUrl,
|
|
733
662
|
resolvedConfig.seed,
|
|
@@ -747,7 +676,7 @@ function MidenProvider({
|
|
|
747
676
|
currentStoreNameRef.current = signerContext.storeName;
|
|
748
677
|
} else {
|
|
749
678
|
const seed = resolvedConfig.seed;
|
|
750
|
-
webClient = await
|
|
679
|
+
webClient = await WebClient.createClient(
|
|
751
680
|
resolvedConfig.rpcUrl,
|
|
752
681
|
resolvedConfig.noteTransportUrl,
|
|
753
682
|
seed
|
|
@@ -816,7 +745,7 @@ function MidenProvider({
|
|
|
816
745
|
// signCb changes are handled by the dedicated useEffect + signCbRef above,
|
|
817
746
|
// not by this effect.
|
|
818
747
|
]);
|
|
819
|
-
|
|
748
|
+
useEffect(() => {
|
|
820
749
|
if (!isReady || !client) return;
|
|
821
750
|
const interval = config.autoSyncInterval ?? DEFAULTS.AUTO_SYNC_INTERVAL;
|
|
822
751
|
if (interval <= 0) return;
|
|
@@ -832,7 +761,7 @@ function MidenProvider({
|
|
|
832
761
|
}
|
|
833
762
|
};
|
|
834
763
|
}, [isReady, client, config.autoSyncInterval, sync]);
|
|
835
|
-
|
|
764
|
+
useEffect(() => {
|
|
836
765
|
if (!isReady || !client) return;
|
|
837
766
|
const unsubscribe = client.onStateChanged?.(async () => {
|
|
838
767
|
try {
|
|
@@ -847,13 +776,13 @@ function MidenProvider({
|
|
|
847
776
|
};
|
|
848
777
|
}, [isReady, client, setSyncState]);
|
|
849
778
|
if (isInitializing && loadingComponent) {
|
|
850
|
-
return /* @__PURE__ */
|
|
779
|
+
return /* @__PURE__ */ jsx(Fragment, { children: loadingComponent });
|
|
851
780
|
}
|
|
852
781
|
if (initError && errorComponent) {
|
|
853
782
|
if (typeof errorComponent === "function") {
|
|
854
|
-
return /* @__PURE__ */
|
|
783
|
+
return /* @__PURE__ */ jsx(Fragment, { children: errorComponent(initError) });
|
|
855
784
|
}
|
|
856
|
-
return /* @__PURE__ */
|
|
785
|
+
return /* @__PURE__ */ jsx(Fragment, { children: errorComponent });
|
|
857
786
|
}
|
|
858
787
|
const contextValue = {
|
|
859
788
|
client,
|
|
@@ -866,10 +795,10 @@ function MidenProvider({
|
|
|
866
795
|
signerAccountId,
|
|
867
796
|
signerConnected
|
|
868
797
|
};
|
|
869
|
-
return /* @__PURE__ */
|
|
798
|
+
return /* @__PURE__ */ jsx(MidenContext.Provider, { value: contextValue, children });
|
|
870
799
|
}
|
|
871
800
|
function useMiden() {
|
|
872
|
-
const context = (
|
|
801
|
+
const context = useContext2(MidenContext);
|
|
873
802
|
if (!context) {
|
|
874
803
|
throw new Error("useMiden must be used within a MidenProvider");
|
|
875
804
|
}
|
|
@@ -886,22 +815,30 @@ function useMidenClient() {
|
|
|
886
815
|
}
|
|
887
816
|
|
|
888
817
|
// src/context/MultiSignerProvider.tsx
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
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);
|
|
893
830
|
function MultiSignerProvider({ children }) {
|
|
894
|
-
const signersRef = (
|
|
895
|
-
const [signersSnapshot, setSignersSnapshot] = (
|
|
831
|
+
const signersRef = useRef2(/* @__PURE__ */ new Map());
|
|
832
|
+
const [signersSnapshot, setSignersSnapshot] = useState2(
|
|
896
833
|
[]
|
|
897
834
|
);
|
|
898
|
-
const [activeSignerName, setActiveSignerName] = (
|
|
899
|
-
const activeSignerNameRef = (
|
|
900
|
-
const generationRef = (0
|
|
901
|
-
const updateSnapshot = (
|
|
835
|
+
const [activeSignerName, setActiveSignerName] = useState2(null);
|
|
836
|
+
const activeSignerNameRef = useRef2(null);
|
|
837
|
+
const generationRef = useRef2(0);
|
|
838
|
+
const updateSnapshot = useCallback2(() => {
|
|
902
839
|
setSignersSnapshot(Array.from(signersRef.current.values()));
|
|
903
840
|
}, []);
|
|
904
|
-
const register = (
|
|
841
|
+
const register = useCallback2(
|
|
905
842
|
(value) => {
|
|
906
843
|
const prev = signersRef.current.get(value.name);
|
|
907
844
|
signersRef.current.set(value.name, value);
|
|
@@ -911,7 +848,7 @@ function MultiSignerProvider({ children }) {
|
|
|
911
848
|
},
|
|
912
849
|
[updateSnapshot]
|
|
913
850
|
);
|
|
914
|
-
const unregister = (
|
|
851
|
+
const unregister = useCallback2(
|
|
915
852
|
(name) => {
|
|
916
853
|
signersRef.current.delete(name);
|
|
917
854
|
setActiveSignerName((current) => current === name ? null : current);
|
|
@@ -919,12 +856,15 @@ function MultiSignerProvider({ children }) {
|
|
|
919
856
|
},
|
|
920
857
|
[updateSnapshot]
|
|
921
858
|
);
|
|
922
|
-
const registry = (
|
|
859
|
+
const registry = useMemo2(
|
|
923
860
|
() => ({ register, unregister }),
|
|
924
861
|
[register, unregister]
|
|
925
862
|
);
|
|
926
|
-
const activeSigner = activeSignerName ?
|
|
927
|
-
|
|
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(
|
|
928
868
|
async (pubKey, signingInputs) => {
|
|
929
869
|
const name = activeSignerName;
|
|
930
870
|
if (!name) throw new Error("No active signer (signer was disconnected)");
|
|
@@ -934,21 +874,21 @@ function MultiSignerProvider({ children }) {
|
|
|
934
874
|
},
|
|
935
875
|
[activeSignerName]
|
|
936
876
|
);
|
|
937
|
-
const stableConnect = (
|
|
877
|
+
const stableConnect = useCallback2(async () => {
|
|
938
878
|
const name = activeSignerName;
|
|
939
879
|
if (!name) throw new Error("No active signer (signer was disconnected)");
|
|
940
880
|
const signer = signersRef.current.get(name);
|
|
941
881
|
if (!signer) throw new Error(`Signer "${name}" not found in registry`);
|
|
942
882
|
return signer.connect();
|
|
943
883
|
}, [activeSignerName]);
|
|
944
|
-
const stableDisconnect = (
|
|
884
|
+
const stableDisconnect = useCallback2(async () => {
|
|
945
885
|
const name = activeSignerName;
|
|
946
886
|
if (!name) throw new Error("No active signer (signer was disconnected)");
|
|
947
887
|
const signer = signersRef.current.get(name);
|
|
948
888
|
if (!signer) throw new Error(`Signer "${name}" not found in registry`);
|
|
949
889
|
return signer.disconnect();
|
|
950
890
|
}, [activeSignerName]);
|
|
951
|
-
const forwardedValue = (
|
|
891
|
+
const forwardedValue = useMemo2(() => {
|
|
952
892
|
if (!activeSigner) return null;
|
|
953
893
|
return {
|
|
954
894
|
name: activeSigner.name,
|
|
@@ -968,11 +908,11 @@ function MultiSignerProvider({ children }) {
|
|
|
968
908
|
stableConnect,
|
|
969
909
|
stableDisconnect
|
|
970
910
|
]);
|
|
971
|
-
const setActiveName = (
|
|
911
|
+
const setActiveName = useCallback2((name) => {
|
|
972
912
|
activeSignerNameRef.current = name;
|
|
973
913
|
setActiveSignerName(name);
|
|
974
914
|
}, []);
|
|
975
|
-
const connectSigner = (
|
|
915
|
+
const connectSigner = useCallback2(
|
|
976
916
|
async (name) => {
|
|
977
917
|
const currentName = activeSignerNameRef.current;
|
|
978
918
|
const currentSigner = currentName ? signersRef.current.get(currentName) : null;
|
|
@@ -997,7 +937,7 @@ function MultiSignerProvider({ children }) {
|
|
|
997
937
|
},
|
|
998
938
|
[setActiveName]
|
|
999
939
|
);
|
|
1000
|
-
const disconnectSigner = (
|
|
940
|
+
const disconnectSigner = useCallback2(async () => {
|
|
1001
941
|
++generationRef.current;
|
|
1002
942
|
const currentName = activeSignerNameRef.current;
|
|
1003
943
|
const signer = currentName ? signersRef.current.get(currentName) : null;
|
|
@@ -1008,7 +948,7 @@ function MultiSignerProvider({ children }) {
|
|
|
1008
948
|
});
|
|
1009
949
|
}
|
|
1010
950
|
}, [setActiveName]);
|
|
1011
|
-
const multiSignerValue = (
|
|
951
|
+
const multiSignerValue = useMemo2(
|
|
1012
952
|
() => ({
|
|
1013
953
|
signers: signersSnapshot,
|
|
1014
954
|
activeSigner,
|
|
@@ -1017,18 +957,18 @@ function MultiSignerProvider({ children }) {
|
|
|
1017
957
|
}),
|
|
1018
958
|
[signersSnapshot, activeSigner, connectSigner, disconnectSigner]
|
|
1019
959
|
);
|
|
1020
|
-
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 }) }) });
|
|
1021
961
|
}
|
|
1022
962
|
function SignerSlot() {
|
|
1023
963
|
const signerValue = useSigner();
|
|
1024
|
-
const registry = (
|
|
1025
|
-
const nameRef = (
|
|
1026
|
-
(
|
|
964
|
+
const registry = useContext3(MultiSignerRegistryContext);
|
|
965
|
+
const nameRef = useRef2();
|
|
966
|
+
useEffect2(() => {
|
|
1027
967
|
if (!signerValue || !registry) return;
|
|
1028
968
|
nameRef.current = signerValue.name;
|
|
1029
969
|
registry.register(signerValue);
|
|
1030
970
|
}, [signerValue, registry]);
|
|
1031
|
-
(
|
|
971
|
+
useEffect2(() => {
|
|
1032
972
|
return () => {
|
|
1033
973
|
if (nameRef.current && registry) {
|
|
1034
974
|
registry.unregister(nameRef.current);
|
|
@@ -1038,18 +978,18 @@ function SignerSlot() {
|
|
|
1038
978
|
return null;
|
|
1039
979
|
}
|
|
1040
980
|
function useMultiSigner() {
|
|
1041
|
-
return (
|
|
981
|
+
return useContext3(MultiSignerContext);
|
|
1042
982
|
}
|
|
1043
983
|
|
|
1044
984
|
// src/hooks/useAccounts.ts
|
|
1045
|
-
|
|
985
|
+
import { useCallback as useCallback3, useEffect as useEffect3 } from "react";
|
|
1046
986
|
function useAccounts() {
|
|
1047
987
|
const { client, isReady } = useMiden();
|
|
1048
988
|
const accounts = useAccountsStore();
|
|
1049
989
|
const isLoadingAccounts = useMidenStore((state) => state.isLoadingAccounts);
|
|
1050
990
|
const setLoadingAccounts = useMidenStore((state) => state.setLoadingAccounts);
|
|
1051
991
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1052
|
-
const refetch = (
|
|
992
|
+
const refetch = useCallback3(async () => {
|
|
1053
993
|
if (!client || !isReady) return;
|
|
1054
994
|
setLoadingAccounts(true);
|
|
1055
995
|
try {
|
|
@@ -1061,7 +1001,7 @@ function useAccounts() {
|
|
|
1061
1001
|
setLoadingAccounts(false);
|
|
1062
1002
|
}
|
|
1063
1003
|
}, [client, isReady, setAccounts, setLoadingAccounts]);
|
|
1064
|
-
(
|
|
1004
|
+
useEffect3(() => {
|
|
1065
1005
|
if (isReady && accounts.length === 0) {
|
|
1066
1006
|
refetch();
|
|
1067
1007
|
}
|
|
@@ -1087,11 +1027,15 @@ function useAccounts() {
|
|
|
1087
1027
|
}
|
|
1088
1028
|
|
|
1089
1029
|
// src/hooks/useAccount.ts
|
|
1090
|
-
|
|
1030
|
+
import { useCallback as useCallback4, useEffect as useEffect5, useState as useState3, useMemo as useMemo4 } from "react";
|
|
1091
1031
|
|
|
1092
1032
|
// src/hooks/useAssetMetadata.ts
|
|
1093
|
-
|
|
1094
|
-
|
|
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";
|
|
1095
1039
|
var inflight = /* @__PURE__ */ new Map();
|
|
1096
1040
|
var rpcClients = /* @__PURE__ */ new Map();
|
|
1097
1041
|
var getRpcClient = (rpcUrl) => {
|
|
@@ -1099,8 +1043,8 @@ var getRpcClient = (rpcUrl) => {
|
|
|
1099
1043
|
const existing = rpcClients.get(key);
|
|
1100
1044
|
if (existing) return existing;
|
|
1101
1045
|
try {
|
|
1102
|
-
const endpoint = rpcUrl ? new
|
|
1103
|
-
const client = new
|
|
1046
|
+
const endpoint = rpcUrl ? new Endpoint(rpcUrl) : Endpoint.testnet();
|
|
1047
|
+
const client = new RpcClient(endpoint);
|
|
1104
1048
|
rpcClients.set(key, client);
|
|
1105
1049
|
return client;
|
|
1106
1050
|
} catch {
|
|
@@ -1114,7 +1058,7 @@ var fetchAssetMetadata = async (rpcClient, assetId) => {
|
|
|
1114
1058
|
const fetched = await rpcClient.getAccountDetails(accountId);
|
|
1115
1059
|
const account = fetched.account?.();
|
|
1116
1060
|
if (!account) return null;
|
|
1117
|
-
const faucet =
|
|
1061
|
+
const faucet = BasicFungibleFaucetComponent.fromAccount(account);
|
|
1118
1062
|
const symbol = faucet.symbol().toString();
|
|
1119
1063
|
const decimals = faucet.decimals();
|
|
1120
1064
|
return { assetId, symbol, decimals };
|
|
@@ -1126,12 +1070,12 @@ function useAssetMetadata(assetIds = []) {
|
|
|
1126
1070
|
const assetMetadata = useAssetMetadataStore();
|
|
1127
1071
|
const setAssetMetadata = useMidenStore((state) => state.setAssetMetadata);
|
|
1128
1072
|
const rpcUrl = useMidenStore((state) => state.config.rpcUrl);
|
|
1129
|
-
const rpcClient = (
|
|
1130
|
-
const uniqueAssetIds = (
|
|
1073
|
+
const rpcClient = useMemo3(() => getRpcClient(rpcUrl), [rpcUrl]);
|
|
1074
|
+
const uniqueAssetIds = useMemo3(
|
|
1131
1075
|
() => Array.from(new Set(assetIds.filter(Boolean))),
|
|
1132
1076
|
[assetIds]
|
|
1133
1077
|
);
|
|
1134
|
-
(
|
|
1078
|
+
useEffect4(() => {
|
|
1135
1079
|
if (!rpcClient || uniqueAssetIds.length === 0) return;
|
|
1136
1080
|
uniqueAssetIds.forEach((assetId) => {
|
|
1137
1081
|
const existing = assetMetadata.get(assetId);
|
|
@@ -1154,15 +1098,15 @@ function useAccount(accountId) {
|
|
|
1154
1098
|
const accountDetails = useMidenStore((state) => state.accountDetails);
|
|
1155
1099
|
const setAccountDetails = useMidenStore((state) => state.setAccountDetails);
|
|
1156
1100
|
const { lastSyncTime } = useSyncStateStore();
|
|
1157
|
-
const [isLoading, setIsLoading] = (
|
|
1158
|
-
const [error, setError] = (
|
|
1159
|
-
const accountIdStr = (
|
|
1101
|
+
const [isLoading, setIsLoading] = useState3(false);
|
|
1102
|
+
const [error, setError] = useState3(null);
|
|
1103
|
+
const accountIdStr = useMemo4(() => {
|
|
1160
1104
|
if (!accountId) return void 0;
|
|
1161
1105
|
if (typeof accountId === "string") return accountId;
|
|
1162
1106
|
return parseAccountId(accountId).toString();
|
|
1163
1107
|
}, [accountId]);
|
|
1164
1108
|
const account = accountIdStr ? accountDetails.get(accountIdStr) ?? null : null;
|
|
1165
|
-
const refetch = (
|
|
1109
|
+
const refetch = useCallback4(async () => {
|
|
1166
1110
|
if (!client || !isReady || !accountIdStr) return;
|
|
1167
1111
|
setIsLoading(true);
|
|
1168
1112
|
setError(null);
|
|
@@ -1179,16 +1123,16 @@ function useAccount(accountId) {
|
|
|
1179
1123
|
setIsLoading(false);
|
|
1180
1124
|
}
|
|
1181
1125
|
}, [client, isReady, accountIdStr, setAccountDetails]);
|
|
1182
|
-
(
|
|
1126
|
+
useEffect5(() => {
|
|
1183
1127
|
if (isReady && accountIdStr && !account) {
|
|
1184
1128
|
refetch();
|
|
1185
1129
|
}
|
|
1186
1130
|
}, [isReady, accountIdStr, account, refetch]);
|
|
1187
|
-
(
|
|
1131
|
+
useEffect5(() => {
|
|
1188
1132
|
if (!isReady || !accountIdStr || !lastSyncTime) return;
|
|
1189
1133
|
refetch();
|
|
1190
1134
|
}, [isReady, accountIdStr, lastSyncTime, refetch]);
|
|
1191
|
-
const rawAssets = (
|
|
1135
|
+
const rawAssets = useMemo4(() => {
|
|
1192
1136
|
if (!account) return [];
|
|
1193
1137
|
try {
|
|
1194
1138
|
const vault = account.vault();
|
|
@@ -1205,12 +1149,12 @@ function useAccount(accountId) {
|
|
|
1205
1149
|
return [];
|
|
1206
1150
|
}
|
|
1207
1151
|
}, [account]);
|
|
1208
|
-
const assetIds = (
|
|
1152
|
+
const assetIds = useMemo4(
|
|
1209
1153
|
() => rawAssets.map((asset) => asset.assetId),
|
|
1210
1154
|
[rawAssets]
|
|
1211
1155
|
);
|
|
1212
1156
|
const { assetMetadata } = useAssetMetadata(assetIds);
|
|
1213
|
-
const assets = (
|
|
1157
|
+
const assets = useMemo4(
|
|
1214
1158
|
() => rawAssets.map((asset) => {
|
|
1215
1159
|
const metadata = assetMetadata.get(asset.assetId);
|
|
1216
1160
|
return {
|
|
@@ -1221,7 +1165,7 @@ function useAccount(accountId) {
|
|
|
1221
1165
|
}),
|
|
1222
1166
|
[rawAssets, assetMetadata]
|
|
1223
1167
|
);
|
|
1224
|
-
const getBalance = (
|
|
1168
|
+
const getBalance = useCallback4(
|
|
1225
1169
|
(assetId) => {
|
|
1226
1170
|
const asset = assets.find((a) => a.assetId === assetId);
|
|
1227
1171
|
return asset?.amount ?? 0n;
|
|
@@ -1239,8 +1183,8 @@ function useAccount(accountId) {
|
|
|
1239
1183
|
}
|
|
1240
1184
|
|
|
1241
1185
|
// src/hooks/useNotes.ts
|
|
1242
|
-
|
|
1243
|
-
|
|
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";
|
|
1244
1188
|
|
|
1245
1189
|
// src/utils/amounts.ts
|
|
1246
1190
|
var formatAssetAmount = (amount, decimals) => {
|
|
@@ -1345,30 +1289,35 @@ function accountIdsEqual(a, b) {
|
|
|
1345
1289
|
}
|
|
1346
1290
|
|
|
1347
1291
|
// src/utils/noteFilters.ts
|
|
1348
|
-
|
|
1292
|
+
import {
|
|
1293
|
+
NoteFilterTypes,
|
|
1294
|
+
NoteType,
|
|
1295
|
+
TransactionFilter
|
|
1296
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1349
1297
|
function getNoteFilterType(status) {
|
|
1350
1298
|
switch (status) {
|
|
1351
1299
|
case "consumed":
|
|
1352
|
-
return
|
|
1300
|
+
return NoteFilterTypes.Consumed;
|
|
1353
1301
|
case "committed":
|
|
1354
|
-
return
|
|
1302
|
+
return NoteFilterTypes.Committed;
|
|
1355
1303
|
case "expected":
|
|
1356
|
-
return
|
|
1304
|
+
return NoteFilterTypes.Expected;
|
|
1357
1305
|
case "processing":
|
|
1358
|
-
return
|
|
1306
|
+
return NoteFilterTypes.Processing;
|
|
1359
1307
|
case "all":
|
|
1360
1308
|
default:
|
|
1361
|
-
return
|
|
1309
|
+
return NoteFilterTypes.All;
|
|
1362
1310
|
}
|
|
1363
1311
|
}
|
|
1364
1312
|
function getNoteType(type) {
|
|
1365
1313
|
switch (type) {
|
|
1366
1314
|
case "private":
|
|
1367
|
-
return
|
|
1315
|
+
return NoteType.Private;
|
|
1368
1316
|
case "public":
|
|
1369
|
-
return
|
|
1317
|
+
return NoteType.Public;
|
|
1318
|
+
/* v8 ignore next 2 — TypeScript type ensures only "private"|"public"; default is unreachable */
|
|
1370
1319
|
default:
|
|
1371
|
-
return
|
|
1320
|
+
return NoteType.Private;
|
|
1372
1321
|
}
|
|
1373
1322
|
}
|
|
1374
1323
|
async function waitForTransactionCommit(client, runExclusiveSafe, txIdHex, maxWaitMs = 1e4, delayMs = 1e3) {
|
|
@@ -1377,7 +1326,7 @@ async function waitForTransactionCommit(client, runExclusiveSafe, txIdHex, maxWa
|
|
|
1377
1326
|
while (Date.now() < deadline) {
|
|
1378
1327
|
await runExclusiveSafe(() => client.syncState());
|
|
1379
1328
|
const records = await runExclusiveSafe(
|
|
1380
|
-
() => client.getTransactions(
|
|
1329
|
+
() => client.getTransactions(TransactionFilter.all())
|
|
1381
1330
|
);
|
|
1382
1331
|
const record = records.find(
|
|
1383
1332
|
(r) => normalizeHex(r.id().toHex()) === targetHex
|
|
@@ -1413,14 +1362,14 @@ function useNotes(options) {
|
|
|
1413
1362
|
(state) => state.setConsumableNotesIfChanged
|
|
1414
1363
|
);
|
|
1415
1364
|
const { lastSyncTime } = useSyncStateStore();
|
|
1416
|
-
const [error, setError] = (
|
|
1417
|
-
const refetch = (
|
|
1365
|
+
const [error, setError] = useState4(null);
|
|
1366
|
+
const refetch = useCallback5(async () => {
|
|
1418
1367
|
if (!client || !isReady) return;
|
|
1419
1368
|
setLoadingNotes(true);
|
|
1420
1369
|
setError(null);
|
|
1421
1370
|
try {
|
|
1422
1371
|
const filterType = getNoteFilterType(options?.status);
|
|
1423
|
-
const filter = new
|
|
1372
|
+
const filter = new NoteFilter(filterType);
|
|
1424
1373
|
const fetchedNotes = await client.getInputNotes(filter);
|
|
1425
1374
|
let fetchedConsumable;
|
|
1426
1375
|
if (options?.accountId) {
|
|
@@ -1445,16 +1394,16 @@ function useNotes(options) {
|
|
|
1445
1394
|
setNotesIfChanged,
|
|
1446
1395
|
setConsumableNotesIfChanged
|
|
1447
1396
|
]);
|
|
1448
|
-
(
|
|
1397
|
+
useEffect6(() => {
|
|
1449
1398
|
if (isReady && notes.length === 0) {
|
|
1450
1399
|
refetch();
|
|
1451
1400
|
}
|
|
1452
1401
|
}, [isReady, notes.length, refetch]);
|
|
1453
|
-
(
|
|
1402
|
+
useEffect6(() => {
|
|
1454
1403
|
if (!isReady || !lastSyncTime) return;
|
|
1455
1404
|
refetch();
|
|
1456
1405
|
}, [isReady, lastSyncTime, refetch]);
|
|
1457
|
-
const noteAssetIds = (
|
|
1406
|
+
const noteAssetIds = useMemo5(() => {
|
|
1458
1407
|
const ids = /* @__PURE__ */ new Set();
|
|
1459
1408
|
const collect = (note) => {
|
|
1460
1409
|
const summary = getNoteSummary(note);
|
|
@@ -1466,11 +1415,11 @@ function useNotes(options) {
|
|
|
1466
1415
|
return Array.from(ids);
|
|
1467
1416
|
}, [notes, consumableNotes]);
|
|
1468
1417
|
const { assetMetadata } = useAssetMetadata(noteAssetIds);
|
|
1469
|
-
const getMetadata = (
|
|
1418
|
+
const getMetadata = useCallback5(
|
|
1470
1419
|
(assetId) => assetMetadata.get(assetId),
|
|
1471
1420
|
[assetMetadata]
|
|
1472
1421
|
);
|
|
1473
|
-
const normalizedSender = (
|
|
1422
|
+
const normalizedSender = useMemo5(() => {
|
|
1474
1423
|
if (!options?.sender) return null;
|
|
1475
1424
|
try {
|
|
1476
1425
|
return normalizeAccountId(options.sender);
|
|
@@ -1478,11 +1427,11 @@ function useNotes(options) {
|
|
|
1478
1427
|
return options.sender;
|
|
1479
1428
|
}
|
|
1480
1429
|
}, [options?.sender]);
|
|
1481
|
-
const excludeIdsKey = (
|
|
1430
|
+
const excludeIdsKey = useMemo5(() => {
|
|
1482
1431
|
if (!options?.excludeIds || options.excludeIds.length === 0) return "";
|
|
1483
1432
|
return [...options.excludeIds].sort().join("\0");
|
|
1484
1433
|
}, [options?.excludeIds]);
|
|
1485
|
-
const filterBySender = (
|
|
1434
|
+
const filterBySender = useCallback5(
|
|
1486
1435
|
(summaries, target) => {
|
|
1487
1436
|
const cache = /* @__PURE__ */ new Map();
|
|
1488
1437
|
return summaries.filter((s) => {
|
|
@@ -1501,7 +1450,7 @@ function useNotes(options) {
|
|
|
1501
1450
|
},
|
|
1502
1451
|
[]
|
|
1503
1452
|
);
|
|
1504
|
-
const noteSummaries = (
|
|
1453
|
+
const noteSummaries = useMemo5(() => {
|
|
1505
1454
|
let summaries = notes.map((note) => getNoteSummary(note, getMetadata)).filter(Boolean);
|
|
1506
1455
|
if (normalizedSender) {
|
|
1507
1456
|
summaries = filterBySender(summaries, normalizedSender);
|
|
@@ -1512,7 +1461,7 @@ function useNotes(options) {
|
|
|
1512
1461
|
}
|
|
1513
1462
|
return summaries;
|
|
1514
1463
|
}, [notes, getMetadata, normalizedSender, excludeIdsKey, filterBySender]);
|
|
1515
|
-
const consumableNoteSummaries = (
|
|
1464
|
+
const consumableNoteSummaries = useMemo5(() => {
|
|
1516
1465
|
let summaries = consumableNotes.map((note) => getNoteSummary(note, getMetadata)).filter(Boolean);
|
|
1517
1466
|
if (normalizedSender) {
|
|
1518
1467
|
summaries = filterBySender(summaries, normalizedSender);
|
|
@@ -1541,11 +1490,16 @@ function useNotes(options) {
|
|
|
1541
1490
|
}
|
|
1542
1491
|
|
|
1543
1492
|
// src/hooks/useNoteStream.ts
|
|
1544
|
-
|
|
1545
|
-
|
|
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";
|
|
1546
1495
|
|
|
1547
1496
|
// src/utils/noteAttachment.ts
|
|
1548
|
-
|
|
1497
|
+
import {
|
|
1498
|
+
NoteAttachment,
|
|
1499
|
+
NoteAttachmentKind,
|
|
1500
|
+
NoteAttachmentScheme,
|
|
1501
|
+
Word
|
|
1502
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1549
1503
|
function readNoteAttachment(note) {
|
|
1550
1504
|
try {
|
|
1551
1505
|
const metadata = note.metadata?.();
|
|
@@ -1554,8 +1508,8 @@ function readNoteAttachment(note) {
|
|
|
1554
1508
|
if (!attachment) return null;
|
|
1555
1509
|
const kind = attachment.kind?.();
|
|
1556
1510
|
if (!kind) return null;
|
|
1557
|
-
if (kind ===
|
|
1558
|
-
if (kind ===
|
|
1511
|
+
if (kind === NoteAttachmentKind.None) return null;
|
|
1512
|
+
if (kind === NoteAttachmentKind.Word) {
|
|
1559
1513
|
const word = attachment.asWord?.();
|
|
1560
1514
|
if (!word) return null;
|
|
1561
1515
|
const u64s = word.toU64s();
|
|
@@ -1564,7 +1518,7 @@ function readNoteAttachment(note) {
|
|
|
1564
1518
|
);
|
|
1565
1519
|
return { values, kind: "word" };
|
|
1566
1520
|
}
|
|
1567
|
-
if (kind ===
|
|
1521
|
+
if (kind === NoteAttachmentKind.Array) {
|
|
1568
1522
|
const arr = attachment.asArray?.();
|
|
1569
1523
|
if (!arr) return null;
|
|
1570
1524
|
const u64s = arr.toU64s();
|
|
@@ -1584,30 +1538,30 @@ function createNoteAttachment(values) {
|
|
|
1584
1538
|
bigints.push(BigInt(values[i]));
|
|
1585
1539
|
}
|
|
1586
1540
|
if (bigints.length === 0) {
|
|
1587
|
-
return new
|
|
1541
|
+
return new NoteAttachment();
|
|
1588
1542
|
}
|
|
1589
|
-
const scheme =
|
|
1543
|
+
const scheme = NoteAttachmentScheme.none();
|
|
1590
1544
|
if (bigints.length <= 4) {
|
|
1591
1545
|
while (bigints.length < 4) {
|
|
1592
1546
|
bigints.push(0n);
|
|
1593
1547
|
}
|
|
1594
|
-
const word = new
|
|
1595
|
-
return
|
|
1548
|
+
const word = new Word(BigUint64Array.from(bigints));
|
|
1549
|
+
return NoteAttachment.newWord(scheme, word);
|
|
1596
1550
|
}
|
|
1597
1551
|
while (bigints.length % 4 !== 0) {
|
|
1598
1552
|
bigints.push(0n);
|
|
1599
1553
|
}
|
|
1600
1554
|
const words = [];
|
|
1601
1555
|
for (let i = 0; i < bigints.length; i += 4) {
|
|
1602
|
-
words.push(new
|
|
1556
|
+
words.push(new Word(BigUint64Array.from(bigints.slice(i, i + 4))));
|
|
1603
1557
|
}
|
|
1604
|
-
const newArray =
|
|
1558
|
+
const newArray = NoteAttachment["newArray"];
|
|
1605
1559
|
if (typeof newArray !== "function") {
|
|
1606
1560
|
throw new Error(
|
|
1607
1561
|
"NoteAttachment.newArray is not available. Ensure @miden-sdk/miden-sdk >= 0.13.1."
|
|
1608
1562
|
);
|
|
1609
1563
|
}
|
|
1610
|
-
return newArray.call(
|
|
1564
|
+
return newArray.call(NoteAttachment, scheme, words);
|
|
1611
1565
|
}
|
|
1612
1566
|
|
|
1613
1567
|
// src/hooks/useNoteStream.ts
|
|
@@ -1617,32 +1571,32 @@ function useNoteStream(options = {}) {
|
|
|
1617
1571
|
const noteFirstSeen = useNoteFirstSeenStore();
|
|
1618
1572
|
const { lastSyncTime } = useSyncStateStore();
|
|
1619
1573
|
const setNotesIfChanged = useMidenStore((state) => state.setNotesIfChanged);
|
|
1620
|
-
const [isLoading, setIsLoading] = (
|
|
1621
|
-
const [error, setError] = (
|
|
1622
|
-
const handledIdsRef = (
|
|
1623
|
-
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);
|
|
1624
1578
|
const status = options.status ?? "committed";
|
|
1625
1579
|
const sender = options.sender ?? null;
|
|
1626
1580
|
const since = options.since;
|
|
1627
|
-
const amountFilterRef = (
|
|
1581
|
+
const amountFilterRef = useRef3(options.amountFilter);
|
|
1628
1582
|
amountFilterRef.current = options.amountFilter;
|
|
1629
|
-
const excludeIdsKey = (
|
|
1583
|
+
const excludeIdsKey = useMemo6(() => {
|
|
1630
1584
|
if (!options.excludeIds) return "";
|
|
1631
1585
|
if (options.excludeIds instanceof Set)
|
|
1632
1586
|
return Array.from(options.excludeIds).sort().join("\0");
|
|
1633
1587
|
return [...options.excludeIds].sort().join("\0");
|
|
1634
1588
|
}, [options.excludeIds]);
|
|
1635
|
-
const excludeIdSet = (
|
|
1589
|
+
const excludeIdSet = useMemo6(() => {
|
|
1636
1590
|
if (!excludeIdsKey) return null;
|
|
1637
1591
|
return new Set(excludeIdsKey.split("\0"));
|
|
1638
1592
|
}, [excludeIdsKey]);
|
|
1639
|
-
const refetch = (
|
|
1593
|
+
const refetch = useCallback6(async () => {
|
|
1640
1594
|
if (!client || !isReady) return;
|
|
1641
1595
|
setIsLoading(true);
|
|
1642
1596
|
setError(null);
|
|
1643
1597
|
try {
|
|
1644
1598
|
const filterType = getNoteFilterType(status);
|
|
1645
|
-
const filter = new
|
|
1599
|
+
const filter = new NoteFilter2(filterType);
|
|
1646
1600
|
const fetched = await client.getInputNotes(filter);
|
|
1647
1601
|
setNotesIfChanged(fetched);
|
|
1648
1602
|
} catch (err) {
|
|
@@ -1651,12 +1605,12 @@ function useNoteStream(options = {}) {
|
|
|
1651
1605
|
setIsLoading(false);
|
|
1652
1606
|
}
|
|
1653
1607
|
}, [client, isReady, status, setNotesIfChanged]);
|
|
1654
|
-
(
|
|
1608
|
+
useEffect7(() => {
|
|
1655
1609
|
if (isReady) {
|
|
1656
1610
|
refetch();
|
|
1657
1611
|
}
|
|
1658
1612
|
}, [isReady, lastSyncTime, refetch]);
|
|
1659
|
-
const streamedNotes = (
|
|
1613
|
+
const streamedNotes = useMemo6(() => {
|
|
1660
1614
|
void handledVersion;
|
|
1661
1615
|
const result = [];
|
|
1662
1616
|
let normalizedSender = null;
|
|
@@ -1681,15 +1635,15 @@ function useNoteStream(options = {}) {
|
|
|
1681
1635
|
result.sort((a, b) => a.firstSeenAt - b.firstSeenAt);
|
|
1682
1636
|
return result;
|
|
1683
1637
|
}, [allNotes, noteFirstSeen, excludeIdSet, sender, since, handledVersion]);
|
|
1684
|
-
const latest = (
|
|
1638
|
+
const latest = useMemo6(
|
|
1685
1639
|
() => streamedNotes.length > 0 ? streamedNotes[streamedNotes.length - 1] : null,
|
|
1686
1640
|
[streamedNotes]
|
|
1687
1641
|
);
|
|
1688
|
-
const markHandled = (
|
|
1642
|
+
const markHandled = useCallback6((noteId) => {
|
|
1689
1643
|
handledIdsRef.current = new Set(handledIdsRef.current).add(noteId);
|
|
1690
1644
|
setHandledVersion((v) => v + 1);
|
|
1691
1645
|
}, []);
|
|
1692
|
-
const markAllHandled = (
|
|
1646
|
+
const markAllHandled = useCallback6(() => {
|
|
1693
1647
|
const newSet = new Set(handledIdsRef.current);
|
|
1694
1648
|
for (const note of streamedNotes) {
|
|
1695
1649
|
newSet.add(note.id);
|
|
@@ -1697,7 +1651,7 @@ function useNoteStream(options = {}) {
|
|
|
1697
1651
|
handledIdsRef.current = newSet;
|
|
1698
1652
|
setHandledVersion((v) => v + 1);
|
|
1699
1653
|
}, [streamedNotes]);
|
|
1700
|
-
const snapshot = (
|
|
1654
|
+
const snapshot = useCallback6(() => {
|
|
1701
1655
|
const ids = /* @__PURE__ */ new Set();
|
|
1702
1656
|
for (const note of streamedNotes) {
|
|
1703
1657
|
ids.add(note.id);
|
|
@@ -1753,20 +1707,20 @@ function buildStreamedNote(record, noteFirstSeen) {
|
|
|
1753
1707
|
}
|
|
1754
1708
|
|
|
1755
1709
|
// src/hooks/useTransactionHistory.ts
|
|
1756
|
-
|
|
1757
|
-
|
|
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";
|
|
1758
1712
|
function useTransactionHistory(options = {}) {
|
|
1759
1713
|
const { client, isReady } = useMiden();
|
|
1760
1714
|
const { lastSyncTime } = useSyncStateStore();
|
|
1761
|
-
const [records, setRecords] = (
|
|
1762
|
-
const [isLoading, setIsLoading] = (
|
|
1763
|
-
const [error, setError] = (
|
|
1764
|
-
const rawIds = (
|
|
1715
|
+
const [records, setRecords] = useState6([]);
|
|
1716
|
+
const [isLoading, setIsLoading] = useState6(false);
|
|
1717
|
+
const [error, setError] = useState6(null);
|
|
1718
|
+
const rawIds = useMemo7(() => {
|
|
1765
1719
|
if (options.id) return [options.id];
|
|
1766
1720
|
if (options.ids && options.ids.length > 0) return options.ids;
|
|
1767
1721
|
return null;
|
|
1768
1722
|
}, [options.id, options.ids]);
|
|
1769
|
-
const idsHex = (
|
|
1723
|
+
const idsHex = useMemo7(() => {
|
|
1770
1724
|
if (!rawIds) return null;
|
|
1771
1725
|
return rawIds.map(
|
|
1772
1726
|
(id) => normalizeHex2(typeof id === "string" ? id : id.toHex())
|
|
@@ -1774,7 +1728,7 @@ function useTransactionHistory(options = {}) {
|
|
|
1774
1728
|
}, [rawIds]);
|
|
1775
1729
|
const filter = options.filter;
|
|
1776
1730
|
const refreshOnSync = options.refreshOnSync !== false;
|
|
1777
|
-
const refetch = (
|
|
1731
|
+
const refetch = useCallback7(async () => {
|
|
1778
1732
|
if (!client || !isReady) return;
|
|
1779
1733
|
setIsLoading(true);
|
|
1780
1734
|
setError(null);
|
|
@@ -1795,19 +1749,19 @@ function useTransactionHistory(options = {}) {
|
|
|
1795
1749
|
setIsLoading(false);
|
|
1796
1750
|
}
|
|
1797
1751
|
}, [client, isReady, filter, rawIds, idsHex]);
|
|
1798
|
-
(
|
|
1752
|
+
useEffect8(() => {
|
|
1799
1753
|
if (!isReady) return;
|
|
1800
1754
|
refetch();
|
|
1801
1755
|
}, [isReady, refetch]);
|
|
1802
|
-
(
|
|
1756
|
+
useEffect8(() => {
|
|
1803
1757
|
if (!isReady || !refreshOnSync || !lastSyncTime) return;
|
|
1804
1758
|
refetch();
|
|
1805
1759
|
}, [isReady, lastSyncTime, refreshOnSync, refetch]);
|
|
1806
|
-
const record = (
|
|
1760
|
+
const record = useMemo7(() => {
|
|
1807
1761
|
if (!idsHex || idsHex.length !== 1) return null;
|
|
1808
1762
|
return records.find((item) => normalizeHex2(item.id().toHex()) === idsHex[0]) ?? null;
|
|
1809
1763
|
}, [records, idsHex]);
|
|
1810
|
-
const status = (
|
|
1764
|
+
const status = useMemo7(() => {
|
|
1811
1765
|
if (!record) return null;
|
|
1812
1766
|
const current = record.transactionStatus();
|
|
1813
1767
|
if (current.isCommitted()) return "committed";
|
|
@@ -1829,14 +1783,15 @@ function buildFilter(filter, ids, idsHex) {
|
|
|
1829
1783
|
return { filter };
|
|
1830
1784
|
}
|
|
1831
1785
|
if (!ids || ids.length === 0) {
|
|
1832
|
-
return { filter:
|
|
1786
|
+
return { filter: TransactionFilter2.all() };
|
|
1833
1787
|
}
|
|
1834
1788
|
const allTransactionIds = ids.every((id) => typeof id !== "string");
|
|
1835
1789
|
if (allTransactionIds) {
|
|
1836
|
-
return { filter:
|
|
1790
|
+
return { filter: TransactionFilter2.ids(ids) };
|
|
1837
1791
|
}
|
|
1838
1792
|
return {
|
|
1839
|
-
filter:
|
|
1793
|
+
filter: TransactionFilter2.all(),
|
|
1794
|
+
/* v8 ignore next 1 — idsHex is always non-null when ids is non-empty; ?? [] is a safety net */
|
|
1840
1795
|
localFilterHexes: idsHex ?? []
|
|
1841
1796
|
};
|
|
1842
1797
|
}
|
|
@@ -1847,11 +1802,11 @@ function normalizeHex2(value) {
|
|
|
1847
1802
|
}
|
|
1848
1803
|
|
|
1849
1804
|
// src/hooks/useSyncState.ts
|
|
1850
|
-
|
|
1805
|
+
import { useCallback as useCallback8 } from "react";
|
|
1851
1806
|
function useSyncState() {
|
|
1852
1807
|
const { sync: triggerSync } = useMiden();
|
|
1853
1808
|
const syncState = useSyncStateStore();
|
|
1854
|
-
const sync = (
|
|
1809
|
+
const sync = useCallback8(async () => {
|
|
1855
1810
|
await triggerSync();
|
|
1856
1811
|
}, [triggerSync]);
|
|
1857
1812
|
return {
|
|
@@ -1861,8 +1816,11 @@ function useSyncState() {
|
|
|
1861
1816
|
}
|
|
1862
1817
|
|
|
1863
1818
|
// src/hooks/useCreateWallet.ts
|
|
1864
|
-
|
|
1865
|
-
|
|
1819
|
+
import { useCallback as useCallback9, useState as useState7 } from "react";
|
|
1820
|
+
import {
|
|
1821
|
+
AccountStorageMode,
|
|
1822
|
+
resolveAuthScheme
|
|
1823
|
+
} from "@miden-sdk/miden-sdk/mt/lazy";
|
|
1866
1824
|
|
|
1867
1825
|
// src/utils/runExclusive.ts
|
|
1868
1826
|
var runExclusiveDirect = async (fn) => fn();
|
|
@@ -1872,10 +1830,10 @@ function useCreateWallet() {
|
|
|
1872
1830
|
const { client, isReady, runExclusive } = useMiden();
|
|
1873
1831
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1874
1832
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1875
|
-
const [wallet, setWallet] = (
|
|
1876
|
-
const [isCreating, setIsCreating] = (
|
|
1877
|
-
const [error, setError] = (
|
|
1878
|
-
const createWallet = (
|
|
1833
|
+
const [wallet, setWallet] = useState7(null);
|
|
1834
|
+
const [isCreating, setIsCreating] = useState7(false);
|
|
1835
|
+
const [error, setError] = useState7(null);
|
|
1836
|
+
const createWallet = useCallback9(
|
|
1879
1837
|
async (options = {}) => {
|
|
1880
1838
|
if (!client || !isReady) {
|
|
1881
1839
|
throw new Error("Miden client is not ready");
|
|
@@ -1887,7 +1845,7 @@ function useCreateWallet() {
|
|
|
1887
1845
|
options.storageMode ?? DEFAULTS.STORAGE_MODE
|
|
1888
1846
|
);
|
|
1889
1847
|
const mutable = options.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
1890
|
-
const authScheme =
|
|
1848
|
+
const authScheme = resolveAuthScheme(
|
|
1891
1849
|
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
1892
1850
|
);
|
|
1893
1851
|
const newWallet = await runExclusiveSafe(async () => {
|
|
@@ -1914,7 +1872,7 @@ function useCreateWallet() {
|
|
|
1914
1872
|
},
|
|
1915
1873
|
[client, isReady, runExclusive, setAccounts]
|
|
1916
1874
|
);
|
|
1917
|
-
const reset = (
|
|
1875
|
+
const reset = useCallback9(() => {
|
|
1918
1876
|
setWallet(null);
|
|
1919
1877
|
setIsCreating(false);
|
|
1920
1878
|
setError(null);
|
|
@@ -1930,27 +1888,30 @@ function useCreateWallet() {
|
|
|
1930
1888
|
function getStorageMode(mode) {
|
|
1931
1889
|
switch (mode) {
|
|
1932
1890
|
case "private":
|
|
1933
|
-
return
|
|
1891
|
+
return AccountStorageMode.private();
|
|
1934
1892
|
case "public":
|
|
1935
|
-
return
|
|
1893
|
+
return AccountStorageMode.public();
|
|
1936
1894
|
case "network":
|
|
1937
|
-
return
|
|
1895
|
+
return AccountStorageMode.network();
|
|
1938
1896
|
default:
|
|
1939
|
-
return
|
|
1897
|
+
return AccountStorageMode.private();
|
|
1940
1898
|
}
|
|
1941
1899
|
}
|
|
1942
1900
|
|
|
1943
1901
|
// src/hooks/useCreateFaucet.ts
|
|
1944
|
-
|
|
1945
|
-
|
|
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";
|
|
1946
1907
|
function useCreateFaucet() {
|
|
1947
1908
|
const { client, isReady, runExclusive } = useMiden();
|
|
1948
1909
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
1949
1910
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
1950
|
-
const [faucet, setFaucet] = (
|
|
1951
|
-
const [isCreating, setIsCreating] = (
|
|
1952
|
-
const [error, setError] = (
|
|
1953
|
-
const createFaucet = (
|
|
1911
|
+
const [faucet, setFaucet] = useState8(null);
|
|
1912
|
+
const [isCreating, setIsCreating] = useState8(false);
|
|
1913
|
+
const [error, setError] = useState8(null);
|
|
1914
|
+
const createFaucet = useCallback10(
|
|
1954
1915
|
async (options) => {
|
|
1955
1916
|
if (!client || !isReady) {
|
|
1956
1917
|
throw new Error("Miden client is not ready");
|
|
@@ -1962,7 +1923,7 @@ function useCreateFaucet() {
|
|
|
1962
1923
|
options.storageMode ?? DEFAULTS.STORAGE_MODE
|
|
1963
1924
|
);
|
|
1964
1925
|
const decimals = options.decimals ?? DEFAULTS.FAUCET_DECIMALS;
|
|
1965
|
-
const authScheme = (
|
|
1926
|
+
const authScheme = resolveAuthScheme2(
|
|
1966
1927
|
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
1967
1928
|
);
|
|
1968
1929
|
const newFaucet = await runExclusiveSafe(async () => {
|
|
@@ -1991,7 +1952,7 @@ function useCreateFaucet() {
|
|
|
1991
1952
|
},
|
|
1992
1953
|
[client, isReady, runExclusive, setAccounts]
|
|
1993
1954
|
);
|
|
1994
|
-
const reset = (
|
|
1955
|
+
const reset = useCallback10(() => {
|
|
1995
1956
|
setFaucet(null);
|
|
1996
1957
|
setIsCreating(false);
|
|
1997
1958
|
setError(null);
|
|
@@ -2007,19 +1968,19 @@ function useCreateFaucet() {
|
|
|
2007
1968
|
function getStorageMode2(mode) {
|
|
2008
1969
|
switch (mode) {
|
|
2009
1970
|
case "private":
|
|
2010
|
-
return
|
|
1971
|
+
return AccountStorageMode2.private();
|
|
2011
1972
|
case "public":
|
|
2012
|
-
return
|
|
1973
|
+
return AccountStorageMode2.public();
|
|
2013
1974
|
case "network":
|
|
2014
|
-
return
|
|
1975
|
+
return AccountStorageMode2.network();
|
|
2015
1976
|
default:
|
|
2016
|
-
return
|
|
1977
|
+
return AccountStorageMode2.private();
|
|
2017
1978
|
}
|
|
2018
1979
|
}
|
|
2019
1980
|
|
|
2020
1981
|
// src/hooks/useImportAccount.ts
|
|
2021
|
-
|
|
2022
|
-
|
|
1982
|
+
import { useCallback as useCallback11, useState as useState9 } from "react";
|
|
1983
|
+
import { AccountFile, resolveAuthScheme as resolveAuthScheme3 } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2023
1984
|
|
|
2024
1985
|
// src/utils/errors.ts
|
|
2025
1986
|
var MidenError = class extends Error {
|
|
@@ -2077,10 +2038,10 @@ function wrapWasmError(e) {
|
|
|
2077
2038
|
function useImportAccount() {
|
|
2078
2039
|
const { client, isReady, signerConnected } = useMiden();
|
|
2079
2040
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
2080
|
-
const [account, setAccount] = (
|
|
2081
|
-
const [isImporting, setIsImporting] = (
|
|
2082
|
-
const [error, setError] = (
|
|
2083
|
-
const importAccount = (
|
|
2041
|
+
const [account, setAccount] = useState9(null);
|
|
2042
|
+
const [isImporting, setIsImporting] = useState9(false);
|
|
2043
|
+
const [error, setError] = useState9(null);
|
|
2044
|
+
const importAccount = useCallback11(
|
|
2084
2045
|
async (options) => {
|
|
2085
2046
|
if (!client || !isReady) {
|
|
2086
2047
|
throw new Error("Miden client is not ready");
|
|
@@ -2152,7 +2113,7 @@ function useImportAccount() {
|
|
|
2152
2113
|
}
|
|
2153
2114
|
case "seed": {
|
|
2154
2115
|
const mutable = options.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
2155
|
-
const authScheme = (
|
|
2116
|
+
const authScheme = resolveAuthScheme3(
|
|
2156
2117
|
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
2157
2118
|
);
|
|
2158
2119
|
return await client.importPublicAccountFromSeed(
|
|
@@ -2178,7 +2139,7 @@ function useImportAccount() {
|
|
|
2178
2139
|
},
|
|
2179
2140
|
[client, isReady, setAccounts, signerConnected]
|
|
2180
2141
|
);
|
|
2181
|
-
const reset = (
|
|
2142
|
+
const reset = useCallback11(() => {
|
|
2182
2143
|
setAccount(null);
|
|
2183
2144
|
setIsImporting(false);
|
|
2184
2145
|
setError(null);
|
|
@@ -2193,10 +2154,10 @@ function useImportAccount() {
|
|
|
2193
2154
|
}
|
|
2194
2155
|
async function resolveAccountFile(file) {
|
|
2195
2156
|
if (file instanceof Uint8Array) {
|
|
2196
|
-
return
|
|
2157
|
+
return AccountFile.deserialize(file);
|
|
2197
2158
|
}
|
|
2198
2159
|
if (file instanceof ArrayBuffer) {
|
|
2199
|
-
return
|
|
2160
|
+
return AccountFile.deserialize(new Uint8Array(file));
|
|
2200
2161
|
}
|
|
2201
2162
|
return file;
|
|
2202
2163
|
}
|
|
@@ -2225,17 +2186,25 @@ function bytesEqual(left, right) {
|
|
|
2225
2186
|
}
|
|
2226
2187
|
|
|
2227
2188
|
// src/hooks/useSend.ts
|
|
2228
|
-
|
|
2229
|
-
|
|
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";
|
|
2230
2199
|
function useSend() {
|
|
2231
2200
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2232
2201
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2233
|
-
const isBusyRef = (
|
|
2234
|
-
const [result, setResult] = (
|
|
2235
|
-
const [isLoading, setIsLoading] = (
|
|
2236
|
-
const [stage, setStage] = (
|
|
2237
|
-
const [error, setError] = (
|
|
2238
|
-
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(
|
|
2239
2208
|
async (options) => {
|
|
2240
2209
|
if (!client || !isReady) {
|
|
2241
2210
|
throw new Error("Miden client is not ready");
|
|
@@ -2293,26 +2262,26 @@ function useSend() {
|
|
|
2293
2262
|
const fromId = parseAccountId(options.from);
|
|
2294
2263
|
const toId = parseAccountId(options.to);
|
|
2295
2264
|
const assetObj = parseAccountId(assetId);
|
|
2296
|
-
const assets = new
|
|
2297
|
-
new
|
|
2265
|
+
const assets = new NoteAssets([
|
|
2266
|
+
new FungibleAsset(assetObj, BigInt(amount))
|
|
2298
2267
|
]);
|
|
2299
|
-
const p2idNote =
|
|
2268
|
+
const p2idNote = Note.createP2IDNote(
|
|
2300
2269
|
fromId,
|
|
2301
2270
|
toId,
|
|
2302
2271
|
assets,
|
|
2303
2272
|
noteType,
|
|
2304
|
-
new
|
|
2273
|
+
new NoteAttachment2()
|
|
2305
2274
|
);
|
|
2306
|
-
const ownOutputs = new
|
|
2275
|
+
const ownOutputs = new NoteArray();
|
|
2307
2276
|
ownOutputs.push(p2idNote);
|
|
2308
|
-
const txRequest = new
|
|
2277
|
+
const txRequest = new TransactionRequestBuilder().withOwnOutputNotes(ownOutputs).build();
|
|
2309
2278
|
const execFromId = parseAccountId(options.from);
|
|
2310
2279
|
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
2311
2280
|
execFromId,
|
|
2312
2281
|
txRequest,
|
|
2313
2282
|
prover
|
|
2314
2283
|
) : await client.submitNewTransaction(execFromId, txRequest);
|
|
2315
|
-
return { txId: txId.
|
|
2284
|
+
return { txId: txId.toHex(), note: p2idNote };
|
|
2316
2285
|
});
|
|
2317
2286
|
setStage("complete");
|
|
2318
2287
|
setResult(returnResult);
|
|
@@ -2326,17 +2295,17 @@ function useSend() {
|
|
|
2326
2295
|
let txRequest;
|
|
2327
2296
|
if (hasAttachment) {
|
|
2328
2297
|
const attachment = createNoteAttachment(options.attachment);
|
|
2329
|
-
const assets = new
|
|
2330
|
-
new
|
|
2298
|
+
const assets = new NoteAssets([
|
|
2299
|
+
new FungibleAsset(assetIdObj, amount)
|
|
2331
2300
|
]);
|
|
2332
|
-
const note =
|
|
2301
|
+
const note = Note.createP2IDNote(
|
|
2333
2302
|
fromAccountId,
|
|
2334
2303
|
toAccountId,
|
|
2335
2304
|
assets,
|
|
2336
2305
|
noteType,
|
|
2337
2306
|
attachment
|
|
2338
2307
|
);
|
|
2339
|
-
txRequest = new
|
|
2308
|
+
txRequest = new TransactionRequestBuilder().withOwnOutputNotes(new NoteArray([note])).build();
|
|
2340
2309
|
} else {
|
|
2341
2310
|
txRequest = client.newSendTransactionRequest(
|
|
2342
2311
|
fromAccountId,
|
|
@@ -2364,15 +2333,14 @@ function useSend() {
|
|
|
2364
2333
|
() => client.submitProvenTransaction(provenTransaction, txResult)
|
|
2365
2334
|
);
|
|
2366
2335
|
const txIdHex = txResult.id().toHex();
|
|
2367
|
-
const txIdString = txResult.id().toString();
|
|
2368
2336
|
let fullNote = null;
|
|
2369
|
-
if (noteType ===
|
|
2337
|
+
if (noteType === NoteType2.Private) {
|
|
2370
2338
|
fullNote = extractFullNote(txResult);
|
|
2371
2339
|
}
|
|
2372
2340
|
await runExclusiveSafe(
|
|
2373
2341
|
() => client.applyTransaction(txResult, submissionHeight)
|
|
2374
2342
|
);
|
|
2375
|
-
if (noteType ===
|
|
2343
|
+
if (noteType === NoteType2.Private) {
|
|
2376
2344
|
if (!fullNote) {
|
|
2377
2345
|
throw new Error("Missing full note for private send");
|
|
2378
2346
|
}
|
|
@@ -2388,7 +2356,7 @@ function useSend() {
|
|
|
2388
2356
|
);
|
|
2389
2357
|
}
|
|
2390
2358
|
const sendResult = {
|
|
2391
|
-
txId:
|
|
2359
|
+
txId: txIdHex,
|
|
2392
2360
|
note: null
|
|
2393
2361
|
};
|
|
2394
2362
|
setStage("complete");
|
|
@@ -2407,7 +2375,7 @@ function useSend() {
|
|
|
2407
2375
|
},
|
|
2408
2376
|
[client, isReady, prover, runExclusive, sync]
|
|
2409
2377
|
);
|
|
2410
|
-
const reset = (
|
|
2378
|
+
const reset = useCallback12(() => {
|
|
2411
2379
|
setResult(null);
|
|
2412
2380
|
setIsLoading(false);
|
|
2413
2381
|
setStage("idle");
|
|
@@ -2434,16 +2402,24 @@ function extractFullNote(txResult) {
|
|
|
2434
2402
|
}
|
|
2435
2403
|
|
|
2436
2404
|
// src/hooks/useMultiSend.ts
|
|
2437
|
-
|
|
2438
|
-
|
|
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";
|
|
2439
2415
|
function useMultiSend() {
|
|
2440
2416
|
const { client, isReady, sync, prover, signerConnected } = useMiden();
|
|
2441
|
-
const isBusyRef = (
|
|
2442
|
-
const [result, setResult] = (
|
|
2443
|
-
const [isLoading, setIsLoading] = (
|
|
2444
|
-
const [stage, setStage] = (
|
|
2445
|
-
const [error, setError] = (
|
|
2446
|
-
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(
|
|
2447
2423
|
async (options) => {
|
|
2448
2424
|
if (!client || !isReady) {
|
|
2449
2425
|
throw new Error("Miden client is not ready");
|
|
@@ -2472,12 +2448,12 @@ function useMultiSend() {
|
|
|
2472
2448
|
const iterSenderId = parseAccountId(options.from);
|
|
2473
2449
|
const iterAssetId = parseAccountId(options.assetId);
|
|
2474
2450
|
const receiverId = parseAccountId(to);
|
|
2475
|
-
const assets = new
|
|
2476
|
-
new
|
|
2451
|
+
const assets = new NoteAssets2([
|
|
2452
|
+
new FungibleAsset2(iterAssetId, BigInt(amount))
|
|
2477
2453
|
]);
|
|
2478
2454
|
const resolvedNoteType = recipientNoteType ? getNoteType(recipientNoteType) : noteType;
|
|
2479
|
-
const noteAttachment = attachment !== void 0 && attachment !== null ? createNoteAttachment(attachment) : new
|
|
2480
|
-
const note =
|
|
2455
|
+
const noteAttachment = attachment !== void 0 && attachment !== null ? createNoteAttachment(attachment) : new NoteAttachment3();
|
|
2456
|
+
const note = Note2.createP2IDNote(
|
|
2481
2457
|
iterSenderId,
|
|
2482
2458
|
receiverId,
|
|
2483
2459
|
assets,
|
|
@@ -2492,7 +2468,11 @@ function useMultiSend() {
|
|
|
2492
2468
|
};
|
|
2493
2469
|
}
|
|
2494
2470
|
);
|
|
2495
|
-
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();
|
|
2496
2476
|
const txSenderId = parseAccountId(options.from);
|
|
2497
2477
|
const txResult = await client.executeTransaction(txSenderId, txRequest);
|
|
2498
2478
|
setStage("proving");
|
|
@@ -2509,9 +2489,8 @@ function useMultiSend() {
|
|
|
2509
2489
|
txResult
|
|
2510
2490
|
);
|
|
2511
2491
|
const txIdHex = txResult.id().toHex();
|
|
2512
|
-
const txIdString = txResult.id().toString();
|
|
2513
2492
|
await client.applyTransaction(txResult, submissionHeight);
|
|
2514
|
-
const hasPrivate = outputs.some((o) => o.noteType ===
|
|
2493
|
+
const hasPrivate = outputs.some((o) => o.noteType === NoteType3.Private);
|
|
2515
2494
|
if (hasPrivate) {
|
|
2516
2495
|
await waitForTransactionCommit(
|
|
2517
2496
|
client,
|
|
@@ -2519,7 +2498,7 @@ function useMultiSend() {
|
|
|
2519
2498
|
txIdHex
|
|
2520
2499
|
);
|
|
2521
2500
|
for (const output of outputs) {
|
|
2522
|
-
if (output.noteType ===
|
|
2501
|
+
if (output.noteType === NoteType3.Private) {
|
|
2523
2502
|
await client.sendPrivateNote(
|
|
2524
2503
|
output.note,
|
|
2525
2504
|
output.recipientAddress
|
|
@@ -2527,7 +2506,7 @@ function useMultiSend() {
|
|
|
2527
2506
|
}
|
|
2528
2507
|
}
|
|
2529
2508
|
}
|
|
2530
|
-
const txSummary = { transactionId:
|
|
2509
|
+
const txSummary = { transactionId: txIdHex };
|
|
2531
2510
|
setStage("complete");
|
|
2532
2511
|
setResult(txSummary);
|
|
2533
2512
|
await sync();
|
|
@@ -2544,7 +2523,7 @@ function useMultiSend() {
|
|
|
2544
2523
|
},
|
|
2545
2524
|
[client, isReady, prover, signerConnected, sync]
|
|
2546
2525
|
);
|
|
2547
|
-
const reset = (
|
|
2526
|
+
const reset = useCallback13(() => {
|
|
2548
2527
|
setResult(null);
|
|
2549
2528
|
setIsLoading(false);
|
|
2550
2529
|
setStage("idle");
|
|
@@ -2561,11 +2540,11 @@ function useMultiSend() {
|
|
|
2561
2540
|
}
|
|
2562
2541
|
|
|
2563
2542
|
// src/hooks/useWaitForCommit.ts
|
|
2564
|
-
|
|
2565
|
-
|
|
2543
|
+
import { useCallback as useCallback14 } from "react";
|
|
2544
|
+
import { TransactionFilter as TransactionFilter3 } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2566
2545
|
function useWaitForCommit() {
|
|
2567
2546
|
const { client, isReady } = useMiden();
|
|
2568
|
-
const waitForCommit = (
|
|
2547
|
+
const waitForCommit = useCallback14(
|
|
2569
2548
|
async (txId, options) => {
|
|
2570
2549
|
if (!client || !isReady) {
|
|
2571
2550
|
throw new Error("Miden client is not ready");
|
|
@@ -2579,7 +2558,7 @@ function useWaitForCommit() {
|
|
|
2579
2558
|
while (Date.now() < deadline) {
|
|
2580
2559
|
await client.syncState();
|
|
2581
2560
|
const records = await client.getTransactions(
|
|
2582
|
-
typeof txId === "string" ?
|
|
2561
|
+
typeof txId === "string" ? TransactionFilter3.all() : TransactionFilter3.ids([txId])
|
|
2583
2562
|
);
|
|
2584
2563
|
const record = records.find(
|
|
2585
2564
|
(item) => normalizeHex3(item.id().toHex()) === targetHex
|
|
@@ -2608,11 +2587,11 @@ function normalizeHex3(value) {
|
|
|
2608
2587
|
}
|
|
2609
2588
|
|
|
2610
2589
|
// src/hooks/useWaitForNotes.ts
|
|
2611
|
-
|
|
2590
|
+
import { useCallback as useCallback15 } from "react";
|
|
2612
2591
|
function useWaitForNotes() {
|
|
2613
2592
|
const { client, isReady, runExclusive } = useMiden();
|
|
2614
2593
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2615
|
-
const waitForConsumableNotes = (
|
|
2594
|
+
const waitForConsumableNotes = useCallback15(
|
|
2616
2595
|
async (options) => {
|
|
2617
2596
|
if (!client || !isReady) {
|
|
2618
2597
|
throw new Error("Miden client is not ready");
|
|
@@ -2643,15 +2622,15 @@ function useWaitForNotes() {
|
|
|
2643
2622
|
}
|
|
2644
2623
|
|
|
2645
2624
|
// src/hooks/useMint.ts
|
|
2646
|
-
|
|
2625
|
+
import { useCallback as useCallback16, useState as useState12 } from "react";
|
|
2647
2626
|
function useMint() {
|
|
2648
2627
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2649
2628
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2650
|
-
const [result, setResult] = (
|
|
2651
|
-
const [isLoading, setIsLoading] = (
|
|
2652
|
-
const [stage, setStage] = (
|
|
2653
|
-
const [error, setError] = (
|
|
2654
|
-
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(
|
|
2655
2634
|
async (options) => {
|
|
2656
2635
|
if (!client || !isReady) {
|
|
2657
2636
|
throw new Error("Miden client is not ready");
|
|
@@ -2676,7 +2655,7 @@ function useMint() {
|
|
|
2676
2655
|
txRequest,
|
|
2677
2656
|
prover
|
|
2678
2657
|
) : await client.submitNewTransaction(faucetIdObj, txRequest);
|
|
2679
|
-
return { transactionId: txId.
|
|
2658
|
+
return { transactionId: txId.toHex() };
|
|
2680
2659
|
});
|
|
2681
2660
|
setStage("complete");
|
|
2682
2661
|
setResult(txResult);
|
|
@@ -2693,7 +2672,7 @@ function useMint() {
|
|
|
2693
2672
|
},
|
|
2694
2673
|
[client, isReady, prover, runExclusive, sync]
|
|
2695
2674
|
);
|
|
2696
|
-
const reset = (
|
|
2675
|
+
const reset = useCallback16(() => {
|
|
2697
2676
|
setResult(null);
|
|
2698
2677
|
setIsLoading(false);
|
|
2699
2678
|
setStage("idle");
|
|
@@ -2710,16 +2689,16 @@ function useMint() {
|
|
|
2710
2689
|
}
|
|
2711
2690
|
|
|
2712
2691
|
// src/hooks/useConsume.ts
|
|
2713
|
-
|
|
2714
|
-
|
|
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";
|
|
2715
2694
|
function useConsume() {
|
|
2716
2695
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2717
2696
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2718
|
-
const [result, setResult] = (
|
|
2719
|
-
const [isLoading, setIsLoading] = (
|
|
2720
|
-
const [stage, setStage] = (
|
|
2721
|
-
const [error, setError] = (
|
|
2722
|
-
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(
|
|
2723
2702
|
async (options) => {
|
|
2724
2703
|
if (!client || !isReady) {
|
|
2725
2704
|
throw new Error("Miden client is not ready");
|
|
@@ -2741,7 +2720,7 @@ function useConsume() {
|
|
|
2741
2720
|
const item = options.notes[i];
|
|
2742
2721
|
if (typeof item === "string") {
|
|
2743
2722
|
lookupIndices.push(i);
|
|
2744
|
-
lookupIds.push(
|
|
2723
|
+
lookupIds.push(NoteId.fromHex(item));
|
|
2745
2724
|
} else if (item !== null && typeof item === "object" && typeof item.toNote === "function") {
|
|
2746
2725
|
resolved[i] = item.toNote();
|
|
2747
2726
|
} else if (item !== null && typeof item === "object" && typeof item.id === "function") {
|
|
@@ -2752,16 +2731,17 @@ function useConsume() {
|
|
|
2752
2731
|
}
|
|
2753
2732
|
}
|
|
2754
2733
|
if (lookupIds.length > 0) {
|
|
2755
|
-
const
|
|
2734
|
+
const lookupIdStrings = lookupIds.map((id) => id.toString());
|
|
2735
|
+
const filter = new NoteFilter3(NoteFilterTypes2.List, lookupIds);
|
|
2756
2736
|
const noteRecords = await client.getInputNotes(filter);
|
|
2757
|
-
if (noteRecords.length !==
|
|
2737
|
+
if (noteRecords.length !== lookupIdStrings.length) {
|
|
2758
2738
|
throw new Error("Some notes could not be found for provided IDs");
|
|
2759
2739
|
}
|
|
2760
2740
|
const recordById = new Map(
|
|
2761
2741
|
noteRecords.map((r) => [r.id().toString(), r])
|
|
2762
2742
|
);
|
|
2763
2743
|
for (let j = 0; j < lookupIndices.length; j++) {
|
|
2764
|
-
const record = recordById.get(
|
|
2744
|
+
const record = recordById.get(lookupIdStrings[j]);
|
|
2765
2745
|
if (!record) {
|
|
2766
2746
|
throw new Error(
|
|
2767
2747
|
"Some notes could not be found for provided IDs"
|
|
@@ -2783,7 +2763,7 @@ function useConsume() {
|
|
|
2783
2763
|
txRequest,
|
|
2784
2764
|
prover
|
|
2785
2765
|
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2786
|
-
return { transactionId: txId.
|
|
2766
|
+
return { transactionId: txId.toHex() };
|
|
2787
2767
|
});
|
|
2788
2768
|
setStage("complete");
|
|
2789
2769
|
setResult(txResult);
|
|
@@ -2800,7 +2780,7 @@ function useConsume() {
|
|
|
2800
2780
|
},
|
|
2801
2781
|
[client, isReady, prover, runExclusive, sync]
|
|
2802
2782
|
);
|
|
2803
|
-
const reset = (
|
|
2783
|
+
const reset = useCallback17(() => {
|
|
2804
2784
|
setResult(null);
|
|
2805
2785
|
setIsLoading(false);
|
|
2806
2786
|
setStage("idle");
|
|
@@ -2817,15 +2797,15 @@ function useConsume() {
|
|
|
2817
2797
|
}
|
|
2818
2798
|
|
|
2819
2799
|
// src/hooks/useSwap.ts
|
|
2820
|
-
|
|
2800
|
+
import { useCallback as useCallback18, useState as useState14 } from "react";
|
|
2821
2801
|
function useSwap() {
|
|
2822
2802
|
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2823
2803
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2824
|
-
const [result, setResult] = (
|
|
2825
|
-
const [isLoading, setIsLoading] = (
|
|
2826
|
-
const [stage, setStage] = (
|
|
2827
|
-
const [error, setError] = (
|
|
2828
|
-
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(
|
|
2829
2809
|
async (options) => {
|
|
2830
2810
|
if (!client || !isReady) {
|
|
2831
2811
|
throw new Error("Miden client is not ready");
|
|
@@ -2857,7 +2837,7 @@ function useSwap() {
|
|
|
2857
2837
|
txRequest,
|
|
2858
2838
|
prover
|
|
2859
2839
|
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2860
|
-
return { transactionId: txId.
|
|
2840
|
+
return { transactionId: txId.toHex() };
|
|
2861
2841
|
});
|
|
2862
2842
|
setStage("complete");
|
|
2863
2843
|
setResult(txResult);
|
|
@@ -2874,7 +2854,7 @@ function useSwap() {
|
|
|
2874
2854
|
},
|
|
2875
2855
|
[client, isReady, prover, runExclusive, sync]
|
|
2876
2856
|
);
|
|
2877
|
-
const reset = (
|
|
2857
|
+
const reset = useCallback18(() => {
|
|
2878
2858
|
setResult(null);
|
|
2879
2859
|
setIsLoading(false);
|
|
2880
2860
|
setStage("idle");
|
|
@@ -2891,16 +2871,16 @@ function useSwap() {
|
|
|
2891
2871
|
}
|
|
2892
2872
|
|
|
2893
2873
|
// src/hooks/useTransaction.ts
|
|
2894
|
-
|
|
2874
|
+
import { useCallback as useCallback19, useRef as useRef6, useState as useState15 } from "react";
|
|
2895
2875
|
|
|
2896
2876
|
// src/utils/transactions.ts
|
|
2897
|
-
|
|
2877
|
+
import { NoteType as NoteType4, TransactionFilter as TransactionFilter4 } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
2898
2878
|
async function waitForTransactionCommit2(client, runExclusiveSafe, txId, maxWaitMs = 1e4, delayMs = 1e3) {
|
|
2899
2879
|
let waited = 0;
|
|
2900
2880
|
while (waited < maxWaitMs) {
|
|
2901
2881
|
await runExclusiveSafe(() => client.syncState());
|
|
2902
2882
|
const [record] = await runExclusiveSafe(
|
|
2903
|
-
() => client.getTransactions(
|
|
2883
|
+
() => client.getTransactions(TransactionFilter4.ids([txId]))
|
|
2904
2884
|
);
|
|
2905
2885
|
if (record) {
|
|
2906
2886
|
const status = record.transactionStatus();
|
|
@@ -2922,7 +2902,7 @@ function extractFullNotes(txResult) {
|
|
|
2922
2902
|
const notes = executedTx?.outputNotes?.().notes?.() ?? [];
|
|
2923
2903
|
const result = [];
|
|
2924
2904
|
for (const note of notes) {
|
|
2925
|
-
if (note.noteType?.() ===
|
|
2905
|
+
if (note.noteType?.() === NoteType4.Private) {
|
|
2926
2906
|
const full = note.intoFull?.();
|
|
2927
2907
|
if (full) result.push(full);
|
|
2928
2908
|
}
|
|
@@ -2937,12 +2917,12 @@ function extractFullNotes(txResult) {
|
|
|
2937
2917
|
function useTransaction() {
|
|
2938
2918
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
2939
2919
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2940
|
-
const isBusyRef = (
|
|
2941
|
-
const [result, setResult] = (
|
|
2942
|
-
const [isLoading, setIsLoading] = (
|
|
2943
|
-
const [stage, setStage] = (
|
|
2944
|
-
const [error, setError] = (
|
|
2945
|
-
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(
|
|
2946
2926
|
async (options) => {
|
|
2947
2927
|
if (!client || !isReady) {
|
|
2948
2928
|
throw new Error("Miden client is not ready");
|
|
@@ -2992,7 +2972,7 @@ function useTransaction() {
|
|
|
2992
2972
|
);
|
|
2993
2973
|
}
|
|
2994
2974
|
}
|
|
2995
|
-
const txSummary = { transactionId: txId.
|
|
2975
|
+
const txSummary = { transactionId: txId.toHex() };
|
|
2996
2976
|
setStage("complete");
|
|
2997
2977
|
setResult(txSummary);
|
|
2998
2978
|
await sync();
|
|
@@ -3009,7 +2989,7 @@ function useTransaction() {
|
|
|
3009
2989
|
},
|
|
3010
2990
|
[client, isReady, runExclusive, sync]
|
|
3011
2991
|
);
|
|
3012
|
-
const reset = (
|
|
2992
|
+
const reset = useCallback19(() => {
|
|
3013
2993
|
setResult(null);
|
|
3014
2994
|
setIsLoading(false);
|
|
3015
2995
|
setStage("idle");
|
|
@@ -3032,19 +3012,24 @@ async function resolveRequest(request, client) {
|
|
|
3032
3012
|
}
|
|
3033
3013
|
|
|
3034
3014
|
// src/hooks/useExecuteProgram.ts
|
|
3035
|
-
|
|
3036
|
-
|
|
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";
|
|
3037
3022
|
function isForeignAccountWrapper(fa) {
|
|
3038
3023
|
return fa !== null && typeof fa === "object" && "id" in fa && typeof fa.id !== "function";
|
|
3039
3024
|
}
|
|
3040
3025
|
function useExecuteProgram() {
|
|
3041
3026
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
3042
3027
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3043
|
-
const isBusyRef = (
|
|
3044
|
-
const [result, setResult] = (
|
|
3045
|
-
const [isLoading, setIsLoading] = (
|
|
3046
|
-
const [error, setError] = (
|
|
3047
|
-
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(
|
|
3048
3033
|
async (options) => {
|
|
3049
3034
|
if (!client || !isReady) {
|
|
3050
3035
|
throw new Error("Miden client is not ready");
|
|
@@ -3064,18 +3049,18 @@ function useExecuteProgram() {
|
|
|
3064
3049
|
}
|
|
3065
3050
|
const programResult = await runExclusiveSafe(async () => {
|
|
3066
3051
|
const accountIdObj = parseAccountId(options.accountId);
|
|
3067
|
-
const adviceInputs = options.adviceInputs ?? new
|
|
3052
|
+
const adviceInputs = options.adviceInputs ?? new AdviceInputs();
|
|
3068
3053
|
let foreignAccountsArray;
|
|
3069
3054
|
if (options.foreignAccounts?.length) {
|
|
3070
3055
|
const accounts = options.foreignAccounts.map((fa) => {
|
|
3071
3056
|
const wrapper = isForeignAccountWrapper(fa);
|
|
3072
3057
|
const id = parseAccountId(wrapper ? fa.id : fa);
|
|
3073
|
-
const storage = wrapper && fa.storage ? fa.storage : new
|
|
3074
|
-
return
|
|
3058
|
+
const storage = wrapper && fa.storage ? fa.storage : new AccountStorageRequirements();
|
|
3059
|
+
return ForeignAccount.public(id, storage);
|
|
3075
3060
|
});
|
|
3076
|
-
foreignAccountsArray = new
|
|
3061
|
+
foreignAccountsArray = new ForeignAccountArray(accounts);
|
|
3077
3062
|
} else {
|
|
3078
|
-
foreignAccountsArray = new
|
|
3063
|
+
foreignAccountsArray = new ForeignAccountArray();
|
|
3079
3064
|
}
|
|
3080
3065
|
const feltArray = await client.executeProgram(
|
|
3081
3066
|
accountIdObj,
|
|
@@ -3103,7 +3088,7 @@ function useExecuteProgram() {
|
|
|
3103
3088
|
},
|
|
3104
3089
|
[client, isReady, runExclusive, sync]
|
|
3105
3090
|
);
|
|
3106
|
-
const reset = (
|
|
3091
|
+
const reset = useCallback20(() => {
|
|
3107
3092
|
setResult(null);
|
|
3108
3093
|
setIsLoading(false);
|
|
3109
3094
|
setError(null);
|
|
@@ -3118,29 +3103,29 @@ function useExecuteProgram() {
|
|
|
3118
3103
|
}
|
|
3119
3104
|
|
|
3120
3105
|
// src/hooks/useCompile.ts
|
|
3121
|
-
|
|
3122
|
-
|
|
3106
|
+
import { useCallback as useCallback21, useMemo as useMemo8 } from "react";
|
|
3107
|
+
import { CompilerResource, getWasmOrThrow } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3123
3108
|
function useCompile() {
|
|
3124
3109
|
const { client, isReady } = useMiden();
|
|
3125
|
-
const resource = (
|
|
3126
|
-
() => client && isReady ? new
|
|
3110
|
+
const resource = useMemo8(
|
|
3111
|
+
() => client && isReady ? new CompilerResource(client, getWasmOrThrow) : null,
|
|
3127
3112
|
[client, isReady]
|
|
3128
3113
|
);
|
|
3129
|
-
const requireResource = (
|
|
3114
|
+
const requireResource = useCallback21(() => {
|
|
3130
3115
|
if (!resource) {
|
|
3131
3116
|
throw new Error("Miden client is not ready");
|
|
3132
3117
|
}
|
|
3133
3118
|
return resource;
|
|
3134
3119
|
}, [resource]);
|
|
3135
|
-
const component = (
|
|
3120
|
+
const component = useCallback21(
|
|
3136
3121
|
async (options) => requireResource().component(options),
|
|
3137
3122
|
[requireResource]
|
|
3138
3123
|
);
|
|
3139
|
-
const txScript = (
|
|
3124
|
+
const txScript = useCallback21(
|
|
3140
3125
|
async (options) => requireResource().txScript(options),
|
|
3141
3126
|
[requireResource]
|
|
3142
3127
|
);
|
|
3143
|
-
const noteScript = (
|
|
3128
|
+
const noteScript = useCallback21(
|
|
3144
3129
|
async (options) => requireResource().noteScript(options),
|
|
3145
3130
|
[requireResource]
|
|
3146
3131
|
);
|
|
@@ -3148,27 +3133,30 @@ function useCompile() {
|
|
|
3148
3133
|
}
|
|
3149
3134
|
|
|
3150
3135
|
// src/hooks/useSessionAccount.ts
|
|
3151
|
-
|
|
3152
|
-
|
|
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";
|
|
3153
3141
|
function useSessionAccount(options) {
|
|
3154
3142
|
const { client, isReady, sync } = useMiden();
|
|
3155
3143
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
3156
|
-
const [sessionAccountId, setSessionAccountId] = (
|
|
3157
|
-
const [step, setStep] = (
|
|
3158
|
-
const [error, setError] = (
|
|
3159
|
-
const cancelledRef = (
|
|
3160
|
-
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);
|
|
3161
3149
|
const storagePrefix = options.storagePrefix ?? "miden-session";
|
|
3162
3150
|
const pollIntervalMs = options.pollIntervalMs ?? 3e3;
|
|
3163
3151
|
const maxWaitMs = options.maxWaitMs ?? 6e4;
|
|
3164
3152
|
const storageMode = options.walletOptions?.storageMode ?? "public";
|
|
3165
3153
|
const mutable = options.walletOptions?.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
3166
|
-
const authScheme = (
|
|
3154
|
+
const authScheme = resolveAuthScheme4(
|
|
3167
3155
|
options.walletOptions?.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
3168
3156
|
);
|
|
3169
|
-
const fundRef = (
|
|
3157
|
+
const fundRef = useRef8(options.fund);
|
|
3170
3158
|
fundRef.current = options.fund;
|
|
3171
|
-
(
|
|
3159
|
+
useEffect9(() => {
|
|
3172
3160
|
try {
|
|
3173
3161
|
const stored = localStorage.getItem(`${storagePrefix}:accountId`);
|
|
3174
3162
|
const storedReady = localStorage.getItem(`${storagePrefix}:ready`);
|
|
@@ -3185,7 +3173,7 @@ function useSessionAccount(options) {
|
|
|
3185
3173
|
localStorage.removeItem(`${storagePrefix}:ready`);
|
|
3186
3174
|
}
|
|
3187
3175
|
}, [storagePrefix]);
|
|
3188
|
-
const initialize = (
|
|
3176
|
+
const initialize = useCallback22(async () => {
|
|
3189
3177
|
if (!client || !isReady) {
|
|
3190
3178
|
throw new Error("Miden client is not ready");
|
|
3191
3179
|
}
|
|
@@ -3216,13 +3204,14 @@ function useSessionAccount(options) {
|
|
|
3216
3204
|
setSessionAccountId(walletId);
|
|
3217
3205
|
localStorage.setItem(`${storagePrefix}:accountId`, walletId);
|
|
3218
3206
|
}
|
|
3207
|
+
const resolvedWalletId = walletId;
|
|
3219
3208
|
setStep("funding");
|
|
3220
|
-
await fundRef.current(
|
|
3209
|
+
await fundRef.current(resolvedWalletId);
|
|
3221
3210
|
if (cancelledRef.current) return;
|
|
3222
3211
|
setStep("consuming");
|
|
3223
3212
|
await waitAndConsume(
|
|
3224
3213
|
client,
|
|
3225
|
-
|
|
3214
|
+
resolvedWalletId,
|
|
3226
3215
|
pollIntervalMs,
|
|
3227
3216
|
maxWaitMs,
|
|
3228
3217
|
cancelledRef
|
|
@@ -3254,7 +3243,7 @@ function useSessionAccount(options) {
|
|
|
3254
3243
|
maxWaitMs,
|
|
3255
3244
|
setAccounts
|
|
3256
3245
|
]);
|
|
3257
|
-
const reset = (
|
|
3246
|
+
const reset = useCallback22(() => {
|
|
3258
3247
|
cancelledRef.current = true;
|
|
3259
3248
|
isBusyRef.current = false;
|
|
3260
3249
|
setSessionAccountId(null);
|
|
@@ -3275,11 +3264,11 @@ function useSessionAccount(options) {
|
|
|
3275
3264
|
function getStorageMode3(mode) {
|
|
3276
3265
|
switch (mode) {
|
|
3277
3266
|
case "private":
|
|
3278
|
-
return
|
|
3267
|
+
return AccountStorageMode3.private();
|
|
3279
3268
|
case "public":
|
|
3280
|
-
return
|
|
3269
|
+
return AccountStorageMode3.public();
|
|
3281
3270
|
default:
|
|
3282
|
-
return
|
|
3271
|
+
return AccountStorageMode3.public();
|
|
3283
3272
|
}
|
|
3284
3273
|
}
|
|
3285
3274
|
async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cancelledRef) {
|
|
@@ -3303,13 +3292,13 @@ async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cance
|
|
|
3303
3292
|
}
|
|
3304
3293
|
|
|
3305
3294
|
// src/hooks/useExportStore.ts
|
|
3306
|
-
|
|
3307
|
-
|
|
3295
|
+
import { useCallback as useCallback23, useState as useState18 } from "react";
|
|
3296
|
+
import { exportStore as sdkExportStore } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3308
3297
|
function useExportStore() {
|
|
3309
3298
|
const { client, isReady, runExclusive } = useMiden();
|
|
3310
|
-
const [isExporting, setIsExporting] = (
|
|
3311
|
-
const [error, setError] = (
|
|
3312
|
-
const exportStore = (
|
|
3299
|
+
const [isExporting, setIsExporting] = useState18(false);
|
|
3300
|
+
const [error, setError] = useState18(null);
|
|
3301
|
+
const exportStore = useCallback23(async () => {
|
|
3313
3302
|
if (!client || !isReady) {
|
|
3314
3303
|
throw new Error("Miden client is not ready");
|
|
3315
3304
|
}
|
|
@@ -3317,7 +3306,7 @@ function useExportStore() {
|
|
|
3317
3306
|
setError(null);
|
|
3318
3307
|
try {
|
|
3319
3308
|
const storeName = client.storeIdentifier();
|
|
3320
|
-
const snapshot = await runExclusive(() => (
|
|
3309
|
+
const snapshot = await runExclusive(() => sdkExportStore(storeName));
|
|
3321
3310
|
return snapshot;
|
|
3322
3311
|
} catch (err) {
|
|
3323
3312
|
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
@@ -3327,7 +3316,7 @@ function useExportStore() {
|
|
|
3327
3316
|
setIsExporting(false);
|
|
3328
3317
|
}
|
|
3329
3318
|
}, [client, isReady, runExclusive]);
|
|
3330
|
-
const reset = (
|
|
3319
|
+
const reset = useCallback23(() => {
|
|
3331
3320
|
setIsExporting(false);
|
|
3332
3321
|
setError(null);
|
|
3333
3322
|
}, []);
|
|
@@ -3340,13 +3329,13 @@ function useExportStore() {
|
|
|
3340
3329
|
}
|
|
3341
3330
|
|
|
3342
3331
|
// src/hooks/useImportStore.ts
|
|
3343
|
-
|
|
3344
|
-
|
|
3332
|
+
import { useCallback as useCallback24, useState as useState19 } from "react";
|
|
3333
|
+
import { importStore as sdkImportStore } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3345
3334
|
function useImportStore() {
|
|
3346
3335
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3347
|
-
const [isImporting, setIsImporting] = (
|
|
3348
|
-
const [error, setError] = (
|
|
3349
|
-
const importStore = (
|
|
3336
|
+
const [isImporting, setIsImporting] = useState19(false);
|
|
3337
|
+
const [error, setError] = useState19(null);
|
|
3338
|
+
const importStore = useCallback24(
|
|
3350
3339
|
async (storeDump, storeName, options) => {
|
|
3351
3340
|
if (!client || !isReady) {
|
|
3352
3341
|
throw new Error("Miden client is not ready");
|
|
@@ -3354,7 +3343,7 @@ function useImportStore() {
|
|
|
3354
3343
|
setIsImporting(true);
|
|
3355
3344
|
setError(null);
|
|
3356
3345
|
try {
|
|
3357
|
-
await runExclusive(() => (
|
|
3346
|
+
await runExclusive(() => sdkImportStore(storeName, storeDump));
|
|
3358
3347
|
if (!options?.skipSync) {
|
|
3359
3348
|
await sync();
|
|
3360
3349
|
}
|
|
@@ -3368,7 +3357,7 @@ function useImportStore() {
|
|
|
3368
3357
|
},
|
|
3369
3358
|
[client, isReady, runExclusive, sync]
|
|
3370
3359
|
);
|
|
3371
|
-
const reset = (
|
|
3360
|
+
const reset = useCallback24(() => {
|
|
3372
3361
|
setIsImporting(false);
|
|
3373
3362
|
setError(null);
|
|
3374
3363
|
}, []);
|
|
@@ -3381,13 +3370,13 @@ function useImportStore() {
|
|
|
3381
3370
|
}
|
|
3382
3371
|
|
|
3383
3372
|
// src/hooks/useImportNote.ts
|
|
3384
|
-
|
|
3385
|
-
|
|
3373
|
+
import { useCallback as useCallback25, useState as useState20 } from "react";
|
|
3374
|
+
import { NoteFile } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3386
3375
|
function useImportNote() {
|
|
3387
3376
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3388
|
-
const [isImporting, setIsImporting] = (
|
|
3389
|
-
const [error, setError] = (
|
|
3390
|
-
const importNote = (
|
|
3377
|
+
const [isImporting, setIsImporting] = useState20(false);
|
|
3378
|
+
const [error, setError] = useState20(null);
|
|
3379
|
+
const importNote = useCallback25(
|
|
3391
3380
|
async (noteBytes) => {
|
|
3392
3381
|
if (!client || !isReady) {
|
|
3393
3382
|
throw new Error("Miden client is not ready");
|
|
@@ -3395,7 +3384,7 @@ function useImportNote() {
|
|
|
3395
3384
|
setIsImporting(true);
|
|
3396
3385
|
setError(null);
|
|
3397
3386
|
try {
|
|
3398
|
-
const noteFile =
|
|
3387
|
+
const noteFile = NoteFile.deserialize(noteBytes);
|
|
3399
3388
|
const noteId = await runExclusive(
|
|
3400
3389
|
() => client.importNoteFile(noteFile)
|
|
3401
3390
|
);
|
|
@@ -3411,7 +3400,7 @@ function useImportNote() {
|
|
|
3411
3400
|
},
|
|
3412
3401
|
[client, isReady, runExclusive, sync]
|
|
3413
3402
|
);
|
|
3414
|
-
const reset = (
|
|
3403
|
+
const reset = useCallback25(() => {
|
|
3415
3404
|
setIsImporting(false);
|
|
3416
3405
|
setError(null);
|
|
3417
3406
|
}, []);
|
|
@@ -3424,13 +3413,13 @@ function useImportNote() {
|
|
|
3424
3413
|
}
|
|
3425
3414
|
|
|
3426
3415
|
// src/hooks/useExportNote.ts
|
|
3427
|
-
|
|
3428
|
-
|
|
3416
|
+
import { useCallback as useCallback26, useState as useState21 } from "react";
|
|
3417
|
+
import { NoteExportFormat } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
3429
3418
|
function useExportNote() {
|
|
3430
3419
|
const { client, isReady, runExclusive } = useMiden();
|
|
3431
|
-
const [isExporting, setIsExporting] = (
|
|
3432
|
-
const [error, setError] = (
|
|
3433
|
-
const exportNote = (
|
|
3420
|
+
const [isExporting, setIsExporting] = useState21(false);
|
|
3421
|
+
const [error, setError] = useState21(null);
|
|
3422
|
+
const exportNote = useCallback26(
|
|
3434
3423
|
async (noteId) => {
|
|
3435
3424
|
if (!client || !isReady) {
|
|
3436
3425
|
throw new Error("Miden client is not ready");
|
|
@@ -3439,7 +3428,7 @@ function useExportNote() {
|
|
|
3439
3428
|
setError(null);
|
|
3440
3429
|
try {
|
|
3441
3430
|
const noteFile = await runExclusive(
|
|
3442
|
-
() => client.exportNoteFile(noteId,
|
|
3431
|
+
() => client.exportNoteFile(noteId, NoteExportFormat.Full)
|
|
3443
3432
|
);
|
|
3444
3433
|
return noteFile.serialize();
|
|
3445
3434
|
} catch (err) {
|
|
@@ -3452,7 +3441,7 @@ function useExportNote() {
|
|
|
3452
3441
|
},
|
|
3453
3442
|
[client, isReady, runExclusive]
|
|
3454
3443
|
);
|
|
3455
|
-
const reset = (
|
|
3444
|
+
const reset = useCallback26(() => {
|
|
3456
3445
|
setIsExporting(false);
|
|
3457
3446
|
setError(null);
|
|
3458
3447
|
}, []);
|
|
@@ -3465,12 +3454,12 @@ function useExportNote() {
|
|
|
3465
3454
|
}
|
|
3466
3455
|
|
|
3467
3456
|
// src/hooks/useSyncControl.ts
|
|
3468
|
-
|
|
3457
|
+
import { useCallback as useCallback27 } from "react";
|
|
3469
3458
|
function useSyncControl() {
|
|
3470
3459
|
const isPaused = useMidenStore((state) => state.syncPaused);
|
|
3471
3460
|
const setSyncPaused = useMidenStore((state) => state.setSyncPaused);
|
|
3472
|
-
const pauseSync = (
|
|
3473
|
-
const resumeSync = (
|
|
3461
|
+
const pauseSync = useCallback27(() => setSyncPaused(true), [setSyncPaused]);
|
|
3462
|
+
const resumeSync = useCallback27(() => setSyncPaused(false), [setSyncPaused]);
|
|
3474
3463
|
return {
|
|
3475
3464
|
pauseSync,
|
|
3476
3465
|
resumeSync,
|
|
@@ -3627,8 +3616,7 @@ function createMidenStorage(prefix) {
|
|
|
3627
3616
|
|
|
3628
3617
|
// src/index.ts
|
|
3629
3618
|
installAccountBech32();
|
|
3630
|
-
|
|
3631
|
-
0 && (module.exports = {
|
|
3619
|
+
export {
|
|
3632
3620
|
AuthScheme,
|
|
3633
3621
|
DEFAULTS,
|
|
3634
3622
|
MidenError,
|
|
@@ -3683,4 +3671,4 @@ installAccountBech32();
|
|
|
3683
3671
|
useWaitForNotes,
|
|
3684
3672
|
waitForWalletDetection,
|
|
3685
3673
|
wrapWasmError
|
|
3686
|
-
}
|
|
3674
|
+
};
|