@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/report.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
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 { catalogueEntry } from "./catalogue.js";
|
|
13
|
+
import { checkStatus, skipped, summarize, toStructuredRun, } from "./check.js";
|
|
14
|
+
import { networkClass } from "./guard/networks.js";
|
|
15
|
+
import { sanitizeText } from "./sanitize.js";
|
|
16
|
+
/** The group whose result decides whether an endpoint can be graded at all. */
|
|
17
|
+
const GATING_GROUP = {
|
|
18
|
+
x402: "challenge",
|
|
19
|
+
"mpp-charge": "mppCharge",
|
|
20
|
+
"mpp-channel": "mppChannel",
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* The group of a check id. X402-01..05 read the challenge, X402-06..10 pay;
|
|
24
|
+
* the MPP checks follow their mode. An id with no catalogue entry (PREFLIGHT)
|
|
25
|
+
* belongs to the group of the endpoint it was raised for.
|
|
26
|
+
*/
|
|
27
|
+
export function checkGroup(id, protocol) {
|
|
28
|
+
const entry = catalogueEntry(id);
|
|
29
|
+
if (entry === undefined)
|
|
30
|
+
return GATING_GROUP[protocol];
|
|
31
|
+
if (entry.protocol === "x402")
|
|
32
|
+
return Number(id.slice("X402-".length)) <= 5 ? "challenge" : "payment";
|
|
33
|
+
return GATING_GROUP[entry.protocol];
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* True when an x402 payment check (X402-06..11) was skipped as `unsupported`:
|
|
37
|
+
* the run asked to pay and Wasit cannot pay on that network. A read-only or
|
|
38
|
+
* no-payer skip is not this, and neither is a result of another protocol. An MPP
|
|
39
|
+
* endpoint has no group besides its gating one, so for it this is always false.
|
|
40
|
+
* Works on the results of a fresh run and on the structured results of a report.
|
|
41
|
+
*/
|
|
42
|
+
export function paymentGroupUnsupported(results, protocol) {
|
|
43
|
+
return protocol === "x402" && results.some((result) => result.skipKind === "unsupported" && checkGroup(result.id, protocol) === "payment");
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* The outcome of one endpoint from its results.
|
|
47
|
+
*
|
|
48
|
+
* - any FAIL: `non-conformant`. A real finding outranks a missing one.
|
|
49
|
+
* - else an `unsupported` skip in the endpoint's gating group (the challenge
|
|
50
|
+
* checks for x402): `unsupported`. X402-01 may have passed on an x402 v1
|
|
51
|
+
* service; one passing check does not grade a paywall Wasit cannot read. An
|
|
52
|
+
* `unsupported` payment group alone does not make the endpoint unsupported:
|
|
53
|
+
* the challenge was graded.
|
|
54
|
+
* - else an `unsupported` skip in the payment group (payment checks were asked
|
|
55
|
+
* for and none could be graded on this network): `no-verdict`, so it is not
|
|
56
|
+
* green (Najmi, 2026-11-15).
|
|
57
|
+
* - else any ERROR: `no-verdict`.
|
|
58
|
+
* - else at least one PASS: `conformant`.
|
|
59
|
+
* - else (nothing ran, or everything was skipped): `no-verdict`.
|
|
60
|
+
*/
|
|
61
|
+
export function endpointOutcome(results, protocol) {
|
|
62
|
+
const gating = GATING_GROUP[protocol];
|
|
63
|
+
let passed = 0;
|
|
64
|
+
let errored = 0;
|
|
65
|
+
let unsupported = false;
|
|
66
|
+
for (const result of results) {
|
|
67
|
+
const status = checkStatus(result);
|
|
68
|
+
if (status === "FAIL")
|
|
69
|
+
return "non-conformant";
|
|
70
|
+
if (status === "PASS")
|
|
71
|
+
passed += 1;
|
|
72
|
+
else if (status === "ERROR")
|
|
73
|
+
errored += 1;
|
|
74
|
+
else if (result.skipKind === "unsupported" && checkGroup(result.id, protocol) === gating)
|
|
75
|
+
unsupported = true;
|
|
76
|
+
}
|
|
77
|
+
if (unsupported)
|
|
78
|
+
return "unsupported";
|
|
79
|
+
// Payment checks were asked for and none could be graded here (a typo in the network, a chain
|
|
80
|
+
// with no adapter): the challenge was graded, but the run did not do what it was asked.
|
|
81
|
+
// Najmi, 2026-11-15: not green, exit 2, like 0.7.0.
|
|
82
|
+
if (paymentGroupUnsupported(results, protocol))
|
|
83
|
+
return "no-verdict";
|
|
84
|
+
if (errored > 0)
|
|
85
|
+
return "no-verdict";
|
|
86
|
+
return passed > 0 ? "conformant" : "no-verdict";
|
|
87
|
+
}
|
|
88
|
+
/** The key a protocol's payment group needs, for the words of a skip reason. */
|
|
89
|
+
const KEY_LABEL = {
|
|
90
|
+
x402: "a payer key",
|
|
91
|
+
"mpp-charge": "a payer key",
|
|
92
|
+
"mpp-channel": "a commitment key",
|
|
93
|
+
};
|
|
94
|
+
/** The checks of a protocol that pay or sign. MPP-13 closes a channel for good and is never listed. */
|
|
95
|
+
const PAYMENT_CHECK_IDS = {
|
|
96
|
+
x402: ["X402-06", "X402-07", "X402-08", "X402-09", "X402-10", "X402-11"],
|
|
97
|
+
"mpp-charge": ["MPP-01"],
|
|
98
|
+
"mpp-channel": ["MPP-10", "MPP-11", "MPP-12", "MPP-14"],
|
|
99
|
+
};
|
|
100
|
+
/**
|
|
101
|
+
* The checks of an endpoint that pay or sign, as SKIPs the report can count and
|
|
102
|
+
* name (spec A2: the report says which checks need a payer).
|
|
103
|
+
*
|
|
104
|
+
* `read-only`: the run was asked not to pay. `needs-payer`: the run could have
|
|
105
|
+
* paid and had no key. The names come from the catalogue, so a rename there is
|
|
106
|
+
* the only place to change.
|
|
107
|
+
*/
|
|
108
|
+
export function skippedPaymentChecks(protocol, kind) {
|
|
109
|
+
const key = KEY_LABEL[protocol];
|
|
110
|
+
const reason = kind === "read-only"
|
|
111
|
+
? `the read-only tier makes no payment and signs nothing; this check needs ${key} and the payment tier`
|
|
112
|
+
: `this check pays or signs and no ${key.replace(/^a /, "")} was given`;
|
|
113
|
+
return PAYMENT_CHECK_IDS[protocol].map((id) => skipped(id, catalogueEntry(id)?.name ?? id, reason, kind));
|
|
114
|
+
}
|
|
115
|
+
/**
|
|
116
|
+
* The same checks, skipped with a reason the caller words: the run asked to pay
|
|
117
|
+
* and a rule of the run stopped it (the GitHub event, `operatedByMe`, a key
|
|
118
|
+
* variable that is not set), or the front end does not run them.
|
|
119
|
+
*/
|
|
120
|
+
export function paymentChecksSkipped(protocol, kind, reason) {
|
|
121
|
+
return PAYMENT_CHECK_IDS[protocol].map((id) => skipped(id, catalogueEntry(id)?.name ?? id, reason, kind));
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* The exit code of one endpoint's checks (spec A8 #3, D-021): 1 on any FAIL; 2
|
|
125
|
+
* when the endpoint was not graded (`unsupported` or `no-verdict`) or a check
|
|
126
|
+
* could not run; else 0. Used where there is one endpoint, `wasit test` and the
|
|
127
|
+
* MCP x402 tool; a run of several endpoints uses {@link runExitCode}.
|
|
128
|
+
*/
|
|
129
|
+
export function exitCodeForEndpoint(results, protocol) {
|
|
130
|
+
const base = summarize([...results]).exitCode;
|
|
131
|
+
if (base !== 0)
|
|
132
|
+
return base;
|
|
133
|
+
const outcome = endpointOutcome(results, protocol);
|
|
134
|
+
return outcome === "unsupported" || outcome === "no-verdict" ? 2 : 0;
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* `toStructuredRun` with the outcome the exit rule gives: a service that was
|
|
138
|
+
* never graded is `no-verdict`, never `conformant`, for the MCP agent as for the
|
|
139
|
+
* shell. The counts are the same.
|
|
140
|
+
*/
|
|
141
|
+
export function toGradedRun(results, protocol) {
|
|
142
|
+
const run = toStructuredRun([...results]);
|
|
143
|
+
const code = exitCodeForEndpoint(results, protocol);
|
|
144
|
+
const outcome = code === 0 ? "conformant" : code === 1 ? "non-conformant" : "no-verdict";
|
|
145
|
+
return { ...run, outcome };
|
|
146
|
+
}
|
|
147
|
+
function reasonFor(results, protocol, outcome) {
|
|
148
|
+
if (outcome === "unsupported") {
|
|
149
|
+
const skip = results.find((result) => result.skipKind === "unsupported" && checkGroup(result.id, protocol) === GATING_GROUP[protocol]);
|
|
150
|
+
return skip?.skipReason === undefined ? undefined : sanitizeText(skip.skipReason);
|
|
151
|
+
}
|
|
152
|
+
if (outcome === "no-verdict") {
|
|
153
|
+
const error = results.find((result) => checkStatus(result) === "ERROR");
|
|
154
|
+
if (error !== undefined)
|
|
155
|
+
return sanitizeText(error.error?.message ?? "a check could not run");
|
|
156
|
+
const unsupportedPayment = results.find((result) => result.skipKind === "unsupported" && paymentGroupUnsupported([result], protocol));
|
|
157
|
+
if (unsupportedPayment?.skipReason !== undefined)
|
|
158
|
+
return sanitizeText(unsupportedPayment.skipReason);
|
|
159
|
+
// Skipped only because the run was asked not to pay: say so, not "nothing ran".
|
|
160
|
+
const readOnly = results.find((result) => result.skipKind === "read-only");
|
|
161
|
+
if (readOnly?.skipReason !== undefined)
|
|
162
|
+
return sanitizeText(readOnly.skipReason);
|
|
163
|
+
return "no check passed: every check was skipped or none ran";
|
|
164
|
+
}
|
|
165
|
+
return undefined;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Counts per group from any list of results that have an id and a status: the
|
|
169
|
+
* CheckResults of a fresh run, or the structured results of a report read back.
|
|
170
|
+
*/
|
|
171
|
+
export function groupCounts(results, protocol) {
|
|
172
|
+
const counts = new Map();
|
|
173
|
+
for (const result of results) {
|
|
174
|
+
const group = checkGroup(result.id, protocol);
|
|
175
|
+
const entry = counts.get(group) ?? { passed: 0, failed: 0, errored: 0, skipped: 0 };
|
|
176
|
+
if (result.status === "PASS")
|
|
177
|
+
entry.passed += 1;
|
|
178
|
+
else if (result.status === "FAIL")
|
|
179
|
+
entry.failed += 1;
|
|
180
|
+
else if (result.status === "ERROR")
|
|
181
|
+
entry.errored += 1;
|
|
182
|
+
else
|
|
183
|
+
entry.skipped += 1;
|
|
184
|
+
counts.set(group, entry);
|
|
185
|
+
}
|
|
186
|
+
return Object.fromEntries(counts);
|
|
187
|
+
}
|
|
188
|
+
/** Builds the report of one endpoint. Every text in it has passed through the sanitiser. */
|
|
189
|
+
export function buildEndpointReport(input) {
|
|
190
|
+
const outcome = endpointOutcome(input.results, input.protocol);
|
|
191
|
+
const reason = reasonFor(input.results, input.protocol, outcome);
|
|
192
|
+
return {
|
|
193
|
+
name: sanitizeText(input.name),
|
|
194
|
+
protocol: input.protocol,
|
|
195
|
+
method: sanitizeText(input.method),
|
|
196
|
+
path: sanitizeText(input.path),
|
|
197
|
+
outcome,
|
|
198
|
+
...(reason === undefined ? {} : { reason }),
|
|
199
|
+
groups: groupCounts(input.results.map((result) => ({ id: result.id, status: checkStatus(result) })), input.protocol),
|
|
200
|
+
results: toStructuredRun([...input.results]).results,
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
export function reportTotals(endpoints) {
|
|
204
|
+
const count = (outcome) => endpoints.filter((endpoint) => endpoint.outcome === outcome).length;
|
|
205
|
+
const conformant = count("conformant");
|
|
206
|
+
const nonConformant = count("non-conformant");
|
|
207
|
+
return {
|
|
208
|
+
endpoints: endpoints.length,
|
|
209
|
+
graded: conformant + nonConformant,
|
|
210
|
+
conformant,
|
|
211
|
+
nonConformant,
|
|
212
|
+
noVerdict: count("no-verdict"),
|
|
213
|
+
unsupported: count("unsupported"),
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* The summary line: "0 graded, 1 unsupported". Says how many endpoints were
|
|
218
|
+
* graded first, so a run in which nothing was cannot be read as a pass.
|
|
219
|
+
*/
|
|
220
|
+
export function describeTotals(totals) {
|
|
221
|
+
return [
|
|
222
|
+
`${totals.graded} graded${totals.nonConformant > 0 ? ` (${totals.nonConformant} non-conformant)` : ""}`,
|
|
223
|
+
...(totals.unsupported > 0 ? [`${totals.unsupported} unsupported`] : []),
|
|
224
|
+
...(totals.noVerdict > 0 ? [`${totals.noVerdict} no verdict`] : []),
|
|
225
|
+
].join(", ");
|
|
226
|
+
}
|
|
227
|
+
/** Builds the run report. Pure: the clock and the installed versions are inputs. */
|
|
228
|
+
export function buildRunReport(input) {
|
|
229
|
+
return {
|
|
230
|
+
schema: 1,
|
|
231
|
+
wasit: input.versions.wasit,
|
|
232
|
+
sdk: input.versions.sdk,
|
|
233
|
+
environment: sanitizeText(input.environment),
|
|
234
|
+
network: sanitizeText(input.network),
|
|
235
|
+
networkClass: networkClass(input.network),
|
|
236
|
+
startedAt: input.startedAt,
|
|
237
|
+
endpoints: input.endpoints,
|
|
238
|
+
totals: reportTotals(input.endpoints),
|
|
239
|
+
notes: (input.notes ?? []).map((note) => sanitizeText(note)),
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
/** The keys whose value is a short quote of what the service sent. */
|
|
243
|
+
const SHORT_VALUE_KEYS = new Set(["expected", "actual"]);
|
|
244
|
+
/** The longest `expected` or `actual` in an output. */
|
|
245
|
+
const SHORT_VALUE_MAX = 200;
|
|
246
|
+
function clipValue(text) {
|
|
247
|
+
const characters = Array.from(text);
|
|
248
|
+
return characters.length <= SHORT_VALUE_MAX ? text : `${characters.slice(0, SHORT_VALUE_MAX - 1).join("")}…`;
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Applies `change` to every string in a JSON-shaped value; numbers, booleans and
|
|
252
|
+
* null stay. The string under an `expected` or `actual` key is changed first and
|
|
253
|
+
* cut to {@link SHORT_VALUE_MAX} after: a cut made before the secrets are removed
|
|
254
|
+
* could leave the start of one in the output.
|
|
255
|
+
*/
|
|
256
|
+
function mapStrings(value, change) {
|
|
257
|
+
if (typeof value === "string")
|
|
258
|
+
return change(value);
|
|
259
|
+
if (Array.isArray(value))
|
|
260
|
+
return value.map((item) => mapStrings(item, change));
|
|
261
|
+
if (typeof value === "object" && value !== null) {
|
|
262
|
+
return Object.fromEntries(Object.entries(value).map(([key, item]) => [
|
|
263
|
+
key,
|
|
264
|
+
typeof item === "string" && SHORT_VALUE_KEYS.has(key) ? clipValue(change(item)) : mapStrings(item, change),
|
|
265
|
+
]));
|
|
266
|
+
}
|
|
267
|
+
return value;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* A copy of a JSON-shaped value with `secrets` removed from every string in it
|
|
271
|
+
* (and control characters, `::` lines and Stellar keys dealt with, as
|
|
272
|
+
* everywhere), and every `expected` and `actual` cut to a short length. The
|
|
273
|
+
* report is built from text a service sent, and a service can echo a header it
|
|
274
|
+
* was sent; this is the last pass before it is printed or written.
|
|
275
|
+
*/
|
|
276
|
+
export function redactValue(value, secrets) {
|
|
277
|
+
return mapStrings(value, (text) => sanitizeText(text, { redact: secrets }));
|
|
278
|
+
}
|
|
279
|
+
/** {@link redactValue} for a run report. */
|
|
280
|
+
export function redactReport(report, secrets) {
|
|
281
|
+
return redactValue(report, secrets);
|
|
282
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one sanitiser. Everything Wasit prints, writes into a report, or puts in
|
|
3
|
+
* a pull request comment or job summary passes through here when it can carry
|
|
4
|
+
* text a service chose.
|
|
5
|
+
*
|
|
6
|
+
* A service answers with whatever it likes, and a pull request can change what
|
|
7
|
+
* that is. Two sinks are dangerous:
|
|
8
|
+
*
|
|
9
|
+
* - a terminal or a CI job log: control characters move the cursor or hide
|
|
10
|
+
* text, and a line that starts with `::` is a workflow command to the
|
|
11
|
+
* GitHub runner (set an output, add a mask, stop all commands);
|
|
12
|
+
* - a Markdown comment: HTML, links, mentions and table syntax change what the
|
|
13
|
+
* reader sees and who gets notified.
|
|
14
|
+
*
|
|
15
|
+
* `sanitizeText` is the plain level for the first, `sanitizeForMarkdown` adds
|
|
16
|
+
* the second. Neither is a security boundary on its own against a renderer
|
|
17
|
+
* Wasit does not control; they make the common attacks inert and are tested
|
|
18
|
+
* against the CommonMark rules, not against GitHub's renderer.
|
|
19
|
+
*/
|
|
20
|
+
/** The longest a service-supplied value may be in a comment or summary. */
|
|
21
|
+
export declare const MARKDOWN_VALUE_MAX = 300;
|
|
22
|
+
export interface SanitizeOptions {
|
|
23
|
+
/**
|
|
24
|
+
* Values that must never appear in the output, such as the value of a
|
|
25
|
+
* `WASIT_HEADER_*` variable or a payer key. Matched as literals, after
|
|
26
|
+
* control characters are stripped, so a control character cannot hide one.
|
|
27
|
+
*/
|
|
28
|
+
readonly redact?: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
export interface MarkdownOptions extends SanitizeOptions {
|
|
31
|
+
/** Longest value, in characters, ellipsis included. Default {@link MARKDOWN_VALUE_MAX}. */
|
|
32
|
+
readonly maxLength?: number;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Plain level, for the terminal, the job log and report text.
|
|
36
|
+
*
|
|
37
|
+
* Strips control characters (keeping newline and tab), masks secrets, and
|
|
38
|
+
* breaks a `::` or `##[` at the start of a line by putting a space inside it.
|
|
39
|
+
* Idempotent. Newlines stay: this level does not reflow text.
|
|
40
|
+
*/
|
|
41
|
+
export declare function sanitizeText(input: string, options?: SanitizeOptions): string;
|
|
42
|
+
/**
|
|
43
|
+
* Markdown level, for a value placed in a pull request comment or job summary.
|
|
44
|
+
*
|
|
45
|
+
* Returns one line: the plain level first, then whitespace (newlines too)
|
|
46
|
+
* collapsed so the value cannot open a heading, list or table row; links,
|
|
47
|
+
* issue references and mentions removed; the value cut to `maxLength`
|
|
48
|
+
* characters (300 by default); then Markdown and HTML escaped. The cut comes
|
|
49
|
+
* before the escaping, so an escape or an entity is never split. Not
|
|
50
|
+
* idempotent: apply it once, to text that has only had the plain level.
|
|
51
|
+
*/
|
|
52
|
+
export declare function sanitizeForMarkdown(input: string, options?: MarkdownOptions): string;
|
package/dist/sanitize.js
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The one sanitiser. Everything Wasit prints, writes into a report, or puts in
|
|
3
|
+
* a pull request comment or job summary passes through here when it can carry
|
|
4
|
+
* text a service chose.
|
|
5
|
+
*
|
|
6
|
+
* A service answers with whatever it likes, and a pull request can change what
|
|
7
|
+
* that is. Two sinks are dangerous:
|
|
8
|
+
*
|
|
9
|
+
* - a terminal or a CI job log: control characters move the cursor or hide
|
|
10
|
+
* text, and a line that starts with `::` is a workflow command to the
|
|
11
|
+
* GitHub runner (set an output, add a mask, stop all commands);
|
|
12
|
+
* - a Markdown comment: HTML, links, mentions and table syntax change what the
|
|
13
|
+
* reader sees and who gets notified.
|
|
14
|
+
*
|
|
15
|
+
* `sanitizeText` is the plain level for the first, `sanitizeForMarkdown` adds
|
|
16
|
+
* the second. Neither is a security boundary on its own against a renderer
|
|
17
|
+
* Wasit does not control; they make the common attacks inert and are tested
|
|
18
|
+
* against the CommonMark rules, not against GitHub's renderer.
|
|
19
|
+
*/
|
|
20
|
+
/** The longest a service-supplied value may be in a comment or summary. */
|
|
21
|
+
export const MARKDOWN_VALUE_MAX = 300;
|
|
22
|
+
/** What replaces a secret, or a value that looks like one. */
|
|
23
|
+
const REDACTED = "[redacted]";
|
|
24
|
+
/** A redact entry shorter than this would blank ordinary words, and is not a secret. */
|
|
25
|
+
const MIN_REDACT_LENGTH = 4;
|
|
26
|
+
/**
|
|
27
|
+
* C0 controls except tab (U+0009) and newline (U+000A), DEL, C1 controls, and
|
|
28
|
+
* the bidirectional overrides that make text read in another order than it is
|
|
29
|
+
* stored. A carriage return is stripped too: .NET readers, the GitHub runner
|
|
30
|
+
* among them, split lines on it, so it could start a line of its own.
|
|
31
|
+
*/
|
|
32
|
+
const CONTROL_CHARACTERS = /[\u0000-\u0008\u000b-\u001f\u007f-\u009f--]/g;
|
|
33
|
+
/** The shape of a Stellar secret key. Public keys, contract ids and hashes do not match. */
|
|
34
|
+
const STELLAR_SECRET = /S[A-Z2-7]{55}/g;
|
|
35
|
+
/**
|
|
36
|
+
* A line the GitHub runner reads as a command: `::name::`, or the older
|
|
37
|
+
* `##[name]`. The runner trims leading whitespace first, and .NET counts more
|
|
38
|
+
* characters as whitespace than a space and a tab, so any whitespace but the
|
|
39
|
+
* line break is allowed before it.
|
|
40
|
+
*/
|
|
41
|
+
const LINE_START_COMMAND = /^([^\S\n]*)(::|##\[)/gm;
|
|
42
|
+
/**
|
|
43
|
+
* Plain level, for the terminal, the job log and report text.
|
|
44
|
+
*
|
|
45
|
+
* Strips control characters (keeping newline and tab), masks secrets, and
|
|
46
|
+
* breaks a `::` or `##[` at the start of a line by putting a space inside it.
|
|
47
|
+
* Idempotent. Newlines stay: this level does not reflow text.
|
|
48
|
+
*/
|
|
49
|
+
export function sanitizeText(input, options = {}) {
|
|
50
|
+
let text = String(input).replace(CONTROL_CHARACTERS, "");
|
|
51
|
+
const secrets = [...(options.redact ?? [])]
|
|
52
|
+
.filter((secret) => secret.length >= MIN_REDACT_LENGTH)
|
|
53
|
+
.sort((a, b) => b.length - a.length);
|
|
54
|
+
for (const secret of secrets)
|
|
55
|
+
text = text.split(secret).join(REDACTED);
|
|
56
|
+
return text
|
|
57
|
+
.replace(STELLAR_SECRET, REDACTED)
|
|
58
|
+
.replace(LINE_START_COMMAND, (_match, space, command) => space + (command === "::" ? ": :" : "# #["));
|
|
59
|
+
}
|
|
60
|
+
/** A link a Markdown renderer would make clickable: a scheme with an authority, `www.`, mailto and xmpp. */
|
|
61
|
+
const LINK = /\b[a-z][a-z0-9+.-]*:\/\/\S*|\b(?:www\.|mailto:|xmpp:)\S*/gi;
|
|
62
|
+
/** `#123` and `owner/repo#123`: GitHub turns both into links, the second one on another repository. */
|
|
63
|
+
const ISSUE_REFERENCE = /(?:[\w.-]+\/[\w.-]+)?#\d+/g;
|
|
64
|
+
/** An `@` that GitHub would read as the start of a mention. */
|
|
65
|
+
const MENTION = /@(?=[A-Za-z0-9_])/g;
|
|
66
|
+
const LINK_REMOVED = "[link removed]";
|
|
67
|
+
/** Cuts to `max` characters, counting code points, with an ellipsis in the last place. */
|
|
68
|
+
function truncate(text, max) {
|
|
69
|
+
const characters = Array.from(text);
|
|
70
|
+
if (characters.length <= max)
|
|
71
|
+
return text;
|
|
72
|
+
return `${characters.slice(0, Math.max(0, max - 1)).join("")}…`;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Backslash-escapes what could still format text inside a cell or a line, and
|
|
76
|
+
* HTML-escapes the rest. Newlines are already gone, so only the start of the
|
|
77
|
+
* string can open a heading, a list or a block quote.
|
|
78
|
+
*/
|
|
79
|
+
function escapeMarkdown(text) {
|
|
80
|
+
return text
|
|
81
|
+
.replace(/[\\`*_~[\]()|]/g, "\\$&")
|
|
82
|
+
.replace(/^([-+=#])/, "\\$1")
|
|
83
|
+
.replace(/^(\d+)\./, "$1\\.")
|
|
84
|
+
.replace(/&/g, "&")
|
|
85
|
+
.replace(/</g, "<")
|
|
86
|
+
.replace(/>/g, ">");
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Markdown level, for a value placed in a pull request comment or job summary.
|
|
90
|
+
*
|
|
91
|
+
* Returns one line: the plain level first, then whitespace (newlines too)
|
|
92
|
+
* collapsed so the value cannot open a heading, list or table row; links,
|
|
93
|
+
* issue references and mentions removed; the value cut to `maxLength`
|
|
94
|
+
* characters (300 by default); then Markdown and HTML escaped. The cut comes
|
|
95
|
+
* before the escaping, so an escape or an entity is never split. Not
|
|
96
|
+
* idempotent: apply it once, to text that has only had the plain level.
|
|
97
|
+
*/
|
|
98
|
+
export function sanitizeForMarkdown(input, options = {}) {
|
|
99
|
+
const max = Math.max(1, Math.floor(options.maxLength ?? MARKDOWN_VALUE_MAX));
|
|
100
|
+
const plain = sanitizeText(input, options).replace(/\s+/g, " ").trim();
|
|
101
|
+
const stripped = plain
|
|
102
|
+
.replace(LINK, LINK_REMOVED)
|
|
103
|
+
.replace(ISSUE_REFERENCE, LINK_REMOVED)
|
|
104
|
+
.replace(MENTION, "[at]");
|
|
105
|
+
return escapeMarkdown(truncate(stripped, max));
|
|
106
|
+
}
|
package/dist/settlement.d.ts
CHANGED
|
@@ -22,6 +22,20 @@ export interface TransferEvent {
|
|
|
22
22
|
readonly amount: bigint;
|
|
23
23
|
readonly contract: string;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* Reads the amount, and the destination's muxed id if any, from a `transfer`
|
|
27
|
+
* event's data.
|
|
28
|
+
*
|
|
29
|
+
* CAP-46 made the data a bare `i128` amount. CAP-67 keeps that when no muxed
|
|
30
|
+
* information is emitted, and otherwise makes it a map
|
|
31
|
+
* `{ amount: i128, to_muxed_id: u64 | bytes | string }`. Reading only the bare
|
|
32
|
+
* form would drop every payment to a muxed address, and report a settlement
|
|
33
|
+
* that happened as one that did not.
|
|
34
|
+
*/
|
|
35
|
+
export declare function readTransferData(data: xdr.ScVal): {
|
|
36
|
+
amount: bigint;
|
|
37
|
+
toMuxedId?: string;
|
|
38
|
+
} | undefined;
|
|
25
39
|
/**
|
|
26
40
|
* Extracts CAP-46 `transfer` events from a settled transaction.
|
|
27
41
|
*
|
package/dist/settlement.js
CHANGED
|
@@ -36,7 +36,7 @@ function asRecord(value) {
|
|
|
36
36
|
* form would drop every payment to a muxed address, and report a settlement
|
|
37
37
|
* that happened as one that did not.
|
|
38
38
|
*/
|
|
39
|
-
function readTransferData(data) {
|
|
39
|
+
export function readTransferData(data) {
|
|
40
40
|
const native = scValToNative(data);
|
|
41
41
|
if (typeof native === "bigint")
|
|
42
42
|
return { amount: native };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The exit code of a run of several endpoints (spec A2 with A8 #3, D-021).
|
|
3
|
+
*
|
|
4
|
+
* - 1: an endpoint is non-conformant, or an endpoint that was graded on the
|
|
5
|
+
* default branch is not graded now (the baseline says so). A service that
|
|
6
|
+
* drops below the standard of its chain must not be green.
|
|
7
|
+
* - 2: no verdict. Nothing could be graded, a check could not run, or payment
|
|
8
|
+
* checks were asked for and none could be graded on an endpoint's network. A
|
|
9
|
+
* service that was never graded is here: not green, and not labelled FAIL.
|
|
10
|
+
* - 0: at least one endpoint was graded, none failed, no check errored.
|
|
11
|
+
*
|
|
12
|
+
* The reason carries the counts ("0 graded, 1 unsupported"), so a green run
|
|
13
|
+
* cannot be read as a pass of something that was not graded.
|
|
14
|
+
*/
|
|
15
|
+
import { type Regression } from "./baseline.js";
|
|
16
|
+
import { type RunReport } from "./report.js";
|
|
17
|
+
export interface RunVerdict {
|
|
18
|
+
readonly code: 0 | 1 | 2;
|
|
19
|
+
/** One line, for the terminal, the job summary and the report notes. */
|
|
20
|
+
readonly reason: string;
|
|
21
|
+
/** Endpoints that were graded on the baseline and are not now. Empty without a baseline. */
|
|
22
|
+
readonly regressions: readonly Regression[];
|
|
23
|
+
}
|
|
24
|
+
export declare function runExitCode(report: RunReport, baseline?: RunReport): RunVerdict;
|
package/dist/verdict.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The exit code of a run of several endpoints (spec A2 with A8 #3, D-021).
|
|
3
|
+
*
|
|
4
|
+
* - 1: an endpoint is non-conformant, or an endpoint that was graded on the
|
|
5
|
+
* default branch is not graded now (the baseline says so). A service that
|
|
6
|
+
* drops below the standard of its chain must not be green.
|
|
7
|
+
* - 2: no verdict. Nothing could be graded, a check could not run, or payment
|
|
8
|
+
* checks were asked for and none could be graded on an endpoint's network. A
|
|
9
|
+
* service that was never graded is here: not green, and not labelled FAIL.
|
|
10
|
+
* - 0: at least one endpoint was graded, none failed, no check errored.
|
|
11
|
+
*
|
|
12
|
+
* The reason carries the counts ("0 graded, 1 unsupported"), so a green run
|
|
13
|
+
* cannot be read as a pass of something that was not graded.
|
|
14
|
+
*/
|
|
15
|
+
import { findRegressions } from "./baseline.js";
|
|
16
|
+
import { describeTotals, paymentGroupUnsupported } from "./report.js";
|
|
17
|
+
export function runExitCode(report, baseline) {
|
|
18
|
+
const regressions = baseline === undefined ? [] : findRegressions(report, baseline);
|
|
19
|
+
const counts = describeTotals(report.totals);
|
|
20
|
+
const errored = report.endpoints.reduce((total, endpoint) => total + endpoint.results.filter((result) => result.status === "ERROR").length, 0);
|
|
21
|
+
if (report.totals.nonConformant > 0) {
|
|
22
|
+
const n = report.totals.nonConformant;
|
|
23
|
+
return { code: 1, reason: `${n} endpoint${n === 1 ? " is" : "s are"} non-conformant (${counts})`, regressions };
|
|
24
|
+
}
|
|
25
|
+
if (regressions.length > 0) {
|
|
26
|
+
const list = regressions.map((item) => `${item.endpoint} (${item.was} on main, now ${item.now})`).join(", ");
|
|
27
|
+
return { code: 1, reason: `regression against main: ${list} (${counts})`, regressions };
|
|
28
|
+
}
|
|
29
|
+
if (report.totals.graded === 0) {
|
|
30
|
+
return { code: 2, reason: `nothing could be graded: ${counts}`, regressions };
|
|
31
|
+
}
|
|
32
|
+
if (errored > 0) {
|
|
33
|
+
return { code: 2, reason: `${errored} check${errored === 1 ? "" : "s"} could not run (${counts})`, regressions };
|
|
34
|
+
}
|
|
35
|
+
// Payment checks were asked for and none could be graded on an endpoint's network (Najmi, 2026-11-15).
|
|
36
|
+
const unsupportedPayment = report.endpoints.filter((endpoint) => paymentGroupUnsupported(endpoint.results, endpoint.protocol)).length;
|
|
37
|
+
if (unsupportedPayment > 0) {
|
|
38
|
+
return {
|
|
39
|
+
code: 2,
|
|
40
|
+
reason: `payment checks were asked for and could not be graded on ${unsupportedPayment} ` +
|
|
41
|
+
`endpoint${unsupportedPayment === 1 ? "" : "s"} (${counts})`,
|
|
42
|
+
regressions,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return { code: 0, reason: counts, regressions };
|
|
46
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
/**
|
|
13
|
+
* The installed version of `name`, found the way Node finds a dependency: in
|
|
14
|
+
* `node_modules` of `from` or of any directory above it.
|
|
15
|
+
*
|
|
16
|
+
* Returns "unknown" when the package is not there, its name does not match, or
|
|
17
|
+
* its version is not a version.
|
|
18
|
+
*/
|
|
19
|
+
export declare function readPackageVersion(name: string, from: string): string;
|
|
20
|
+
/** True for exactly seven lower-case hex characters: the only build text that reaches a comment. */
|
|
21
|
+
export declare function isShortCommit(value: unknown): value is string;
|
|
22
|
+
/**
|
|
23
|
+
* The commit this build of Wasit was made from, when the Action says so: the
|
|
24
|
+
* action ref (`WASIT_BUILD_COMMIT`) if it is a full commit id. A tag or a branch
|
|
25
|
+
* name is not a commit, and says nothing here: a pinned tag already names the
|
|
26
|
+
* version, and a result must not name a build it cannot show.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readBuildCommit(env: Readonly<Record<string, string | undefined>>): string | undefined;
|
|
29
|
+
export interface ToolVersions {
|
|
30
|
+
readonly wasit: {
|
|
31
|
+
readonly cli: string;
|
|
32
|
+
readonly core: string;
|
|
33
|
+
/** The first seven characters of the commit an Action build came from. Absent for an installed package. */
|
|
34
|
+
readonly build?: string;
|
|
35
|
+
};
|
|
36
|
+
readonly sdk: {
|
|
37
|
+
/** The x402 version Wasit grades. */
|
|
38
|
+
readonly x402Version: 2;
|
|
39
|
+
readonly "@x402/core": string;
|
|
40
|
+
readonly "@x402/stellar": string;
|
|
41
|
+
readonly "@stellar/mpp": string;
|
|
42
|
+
readonly mppx: string;
|
|
43
|
+
readonly "@stellar/stellar-sdk": string;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* The versions of this run. The CLI knows its own version (core cannot read the
|
|
48
|
+
* CLI's `package.json`), so it passes it in.
|
|
49
|
+
*/
|
|
50
|
+
export declare function readToolVersions(cliVersion?: string, build?: string): ToolVersions;
|