@miden-sdk/miden-sdk 0.15.7 → 0.16.0-alpha.1
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/README.md +0 -152
- package/dist/mt/{Cargo-CnGom-_z.js → Cargo-DKsyWYgG.js} +700 -1245
- package/dist/mt/Cargo-DKsyWYgG.js.map +1 -0
- package/dist/mt/api-types.d.ts +38 -370
- package/dist/mt/assets/miden_client_web.wasm +0 -0
- package/dist/mt/crates/miden_client_web.d.ts +179 -402
- package/dist/mt/docs-entry.d.ts +3 -9
- package/dist/mt/eager.js +1 -1
- package/dist/mt/index.d.ts +0 -3
- package/dist/mt/index.js +53 -701
- 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-CnGom-_z-X_3VwTbo.js → Cargo-DKsyWYgG-DfOhgt23.js} +700 -1245
- package/dist/mt/workers/Cargo-DKsyWYgG-DfOhgt23.js.map +1 -0
- package/dist/mt/workers/assets/miden_client_web.wasm +0 -0
- package/dist/mt/workers/web-client-methods-worker.js +703 -1251
- package/dist/mt/workers/web-client-methods-worker.js.map +1 -1
- package/dist/mt/workers/web-client-methods-worker.module.js +1 -1
- 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-DR9fiMbE.js → Cargo-LwITdlzJ.js} +695 -1237
- package/dist/st/Cargo-LwITdlzJ.js.map +1 -0
- package/dist/st/api-types.d.ts +38 -370
- package/dist/st/assets/miden_client_web.wasm +0 -0
- package/dist/st/crates/miden_client_web.d.ts +179 -402
- package/dist/st/docs-entry.d.ts +3 -9
- package/dist/st/eager.js +1 -1
- package/dist/st/index.d.ts +0 -3
- package/dist/st/index.js +53 -701
- package/dist/st/index.js.map +1 -1
- package/dist/st/wasm.js +1 -1
- package/dist/st/workers/{Cargo-DR9fiMbE-C0G0clA_.js → Cargo-LwITdlzJ-Dyl2bCwN.js} +695 -1237
- package/dist/st/workers/Cargo-LwITdlzJ-Dyl2bCwN.js.map +1 -0
- package/dist/st/workers/assets/miden_client_web.wasm +0 -0
- package/dist/st/workers/web-client-methods-worker.js +698 -1243
- package/dist/st/workers/web-client-methods-worker.js.map +1 -1
- package/dist/st/workers/web-client-methods-worker.module.js +1 -1
- package/dist/st/workers/web-client-methods-worker.module.js.map +1 -1
- package/js/client.js +2 -4
- package/js/node/client-factory.js +4 -11
- package/js/node/napi-compat.js +1 -0
- package/js/node-index.js +11 -11
- package/js/resources/compiler.js +23 -12
- package/js/resources/transactions.js +24 -540
- package/js/standalone.js +3 -61
- package/package.json +4 -4
- package/dist/mt/Cargo-CnGom-_z.js.map +0 -1
- package/dist/mt/workers/Cargo-CnGom-_z-X_3VwTbo.js.map +0 -1
- package/dist/st/Cargo-DR9fiMbE.js.map +0 -1
- package/dist/st/workers/Cargo-DR9fiMbE-C0G0clA_.js.map +0 -1
- package/js/resources/pswap.js +0 -132
package/js/resources/pswap.js
DELETED
|
@@ -1,132 +0,0 @@
|
|
|
1
|
-
import { resolveAccountRef } from "../utils.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Coerce an `orderId` (string | bigint) to a decimal string for the WASM
|
|
5
|
-
* `u64` parse on the other side.
|
|
6
|
-
*
|
|
7
|
-
* A PSWAP `orderId` is `u64`-shaped and routinely exceeds
|
|
8
|
-
* `Number.MAX_SAFE_INTEGER` (`2^53 - 1`). JS `number` cannot represent the
|
|
9
|
-
* full u64 range without silent precision loss, so it is not accepted — pass
|
|
10
|
-
* `orderId` as a `bigint` or `string` instead.
|
|
11
|
-
*
|
|
12
|
-
* @param {string | bigint} orderId
|
|
13
|
-
* @returns {string}
|
|
14
|
-
*/
|
|
15
|
-
function normalizeOrderId(orderId) {
|
|
16
|
-
if (typeof orderId === "bigint") return orderId.toString();
|
|
17
|
-
if (typeof orderId === "string") return orderId;
|
|
18
|
-
throw new TypeError(
|
|
19
|
-
`PSWAP orderId must be a string or bigint; got ${typeof orderId}`
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* PswapResource surfaces partial-swap (PSWAP) lineage tracking and creator-side
|
|
25
|
-
* cancellation keyed by a lineage's stable order id.
|
|
26
|
-
*
|
|
27
|
-
* A PSWAP note can be filled by many consumers; each fill advances the lineage
|
|
28
|
-
* to a new remainder note. The client persists that chain locally as it syncs,
|
|
29
|
-
* and the reader methods here expose it. {@link PswapResource#cancelByOrder}
|
|
30
|
-
* reclaims the unfilled offered asset on the current tip of an active lineage,
|
|
31
|
-
* resolving the creator account from the tracked record so the caller only
|
|
32
|
-
* needs the order id.
|
|
33
|
-
*/
|
|
34
|
-
export class PswapResource {
|
|
35
|
-
#inner;
|
|
36
|
-
#getWasm;
|
|
37
|
-
#client;
|
|
38
|
-
|
|
39
|
-
constructor(inner, getWasm, client) {
|
|
40
|
-
this.#inner = inner;
|
|
41
|
-
this.#getWasm = getWasm;
|
|
42
|
-
this.#client = client;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Returns every PSWAP lineage tracked by this client.
|
|
47
|
-
*
|
|
48
|
-
* @returns {Promise<PswapLineageRecord[]>} All tracked lineages.
|
|
49
|
-
*/
|
|
50
|
-
async lineages() {
|
|
51
|
-
this.#client.assertNotTerminated();
|
|
52
|
-
return await this.#inner.getPswapLineages();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Returns lineages created by a specific local account.
|
|
57
|
-
*
|
|
58
|
-
* @param {AccountRef} account - Creator account (hex, bech32, Account, or AccountId).
|
|
59
|
-
* @returns {Promise<PswapLineageRecord[]>} Lineages created by the account.
|
|
60
|
-
*/
|
|
61
|
-
async lineagesFor(account) {
|
|
62
|
-
this.#client.assertNotTerminated();
|
|
63
|
-
const wasm = await this.#getWasm();
|
|
64
|
-
const accountId = resolveAccountRef(account, wasm);
|
|
65
|
-
return await this.#inner.getPswapLineagesFor(accountId);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Returns the lineage for one order, or null if not tracked.
|
|
70
|
-
*
|
|
71
|
-
* @param {string | bigint} orderId - Stable order id. Pass as a `string` or
|
|
72
|
-
* `bigint` for the full `u64` range; `number` is rejected because it cannot
|
|
73
|
-
* represent ids above `Number.MAX_SAFE_INTEGER` without precision loss.
|
|
74
|
-
* @returns {Promise<PswapLineageRecord | null>} The lineage, or null.
|
|
75
|
-
*/
|
|
76
|
-
async lineage(orderId) {
|
|
77
|
-
this.#client.assertNotTerminated();
|
|
78
|
-
const result = await this.#inner.getPswapLineage(normalizeOrderId(orderId));
|
|
79
|
-
return result ?? null;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Builds and submits a transaction reclaiming the unfilled offered asset on
|
|
84
|
-
* the current tip of an Active lineage. The creator account is resolved from
|
|
85
|
-
* the tracked lineage, so only the order id is required. Runs through the
|
|
86
|
-
* same execute/prove/submit path as the other transaction helpers.
|
|
87
|
-
*
|
|
88
|
-
* Throws before submitting any transaction when:
|
|
89
|
-
* - no lineage is tracked for `orderId`, OR
|
|
90
|
-
* - the lineage is in a terminal state (`FullyFilled` or `Reclaimed`,
|
|
91
|
-
* guarded by the `buildPswapCancelByOrder` binding).
|
|
92
|
-
*
|
|
93
|
-
* Concurrency: the lineage-read, build, and submit steps below are not
|
|
94
|
-
* atomic against external fills. If another consumer — or this client's own
|
|
95
|
-
* in-flight tx — advances the lineage tip between the build and submit, the
|
|
96
|
-
* cancel will target an already-consumed note and the kernel will reject
|
|
97
|
-
* it with a "note already nullified" error. Treat that as a signal to
|
|
98
|
-
* re-read the lineage and retry against the new tip.
|
|
99
|
-
*
|
|
100
|
-
* @param {PswapCancelByOrderOptions} opts - Order id and optional tx options.
|
|
101
|
-
* @returns {Promise<TransactionSubmitResult>} The submitted transaction.
|
|
102
|
-
*/
|
|
103
|
-
async cancelByOrder(opts) {
|
|
104
|
-
this.#client.assertNotTerminated();
|
|
105
|
-
const orderId = normalizeOrderId(opts.orderId);
|
|
106
|
-
|
|
107
|
-
// Fetch the lineage for the creator account (the cancel's submitter).
|
|
108
|
-
// The terminal-state guard is authoritative in the `buildPswapCancelByOrder`
|
|
109
|
-
// binding below, so it is not repeated here.
|
|
110
|
-
const lineage = await this.#inner.getPswapLineage(orderId);
|
|
111
|
-
if (!lineage) {
|
|
112
|
-
throw new Error(`No PSWAP lineage tracked for order ${orderId}`);
|
|
113
|
-
}
|
|
114
|
-
const accountId = lineage.creatorAccountId();
|
|
115
|
-
|
|
116
|
-
const request = await this.#inner.buildPswapCancelByOrder(orderId);
|
|
117
|
-
|
|
118
|
-
const { txId, result } = await this.#client.transactions.submit(
|
|
119
|
-
accountId,
|
|
120
|
-
request,
|
|
121
|
-
{ prover: opts.prover }
|
|
122
|
-
);
|
|
123
|
-
|
|
124
|
-
if (opts.waitForConfirmation) {
|
|
125
|
-
await this.#client.transactions.waitFor(txId.toHex(), {
|
|
126
|
-
timeout: opts.timeout,
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
return { txId, result };
|
|
131
|
-
}
|
|
132
|
-
}
|