@wasit-dev/core 0.7.0 → 0.8.0-beta.2

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.
Files changed (88) hide show
  1. package/README.md +13 -2
  2. package/dist/baseline.d.ts +109 -0
  3. package/dist/baseline.js +353 -0
  4. package/dist/catalogue.js +10 -0
  5. package/dist/check.d.ts +57 -2
  6. package/dist/check.js +46 -6
  7. package/dist/ci-report.d.ts +74 -0
  8. package/dist/ci-report.js +399 -0
  9. package/dist/config-writer.d.ts +96 -0
  10. package/dist/config-writer.js +281 -0
  11. package/dist/config.d.ts +205 -0
  12. package/dist/config.js +1011 -0
  13. package/dist/denied-env.d.ts +33 -0
  14. package/dist/denied-env.js +86 -0
  15. package/dist/errors.d.ts +44 -1
  16. package/dist/errors.js +151 -2
  17. package/dist/guard/budget.d.ts +138 -0
  18. package/dist/guard/budget.js +206 -0
  19. package/dist/guard/ci-event.d.ts +56 -0
  20. package/dist/guard/ci-event.js +129 -0
  21. package/dist/guard/ci-mainnet.d.ts +59 -0
  22. package/dist/guard/ci-mainnet.js +149 -0
  23. package/dist/guard/horizon.d.ts +30 -0
  24. package/dist/guard/horizon.js +107 -0
  25. package/dist/guard/mainnet-payer.d.ts +66 -0
  26. package/dist/guard/mainnet-payer.js +92 -0
  27. package/dist/guard/mainnet-plan.d.ts +133 -0
  28. package/dist/guard/mainnet-plan.js +208 -0
  29. package/dist/guard/mainnet-run.d.ts +87 -0
  30. package/dist/guard/mainnet-run.js +225 -0
  31. package/dist/guard/networks.d.ts +51 -0
  32. package/dist/guard/networks.js +91 -0
  33. package/dist/guard/optin.d.ts +106 -0
  34. package/dist/guard/optin.js +202 -0
  35. package/dist/guard/rpc-identity.d.ts +45 -0
  36. package/dist/guard/rpc-identity.js +156 -0
  37. package/dist/guard/rpc-in-use.d.ts +48 -0
  38. package/dist/guard/rpc-in-use.js +84 -0
  39. package/dist/guard/run-ledger.d.ts +212 -0
  40. package/dist/guard/run-ledger.js +426 -0
  41. package/dist/guard/run-lock.d.ts +62 -0
  42. package/dist/guard/run-lock.js +172 -0
  43. package/dist/guard/signed-terms.d.ts +96 -0
  44. package/dist/guard/signed-terms.js +207 -0
  45. package/dist/index.d.ts +44 -4
  46. package/dist/index.js +42 -2
  47. package/dist/mpp/channel-commitment.d.ts +48 -2
  48. package/dist/mpp/channel-commitment.js +80 -4
  49. package/dist/mpp/channel-credential.d.ts +13 -1
  50. package/dist/mpp/channel-credential.js +21 -2
  51. package/dist/mpp/channel.d.ts +6 -0
  52. package/dist/mpp/channel.js +36 -3
  53. package/dist/mpp/charge.d.ts +33 -1
  54. package/dist/mpp/charge.js +90 -20
  55. package/dist/mpp/network.js +4 -1
  56. package/dist/mpp/plan.d.ts +77 -0
  57. package/dist/mpp/plan.js +188 -0
  58. package/dist/mpp/suite.d.ts +6 -0
  59. package/dist/mpp/suite.js +12 -3
  60. package/dist/report.d.ts +163 -0
  61. package/dist/report.js +282 -0
  62. package/dist/route-reader.d.ts +124 -0
  63. package/dist/route-reader.js +349 -0
  64. package/dist/sanitize.d.ts +52 -0
  65. package/dist/sanitize.js +106 -0
  66. package/dist/settlement.d.ts +14 -0
  67. package/dist/settlement.js +1 -1
  68. package/dist/verdict.d.ts +24 -0
  69. package/dist/verdict.js +46 -0
  70. package/dist/versions.d.ts +50 -0
  71. package/dist/versions.js +123 -0
  72. package/dist/wallet.d.ts +58 -1
  73. package/dist/wallet.js +128 -0
  74. package/dist/x402/chains/evm.js +3 -0
  75. package/dist/x402/chains/index.d.ts +8 -0
  76. package/dist/x402/chains/index.js +13 -2
  77. package/dist/x402/chains/stellar.d.ts +8 -1
  78. package/dist/x402/chains/stellar.js +259 -4
  79. package/dist/x402/chains/types.d.ts +104 -2
  80. package/dist/x402/plan.d.ts +184 -0
  81. package/dist/x402/plan.js +520 -0
  82. package/dist/x402/rejected-request.d.ts +156 -0
  83. package/dist/x402/rejected-request.js +287 -0
  84. package/dist/x402/requirements.d.ts +1 -0
  85. package/dist/x402/requirements.js +37 -4
  86. package/dist/x402/simulator.d.ts +86 -1
  87. package/dist/x402/simulator.js +863 -87
  88. package/package.json +1 -1
