@miden-sdk/miden-sdk 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/dist/mt/{Cargo-CZopJ--X.js → Cargo-smJQCGjz.js} +1111 -768
- package/dist/mt/Cargo-smJQCGjz.js.map +1 -0
- package/dist/mt/api-types.d.ts +122 -33
- package/dist/mt/assets/miden_client_web.wasm +0 -0
- package/dist/mt/crates/miden_client_web.d.ts +376 -303
- package/dist/mt/docs-entry.d.ts +3 -0
- package/dist/mt/eager.js +7 -4
- package/dist/mt/eager.js.map +1 -1
- package/dist/mt/index.d.ts +103 -10
- package/dist/mt/index.js +669 -312
- package/dist/mt/index.js.map +1 -1
- package/dist/mt/wasm.js +1 -1
- package/dist/mt/workerHelpers.js +1 -1
- package/dist/mt/workers/{Cargo-CZopJ--X-SsyOTzpb.js → Cargo-smJQCGjz-q4GYXDiD.js} +1111 -768
- package/dist/mt/workers/Cargo-smJQCGjz-q4GYXDiD.js.map +1 -0
- package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
- package/dist/mt/workers/web-client-methods-worker.js +1140 -792
- package/dist/mt/workers/web-client-methods-worker.js.map +1 -1
- package/dist/mt/workers/web-client-methods-worker.module.js +23 -19
- package/dist/mt/workers/web-client-methods-worker.module.js.map +1 -1
- package/dist/mt/workers/workerHelpers.js +1 -1
- package/dist/st/{Cargo-DC6jSekr.js → Cargo-CG4XszZo.js} +1105 -763
- package/dist/st/Cargo-CG4XszZo.js.map +1 -0
- package/dist/st/api-types.d.ts +122 -33
- package/dist/st/assets/miden_client_web.wasm +0 -0
- package/dist/st/crates/miden_client_web.d.ts +376 -303
- package/dist/st/docs-entry.d.ts +3 -0
- package/dist/st/eager.js +7 -4
- package/dist/st/eager.js.map +1 -1
- package/dist/st/index.d.ts +103 -10
- package/dist/st/index.js +669 -312
- package/dist/st/index.js.map +1 -1
- package/dist/st/wasm.js +1 -1
- package/dist/st/workers/{Cargo-DC6jSekr-BG7C7m56.js → Cargo-CG4XszZo-S7EHAZSa.js} +1105 -763
- package/dist/st/workers/Cargo-CG4XszZo-S7EHAZSa.js.map +1 -0
- package/dist/st/workers/assets/miden_client_web.wasm +0 -0
- package/dist/st/workers/web-client-methods-worker.js +1134 -787
- package/dist/st/workers/web-client-methods-worker.js.map +1 -1
- package/dist/st/workers/web-client-methods-worker.module.js +23 -19
- package/dist/st/workers/web-client-methods-worker.module.js.map +1 -1
- package/js/client.js +491 -0
- package/js/node/client-factory.js +117 -0
- package/js/node/loader.js +138 -0
- package/js/node/napi-compat.js +253 -0
- package/js/node-index.js +194 -0
- package/js/resources/accounts.js +222 -0
- package/js/resources/compiler.js +74 -0
- package/js/resources/keystore.js +54 -0
- package/js/resources/notes.js +124 -0
- package/js/resources/settings.js +30 -0
- package/js/resources/tags.js +31 -0
- package/js/resources/transactions.js +667 -0
- package/js/standalone.js +109 -0
- package/js/utils.js +232 -0
- package/package.json +17 -2
- package/dist/mt/Cargo-CZopJ--X.js.map +0 -1
- package/dist/mt/workers/Cargo-CZopJ--X-SsyOTzpb.js.map +0 -1
- package/dist/st/Cargo-DC6jSekr.js.map +0 -1
- package/dist/st/workers/Cargo-DC6jSekr-BG7C7m56.js.map +0 -1
package/dist/mt/index.js
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import loadWasm from './wasm.js';
|
|
2
|
-
|
|
3
|
-
export { Account, AccountBuilder, AccountBuilderResult, AccountCode, AccountComponent, AccountComponentCode, AccountDelta, AccountFile, AccountHeader, AccountId, AccountInterface, AccountProof, AccountReader, AccountStatus, AccountStorage, AccountStorageDelta, AccountStorageMode, AccountStorageRequirements, AccountVaultDelta, Address, AdviceInputs, AdviceMap, AssetVault, AuthFalcon512RpoMultisigConfig, AuthSecretKey, BasicFungibleFaucetComponent, BlockHeader, CodeBuilder, CommittedNote, ConsumableNoteRecord, Endpoint, ExecutedTransaction, Felt, FetchedAccount, FetchedNote, FlattenedU8Vec, ForeignAccount, FungibleAsset, FungibleAssetDelta, FungibleAssetDeltaItem, GetProceduresResultItem, InputNote, InputNoteRecord, InputNoteState, InputNotes, IntoUnderlyingByteSource, IntoUnderlyingSink, IntoUnderlyingSource, JsAccountUpdate, JsStateSyncUpdate, JsStorageMapEntry, JsStorageSlot, JsVaultAsset, Library, MerklePath, NetworkId, NetworkType, Note, NoteAndArgs, NoteAssets, NoteAttachment, NoteAttachmentKind, NoteAttachmentScheme, NoteConsumability, NoteConsumptionStatus, NoteDetails, NoteDetailsAndTag, NoteDetailsAndTagArray, NoteExecutionHint, NoteExportFormat, NoteFile, NoteFilter, NoteFilterTypes, NoteHeader, NoteId, NoteIdAndArgs, NoteInclusionProof, NoteLocation, NoteMetadata, NoteRecipient, NoteScript, NoteStorage, NoteSyncBlock, NoteSyncInfo, NoteTag, NoteType, OutputNote, OutputNoteRecord, OutputNoteState, OutputNotes, Package, PartialNote, Poseidon2, ProcedureThreshold, Program, ProvenTransaction, PublicKey, RpcClient, Rpo256, SerializedInputNoteData, SerializedOutputNoteData, SerializedTransactionData, Signature, SigningInputs, SigningInputsType, SlotAndKeys, SparseMerklePath, StorageMap, StorageMapEntry, StorageMapInfo, StorageMapUpdate, StorageSlot, SyncSummary, TestUtils, TokenSymbol, TransactionArgs, TransactionFilter, TransactionId, TransactionProver, TransactionRecord, TransactionRequest, TransactionRequestBuilder, TransactionResult, TransactionScript, TransactionScriptInputPair, TransactionStatus, TransactionStoreUpdate, TransactionSummary, WebClient, WebKeystoreApi, Word, createAuthFalcon512RpoMultisig, exportStore, importStore, initSync, initThreadPool, parallelSumBench, rayonThreadCount, sequentialSumBench, setupLogging, wbg_rayon_PoolBuilder, wbg_rayon_start_worker } from './Cargo-CZopJ--X.js';
|
|
2
|
+
export { Account, AccountArray, AccountBuilder, AccountBuilderResult, AccountCode, AccountComponent, AccountComponentCode, AccountDelta, AccountFile, AccountHeader, AccountId, AccountIdArray, AccountInterface, AccountProof, AccountReader, AccountStatus, AccountStorage, AccountStorageDelta, AccountStorageMode, AccountStorageRequirements, AccountVaultDelta, Address, AdviceInputs, AdviceMap, AssetVault, AuthFalcon512RpoMultisigConfig, AuthSecretKey, BasicFungibleFaucetComponent, BlockHeader, CodeBuilder, CommittedNote, ConsumableNoteRecord, Endpoint, ExecutedTransaction, Felt, FeltArray, FetchedAccount, FetchedNote, FlattenedU8Vec, ForeignAccount, ForeignAccountArray, FungibleAsset, FungibleAssetDelta, FungibleAssetDeltaItem, GetProceduresResultItem, InputNote, InputNoteRecord, InputNoteState, InputNotes, IntoUnderlyingByteSource, IntoUnderlyingSink, IntoUnderlyingSource, JsAccountUpdate, JsStateSyncUpdate, JsStorageMapEntry, JsStorageSlot, JsVaultAsset, Library, MerklePath, NetworkId, NetworkNoteStatusInfo, NetworkType, Note, NoteAndArgs, NoteAndArgsArray, NoteArray, NoteAssets, NoteAttachment, NoteAttachmentScheme, NoteConsumability, NoteConsumptionStatus, NoteDetails, NoteDetailsAndTag, NoteDetailsAndTagArray, NoteExecutionHint, NoteExportFormat, NoteFile, NoteFilter, NoteFilterTypes, NoteHeader, NoteId, NoteIdAndArgs, NoteIdAndArgsArray, NoteInclusionProof, NoteLocation, NoteMetadata, NoteRecipient, NoteRecipientArray, NoteScript, NoteStorage, NoteSyncBlock, NoteSyncInfo, NoteTag, NoteType, OutputNote, OutputNoteArray, OutputNoteRecord, OutputNoteState, OutputNotes, Package, PartialNote, Poseidon2, ProcedureThreshold, Program, ProvenTransaction, PublicKey, RpcClient, Rpo256, SerializedInputNoteData, SerializedOutputNoteData, SerializedTransactionData, Signature, SigningInputs, SigningInputsType, SlotAndKeys, SparseMerklePath, StorageMap, StorageMapEntry, StorageMapEntryJs, StorageMapInfo, StorageMapUpdate, StorageSlot, StorageSlotArray, SyncSummary, TestUtils, TokenSymbol, TransactionArgs, TransactionFilter, TransactionId, TransactionProver, TransactionRecord, TransactionRequest, TransactionRequestBuilder, TransactionResult, TransactionScript, TransactionScriptInputPair, TransactionScriptInputPairArray, TransactionStatus, TransactionStoreUpdate, TransactionSummary, WebClient, WebKeystoreApi, Word, createAuthFalcon512RpoMultisig, exportStore, importStore, initSync, initThreadPool, parallelSumBench, rayonThreadCount, sequentialSumBench, setupLogging, wbg_rayon_PoolBuilder, wbg_rayon_start_worker } from './Cargo-smJQCGjz.js';
|
|
4
3
|
|
|
5
4
|
const WorkerAction = Object.freeze({
|
|
6
5
|
INIT: "init",
|
|
@@ -352,31 +351,18 @@ function resolveStorageMode(mode, wasm) {
|
|
|
352
351
|
}
|
|
353
352
|
|
|
354
353
|
/**
|
|
355
|
-
* Resolves an auth scheme string to a WASM
|
|
354
|
+
* Resolves an auth scheme string to a WASM AuthScheme enum value.
|
|
356
355
|
*
|
|
357
|
-
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
360
|
-
* expect the numeric variant from the Rust `AuthScheme` enum. This helper
|
|
361
|
-
* bridges the two so callers never touch wasm-bindgen internals directly.
|
|
362
|
-
*
|
|
363
|
-
* `wasm` is optional: when provided (by internal callers who already have
|
|
364
|
-
* the module loaded), the numeric value is read from the binding itself,
|
|
365
|
-
* keeping the mapping robust if wasm-bindgen ever renumbers the enum. When
|
|
366
|
-
* omitted (public callers who don't have a handle to the WASM module), the
|
|
367
|
-
* hardcoded discriminants below are used — these are pinned to the Rust
|
|
368
|
-
* enum order by a cross-check test in `test/account_component.test.ts`.
|
|
369
|
-
*
|
|
370
|
-
* @param {"falcon" | "ecdsa" | undefined} scheme - Defaults to `"falcon"`.
|
|
371
|
-
* @param {object} [wasm] - Optional WASM module handle.
|
|
372
|
-
* @returns {number} The AuthScheme enum numeric value (1 or 2).
|
|
356
|
+
* @param {string | undefined} scheme - "falcon" or "ecdsa". Defaults to "falcon".
|
|
357
|
+
* @param {object} wasm - The WASM module.
|
|
358
|
+
* @returns {number} The AuthScheme enum value.
|
|
373
359
|
*/
|
|
374
360
|
function resolveAuthScheme(scheme, wasm) {
|
|
375
361
|
if (scheme === "ecdsa") {
|
|
376
|
-
return wasm
|
|
362
|
+
return wasm.AuthScheme.AuthEcdsaK256Keccak;
|
|
377
363
|
}
|
|
378
364
|
if (scheme === "falcon" || scheme == null) {
|
|
379
|
-
return wasm
|
|
365
|
+
return wasm.AuthScheme.AuthRpoFalcon512;
|
|
380
366
|
}
|
|
381
367
|
throw new Error(
|
|
382
368
|
`Unknown auth scheme: "${scheme}". Expected "falcon" or "ecdsa".`
|
|
@@ -519,6 +505,7 @@ class AccountsResource {
|
|
|
519
505
|
return await this.#inner.newFaucet(
|
|
520
506
|
storageMode,
|
|
521
507
|
type === 1 || type === "NonFungibleFaucet",
|
|
508
|
+
opts.name ?? opts.symbol,
|
|
522
509
|
opts.symbol,
|
|
523
510
|
opts.decimals,
|
|
524
511
|
BigInt(opts.maxSupply),
|
|
@@ -551,21 +538,27 @@ class AccountsResource {
|
|
|
551
538
|
if (!opts.auth)
|
|
552
539
|
throw new Error("Contract creation requires an 'auth' (AuthSecretKey)");
|
|
553
540
|
|
|
554
|
-
//
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
? wasm.AccountType.RegularAccountUpdatableCode
|
|
558
|
-
: wasm.AccountType.RegularAccountImmutableCode;
|
|
541
|
+
// The 0.15 protocol has no code-mutability distinction, so the `type`
|
|
542
|
+
// ("ImmutableContract" / "MutableContract") only steers routing here; the
|
|
543
|
+
// account's on-chain visibility is set entirely by `storageMode`.
|
|
559
544
|
const storageMode = resolveStorageMode(opts.storage ?? "public", wasm);
|
|
560
545
|
const authComponent =
|
|
561
546
|
wasm.AccountComponent.createAuthComponentFromSecretKey(opts.auth);
|
|
562
547
|
|
|
548
|
+
// Schema commitment from `build()` is not a substitute for contract code; require explicit
|
|
549
|
+
// `components` so auth-only contracts are rejected at this layer.
|
|
550
|
+
const components = opts.components ?? [];
|
|
551
|
+
if (components.length === 0) {
|
|
552
|
+
throw new Error(
|
|
553
|
+
"Contract accounts require at least one non-auth procedure: pass at least one entry in `components`."
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
|
|
563
557
|
let builder = new wasm.AccountBuilder(opts.seed)
|
|
564
|
-
.accountType(accountTypeEnum)
|
|
565
558
|
.storageMode(storageMode)
|
|
566
559
|
.withAuthComponent(authComponent);
|
|
567
560
|
|
|
568
|
-
for (const component of
|
|
561
|
+
for (const component of components) {
|
|
569
562
|
builder = builder.withComponent(component);
|
|
570
563
|
}
|
|
571
564
|
|
|
@@ -607,7 +600,9 @@ class AccountsResource {
|
|
|
607
600
|
if (!account) {
|
|
608
601
|
throw new Error(`Account not found: ${id.toString()}`);
|
|
609
602
|
}
|
|
610
|
-
const keys =
|
|
603
|
+
const keys = this.#inner.keystore
|
|
604
|
+
? await this.#inner.keystore.getCommitments(id)
|
|
605
|
+
: await this.#inner.getPublicKeyCommitmentsOfAccount(id);
|
|
611
606
|
return {
|
|
612
607
|
account,
|
|
613
608
|
vault: account.vault(),
|
|
@@ -622,7 +617,7 @@ class AccountsResource {
|
|
|
622
617
|
const wasm = await this.#getWasm();
|
|
623
618
|
const accountId = resolveAccountRef(accountRef, wasm);
|
|
624
619
|
const faucetId = resolveAccountRef(tokenRef, wasm);
|
|
625
|
-
const reader = this.#inner.accountReader(accountId);
|
|
620
|
+
const reader = await this.#inner.accountReader(accountId);
|
|
626
621
|
return await reader.getBalance(faucetId);
|
|
627
622
|
}
|
|
628
623
|
|
|
@@ -870,6 +865,72 @@ class TransactionsResource {
|
|
|
870
865
|
return { txId, result };
|
|
871
866
|
}
|
|
872
867
|
|
|
868
|
+
/** Create a partial-swap (PSWAP) note. See {@link PswapCreateOptions}. */
|
|
869
|
+
async pswapCreate(opts) {
|
|
870
|
+
this.#client.assertNotTerminated();
|
|
871
|
+
const wasm = await this.#getWasm();
|
|
872
|
+
const { accountId, request } = await this.#buildPswapCreateRequest(
|
|
873
|
+
opts,
|
|
874
|
+
wasm
|
|
875
|
+
);
|
|
876
|
+
|
|
877
|
+
const { txId, result } = await this.#submitOrSubmitWithProver(
|
|
878
|
+
accountId,
|
|
879
|
+
request,
|
|
880
|
+
opts.prover
|
|
881
|
+
);
|
|
882
|
+
|
|
883
|
+
if (opts.waitForConfirmation) {
|
|
884
|
+
await this.waitFor(txId.toHex(), { timeout: opts.timeout });
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
return { txId, result };
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/** Consume (fully or partially fill) a PSWAP note. See {@link PswapConsumeOptions}. */
|
|
891
|
+
async pswapConsume(opts) {
|
|
892
|
+
this.#client.assertNotTerminated();
|
|
893
|
+
const wasm = await this.#getWasm();
|
|
894
|
+
const { accountId, request } = await this.#buildPswapConsumeRequest(
|
|
895
|
+
opts,
|
|
896
|
+
wasm
|
|
897
|
+
);
|
|
898
|
+
|
|
899
|
+
const { txId, result } = await this.#submitOrSubmitWithProver(
|
|
900
|
+
accountId,
|
|
901
|
+
request,
|
|
902
|
+
opts.prover
|
|
903
|
+
);
|
|
904
|
+
|
|
905
|
+
if (opts.waitForConfirmation) {
|
|
906
|
+
await this.waitFor(txId.toHex(), { timeout: opts.timeout });
|
|
907
|
+
}
|
|
908
|
+
|
|
909
|
+
return { txId, result };
|
|
910
|
+
}
|
|
911
|
+
|
|
912
|
+
/** Cancel a PSWAP note as its creator and reclaim the offered asset. See {@link PswapCancelOptions}. */
|
|
913
|
+
async pswapCancel(opts) {
|
|
914
|
+
this.#client.assertNotTerminated();
|
|
915
|
+
const wasm = await this.#getWasm();
|
|
916
|
+
const { accountId, request } = await this.#buildPswapCancelRequest(
|
|
917
|
+
opts,
|
|
918
|
+
wasm
|
|
919
|
+
);
|
|
920
|
+
|
|
921
|
+
const { txId, result } = await this.#submitOrSubmitWithProver(
|
|
922
|
+
accountId,
|
|
923
|
+
request,
|
|
924
|
+
opts.prover
|
|
925
|
+
);
|
|
926
|
+
|
|
927
|
+
if (opts.waitForConfirmation) {
|
|
928
|
+
await this.waitFor(txId.toHex(), { timeout: opts.timeout });
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
return { txId, result };
|
|
932
|
+
}
|
|
933
|
+
|
|
873
934
|
async preview(opts) {
|
|
874
935
|
this.#client.assertNotTerminated();
|
|
875
936
|
const wasm = await this.#getWasm();
|
|
@@ -894,6 +955,27 @@ class TransactionsResource {
|
|
|
894
955
|
({ accountId, request } = await this.#buildSwapRequest(opts, wasm));
|
|
895
956
|
break;
|
|
896
957
|
}
|
|
958
|
+
case "pswapCreate": {
|
|
959
|
+
({ accountId, request } = await this.#buildPswapCreateRequest(
|
|
960
|
+
opts,
|
|
961
|
+
wasm
|
|
962
|
+
));
|
|
963
|
+
break;
|
|
964
|
+
}
|
|
965
|
+
case "pswapConsume": {
|
|
966
|
+
({ accountId, request } = await this.#buildPswapConsumeRequest(
|
|
967
|
+
opts,
|
|
968
|
+
wasm
|
|
969
|
+
));
|
|
970
|
+
break;
|
|
971
|
+
}
|
|
972
|
+
case "pswapCancel": {
|
|
973
|
+
({ accountId, request } = await this.#buildPswapCancelRequest(
|
|
974
|
+
opts,
|
|
975
|
+
wasm
|
|
976
|
+
));
|
|
977
|
+
break;
|
|
978
|
+
}
|
|
897
979
|
case "custom": {
|
|
898
980
|
accountId = resolveAccountRef(opts.account, wasm);
|
|
899
981
|
request = opts.request;
|
|
@@ -1180,6 +1262,53 @@ class TransactionsResource {
|
|
|
1180
1262
|
return { accountId, request };
|
|
1181
1263
|
}
|
|
1182
1264
|
|
|
1265
|
+
async #buildPswapCreateRequest(opts, wasm) {
|
|
1266
|
+
const accountId = resolveAccountRef(opts.account, wasm);
|
|
1267
|
+
const offeredFaucetId = resolveAccountRef(opts.offer.token, wasm);
|
|
1268
|
+
const requestedFaucetId = resolveAccountRef(opts.request.token, wasm);
|
|
1269
|
+
const noteType = resolveNoteType(opts.type, wasm);
|
|
1270
|
+
const paybackNoteType = resolveNoteType(
|
|
1271
|
+
opts.paybackType ?? opts.type,
|
|
1272
|
+
wasm
|
|
1273
|
+
);
|
|
1274
|
+
|
|
1275
|
+
const request = await this.#inner.newPswapCreateTransactionRequest(
|
|
1276
|
+
accountId,
|
|
1277
|
+
offeredFaucetId,
|
|
1278
|
+
BigInt(opts.offer.amount),
|
|
1279
|
+
requestedFaucetId,
|
|
1280
|
+
BigInt(opts.request.amount),
|
|
1281
|
+
noteType,
|
|
1282
|
+
paybackNoteType
|
|
1283
|
+
);
|
|
1284
|
+
return { accountId, request };
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1287
|
+
async #buildPswapConsumeRequest(opts, wasm) {
|
|
1288
|
+
const accountId = resolveAccountRef(opts.account, wasm);
|
|
1289
|
+
const note = await this.#resolveNoteInput(opts.note);
|
|
1290
|
+
const noteFillAmount = opts.noteFillAmount ?? 0n;
|
|
1291
|
+
|
|
1292
|
+
const request = await this.#inner.newPswapConsumeTransactionRequest(
|
|
1293
|
+
note,
|
|
1294
|
+
accountId,
|
|
1295
|
+
BigInt(opts.fillAmount),
|
|
1296
|
+
BigInt(noteFillAmount)
|
|
1297
|
+
);
|
|
1298
|
+
return { accountId, request };
|
|
1299
|
+
}
|
|
1300
|
+
|
|
1301
|
+
async #buildPswapCancelRequest(opts, wasm) {
|
|
1302
|
+
const accountId = resolveAccountRef(opts.account, wasm);
|
|
1303
|
+
const note = await this.#resolveNoteInput(opts.note);
|
|
1304
|
+
|
|
1305
|
+
const request = await this.#inner.newPswapCancelTransactionRequest(
|
|
1306
|
+
note,
|
|
1307
|
+
accountId
|
|
1308
|
+
);
|
|
1309
|
+
return { accountId, request };
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1183
1312
|
async #resolveNoteInput(input) {
|
|
1184
1313
|
if (typeof input === "string") {
|
|
1185
1314
|
const record = await this.#inner.getInputNote(input);
|
|
@@ -1215,13 +1344,8 @@ class TransactionsResource {
|
|
|
1215
1344
|
async #submitOrSubmitWithProver(accountId, request, perCallProver) {
|
|
1216
1345
|
const result = await this.#inner.executeTransaction(accountId, request);
|
|
1217
1346
|
const prover = perCallProver ?? this.#client.defaultProver;
|
|
1218
|
-
// Use proveTransactionWithProver (by-reference) when a prover is
|
|
1219
|
-
// provided, so the JS-side handle is NOT consumed by wasm-bindgen.
|
|
1220
|
-
// Passing the prover by value would transfer ownership and invalidate
|
|
1221
|
-
// the JS object after one call, causing silent fallback to local
|
|
1222
|
-
// proving on reuse.
|
|
1223
1347
|
const proven = prover
|
|
1224
|
-
? await this.#inner.
|
|
1348
|
+
? await this.#inner.proveTransaction(result, prover)
|
|
1225
1349
|
: await this.#inner.proveTransaction(result);
|
|
1226
1350
|
const txId = result.id();
|
|
1227
1351
|
const height = await this.#inner.submitProvenTransaction(proven, result);
|
|
@@ -1432,7 +1556,7 @@ class CompilerResource {
|
|
|
1432
1556
|
async component({ code, slots = [], supportAllTypes = true }) {
|
|
1433
1557
|
this.#client?.assertNotTerminated();
|
|
1434
1558
|
const wasm = await this.#getWasm();
|
|
1435
|
-
const builder = this.#inner.createCodeBuilder();
|
|
1559
|
+
const builder = await this.#inner.createCodeBuilder();
|
|
1436
1560
|
const compiled = builder.compileAccountComponentCode(code);
|
|
1437
1561
|
const component = wasm.AccountComponent.compile(compiled, slots);
|
|
1438
1562
|
return supportAllTypes ? component.withSupportsAllTypes() : component;
|
|
@@ -1448,7 +1572,7 @@ class CompilerResource {
|
|
|
1448
1572
|
this.#client?.assertNotTerminated();
|
|
1449
1573
|
// Ensure WASM is initialized (result unused — only #inner needs it)
|
|
1450
1574
|
await this.#getWasm();
|
|
1451
|
-
const builder = this.#inner.createCodeBuilder();
|
|
1575
|
+
const builder = await this.#inner.createCodeBuilder();
|
|
1452
1576
|
linkLibraries(builder, libraries);
|
|
1453
1577
|
return builder.compileTxScript(code);
|
|
1454
1578
|
}
|
|
@@ -1462,7 +1586,7 @@ class CompilerResource {
|
|
|
1462
1586
|
async noteScript({ code, libraries = [] }) {
|
|
1463
1587
|
this.#client?.assertNotTerminated();
|
|
1464
1588
|
await this.#getWasm();
|
|
1465
|
-
const builder = this.#inner.createCodeBuilder();
|
|
1589
|
+
const builder = await this.#inner.createCodeBuilder();
|
|
1466
1590
|
linkLibraries(builder, libraries);
|
|
1467
1591
|
return builder.compileNoteScript(code);
|
|
1468
1592
|
}
|
|
@@ -1498,32 +1622,47 @@ class KeystoreResource {
|
|
|
1498
1622
|
|
|
1499
1623
|
async insert(accountId, secretKey) {
|
|
1500
1624
|
this.#client.assertNotTerminated();
|
|
1501
|
-
|
|
1502
|
-
|
|
1625
|
+
if (this.#inner.keystore) {
|
|
1626
|
+
return await this.#inner.keystore.insert(accountId, secretKey);
|
|
1627
|
+
}
|
|
1628
|
+
return await this.#inner.addAccountSecretKeyToWebStore(
|
|
1629
|
+
accountId,
|
|
1630
|
+
secretKey
|
|
1631
|
+
);
|
|
1503
1632
|
}
|
|
1504
1633
|
|
|
1505
1634
|
async get(pubKeyCommitment) {
|
|
1506
1635
|
this.#client.assertNotTerminated();
|
|
1507
|
-
|
|
1508
|
-
|
|
1636
|
+
if (this.#inner.keystore) {
|
|
1637
|
+
return await this.#inner.keystore.get(pubKeyCommitment);
|
|
1638
|
+
}
|
|
1639
|
+
return await this.#inner.getAccountAuthByPubKeyCommitment(pubKeyCommitment);
|
|
1509
1640
|
}
|
|
1510
1641
|
|
|
1511
1642
|
async remove(pubKeyCommitment) {
|
|
1512
1643
|
this.#client.assertNotTerminated();
|
|
1513
|
-
|
|
1514
|
-
|
|
1644
|
+
if (this.#inner.keystore) {
|
|
1645
|
+
return await this.#inner.keystore.remove(pubKeyCommitment);
|
|
1646
|
+
}
|
|
1647
|
+
throw new Error("remove() is not supported on this platform");
|
|
1515
1648
|
}
|
|
1516
1649
|
|
|
1517
1650
|
async getCommitments(accountId) {
|
|
1518
1651
|
this.#client.assertNotTerminated();
|
|
1519
|
-
|
|
1520
|
-
|
|
1652
|
+
if (this.#inner.keystore) {
|
|
1653
|
+
return await this.#inner.keystore.getCommitments(accountId);
|
|
1654
|
+
}
|
|
1655
|
+
return await this.#inner.getPublicKeyCommitmentsOfAccount(accountId);
|
|
1521
1656
|
}
|
|
1522
1657
|
|
|
1523
1658
|
async getAccountId(pubKeyCommitment) {
|
|
1524
1659
|
this.#client.assertNotTerminated();
|
|
1525
|
-
|
|
1526
|
-
|
|
1660
|
+
if (this.#inner.keystore) {
|
|
1661
|
+
return await this.#inner.keystore.getAccountId(pubKeyCommitment);
|
|
1662
|
+
}
|
|
1663
|
+
const account =
|
|
1664
|
+
await this.#inner.getAccountByKeyCommitment(pubKeyCommitment);
|
|
1665
|
+
return account ? account.id() : undefined;
|
|
1527
1666
|
}
|
|
1528
1667
|
}
|
|
1529
1668
|
|
|
@@ -1678,7 +1817,7 @@ class MidenClient {
|
|
|
1678
1817
|
options.keystore.getKey,
|
|
1679
1818
|
options.keystore.insertKey,
|
|
1680
1819
|
options.keystore.sign,
|
|
1681
|
-
|
|
1820
|
+
options?.debugMode,
|
|
1682
1821
|
useWorker
|
|
1683
1822
|
);
|
|
1684
1823
|
} else {
|
|
@@ -1687,7 +1826,7 @@ class MidenClient {
|
|
|
1687
1826
|
noteTransportUrl,
|
|
1688
1827
|
seed,
|
|
1689
1828
|
options?.storeName,
|
|
1690
|
-
|
|
1829
|
+
options?.debugMode,
|
|
1691
1830
|
useWorker
|
|
1692
1831
|
);
|
|
1693
1832
|
}
|
|
@@ -1868,6 +2007,13 @@ class MidenClient {
|
|
|
1868
2007
|
* otherwise erase. Call immediately after catching a failed
|
|
1869
2008
|
* `transactions.submit` / `transactions.send` / `transactions.consume`.
|
|
1870
2009
|
*
|
|
2010
|
+
* Meaningful only with `useWorker: false`: under the worker shim the
|
|
2011
|
+
* sign callback fires against the worker's WASM keystore, while this
|
|
2012
|
+
* accessor reads the main-thread instance — which never signed — so it
|
|
2013
|
+
* returns `null`. Consumers that need this signal (e.g. external
|
|
2014
|
+
* keystores with lock-aware sign callbacks) already require
|
|
2015
|
+
* `useWorker: false` for the callback to be reachable at all.
|
|
2016
|
+
*
|
|
1871
2017
|
* @returns {any} The raw thrown value, or `null`.
|
|
1872
2018
|
*/
|
|
1873
2019
|
lastAuthError() {
|
|
@@ -1896,9 +2042,9 @@ class MidenClient {
|
|
|
1896
2042
|
*
|
|
1897
2043
|
* @returns {string} The store identifier.
|
|
1898
2044
|
*/
|
|
1899
|
-
storeIdentifier() {
|
|
2045
|
+
async storeIdentifier() {
|
|
1900
2046
|
this.assertNotTerminated();
|
|
1901
|
-
return this.#inner.storeIdentifier();
|
|
2047
|
+
return await this.#inner.storeIdentifier();
|
|
1902
2048
|
}
|
|
1903
2049
|
|
|
1904
2050
|
// ── Mock-only methods ──
|
|
@@ -2112,55 +2258,337 @@ function buildNoteAssets(assets, wasm) {
|
|
|
2112
2258
|
}
|
|
2113
2259
|
|
|
2114
2260
|
/**
|
|
2115
|
-
*
|
|
2261
|
+
* StorageView wraps the raw WASM AccountStorage to provide a developer-friendly
|
|
2262
|
+
* (and AI-agent-friendly) API.
|
|
2116
2263
|
*
|
|
2117
|
-
*
|
|
2118
|
-
*
|
|
2119
|
-
*
|
|
2120
|
-
*
|
|
2121
|
-
* is unchanged so the JS object looks fine, but any subsequent method call
|
|
2122
|
-
* panics inside WASM with the opaque `"null pointer passed to rust"`
|
|
2123
|
-
* error from wasm-bindgen.
|
|
2264
|
+
* Key behavior: `getItem()` returns a `StorageResult` that works intuitively for
|
|
2265
|
+
* both Value and StorageMap slots. The result has `.toBigInt()`, `.toHex()`, and
|
|
2266
|
+
* `.toString()` methods that do the right thing automatically. For StorageMap slots,
|
|
2267
|
+
* `.entries` provides access to all map entries.
|
|
2124
2268
|
*
|
|
2125
|
-
*
|
|
2126
|
-
*
|
|
2127
|
-
*
|
|
2128
|
-
*
|
|
2129
|
-
* clones — leaving the originals fully usable afterwards.
|
|
2269
|
+
* Numeric ergonomics: `StorageResult` is usable directly in template strings,
|
|
2270
|
+
* JSX, and arithmetic via `toString()` (lossless, BigInt-backed) and `valueOf()`
|
|
2271
|
+
* (returns a JS number for values that fit, throws on overflow — never silently
|
|
2272
|
+
* corrupts). For exact u64 access use `.toBigInt()`.
|
|
2130
2273
|
*
|
|
2131
|
-
* The
|
|
2132
|
-
*
|
|
2133
|
-
* methods) keep working transparently.
|
|
2274
|
+
* The raw WASM AccountStorage is still accessible via `.raw` for advanced use cases
|
|
2275
|
+
* that need the original behavior (e.g., comparing map commitment roots).
|
|
2134
2276
|
*/
|
|
2277
|
+
/** @param {string} hex @param {typeof Word} WordClass @returns {Word | undefined} */
|
|
2278
|
+
function hexToWord(hex, WordClass) {
|
|
2279
|
+
if (!hex || !WordClass) return undefined;
|
|
2280
|
+
try {
|
|
2281
|
+
return WordClass.fromHex(hex);
|
|
2282
|
+
} catch {
|
|
2283
|
+
return undefined;
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2135
2286
|
|
|
2287
|
+
class StorageView {
|
|
2288
|
+
#storage;
|
|
2289
|
+
#WordClass;
|
|
2136
2290
|
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2142
|
-
|
|
2143
|
-
|
|
2144
|
-
|
|
2145
|
-
|
|
2146
|
-
|
|
2291
|
+
/**
|
|
2292
|
+
* @param {AccountStorage} wasmStorage
|
|
2293
|
+
* @param {typeof Word} WordClass
|
|
2294
|
+
*/
|
|
2295
|
+
constructor(wasmStorage, WordClass) {
|
|
2296
|
+
this.#storage = wasmStorage;
|
|
2297
|
+
this.#WordClass = WordClass;
|
|
2298
|
+
}
|
|
2299
|
+
|
|
2300
|
+
/**
|
|
2301
|
+
* The raw WASM AccountStorage, for cases where you need the original
|
|
2302
|
+
* primitive behavior (e.g., reading map commitment roots via raw.getItem()).
|
|
2303
|
+
*/
|
|
2304
|
+
get raw() {
|
|
2305
|
+
return this.#storage;
|
|
2306
|
+
}
|
|
2307
|
+
|
|
2308
|
+
/**
|
|
2309
|
+
* Returns the commitment to the full account storage.
|
|
2310
|
+
*/
|
|
2311
|
+
commitment() {
|
|
2312
|
+
return this.#storage.commitment();
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
/**
|
|
2316
|
+
* Returns the names of all storage slots on this account.
|
|
2317
|
+
* @returns {string[]}
|
|
2318
|
+
*/
|
|
2319
|
+
getSlotNames() {
|
|
2320
|
+
return this.#storage.getSlotNames();
|
|
2321
|
+
}
|
|
2322
|
+
|
|
2323
|
+
/**
|
|
2324
|
+
* Returns a StorageResult for the given slot.
|
|
2325
|
+
*
|
|
2326
|
+
* The result has convenience methods that work for both Value and StorageMap slots:
|
|
2327
|
+
* - `.toBigInt()` — first felt as BigInt (full u64 precision)
|
|
2328
|
+
* - `.toHex()` — first felt's Word as hex string
|
|
2329
|
+
* - `.toString()` — renders as the BigInt value (works in JSX: {result})
|
|
2330
|
+
* - `.isMap` — true if this is a StorageMap slot
|
|
2331
|
+
* - `.entries` — all map entries (undefined for Value slots)
|
|
2332
|
+
* - `.word` — the underlying Word value
|
|
2333
|
+
*
|
|
2334
|
+
* The result is also usable directly in arithmetic (`+result`, `result * 2`)
|
|
2335
|
+
* via `valueOf()`, which returns a JS number for values that fit and throws
|
|
2336
|
+
* `RangeError` for values exceeding `Number.MAX_SAFE_INTEGER` — use `.toBigInt()`
|
|
2337
|
+
* for exact access to large u64 values.
|
|
2338
|
+
*
|
|
2339
|
+
* For explicit key-based map reads, use `getMapItem(slotName, key)`.
|
|
2340
|
+
* For the raw commitment hash, use `raw.getItem(slotName)`.
|
|
2341
|
+
*
|
|
2342
|
+
* @param {string} slotName
|
|
2343
|
+
* @returns {StorageResult | undefined}
|
|
2344
|
+
*/
|
|
2345
|
+
getItem(slotName) {
|
|
2346
|
+
// Type detection + value retrieval in one pass.
|
|
2347
|
+
// We call getMapEntries to detect maps, but defer parsing the entries
|
|
2348
|
+
// until .entries is actually accessed (lazy). Only the first entry's
|
|
2349
|
+
// Word is parsed eagerly for the convenience methods (toBigInt, etc.).
|
|
2350
|
+
const rawEntries = this.#storage.getMapEntries(slotName);
|
|
2351
|
+
if (rawEntries !== undefined && rawEntries !== null) {
|
|
2352
|
+
// StorageMap — parse only the first entry eagerly
|
|
2353
|
+
const firstWord =
|
|
2354
|
+
rawEntries.length > 0
|
|
2355
|
+
? hexToWord(rawEntries[0].value, this.#WordClass)
|
|
2356
|
+
: undefined;
|
|
2357
|
+
return new StorageResult(firstWord, true, rawEntries, this.#WordClass);
|
|
2147
2358
|
}
|
|
2148
|
-
|
|
2359
|
+
|
|
2360
|
+
// Value slot — use raw getItem
|
|
2361
|
+
const word = this.#storage.getItem(slotName);
|
|
2362
|
+
if (!word) return undefined;
|
|
2363
|
+
return new StorageResult(word, false, undefined, this.#WordClass);
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
/**
|
|
2367
|
+
* Returns the value for a key in a StorageMap slot.
|
|
2368
|
+
* Delegates directly to the raw WASM method.
|
|
2369
|
+
*
|
|
2370
|
+
* @param {string} slotName
|
|
2371
|
+
* @param {Word} key
|
|
2372
|
+
* @returns {Word | undefined}
|
|
2373
|
+
*/
|
|
2374
|
+
getMapItem(slotName, key) {
|
|
2375
|
+
return this.#storage.getMapItem(slotName, key);
|
|
2376
|
+
}
|
|
2377
|
+
|
|
2378
|
+
/**
|
|
2379
|
+
* Get all key-value pairs from a StorageMap slot.
|
|
2380
|
+
* Returns undefined if the slot isn't a map, or an empty array if the map is empty.
|
|
2381
|
+
*/
|
|
2382
|
+
getMapEntries(slotName) {
|
|
2383
|
+
return this.#storage.getMapEntries(slotName);
|
|
2384
|
+
}
|
|
2385
|
+
|
|
2386
|
+
/**
|
|
2387
|
+
* Returns the commitment root of a storage slot as a Word.
|
|
2388
|
+
*
|
|
2389
|
+
* For Value slots, this is the stored Word itself.
|
|
2390
|
+
* For StorageMap slots, this is the Merkle root hash of the map — useful for:
|
|
2391
|
+
* - Verifying state hasn't changed between transactions
|
|
2392
|
+
* - Merkle inclusion proofs against the account state
|
|
2393
|
+
* - Comparing map state across accounts or sync cycles
|
|
2394
|
+
*
|
|
2395
|
+
* This is the raw protocol-level value. For reading stored data, use `getItem()`.
|
|
2396
|
+
*
|
|
2397
|
+
* @param {string} slotName
|
|
2398
|
+
* @returns {Word | undefined}
|
|
2399
|
+
*/
|
|
2400
|
+
getCommitment(slotName) {
|
|
2401
|
+
return this.#storage.getItem(slotName);
|
|
2402
|
+
}
|
|
2149
2403
|
}
|
|
2150
2404
|
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
|
|
2154
|
-
|
|
2155
|
-
|
|
2156
|
-
|
|
2157
|
-
|
|
2158
|
-
|
|
2159
|
-
|
|
2160
|
-
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2405
|
+
/**
|
|
2406
|
+
* Result of reading a storage slot. Works for both Value and StorageMap slots.
|
|
2407
|
+
*
|
|
2408
|
+
* Provides a unified interface so code like `storage.getItem(name).toBigInt()`
|
|
2409
|
+
* works regardless of the underlying slot type.
|
|
2410
|
+
*
|
|
2411
|
+
* For StorageMap slots, the convenience methods (toHex, toBigInt) operate on
|
|
2412
|
+
* the first entry's value. The full map data is available via `.entries`.
|
|
2413
|
+
* Note: Miden storage maps are Merkle-based, so "first" is determined by key hash
|
|
2414
|
+
* order — deterministic for a given map state, but not meaningful as an ordering.
|
|
2415
|
+
*/
|
|
2416
|
+
class StorageResult {
|
|
2417
|
+
#word;
|
|
2418
|
+
#isMap;
|
|
2419
|
+
#rawEntries; // Raw JsStorageMapEntry[] from WASM — parsed lazily
|
|
2420
|
+
#parsedEntries; // Parsed entries with Word objects — created on first .entries access
|
|
2421
|
+
#WordClass;
|
|
2422
|
+
|
|
2423
|
+
/**
|
|
2424
|
+
* @param {Word | undefined} word — the primary Word value (first entry for maps)
|
|
2425
|
+
* @param {boolean} isMap — whether this came from a StorageMap slot
|
|
2426
|
+
* @param {Array | undefined} rawEntries — raw WASM entries (parsed lazily on .entries access)
|
|
2427
|
+
* @param {typeof Word} WordClass — Word constructor for hex parsing
|
|
2428
|
+
*/
|
|
2429
|
+
constructor(word, isMap, rawEntries, WordClass) {
|
|
2430
|
+
this.#word = word;
|
|
2431
|
+
this.#isMap = isMap;
|
|
2432
|
+
this.#rawEntries = rawEntries;
|
|
2433
|
+
this.#WordClass = WordClass;
|
|
2434
|
+
}
|
|
2435
|
+
|
|
2436
|
+
/** True if this slot is a StorageMap. */
|
|
2437
|
+
get isMap() {
|
|
2438
|
+
return this.#isMap;
|
|
2439
|
+
}
|
|
2440
|
+
|
|
2441
|
+
/**
|
|
2442
|
+
* All entries from a StorageMap slot (lazily parsed on first access).
|
|
2443
|
+
* Each entry has { key: string (hex), value: string (hex), word: Word | undefined }.
|
|
2444
|
+
* Returns undefined for Value slots.
|
|
2445
|
+
*/
|
|
2446
|
+
get entries() {
|
|
2447
|
+
if (!this.#isMap) return undefined;
|
|
2448
|
+
if (this.#parsedEntries) return this.#parsedEntries;
|
|
2449
|
+
if (!this.#rawEntries) return [];
|
|
2450
|
+
|
|
2451
|
+
// Parse entries lazily — only when the user actually accesses .entries
|
|
2452
|
+
this.#parsedEntries = this.#rawEntries.map((e) => ({
|
|
2453
|
+
key: e.key,
|
|
2454
|
+
value: e.value,
|
|
2455
|
+
word: hexToWord(e.value, this.#WordClass),
|
|
2456
|
+
}));
|
|
2457
|
+
this.#rawEntries = undefined; // Free raw entries
|
|
2458
|
+
return this.#parsedEntries;
|
|
2459
|
+
}
|
|
2460
|
+
|
|
2461
|
+
/**
|
|
2462
|
+
* The underlying Word value.
|
|
2463
|
+
* For Value slots: the stored Word.
|
|
2464
|
+
* For StorageMap slots: the first entry's value as a Word (or undefined if empty).
|
|
2465
|
+
*/
|
|
2466
|
+
get word() {
|
|
2467
|
+
return this.#word;
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2470
|
+
/**
|
|
2471
|
+
* Returns all four Felts of the stored Word as an array.
|
|
2472
|
+
* Pass-through to Word.toFelts() — ensures code that expects a Word-like
|
|
2473
|
+
* object (e.g., `result.toFelts()[0].asInt()`) works on StorageResult.
|
|
2474
|
+
* @returns {Felt[]}
|
|
2475
|
+
*/
|
|
2476
|
+
toFelts() {
|
|
2477
|
+
if (!this.#word) return [];
|
|
2478
|
+
return this.#word.toFelts();
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
/**
|
|
2482
|
+
* The first Felt of the stored Word.
|
|
2483
|
+
* Returns the WASM Felt object — use .asInt() to get its BigInt value.
|
|
2484
|
+
* @returns {Felt | undefined}
|
|
2485
|
+
*/
|
|
2486
|
+
felt() {
|
|
2487
|
+
if (!this.#word) return undefined;
|
|
2488
|
+
const felts = this.#word.toFelts();
|
|
2489
|
+
return felts?.[0];
|
|
2490
|
+
}
|
|
2491
|
+
|
|
2492
|
+
/**
|
|
2493
|
+
* First felt as a BigInt. Preserves full u64 precision.
|
|
2494
|
+
* @returns {bigint}
|
|
2495
|
+
*/
|
|
2496
|
+
toBigInt() {
|
|
2497
|
+
if (!this.#word) return 0n;
|
|
2498
|
+
return wordToBigInt(this.#word);
|
|
2499
|
+
}
|
|
2500
|
+
|
|
2501
|
+
/**
|
|
2502
|
+
* The Word's hex representation.
|
|
2503
|
+
* For Value slots: the stored Word hex.
|
|
2504
|
+
* For StorageMap slots: the first entry's value Word hex.
|
|
2505
|
+
* @returns {string}
|
|
2506
|
+
*/
|
|
2507
|
+
toHex() {
|
|
2508
|
+
if (!this.#word) return "0x" + "0".repeat(64);
|
|
2509
|
+
return this.#word.toHex();
|
|
2510
|
+
}
|
|
2511
|
+
|
|
2512
|
+
/**
|
|
2513
|
+
* Renders as the BigInt value (lossless). Makes `{storageResult}` work in JSX
|
|
2514
|
+
* and template literals: `` `value: ${result}` ``.
|
|
2515
|
+
* @returns {string}
|
|
2516
|
+
*/
|
|
2517
|
+
toString() {
|
|
2518
|
+
return this.toBigInt().toString();
|
|
2519
|
+
}
|
|
2520
|
+
|
|
2521
|
+
/**
|
|
2522
|
+
* JSON serialization — returns the value as a string to avoid
|
|
2523
|
+
* precision loss for large u64 felt values.
|
|
2524
|
+
*/
|
|
2525
|
+
toJSON() {
|
|
2526
|
+
return this.toBigInt().toString();
|
|
2527
|
+
}
|
|
2528
|
+
|
|
2529
|
+
/**
|
|
2530
|
+
* Allows `+result`, `result * 2`, etc. to work as expected.
|
|
2531
|
+
*
|
|
2532
|
+
* Returns a JS number for values that fit in `Number.MAX_SAFE_INTEGER`
|
|
2533
|
+
* (2^53 - 1). For larger u64 values, throws `RangeError` rather than
|
|
2534
|
+
* silently losing precision — use `.toBigInt()` to access the exact value.
|
|
2535
|
+
*
|
|
2536
|
+
* @returns {number}
|
|
2537
|
+
* @throws {RangeError} if the underlying felt exceeds Number.MAX_SAFE_INTEGER
|
|
2538
|
+
*/
|
|
2539
|
+
valueOf() {
|
|
2540
|
+
const big = this.toBigInt();
|
|
2541
|
+
if (big > BigInt(Number.MAX_SAFE_INTEGER)) {
|
|
2542
|
+
throw new RangeError(
|
|
2543
|
+
`StorageResult value ${big} exceeds Number.MAX_SAFE_INTEGER ` +
|
|
2544
|
+
`(${Number.MAX_SAFE_INTEGER}) — use .toBigInt() to read the exact value.`
|
|
2545
|
+
);
|
|
2546
|
+
}
|
|
2547
|
+
return Number(big);
|
|
2548
|
+
}
|
|
2549
|
+
}
|
|
2550
|
+
|
|
2551
|
+
/**
|
|
2552
|
+
* Convert a Word's first felt to a BigInt.
|
|
2553
|
+
* Uses BigInt to preserve full u64 precision (felts are u64-backed).
|
|
2554
|
+
* Handles the little-endian byte order of felt serialization.
|
|
2555
|
+
*
|
|
2556
|
+
* @param {Word} word
|
|
2557
|
+
* @returns {bigint}
|
|
2558
|
+
*/
|
|
2559
|
+
function wordToBigInt(word) {
|
|
2560
|
+
try {
|
|
2561
|
+
const hex = word.toHex();
|
|
2562
|
+
// Word.toHex() returns "0x" + 64 hex chars (4 felts × 16 hex chars each).
|
|
2563
|
+
// Each felt is serialized as 8 little-endian bytes, so we take the first 16
|
|
2564
|
+
// hex chars (first felt) and reverse the byte pairs to get the integer value.
|
|
2565
|
+
const feltHex = hex.slice(2, 18);
|
|
2566
|
+
const bytes = feltHex.match(/../g);
|
|
2567
|
+
if (!bytes) return 0n;
|
|
2568
|
+
return BigInt("0x" + bytes.reverse().join(""));
|
|
2569
|
+
} catch {
|
|
2570
|
+
return 0n;
|
|
2571
|
+
}
|
|
2572
|
+
}
|
|
2573
|
+
|
|
2574
|
+
/**
|
|
2575
|
+
* Install the StorageView wrapper on Account.prototype.storage().
|
|
2576
|
+
* After this, `account.storage()` returns a StorageView instead of raw AccountStorage.
|
|
2577
|
+
*
|
|
2578
|
+
* @param {object} wasmModule — the loaded WASM module containing Account, Word, etc.
|
|
2579
|
+
*/
|
|
2580
|
+
function installStorageView(wasmModule) {
|
|
2581
|
+
const AccountProto = wasmModule.Account?.prototype;
|
|
2582
|
+
if (!AccountProto || !AccountProto.storage) return;
|
|
2583
|
+
|
|
2584
|
+
const originalStorage = AccountProto.storage;
|
|
2585
|
+
const WordClass = wasmModule.Word;
|
|
2586
|
+
|
|
2587
|
+
AccountProto.storage = function () {
|
|
2588
|
+
const raw = originalStorage.call(this);
|
|
2589
|
+
return new StorageView(raw, WordClass);
|
|
2590
|
+
};
|
|
2591
|
+
}
|
|
2164
2592
|
|
|
2165
2593
|
const AccountType = Object.freeze({
|
|
2166
2594
|
// WASM-compatible numeric values — usable with AccountBuilder directly
|
|
@@ -2188,7 +2616,6 @@ const NoteVisibility = Object.freeze({
|
|
|
2188
2616
|
const StorageMode = Object.freeze({
|
|
2189
2617
|
Public: "public",
|
|
2190
2618
|
Private: "private",
|
|
2191
|
-
Network: "network",
|
|
2192
2619
|
});
|
|
2193
2620
|
|
|
2194
2621
|
const Linking = Object.freeze({
|
|
@@ -2196,43 +2623,6 @@ const Linking = Object.freeze({
|
|
|
2196
2623
|
Static: "static",
|
|
2197
2624
|
});
|
|
2198
2625
|
|
|
2199
|
-
// Method classification sets — used by scripts/check-method-classification.js to ensure
|
|
2200
|
-
// every WASM export is explicitly categorised. Update when adding new WASM methods.
|
|
2201
|
-
//
|
|
2202
|
-
// Note on `SYNC_METHODS`: the classifier is "synchronous in JS" — i.e.
|
|
2203
|
-
// `pub fn ...` in Rust, not `pub async fn ...`. Two sub-cases:
|
|
2204
|
-
// 1. Factory methods that return a non-Promise value (`accountReader`
|
|
2205
|
-
// returns `AccountReader`; the transaction-request builders return
|
|
2206
|
-
// `TransactionRequestBuilder`; `createCodeBuilder` returns a builder).
|
|
2207
|
-
// Wrapping these in `_serializeWasmCall` would turn their return
|
|
2208
|
-
// value into `Promise<T>` and break callers that use the result
|
|
2209
|
-
// immediately (e.g. `const reader = client.accountReader(id);
|
|
2210
|
-
// await reader.nonce();`).
|
|
2211
|
-
// 2. Sync methods that still take `&mut self` in Rust (`proveBlock`,
|
|
2212
|
-
// `serializeMockChain`, `setDebugMode`). Safe to opt out because JS
|
|
2213
|
-
// is single-threaded — the event loop cannot interleave another
|
|
2214
|
-
// call during their synchronous execution, so the RefCell borrow
|
|
2215
|
-
// is always released before any other borrow can start.
|
|
2216
|
-
// Do NOT move a sync-in-JS method into `WRITE_METHODS` / `READ_METHODS`
|
|
2217
|
-
// just because it takes `&mut self` or `&self`; wrapping changes its
|
|
2218
|
-
// return shape and breaks every caller.
|
|
2219
|
-
const SYNC_METHODS = new Set([
|
|
2220
|
-
"accountReader",
|
|
2221
|
-
"buildSwapTag",
|
|
2222
|
-
"createCodeBuilder",
|
|
2223
|
-
"lastAuthError",
|
|
2224
|
-
"newConsumeTransactionRequest",
|
|
2225
|
-
"newMintTransactionRequest",
|
|
2226
|
-
"newSendTransactionRequest",
|
|
2227
|
-
"newSwapTransactionRequest",
|
|
2228
|
-
"proveBlock",
|
|
2229
|
-
"serializeMockChain",
|
|
2230
|
-
"serializeMockNoteTransportNode",
|
|
2231
|
-
"setDebugMode",
|
|
2232
|
-
"storeIdentifier",
|
|
2233
|
-
"usesMockChain",
|
|
2234
|
-
]);
|
|
2235
|
-
|
|
2236
2626
|
const MOCK_STORE_NAME = "mock_client_db";
|
|
2237
2627
|
|
|
2238
2628
|
const buildTypedArraysExport = (exportObject) => {
|
|
@@ -2289,6 +2679,9 @@ const ensureWasm = async () => {
|
|
|
2289
2679
|
}
|
|
2290
2680
|
// Set WASM module for standalone utilities
|
|
2291
2681
|
_setWasm(module);
|
|
2682
|
+
// Install StorageView: account.storage() now returns a developer-friendly
|
|
2683
|
+
// wrapper that makes getItem() work correctly for StorageMap slots.
|
|
2684
|
+
installStorageView(module);
|
|
2292
2685
|
}
|
|
2293
2686
|
return module;
|
|
2294
2687
|
});
|
|
@@ -2333,16 +2726,6 @@ const getWasmOrThrow = async () => {
|
|
|
2333
2726
|
/**
|
|
2334
2727
|
* Create a Proxy that forwards missing properties to the underlying WASM
|
|
2335
2728
|
* WebClient.
|
|
2336
|
-
*
|
|
2337
|
-
* Async proxy-fallback methods (every WASM method that borrows the
|
|
2338
|
-
* WebClient's RefCell — reads included, since `&self` and `&mut self` both
|
|
2339
|
-
* trip wasm-bindgen's "recursive use of an object detected" panic if
|
|
2340
|
-
* another borrow is live) are routed through `_serializeWasmCall` so they
|
|
2341
|
-
* queue on the same chain as the explicitly-wrapped methods.
|
|
2342
|
-
*
|
|
2343
|
-
* `SYNC_METHODS` opts out: they are synchronous in JS and wrapping them
|
|
2344
|
-
* would change their return type to `Promise<T>`, which is a breaking
|
|
2345
|
-
* change for consumers that use them as plain getters or builders.
|
|
2346
2729
|
*/
|
|
2347
2730
|
function createClientProxy(instance) {
|
|
2348
2731
|
return new Proxy(instance, {
|
|
@@ -2353,13 +2736,7 @@ function createClientProxy(instance) {
|
|
|
2353
2736
|
if (target.wasmWebClient && prop in target.wasmWebClient) {
|
|
2354
2737
|
const value = target.wasmWebClient[prop];
|
|
2355
2738
|
if (typeof value === "function") {
|
|
2356
|
-
|
|
2357
|
-
return value.bind(target.wasmWebClient);
|
|
2358
|
-
}
|
|
2359
|
-
return (...args) =>
|
|
2360
|
-
target._serializeWasmCall(() =>
|
|
2361
|
-
value.apply(target.wasmWebClient, args)
|
|
2362
|
-
);
|
|
2739
|
+
return value.bind(target.wasmWebClient);
|
|
2363
2740
|
}
|
|
2364
2741
|
return value;
|
|
2365
2742
|
}
|
|
@@ -2879,6 +3256,7 @@ class WebClient {
|
|
|
2879
3256
|
async newFaucet(
|
|
2880
3257
|
storageMode,
|
|
2881
3258
|
nonFungible,
|
|
3259
|
+
tokenName,
|
|
2882
3260
|
tokenSymbol,
|
|
2883
3261
|
decimals,
|
|
2884
3262
|
maxSupply,
|
|
@@ -2889,6 +3267,7 @@ class WebClient {
|
|
|
2889
3267
|
return await wasmWebClient.newFaucet(
|
|
2890
3268
|
storageMode,
|
|
2891
3269
|
nonFungible,
|
|
3270
|
+
tokenName,
|
|
2892
3271
|
tokenSymbol,
|
|
2893
3272
|
decimals,
|
|
2894
3273
|
maxSupply,
|
|
@@ -2912,171 +3291,147 @@ class WebClient {
|
|
|
2912
3291
|
}
|
|
2913
3292
|
|
|
2914
3293
|
async submitNewTransaction(accountId, transactionRequest) {
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
transactionRequest
|
|
2922
|
-
);
|
|
2923
|
-
}
|
|
2924
|
-
|
|
2925
|
-
const wasm = await getWasmOrThrow();
|
|
2926
|
-
const serializedTransactionRequest = transactionRequest.serialize();
|
|
2927
|
-
const result = await this.callMethodWithWorker(
|
|
2928
|
-
MethodName.SUBMIT_NEW_TRANSACTION,
|
|
2929
|
-
accountId.toString(),
|
|
2930
|
-
serializedTransactionRequest
|
|
3294
|
+
try {
|
|
3295
|
+
if (!this.worker) {
|
|
3296
|
+
const wasmWebClient = await this.getWasmWebClient();
|
|
3297
|
+
return await wasmWebClient.submitNewTransaction(
|
|
3298
|
+
accountId,
|
|
3299
|
+
transactionRequest
|
|
2931
3300
|
);
|
|
3301
|
+
}
|
|
2932
3302
|
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
3303
|
+
const wasm = await getWasmOrThrow();
|
|
3304
|
+
const serializedTransactionRequest = transactionRequest.serialize();
|
|
3305
|
+
const result = await this.callMethodWithWorker(
|
|
3306
|
+
MethodName.SUBMIT_NEW_TRANSACTION,
|
|
3307
|
+
accountId.toString(),
|
|
3308
|
+
serializedTransactionRequest
|
|
3309
|
+
);
|
|
2936
3310
|
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
})
|
|
3311
|
+
const transactionResult = wasm.TransactionResult.deserialize(
|
|
3312
|
+
new Uint8Array(result.serializedTransactionResult)
|
|
3313
|
+
);
|
|
3314
|
+
|
|
3315
|
+
return transactionResult.id();
|
|
3316
|
+
} catch (error) {
|
|
3317
|
+
console.error("INDEX.JS: Error in submitNewTransaction:", error);
|
|
3318
|
+
throw error;
|
|
3319
|
+
}
|
|
2943
3320
|
}
|
|
2944
3321
|
|
|
2945
3322
|
async submitNewTransactionWithProver(accountId, transactionRequest, prover) {
|
|
2946
|
-
|
|
2947
|
-
|
|
2948
|
-
|
|
2949
|
-
|
|
2950
|
-
|
|
2951
|
-
|
|
2952
|
-
|
|
2953
|
-
prover
|
|
2954
|
-
);
|
|
2955
|
-
}
|
|
2956
|
-
|
|
2957
|
-
const wasm = await getWasmOrThrow();
|
|
2958
|
-
const serializedTransactionRequest = transactionRequest.serialize();
|
|
2959
|
-
const proverPayload = prover.serialize();
|
|
2960
|
-
const result = await this.callMethodWithWorker(
|
|
2961
|
-
MethodName.SUBMIT_NEW_TRANSACTION_WITH_PROVER,
|
|
2962
|
-
accountId.toString(),
|
|
2963
|
-
serializedTransactionRequest,
|
|
2964
|
-
proverPayload
|
|
3323
|
+
try {
|
|
3324
|
+
if (!this.worker) {
|
|
3325
|
+
const wasmWebClient = await this.getWasmWebClient();
|
|
3326
|
+
return await wasmWebClient.submitNewTransactionWithProver(
|
|
3327
|
+
accountId,
|
|
3328
|
+
transactionRequest,
|
|
3329
|
+
prover
|
|
2965
3330
|
);
|
|
3331
|
+
}
|
|
2966
3332
|
|
|
2967
|
-
|
|
2968
|
-
|
|
2969
|
-
|
|
3333
|
+
const wasm = await getWasmOrThrow();
|
|
3334
|
+
const serializedTransactionRequest = transactionRequest.serialize();
|
|
3335
|
+
const proverPayload = prover.serialize();
|
|
3336
|
+
const result = await this.callMethodWithWorker(
|
|
3337
|
+
MethodName.SUBMIT_NEW_TRANSACTION_WITH_PROVER,
|
|
3338
|
+
accountId.toString(),
|
|
3339
|
+
serializedTransactionRequest,
|
|
3340
|
+
proverPayload
|
|
3341
|
+
);
|
|
2970
3342
|
|
|
2971
|
-
|
|
2972
|
-
|
|
2973
|
-
|
|
2974
|
-
|
|
2975
|
-
|
|
2976
|
-
|
|
2977
|
-
|
|
2978
|
-
|
|
2979
|
-
|
|
3343
|
+
const transactionResult = wasm.TransactionResult.deserialize(
|
|
3344
|
+
new Uint8Array(result.serializedTransactionResult)
|
|
3345
|
+
);
|
|
3346
|
+
|
|
3347
|
+
return transactionResult.id();
|
|
3348
|
+
} catch (error) {
|
|
3349
|
+
console.error(
|
|
3350
|
+
"INDEX.JS: Error in submitNewTransactionWithProver:",
|
|
3351
|
+
error
|
|
3352
|
+
);
|
|
3353
|
+
throw error;
|
|
3354
|
+
}
|
|
2980
3355
|
}
|
|
2981
3356
|
|
|
2982
3357
|
async executeTransaction(accountId, transactionRequest) {
|
|
2983
|
-
|
|
2984
|
-
|
|
2985
|
-
|
|
2986
|
-
|
|
2987
|
-
|
|
2988
|
-
|
|
2989
|
-
transactionRequest
|
|
2990
|
-
);
|
|
2991
|
-
}
|
|
2992
|
-
|
|
2993
|
-
const wasm = await getWasmOrThrow();
|
|
2994
|
-
const serializedTransactionRequest = transactionRequest.serialize();
|
|
2995
|
-
const serializedResultBytes = await this.callMethodWithWorker(
|
|
2996
|
-
MethodName.EXECUTE_TRANSACTION,
|
|
2997
|
-
accountId.toString(),
|
|
2998
|
-
serializedTransactionRequest
|
|
2999
|
-
);
|
|
3000
|
-
|
|
3001
|
-
return wasm.TransactionResult.deserialize(
|
|
3002
|
-
new Uint8Array(serializedResultBytes)
|
|
3358
|
+
try {
|
|
3359
|
+
if (!this.worker) {
|
|
3360
|
+
const wasmWebClient = await this.getWasmWebClient();
|
|
3361
|
+
return await wasmWebClient.executeTransaction(
|
|
3362
|
+
accountId,
|
|
3363
|
+
transactionRequest
|
|
3003
3364
|
);
|
|
3004
|
-
} catch (error) {
|
|
3005
|
-
console.error("INDEX.JS: Error in executeTransaction:", error);
|
|
3006
|
-
throw error;
|
|
3007
3365
|
}
|
|
3008
|
-
|
|
3366
|
+
|
|
3367
|
+
const wasm = await getWasmOrThrow();
|
|
3368
|
+
const serializedTransactionRequest = transactionRequest.serialize();
|
|
3369
|
+
const serializedResultBytes = await this.callMethodWithWorker(
|
|
3370
|
+
MethodName.EXECUTE_TRANSACTION,
|
|
3371
|
+
accountId.toString(),
|
|
3372
|
+
serializedTransactionRequest
|
|
3373
|
+
);
|
|
3374
|
+
|
|
3375
|
+
return wasm.TransactionResult.deserialize(
|
|
3376
|
+
new Uint8Array(serializedResultBytes)
|
|
3377
|
+
);
|
|
3378
|
+
} catch (error) {
|
|
3379
|
+
console.error("INDEX.JS: Error in executeTransaction:", error);
|
|
3380
|
+
throw error;
|
|
3381
|
+
}
|
|
3009
3382
|
}
|
|
3010
3383
|
|
|
3011
3384
|
async proveTransaction(transactionResult, prover) {
|
|
3012
|
-
|
|
3013
|
-
|
|
3014
|
-
|
|
3015
|
-
|
|
3016
|
-
|
|
3017
|
-
? await wasmWebClient.proveTransactionWithProver(
|
|
3018
|
-
transactionResult,
|
|
3019
|
-
prover
|
|
3020
|
-
)
|
|
3021
|
-
: await wasmWebClient.proveTransaction(transactionResult);
|
|
3022
|
-
}
|
|
3023
|
-
|
|
3024
|
-
const wasm = await getWasmOrThrow();
|
|
3025
|
-
const serializedTransactionResult = transactionResult.serialize();
|
|
3026
|
-
const proverPayload = prover ? prover.serialize() : null;
|
|
3385
|
+
try {
|
|
3386
|
+
if (!this.worker) {
|
|
3387
|
+
const wasmWebClient = await this.getWasmWebClient();
|
|
3388
|
+
return await wasmWebClient.proveTransaction(transactionResult, prover);
|
|
3389
|
+
}
|
|
3027
3390
|
|
|
3028
|
-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
proverPayload
|
|
3032
|
-
);
|
|
3391
|
+
const wasm = await getWasmOrThrow();
|
|
3392
|
+
const serializedTransactionResult = transactionResult.serialize();
|
|
3393
|
+
const proverPayload = prover ? prover.serialize() : null;
|
|
3033
3394
|
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
throw error;
|
|
3040
|
-
}
|
|
3041
|
-
});
|
|
3042
|
-
}
|
|
3395
|
+
const serializedProvenBytes = await this.callMethodWithWorker(
|
|
3396
|
+
MethodName.PROVE_TRANSACTION,
|
|
3397
|
+
serializedTransactionResult,
|
|
3398
|
+
proverPayload
|
|
3399
|
+
);
|
|
3043
3400
|
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3401
|
+
return wasm.ProvenTransaction.deserialize(
|
|
3402
|
+
new Uint8Array(serializedProvenBytes)
|
|
3403
|
+
);
|
|
3404
|
+
} catch (error) {
|
|
3405
|
+
console.error("INDEX.JS: Error in proveTransaction:", error);
|
|
3406
|
+
throw error;
|
|
3407
|
+
}
|
|
3051
3408
|
}
|
|
3052
3409
|
|
|
3053
3410
|
async applyTransaction(transactionResult, submissionHeight) {
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
transactionResult,
|
|
3060
|
-
submissionHeight
|
|
3061
|
-
);
|
|
3062
|
-
}
|
|
3063
|
-
|
|
3064
|
-
const wasm = await getWasmOrThrow();
|
|
3065
|
-
const serializedTransactionResult = transactionResult.serialize();
|
|
3066
|
-
const serializedUpdateBytes = await this.callMethodWithWorker(
|
|
3067
|
-
MethodName.APPLY_TRANSACTION,
|
|
3068
|
-
serializedTransactionResult,
|
|
3411
|
+
try {
|
|
3412
|
+
if (!this.worker) {
|
|
3413
|
+
const wasmWebClient = await this.getWasmWebClient();
|
|
3414
|
+
return await wasmWebClient.applyTransaction(
|
|
3415
|
+
transactionResult,
|
|
3069
3416
|
submissionHeight
|
|
3070
3417
|
);
|
|
3071
|
-
|
|
3072
|
-
return wasm.TransactionStoreUpdate.deserialize(
|
|
3073
|
-
new Uint8Array(serializedUpdateBytes)
|
|
3074
|
-
);
|
|
3075
|
-
} catch (error) {
|
|
3076
|
-
console.error("INDEX.JS: Error in applyTransaction:", error);
|
|
3077
|
-
throw error;
|
|
3078
3418
|
}
|
|
3079
|
-
|
|
3419
|
+
|
|
3420
|
+
const wasm = await getWasmOrThrow();
|
|
3421
|
+
const serializedTransactionResult = transactionResult.serialize();
|
|
3422
|
+
const serializedUpdateBytes = await this.callMethodWithWorker(
|
|
3423
|
+
MethodName.APPLY_TRANSACTION,
|
|
3424
|
+
serializedTransactionResult,
|
|
3425
|
+
submissionHeight
|
|
3426
|
+
);
|
|
3427
|
+
|
|
3428
|
+
return wasm.TransactionStoreUpdate.deserialize(
|
|
3429
|
+
new Uint8Array(serializedUpdateBytes)
|
|
3430
|
+
);
|
|
3431
|
+
} catch (error) {
|
|
3432
|
+
console.error("INDEX.JS: Error in applyTransaction:", error);
|
|
3433
|
+
throw error;
|
|
3434
|
+
}
|
|
3080
3435
|
}
|
|
3081
3436
|
|
|
3082
3437
|
/**
|
|
@@ -3115,25 +3470,21 @@ class WebClient {
|
|
|
3115
3470
|
return lockHandle.coalescedResult;
|
|
3116
3471
|
}
|
|
3117
3472
|
|
|
3118
|
-
// We acquired the lock - perform the sync
|
|
3119
|
-
// call in _serializeWasmCall so it can't race with any other
|
|
3120
|
-
// mutating method (executeTransaction, submitNewTransaction, etc.)
|
|
3121
|
-
// on the same WebClient. The outer coalescing lock stays in place
|
|
3122
|
-
// so concurrent syncState callers still share one in-flight sync.
|
|
3473
|
+
// We acquired the lock - perform the sync
|
|
3123
3474
|
try {
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3475
|
+
let result;
|
|
3476
|
+
if (!this.worker) {
|
|
3477
|
+
const wasmWebClient = await this.getWasmWebClient();
|
|
3478
|
+
result = await wasmWebClient.syncStateImpl();
|
|
3479
|
+
} else {
|
|
3129
3480
|
const wasm = await getWasmOrThrow();
|
|
3130
3481
|
const serializedSyncSummaryBytes = await this.callMethodWithWorker(
|
|
3131
3482
|
MethodName.SYNC_STATE
|
|
3132
3483
|
);
|
|
3133
|
-
|
|
3484
|
+
result = wasm.SyncSummary.deserialize(
|
|
3134
3485
|
new Uint8Array(serializedSyncSummaryBytes)
|
|
3135
3486
|
);
|
|
3136
|
-
}
|
|
3487
|
+
}
|
|
3137
3488
|
|
|
3138
3489
|
// Release the lock with the result
|
|
3139
3490
|
releaseSyncLock(dbId, result);
|
|
@@ -3212,9 +3563,9 @@ class MockWebClient extends WebClient {
|
|
|
3212
3563
|
// Wait for the underlying wasmWebClient to be initialized.
|
|
3213
3564
|
const wasmWebClient = await instance.getWasmWebClient();
|
|
3214
3565
|
await wasmWebClient.createMockClient(
|
|
3215
|
-
seed,
|
|
3216
|
-
serializedMockChain,
|
|
3217
|
-
serializedMockNoteTransportNode
|
|
3566
|
+
seed ?? null,
|
|
3567
|
+
serializedMockChain ?? null,
|
|
3568
|
+
serializedMockNoteTransportNode ?? null
|
|
3218
3569
|
);
|
|
3219
3570
|
|
|
3220
3571
|
// Wait for the worker to be ready
|
|
@@ -3259,9 +3610,11 @@ class MockWebClient extends WebClient {
|
|
|
3259
3610
|
if (!this.worker) {
|
|
3260
3611
|
result = await wasmWebClient.syncStateImpl();
|
|
3261
3612
|
} else {
|
|
3262
|
-
let serializedMockChain = wasmWebClient.serializeMockChain()
|
|
3263
|
-
|
|
3264
|
-
|
|
3613
|
+
let serializedMockChain = (await wasmWebClient.serializeMockChain())
|
|
3614
|
+
.buffer;
|
|
3615
|
+
let serializedMockNoteTransportNode = (
|
|
3616
|
+
await wasmWebClient.serializeMockNoteTransportNode()
|
|
3617
|
+
).buffer;
|
|
3265
3618
|
|
|
3266
3619
|
const wasm = await getWasmOrThrow();
|
|
3267
3620
|
|
|
@@ -3297,9 +3650,11 @@ class MockWebClient extends WebClient {
|
|
|
3297
3650
|
const wasmWebClient = await this.getWasmWebClient();
|
|
3298
3651
|
const wasm = await getWasmOrThrow();
|
|
3299
3652
|
const serializedTransactionRequest = transactionRequest.serialize();
|
|
3300
|
-
const serializedMockChain = wasmWebClient.serializeMockChain()
|
|
3301
|
-
|
|
3302
|
-
|
|
3653
|
+
const serializedMockChain = (await wasmWebClient.serializeMockChain())
|
|
3654
|
+
.buffer;
|
|
3655
|
+
const serializedMockNoteTransportNode = (
|
|
3656
|
+
await wasmWebClient.serializeMockNoteTransportNode()
|
|
3657
|
+
).buffer;
|
|
3303
3658
|
|
|
3304
3659
|
const result = await this.callMethodWithWorker(
|
|
3305
3660
|
MethodName.SUBMIT_NEW_TRANSACTION_MOCK,
|
|
@@ -3351,9 +3706,11 @@ class MockWebClient extends WebClient {
|
|
|
3351
3706
|
const wasm = await getWasmOrThrow();
|
|
3352
3707
|
const serializedTransactionRequest = transactionRequest.serialize();
|
|
3353
3708
|
const proverPayload = prover.serialize();
|
|
3354
|
-
const serializedMockChain = wasmWebClient.serializeMockChain()
|
|
3355
|
-
|
|
3356
|
-
|
|
3709
|
+
const serializedMockChain = (await wasmWebClient.serializeMockChain())
|
|
3710
|
+
.buffer;
|
|
3711
|
+
const serializedMockNoteTransportNode = (
|
|
3712
|
+
await wasmWebClient.serializeMockNoteTransportNode()
|
|
3713
|
+
).buffer;
|
|
3357
3714
|
|
|
3358
3715
|
const result = await this.callMethodWithWorker(
|
|
3359
3716
|
MethodName.SUBMIT_NEW_TRANSACTION_WITH_PROVER_MOCK,
|
|
@@ -3417,5 +3774,5 @@ MidenClient._MockWasmWebClient = MockWebClient;
|
|
|
3417
3774
|
MidenClient._getWasmOrThrow = getWasmOrThrow;
|
|
3418
3775
|
_setWebClient(WebClient);
|
|
3419
3776
|
|
|
3420
|
-
export {
|
|
3777
|
+
export { AccountType, AuthScheme, CompilerResource, Linking, MidenArrays, MidenClient, MockWebClient as MockWasmWebClient, MockWebClient, NoteVisibility, StorageMode, StorageResult, StorageView, WebClient as WasmWebClient, buildSwapTag, createP2IDENote, createP2IDNote, getWasmOrThrow, wordToBigInt };
|
|
3421
3778
|
//# sourceMappingURL=index.js.map
|