@miden-sdk/react 0.15.0-alpha.4 → 0.15.0-alpha.6
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 +146 -7
- package/dist/index.d.ts +222 -10
- package/dist/index.mjs +370 -130
- package/dist/{index.d.mts → lazy.d.ts} +222 -10
- package/dist/lazy.mjs +3865 -0
- package/dist/mt/lazy.d.ts +1711 -0
- package/dist/mt/lazy.mjs +3865 -0
- package/dist/mt.d.ts +1711 -0
- package/dist/{index.js → mt.mjs} +716 -513
- package/lazy/package.json +5 -0
- package/mt/lazy/package.json +5 -0
- package/mt/package.json +5 -0
- package/package.json +22 -14
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import * as react from 'react';
|
|
3
3
|
import { ReactNode } from 'react';
|
|
4
|
-
import { AccountId, Account, AccountHeader, AccountStorageMode, AccountComponent, NoteId, InputNoteRecord, Note, StorageMode, AuthScheme, TransactionScript, AdviceInputs, AccountStorageRequirements, TransactionRequest, WasmWebClient, AccountFile, NoteVisibility, ConsumableNoteRecord, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteScript, NoteAttachment } from '@miden-sdk/miden-sdk';
|
|
4
|
+
import { AccountId, Account, AccountHeader, AccountStorageMode, AccountComponent, NoteId, InputNoteRecord, Note, StorageMode, AuthScheme, TransactionScript, AdviceInputs, AccountStorageRequirements, TransactionRequest, WasmWebClient, AccountFile, NoteVisibility, ConsumableNoteRecord, NoteInput, TransactionId, TransactionFilter, TransactionRecord, TransactionProver, CompileComponentOptions, CompileTxScriptOptions, CompileNoteScriptOptions, NoteScript, NoteAttachment } from '@miden-sdk/miden-sdk';
|
|
5
5
|
export { Account, AccountFile, AccountHeader, AccountId, AccountStorageMode, AuthScheme, ConsumableNoteRecord, InputNoteRecord, Note, NoteType, TransactionFilter, TransactionId, TransactionRecord, TransactionRequest, WasmWebClient as WebClient } from '@miden-sdk/miden-sdk';
|
|
6
6
|
|
|
7
7
|
declare module "@miden-sdk/miden-sdk" {
|
|
@@ -150,6 +150,22 @@ interface MidenConfig {
|
|
|
150
150
|
proverUrls?: ProverUrls;
|
|
151
151
|
/** Default timeout for remote prover requests in milliseconds. */
|
|
152
152
|
proverTimeoutMs?: number | bigint;
|
|
153
|
+
/**
|
|
154
|
+
* Enable the Web Worker shim that runs WASM calls off the main thread.
|
|
155
|
+
* Defaults to `true` — leave it that way in browsers/extensions so the UI
|
|
156
|
+
* stays responsive while WASM is busy.
|
|
157
|
+
*
|
|
158
|
+
* Set to `false` when:
|
|
159
|
+
* - You pass a `CallbackProver` (e.g. a native iOS/Android prover via
|
|
160
|
+
* a Capacitor plugin). The worker boundary serializes the prover with
|
|
161
|
+
* `TransactionProver.serialize()`, which has no encoding for the
|
|
162
|
+
* callback variant and silently downgrades to `"local"` — your
|
|
163
|
+
* callback would never fire.
|
|
164
|
+
* - You're embedding the client in a single-WebView native shell
|
|
165
|
+
* (Capacitor host, Tauri, Electron preload), where the UI thread
|
|
166
|
+
* isn't competing with the WASM thread anyway.
|
|
167
|
+
*/
|
|
168
|
+
useWorker?: boolean;
|
|
153
169
|
}
|
|
154
170
|
interface MidenState {
|
|
155
171
|
client: WasmWebClient | null;
|
|
@@ -267,6 +283,8 @@ interface CreateWalletOptions {
|
|
|
267
283
|
interface CreateFaucetOptions {
|
|
268
284
|
/** Token symbol (e.g., "TEST") */
|
|
269
285
|
tokenSymbol: string;
|
|
286
|
+
/** Human-readable token name. Defaults to `tokenSymbol` when omitted. */
|
|
287
|
+
tokenName?: string;
|
|
270
288
|
/** Number of decimals. Default: 8 */
|
|
271
289
|
decimals?: number;
|
|
272
290
|
/** Maximum supply */
|
|
@@ -386,6 +404,54 @@ interface SwapOptions {
|
|
|
386
404
|
/** Note type for payback note. Default: private */
|
|
387
405
|
paybackNoteType?: NoteVisibility;
|
|
388
406
|
}
|
|
407
|
+
interface PswapCreateOptions {
|
|
408
|
+
/** Account that creates the PSWAP note */
|
|
409
|
+
accountId: AccountRef;
|
|
410
|
+
/** Faucet ID of the offered asset */
|
|
411
|
+
offeredFaucetId: AccountRef;
|
|
412
|
+
/** Amount being offered */
|
|
413
|
+
offeredAmount: bigint | number;
|
|
414
|
+
/** Faucet ID of the requested asset */
|
|
415
|
+
requestedFaucetId: AccountRef;
|
|
416
|
+
/** Amount being requested */
|
|
417
|
+
requestedAmount: bigint | number;
|
|
418
|
+
/** Visibility of the PSWAP note. Default: private */
|
|
419
|
+
noteType?: NoteVisibility;
|
|
420
|
+
/** Visibility of the payback note. Default: private */
|
|
421
|
+
paybackNoteType?: NoteVisibility;
|
|
422
|
+
}
|
|
423
|
+
interface PswapConsumeOptions {
|
|
424
|
+
/** Consumer account filling the PSWAP note */
|
|
425
|
+
accountId: AccountRef;
|
|
426
|
+
/**
|
|
427
|
+
* PSWAP note to consume. Accepts a hex string ID, `NoteId` object,
|
|
428
|
+
* `InputNoteRecord`, or `Note` — string/NoteId values are looked up from
|
|
429
|
+
* the local store; record/Note values are used directly.
|
|
430
|
+
*/
|
|
431
|
+
note: NoteInput;
|
|
432
|
+
/**
|
|
433
|
+
* Amount of the requested asset the consumer is providing from its own
|
|
434
|
+
* vault. Receives a proportional share of the offered asset; partial fills
|
|
435
|
+
* also produce a remainder PSWAP note carrying the unfilled portion.
|
|
436
|
+
*/
|
|
437
|
+
fillAmount: bigint | number;
|
|
438
|
+
/**
|
|
439
|
+
* Amount of the requested asset supplied by other (in-flight) notes routed
|
|
440
|
+
* into the same transaction. Defaults to `0`; most callers should leave
|
|
441
|
+
* this unset.
|
|
442
|
+
*/
|
|
443
|
+
noteFillAmount?: bigint | number;
|
|
444
|
+
}
|
|
445
|
+
interface PswapCancelOptions {
|
|
446
|
+
/** Creator account reclaiming the offered asset */
|
|
447
|
+
accountId: AccountRef;
|
|
448
|
+
/**
|
|
449
|
+
* PSWAP note to cancel. Accepts a hex string ID, `NoteId` object,
|
|
450
|
+
* `InputNoteRecord`, or `Note` — string/NoteId values are looked up from
|
|
451
|
+
* the local store; record/Note values are used directly.
|
|
452
|
+
*/
|
|
453
|
+
note: NoteInput;
|
|
454
|
+
}
|
|
389
455
|
interface ExecuteTransactionOptions {
|
|
390
456
|
/** Account ID the transaction applies to */
|
|
391
457
|
accountId: AccountRef;
|
|
@@ -1101,6 +1167,128 @@ interface UseSwapResult {
|
|
|
1101
1167
|
*/
|
|
1102
1168
|
declare function useSwap(): UseSwapResult;
|
|
1103
1169
|
|
|
1170
|
+
interface UsePswapCreateResult {
|
|
1171
|
+
/** Create a partial-swap (PSWAP) note */
|
|
1172
|
+
pswapCreate: (options: PswapCreateOptions) => Promise<TransactionResult>;
|
|
1173
|
+
/** The transaction result */
|
|
1174
|
+
result: TransactionResult | null;
|
|
1175
|
+
/** Whether the transaction is in progress */
|
|
1176
|
+
isLoading: boolean;
|
|
1177
|
+
/** Current stage of the transaction */
|
|
1178
|
+
stage: TransactionStage;
|
|
1179
|
+
/** Error if transaction failed */
|
|
1180
|
+
error: Error | null;
|
|
1181
|
+
/** Reset the hook state */
|
|
1182
|
+
reset: () => void;
|
|
1183
|
+
}
|
|
1184
|
+
/**
|
|
1185
|
+
* Hook to create a partial-swap (PSWAP) note. The note can be filled by
|
|
1186
|
+
* multiple consumers; partial fills emit a remainder PSWAP note.
|
|
1187
|
+
*
|
|
1188
|
+
* @example
|
|
1189
|
+
* ```tsx
|
|
1190
|
+
* function CreatePswapButton({ accountId }: { accountId: string }) {
|
|
1191
|
+
* const { pswapCreate, isLoading, stage, error } = usePswapCreate();
|
|
1192
|
+
*
|
|
1193
|
+
* const handleCreate = async () => {
|
|
1194
|
+
* const result = await pswapCreate({
|
|
1195
|
+
* accountId,
|
|
1196
|
+
* offeredFaucetId: '0x...',
|
|
1197
|
+
* offeredAmount: 100n,
|
|
1198
|
+
* requestedFaucetId: '0x...',
|
|
1199
|
+
* requestedAmount: 50n,
|
|
1200
|
+
* });
|
|
1201
|
+
* console.log('PSWAP created! TX:', result.transactionId);
|
|
1202
|
+
* };
|
|
1203
|
+
*
|
|
1204
|
+
* return (
|
|
1205
|
+
* <button onClick={handleCreate} disabled={isLoading}>
|
|
1206
|
+
* {isLoading ? stage : 'Create PSWAP'}
|
|
1207
|
+
* </button>
|
|
1208
|
+
* );
|
|
1209
|
+
* }
|
|
1210
|
+
* ```
|
|
1211
|
+
*/
|
|
1212
|
+
declare function usePswapCreate(): UsePswapCreateResult;
|
|
1213
|
+
|
|
1214
|
+
interface UsePswapConsumeResult {
|
|
1215
|
+
/** Fill (consume) an existing partial-swap (PSWAP) note */
|
|
1216
|
+
pswapConsume: (options: PswapConsumeOptions) => Promise<TransactionResult>;
|
|
1217
|
+
/** The transaction result */
|
|
1218
|
+
result: TransactionResult | null;
|
|
1219
|
+
/** Whether the transaction is in progress */
|
|
1220
|
+
isLoading: boolean;
|
|
1221
|
+
/** Current stage of the transaction */
|
|
1222
|
+
stage: TransactionStage;
|
|
1223
|
+
/** Error if transaction failed */
|
|
1224
|
+
error: Error | null;
|
|
1225
|
+
/** Reset the hook state */
|
|
1226
|
+
reset: () => void;
|
|
1227
|
+
}
|
|
1228
|
+
/**
|
|
1229
|
+
* Hook to consume (fully or partially fill) an existing PSWAP note. The
|
|
1230
|
+
* consumer supplies `fillAmount` and receives a proportional share of the
|
|
1231
|
+
* offered asset.
|
|
1232
|
+
*
|
|
1233
|
+
* @example
|
|
1234
|
+
* ```tsx
|
|
1235
|
+
* function FillPswapButton({ accountId, note }: Props) {
|
|
1236
|
+
* const { pswapConsume, isLoading, stage } = usePswapConsume();
|
|
1237
|
+
*
|
|
1238
|
+
* const handleFill = async () => {
|
|
1239
|
+
* await pswapConsume({
|
|
1240
|
+
* accountId,
|
|
1241
|
+
* note,
|
|
1242
|
+
* fillAmount: 25n,
|
|
1243
|
+
* });
|
|
1244
|
+
* };
|
|
1245
|
+
*
|
|
1246
|
+
* return (
|
|
1247
|
+
* <button onClick={handleFill} disabled={isLoading}>
|
|
1248
|
+
* {isLoading ? stage : 'Fill PSWAP'}
|
|
1249
|
+
* </button>
|
|
1250
|
+
* );
|
|
1251
|
+
* }
|
|
1252
|
+
* ```
|
|
1253
|
+
*/
|
|
1254
|
+
declare function usePswapConsume(): UsePswapConsumeResult;
|
|
1255
|
+
|
|
1256
|
+
interface UsePswapCancelResult {
|
|
1257
|
+
/** Cancel a partial-swap (PSWAP) note as the creator */
|
|
1258
|
+
pswapCancel: (options: PswapCancelOptions) => Promise<TransactionResult>;
|
|
1259
|
+
/** The transaction result */
|
|
1260
|
+
result: TransactionResult | null;
|
|
1261
|
+
/** Whether the transaction is in progress */
|
|
1262
|
+
isLoading: boolean;
|
|
1263
|
+
/** Current stage of the transaction */
|
|
1264
|
+
stage: TransactionStage;
|
|
1265
|
+
/** Error if transaction failed */
|
|
1266
|
+
error: Error | null;
|
|
1267
|
+
/** Reset the hook state */
|
|
1268
|
+
reset: () => void;
|
|
1269
|
+
}
|
|
1270
|
+
/**
|
|
1271
|
+
* Hook to cancel a PSWAP note as the creator and reclaim the offered asset.
|
|
1272
|
+
*
|
|
1273
|
+
* @example
|
|
1274
|
+
* ```tsx
|
|
1275
|
+
* function CancelPswapButton({ accountId, note }: Props) {
|
|
1276
|
+
* const { pswapCancel, isLoading, stage } = usePswapCancel();
|
|
1277
|
+
*
|
|
1278
|
+
* const handleCancel = async () => {
|
|
1279
|
+
* await pswapCancel({ accountId, note });
|
|
1280
|
+
* };
|
|
1281
|
+
*
|
|
1282
|
+
* return (
|
|
1283
|
+
* <button onClick={handleCancel} disabled={isLoading}>
|
|
1284
|
+
* {isLoading ? stage : 'Cancel PSWAP'}
|
|
1285
|
+
* </button>
|
|
1286
|
+
* );
|
|
1287
|
+
* }
|
|
1288
|
+
* ```
|
|
1289
|
+
*/
|
|
1290
|
+
declare function usePswapCancel(): UsePswapCancelResult;
|
|
1291
|
+
|
|
1104
1292
|
interface UseTransactionResult {
|
|
1105
1293
|
/** Execute a transaction request end-to-end */
|
|
1106
1294
|
execute: (options: ExecuteTransactionOptions) => Promise<TransactionResult>;
|
|
@@ -1417,17 +1605,41 @@ interface NoteAttachmentData {
|
|
|
1417
1605
|
kind: "word" | "array";
|
|
1418
1606
|
}
|
|
1419
1607
|
/**
|
|
1420
|
-
* Decode a note's attachment
|
|
1608
|
+
* Decode a note's attachment payload back into the bigint values that
|
|
1609
|
+
* `createNoteAttachment` packed in.
|
|
1610
|
+
*
|
|
1611
|
+
* On the 0.15 protocol surface the full attachment content (the packed words)
|
|
1612
|
+
* lives on the note record (`InputNoteRecord.attachments()`), not on
|
|
1613
|
+
* `NoteMetadata`. This reads the note's first attachment and flattens its
|
|
1614
|
+
* words back into a `bigint[]`, the inverse of `createNoteAttachment`.
|
|
1615
|
+
*
|
|
1616
|
+
* - No attachments → `null`.
|
|
1617
|
+
* - An all-zero payload (regardless of word count) → `null`. This covers the
|
|
1618
|
+
* placeholder produced by `emptyAttachment()` (a single all-zero word) and
|
|
1619
|
+
* matches the pre-0.15 behavior where a `None`-kind attachment decoded to
|
|
1620
|
+
* `null`.
|
|
1621
|
+
* - Otherwise → `{ values, kind }` where `kind` is `"word"` for a single-word
|
|
1622
|
+
* attachment and `"array"` for multi-word content.
|
|
1623
|
+
*
|
|
1624
|
+
* The returned `values` include the trailing-zero padding `createNoteAttachment`
|
|
1625
|
+
* added to reach word boundaries; consumers that need the original unpadded
|
|
1626
|
+
* values should strip trailing zeros.
|
|
1421
1627
|
*/
|
|
1422
1628
|
declare function readNoteAttachment(note: InputNoteRecord): NoteAttachmentData | null;
|
|
1423
1629
|
/**
|
|
1424
|
-
* Encode values into a NoteAttachment
|
|
1425
|
-
*
|
|
1426
|
-
*
|
|
1427
|
-
*
|
|
1428
|
-
*
|
|
1429
|
-
*
|
|
1430
|
-
*
|
|
1630
|
+
* Encode bigint values into a `NoteAttachment`.
|
|
1631
|
+
*
|
|
1632
|
+
* - 0 values → falls back to `emptyAttachment()` (a single zero-Word
|
|
1633
|
+
* attachment with the `none` scheme). On the 0.15 protocol surface there
|
|
1634
|
+
* is no native "empty" attachment; this preserves the pre-migration
|
|
1635
|
+
* "default attachment when caller has no payload" behavior at the cost
|
|
1636
|
+
* of one trivial word.
|
|
1637
|
+
* - 1..=4 values → padded to 4 elements and wrapped as a single Word via
|
|
1638
|
+
* `NoteAttachment.fromWord(scheme, word)`.
|
|
1639
|
+
* - >4 values → padded to a multiple of 4, chunked into Words, and wrapped
|
|
1640
|
+
* via `NoteAttachment.fromWords(scheme, words)`.
|
|
1641
|
+
*
|
|
1642
|
+
* Values are padded to word boundaries (multiples of 4) with trailing `0n`.
|
|
1431
1643
|
*/
|
|
1432
1644
|
declare function createNoteAttachment(values: bigint[] | Uint8Array | number[]): NoteAttachment;
|
|
1433
1645
|
|
|
@@ -1496,4 +1708,4 @@ declare function createMidenStorage(prefix: string): {
|
|
|
1496
1708
|
clear(): void;
|
|
1497
1709
|
};
|
|
1498
1710
|
|
|
1499
|
-
export { type AccountRef, type AccountResult, type AccountsResult, type AssetBalance, type AssetMetadata, type ConsumeOptions, type CreateFaucetOptions, type CreateWalletOptions, DEFAULTS, type ExecuteProgramOptions, type ExecuteProgramResult, type ExecuteTransactionOptions, type ImportAccountOptions, type ImportStoreOptions, type MidenConfig, MidenError, type MidenErrorCode, MidenProvider, type MidenState, type MigrateStorageOptions, type MintOptions, type MultiSendOptions, type MultiSendRecipient, type MultiSignerContextValue, MultiSignerProvider, type MutationResult, type NoteAsset, type NoteAttachmentData, type NoteSummary, type NotesFilter, type NotesResult, type ProverConfig, type ProverTarget, type ProverUrls, type QueryResult, type RpcUrlConfig, type SendOptions, type SendResult, type SessionAccountStep, type SignCallback, type SignerAccountConfig, type SignerAccountType, SignerContext, type SignerContextValue, SignerSlot, type StreamedNote, type SwapOptions, type SyncState, type TransactionHistoryOptions, type TransactionHistoryResult, type TransactionResult, type TransactionStage, type TransactionStatus, type UseCompileResult, type UseConsumeResult, type UseCreateFaucetResult, type UseCreateWalletResult, type UseExecuteProgramResult, type UseExportNoteResult, type UseExportStoreResult, type UseImportAccountResult, type UseImportNoteResult, type UseImportStoreResult, type UseMintResult, type UseMultiSendResult, type UseNoteStreamOptions, type UseNoteStreamReturn, type UseSendResult, type UseSessionAccountOptions, type UseSessionAccountReturn, type UseSwapResult, type UseSyncControlResult, type UseSyncStateResult, type UseTransactionHistoryResult, type UseTransactionResult, type UseWaitForCommitResult, type UseWaitForNotesResult, type WaitForCommitOptions, type WaitForNotesOptions, type WalletAdapterLike, accountIdsEqual, bigIntToBytes, bytesToBigInt, clearMidenStorage, concatBytes, createMidenStorage, createNoteAttachment, ensureAccountBech32, formatAssetAmount, formatNoteSummary, getNoteSummary, installAccountBech32, migrateStorage, normalizeAccountId, parseAssetAmount, readNoteAttachment, toBech32AccountId, useAccount, useAccounts, useAssetMetadata, useCompile, useConsume, useCreateFaucet, useCreateWallet, useExecuteProgram, useExportNote, useExportStore, useImportAccount, useImportNote, useImportStore, useMiden, useMidenClient, useMint, useMultiSend, useMultiSigner, useNoteStream, useNotes, useSend, useSessionAccount, useSigner, useSwap, useSyncControl, useSyncState, useTransaction, useTransactionHistory, useWaitForCommit, useWaitForNotes, waitForWalletDetection, wrapWasmError };
|
|
1711
|
+
export { type AccountRef, type AccountResult, type AccountsResult, type AssetBalance, type AssetMetadata, type ConsumeOptions, type CreateFaucetOptions, type CreateWalletOptions, DEFAULTS, type ExecuteProgramOptions, type ExecuteProgramResult, type ExecuteTransactionOptions, type ImportAccountOptions, type ImportStoreOptions, type MidenConfig, MidenError, type MidenErrorCode, MidenProvider, type MidenState, type MigrateStorageOptions, type MintOptions, type MultiSendOptions, type MultiSendRecipient, type MultiSignerContextValue, MultiSignerProvider, type MutationResult, type NoteAsset, type NoteAttachmentData, type NoteSummary, type NotesFilter, type NotesResult, type ProverConfig, type ProverTarget, type ProverUrls, type PswapCancelOptions, type PswapConsumeOptions, type PswapCreateOptions, type QueryResult, type RpcUrlConfig, type SendOptions, type SendResult, type SessionAccountStep, type SignCallback, type SignerAccountConfig, type SignerAccountType, SignerContext, type SignerContextValue, SignerSlot, type StreamedNote, type SwapOptions, type SyncState, type TransactionHistoryOptions, type TransactionHistoryResult, type TransactionResult, type TransactionStage, type TransactionStatus, type UseCompileResult, type UseConsumeResult, type UseCreateFaucetResult, type UseCreateWalletResult, type UseExecuteProgramResult, type UseExportNoteResult, type UseExportStoreResult, type UseImportAccountResult, type UseImportNoteResult, type UseImportStoreResult, type UseMintResult, type UseMultiSendResult, type UseNoteStreamOptions, type UseNoteStreamReturn, type UsePswapCancelResult, type UsePswapConsumeResult, type UsePswapCreateResult, type UseSendResult, type UseSessionAccountOptions, type UseSessionAccountReturn, type UseSwapResult, type UseSyncControlResult, type UseSyncStateResult, type UseTransactionHistoryResult, type UseTransactionResult, type UseWaitForCommitResult, type UseWaitForNotesResult, type WaitForCommitOptions, type WaitForNotesOptions, type WalletAdapterLike, accountIdsEqual, bigIntToBytes, bytesToBigInt, clearMidenStorage, concatBytes, createMidenStorage, createNoteAttachment, ensureAccountBech32, formatAssetAmount, formatNoteSummary, getNoteSummary, installAccountBech32, migrateStorage, normalizeAccountId, parseAssetAmount, readNoteAttachment, toBech32AccountId, useAccount, useAccounts, useAssetMetadata, useCompile, useConsume, useCreateFaucet, useCreateWallet, useExecuteProgram, useExportNote, useExportStore, useImportAccount, useImportNote, useImportStore, useMiden, useMidenClient, useMint, useMultiSend, useMultiSigner, useNoteStream, useNotes, usePswapCancel, usePswapConsume, usePswapCreate, useSend, useSessionAccount, useSigner, useSwap, useSyncControl, useSyncState, useTransaction, useTransactionHistory, useWaitForCommit, useWaitForNotes, waitForWalletDetection, wrapWasmError };
|