@@ -0,0 +1,123 @@
1
+ /**
2
+ * The versions a result names: Wasit core and the CLI, the x402 version Wasit
3
+ * grades, and the SDK packages the checks run through.
4
+ *
5
+ * Read at run time from the installed packages' own `package.json`, by path,
6
+ * never typed by hand: a constant drifts from what is installed, and the point
7
+ * of printing a version is that it is the one that ran. They are read by path
8
+ * and not through `require.resolve("<pkg>/package.json")` because the SDK
9
+ * packages' export maps do not list it (checked on 2026-11-15 for all five:
10
+ * ERR_PACKAGE_PATH_NOT_EXPORTED).
11
+ */
12
+ import { readFileSync } from "node:fs";
13
+ import { dirname, join, resolve } from "node:path";
14
+ import { fileURLToPath } from "node:url";
15
+ /** What is printed when a version cannot be established. Never a guess. */
16
+ const UNKNOWN = "unknown";
17
+ /** A version as npm publishes it. Anything else is not printed: these strings reach a pull request comment. */
18
+ const VERSION = /^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.+-]*)?$/;
19
+ /** An npm package name, scoped or not: no path segment can climb out of node_modules. */
20
+ const PACKAGE_NAME = /^(?:@[a-z0-9][a-z0-9._~-]*\/)?[a-z0-9][a-z0-9._~-]*$/;
21
+ function versionIn(manifestPath, expectedName) {
22
+ try {
23
+ const manifest = JSON.parse(readFileSync(manifestPath, "utf-8"));
24
+ return manifest.name === expectedName && typeof manifest.version === "string" && VERSION.test(manifest.version)
25
+ ? manifest.version
26
+ : undefined;
27
+ }
28
+ catch {
29
+ return undefined;
30
+ }
31
+ }
32
+ /**
33
+ * The installed version of `name`, found the way Node finds a dependency: in
34
+ * `node_modules` of `from` or of any directory above it.
35
+ *
36
+ * Returns "unknown" when the package is not there, its name does not match, or
37
+ * its version is not a version.
38
+ */
39
+ export function readPackageVersion(name, from) {
40
+ if (!PACKAGE_NAME.test(name))
41
+ return UNKNOWN;
42
+ let directory = resolve(from);
43
+ for (;;) {
44
+ const version = versionIn(join(directory, "node_modules", name, "package.json"), name);
45
+ if (version !== undefined)
46
+ return version;
47
+ const parent = dirname(directory);
48
+ if (parent === directory)
49
+ return UNKNOWN;
50
+ directory = parent;
51
+ }
52
+ }
53
+ /** This package's own version: the `package.json` above this file, in `src/` and in `dist/` alike. */
54
+ function ownVersion() {
55
+ let directory = dirname(fileURLToPath(import.meta.url));
56
+ for (;;) {
57
+ const version = versionIn(join(directory, "package.json"), "@wasit-dev/core");
58
+ if (version !== undefined)
59
+ return version;
60
+ const parent = dirname(directory);
61
+ if (parent === directory)
62
+ return UNKNOWN;
63
+ directory = parent;
64
+ }
65
+ }
66
+ /** A commit id as an Action ref gives it: all 40 characters, lower case. Anything else (a tag, a branch) is not a commit. */
67
+ const FULL_COMMIT = /^[0-9a-f]{40}$/;
68
+ /** What a result names of a commit: its first seven characters. */
69
+ const SHORT_COMMIT = /^[0-9a-f]{7}$/;
70
+ /** True for exactly seven lower-case hex characters: the only build text that reaches a comment. */
71
+ export function isShortCommit(value) {
72
+ return typeof value === "string" && SHORT_COMMIT.test(value);
73
+ }
74
+ /**
75
+ * The commit this build of Wasit was made from, when the Action says so: the
76
+ * action ref (`WASIT_BUILD_COMMIT`) if it is a full commit id. A tag or a branch
77
+ * name is not a commit, and says nothing here: a pinned tag already names the
78
+ * version, and a result must not name a build it cannot show.
79
+ */
80
+ export function readBuildCommit(env) {
81
+ const value = env["WASIT_BUILD_COMMIT"];
82
+ return value !== undefined && FULL_COMMIT.test(value) ? value.slice(0, 7) : undefined;
83
+ }
84
+ /**
85
+ * The versions of this run. The CLI knows its own version (core cannot read the
86
+ * CLI's `package.json`), so it passes it in.
87
+ */
88
+ export function readToolVersions(cliVersion, build) {
89
+ const here = dirname(fileURLToPath(import.meta.url));
90
+ // `@x402/core` is a dependency of `@x402/fetch`; when npm does not hoist it, it sits under that package.
91
+ const fetchDir = (() => {
92
+ for (let directory = here;; directory = dirname(directory)) {
93
+ const candidate = join(directory, "node_modules", "@x402", "fetch");
94
+ if (versionIn(join(candidate, "package.json"), "@x402/fetch") !== undefined)
95
+ return candidate;
96
+ if (dirname(directory) === directory)
97
+ return undefined;
98
+ }
99
+ })();
100
+ const read = (name) => {
101
+ for (const start of fetchDir === undefined ? [here] : [here, fetchDir]) {
102
+ const version = readPackageVersion(name, start);
103
+ if (version !== UNKNOWN)
104
+ return version;
105
+ }
106
+ return UNKNOWN;
107
+ };
108
+ return {
109
+ wasit: {
110
+ cli: cliVersion !== undefined && VERSION.test(cliVersion) ? cliVersion : UNKNOWN,
111
+ core: ownVersion(),
112
+ ...(isShortCommit(build) ? { build } : {}),
113
+ },
114
+ sdk: {
115
+ x402Version: 2,
116
+ "@x402/core": read("@x402/core"),
117
+ "@x402/stellar": read("@x402/stellar"),
118
+ "@stellar/mpp": read("@stellar/mpp"),
119
+ mppx: read("mppx"),
120
+ "@stellar/stellar-sdk": read("@stellar/stellar-sdk"),
121
+ },
122
+ };
123
+ }
package/dist/wallet.d.ts CHANGED
@@ -12,6 +12,9 @@
12
12
  * (faucet.circle.com) is a captcha-gated web form with no public API for
