@miden-sdk/react 0.15.0-alpha.4 → 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 +146 -7
- package/dist/index.d.ts +222 -10
- package/dist/index.mjs +356 -121
- package/dist/{index.d.mts → lazy.d.ts} +222 -10
- package/dist/lazy.mjs +3860 -0
- package/dist/mt/lazy.d.ts +1711 -0
- package/dist/mt/lazy.mjs +3860 -0
- package/dist/mt.d.ts +1711 -0
- package/dist/{index.js → mt.mjs} +703 -505
- package/lazy/package.json +5 -0
- package/mt/lazy/package.json +5 -0
- package/mt/package.json +5 -0
- package/package.json +22 -14
package/CLAUDE.md
CHANGED
|
@@ -409,6 +409,9 @@ Query hooks return `{ ...data, isLoading, error, refetch }`. Mutation hooks retu
|
|
|
409
409
|
| `useMint()` | `mint({ faucetId, to, amount })` | `TransactionResult` |
|
|
410
410
|
| `useConsume()` | `consume({ accountId, notes })` | `TransactionResult` |
|
|
411
411
|
| `useSwap()` | `swap({ ... })` | `TransactionResult` |
|
|
412
|
+
| `usePswapCreate()` | `pswapCreate({ accountId, offeredFaucetId, offeredAmount, requestedFaucetId, requestedAmount, ... })` | `TransactionResult` (creates partial-swap note) |
|
|
413
|
+
| `usePswapConsume()` | `pswapConsume({ accountId, note, fillAmount, noteFillAmount? })` — `note` accepts hex string \| `NoteId` \| `InputNoteRecord` \| `Note` | `TransactionResult` (fills PSWAP fully or partially) |
|
|
414
|
+
| `usePswapCancel()` | `pswapCancel({ accountId, note })` — creator only, reclaims unfilled offered asset | `TransactionResult` |
|
|
412
415
|
| `useTransaction()` | `transact({ ... })` | `TransactionResult` (custom tx) |
|
|
413
416
|
| `useExecuteProgram()` | `execute(...)` | program output |
|
|
414
417
|
| `useCompile()` | `compile({ source })` | `{ component, txScript, noteScript }` |
|
package/README.md
CHANGED
|
@@ -22,8 +22,6 @@ React hooks library for the Miden Web Client. Provides a simple, ergonomic inter
|
|
|
22
22
|
npm install @miden-sdk/react @miden-sdk/miden-sdk
|
|
23
23
|
# or
|
|
24
24
|
pnpm add @miden-sdk/react @miden-sdk/miden-sdk
|
|
25
|
-
# or
|
|
26
|
-
pnpm add @miden-sdk/react @miden-sdk/miden-sdk
|
|
27
25
|
```
|
|
28
26
|
|
|
29
27
|
## Testing
|
|
@@ -119,14 +117,25 @@ function App() {
|
|
|
119
117
|
}
|
|
120
118
|
```
|
|
121
119
|
|
|
122
|
-
##
|
|
120
|
+
## Subpaths: Eager / Lazy × ST / MT
|
|
121
|
+
|
|
122
|
+
The React SDK ships **four** bundle variants built from a single source tree. The two axes are independent:
|
|
123
|
+
|
|
124
|
+
- **WASM init timing** — _eager_ awaits at SDK load (TLA); _lazy_ leaves init to `MidenClient.ready()` or first awaiting method.
|
|
125
|
+
- **WASM threading model** — _ST_ (single-threaded) loads anywhere; _MT_ (multi-threaded via `wasm-bindgen-rayon`) parallelizes proving but **requires the page to be cross-origin-isolated**.
|
|
126
|
+
|
|
127
|
+
| Subpath | SDK variant | When to use |
|
|
128
|
+
| ---------------------------------- | --------------------------------- | ---------------------------------------------------------- |
|
|
129
|
+
| `@miden-sdk/react` | eager + ST | Plain browser apps, Vite, CRA, esbuild — no host control needed. |
|
|
130
|
+
| `@miden-sdk/react/lazy` | lazy + ST | Next.js / SSR, Capacitor (iOS/Android WKWebView). |
|
|
131
|
+
| `@miden-sdk/react/mt` | eager + MT | dApps with COOP/COEP set; want fast proving and tolerate TLA. |
|
|
132
|
+
| `@miden-sdk/react/mt/lazy` | lazy + MT | dApps with COOP/COEP set, on Next.js or anywhere TLA can't run. |
|
|
123
133
|
|
|
124
|
-
|
|
134
|
+
All four exports have identical APIs. The choice affects which `@miden-sdk/miden-sdk` variant your bundler resolves and therefore the underlying WASM behavior.
|
|
125
135
|
|
|
126
|
-
|
|
127
|
-
- `@miden-sdk/react/lazy` — internally consumes the lazy SDK. Use this in Next.js (app router or pages), SSR, or inside a Capacitor iOS/Android WKWebView host (the wallet shell uses this).
|
|
136
|
+
### Next.js / SSR
|
|
128
137
|
|
|
129
|
-
|
|
138
|
+
The lazy variants (`/lazy`, `/mt/lazy`) do not run a top-level `await` at module evaluation. Server-side rendering never hangs on WASM init. Use these in any Next.js app or Capacitor host:
|
|
130
139
|
|
|
131
140
|
```tsx
|
|
132
141
|
// Next.js: app/providers.tsx
|
|
@@ -141,6 +150,50 @@ export function Providers({ children }: { children: React.ReactNode }) {
|
|
|
141
150
|
|
|
142
151
|
`MidenProvider` gates child rendering on `isReady`, so you don't have to await anything manually in components — hooks already fire only after WASM is initialized.
|
|
143
152
|
|
|
153
|
+
### Multi-threaded proving (`/mt`, `/mt/lazy`)
|
|
154
|
+
|
|
155
|
+
The MT variants enable `wasm-bindgen-rayon` for ~3–5× faster local proving on commodity laptops. Same API surface as the ST variants. Two extra requirements compared to ST:
|
|
156
|
+
|
|
157
|
+
**1. The page must be cross-origin-isolated.** Set the host response headers:
|
|
158
|
+
|
|
159
|
+
```
|
|
160
|
+
Cross-Origin-Opener-Policy: same-origin
|
|
161
|
+
Cross-Origin-Embedder-Policy: require-corp
|
|
162
|
+
```
|
|
163
|
+
|
|
164
|
+
Without those, the browser refuses to construct `WebAssembly.Memory({ shared: true })` and the MT WASM fails to instantiate at SDK load. See the underlying [`@miden-sdk/miden-sdk` README](https://github.com/0xMiden/web-sdk/blob/main/crates/web-client/README.md#setting-cross-origin-isolation-headers) for snippets per host (Vite, Next.js, Express, browser-extension manifests). COEP also blocks cross-origin resources unless they carry CORP / proper CORS — opt in deliberately.
|
|
165
|
+
|
|
166
|
+
**2. Bring up the rayon thread pool once at startup.** Re-exported as `initThreadPool(n)`. The React SDK does NOT call this for you — consumers must `await` it before the first transaction:
|
|
167
|
+
|
|
168
|
+
```tsx
|
|
169
|
+
"use client";
|
|
170
|
+
import { useEffect } from "react";
|
|
171
|
+
import { MidenProvider, useMiden } from "@miden-sdk/react/mt/lazy";
|
|
172
|
+
import { initThreadPool } from "@miden-sdk/miden-sdk/mt/lazy";
|
|
173
|
+
|
|
174
|
+
function ThreadPoolBoot() {
|
|
175
|
+
const { isReady } = useMiden();
|
|
176
|
+
useEffect(() => {
|
|
177
|
+
if (!isReady) return;
|
|
178
|
+
void initThreadPool(navigator.hardwareConcurrency);
|
|
179
|
+
}, [isReady]);
|
|
180
|
+
return null;
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
184
|
+
return (
|
|
185
|
+
<MidenProvider config={{ rpcUrl: "testnet" }}>
|
|
186
|
+
<ThreadPoolBoot />
|
|
187
|
+
{children}
|
|
188
|
+
</MidenProvider>
|
|
189
|
+
);
|
|
190
|
+
}
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
`initThreadPool` is idempotent — calling it multiple times resolves with the existing pool. Without this call, the rayon global thread pool spawns zero workers on `wasm32` and every `par_iter(...)` falls through to a sequential loop. You'd be shipping multi-threaded WASM that runs single-threaded.
|
|
194
|
+
|
|
195
|
+
If you can't satisfy the COI requirement (third-party host, CDN that won't set headers), stay on the default `@miden-sdk/react` / `/lazy` subpaths — they ship the ST WASM and load anywhere.
|
|
196
|
+
|
|
144
197
|
### Constructing wasm-bindgen types directly in Next.js
|
|
145
198
|
|
|
146
199
|
Hooks accept strings for account IDs, asset IDs, and note IDs (auto-detecting hex vs. bech32) and parse them internally inside async callbacks, so **most apps never touch wasm-bindgen types directly**. If you do need to (e.g. to inspect an ID's prefix/suffix, validate a pasted string, or use a low-level API like `new Felt(…)`), import from `@miden-sdk/miden-sdk/lazy` and gate the call on `isReady`:
|
|
@@ -966,6 +1019,92 @@ function SwapForm() {
|
|
|
966
1019
|
}
|
|
967
1020
|
```
|
|
968
1021
|
|
|
1022
|
+
#### `usePswapCreate()`
|
|
1023
|
+
|
|
1024
|
+
Create a partial-swap (PSWAP) note. Unlike `useSwap`, a PSWAP can be filled by
|
|
1025
|
+
multiple consumers — each fill emits a payback note to the creator and, on a
|
|
1026
|
+
partial fill, a remainder PSWAP note carrying the unfilled portion. Use this
|
|
1027
|
+
when you want an offer that lives on-chain and can be matched piecemeal.
|
|
1028
|
+
|
|
1029
|
+
```tsx
|
|
1030
|
+
import { usePswapCreate } from '@miden-sdk/react';
|
|
1031
|
+
|
|
1032
|
+
function CreatePswapForm() {
|
|
1033
|
+
const { pswapCreate, isLoading, stage } = usePswapCreate();
|
|
1034
|
+
|
|
1035
|
+
const handleCreate = async () => {
|
|
1036
|
+
await pswapCreate({
|
|
1037
|
+
accountId: '0xmywallet...',
|
|
1038
|
+
offeredFaucetId: '0xtokenA...',
|
|
1039
|
+
offeredAmount: 100n,
|
|
1040
|
+
requestedFaucetId: '0xtokenB...',
|
|
1041
|
+
requestedAmount: 50n,
|
|
1042
|
+
// noteType, paybackNoteType — default 'private'
|
|
1043
|
+
});
|
|
1044
|
+
};
|
|
1045
|
+
|
|
1046
|
+
return (
|
|
1047
|
+
<button onClick={handleCreate} disabled={isLoading}>
|
|
1048
|
+
{isLoading ? `Creating PSWAP (${stage})...` : 'Create PSWAP'}
|
|
1049
|
+
</button>
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
```
|
|
1053
|
+
|
|
1054
|
+
#### `usePswapConsume()`
|
|
1055
|
+
|
|
1056
|
+
Fill an existing PSWAP note in whole or in part. The consumer supplies
|
|
1057
|
+
`fillAmount` of the requested asset and receives a proportional share of the
|
|
1058
|
+
offered asset. The `note` field accepts a hex string ID, a `NoteId` object,
|
|
1059
|
+
an `InputNoteRecord`, or a `Note` — strings and `NoteId`s are looked up from
|
|
1060
|
+
the local store; records and `Note`s are used directly.
|
|
1061
|
+
|
|
1062
|
+
```tsx
|
|
1063
|
+
import { usePswapConsume } from '@miden-sdk/react';
|
|
1064
|
+
|
|
1065
|
+
function FillPswapButton({ accountId, note }: Props) {
|
|
1066
|
+
const { pswapConsume, isLoading, stage } = usePswapConsume();
|
|
1067
|
+
|
|
1068
|
+
const handleFill = async () => {
|
|
1069
|
+
await pswapConsume({
|
|
1070
|
+
accountId,
|
|
1071
|
+
note, // string | NoteId | InputNoteRecord | Note
|
|
1072
|
+
fillAmount: 25n,
|
|
1073
|
+
});
|
|
1074
|
+
};
|
|
1075
|
+
|
|
1076
|
+
return (
|
|
1077
|
+
<button onClick={handleFill} disabled={isLoading}>
|
|
1078
|
+
{isLoading ? stage : 'Fill PSWAP'}
|
|
1079
|
+
</button>
|
|
1080
|
+
);
|
|
1081
|
+
}
|
|
1082
|
+
```
|
|
1083
|
+
|
|
1084
|
+
#### `usePswapCancel()`
|
|
1085
|
+
|
|
1086
|
+
Cancel a PSWAP note as its creator and reclaim the unfilled offered asset.
|
|
1087
|
+
The submitting account must be the original creator; the WASM builder
|
|
1088
|
+
enforces this at request-build time.
|
|
1089
|
+
|
|
1090
|
+
```tsx
|
|
1091
|
+
import { usePswapCancel } from '@miden-sdk/react';
|
|
1092
|
+
|
|
1093
|
+
function CancelPswapButton({ accountId, note }: Props) {
|
|
1094
|
+
const { pswapCancel, isLoading, stage } = usePswapCancel();
|
|
1095
|
+
|
|
1096
|
+
const handleCancel = async () => {
|
|
1097
|
+
await pswapCancel({ accountId, note });
|
|
1098
|
+
};
|
|
1099
|
+
|
|
1100
|
+
return (
|
|
1101
|
+
<button onClick={handleCancel} disabled={isLoading}>
|
|
1102
|
+
{isLoading ? stage : 'Cancel PSWAP'}
|
|
1103
|
+
</button>
|
|
1104
|
+
);
|
|
1105
|
+
}
|
|
1106
|
+
```
|
|
1107
|
+
|
|
969
1108
|
#### `useTransaction()`
|
|
970
1109
|
|
|
971
1110
|
Execute a custom `TransactionRequest` or build one with the client. This is the
|
package/dist/index.d.ts
CHANGED
|
@@ -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 };
|