@miden-sdk/react 0.14.11 → 0.15.0-alpha.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +3 -0
- package/README.md +86 -2
- package/dist/index.d.ts +213 -15
- package/dist/index.mjs +367 -186
- package/dist/lazy.d.ts +213 -15
- package/dist/lazy.mjs +367 -186
- package/dist/mt/lazy.d.ts +213 -15
- package/dist/mt/lazy.mjs +367 -186
- package/dist/mt.d.ts +213 -15
- package/dist/mt.mjs +367 -186
- package/package.json +3 -3
package/dist/mt.mjs
CHANGED
|
@@ -316,7 +316,7 @@ var DEFAULTS = {
|
|
|
316
316
|
AUTO_SYNC_INTERVAL: 15e3,
|
|
317
317
|
STORAGE_MODE: "private",
|
|
318
318
|
WALLET_MUTABLE: true,
|
|
319
|
-
AUTH_SCHEME: AuthScheme.
|
|
319
|
+
AUTH_SCHEME: AuthScheme.AuthRpoFalcon512,
|
|
320
320
|
NOTE_TYPE: "private",
|
|
321
321
|
FAUCET_DECIMALS: 8
|
|
322
322
|
};
|
|
@@ -402,10 +402,7 @@ function resolveProverTarget(target, config) {
|
|
|
402
402
|
return TransactionProver.newLocalProver();
|
|
403
403
|
}
|
|
404
404
|
if (normalized === "devnet" || normalized === "testnet") {
|
|
405
|
-
const url = config.proverUrls?.[normalized] ?? DEFAULT_PROVER_URLS[normalized]
|
|
406
|
-
if (!url) {
|
|
407
|
-
throw new Error(`Missing ${normalized} prover URL`);
|
|
408
|
-
}
|
|
405
|
+
const url = config.proverUrls?.[normalized] ?? DEFAULT_PROVER_URLS[normalized];
|
|
409
406
|
return TransactionProver.newRemoteProver(
|
|
410
407
|
url,
|
|
411
408
|
normalizeTimeout(config.proverTimeoutMs)
|
|
@@ -425,7 +422,6 @@ function createRemoteProver(config, fallbackTimeout) {
|
|
|
425
422
|
}
|
|
426
423
|
return TransactionProver.newRemoteProver(
|
|
427
424
|
url,
|
|
428
|
-
/* v8 ignore next 1 — timeoutMs is always provided in tests; ?? fallbackTimeout path unreachable */
|
|
429
425
|
normalizeTimeout(timeoutMs ?? fallbackTimeout)
|
|
430
426
|
);
|
|
431
427
|
}
|
|
@@ -447,34 +443,21 @@ function useSigner() {
|
|
|
447
443
|
}
|
|
448
444
|
|
|
449
445
|
// src/utils/signerAccount.ts
|
|
450
|
-
var WASM_ACCOUNT_TYPE = {
|
|
451
|
-
FungibleFaucet: 0,
|
|
452
|
-
NonFungibleFaucet: 1,
|
|
453
|
-
RegularAccountImmutableCode: 2,
|
|
454
|
-
RegularAccountUpdatableCode: 3
|
|
455
|
-
};
|
|
456
|
-
function getAccountType(accountType) {
|
|
457
|
-
return WASM_ACCOUNT_TYPE[accountType] ?? WASM_ACCOUNT_TYPE.RegularAccountImmutableCode;
|
|
458
|
-
}
|
|
459
446
|
function isPrivateStorageMode(storageMode) {
|
|
460
447
|
return storageMode.toString() === "private";
|
|
461
448
|
}
|
|
462
449
|
async function initializeSignerAccount(client, config) {
|
|
463
|
-
const {
|
|
464
|
-
AccountBuilder,
|
|
465
|
-
AccountComponent,
|
|
466
|
-
AuthScheme: AuthScheme2,
|
|
467
|
-
Word: Word2,
|
|
468
|
-
resolveAuthScheme: resolveAuthScheme5
|
|
469
|
-
} = await import("@miden-sdk/miden-sdk/mt");
|
|
450
|
+
const { AccountBuilder, AccountComponent, AuthScheme: AuthScheme2, Word: Word2 } = await import("@miden-sdk/miden-sdk/mt");
|
|
470
451
|
await client.syncState();
|
|
471
452
|
if (config.importAccountId) {
|
|
472
453
|
const accountId2 = parseAccountId(config.importAccountId);
|
|
473
454
|
try {
|
|
474
455
|
await client.importAccountById(accountId2);
|
|
475
456
|
} catch (e) {
|
|
476
|
-
const
|
|
477
|
-
|
|
457
|
+
const code = e?.code;
|
|
458
|
+
const isFreshAccount = code === "ACCOUNT_NOT_FOUND_ON_CHAIN";
|
|
459
|
+
const isAlreadyTracked = code === "ACCOUNT_ALREADY_TRACKED";
|
|
460
|
+
if (!isAlreadyTracked && !isFreshAccount) {
|
|
478
461
|
throw e;
|
|
479
462
|
}
|
|
480
463
|
}
|
|
@@ -483,13 +466,12 @@ async function initializeSignerAccount(client, config) {
|
|
|
483
466
|
}
|
|
484
467
|
const commitmentWord = Word2.deserialize(config.publicKeyCommitment);
|
|
485
468
|
const seed = config.accountSeed ?? crypto.getRandomValues(new Uint8Array(32));
|
|
486
|
-
const accountType = getAccountType(config.accountType);
|
|
487
469
|
let builder = new AccountBuilder(seed).withAuthComponent(
|
|
488
470
|
AccountComponent.createAuthComponentFromCommitment(
|
|
489
471
|
commitmentWord,
|
|
490
|
-
|
|
472
|
+
AuthScheme2.AuthEcdsaK256Keccak
|
|
491
473
|
)
|
|
492
|
-
).
|
|
474
|
+
).storageMode(config.storageMode).withBasicWalletComponent();
|
|
493
475
|
if (config.customComponents?.length) {
|
|
494
476
|
for (const component of config.customComponents) {
|
|
495
477
|
if (component == null || typeof component.getProcedures !== "function") {
|
|
@@ -560,23 +542,16 @@ function MidenProvider({
|
|
|
560
542
|
}),
|
|
561
543
|
[config]
|
|
562
544
|
);
|
|
563
|
-
const
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
resolvedConfig.prover,
|
|
573
|
-
resolvedConfig.proverTimeoutMs,
|
|
574
|
-
/* v8 ignore next 2 — optional chain on proverUrls; tests don't pass proverUrls config */
|
|
575
|
-
resolvedConfig.proverUrls?.devnet,
|
|
576
|
-
resolvedConfig.proverUrls?.testnet
|
|
577
|
-
]);
|
|
545
|
+
const defaultProver = useMemo(
|
|
546
|
+
() => resolveTransactionProver(resolvedConfig),
|
|
547
|
+
[
|
|
548
|
+
resolvedConfig.prover,
|
|
549
|
+
resolvedConfig.proverTimeoutMs,
|
|
550
|
+
resolvedConfig.proverUrls?.devnet,
|
|
551
|
+
resolvedConfig.proverUrls?.testnet
|
|
552
|
+
]
|
|
553
|
+
);
|
|
578
554
|
const runExclusive = useCallback(
|
|
579
|
-
/* v8 ignore next 3 — runExclusive callback body; only called by advanced consumers, not directly in tests */
|
|
580
555
|
async (fn) => clientLockRef.current.runExclusive(fn),
|
|
581
556
|
[]
|
|
582
557
|
);
|
|
@@ -611,8 +586,6 @@ function MidenProvider({
|
|
|
611
586
|
signCbRef.current = signerContext?.signCb ?? null;
|
|
612
587
|
}, [signerContext?.signCb]);
|
|
613
588
|
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. */
|
|
616
589
|
async (pubKey, signingInputs) => {
|
|
617
590
|
const cb = signCbRef.current;
|
|
618
591
|
if (!cb) {
|
|
@@ -865,10 +838,7 @@ function MultiSignerProvider({ children }) {
|
|
|
865
838
|
() => ({ register, unregister }),
|
|
866
839
|
[register, unregister]
|
|
867
840
|
);
|
|
868
|
-
const activeSigner = activeSignerName ? (
|
|
869
|
-
/* v8 ignore next 1 — ?? null fallback; find() returns undefined only when the signer was unregistered between renders */
|
|
870
|
-
signersSnapshot.find((s) => s.name === activeSignerName) ?? null
|
|
871
|
-
) : null;
|
|
841
|
+
const activeSigner = activeSignerName ? signersSnapshot.find((s) => s.name === activeSignerName) ?? null : null;
|
|
872
842
|
const stableSignCb = useCallback2(
|
|
873
843
|
async (pubKey, signingInputs) => {
|
|
874
844
|
const name = activeSignerName;
|
|
@@ -1231,6 +1201,27 @@ var parseAssetAmount = (input, decimals) => {
|
|
|
1231
1201
|
};
|
|
1232
1202
|
|
|
1233
1203
|
// src/utils/notes.ts
|
|
1204
|
+
var resolveNoteInput = async (input, client) => {
|
|
1205
|
+
if (typeof input === "string") {
|
|
1206
|
+
const record2 = await client.getInputNote(input);
|
|
1207
|
+
if (!record2) {
|
|
1208
|
+
throw new Error(`Note not found: ${input}`);
|
|
1209
|
+
}
|
|
1210
|
+
return record2.toNote();
|
|
1211
|
+
}
|
|
1212
|
+
if (typeof input.toNote === "function") {
|
|
1213
|
+
return input.toNote();
|
|
1214
|
+
}
|
|
1215
|
+
if (typeof input.id === "function") {
|
|
1216
|
+
return input;
|
|
1217
|
+
}
|
|
1218
|
+
const hex = input.toString();
|
|
1219
|
+
const record = await client.getInputNote(hex);
|
|
1220
|
+
if (!record) {
|
|
1221
|
+
throw new Error(`Note not found: ${hex}`);
|
|
1222
|
+
}
|
|
1223
|
+
return record.toNote();
|
|
1224
|
+
};
|
|
1234
1225
|
var getInputNoteRecord = (note) => {
|
|
1235
1226
|
const maybeConsumable = note;
|
|
1236
1227
|
if (typeof maybeConsumable.inputNoteRecord === "function") {
|
|
@@ -1241,7 +1232,9 @@ var getInputNoteRecord = (note) => {
|
|
|
1241
1232
|
var getNoteSummary = (note, getAssetMetadata) => {
|
|
1242
1233
|
try {
|
|
1243
1234
|
const record = getInputNoteRecord(note);
|
|
1244
|
-
const
|
|
1235
|
+
const rawId = record.id();
|
|
1236
|
+
if (!rawId) return null;
|
|
1237
|
+
const id = rawId.toString();
|
|
1245
1238
|
const assets = [];
|
|
1246
1239
|
try {
|
|
1247
1240
|
const details = record.details();
|
|
@@ -1320,7 +1313,6 @@ function getNoteType(type) {
|
|
|
1320
1313
|
return NoteType.Private;
|
|
1321
1314
|
case "public":
|
|
1322
1315
|
return NoteType.Public;
|
|
1323
|
-
/* v8 ignore next 2 — TypeScript type ensures only "private"|"public"; default is unreachable */
|
|
1324
1316
|
default:
|
|
1325
1317
|
return NoteType.Private;
|
|
1326
1318
|
}
|
|
@@ -1501,38 +1493,23 @@ import { NoteFilter as NoteFilter2 } from "@miden-sdk/miden-sdk/mt";
|
|
|
1501
1493
|
// src/utils/noteAttachment.ts
|
|
1502
1494
|
import {
|
|
1503
1495
|
NoteAttachment,
|
|
1504
|
-
NoteAttachmentKind,
|
|
1505
1496
|
NoteAttachmentScheme,
|
|
1506
1497
|
Word
|
|
1507
1498
|
} from "@miden-sdk/miden-sdk/mt";
|
|
1508
1499
|
function readNoteAttachment(note) {
|
|
1509
1500
|
try {
|
|
1510
|
-
const
|
|
1511
|
-
if (!
|
|
1512
|
-
const
|
|
1513
|
-
if (
|
|
1514
|
-
const
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
(v) => BigInt(v)
|
|
1523
|
-
);
|
|
1524
|
-
return { values, kind: "word" };
|
|
1525
|
-
}
|
|
1526
|
-
if (kind === NoteAttachmentKind.Array) {
|
|
1527
|
-
const arr = attachment.asArray?.();
|
|
1528
|
-
if (!arr) return null;
|
|
1529
|
-
const u64s = arr.toU64s();
|
|
1530
|
-
const values = Array.from(u64s).map(
|
|
1531
|
-
(v) => BigInt(v)
|
|
1532
|
-
);
|
|
1533
|
-
return { values, kind: "array" };
|
|
1534
|
-
}
|
|
1535
|
-
return null;
|
|
1501
|
+
const attachments = note.attachments?.();
|
|
1502
|
+
if (!attachments || attachments.length === 0) return null;
|
|
1503
|
+
const words = attachments[0].toWords();
|
|
1504
|
+
if (words.length === 0) return null;
|
|
1505
|
+
const values = [];
|
|
1506
|
+
for (const word of words) {
|
|
1507
|
+
for (const value of word.toU64s()) {
|
|
1508
|
+
values.push(BigInt(value));
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
if (values.every((value) => value === 0n)) return null;
|
|
1512
|
+
return { values, kind: words.length === 1 ? "word" : "array" };
|
|
1536
1513
|
} catch {
|
|
1537
1514
|
return null;
|
|
1538
1515
|
}
|
|
@@ -1543,7 +1520,7 @@ function createNoteAttachment(values) {
|
|
|
1543
1520
|
bigints.push(BigInt(values[i]));
|
|
1544
1521
|
}
|
|
1545
1522
|
if (bigints.length === 0) {
|
|
1546
|
-
return
|
|
1523
|
+
return emptyAttachment();
|
|
1547
1524
|
}
|
|
1548
1525
|
const scheme = NoteAttachmentScheme.none();
|
|
1549
1526
|
if (bigints.length <= 4) {
|
|
@@ -1551,7 +1528,7 @@ function createNoteAttachment(values) {
|
|
|
1551
1528
|
bigints.push(0n);
|
|
1552
1529
|
}
|
|
1553
1530
|
const word = new Word(BigUint64Array.from(bigints));
|
|
1554
|
-
return NoteAttachment.
|
|
1531
|
+
return NoteAttachment.fromWord(scheme, word);
|
|
1555
1532
|
}
|
|
1556
1533
|
while (bigints.length % 4 !== 0) {
|
|
1557
1534
|
bigints.push(0n);
|
|
@@ -1560,13 +1537,12 @@ function createNoteAttachment(values) {
|
|
|
1560
1537
|
for (let i = 0; i < bigints.length; i += 4) {
|
|
1561
1538
|
words.push(new Word(BigUint64Array.from(bigints.slice(i, i + 4))));
|
|
1562
1539
|
}
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
return newArray.call(NoteAttachment, scheme, words);
|
|
1540
|
+
return NoteAttachment.fromWords(scheme, words);
|
|
1541
|
+
}
|
|
1542
|
+
function emptyAttachment() {
|
|
1543
|
+
const scheme = NoteAttachmentScheme.none();
|
|
1544
|
+
const word = new Word(BigUint64Array.from([0n, 0n, 0n, 0n]));
|
|
1545
|
+
return NoteAttachment.fromWord(scheme, word);
|
|
1570
1546
|
}
|
|
1571
1547
|
|
|
1572
1548
|
// src/hooks/useNoteStream.ts
|
|
@@ -1675,7 +1651,9 @@ function useNoteStream(options = {}) {
|
|
|
1675
1651
|
}
|
|
1676
1652
|
function buildStreamedNote(record, noteFirstSeen) {
|
|
1677
1653
|
try {
|
|
1678
|
-
const
|
|
1654
|
+
const rawId = record.id();
|
|
1655
|
+
if (!rawId) return null;
|
|
1656
|
+
const id = rawId.toString();
|
|
1679
1657
|
const metadata = record.metadata?.();
|
|
1680
1658
|
const senderHex = metadata?.sender?.()?.toString?.();
|
|
1681
1659
|
const sender = senderHex ? toBech32AccountId(senderHex) : "";
|
|
@@ -1796,7 +1774,6 @@ function buildFilter(filter, ids, idsHex) {
|
|
|
1796
1774
|
}
|
|
1797
1775
|
return {
|
|
1798
1776
|
filter: TransactionFilter2.all(),
|
|
1799
|
-
/* v8 ignore next 1 — idsHex is always non-null when ids is non-empty; ?? [] is a safety net */
|
|
1800
1777
|
localFilterHexes: idsHex ?? []
|
|
1801
1778
|
};
|
|
1802
1779
|
}
|
|
@@ -1822,10 +1799,7 @@ function useSyncState() {
|
|
|
1822
1799
|
|
|
1823
1800
|
// src/hooks/useCreateWallet.ts
|
|
1824
1801
|
import { useCallback as useCallback9, useState as useState7 } from "react";
|
|
1825
|
-
import {
|
|
1826
|
-
AccountStorageMode,
|
|
1827
|
-
resolveAuthScheme
|
|
1828
|
-
} from "@miden-sdk/miden-sdk/mt";
|
|
1802
|
+
import { AccountStorageMode } from "@miden-sdk/miden-sdk/mt";
|
|
1829
1803
|
|
|
1830
1804
|
// src/utils/runExclusive.ts
|
|
1831
1805
|
var runExclusiveDirect = async (fn) => fn();
|
|
@@ -1850,9 +1824,7 @@ function useCreateWallet() {
|
|
|
1850
1824
|
options.storageMode ?? DEFAULTS.STORAGE_MODE
|
|
1851
1825
|
);
|
|
1852
1826
|
const mutable = options.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
1853
|
-
const authScheme =
|
|
1854
|
-
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
1855
|
-
);
|
|
1827
|
+
const authScheme = options.authScheme ?? DEFAULTS.AUTH_SCHEME;
|
|
1856
1828
|
const newWallet = await runExclusiveSafe(async () => {
|
|
1857
1829
|
const createdWallet = await client.newWallet(
|
|
1858
1830
|
storageMode,
|
|
@@ -1896,8 +1868,6 @@ function getStorageMode(mode) {
|
|
|
1896
1868
|
return AccountStorageMode.private();
|
|
1897
1869
|
case "public":
|
|
1898
1870
|
return AccountStorageMode.public();
|
|
1899
|
-
case "network":
|
|
1900
|
-
return AccountStorageMode.network();
|
|
1901
1871
|
default:
|
|
1902
1872
|
return AccountStorageMode.private();
|
|
1903
1873
|
}
|
|
@@ -1905,10 +1875,7 @@ function getStorageMode(mode) {
|
|
|
1905
1875
|
|
|
1906
1876
|
// src/hooks/useCreateFaucet.ts
|
|
1907
1877
|
import { useCallback as useCallback10, useState as useState8 } from "react";
|
|
1908
|
-
import {
|
|
1909
|
-
AccountStorageMode as AccountStorageMode2,
|
|
1910
|
-
resolveAuthScheme as resolveAuthScheme2
|
|
1911
|
-
} from "@miden-sdk/miden-sdk/mt";
|
|
1878
|
+
import { AccountStorageMode as AccountStorageMode2 } from "@miden-sdk/miden-sdk/mt";
|
|
1912
1879
|
function useCreateFaucet() {
|
|
1913
1880
|
const { client, isReady, runExclusive } = useMiden();
|
|
1914
1881
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
@@ -1928,14 +1895,13 @@ function useCreateFaucet() {
|
|
|
1928
1895
|
options.storageMode ?? DEFAULTS.STORAGE_MODE
|
|
1929
1896
|
);
|
|
1930
1897
|
const decimals = options.decimals ?? DEFAULTS.FAUCET_DECIMALS;
|
|
1931
|
-
const authScheme =
|
|
1932
|
-
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
1933
|
-
);
|
|
1898
|
+
const authScheme = options.authScheme ?? DEFAULTS.AUTH_SCHEME;
|
|
1934
1899
|
const newFaucet = await runExclusiveSafe(async () => {
|
|
1935
1900
|
const createdFaucet = await client.newFaucet(
|
|
1936
1901
|
storageMode,
|
|
1937
1902
|
false,
|
|
1938
1903
|
// nonFungible - currently only fungible faucets supported
|
|
1904
|
+
options.tokenName ?? options.tokenSymbol,
|
|
1939
1905
|
options.tokenSymbol,
|
|
1940
1906
|
decimals,
|
|
1941
1907
|
BigInt(options.maxSupply),
|
|
@@ -1976,8 +1942,6 @@ function getStorageMode2(mode) {
|
|
|
1976
1942
|
return AccountStorageMode2.private();
|
|
1977
1943
|
case "public":
|
|
1978
1944
|
return AccountStorageMode2.public();
|
|
1979
|
-
case "network":
|
|
1980
|
-
return AccountStorageMode2.network();
|
|
1981
1945
|
default:
|
|
1982
1946
|
return AccountStorageMode2.private();
|
|
1983
1947
|
}
|
|
@@ -1985,7 +1949,7 @@ function getStorageMode2(mode) {
|
|
|
1985
1949
|
|
|
1986
1950
|
// src/hooks/useImportAccount.ts
|
|
1987
1951
|
import { useCallback as useCallback11, useState as useState9 } from "react";
|
|
1988
|
-
import { AccountFile
|
|
1952
|
+
import { AccountFile } from "@miden-sdk/miden-sdk/mt";
|
|
1989
1953
|
|
|
1990
1954
|
// src/utils/errors.ts
|
|
1991
1955
|
var MidenError = class extends Error {
|
|
@@ -2118,9 +2082,7 @@ function useImportAccount() {
|
|
|
2118
2082
|
}
|
|
2119
2083
|
case "seed": {
|
|
2120
2084
|
const mutable = options.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
2121
|
-
const authScheme =
|
|
2122
|
-
options.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
2123
|
-
);
|
|
2085
|
+
const authScheme = options.authScheme ?? DEFAULTS.AUTH_SCHEME;
|
|
2124
2086
|
return await client.importPublicAccountFromSeed(
|
|
2125
2087
|
options.seed,
|
|
2126
2088
|
mutable,
|
|
@@ -2196,7 +2158,6 @@ import {
|
|
|
2196
2158
|
FungibleAsset,
|
|
2197
2159
|
Note,
|
|
2198
2160
|
NoteAssets,
|
|
2199
|
-
NoteAttachment as NoteAttachment2,
|
|
2200
2161
|
NoteType as NoteType2,
|
|
2201
2162
|
NoteArray,
|
|
2202
2163
|
TransactionRequestBuilder
|
|
@@ -2275,7 +2236,7 @@ function useSend() {
|
|
|
2275
2236
|
toId,
|
|
2276
2237
|
assets,
|
|
2277
2238
|
noteType,
|
|
2278
|
-
|
|
2239
|
+
emptyAttachment()
|
|
2279
2240
|
);
|
|
2280
2241
|
const ownOutputs = new NoteArray();
|
|
2281
2242
|
ownOutputs.push(p2idNote);
|
|
@@ -2312,7 +2273,7 @@ function useSend() {
|
|
|
2312
2273
|
);
|
|
2313
2274
|
txRequest = new TransactionRequestBuilder().withOwnOutputNotes(new NoteArray([note])).build();
|
|
2314
2275
|
} else {
|
|
2315
|
-
txRequest = client.newSendTransactionRequest(
|
|
2276
|
+
txRequest = await client.newSendTransactionRequest(
|
|
2316
2277
|
fromAccountId,
|
|
2317
2278
|
toAccountId,
|
|
2318
2279
|
assetIdObj,
|
|
@@ -2329,7 +2290,7 @@ function useSend() {
|
|
|
2329
2290
|
const proverConfig = useMidenStore.getState().config;
|
|
2330
2291
|
const provenTransaction = await proveWithFallback(
|
|
2331
2292
|
(resolvedProver) => runExclusiveSafe(
|
|
2332
|
-
() =>
|
|
2293
|
+
() => client.proveTransaction(txResult, resolvedProver)
|
|
2333
2294
|
),
|
|
2334
2295
|
proverConfig
|
|
2335
2296
|
);
|
|
@@ -2412,7 +2373,6 @@ import {
|
|
|
2412
2373
|
FungibleAsset as FungibleAsset2,
|
|
2413
2374
|
Note as Note2,
|
|
2414
2375
|
NoteAssets as NoteAssets2,
|
|
2415
|
-
NoteAttachment as NoteAttachment3,
|
|
2416
2376
|
NoteType as NoteType3,
|
|
2417
2377
|
NoteArray as NoteArray2,
|
|
2418
2378
|
TransactionRequestBuilder as TransactionRequestBuilder2
|
|
@@ -2457,7 +2417,7 @@ function useMultiSend() {
|
|
|
2457
2417
|
new FungibleAsset2(iterAssetId, BigInt(amount))
|
|
2458
2418
|
]);
|
|
2459
2419
|
const resolvedNoteType = recipientNoteType ? getNoteType(recipientNoteType) : noteType;
|
|
2460
|
-
const noteAttachment = attachment !== void 0 && attachment !== null ? createNoteAttachment(attachment) :
|
|
2420
|
+
const noteAttachment = attachment !== void 0 && attachment !== null ? createNoteAttachment(attachment) : emptyAttachment();
|
|
2461
2421
|
const note = Note2.createP2IDNote(
|
|
2462
2422
|
iterSenderId,
|
|
2463
2423
|
receiverId,
|
|
@@ -2484,7 +2444,7 @@ function useMultiSend() {
|
|
|
2484
2444
|
const proverConfig = useMidenStore.getState().config;
|
|
2485
2445
|
const provenTransaction = await proveWithFallback(
|
|
2486
2446
|
(resolvedProver) => runExclusiveDirect(
|
|
2487
|
-
() =>
|
|
2447
|
+
() => client.proveTransaction(txResult, resolvedProver)
|
|
2488
2448
|
),
|
|
2489
2449
|
proverConfig
|
|
2490
2450
|
);
|
|
@@ -2649,7 +2609,7 @@ function useMint() {
|
|
|
2649
2609
|
const faucetIdObj = parseAccountId(options.faucetId);
|
|
2650
2610
|
setStage("proving");
|
|
2651
2611
|
const txResult = await runExclusiveSafe(async () => {
|
|
2652
|
-
const txRequest = client.newMintTransactionRequest(
|
|
2612
|
+
const txRequest = await client.newMintTransactionRequest(
|
|
2653
2613
|
targetAccountIdObj,
|
|
2654
2614
|
faucetIdObj,
|
|
2655
2615
|
noteType,
|
|
@@ -2743,7 +2703,15 @@ function useConsume() {
|
|
|
2743
2703
|
throw new Error("Some notes could not be found for provided IDs");
|
|
2744
2704
|
}
|
|
2745
2705
|
const recordById = new Map(
|
|
2746
|
-
noteRecords.map((r) =>
|
|
2706
|
+
noteRecords.map((r) => {
|
|
2707
|
+
const id = r.id();
|
|
2708
|
+
if (!id) {
|
|
2709
|
+
throw new Error(
|
|
2710
|
+
"getInputNotes returned a record without a note id"
|
|
2711
|
+
);
|
|
2712
|
+
}
|
|
2713
|
+
return [id.toString(), r];
|
|
2714
|
+
})
|
|
2747
2715
|
);
|
|
2748
2716
|
for (let j = 0; j < lookupIndices.length; j++) {
|
|
2749
2717
|
const record = recordById.get(lookupIdStrings[j]);
|
|
@@ -2756,12 +2724,6 @@ function useConsume() {
|
|
|
2756
2724
|
}
|
|
2757
2725
|
}
|
|
2758
2726
|
const notes = resolved;
|
|
2759
|
-
if (notes.length === 0) {
|
|
2760
|
-
throw new Error("No notes found for provided IDs");
|
|
2761
|
-
}
|
|
2762
|
-
if (notes.length !== options.notes.length) {
|
|
2763
|
-
throw new Error("Some notes could not be found for provided IDs");
|
|
2764
|
-
}
|
|
2765
2727
|
const txRequest = client.newConsumeTransactionRequest(notes);
|
|
2766
2728
|
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
2767
2729
|
accountIdObj,
|
|
@@ -2828,7 +2790,7 @@ function useSwap() {
|
|
|
2828
2790
|
const requestedFaucetIdObj = parseAccountId(options.requestedFaucetId);
|
|
2829
2791
|
setStage("proving");
|
|
2830
2792
|
const txResult = await runExclusiveSafe(async () => {
|
|
2831
|
-
const txRequest = client.newSwapTransactionRequest(
|
|
2793
|
+
const txRequest = await client.newSwapTransactionRequest(
|
|
2832
2794
|
accountIdObj,
|
|
2833
2795
|
offeredFaucetIdObj,
|
|
2834
2796
|
BigInt(options.offeredAmount),
|
|
@@ -2875,8 +2837,228 @@ function useSwap() {
|
|
|
2875
2837
|
};
|
|
2876
2838
|
}
|
|
2877
2839
|
|
|
2840
|
+
// src/hooks/usePswapCreate.ts
|
|
2841
|
+
import { useCallback as useCallback19, useState as useState15 } from "react";
|
|
2842
|
+
function usePswapCreate() {
|
|
2843
|
+
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2844
|
+
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2845
|
+
const [result, setResult] = useState15(null);
|
|
2846
|
+
const [isLoading, setIsLoading] = useState15(false);
|
|
2847
|
+
const [stage, setStage] = useState15("idle");
|
|
2848
|
+
const [error, setError] = useState15(null);
|
|
2849
|
+
const pswapCreate = useCallback19(
|
|
2850
|
+
async (options) => {
|
|
2851
|
+
if (!client || !isReady) {
|
|
2852
|
+
throw new Error("Miden client is not ready");
|
|
2853
|
+
}
|
|
2854
|
+
const offeredAmount = BigInt(options.offeredAmount);
|
|
2855
|
+
const requestedAmount = BigInt(options.requestedAmount);
|
|
2856
|
+
if (offeredAmount <= 0n) {
|
|
2857
|
+
throw new Error("offeredAmount must be greater than 0");
|
|
2858
|
+
}
|
|
2859
|
+
if (requestedAmount <= 0n) {
|
|
2860
|
+
throw new Error("requestedAmount must be greater than 0");
|
|
2861
|
+
}
|
|
2862
|
+
setIsLoading(true);
|
|
2863
|
+
setStage("executing");
|
|
2864
|
+
setError(null);
|
|
2865
|
+
try {
|
|
2866
|
+
const noteType = getNoteType(options.noteType ?? DEFAULTS.NOTE_TYPE);
|
|
2867
|
+
const paybackNoteType = getNoteType(
|
|
2868
|
+
options.paybackNoteType ?? DEFAULTS.NOTE_TYPE
|
|
2869
|
+
);
|
|
2870
|
+
const accountIdObj = parseAccountId(options.accountId);
|
|
2871
|
+
const offeredFaucetIdObj = parseAccountId(options.offeredFaucetId);
|
|
2872
|
+
const requestedFaucetIdObj = parseAccountId(options.requestedFaucetId);
|
|
2873
|
+
setStage("proving");
|
|
2874
|
+
const txResult = await runExclusiveSafe(async () => {
|
|
2875
|
+
const txRequest = await client.newPswapCreateTransactionRequest(
|
|
2876
|
+
accountIdObj,
|
|
2877
|
+
offeredFaucetIdObj,
|
|
2878
|
+
offeredAmount,
|
|
2879
|
+
requestedFaucetIdObj,
|
|
2880
|
+
requestedAmount,
|
|
2881
|
+
noteType,
|
|
2882
|
+
paybackNoteType
|
|
2883
|
+
);
|
|
2884
|
+
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
2885
|
+
accountIdObj,
|
|
2886
|
+
txRequest,
|
|
2887
|
+
prover
|
|
2888
|
+
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2889
|
+
return { transactionId: txId.toHex() };
|
|
2890
|
+
});
|
|
2891
|
+
setStage("complete");
|
|
2892
|
+
setResult(txResult);
|
|
2893
|
+
await sync();
|
|
2894
|
+
return txResult;
|
|
2895
|
+
} catch (err) {
|
|
2896
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
2897
|
+
setError(error2);
|
|
2898
|
+
setStage("idle");
|
|
2899
|
+
throw error2;
|
|
2900
|
+
} finally {
|
|
2901
|
+
setIsLoading(false);
|
|
2902
|
+
}
|
|
2903
|
+
},
|
|
2904
|
+
[client, isReady, prover, runExclusive, sync]
|
|
2905
|
+
);
|
|
2906
|
+
const reset = useCallback19(() => {
|
|
2907
|
+
setResult(null);
|
|
2908
|
+
setIsLoading(false);
|
|
2909
|
+
setStage("idle");
|
|
2910
|
+
setError(null);
|
|
2911
|
+
}, []);
|
|
2912
|
+
return {
|
|
2913
|
+
pswapCreate,
|
|
2914
|
+
result,
|
|
2915
|
+
isLoading,
|
|
2916
|
+
stage,
|
|
2917
|
+
error,
|
|
2918
|
+
reset
|
|
2919
|
+
};
|
|
2920
|
+
}
|
|
2921
|
+
|
|
2922
|
+
// src/hooks/usePswapConsume.ts
|
|
2923
|
+
import { useCallback as useCallback20, useState as useState16 } from "react";
|
|
2924
|
+
function usePswapConsume() {
|
|
2925
|
+
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
2926
|
+
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2927
|
+
const [result, setResult] = useState16(null);
|
|
2928
|
+
const [isLoading, setIsLoading] = useState16(false);
|
|
2929
|
+
const [stage, setStage] = useState16("idle");
|
|
2930
|
+
const [error, setError] = useState16(null);
|
|
2931
|
+
const pswapConsume = useCallback20(
|
|
2932
|
+
async (options) => {
|
|
2933
|
+
if (!client || !isReady) {
|
|
2934
|
+
throw new Error("Miden client is not ready");
|
|
2935
|
+
}
|
|
2936
|
+
const fillAmount = BigInt(options.fillAmount);
|
|
2937
|
+
const noteFillAmount = BigInt(options.noteFillAmount ?? 0);
|
|
2938
|
+
if (fillAmount <= 0n) {
|
|
2939
|
+
throw new Error("fillAmount must be greater than 0");
|
|
2940
|
+
}
|
|
2941
|
+
if (noteFillAmount < 0n) {
|
|
2942
|
+
throw new Error("noteFillAmount must not be negative");
|
|
2943
|
+
}
|
|
2944
|
+
setIsLoading(true);
|
|
2945
|
+
setStage("executing");
|
|
2946
|
+
setError(null);
|
|
2947
|
+
try {
|
|
2948
|
+
const accountIdObj = parseAccountId(options.accountId);
|
|
2949
|
+
setStage("proving");
|
|
2950
|
+
const txResult = await runExclusiveSafe(async () => {
|
|
2951
|
+
const note = await resolveNoteInput(options.note, client);
|
|
2952
|
+
const txRequest = await client.newPswapConsumeTransactionRequest(
|
|
2953
|
+
note,
|
|
2954
|
+
accountIdObj,
|
|
2955
|
+
fillAmount,
|
|
2956
|
+
noteFillAmount
|
|
2957
|
+
);
|
|
2958
|
+
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
2959
|
+
accountIdObj,
|
|
2960
|
+
txRequest,
|
|
2961
|
+
prover
|
|
2962
|
+
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
2963
|
+
return { transactionId: txId.toHex() };
|
|
2964
|
+
});
|
|
2965
|
+
setStage("complete");
|
|
2966
|
+
setResult(txResult);
|
|
2967
|
+
await sync();
|
|
2968
|
+
return txResult;
|
|
2969
|
+
} catch (err) {
|
|
2970
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
2971
|
+
setError(error2);
|
|
2972
|
+
setStage("idle");
|
|
2973
|
+
throw error2;
|
|
2974
|
+
} finally {
|
|
2975
|
+
setIsLoading(false);
|
|
2976
|
+
}
|
|
2977
|
+
},
|
|
2978
|
+
[client, isReady, prover, runExclusive, sync]
|
|
2979
|
+
);
|
|
2980
|
+
const reset = useCallback20(() => {
|
|
2981
|
+
setResult(null);
|
|
2982
|
+
setIsLoading(false);
|
|
2983
|
+
setStage("idle");
|
|
2984
|
+
setError(null);
|
|
2985
|
+
}, []);
|
|
2986
|
+
return {
|
|
2987
|
+
pswapConsume,
|
|
2988
|
+
result,
|
|
2989
|
+
isLoading,
|
|
2990
|
+
stage,
|
|
2991
|
+
error,
|
|
2992
|
+
reset
|
|
2993
|
+
};
|
|
2994
|
+
}
|
|
2995
|
+
|
|
2996
|
+
// src/hooks/usePswapCancel.ts
|
|
2997
|
+
import { useCallback as useCallback21, useState as useState17 } from "react";
|
|
2998
|
+
function usePswapCancel() {
|
|
2999
|
+
const { client, isReady, sync, runExclusive, prover } = useMiden();
|
|
3000
|
+
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3001
|
+
const [result, setResult] = useState17(null);
|
|
3002
|
+
const [isLoading, setIsLoading] = useState17(false);
|
|
3003
|
+
const [stage, setStage] = useState17("idle");
|
|
3004
|
+
const [error, setError] = useState17(null);
|
|
3005
|
+
const pswapCancel = useCallback21(
|
|
3006
|
+
async (options) => {
|
|
3007
|
+
if (!client || !isReady) {
|
|
3008
|
+
throw new Error("Miden client is not ready");
|
|
3009
|
+
}
|
|
3010
|
+
setIsLoading(true);
|
|
3011
|
+
setStage("executing");
|
|
3012
|
+
setError(null);
|
|
3013
|
+
try {
|
|
3014
|
+
const accountIdObj = parseAccountId(options.accountId);
|
|
3015
|
+
setStage("proving");
|
|
3016
|
+
const txResult = await runExclusiveSafe(async () => {
|
|
3017
|
+
const note = await resolveNoteInput(options.note, client);
|
|
3018
|
+
const txRequest = await client.newPswapCancelTransactionRequest(
|
|
3019
|
+
note,
|
|
3020
|
+
accountIdObj
|
|
3021
|
+
);
|
|
3022
|
+
const txId = prover ? await client.submitNewTransactionWithProver(
|
|
3023
|
+
accountIdObj,
|
|
3024
|
+
txRequest,
|
|
3025
|
+
prover
|
|
3026
|
+
) : await client.submitNewTransaction(accountIdObj, txRequest);
|
|
3027
|
+
return { transactionId: txId.toHex() };
|
|
3028
|
+
});
|
|
3029
|
+
setStage("complete");
|
|
3030
|
+
setResult(txResult);
|
|
3031
|
+
await sync();
|
|
3032
|
+
return txResult;
|
|
3033
|
+
} catch (err) {
|
|
3034
|
+
const error2 = err instanceof Error ? err : new Error(String(err));
|
|
3035
|
+
setError(error2);
|
|
3036
|
+
setStage("idle");
|
|
3037
|
+
throw error2;
|
|
3038
|
+
} finally {
|
|
3039
|
+
setIsLoading(false);
|
|
3040
|
+
}
|
|
3041
|
+
},
|
|
3042
|
+
[client, isReady, prover, runExclusive, sync]
|
|
3043
|
+
);
|
|
3044
|
+
const reset = useCallback21(() => {
|
|
3045
|
+
setResult(null);
|
|
3046
|
+
setIsLoading(false);
|
|
3047
|
+
setStage("idle");
|
|
3048
|
+
setError(null);
|
|
3049
|
+
}, []);
|
|
3050
|
+
return {
|
|
3051
|
+
pswapCancel,
|
|
3052
|
+
result,
|
|
3053
|
+
isLoading,
|
|
3054
|
+
stage,
|
|
3055
|
+
error,
|
|
3056
|
+
reset
|
|
3057
|
+
};
|
|
3058
|
+
}
|
|
3059
|
+
|
|
2878
3060
|
// src/hooks/useTransaction.ts
|
|
2879
|
-
import { useCallback as
|
|
3061
|
+
import { useCallback as useCallback22, useRef as useRef6, useState as useState18 } from "react";
|
|
2880
3062
|
|
|
2881
3063
|
// src/utils/transactions.ts
|
|
2882
3064
|
import { NoteType as NoteType4, TransactionFilter as TransactionFilter4 } from "@miden-sdk/miden-sdk/mt";
|
|
@@ -2923,11 +3105,11 @@ function useTransaction() {
|
|
|
2923
3105
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
2924
3106
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
2925
3107
|
const isBusyRef = useRef6(false);
|
|
2926
|
-
const [result, setResult] =
|
|
2927
|
-
const [isLoading, setIsLoading] =
|
|
2928
|
-
const [stage, setStage] =
|
|
2929
|
-
const [error, setError] =
|
|
2930
|
-
const execute =
|
|
3108
|
+
const [result, setResult] = useState18(null);
|
|
3109
|
+
const [isLoading, setIsLoading] = useState18(false);
|
|
3110
|
+
const [stage, setStage] = useState18("idle");
|
|
3111
|
+
const [error, setError] = useState18(null);
|
|
3112
|
+
const execute = useCallback22(
|
|
2931
3113
|
async (options) => {
|
|
2932
3114
|
if (!client || !isReady) {
|
|
2933
3115
|
throw new Error("Miden client is not ready");
|
|
@@ -2955,7 +3137,7 @@ function useTransaction() {
|
|
|
2955
3137
|
const proverConfig = useMidenStore.getState().config;
|
|
2956
3138
|
const provenTransaction = await proveWithFallback(
|
|
2957
3139
|
(resolvedProver) => runExclusiveSafe(
|
|
2958
|
-
() =>
|
|
3140
|
+
() => client.proveTransaction(txResult, resolvedProver)
|
|
2959
3141
|
),
|
|
2960
3142
|
proverConfig
|
|
2961
3143
|
);
|
|
@@ -2994,7 +3176,7 @@ function useTransaction() {
|
|
|
2994
3176
|
},
|
|
2995
3177
|
[client, isReady, runExclusive, sync]
|
|
2996
3178
|
);
|
|
2997
|
-
const reset =
|
|
3179
|
+
const reset = useCallback22(() => {
|
|
2998
3180
|
setResult(null);
|
|
2999
3181
|
setIsLoading(false);
|
|
3000
3182
|
setStage("idle");
|
|
@@ -3017,7 +3199,7 @@ async function resolveRequest(request, client) {
|
|
|
3017
3199
|
}
|
|
3018
3200
|
|
|
3019
3201
|
// src/hooks/useExecuteProgram.ts
|
|
3020
|
-
import { useCallback as
|
|
3202
|
+
import { useCallback as useCallback23, useRef as useRef7, useState as useState19 } from "react";
|
|
3021
3203
|
import {
|
|
3022
3204
|
AdviceInputs,
|
|
3023
3205
|
ForeignAccount,
|
|
@@ -3031,10 +3213,10 @@ function useExecuteProgram() {
|
|
|
3031
3213
|
const { client, isReady, sync, runExclusive } = useMiden();
|
|
3032
3214
|
const runExclusiveSafe = runExclusive ?? runExclusiveDirect;
|
|
3033
3215
|
const isBusyRef = useRef7(false);
|
|
3034
|
-
const [result, setResult] =
|
|
3035
|
-
const [isLoading, setIsLoading] =
|
|
3036
|
-
const [error, setError] =
|
|
3037
|
-
const execute =
|
|
3216
|
+
const [result, setResult] = useState19(null);
|
|
3217
|
+
const [isLoading, setIsLoading] = useState19(false);
|
|
3218
|
+
const [error, setError] = useState19(null);
|
|
3219
|
+
const execute = useCallback23(
|
|
3038
3220
|
async (options) => {
|
|
3039
3221
|
if (!client || !isReady) {
|
|
3040
3222
|
throw new Error("Miden client is not ready");
|
|
@@ -3093,7 +3275,7 @@ function useExecuteProgram() {
|
|
|
3093
3275
|
},
|
|
3094
3276
|
[client, isReady, runExclusive, sync]
|
|
3095
3277
|
);
|
|
3096
|
-
const reset =
|
|
3278
|
+
const reset = useCallback23(() => {
|
|
3097
3279
|
setResult(null);
|
|
3098
3280
|
setIsLoading(false);
|
|
3099
3281
|
setError(null);
|
|
@@ -3108,7 +3290,7 @@ function useExecuteProgram() {
|
|
|
3108
3290
|
}
|
|
3109
3291
|
|
|
3110
3292
|
// src/hooks/useCompile.ts
|
|
3111
|
-
import { useCallback as
|
|
3293
|
+
import { useCallback as useCallback24, useMemo as useMemo8 } from "react";
|
|
3112
3294
|
import { CompilerResource, getWasmOrThrow } from "@miden-sdk/miden-sdk/mt";
|
|
3113
3295
|
function useCompile() {
|
|
3114
3296
|
const { client, isReady } = useMiden();
|
|
@@ -3116,21 +3298,21 @@ function useCompile() {
|
|
|
3116
3298
|
() => client && isReady ? new CompilerResource(client, getWasmOrThrow) : null,
|
|
3117
3299
|
[client, isReady]
|
|
3118
3300
|
);
|
|
3119
|
-
const requireResource =
|
|
3301
|
+
const requireResource = useCallback24(() => {
|
|
3120
3302
|
if (!resource) {
|
|
3121
3303
|
throw new Error("Miden client is not ready");
|
|
3122
3304
|
}
|
|
3123
3305
|
return resource;
|
|
3124
3306
|
}, [resource]);
|
|
3125
|
-
const component =
|
|
3307
|
+
const component = useCallback24(
|
|
3126
3308
|
async (options) => requireResource().component(options),
|
|
3127
3309
|
[requireResource]
|
|
3128
3310
|
);
|
|
3129
|
-
const txScript =
|
|
3311
|
+
const txScript = useCallback24(
|
|
3130
3312
|
async (options) => requireResource().txScript(options),
|
|
3131
3313
|
[requireResource]
|
|
3132
3314
|
);
|
|
3133
|
-
const noteScript =
|
|
3315
|
+
const noteScript = useCallback24(
|
|
3134
3316
|
async (options) => requireResource().noteScript(options),
|
|
3135
3317
|
[requireResource]
|
|
3136
3318
|
);
|
|
@@ -3138,17 +3320,14 @@ function useCompile() {
|
|
|
3138
3320
|
}
|
|
3139
3321
|
|
|
3140
3322
|
// src/hooks/useSessionAccount.ts
|
|
3141
|
-
import { useCallback as
|
|
3142
|
-
import {
|
|
3143
|
-
AccountStorageMode as AccountStorageMode3,
|
|
3144
|
-
resolveAuthScheme as resolveAuthScheme4
|
|
3145
|
-
} from "@miden-sdk/miden-sdk/mt";
|
|
3323
|
+
import { useCallback as useCallback25, useEffect as useEffect9, useRef as useRef8, useState as useState20 } from "react";
|
|
3324
|
+
import { AccountStorageMode as AccountStorageMode3 } from "@miden-sdk/miden-sdk/mt";
|
|
3146
3325
|
function useSessionAccount(options) {
|
|
3147
3326
|
const { client, isReady, sync } = useMiden();
|
|
3148
3327
|
const setAccounts = useMidenStore((state) => state.setAccounts);
|
|
3149
|
-
const [sessionAccountId, setSessionAccountId] =
|
|
3150
|
-
const [step, setStep] =
|
|
3151
|
-
const [error, setError] =
|
|
3328
|
+
const [sessionAccountId, setSessionAccountId] = useState20(null);
|
|
3329
|
+
const [step, setStep] = useState20("idle");
|
|
3330
|
+
const [error, setError] = useState20(null);
|
|
3152
3331
|
const cancelledRef = useRef8(false);
|
|
3153
3332
|
const isBusyRef = useRef8(false);
|
|
3154
3333
|
const storagePrefix = options.storagePrefix ?? "miden-session";
|
|
@@ -3156,9 +3335,7 @@ function useSessionAccount(options) {
|
|
|
3156
3335
|
const maxWaitMs = options.maxWaitMs ?? 6e4;
|
|
3157
3336
|
const storageMode = options.walletOptions?.storageMode ?? "public";
|
|
3158
3337
|
const mutable = options.walletOptions?.mutable ?? DEFAULTS.WALLET_MUTABLE;
|
|
3159
|
-
const authScheme =
|
|
3160
|
-
options.walletOptions?.authScheme ?? DEFAULTS.AUTH_SCHEME
|
|
3161
|
-
);
|
|
3338
|
+
const authScheme = options.walletOptions?.authScheme ?? DEFAULTS.AUTH_SCHEME;
|
|
3162
3339
|
const fundRef = useRef8(options.fund);
|
|
3163
3340
|
fundRef.current = options.fund;
|
|
3164
3341
|
useEffect9(() => {
|
|
@@ -3178,7 +3355,7 @@ function useSessionAccount(options) {
|
|
|
3178
3355
|
localStorage.removeItem(`${storagePrefix}:ready`);
|
|
3179
3356
|
}
|
|
3180
3357
|
}, [storagePrefix]);
|
|
3181
|
-
const initialize =
|
|
3358
|
+
const initialize = useCallback25(async () => {
|
|
3182
3359
|
if (!client || !isReady) {
|
|
3183
3360
|
throw new Error("Miden client is not ready");
|
|
3184
3361
|
}
|
|
@@ -3209,14 +3386,13 @@ function useSessionAccount(options) {
|
|
|
3209
3386
|
setSessionAccountId(walletId);
|
|
3210
3387
|
localStorage.setItem(`${storagePrefix}:accountId`, walletId);
|
|
3211
3388
|
}
|
|
3212
|
-
const resolvedWalletId = walletId;
|
|
3213
3389
|
setStep("funding");
|
|
3214
|
-
await fundRef.current(
|
|
3390
|
+
await fundRef.current(walletId);
|
|
3215
3391
|
if (cancelledRef.current) return;
|
|
3216
3392
|
setStep("consuming");
|
|
3217
3393
|
await waitAndConsume(
|
|
3218
3394
|
client,
|
|
3219
|
-
|
|
3395
|
+
walletId,
|
|
3220
3396
|
pollIntervalMs,
|
|
3221
3397
|
maxWaitMs,
|
|
3222
3398
|
cancelledRef
|
|
@@ -3248,7 +3424,7 @@ function useSessionAccount(options) {
|
|
|
3248
3424
|
maxWaitMs,
|
|
3249
3425
|
setAccounts
|
|
3250
3426
|
]);
|
|
3251
|
-
const reset =
|
|
3427
|
+
const reset = useCallback25(() => {
|
|
3252
3428
|
cancelledRef.current = true;
|
|
3253
3429
|
isBusyRef.current = false;
|
|
3254
3430
|
setSessionAccountId(null);
|
|
@@ -3297,20 +3473,20 @@ async function waitAndConsume(client, walletId, pollIntervalMs, maxWaitMs, cance
|
|
|
3297
3473
|
}
|
|
3298
3474
|
|
|
3299
3475
|
// src/hooks/useExportStore.ts
|
|
3300
|
-
import { useCallback as
|
|
3476
|
+
import { useCallback as useCallback26, useState as useState21 } from "react";
|
|
3301
3477
|
import { exportStore as sdkExportStore } from "@miden-sdk/miden-sdk/mt";
|
|
3302
3478
|
function useExportStore() {
|
|
3303
3479
|
const { client, isReady, runExclusive } = useMiden();
|
|
3304
|
-
const [isExporting, setIsExporting] =
|
|
3305
|
-
const [error, setError] =
|
|
3306
|
-
const exportStore =
|
|
3480
|
+
const [isExporting, setIsExporting] = useState21(false);
|
|
3481
|
+
const [error, setError] = useState21(null);
|
|
3482
|
+
const exportStore = useCallback26(async () => {
|
|
3307
3483
|
if (!client || !isReady) {
|
|
3308
3484
|
throw new Error("Miden client is not ready");
|
|
3309
3485
|
}
|
|
3310
3486
|
setIsExporting(true);
|
|
3311
3487
|
setError(null);
|
|
3312
3488
|
try {
|
|
3313
|
-
const storeName = client.storeIdentifier();
|
|
3489
|
+
const storeName = await client.storeIdentifier();
|
|
3314
3490
|
const snapshot = await runExclusive(() => sdkExportStore(storeName));
|
|
3315
3491
|
return snapshot;
|
|
3316
3492
|
} catch (err) {
|
|
@@ -3321,7 +3497,7 @@ function useExportStore() {
|
|
|
3321
3497
|
setIsExporting(false);
|
|
3322
3498
|
}
|
|
3323
3499
|
}, [client, isReady, runExclusive]);
|
|
3324
|
-
const reset =
|
|
3500
|
+
const reset = useCallback26(() => {
|
|
3325
3501
|
setIsExporting(false);
|
|
3326
3502
|
setError(null);
|
|
3327
3503
|
}, []);
|
|
@@ -3334,13 +3510,13 @@ function useExportStore() {
|
|
|
3334
3510
|
}
|
|
3335
3511
|
|
|
3336
3512
|
// src/hooks/useImportStore.ts
|
|
3337
|
-
import { useCallback as
|
|
3513
|
+
import { useCallback as useCallback27, useState as useState22 } from "react";
|
|
3338
3514
|
import { importStore as sdkImportStore } from "@miden-sdk/miden-sdk/mt";
|
|
3339
3515
|
function useImportStore() {
|
|
3340
3516
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3341
|
-
const [isImporting, setIsImporting] =
|
|
3342
|
-
const [error, setError] =
|
|
3343
|
-
const importStore =
|
|
3517
|
+
const [isImporting, setIsImporting] = useState22(false);
|
|
3518
|
+
const [error, setError] = useState22(null);
|
|
3519
|
+
const importStore = useCallback27(
|
|
3344
3520
|
async (storeDump, storeName, options) => {
|
|
3345
3521
|
if (!client || !isReady) {
|
|
3346
3522
|
throw new Error("Miden client is not ready");
|
|
@@ -3362,7 +3538,7 @@ function useImportStore() {
|
|
|
3362
3538
|
},
|
|
3363
3539
|
[client, isReady, runExclusive, sync]
|
|
3364
3540
|
);
|
|
3365
|
-
const reset =
|
|
3541
|
+
const reset = useCallback27(() => {
|
|
3366
3542
|
setIsImporting(false);
|
|
3367
3543
|
setError(null);
|
|
3368
3544
|
}, []);
|
|
@@ -3375,13 +3551,13 @@ function useImportStore() {
|
|
|
3375
3551
|
}
|
|
3376
3552
|
|
|
3377
3553
|
// src/hooks/useImportNote.ts
|
|
3378
|
-
import { useCallback as
|
|
3554
|
+
import { useCallback as useCallback28, useState as useState23 } from "react";
|
|
3379
3555
|
import { NoteFile } from "@miden-sdk/miden-sdk/mt";
|
|
3380
3556
|
function useImportNote() {
|
|
3381
3557
|
const { client, isReady, runExclusive, sync } = useMiden();
|
|
3382
|
-
const [isImporting, setIsImporting] =
|
|
3383
|
-
const [error, setError] =
|
|
3384
|
-
const importNote =
|
|
3558
|
+
const [isImporting, setIsImporting] = useState23(false);
|
|
3559
|
+
const [error, setError] = useState23(null);
|
|
3560
|
+
const importNote = useCallback28(
|
|
3385
3561
|
async (noteBytes) => {
|
|
3386
3562
|
if (!client || !isReady) {
|
|
3387
3563
|
throw new Error("Miden client is not ready");
|
|
@@ -3405,7 +3581,7 @@ function useImportNote() {
|
|
|
3405
3581
|
},
|
|
3406
3582
|
[client, isReady, runExclusive, sync]
|
|
3407
3583
|
);
|
|
3408
|
-
const reset =
|
|
3584
|
+
const reset = useCallback28(() => {
|
|
3409
3585
|
setIsImporting(false);
|
|
3410
3586
|
setError(null);
|
|
3411
3587
|
}, []);
|
|
@@ -3418,13 +3594,13 @@ function useImportNote() {
|
|
|
3418
3594
|
}
|
|
3419
3595
|
|
|
3420
3596
|
// src/hooks/useExportNote.ts
|
|
3421
|
-
import { useCallback as
|
|
3597
|
+
import { useCallback as useCallback29, useState as useState24 } from "react";
|
|
3422
3598
|
import { NoteExportFormat } from "@miden-sdk/miden-sdk/mt";
|
|
3423
3599
|
function useExportNote() {
|
|
3424
3600
|
const { client, isReady, runExclusive } = useMiden();
|
|
3425
|
-
const [isExporting, setIsExporting] =
|
|
3426
|
-
const [error, setError] =
|
|
3427
|
-
const exportNote =
|
|
3601
|
+
const [isExporting, setIsExporting] = useState24(false);
|
|
3602
|
+
const [error, setError] = useState24(null);
|
|
3603
|
+
const exportNote = useCallback29(
|
|
3428
3604
|
async (noteId) => {
|
|
3429
3605
|
if (!client || !isReady) {
|
|
3430
3606
|
throw new Error("Miden client is not ready");
|
|
@@ -3446,7 +3622,7 @@ function useExportNote() {
|
|
|
3446
3622
|
},
|
|
3447
3623
|
[client, isReady, runExclusive]
|
|
3448
3624
|
);
|
|
3449
|
-
const reset =
|
|
3625
|
+
const reset = useCallback29(() => {
|
|
3450
3626
|
setIsExporting(false);
|
|
3451
3627
|
setError(null);
|
|
3452
3628
|
}, []);
|
|
@@ -3459,12 +3635,12 @@ function useExportNote() {
|
|
|
3459
3635
|
}
|
|
3460
3636
|
|
|
3461
3637
|
// src/hooks/useSyncControl.ts
|
|
3462
|
-
import { useCallback as
|
|
3638
|
+
import { useCallback as useCallback30 } from "react";
|
|
3463
3639
|
function useSyncControl() {
|
|
3464
3640
|
const isPaused = useMidenStore((state) => state.syncPaused);
|
|
3465
3641
|
const setSyncPaused = useMidenStore((state) => state.setSyncPaused);
|
|
3466
|
-
const pauseSync =
|
|
3467
|
-
const resumeSync =
|
|
3642
|
+
const pauseSync = useCallback30(() => setSyncPaused(true), [setSyncPaused]);
|
|
3643
|
+
const resumeSync = useCallback30(() => setSyncPaused(false), [setSyncPaused]);
|
|
3468
3644
|
return {
|
|
3469
3645
|
pauseSync,
|
|
3470
3646
|
resumeSync,
|
|
@@ -3636,9 +3812,11 @@ export {
|
|
|
3636
3812
|
concatBytes,
|
|
3637
3813
|
createMidenStorage,
|
|
3638
3814
|
createNoteAttachment,
|
|
3815
|
+
ensureAccountBech32,
|
|
3639
3816
|
formatAssetAmount,
|
|
3640
3817
|
formatNoteSummary,
|
|
3641
3818
|
getNoteSummary,
|
|
3819
|
+
installAccountBech32,
|
|
3642
3820
|
migrateStorage,
|
|
3643
3821
|
normalizeAccountId,
|
|
3644
3822
|
parseAssetAmount,
|
|
@@ -3664,6 +3842,9 @@ export {
|
|
|
3664
3842
|
useMultiSigner,
|
|
3665
3843
|
useNoteStream,
|
|
3666
3844
|
useNotes,
|
|
3845
|
+
usePswapCancel,
|
|
3846
|
+
usePswapConsume,
|
|
3847
|
+
usePswapCreate,
|
|
3667
3848
|
useSend,
|
|
3668
3849
|
useSessionAccount,
|
|
3669
3850
|
useSigner,
|