13
13
  * Stellar. `sendUsdcFromDistributor` covers the case where the operator has
14
14
  * already completed that manual step once, on an account of their own.
15
+ * `addTestnetUsdc` (used by `wasit init`) needs neither: it swaps a little of
16
+ * the account's own test XLM for test USDC on the public test exchange, the
17
+ * starter kit's way, and falls back to the trustline alone.
15
18
  *
16
19
  * **Error contract.** Every exported function that can fail throws one of
17
20
  * `errors.ts`'s types and never a raw Stellar SDK error: a bad key or a
@@ -23,7 +26,7 @@
23
26
  * Horizon's result codes into those messages; it stays exported only because
24
27
  * the CLI's own `--json` surface reuses it for non-wallet errors.
25
28
  */
26
- import { Asset } from "@stellar/stellar-sdk";
29
+ import { Asset, Keypair, type Transaction, type TransactionSource } from "@stellar/stellar-sdk";
27
30
  export declare const TESTNET_HORIZON_URL = "https://horizon-testnet.stellar.org";
28
31
  /** Circle's official USDC issuer on Stellar testnet — not a pubnet address. */
29
32
  export declare const TESTNET_USDC_ISSUER = "GBBD47IF6LWK7P7MDEVSCWR7DPUWV3NY3DTQEVFL4NAT4AQH3ZLLFLA5";
