@wasit-dev/core 0.6.0 → 0.8.0-beta.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 +12 -4
- package/dist/baseline.d.ts +109 -0
- package/dist/baseline.js +351 -0
- package/dist/catalogue.d.ts +10 -0
- package/dist/catalogue.js +69 -3
- package/dist/check.d.ts +78 -2
- package/dist/check.js +69 -10
- package/dist/ci-report.d.ts +74 -0
- package/dist/ci-report.js +391 -0
- package/dist/config.d.ts +205 -0
- package/dist/config.js +1011 -0
- package/dist/denied-env.d.ts +33 -0
- package/dist/denied-env.js +86 -0
- package/dist/errors.d.ts +44 -1
- package/dist/errors.js +151 -2
- package/dist/guard/budget.d.ts +135 -0
- package/dist/guard/budget.js +199 -0
- package/dist/guard/ci-event.d.ts +50 -0
- package/dist/guard/ci-event.js +125 -0
- package/dist/guard/mainnet-optin.d.ts +58 -0
- package/dist/guard/mainnet-optin.js +95 -0
- package/dist/guard/networks.d.ts +50 -0
- package/dist/guard/networks.js +80 -0
- package/dist/guard/rpc-identity.d.ts +45 -0
- package/dist/guard/rpc-identity.js +156 -0
- package/dist/guard/rpc-in-use.d.ts +48 -0
- package/dist/guard/rpc-in-use.js +84 -0
- package/dist/index.d.ts +34 -3
- package/dist/index.js +31 -2
- package/dist/mpp/channel-commitment.d.ts +48 -2
- package/dist/mpp/channel-commitment.js +80 -4
- package/dist/mpp/channel-credential.js +3 -0
- package/dist/mpp/channel.js +29 -0
- package/dist/mpp/charge.d.ts +25 -2
- package/dist/mpp/charge.js +100 -8
- package/dist/mpp/network.js +4 -1
- package/dist/mpp/suite.js +10 -2
- package/dist/report.d.ts +163 -0
- package/dist/report.js +282 -0
- package/dist/sanitize.d.ts +52 -0
- package/dist/sanitize.js +106 -0
- package/dist/settlement.d.ts +14 -0
- package/dist/settlement.js +1 -1
- package/dist/verdict.d.ts +24 -0
- package/dist/verdict.js +46 -0
- package/dist/versions.d.ts +50 -0
- package/dist/versions.js +123 -0
- package/dist/x402/chains/evm.d.ts +65 -0
- package/dist/x402/chains/evm.js +237 -0
- package/dist/x402/chains/index.d.ts +18 -0
- package/dist/x402/chains/index.js +28 -0
- package/dist/x402/chains/stellar.d.ts +38 -0
- package/dist/x402/chains/stellar.js +277 -0
- package/dist/x402/chains/svm.d.ts +69 -0
- package/dist/x402/chains/svm.js +333 -0
- package/dist/x402/chains/types.d.ts +152 -0
- package/dist/x402/chains/types.js +10 -0
- package/dist/x402/chains/wait.d.ts +36 -0
- package/dist/x402/chains/wait.js +42 -0
- package/dist/x402/plan.d.ts +82 -0
- package/dist/x402/plan.js +146 -0
- package/dist/x402/rejected-request.d.ts +146 -0
- package/dist/x402/rejected-request.js +269 -0
- package/dist/x402/requirements.d.ts +46 -0
- package/dist/x402/requirements.js +359 -0
- package/dist/x402/simulator.d.ts +74 -17
- package/dist/x402/simulator.js +907 -246
- package/package.json +11 -6
package/dist/mpp/channel.js
CHANGED
|
@@ -4,6 +4,7 @@ import { CheckSetupError } from "../errors.js";
|
|
|
4
4
|
import { readChannelWithdrawn } from "./channel-commitment.js";
|
|
5
5
|
import { buildChannelCredential, fetchChannelChallenge, serializeChannelCredential, submitCredential, } from "./channel-credential.js";
|
|
6
6
|
import { assertMppNetwork, networkPassphrase, resolveRpcUrl } from "./network.js";
|
|
7
|
+
import { assertPaymentNetworkAllowed } from "../guard/networks.js";
|
|
7
8
|
/**
|
|
8
9
|
* MPP-10: The channel contract deploys correctly — its address is valid
|
|
9
10
|
* and its on-chain state is queryable, and matches the parameters it was
|
|
@@ -46,6 +47,20 @@ export async function runMppChannelDeployChecks(options) {
|
|
|
46
47
|
},
|
|
47
48
|
];
|
|
48
49
|
}
|
|
50
|
+
/**
|
|
51
|
+
* L0 for a channel check called on its own: these checks sign commitments, and
|
|
52
|
+
* MPP-13 closes the channel on-chain, so they run on test networks only. The
|
|
53
|
+
* suite runs the same guard once at preflight.
|
|
54
|
+
*/
|
|
55
|
+
function refusedNetwork(id, name, network) {
|
|
56
|
+
try {
|
|
57
|
+
assertPaymentNetworkAllowed("mpp-channel", network);
|
|
58
|
+
return undefined;
|
|
59
|
+
}
|
|
60
|
+
catch (error) {
|
|
61
|
+
return [errored(id, name, error)];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
49
64
|
function failure(id, name, detail) {
|
|
50
65
|
return [{ id, name, pass: false, detail }];
|
|
51
66
|
}
|
|
@@ -128,6 +143,9 @@ export async function runMppChannelOrderingCheck(options) {
|
|
|
128
143
|
const id = "MPP-11";
|
|
129
144
|
const name = "Cumulative Commitment Ordering";
|
|
130
145
|
const { target, commitmentSecretHex, network, rpcUrl } = options;
|
|
146
|
+
const refused = refusedNetwork(id, name, network);
|
|
147
|
+
if (refused)
|
|
148
|
+
return refused;
|
|
131
149
|
try {
|
|
132
150
|
const { amount: baseline } = await advanceCumulative(options);
|
|
133
151
|
// (a) Exactly equal to the cumulative the server now holds.
|
|
@@ -198,6 +216,9 @@ export async function runMppChannelReplayCheck(options) {
|
|
|
198
216
|
const id = "MPP-12";
|
|
199
217
|
const name = "Challenge Replay Rejection";
|
|
200
218
|
const { target } = options;
|
|
219
|
+
const refused = refusedNetwork(id, name, options.network);
|
|
220
|
+
if (refused)
|
|
221
|
+
return refused;
|
|
201
222
|
try {
|
|
202
223
|
const { credential } = await advanceCumulative(options);
|
|
203
224
|
const replay = await submitCredential(target, credential);
|
|
@@ -232,6 +253,9 @@ export async function runMppChannelCommitmentReplayCheck(options) {
|
|
|
232
253
|
const id = "MPP-14";
|
|
233
254
|
const name = "Commitment Replay Rejection";
|
|
234
255
|
const { target } = options;
|
|
256
|
+
const refused = refusedNetwork(id, name, options.network);
|
|
257
|
+
if (refused)
|
|
258
|
+
return refused;
|
|
235
259
|
try {
|
|
236
260
|
const { amount, signature } = await advanceCumulative(options);
|
|
237
261
|
// Fresh challenge, same commitment. The signature is still cryptographically
|
|
@@ -264,6 +288,11 @@ export async function runMppChannelCloseCheck(options) {
|
|
|
264
288
|
const id = "MPP-13";
|
|
265
289
|
const name = "Close Settlement";
|
|
266
290
|
const { target, commitmentSecretHex, network, rpcUrl, expectedChannel, allowDestructive = false, closePollAttempts = 6, closePollDelayMs = 2_000, } = options;
|
|
291
|
+
// Before the destructive switch is even looked at: a close on a network
|
|
292
|
+
// that is not a test network is refused, enabled or not.
|
|
293
|
+
const refused = refusedNetwork(id, name, network);
|
|
294
|
+
if (refused)
|
|
295
|
+
return refused;
|
|
267
296
|
if (!allowDestructive) {
|
|
268
297
|
return [
|
|
269
298
|
skippedDestructive(id, name, "closing settles the channel on-chain and permanently ends it. " +
|
package/dist/mpp/charge.d.ts
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* The target's own 402 challenge is the source of truth for what should be
|
|
5
5
|
* paid. Verifying against it rather than against this run's configuration is
|
|
6
6
|
* what makes the check meaningful against a third-party service: it asks
|
|
7
|
-
* whether the service settled what it advertised, not what we assumed.
|
|
7
|
+
* whether the service settled what it advertised, not what we assumed. The
|
|
8
|
+
* one term it does not get to choose is the network: Wasit signs only for the
|
|
9
|
+
* network the run names, so a target cannot redirect the payer's key to
|
|
10
|
+
* mainnet by asking for it.
|
|
8
11
|
*
|
|
9
12
|
* Settlement is verified from the CAP-46 `transfer` contract event rather than
|
|
10
13
|
* the transaction envelope, because those can disagree. The envelope records
|
|
@@ -14,8 +17,10 @@
|
|
|
14
17
|
* @stellar/mpp's own client guards against when it refuses to sign a
|
|
15
18
|
* non-transfer authorization.
|
|
16
19
|
*/
|
|
20
|
+
import { charge } from "@stellar/mpp/charge/client";
|
|
17
21
|
import { Challenge } from "mppx";
|
|
18
22
|
import { type CheckResult } from "../check.js";
|
|
23
|
+
import { type MppNetwork } from "./network.js";
|
|
19
24
|
export interface MppChargeCheckOptions {
|
|
20
25
|
readonly target: string;
|
|
21
26
|
readonly network: string;
|
|
@@ -27,7 +32,11 @@ export interface ChargeChallenge {
|
|
|
27
32
|
readonly amount: bigint;
|
|
28
33
|
readonly currency: string;
|
|
29
34
|
readonly recipient: string;
|
|
35
|
+
/** The network the SDK's charge client would sign this challenge for. */
|
|
36
|
+
readonly network: MppNetwork;
|
|
30
37
|
}
|
|
38
|
+
/** The SDK's charge client, as `charge()` from @stellar/mpp builds it. */
|
|
39
|
+
type ChargeClient = ReturnType<typeof charge>;
|
|
31
40
|
/**
|
|
32
41
|
* Reads the advertised charge terms out of an already-decoded challenge.
|
|
33
42
|
*
|
|
@@ -38,15 +47,29 @@ export interface ChargeChallenge {
|
|
|
38
47
|
* about the target rather than as a harness failure.
|
|
39
48
|
*/
|
|
40
49
|
export declare function parseChargeChallenge(challenge: Challenge.Challenge): ChargeChallenge;
|
|
50
|
+
/**
|
|
51
|
+
* Pays `target` through `method` once at most, and only a challenge for
|
|
52
|
+
* `network`.
|
|
53
|
+
*
|
|
54
|
+
* mppx answers a 402 that follows a payment by paying the new challenge, up to
|
|
55
|
+
* `maxPaymentRetries` attempts (3 by default, dist/client/internal/Fetch.js in
|
|
56
|
+
* 0.8.14). MPP-01 judges one payment: a target that answers 402 after being
|
|
57
|
+
* paid has that 402 reported, rather than being paid twice more.
|
|
58
|
+
*/
|
|
59
|
+
export declare function payCharge(target: string, network: MppNetwork, method: ChargeClient): Promise<Response>;
|
|
41
60
|
/**
|
|
42
61
|
* MPP-01: the charge must settle on-chain for exactly the advertised amount.
|
|
43
62
|
*
|
|
44
63
|
* Runs a real payment against the target every time it is called. See
|
|
45
64
|
* docs/CHECKS.md — this check spends funds by design.
|
|
46
65
|
*
|
|
47
|
-
* @throws {ConfigurationError} Invalid target URL, network, or missing key
|
|
66
|
+
* @throws {ConfigurationError} Invalid target URL, network, or missing key, or
|
|
67
|
+
* a challenge for another network than the run's (nothing is signed).
|
|
68
|
+
* @throws {PaymentNetworkRefusedError} The run's network is not a test network
|
|
69
|
+
* (nothing is sent).
|
|
48
70
|
* @throws {TargetUnreachableError} The target never answered.
|
|
49
71
|
* @throws {MalformedResponseError} The target answered, non-conformantly.
|
|
50
72
|
* @throws {Error} RPC failure — reported as `harness`, never as a target defect.
|
|
51
73
|
*/
|
|
52
74
|
export declare function runMppChargeChecks(options: MppChargeCheckOptions): Promise<CheckResult[]>;
|
|
75
|
+
export {};
|
package/dist/mpp/charge.js
CHANGED
|
@@ -4,7 +4,10 @@
|
|
|
4
4
|
* The target's own 402 challenge is the source of truth for what should be
|
|
5
5
|
* paid. Verifying against it rather than against this run's configuration is
|
|
6
6
|
* what makes the check meaningful against a third-party service: it asks
|
|
7
|
-
* whether the service settled what it advertised, not what we assumed.
|
|
7
|
+
* whether the service settled what it advertised, not what we assumed. The
|
|
8
|
+
* one term it does not get to choose is the network: Wasit signs only for the
|
|
9
|
+
* network the run names, so a target cannot redirect the payer's key to
|
|
10
|
+
* mainnet by asking for it.
|
|
8
11
|
*
|
|
9
12
|
* Settlement is verified from the CAP-46 `transfer` contract event rather than
|
|
10
13
|
* the transaction envelope, because those can disagree. The envelope records
|
|
@@ -17,8 +20,10 @@
|
|
|
17
20
|
import { Mppx, charge } from "@stellar/mpp/charge/client";
|
|
18
21
|
import { Challenge, Receipt } from "mppx";
|
|
19
22
|
import { Keypair } from "@stellar/stellar-sdk";
|
|
20
|
-
import { ConfigurationError, MalformedResponseError, assertHttpUrl, fetchTarget, } from "../errors.js";
|
|
21
|
-
import { assertMppNetwork, resolveRpcUrl } from "./network.js";
|
|
23
|
+
import { ConfigurationError, MalformedResponseError, assertHttpUrl, fetchTarget, fetchWithoutRedirects, } from "../errors.js";
|
|
24
|
+
import { assertMppNetwork, isMppNetwork, resolveRpcUrl } from "./network.js";
|
|
25
|
+
import { assertPaymentNetworkAllowed } from "../guard/networks.js";
|
|
26
|
+
import { assertRpcServesNetwork } from "../guard/rpc-identity.js";
|
|
22
27
|
import { verifySettlement } from "../settlement.js";
|
|
23
28
|
const CHECK_ID = "MPP-01";
|
|
24
29
|
const CHECK_NAME = "Charge Settlement On-Chain";
|
|
@@ -87,7 +92,72 @@ export function parseChargeChallenge(challenge) {
|
|
|
87
92
|
throw new MalformedResponseError(`Challenge advertises a non-numeric amount ("${amountRaw}"). The spec ` +
|
|
88
93
|
`requires base units, e.g. "10000" for 0.001 of a 7-decimal token.`);
|
|
89
94
|
}
|
|
90
|
-
return { amount, currency, recipient };
|
|
95
|
+
return { amount, currency, recipient, network: chargeNetwork(request) };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The network @stellar/mpp's charge client signs a challenge for.
|
|
99
|
+
*
|
|
100
|
+
* The client takes it from the challenge, `methodDetails.network`, and signs a
|
|
101
|
+
* challenge that names none for testnet (`resolveNetworkId`,
|
|
102
|
+
* dist/shared/validation.js in 0.7.1). This reads it the same way, because
|
|
103
|
+
* what matters is the network the signature will be valid on.
|
|
104
|
+
*/
|
|
105
|
+
function chargeNetwork(request) {
|
|
106
|
+
const network = asRecord(request["methodDetails"])?.["network"];
|
|
107
|
+
if (network === undefined || network === null)
|
|
108
|
+
return "stellar:testnet";
|
|
109
|
+
if (typeof network === "string" && isMppNetwork(network))
|
|
110
|
+
return network;
|
|
111
|
+
throw new MalformedResponseError(`Charge challenge names network ${JSON.stringify(network)}. A Stellar ` +
|
|
112
|
+
`network is "stellar:testnet" or "stellar:pubnet" (CAIP-2).`);
|
|
113
|
+
}
|
|
114
|
+
/** Refuses a challenge for any network but the run's, before anything is signed. */
|
|
115
|
+
function assertRunNetwork(asked, network) {
|
|
116
|
+
if (asked !== network) {
|
|
117
|
+
throw new ConfigurationError(`The target asks to be paid on ${asked}, and this run pays on ${network} ` +
|
|
118
|
+
`only, so nothing was signed.`);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* `method`, refusing to sign a challenge for any network but `network`.
|
|
123
|
+
*
|
|
124
|
+
* Checking the unpaid challenge is not enough on its own: mppx requests the
|
|
125
|
+
* target again and pays the challenge in that answer, which the target is
|
|
126
|
+
* free to change. So the check also sits here, on the exact challenge about to
|
|
127
|
+
* be signed. Without it a target asking for `stellar:pubnet` gets a mainnet
|
|
128
|
+
* transfer signed, sent through the SDK's own default pubnet RPC endpoint.
|
|
129
|
+
*/
|
|
130
|
+
function onNetwork(method, network) {
|
|
131
|
+
return {
|
|
132
|
+
...method,
|
|
133
|
+
createCredential: async (parameters) => {
|
|
134
|
+
assertRunNetwork(chargeNetwork(asRecord(parameters.challenge.request) ?? {}), network);
|
|
135
|
+
return method.createCredential(parameters);
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Pays `target` through `method` once at most, and only a challenge for
|
|
141
|
+
* `network`.
|
|
142
|
+
*
|
|
143
|
+
* mppx answers a 402 that follows a payment by paying the new challenge, up to
|
|
144
|
+
* `maxPaymentRetries` attempts (3 by default, dist/client/internal/Fetch.js in
|
|
145
|
+
* 0.8.14). MPP-01 judges one payment: a target that answers 402 after being
|
|
146
|
+
* paid has that 402 reported, rather than being paid twice more.
|
|
147
|
+
*/
|
|
148
|
+
export async function payCharge(target, network, method) {
|
|
149
|
+
// L0 again at the signing call itself: it is exported, so a caller can
|
|
150
|
+
// reach it without going through runMppChargeChecks.
|
|
151
|
+
assertPaymentNetworkAllowed("mpp-charge", network);
|
|
152
|
+
const mppx = Mppx.create({
|
|
153
|
+
methods: [onNetwork(method, network)],
|
|
154
|
+
polyfill: false,
|
|
155
|
+
maxPaymentRetries: 1,
|
|
156
|
+
// Every request mppx makes here refuses a redirect (D-022c): it pays at the
|
|
157
|
+
// URL it read the challenge from, never at a URL the target sends it on to.
|
|
158
|
+
fetch: fetchWithoutRedirects,
|
|
159
|
+
});
|
|
160
|
+
return mppx.fetch(target);
|
|
91
161
|
}
|
|
92
162
|
function fail(detail) {
|
|
93
163
|
return [{ id: CHECK_ID, name: CHECK_NAME, pass: false, detail }];
|
|
@@ -101,7 +171,10 @@ function pass(detail) {
|
|
|
101
171
|
* Runs a real payment against the target every time it is called. See
|
|
102
172
|
* docs/CHECKS.md — this check spends funds by design.
|
|
103
173
|
*
|
|
104
|
-
* @throws {ConfigurationError} Invalid target URL, network, or missing key
|
|
174
|
+
* @throws {ConfigurationError} Invalid target URL, network, or missing key, or
|
|
175
|
+
* a challenge for another network than the run's (nothing is signed).
|
|
176
|
+
* @throws {PaymentNetworkRefusedError} The run's network is not a test network
|
|
177
|
+
* (nothing is sent).
|
|
105
178
|
* @throws {TargetUnreachableError} The target never answered.
|
|
106
179
|
* @throws {MalformedResponseError} The target answered, non-conformantly.
|
|
107
180
|
* @throws {Error} RPC failure — reported as `harness`, never as a target defect.
|
|
@@ -109,7 +182,10 @@ function pass(detail) {
|
|
|
109
182
|
export async function runMppChargeChecks(options) {
|
|
110
183
|
const { target, network, payerSecretKey, rpcUrl } = options;
|
|
111
184
|
assertHttpUrl(target);
|
|
112
|
-
assertMppNetwork(network);
|
|
185
|
+
const runNetwork = assertMppNetwork(network);
|
|
186
|
+
// L0: before the key is read, any request is sent or the SDK's charge
|
|
187
|
+
// client is built. MPP pays on test networks only.
|
|
188
|
+
assertPaymentNetworkAllowed("mpp-charge", runNetwork);
|
|
113
189
|
if (!payerSecretKey) {
|
|
114
190
|
throw new ConfigurationError("No payer secret key. MPP-01 settles a real payment and cannot run without one.");
|
|
115
191
|
}
|
|
@@ -123,13 +199,29 @@ export async function runMppChargeChecks(options) {
|
|
|
123
199
|
// Resolve the endpoint before spending anything: a bad RPC URL discovered
|
|
124
200
|
// after settlement would leave money moved and no verdict to show for it.
|
|
125
201
|
const endpoint = resolveRpcUrl(network, rpcUrl);
|
|
202
|
+
// The SDK's charge client builds its RPC client without `allowHttp`, so it
|
|
203
|
+
// cannot pay through an http endpoint, though settlement could be read from
|
|
204
|
+
// one. Say so before paying, instead of reporting the SDK's refusal as the
|
|
205
|
+
// target's failure.
|
|
206
|
+
if (endpoint.startsWith("http://")) {
|
|
207
|
+
throw new ConfigurationError(`MPP-01 pays through @stellar/mpp's charge client, which accepts only an ` +
|
|
208
|
+
`https RPC endpoint, and ${endpoint} is http. Nothing was sent.`);
|
|
209
|
+
}
|
|
210
|
+
// The payment is built and its settlement read through this endpoint: it
|
|
211
|
+
// must serve the run's network before the target is asked anything (D-023).
|
|
212
|
+
await assertRpcServesNetwork(runNetwork, endpoint);
|
|
126
213
|
const advertised = await fetchChargeChallenge(target);
|
|
127
|
-
|
|
214
|
+
assertRunNetwork(advertised.network, runNetwork);
|
|
128
215
|
let paid;
|
|
129
216
|
try {
|
|
130
|
-
|
|
217
|
+
// The payment goes through the run's endpoint too. Left to itself the SDK
|
|
218
|
+
// picks its own per network, so `--rpc-url` would cover only the
|
|
219
|
+
// settlement read, and pubnet would get a default endpoint after all.
|
|
220
|
+
paid = await payCharge(target, runNetwork, charge({ secretKey: payerSecretKey, rpcUrl: endpoint }));
|
|
131
221
|
}
|
|
132
222
|
catch (error) {
|
|
223
|
+
if (error instanceof ConfigurationError)
|
|
224
|
+
throw error;
|
|
133
225
|
// The target was reachable moments ago, so this is the payment path
|
|
134
226
|
// failing, not the network. Report it as a conformance failure.
|
|
135
227
|
throw new MalformedResponseError(`Payment attempt failed: ${error.message}`);
|
package/dist/mpp/network.js
CHANGED
|
@@ -9,7 +9,10 @@ import { Networks } from "@stellar/stellar-sdk";
|
|
|
9
9
|
import { ConfigurationError } from "../errors.js";
|
|
10
10
|
export class UnsupportedNetworkError extends ConfigurationError {
|
|
11
11
|
constructor(network) {
|
|
12
|
-
super(
|
|
12
|
+
super(
|
|
13
|
+
// stellar:pubnet is a known network (a challenge may name it), but the
|
|
14
|
+
// MPP checks never pay on it (L0), so only the test network is offered.
|
|
15
|
+
`Unsupported network "${network}". The MPP checks run on "stellar:testnet" only.`);
|
|
13
16
|
this.name = "UnsupportedNetworkError";
|
|
14
17
|
}
|
|
15
18
|
}
|
package/dist/mpp/suite.js
CHANGED
|
@@ -9,7 +9,9 @@ import { errored, skipped } from "../check.js";
|
|
|
9
9
|
import { assertHttpUrl, classifyCheckError } from "../errors.js";
|
|
10
10
|
import { runMppChannelCloseCheck, runMppChannelCommitmentReplayCheck, runMppChannelDeployChecks, runMppChannelOrderingCheck, runMppChannelReplayCheck, } from "./channel.js";
|
|
11
11
|
import { fetchChannelChallenge } from "./channel-credential.js";
|
|
12
|
-
import { assertMppNetwork } from "./network.js";
|
|
12
|
+
import { assertMppNetwork, resolveRpcUrl } from "./network.js";
|
|
13
|
+
import { assertPaymentNetworkAllowed } from "../guard/networks.js";
|
|
14
|
+
import { assertRpcServesNetwork } from "../guard/rpc-identity.js";
|
|
13
15
|
const DEPLOY_ID = "MPP-10";
|
|
14
16
|
const DEPLOY_NAME = "Channel Deploy";
|
|
15
17
|
function missingExpectations(expected) {
|
|
@@ -84,10 +86,16 @@ async function runDeployCheck(params) {
|
|
|
84
86
|
export async function runMppChannelSuite(options) {
|
|
85
87
|
const { target, commitmentSecretHex, network, rpcUrl, channelOverride, expected, allowDestructive = false, destructiveChannel, } = options;
|
|
86
88
|
// A bad URL or an unknown network is wrong for every check in the suite, so
|
|
87
|
-
// it is reported once here instead of repeated identically per check.
|
|
89
|
+
// it is reported once here instead of repeated identically per check. L0
|
|
90
|
+
// runs here too: the suite signs commitments and may close a channel, so a
|
|
91
|
+
// network that is not a test network stops it before any request.
|
|
88
92
|
try {
|
|
89
93
|
assertHttpUrl(target);
|
|
90
94
|
assertMppNetwork(network);
|
|
95
|
+
assertPaymentNetworkAllowed("mpp-channel", network);
|
|
96
|
+
// Commitments are prepared and the channel read through this endpoint: it
|
|
97
|
+
// must serve the run's network before the target is asked anything (D-023).
|
|
98
|
+
await assertRpcServesNetwork(network, resolveRpcUrl(network, rpcUrl));
|
|
91
99
|
}
|
|
92
100
|
catch (error) {
|
|
93
101
|
const preflight = errored("PREFLIGHT", "Run Preflight", error);
|
package/dist/report.d.ts
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The run report: what `wasit run` produces for the CLI's `--json`, the Action
|
|
3
|
+
* and the pull request comment, one shape (spec A2).
|
|
4
|
+
*
|
|
5
|
+
* The central rule is the endpoint outcome. An endpoint counts as graded only
|
|
6
|
+
* when it is `conformant` or `non-conformant` (spec A8 #3, D-021). A service
|
|
7
|
+
* Wasit cannot grade is `unsupported`; one that gave no verdict is
|
|
8
|
+
* `no-verdict`. Neither is a FAIL, and neither is a pass: the totals say how
|
|
9
|
+
* many endpoints were graded, so a run where nothing was cannot be read as
|
|
10
|
+
* green.
|
|
11
|
+
*/
|
|
12
|
+
import { type ProtocolId } from "./catalogue.js";
|
|
13
|
+
import { type CheckResult, type CheckStatus, type SkipKind, type StructuredCheckResult, type StructuredRun } from "./check.js";
|
|
14
|
+
import { type NetworkClass } from "./guard/networks.js";
|
|
15
|
+
import type { ToolVersions } from "./versions.js";
|
|
16
|
+
export type EndpointOutcome = "conformant" | "non-conformant" | "no-verdict" | "unsupported";
|
|
17
|
+
/** The groups of checks a report counts: the read-only challenge checks, the payment checks, and the two MPP modes. */
|
|
18
|
+
export type CheckGroup = "challenge" | "payment" | "mppCharge" | "mppChannel";
|
|
19
|
+
export interface GroupCounts {
|
|
20
|
+
readonly passed: number;
|
|
21
|
+
readonly failed: number;
|
|
22
|
+
readonly errored: number;
|
|
23
|
+
readonly skipped: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The group of a check id. X402-01..05 read the challenge, X402-06..10 pay;
|
|
27
|
+
* the MPP checks follow their mode. An id with no catalogue entry (PREFLIGHT)
|
|
28
|
+
* belongs to the group of the endpoint it was raised for.
|
|
29
|
+
*/
|
|
30
|
+
export declare function checkGroup(id: string, protocol: ProtocolId): CheckGroup;
|
|
31
|
+
/**
|
|
32
|
+
* True when an x402 payment check (X402-06..11) was skipped as `unsupported`:
|
|
33
|
+
* the run asked to pay and Wasit cannot pay on that network. A read-only or
|
|
34
|
+
* no-payer skip is not this, and neither is a result of another protocol. An MPP
|
|
35
|
+
* endpoint has no group besides its gating one, so for it this is always false.
|
|
36
|
+
* Works on the results of a fresh run and on the structured results of a report.
|
|
37
|
+
*/
|
|
38
|
+
export declare function paymentGroupUnsupported(results: ReadonlyArray<{
|
|
39
|
+
readonly id: string;
|
|
40
|
+
readonly skipKind?: SkipKind;
|
|
41
|
+
}>, protocol: ProtocolId): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* The outcome of one endpoint from its results.
|
|
44
|
+
*
|
|
45
|
+
* - any FAIL: `non-conformant`. A real finding outranks a missing one.
|
|
46
|
+
* - else an `unsupported` skip in the endpoint's gating group (the challenge
|
|
47
|
+
* checks for x402): `unsupported`. X402-01 may have passed on an x402 v1
|
|
48
|
+
* service; one passing check does not grade a paywall Wasit cannot read. An
|
|
49
|
+
* `unsupported` payment group alone does not make the endpoint unsupported:
|
|
50
|
+
* the challenge was graded.
|
|
51
|
+
* - else an `unsupported` skip in the payment group (payment checks were asked
|
|
52
|
+
* for and none could be graded on this network): `no-verdict`, so it is not
|
|
53
|
+
* green (Najmi, 2026-11-15).
|
|
54
|
+
* - else any ERROR: `no-verdict`.
|
|
55
|
+
* - else at least one PASS: `conformant`.
|
|
56
|
+
* - else (nothing ran, or everything was skipped): `no-verdict`.
|
|
57
|
+
*/
|
|
58
|
+
export declare function endpointOutcome(results: readonly CheckResult[], protocol: ProtocolId): EndpointOutcome;
|
|
59
|
+
/**
|
|
60
|
+
* The checks of an endpoint that pay or sign, as SKIPs the report can count and
|
|
61
|
+
* name (spec A2: the report says which checks need a payer).
|
|
62
|
+
*
|
|
63
|
+
* `read-only`: the run was asked not to pay. `needs-payer`: the run could have
|
|
64
|
+
* paid and had no key. The names come from the catalogue, so a rename there is
|
|
65
|
+
* the only place to change.
|
|
66
|
+
*/
|
|
67
|
+
export declare function skippedPaymentChecks(protocol: ProtocolId, kind: "read-only" | "needs-payer"): CheckResult[];
|
|
68
|
+
/**
|
|
69
|
+
* The same checks, skipped with a reason the caller words: the run asked to pay
|
|
70
|
+
* and a rule of the run stopped it (the GitHub event, `operatedByMe`, a key
|
|
71
|
+
* variable that is not set), or the front end does not run them.
|
|
72
|
+
*/
|
|
73
|
+
export declare function paymentChecksSkipped(protocol: ProtocolId, kind: SkipKind, reason: string): CheckResult[];
|
|
74
|
+
/**
|
|
75
|
+
* The exit code of one endpoint's checks (spec A8 #3, D-021): 1 on any FAIL; 2
|
|
76
|
+
* when the endpoint was not graded (`unsupported` or `no-verdict`) or a check
|
|
77
|
+
* could not run; else 0. Used where there is one endpoint, `wasit test` and the
|
|
78
|
+
* MCP x402 tool; a run of several endpoints uses {@link runExitCode}.
|
|
79
|
+
*/
|
|
80
|
+
export declare function exitCodeForEndpoint(results: readonly CheckResult[], protocol: ProtocolId): 0 | 1 | 2;
|
|
81
|
+
/**
|
|
82
|
+
* `toStructuredRun` with the outcome the exit rule gives: a service that was
|
|
83
|
+
* never graded is `no-verdict`, never `conformant`, for the MCP agent as for the
|
|
84
|
+
* shell. The counts are the same.
|
|
85
|
+
*/
|
|
86
|
+
export declare function toGradedRun(results: readonly CheckResult[], protocol: ProtocolId): StructuredRun;
|
|
87
|
+
export interface EndpointReport {
|
|
88
|
+
readonly name: string;
|
|
89
|
+
readonly protocol: ProtocolId;
|
|
90
|
+
readonly method: string;
|
|
91
|
+
readonly path: string;
|
|
92
|
+
readonly outcome: EndpointOutcome;
|
|
93
|
+
/** Why the endpoint is `unsupported` or has `no-verdict`; absent otherwise. */
|
|
94
|
+
readonly reason?: string;
|
|
95
|
+
/** Counts for each group that has at least one result; a group with no checks is absent. */
|
|
96
|
+
readonly groups: Readonly<Partial<Record<CheckGroup, GroupCounts>>>;
|
|
97
|
+
readonly results: readonly StructuredCheckResult[];
|
|
98
|
+
}
|
|
99
|
+
export interface EndpointInput {
|
|
100
|
+
readonly name: string;
|
|
101
|
+
readonly protocol: ProtocolId;
|
|
102
|
+
readonly method: string;
|
|
103
|
+
readonly path: string;
|
|
104
|
+
readonly results: readonly CheckResult[];
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Counts per group from any list of results that have an id and a status: the
|
|
108
|
+
* CheckResults of a fresh run, or the structured results of a report read back.
|
|
109
|
+
*/
|
|
110
|
+
export declare function groupCounts(results: ReadonlyArray<{
|
|
111
|
+
readonly id: string;
|
|
112
|
+
readonly status: CheckStatus;
|
|
113
|
+
}>, protocol: ProtocolId): Partial<Record<CheckGroup, GroupCounts>>;
|
|
114
|
+
/** Builds the report of one endpoint. Every text in it has passed through the sanitiser. */
|
|
115
|
+
export declare function buildEndpointReport(input: EndpointInput): EndpointReport;
|
|
116
|
+
export interface RunTotals {
|
|
117
|
+
readonly endpoints: number;
|
|
118
|
+
/** Endpoints that are `conformant` or `non-conformant`: the ones that were tested. */
|
|
119
|
+
readonly graded: number;
|
|
120
|
+
readonly conformant: number;
|
|
121
|
+
readonly nonConformant: number;
|
|
122
|
+
readonly noVerdict: number;
|
|
123
|
+
readonly unsupported: number;
|
|
124
|
+
}
|
|
125
|
+
export declare function reportTotals(endpoints: readonly EndpointReport[]): RunTotals;
|
|
126
|
+
/**
|
|
127
|
+
* The summary line: "0 graded, 1 unsupported". Says how many endpoints were
|
|
128
|
+
* graded first, so a run in which nothing was cannot be read as a pass.
|
|
129
|
+
*/
|
|
130
|
+
export declare function describeTotals(totals: RunTotals): string;
|
|
131
|
+
export interface RunReport {
|
|
132
|
+
readonly schema: 1;
|
|
133
|
+
readonly wasit: ToolVersions["wasit"];
|
|
134
|
+
readonly sdk: ToolVersions["sdk"];
|
|
135
|
+
readonly environment: string;
|
|
136
|
+
readonly network: string;
|
|
137
|
+
readonly networkClass: NetworkClass;
|
|
138
|
+
/** ISO 8601, supplied by the caller. */
|
|
139
|
+
readonly startedAt: string;
|
|
140
|
+
readonly endpoints: readonly EndpointReport[];
|
|
141
|
+
readonly totals: RunTotals;
|
|
142
|
+
readonly notes: readonly string[];
|
|
143
|
+
}
|
|
144
|
+
export interface RunReportInput {
|
|
145
|
+
readonly environment: string;
|
|
146
|
+
readonly network: string;
|
|
147
|
+
readonly startedAt: string;
|
|
148
|
+
readonly versions: ToolVersions;
|
|
149
|
+
readonly endpoints: readonly EndpointReport[];
|
|
150
|
+
readonly notes?: readonly string[];
|
|
151
|
+
}
|
|
152
|
+
/** Builds the run report. Pure: the clock and the installed versions are inputs. */
|
|
153
|
+
export declare function buildRunReport(input: RunReportInput): RunReport;
|
|
154
|
+
/**
|
|
155
|
+
* A copy of a JSON-shaped value with `secrets` removed from every string in it
|
|
156
|
+
* (and control characters, `::` lines and Stellar keys dealt with, as
|
|
157
|
+
* everywhere), and every `expected` and `actual` cut to a short length. The
|
|
158
|
+
* report is built from text a service sent, and a service can echo a header it
|
|
159
|
+
* was sent; this is the last pass before it is printed or written.
|
|
160
|
+
*/
|
|
161
|
+
export declare function redactValue<T>(value: T, secrets: readonly string[]): T;
|
|
162
|
+
/** {@link redactValue} for a run report. */
|
|
163
|
+
export declare function redactReport(report: RunReport, secrets: readonly string[]): RunReport;
|