@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.
- package/README.md +13 -2
- package/dist/baseline.d.ts +109 -0
- package/dist/baseline.js +353 -0
- package/dist/catalogue.js +10 -0
- package/dist/check.d.ts +57 -2
- package/dist/check.js +46 -6
- package/dist/ci-report.d.ts +74 -0
- package/dist/ci-report.js +399 -0
- package/dist/config-writer.d.ts +96 -0
- package/dist/config-writer.js +281 -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 +138 -0
- package/dist/guard/budget.js +206 -0
- package/dist/guard/ci-event.d.ts +56 -0
- package/dist/guard/ci-event.js +129 -0
- package/dist/guard/ci-mainnet.d.ts +59 -0
- package/dist/guard/ci-mainnet.js +149 -0
- package/dist/guard/horizon.d.ts +30 -0
- package/dist/guard/horizon.js +107 -0
- package/dist/guard/mainnet-payer.d.ts +66 -0
- package/dist/guard/mainnet-payer.js +92 -0
- package/dist/guard/mainnet-plan.d.ts +133 -0
- package/dist/guard/mainnet-plan.js +208 -0
- package/dist/guard/mainnet-run.d.ts +87 -0
- package/dist/guard/mainnet-run.js +225 -0
- package/dist/guard/networks.d.ts +51 -0
- package/dist/guard/networks.js +91 -0
- package/dist/guard/optin.d.ts +106 -0
- package/dist/guard/optin.js +202 -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/guard/run-ledger.d.ts +212 -0
- package/dist/guard/run-ledger.js +426 -0
- package/dist/guard/run-lock.d.ts +62 -0
- package/dist/guard/run-lock.js +172 -0
- package/dist/guard/signed-terms.d.ts +96 -0
- package/dist/guard/signed-terms.js +207 -0
- package/dist/index.d.ts +44 -4
- package/dist/index.js +42 -2
- package/dist/mpp/channel-commitment.d.ts +48 -2
- package/dist/mpp/channel-commitment.js +80 -4
- package/dist/mpp/channel-credential.d.ts +13 -1
- package/dist/mpp/channel-credential.js +21 -2
- package/dist/mpp/channel.d.ts +6 -0
- package/dist/mpp/channel.js +36 -3
- package/dist/mpp/charge.d.ts +33 -1
- package/dist/mpp/charge.js +90 -20
- package/dist/mpp/network.js +4 -1
- package/dist/mpp/plan.d.ts +77 -0
- package/dist/mpp/plan.js +188 -0
- package/dist/mpp/suite.d.ts +6 -0
- package/dist/mpp/suite.js +12 -3
- package/dist/report.d.ts +163 -0
- package/dist/report.js +282 -0
- package/dist/route-reader.d.ts +124 -0
- package/dist/route-reader.js +349 -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/wallet.d.ts +58 -1
- package/dist/wallet.js +128 -0
- package/dist/x402/chains/evm.js +3 -0
- package/dist/x402/chains/index.d.ts +8 -0
- package/dist/x402/chains/index.js +13 -2
- package/dist/x402/chains/stellar.d.ts +8 -1
- package/dist/x402/chains/stellar.js +259 -4
- package/dist/x402/chains/types.d.ts +104 -2
- package/dist/x402/plan.d.ts +184 -0
- package/dist/x402/plan.js +520 -0
- package/dist/x402/rejected-request.d.ts +156 -0
- package/dist/x402/rejected-request.js +287 -0
- package/dist/x402/requirements.d.ts +1 -0
- package/dist/x402/requirements.js +37 -4
- package/dist/x402/simulator.d.ts +86 -1
- package/dist/x402/simulator.js +863 -87
- package/package.json +1 -1
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L1 for MPP-01 in `wasit run` (D-036): the charge an MPP charge endpoint asks
|
|
3
|
+
* for, read from its unpaid challenge before anything in the run is signed,
|
|
4
|
+
* held to the same caps as x402 ($1 a payment, one budget for the run), and
|
|
5
|
+
* planned together with the run's x402 payment checks.
|
|
6
|
+
*
|
|
7
|
+
* MPP pays on test networks only (L0): a run on any other network is refused
|
|
8
|
+
* here before any request. MPP-01 signs once per endpoint (mppx is built with
|
|
9
|
+
* `maxPaymentRetries: 1`, `charge.ts`), so its plan is one signature of the
|
|
10
|
+
* advertised amount. The channel checks sign commitments off-chain and Wasit
|
|
11
|
+
* sends no transaction for them, so they are not planned.
|
|
12
|
+
*
|
|
13
|
+
* It sends no payment, reads no key and signs nothing. `x402/plan.ts` is not
|
|
14
|
+
* changed by it: with no MPP charge endpoint the run's plan is the x402 plan
|
|
15
|
+
* as it was.
|
|
16
|
+
*/
|
|
17
|
+
import { type PinTerms } from "../guard/budget.js";
|
|
18
|
+
import { type EndpointPlan, type PlanEndpointInput, type RunPlan } from "../x402/plan.js";
|
|
19
|
+
import { type PlannedCharge } from "./charge.js";
|
|
20
|
+
/** The scheme an MPP-01 entry of a plan carries, so the plan's other readers can tell it from x402. */
|
|
21
|
+
export declare const MPP_CHARGE_SCHEME = "mpp-charge";
|
|
22
|
+
export interface MppChargePlanInput {
|
|
23
|
+
readonly name: string;
|
|
24
|
+
readonly target: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* One MPP charge endpoint's plan: what MPP-01 would sign, or why it would not
|
|
28
|
+
* pay ("not-paid": its challenge could not be read; "refused": the caps, the
|
|
29
|
+
* pin or the network do not allow it).
|
|
30
|
+
*/
|
|
31
|
+
export declare function planMppChargeEndpoint(network: string, endpoint: MppChargePlanInput, pin?: PinTerms): Promise<EndpointPlan>;
|
|
32
|
+
/** What MPP-01 may pay for an endpoint of the plan, or undefined when the plan does not let it pay. */
|
|
33
|
+
export declare function plannedChargeOf(entry: EndpointPlan | undefined): PlannedCharge | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* The x402 plan and the MPP-01 entries as one plan, against one cap: the
|
|
36
|
+
* run's worst case is the sum, and a sum above the cap refuses the run before
|
|
37
|
+
* anything is signed. With no MPP-01 entry it is the x402 plan, unchanged.
|
|
38
|
+
* Pure.
|
|
39
|
+
*/
|
|
40
|
+
export declare function combinePaymentPlan(x402: RunPlan, mppCharge: readonly EndpointPlan[]): RunPlan;
|
|
41
|
+
export interface PaymentRunPlanOptions {
|
|
42
|
+
readonly network: string;
|
|
43
|
+
readonly pin?: PinTerms;
|
|
44
|
+
/** A lower per-run cap in dollars. */
|
|
45
|
+
readonly maxRunUsd?: number;
|
|
46
|
+
/** The x402 endpoints this run pays. */
|
|
47
|
+
readonly x402: readonly PlanEndpointInput[];
|
|
48
|
+
/** The MPP charge endpoints this run pays. */
|
|
49
|
+
readonly mppCharge: readonly MppChargePlanInput[];
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The plan of a paying run on a test network: its x402 payment checks
|
|
53
|
+
* (`planX402Run`) and its MPP-01 payments, one cap for both. Throws the
|
|
54
|
+
* guard's refusal for a network that is not a test network (L0), before any
|
|
55
|
+
* request. Not for a mainnet run: that one pays x402 only, by its own plan.
|
|
56
|
+
*/
|
|
57
|
+
export declare function planPaymentRun(options: PaymentRunPlanOptions): Promise<RunPlan>;
|
|
58
|
+
/**
|
|
59
|
+
* The RPC of a run that pays MPP, checked before its service starts or any
|
|
60
|
+
* MPP endpoint is asked anything (D-023): it must serve the run's network,
|
|
61
|
+
* and for MPP-01 it must be https, because the SDK's charge client builds the
|
|
62
|
+
* payment through it and accepts no other. The suites check it again.
|
|
63
|
+
*
|
|
64
|
+
* @throws {RpcIdentityError} The RPC is not https for MPP-01, or does not serve the network.
|
|
65
|
+
*/
|
|
66
|
+
export declare function assertMppPaymentRpc(network: string, rpcUrl: string | undefined, uses: {
|
|
67
|
+
readonly charge: boolean;
|
|
68
|
+
}): Promise<void>;
|
|
69
|
+
/**
|
|
70
|
+
* The plan for a terminal or a log, as `describePlan` prints it; when the run
|
|
71
|
+
* pays MPP-01 too, its first line says so. `x402` and `mppCharge`: whether the
|
|
72
|
+
* run has endpoints of each.
|
|
73
|
+
*/
|
|
74
|
+
export declare function describePaymentPlan(plan: RunPlan, has: {
|
|
75
|
+
readonly x402: boolean;
|
|
76
|
+
readonly mppCharge: boolean;
|
|
77
|
+
}): string[];
|
package/dist/mpp/plan.js
ADDED
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L1 for MPP-01 in `wasit run` (D-036): the charge an MPP charge endpoint asks
|
|
3
|
+
* for, read from its unpaid challenge before anything in the run is signed,
|
|
4
|
+
* held to the same caps as x402 ($1 a payment, one budget for the run), and
|
|
5
|
+
* planned together with the run's x402 payment checks.
|
|
6
|
+
*
|
|
7
|
+
* MPP pays on test networks only (L0): a run on any other network is refused
|
|
8
|
+
* here before any request. MPP-01 signs once per endpoint (mppx is built with
|
|
9
|
+
* `maxPaymentRetries: 1`, `charge.ts`), so its plan is one signature of the
|
|
10
|
+
* advertised amount. The channel checks sign commitments off-chain and Wasit
|
|
11
|
+
* sends no transaction for them, so they are not planned.
|
|
12
|
+
*
|
|
13
|
+
* It sends no payment, reads no key and signs nothing. `x402/plan.ts` is not
|
|
14
|
+
* changed by it: with no MPP charge endpoint the run's plan is the x402 plan
|
|
15
|
+
* as it was.
|
|
16
|
+
*/
|
|
17
|
+
import { classifyCheckError } from "../errors.js";
|
|
18
|
+
import { sanitizeText } from "../sanitize.js";
|
|
19
|
+
import { PER_PAYMENT_CAP_USD, RunBudget, formatUsd, sameAddress, shown, usdAsset, usdFromDollars, } from "../guard/budget.js";
|
|
20
|
+
import { assertPaymentNetworkAllowed } from "../guard/networks.js";
|
|
21
|
+
import { RpcIdentityError, assertRpcServesNetwork } from "../guard/rpc-identity.js";
|
|
22
|
+
import { describePlan, planX402Run } from "../x402/plan.js";
|
|
23
|
+
import { readChargeChallenge } from "./charge.js";
|
|
24
|
+
import { assertMppNetwork, resolveRpcUrl } from "./network.js";
|
|
25
|
+
/** The scheme an MPP-01 entry of a plan carries, so the plan's other readers can tell it from x402. */
|
|
26
|
+
export const MPP_CHARGE_SCHEME = "mpp-charge";
|
|
27
|
+
const CHECK_ID = "MPP-01";
|
|
28
|
+
const nothing = (name, status, reason) => ({
|
|
29
|
+
name,
|
|
30
|
+
status,
|
|
31
|
+
reason,
|
|
32
|
+
signatures: [],
|
|
33
|
+
worstCase: 0n,
|
|
34
|
+
worstCaseUsd: 0n,
|
|
35
|
+
});
|
|
36
|
+
function message(error) {
|
|
37
|
+
return sanitizeText(classifyCheckError(error).message).replace(/\s+/g, " ");
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* One MPP charge endpoint's plan: what MPP-01 would sign, or why it would not
|
|
41
|
+
* pay ("not-paid": its challenge could not be read; "refused": the caps, the
|
|
42
|
+
* pin or the network do not allow it).
|
|
43
|
+
*/
|
|
44
|
+
export async function planMppChargeEndpoint(network, endpoint, pin) {
|
|
45
|
+
// L0 before any request: MPP pays on test networks only, and on Stellar.
|
|
46
|
+
assertPaymentNetworkAllowed("mpp-charge", network);
|
|
47
|
+
assertMppNetwork(network);
|
|
48
|
+
let challenge;
|
|
49
|
+
try {
|
|
50
|
+
challenge = await readChargeChallenge(endpoint.target);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
// The same reason MPP-01 gives when it reads the challenge itself.
|
|
54
|
+
return nothing(endpoint.name, "not-paid", message(error));
|
|
55
|
+
}
|
|
56
|
+
const { amount, currency, recipient } = challenge;
|
|
57
|
+
if (challenge.network !== network) {
|
|
58
|
+
return nothing(endpoint.name, "refused", `it asks to be paid on ${challenge.network}, and this run pays on ${network} only. Nothing was signed.`);
|
|
59
|
+
}
|
|
60
|
+
if (pin !== undefined) {
|
|
61
|
+
for (const [field, value, pinned] of [
|
|
62
|
+
["recipient", recipient, pin.payTo],
|
|
63
|
+
["currency", currency, pin.asset],
|
|
64
|
+
]) {
|
|
65
|
+
if (!sameAddress(network, value, pinned)) {
|
|
66
|
+
return nothing(endpoint.name, "refused", `its charge has ${field} ${shown(value)}, not the pinned ${pinned}. Nothing was signed.`);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
const asset = usdAsset(network, currency);
|
|
71
|
+
const price = RunBudget.valueOf(network, currency, amount);
|
|
72
|
+
if (asset === undefined || price === undefined) {
|
|
73
|
+
return nothing(endpoint.name, "refused", `it asks to be paid in ${shown(currency)}, an asset Wasit does not value in US dollars, so it cannot be held ` +
|
|
74
|
+
`to the $${PER_PAYMENT_CAP_USD}.00 cap. Nothing was signed.`);
|
|
75
|
+
}
|
|
76
|
+
const perPayment = usdFromDollars(PER_PAYMENT_CAP_USD);
|
|
77
|
+
if (price > perPayment) {
|
|
78
|
+
return nothing(endpoint.name, "refused", `it is priced at ${amount} base units of ${asset.symbol} (${formatUsd(price)}), above the ` +
|
|
79
|
+
`${formatUsd(perPayment)} per payment fixed in Wasit. Nothing was signed. Test a route priced at ` +
|
|
80
|
+
`${formatUsd(perPayment)} or less.`);
|
|
81
|
+
}
|
|
82
|
+
return {
|
|
83
|
+
name: endpoint.name,
|
|
84
|
+
status: "planned",
|
|
85
|
+
option: { scheme: MPP_CHARGE_SCHEME, network, payTo: recipient, asset: currency, amount, maxTimeoutSeconds: 0 },
|
|
86
|
+
signatures: [{ check: CHECK_ID, amount }],
|
|
87
|
+
worstCase: amount,
|
|
88
|
+
worstCaseUsd: price,
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
/** What MPP-01 may pay for an endpoint of the plan, or undefined when the plan does not let it pay. */
|
|
92
|
+
export function plannedChargeOf(entry) {
|
|
93
|
+
if (entry?.status !== "planned" || entry.option?.scheme !== MPP_CHARGE_SCHEME)
|
|
94
|
+
return undefined;
|
|
95
|
+
return { amount: entry.option.amount, currency: entry.option.asset, recipient: entry.option.payTo };
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* The x402 plan and the MPP-01 entries as one plan, against one cap: the
|
|
99
|
+
* run's worst case is the sum, and a sum above the cap refuses the run before
|
|
100
|
+
* anything is signed. With no MPP-01 entry it is the x402 plan, unchanged.
|
|
101
|
+
* Pure.
|
|
102
|
+
*/
|
|
103
|
+
export function combinePaymentPlan(x402, mppCharge) {
|
|
104
|
+
if (mppCharge.length === 0)
|
|
105
|
+
return x402;
|
|
106
|
+
const endpoints = [...x402.endpoints, ...mppCharge];
|
|
107
|
+
const planned = endpoints.filter((endpoint) => endpoint.status === "planned");
|
|
108
|
+
const worstCaseUsd = planned.reduce((sum, endpoint) => sum + endpoint.worstCaseUsd, 0n);
|
|
109
|
+
const { refusal: _x402Refusal, ...rest } = x402;
|
|
110
|
+
const plan = { ...rest, endpoints, worstCaseUsd };
|
|
111
|
+
// No entry may lower the sum: a worst case below zero is not a price, and the
|
|
112
|
+
// challenge reader refuses one. Were one here, the run's sum would hide the rest.
|
|
113
|
+
const negative = planned.filter((endpoint) => endpoint.worstCaseUsd < 0n);
|
|
114
|
+
if (negative.length > 0) {
|
|
115
|
+
return {
|
|
116
|
+
...plan,
|
|
117
|
+
refusal: `The plan has a worst case below zero for ${negative.map((endpoint) => sanitizeText(endpoint.name)).join(", ")}, ` +
|
|
118
|
+
`which is not a price. Nothing was signed.`,
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
if (worstCaseUsd <= x402.capUsd)
|
|
122
|
+
return plan;
|
|
123
|
+
const parts = planned.map((endpoint) => `${sanitizeText(endpoint.name)} ${formatUsd(endpoint.worstCaseUsd)}`);
|
|
124
|
+
return {
|
|
125
|
+
...plan,
|
|
126
|
+
refusal: `This run could spend up to ${formatUsd(worstCaseUsd)} (${parts.join(", ")}), above the ` +
|
|
127
|
+
`${formatUsd(x402.capUsd)} per run${x402.capLowered ? " set by maxRunUsd" : ""}. Nothing was signed. ` +
|
|
128
|
+
`Select fewer endpoints with --endpoint, or test a cheaper route.`,
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* The plan of a paying run on a test network: its x402 payment checks
|
|
133
|
+
* (`planX402Run`) and its MPP-01 payments, one cap for both. Throws the
|
|
134
|
+
* guard's refusal for a network that is not a test network (L0), before any
|
|
135
|
+
* request. Not for a mainnet run: that one pays x402 only, by its own plan.
|
|
136
|
+
*/
|
|
137
|
+
export async function planPaymentRun(options) {
|
|
138
|
+
if (options.mppCharge.length > 0)
|
|
139
|
+
assertPaymentNetworkAllowed("mpp-charge", options.network);
|
|
140
|
+
const x402 = await planX402Run({
|
|
141
|
+
network: options.network,
|
|
142
|
+
...(options.pin === undefined ? {} : { pin: options.pin }),
|
|
143
|
+
...(options.maxRunUsd === undefined ? {} : { maxRunUsd: options.maxRunUsd }),
|
|
144
|
+
endpoints: options.x402,
|
|
145
|
+
});
|
|
146
|
+
const mppCharge = [];
|
|
147
|
+
for (const endpoint of options.mppCharge) {
|
|
148
|
+
mppCharge.push(await planMppChargeEndpoint(options.network, endpoint, options.pin));
|
|
149
|
+
}
|
|
150
|
+
return combinePaymentPlan(x402, mppCharge);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* The RPC of a run that pays MPP, checked before its service starts or any
|
|
154
|
+
* MPP endpoint is asked anything (D-023): it must serve the run's network,
|
|
155
|
+
* and for MPP-01 it must be https, because the SDK's charge client builds the
|
|
156
|
+
* payment through it and accepts no other. The suites check it again.
|
|
157
|
+
*
|
|
158
|
+
* @throws {RpcIdentityError} The RPC is not https for MPP-01, or does not serve the network.
|
|
159
|
+
*/
|
|
160
|
+
export async function assertMppPaymentRpc(network, rpcUrl, uses) {
|
|
161
|
+
const endpoint = resolveRpcUrl(network, rpcUrl);
|
|
162
|
+
if (uses.charge) {
|
|
163
|
+
let protocol = "";
|
|
164
|
+
try {
|
|
165
|
+
protocol = new URL(endpoint).protocol;
|
|
166
|
+
}
|
|
167
|
+
catch {
|
|
168
|
+
protocol = "";
|
|
169
|
+
}
|
|
170
|
+
if (protocol !== "https:") {
|
|
171
|
+
throw new RpcIdentityError(`MPP-01 pays through @stellar/mpp's charge client, which builds the payment through the run's RPC and ` +
|
|
172
|
+
`accepts only an https RPC, and this run's RPC is not https. No payment was sent and nothing was signed.`);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
await assertRpcServesNetwork(network, endpoint);
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* The plan for a terminal or a log, as `describePlan` prints it; when the run
|
|
179
|
+
* pays MPP-01 too, its first line says so. `x402` and `mppCharge`: whether the
|
|
180
|
+
* run has endpoints of each.
|
|
181
|
+
*/
|
|
182
|
+
export function describePaymentPlan(plan, has) {
|
|
183
|
+
const lines = describePlan(plan);
|
|
184
|
+
if (has.x402 && !has.mppCharge)
|
|
185
|
+
return lines;
|
|
186
|
+
const what = has.x402 ? "x402 payment checks and MPP-01" : has.mppCharge ? "MPP-01" : "no payment to plan (no x402 or MPP charge endpoint)";
|
|
187
|
+
return [sanitizeText(`Plan (dry run): ${what} on ${plan.network}. Nothing is signed or sent.`), ...lines.slice(1)];
|
|
188
|
+
}
|
package/dist/mpp/suite.d.ts
CHANGED
|
@@ -24,6 +24,12 @@ export interface MppChannelSuiteOptions {
|
|
|
24
24
|
* on two contracts at once.
|
|
25
25
|
*/
|
|
26
26
|
readonly channelOverride?: string;
|
|
27
|
+
/**
|
|
28
|
+
* The only channel the checks sign commitments for (`wasit run` passes the
|
|
29
|
+
* config's `channel`): a challenge that names another gets no signature.
|
|
30
|
+
* Without it they sign for the channel each challenge names.
|
|
31
|
+
*/
|
|
32
|
+
readonly onlyChannel?: string;
|
|
27
33
|
readonly expected?: Partial<ChannelDeployExpectations>;
|
|
28
34
|
readonly allowDestructive?: boolean;
|
|
29
35
|
readonly destructiveChannel?: string;
|
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) {
|
|
@@ -82,12 +84,18 @@ async function runDeployCheck(params) {
|
|
|
82
84
|
* because a close is terminal.
|
|
83
85
|
*/
|
|
84
86
|
export async function runMppChannelSuite(options) {
|
|
85
|
-
const { target, commitmentSecretHex, network, rpcUrl, channelOverride, expected, allowDestructive = false, destructiveChannel, } = options;
|
|
87
|
+
const { target, commitmentSecretHex, network, rpcUrl, channelOverride, onlyChannel, 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);
|
|
@@ -99,6 +107,7 @@ export async function runMppChannelSuite(options) {
|
|
|
99
107
|
commitmentSecretHex,
|
|
100
108
|
network,
|
|
101
109
|
...(rpcUrl ? { rpcUrl } : {}),
|
|
110
|
+
...(onlyChannel ? { onlyChannel } : {}),
|
|
102
111
|
};
|
|
103
112
|
// The target decides which channel it bills through, so its challenge — not
|
|
104
113
|
// the operator's environment — is the authority on what this run is about.
|
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;
|