@@ -115,6 +118,60 @@ export declare function fundWithFriendbot(publicKey: string, attempts?: number):
115
118
  * reserve a trustline adds); callers should ensure that before calling this.
116
119
  */
117
120
  export declare function createUsdcTrustline(secretKey: string, source?: string): Promise<void>;
121
+ /**
122
+ * How much test XLM a new payer swaps for test USDC on the public test
123
+ * exchange, so it needs no faucet: the starter kit's amount
124
+ * (x402-starter-kit `lib/full.mjs`, `SWAP_XLM`), out of the 10,000 XLM
125
+ * Friendbot gives.
126
+ */
127
+ export declare const TESTNET_SWAP_XLM = "10";
128
+ /** One path Horizon's strict-send search answers with: only the fields the swap reads. */
129
+ export interface SwapPathRecord {
130
+ readonly destination_amount?: unknown;
131
+ readonly destination_asset_type?: unknown;
132
+ readonly destination_asset_code?: unknown;
133
+ readonly destination_asset_issuer?: unknown;
134
+ readonly path?: unknown;
135
+ }
136
+ /** The terms of the swap: the least USDC it accepts, and the assets in between. */
137
+ export interface UsdcSwapQuote {
138
+ /** A Stellar amount with 7 decimals. */
139
+ readonly destMin: string;
140
+ readonly path: readonly Asset[];
141
+ }
142
+ /**
143
+ * The swap's terms from Horizon's answer, or undefined when it gives no usable
144
+ * price. Every record is the exchange's, not trusted: only a path to Circle's
145
+ * testnet USDC counts, with an amount Stellar can carry and assets that parse;
146
+ * of those, the one that gives the most. It must give at least one USDC, and
147
+ * the swap then accepts no less than 80% of it, so it never runs at a much
148
+ * worse price than the one quoted. Sends nothing.
149
+ */
150
+ export declare function swapQuoteFrom(records: readonly SwapPathRecord[]): UsdcSwapQuote | undefined;
151
+ /**
152
+ * The one transaction that gives the account of `keypair` the testnet USDC
153
+ * trustline and, with a quote, swaps {@link TESTNET_SWAP_XLM} of its test XLM
154
+ * for test USDC paid to itself: both happen or neither does. Built for Stellar
155
+ * testnet only and signed; sends nothing.
156
+ */
157
+ export declare function usdcSetupTransaction(account: TransactionSource, keypair: Keypair, quote: UsdcSwapQuote | undefined): Transaction;
158
+ /** What {@link addTestnetUsdc} did: the trustline is there in both cases. */
159
+ export type UsdcSetupOutcome = {
160
+ readonly swapped: true;
161
+ } | {
162
+ readonly swapped: false;
163
+ readonly why: string;
164
+ };
165
+ /**
166
+ * Gives the account of `secretKey` the testnet USDC trustline and test USDC,
167
+ * with no faucet: it swaps {@link TESTNET_SWAP_XLM} test XLM on the public test
168
+ * exchange, in the same transaction as the trustline (the starter kit's way,
169
+ * spec C7 row 3). Without a usable price, or when that transaction fails (a
170
+ * price that moved, an empty book), it adds the trustline alone and says why.
171
+ * Throws only when the trustline itself could not be added. The account needs
172
+ * its test XLM first.
173
+ */
174
+ export declare function addTestnetUsdc(secretKey: string, source?: string): Promise<UsdcSetupOutcome>;
118
175
  /**
119
176
  * Sends testnet USDC from an already-funded distributor account to
120
177
  * `destinationPublicKey`. There is no way to acquire the first unit of
package/dist/wallet.js CHANGED
@@ -12,6 +12,9 @@
12
12
  * (faucet.circle.com) is a captcha-gated web form with no public API for
13
13
  * Stellar. `sendUsdcFromDistributor` covers the case where the operator has
14
14
  * already completed that manual step once, on an account of their own.
15
+ * `addTestnetUsdc` (used by `wasit init`) needs neither: it swaps a little of
16
+ * the account's own test XLM for test USDC on the public test exchange, the
17
+ * starter kit's way, and falls back to the trustline alone.
15
18
  *
16
19
  * **Error contract.** Every exported function that can fail throws one of
17
20
  * `errors.ts`'s types and never a raw Stellar SDK error: a bad key or a
@@ -221,6 +224,131 @@ export async function createUsdcTrustline(secretKey, source) {
221
224
  throw asWalletError(error, "create the USDC trustline");
222
225
  }
223
226
  }
227
+ /**
228
+ * How much test XLM a new payer swaps for test USDC on the public test
229
+ * exchange, so it needs no faucet: the starter kit's amount
230
+ * (x402-starter-kit `lib/full.mjs`, `SWAP_XLM`), out of the 10,000 XLM
231
+ * Friendbot gives.
232
+ */
233
+ export const TESTNET_SWAP_XLM = "10";
234
+ /** The swap accepts no less than this share of the quoted USDC, in percent (the kit's `SWAP_MIN_SHARE`, 0.8). */
235
+ const SWAP_MIN_PERCENT = 80n;
236
+ /** A quote under one USDC, in stroops, is no usable price (the kit's `out >= 1`). */
237
+ const SWAP_MIN_QUOTE_STROOPS = 10000000n;
238
+ const STROOPS_PER_UNIT = 10000000n;
239
+ /** A Stellar amount (at most 7 decimals) in stroops, or undefined when it is not one. */
240
+ function toStroops(amount) {
241
+ if (typeof amount !== "string")
242
+ return undefined;
243
+ const match = /^(\d{1,15})(?:\.(\d{1,7}))?$/.exec(amount);
244
+ if (match === null)
245
+ return undefined;
246
+ return BigInt(match[1]) * STROOPS_PER_UNIT + BigInt((match[2] ?? "").padEnd(7, "0"));
247
+ }
248
+ function fromStroops(stroops) {
249
+ return `${stroops / STROOPS_PER_UNIT}.${(stroops % STROOPS_PER_UNIT).toString().padStart(7, "0")}`;
250
+ }
251
+ function pathAssets(path) {
252
+ if (!Array.isArray(path))
253
+ return undefined;
254
+ try {
255
+ return path.map((entry) => entry.asset_type === "native" ? Asset.native() : new Asset(String(entry.asset_code), String(entry.asset_issuer)));
256
+ }
257
+ catch {
258
+ return undefined;
259
+ }
260
+ }
261
+ /**
262
+ * The swap's terms from Horizon's answer, or undefined when it gives no usable
263
+ * price. Every record is the exchange's, not trusted: only a path to Circle's
264
+ * testnet USDC counts, with an amount Stellar can carry and assets that parse;
265
+ * of those, the one that gives the most. It must give at least one USDC, and
266
+ * the swap then accepts no less than 80% of it, so it never runs at a much
267
+ * worse price than the one quoted. Sends nothing.
268
+ */
269
+ export function swapQuoteFrom(records) {
270
+ let best;
271
+ for (const record of records) {
272
+ if (record.destination_asset_type === "native" ||
273
+ record.destination_asset_code !== "USDC" ||
274
+ record.destination_asset_issuer !== TESTNET_USDC_ISSUER) {
275
+ continue;
276
+ }
277
+ const stroops = toStroops(record.destination_amount);
278
+ const path = pathAssets(record.path);
279
+ if (stroops === undefined || path === undefined)
280
+ continue;
281
+ if (best === undefined || stroops > best.stroops)
282
+ best = { stroops, path };
283
+ }
284
+ if (best === undefined || best.stroops < SWAP_MIN_QUOTE_STROOPS)
285
+ return undefined;
286
+ return { destMin: fromStroops((best.stroops * SWAP_MIN_PERCENT) / 100n), path: best.path };
287
+ }
288
+ /**
289
+ * The one transaction that gives the account of `keypair` the testnet USDC
290
+ * trustline and, with a quote, swaps {@link TESTNET_SWAP_XLM} of its test XLM
291
+ * for test USDC paid to itself: both happen or neither does. Built for Stellar
292
+ * testnet only and signed; sends nothing.
293
+ */
294
+ export function usdcSetupTransaction(account, keypair, quote) {
295
+ const usdc = testnetUsdcAsset();
296
+ const builder = new TransactionBuilder(account, { fee: BASE_FEE, networkPassphrase: Networks.TESTNET }).addOperation(Operation.changeTrust({ asset: usdc }));
297
+ if (quote !== undefined) {
298
+ builder.addOperation(Operation.pathPaymentStrictSend({
299
+ sendAsset: Asset.native(),
300
+ sendAmount: TESTNET_SWAP_XLM,
301
+ destination: keypair.publicKey(),
302
+ destAsset: usdc,
303
+ destMin: quote.destMin,
304
+ path: [...quote.path],
305
+ }));
306
+ }
307
+ const transaction = builder.setTimeout(60).build();
308
+ transaction.sign(keypair);
309
+ return transaction;
310
+ }
311
+ /**
312
+ * Gives the account of `secretKey` the testnet USDC trustline and test USDC,
313
+ * with no faucet: it swaps {@link TESTNET_SWAP_XLM} test XLM on the public test
314
+ * exchange, in the same transaction as the trustline (the starter kit's way,
315
+ * spec C7 row 3). Without a usable price, or when that transaction fails (a
316
+ * price that moved, an empty book), it adds the trustline alone and says why.
317
+ * Throws only when the trustline itself could not be added. The account needs
318
+ * its test XLM first.
319
+ */
320
+ export async function addTestnetUsdc(secretKey, source) {
321
+ publicKeyFromSecret(secretKey, source);
322
+ const keypair = Keypair.fromSecret(secretKey);
323
+ const server = horizonServer();
324
+ let quote;
325
+ let why = "the public test exchange gave no usable price";
326
+ try {
327
+ const found = await server.strictSendPaths(Asset.native(), TESTNET_SWAP_XLM, [testnetUsdcAsset()]).call();
328
+ quote = swapQuoteFrom(found.records);
329
+ }
330
+ catch {
331
+ why = "the public test exchange could not be asked for a price";
332
+ }
333
+ if (quote !== undefined) {
334
+ try {
335
+ const account = await server.loadAccount(keypair.publicKey());
336
+ await server.submitTransaction(usdcSetupTransaction(account, keypair, quote));
337
+ return { swapped: true };
338
+ }
339
+ catch (error) {
340
+ why = `the swap was not confirmed (${describeTransactionError(error)})`;
341
+ }
342
+ }
343
+ try {
344
+ const account = await server.loadAccount(keypair.publicKey());
345
+ await server.submitTransaction(usdcSetupTransaction(account, keypair, undefined));
346
+ }
347
+ catch (error) {
348
+ throw asWalletError(error, "create the USDC trustline");
349
+ }
350
+ return { swapped: false, why };
351
+ }
224
352
  /**
225
353
  * Sends testnet USDC from an already-funded distributor account to
226
354
  * `destinationPublicKey`. There is no way to acquire the first unit of
@@ -207,7 +207,10 @@ export const evmChain = {
207
207
  client.register("eip155:*", new ExactEvmScheme(signer, { rpcUrl }));
208
208
  const allowed = NETWORKS[network]?.allowedAssets;
209
209
  if (allowed !== undefined) {
210
+ // Replaces the controls Wasit set before this call, so the $1 cap on the
211
+ // default assets is stated again rather than left to the SDK's default.
210
212
  client.setSpendControls({
213
+ maxAmountPerPayment: "$1",
211
214
  allowedAssets: allowed.map((entry) => ({ network: network, ...entry })),
212
215
  });
213
216
  }
@@ -4,6 +4,14 @@
4
4
  */
5
5
  import type { PaymentChain } from "./types.js";
6
6
  export type { PaymentChain } from "./types.js";
7
+ /**
8
+ * Tests only: replaces the adapters, so a recording chain can stand in for a
9
+ * real one (spec B11, the worst-case property test). `undefined` restores the
10
+ * real ones. Not exported from the package index, and reachable from no flag,
11
+ * setting or tool argument. The network guard still applies: a replacement
12
+ * pays only on a test network.
13
+ */
14
+ export declare function setPaymentChainsForTesting(replacement: readonly PaymentChain[] | undefined): void;
7
15
  /** The adapter that pays on `network`, if Wasit has one. */
8
16
  export declare function paymentChainFor(network: string): PaymentChain | undefined;
9
17
  /** Every network the payment checks can pay on, in adapter order. */
@@ -7,11 +7,22 @@ import { stellarChain } from "./stellar.js";
7
7
  import { svmChain } from "./svm.js";
8
8
  // Stellar first: it is the default network, and the only chain with MPP.
9
9
  const CHAINS = [stellarChain, evmChain, svmChain];
10
+ let chains = CHAINS;
11
+ /**
12
+ * Tests only: replaces the adapters, so a recording chain can stand in for a
13
+ * real one (spec B11, the worst-case property test). `undefined` restores the
14
+ * real ones. Not exported from the package index, and reachable from no flag,
15
+ * setting or tool argument. The network guard still applies: a replacement
16
+ * pays only on a test network.
17
+ */
18
+ export function setPaymentChainsForTesting(replacement) {
19
+ chains = replacement ?? CHAINS;
20
+ }
10
21
  /** The adapter that pays on `network`, if Wasit has one. */
11
22
  export function paymentChainFor(network) {
12
- return CHAINS.find((chain) => chain.networks.includes(network));
23
+ return chains.find((chain) => chain.networks.includes(network));
13
24
  }
14
25
  /** Every network the payment checks can pay on, in adapter order. */
15
26
  export function paymentNetworks() {
16
- return CHAINS.flatMap((chain) => chain.networks);
27
+ return chains.flatMap((chain) => chain.networks);
17
28
  }
@@ -5,7 +5,7 @@
5
5
  * only one with MPP as well.
6
6
  */
7
7
  import { Asset } from "@stellar/stellar-sdk";
8
- import type { PaymentChain } from "./types.js";
8
+ import type { PaymentChain, SignedAuthorization } from "./types.js";
9
9
  /**
10
10
  * Corrupts the client's authorization signature, and nothing else.
11
11
  *
@@ -28,4 +28,11 @@ export declare function corruptAuthSignature(transaction: string): string;
28
28
  * the id derived from the asset.
29
29
  */
30
30
  export declare function sacAssetFromName(name: unknown, contractId: string, passphrase: string): Asset | undefined;
31
+ /**
32
+ * X402-11 reads (D-032, spec B16.4): the authorization a payment carries, as
33
+ * the payer signed it. Only an address credential is read; another form (the
34
+ * newer `AddressV2`, one with delegates) is not, and gives no reading rather
35
+ * than a guess, since its nonce handling was not read.
36
+ */
37
+ export declare function decodeStellarAuthorization(payload: Record<string, unknown>): SignedAuthorization;
31
38
  export declare const stellarChain: PaymentChain;