@wasit-dev/cli 0.8.0-beta.1 → 0.8.0-beta.3
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 +46 -11
- package/dist/exit.d.ts +42 -0
- package/dist/exit.js +51 -0
- package/dist/index.js +163 -90
- package/dist/init-command.d.ts +98 -0
- package/dist/init-command.js +850 -0
- package/dist/init-keys.d.ts +110 -0
- package/dist/init-keys.js +539 -0
- package/dist/run.d.ts +26 -5
- package/dist/run.js +565 -153
- package/dist/service.d.ts +7 -2
- package/dist/service.js +7 -2
- package/dist/style.d.ts +2 -1
- package/dist/style.js +12 -2
- package/dist/test-live.d.ts +26 -0
- package/dist/test-live.js +81 -0
- package/dist/wallet-command.js +18 -9
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -6,9 +6,9 @@ Protocol-compliance testing for **x402** and **MPP** on Stellar, from your termi
|
|
|
6
6
|
|
|
7
7
|
For both MPP charge payments and x402 payments it verifies the settlement independently — via Stellar RPC and the token contract's own on-chain transfer event, rather than the response the service returns.
|
|
8
8
|
|
|
9
|
-
**Testnet
|
|
9
|
+
**Testnet by default.** Several checks settle real transactions. The payment checks pay on test networks only: any other network, `stellar:pubnet` included, is refused before a key is read, but for `wasit run --mainnet` (beta, below). Do not use production keys: the mainnet opt-in takes a dedicated account only.
|
|
10
10
|
|
|
11
|
-
**This README describes 0.8.0-beta.
|
|
11
|
+
**This README describes 0.8.0-beta.3**, a pre-release on npm under the `beta` tag (`npm install -g @wasit-dev/cli@beta`). `latest` is still 0.7.0. New in 0.8.0-beta.3: fixes for what a fresh install pulled in (the address-bound Stellar credentials of `@stellar/stellar-sdk` 17, `@solana/kit` 8 and version 1 Solana transactions), the x402 libraries pinned to the versions the suites ran on, a clean exit on Windows, and `X402-10` on Stellar waiting on the chain (see the CHANGELOG). New in 0.8.0-beta.2: `wasit init`, which writes the config from one unpaid request to your route and can set up a testnet payer; MPP charge and channel checks in `wasit run`; the capped mainnet opt-in, `wasit run --mainnet` (beta, x402 only); and "resource consumed", the result for a single-use route. New in 0.8.0-beta.1: `wasit run` for a whole service from a `wasit.config.json`, `wasit ci-report`, the GitHub Action, a seventeenth check (`X402-11`), and a cap on every payment Wasit signs.
|
|
12
12
|
|
|
13
13
|
## Install
|
|
14
14
|
|
|
@@ -29,6 +29,14 @@ reads `.env` from the directory you run it in — so on a machine already set up
|
|
|
29
29
|
for a later suite, the first command in this README would settle a real testnet
|
|
30
30
|
payment.
|
|
31
31
|
|
|
32
|
+
### Windows
|
|
33
|
+
|
|
34
|
+
Tested on Windows 11 with Node 24 in PowerShell (2026-11-29, `0.8.0-beta.2`), for the read-only run (`wasit run --read-only --start`); no other Windows version has been run.
|
|
35
|
+
|
|
36
|
+
- PowerShell blocks `npm.ps1` and `npx.ps1` by default ("running scripts is disabled on this system"). Call the `.cmd` files instead: `npm.cmd install -g @wasit-dev/cli@beta`, `npx.cmd wasit --version`. Changing the policy (`Set-ExecutionPolicy -Scope CurrentUser RemoteSigned`) also works, and is your choice.
|
|
37
|
+
- Pressing Ctrl+C while `npx.cmd` runs `wasit` makes `cmd.exe` ask "Terminate batch job (Y/N)?" itself. To stop without that question, run Node on the CLI's file directly: `node .\node_modules\@wasit-dev\cli\dist\index.js run --start`.
|
|
38
|
+
- The GitHub Action runs on Linux runners only.
|
|
39
|
+
|
|
32
40
|
## Quick start
|
|
33
41
|
|
|
34
42
|
The default posture costs nothing — no keys required:
|
|
@@ -39,6 +47,13 @@ wasit test --target https://your-service.example.com/paid --read-only
|
|
|
39
47
|
|
|
40
48
|
That runs the read-only x402 checks (`X402-01`–`05`): whether the service issues a well-formed 402 challenge. Drop `--read-only` and set `STELLAR_PRIVATE_KEY` to also exercise the payment flow — `X402-06` settles a real testnet payment, and `X402-07`–`10` send payments the service must refuse.
|
|
41
49
|
|
|
50
|
+
For a whole service you operate, let Wasit write the config from one unpaid request to a route, then run the free checks:
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me # your service is running; init reads its 402
|
|
54
|
+
wasit run --read-only # what init prints as the next command for x402
|
|
55
|
+
```
|
|
56
|
+
|
|
42
57
|
## Commands
|
|
43
58
|
|
|
44
59
|
### `wasit test` — x402
|
|
@@ -52,7 +67,7 @@ wasit test --target <url> [options]
|
|
|
52
67
|
| `--target <url>` | required | Must include the scheme |
|
|
53
68
|
| `--network <id>` | `stellar:testnet` | Network the payment checks pay on: `stellar:testnet`, `eip155:84532` (Base Sepolia), `eip155:11155111` (Ethereum Sepolia) or `solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` (Solana devnet). Any other network is refused before a key is read. `X402-01`–`05` apply on any chain |
|
|
54
69
|
| `--payer-key <key>` | `STELLAR_PRIVATE_KEY`, `EVM_PRIVATE_KEY` on Base or Ethereum Sepolia, or `SVM_PRIVATE_KEY` on Solana devnet | A Stellar secret (`S...`), an EVM private key (`0x` + 64 hex), or a Solana keypair (base58 of its 64 bytes) |
|
|
55
|
-
| `--rpc-url <url>` | testnet default | Soroban RPC
|
|
70
|
+
| `--rpc-url <url>` | testnet default | Soroban RPC the payment is built through and `X402-06`'s settlement is read from; https only |
|
|
56
71
|
| `--method <verb>` | `GET` | HTTP method the paid endpoint uses |
|
|
57
72
|
| `--body <json>` | — | Request body; implies `Content-Type: application/json` |
|
|
58
73
|
| `--header <name:value>` | — | Extra request header, repeatable |
|
|
@@ -73,7 +88,7 @@ wasit mpp-charge --target <url> [options]
|
|
|
73
88
|
| `--network <id>` | `MPP_STELLAR_NETWORK` | CAIP-2. Only a challenge on this network is paid; `stellar:testnet` only, any other network is refused |
|
|
74
89
|
| `--rpc-url <url>` | testnet default | Used for the payment and the settlement read; https only |
|
|
75
90
|
|
|
76
|
-
**Every run settles a real payment.**
|
|
91
|
+
**Every run settles a real payment.** A settlement that never happened cannot be verified on-chain, so this command has no dry run. To see what a payment would be before anything is signed, use `wasit run --dry-run` (below): it prints the plan of an MPP charge endpoint from its unpaid challenge and signs nothing.
|
|
77
92
|
|
|
78
93
|
### `wasit mpp-channel` — MPP, channel mode
|
|
79
94
|
|
|
@@ -99,6 +114,21 @@ wasit mpp-channel --target <url> [options]
|
|
|
99
114
|
|
|
100
115
|
`--channel` **asserts**, it does not select: the channel under test is resolved from the target's own 402 challenge, so every check in a run reports on the same contract. When `--channel` differs from what the target advertises, `MPP-10` fails and inspects nothing.
|
|
101
116
|
|
|
117
|
+
### `wasit init`: write the config for one route (new in 0.8.0-beta.2)
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me
|
|
121
|
+
wasit init --url http://127.0.0.1:3000/api/chat --method POST --body-file body.json --operated-by-me --start "npm start"
|
|
122
|
+
wasit init --url http://127.0.0.1:3000/mpp/chat --operated-by-me --protocol mpp-charge
|
|
123
|
+
wasit init # at a terminal: asks for what you leave out
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Writes a `wasit.config.json` for one paid route of a service you operate. It sends the route one unpaid request (the method and body you give, and the `WASIT_HEADER_*` headers `wasit run` sends), follows at most one redirect inside the route's origin, and pays and signs nothing. The 402 tells x402 from MPP and gives the protocol, the network, the receiving address and asset (pinned), and for an MPP channel its contract. A route that answers 200, 500 or 503, or does not answer, writes nothing; `--no-read` writes the route from the flags alone, as x402.
|
|
127
|
+
|
|
128
|
+
Nothing is written without `--operated-by-me` (at a terminal, `init` asks): Wasit tests only services their operator runs. At a terminal `init` asks only for what the flags leave out; without one it asks nothing and names the missing flags (exit 2). An existing config is added to, never overwritten (`--force` replaces it), and a route it already has exactly as given is left as it is, so `init` can run again. It writes test networks only, never a header of the route (send a credential in a `WASIT_HEADER_<NAME>` variable), and never a key or a `WASIT_HEADER_*` value. A URL whose query has a parameter named like a credential (`api_key`, `token`, `sig`), given with `--url` or reached by the redirect, is refused, and nothing is written. After writing it prints what it read from your service, what you gave, what it filled in by default and what it did not read, then the next command: `wasit run --read-only` for x402, `wasit run --dry-run` for MPP, which has no read-only checks. Exit codes: `0` the config has the route (written now, or already there as given); `2` `init` refused and nothing was written.
|
|
129
|
+
|
|
130
|
+
**Key setup (Stellar testnet only)**, with `--setup-keys` or a yes at a terminal, after the config is written. First `init` checks that git will not commit `.env`: it must not be tracked and must be ignored, else `.env` is added to `.gitignore` (asked at a terminal) or no key is written. A key that is already set is kept and its account only read. Otherwise `init` makes a testnet key (`STELLAR_PRIVATE_KEY` for x402, `MPP_PAYER_SECRET` for MPP charge), appends it to `.env` without showing the secret, funds it with Friendbot, adds the USDC trustline and swaps 10 test XLM for test USDC on the public test exchange, then prints a status table; what it could not finish is in the table with the command that finishes it. An MPP channel gets no key: `COMMITMENT_SECRET_HEX` must be the key the channel was opened with. A variable set to nothing in your shell hides `.env` from `wasit run`, so `init` says so and writes no key. The key setup never changes the exit code.
|
|
131
|
+
|
|
102
132
|
### `wasit run`: a whole service from `wasit.config.json` (new in 0.8.0-beta.1)
|
|
103
133
|
|
|
104
134
|
```bash
|
|
@@ -109,17 +139,21 @@ wasit run --start # the payment tier, on a test network
|
|
|
109
139
|
|
|
110
140
|
`wasit.config.json` (version 1) holds a service's endpoints, methods, request bodies and environments. The loader is strict: an unknown key is an error, and secrets, the mainnet opt-in and per-payment caps have no place in it. `wasit run` runs every endpoint (`--env`, `--endpoint`) and writes one report (`--json`, `--out`); it can start the service itself (`--start`, `--start-if-local`) and compare with the report of the default branch (`--baseline`).
|
|
111
141
|
|
|
112
|
-
Without `--read-only` or `--dry-run` the run is the payment tier. It pays on test networks only, when the environment has `operatedByMe: true` and the chain's key variable is set: at most $1.00 a payment and $5.00 a run (`maxRunUsd` can only lower it), only to the `payTo` and asset the config pins. In GitHub Actions it pays only on a push to the default branch, a schedule and `workflow_dispatch`; a pull request runs the read-only checks. In another CI the payment tier is refused with exit 2: use `--read-only` there. `--mainnet` is
|
|
142
|
+
Without `--read-only` or `--dry-run` the run is the payment tier. It pays on test networks only, when the environment has `operatedByMe: true` and the chain's key variable is set: at most $1.00 a payment and $5.00 a run (`maxRunUsd` can only lower it), only to the `payTo` and asset the config pins. In GitHub Actions it pays only on a push to the default branch, a schedule and `workflow_dispatch`; a pull request runs the read-only checks. In another CI the payment tier is refused with exit 2: use `--read-only` there. On `stellar:pubnet` a paying run needs `--mainnet` (beta, x402 only, real USDC): it runs only when every rule of the mainnet opt-in holds, says `MAINNET RUN` in its first line, writes every signature to a run ledger before the key signs, and refuses a payer that holds less than the run needs to finish its checks (it says how much is missing), and ends by comparing the payer's balances with that ledger (consistent, explained by checks that FAILed, or inconsistent: exit 2); it does not read `.env`, so export `WASIT_MAINNET_PAYER_SECRET` in the shell; `wasit run --help` lists the rules. `wasit run --dry-run` on `stellar:pubnet` reads no key. A run that will pay checks its RPC before it starts the service, so an RPC that `service.start` itself starts is not up yet and the run stops with exit 2: start such an RPC before `wasit run`. `wasit run --help` lists every option.
|
|
113
143
|
|
|
114
144
|
For an endpoint with a `reject` case in the config, on Stellar, the payment tier also runs `X402-11`: a valid payment is sent with the request the service must refuse, and the chain is read until that payment's authorization has expired, up to six minutes.
|
|
115
145
|
|
|
146
|
+
**MPP in `wasit run` (new in 0.8.0-beta.2).** MPP endpoints run in the payment tier on `stellar:testnet` only, by the same rules as x402: `MPP-01` (charge) with `MPP_PAYER_SECRET`, planned from its unpaid challenge and held to the same caps, in the same budget as x402, and `MPP-10`, `11`, `12` and `14` (channel) with `COMMITMENT_SECRET_HEX`, with the channel and its expected terms from the config. With a channel in the config, commitments are signed for that channel only, and a route whose challenge names another gets none. The channel checks sign commitments off-chain and Wasit sends no transaction for them, so they are not charged to the cap. `MPP-13`, which closes a channel for good, is never run by `wasit run`. The network and the channel come from the config: `MPP_STELLAR_NETWORK` and `CHANNEL_CONTRACT` are not read. An MPP endpoint is sent a plain GET: one with a method, a body or headers is not sent anything. A mainnet run pays its x402 endpoints only.
|
|
147
|
+
|
|
148
|
+
**Single-use routes (new in 0.8.0-beta.2).** A route that can be bought once answers 409 where a new 402 was expected, after `X402-06`'s payment was served. `X402-07`, `09`, `10` and `11` need a new challenge to pay, so they are skipped as "resource consumed" (nothing is signed for them, and the route is not asked again); `X402-08`, the replay, needs none and still runs. A 409 before any payment of the run skips `X402-06` with that reason.
|
|
149
|
+
|
|
116
150
|
### `wasit ci-report`: the pull request comment and the job summary (new in 0.8.0-beta.1)
|
|
117
151
|
|
|
118
152
|
```bash
|
|
119
153
|
wasit ci-report --report wasit-report.json --comment comment.md
|
|
120
154
|
```
|
|
121
155
|
|
|
122
|
-
Turns the report of `wasit run --json --out` into the pull request comment and the job summary, compared with the default branch's report (`--baseline`). `--check-run <file>` also writes the title, summary and conclusion of a GitHub check run. The GitHub Action in the repository's `action/` directory runs `wasit run` and `wasit ci-report` in a workflow and comments on the pull request; pin it by full commit SHA.
|
|
156
|
+
Turns the report of `wasit run --json --out` into the pull request comment and the job summary, compared with the default branch's report (`--baseline`). `--check-run <file>` also writes the title, summary and conclusion of a GitHub check run. The Action also uses `--summary <file>` (the job summary; default `$GITHUB_STEP_SUMMARY`), `--baseline-out <file>` (the next baseline, for a run on the default branch), `--history <file>` (the newest completed run's baseline, for the recent-failures line) and `--baseline-run <id>`; `wasit ci-report --help` lists them. The GitHub Action in the repository's `action/` directory runs `wasit run` and `wasit ci-report` in a workflow and comments on the pull request; pin it by full commit SHA.
|
|
123
157
|
|
|
124
158
|
### `wasit checks` — the catalogue
|
|
125
159
|
|
|
@@ -141,7 +175,7 @@ Testnet-only helpers for the keys the subcommands above read from `.env`. `--net
|
|
|
141
175
|
|
|
142
176
|
`fund --asset usdc` opens the Circle testnet USDC trustline automatically, but **receiving a balance always needs one human step**: there is no scriptable USDC faucet for Stellar. Visit [faucet.circle.com](https://faucet.circle.com) once, or set `WASIT_USDC_DISTRIBUTOR_SECRET` to an account you funded that way and every later run sends from it automatically.
|
|
143
177
|
|
|
144
|
-
`create` prints a secret key to stdout — don't run it on a screen you're recording.
|
|
178
|
+
`create` prints a secret key to stdout — don't run it on a screen you're recording. `wasit init --setup-keys` needs none of this for a Stellar testnet route: it makes the key, writes it to `.env` without showing it and gets test USDC by a swap on the public test exchange (see `wasit init`).
|
|
145
179
|
|
|
146
180
|
### `wasit serve` — a paywall that misbehaves, for testing an agent that pays
|
|
147
181
|
|
|
@@ -196,17 +230,18 @@ A run with both a failure and an error exits `1` — a real finding outranks a m
|
|
|
196
230
|
|
|
197
231
|
| Env var | Used by |
|
|
198
232
|
|---|---|
|
|
199
|
-
| `STELLAR_PRIVATE_KEY` | `test` (x402 payment checks on Stellar) |
|
|
233
|
+
| `STELLAR_PRIVATE_KEY` | `test`, `run` (x402 payment checks on Stellar), `init --setup-keys` |
|
|
200
234
|
| `EVM_PRIVATE_KEY` | `test --network eip155:84532` or `eip155:11155111` (x402 payment checks on Base or Ethereum Sepolia) |
|
|
201
235
|
| `SVM_PRIVATE_KEY` | `test --network solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` (x402 payment checks on Solana devnet) |
|
|
202
|
-
| `MPP_PAYER_SECRET` | `mpp-charge` |
|
|
236
|
+
| `MPP_PAYER_SECRET` | `mpp-charge`, `run` (MPP charge), `init --setup-keys` |
|
|
203
237
|
| `MPP_STELLAR_NETWORK` | `mpp-charge`, `mpp-channel` |
|
|
204
|
-
| `COMMITMENT_SECRET_HEX` | `mpp-channel` |
|
|
238
|
+
| `COMMITMENT_SECRET_HEX` | `mpp-channel`, `run` (MPP channel) |
|
|
205
239
|
| `CHANNEL_CONTRACT` | `mpp-channel` (optional assertion) |
|
|
206
240
|
| `CHANNEL_CONTRACT_DISPOSABLE` | `mpp-channel --allow-destructive` |
|
|
207
241
|
| `WASIT_USDC_DISTRIBUTOR_SECRET` | `wallet fund --asset usdc` (optional) |
|
|
242
|
+
| `WASIT_MAINNET_PAYER_SECRET` | `run --mainnet` only (beta): a dedicated account's secret, exported in the shell, never in `.env` |
|
|
208
243
|
|
|
209
|
-
All keys are **testnet only
|
|
244
|
+
All keys are **testnet only**, except `WASIT_MAINNET_PAYER_SECRET`, which `wasit run --mainnet` reads from the shell alone (a dedicated account; see `wasit run`). `wasit` also reads a `.env` file in the current working directory — pass `--payer-key` / `--commitment-key` directly to override it for a single run. `wasit run` does not read `.env` in CI, nor with `--mainnet`.
|
|
210
245
|
|
|
211
246
|
## What's checked
|
|
212
247
|
|
package/dist/exit.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a command ends once its work is done and its output is written.
|
|
3
|
+
*
|
|
4
|
+
* On Linux and macOS: `process.exit(code)`, as always.
|
|
5
|
+
*
|
|
6
|
+
* On Windows, `process.exit()` called right after a network request can abort
|
|
7
|
+
* Node with a libuv assertion (`!(handle->flags & UV_HANDLE_CLOSING)`,
|
|
8
|
+
* `src\win\async.c`, line 76): the results are printed, then the process dies
|
|
9
|
+
* with exit code 0xC0000409 (-1073740791) instead of the one the command chose,
|
|
10
|
+
* which a script or CI step reads as a crash. Shown on Windows 11 26H2 with
|
|
11
|
+
* Node 24.14.1 (2026-11-29) with plain Node, no Wasit: `fetch` to an RPC, then
|
|
12
|
+
* `process.exit(2)` at once, aborted; the same with `process.exitCode = 2` and
|
|
13
|
+
* no exit call, or with the exit 2 s later, ended with 2. Every Wasit command
|
|
14
|
+
* that reads a chain, a faucet or an RPC ended that way.
|
|
15
|
+
*
|
|
16
|
+
* So on Windows the code is set and the event loop is let drain: pending work
|
|
17
|
+
* (a DNS lookup, a socket closing) finishes first, and Node then exits with the
|
|
18
|
+
* code. A timer that does not keep the process alive ends, after the grace
|
|
19
|
+
* period, a process that something else holds open (and there the abort can
|
|
20
|
+
* still happen).
|
|
21
|
+
*
|
|
22
|
+
* Not covered: the exits before any network work (bad arguments, a missing
|
|
23
|
+
* key), which keep `process.exit`; and the exits on a signal (Ctrl+C during a
|
|
24
|
+
* run, in service.ts, and in `wasit serve`), which stop at once on purpose, so
|
|
25
|
+
* on Windows a Ctrl+C while a request is in flight may still abort.
|
|
26
|
+
*/
|
|
27
|
+
/** How long a Windows process may stay open after its command finished. */
|
|
28
|
+
export declare const WINDOWS_EXIT_GRACE_MS = 10000;
|
|
29
|
+
export interface FinishDeps {
|
|
30
|
+
readonly platform: NodeJS.Platform;
|
|
31
|
+
readonly exit: (code: number) => void;
|
|
32
|
+
readonly setExitCode: (code: number) => void;
|
|
33
|
+
readonly setTimer: (callback: () => void, ms: number) => {
|
|
34
|
+
unref(): unknown;
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Ends the command with `code`. On Windows it returns at once and the process
|
|
39
|
+
* ends when the event loop is empty, so the caller must return right after it
|
|
40
|
+
* and run nothing else.
|
|
41
|
+
*/
|
|
42
|
+
export declare function finish(code: number, deps?: FinishDeps): void;
|
package/dist/exit.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How a command ends once its work is done and its output is written.
|
|
3
|
+
*
|
|
4
|
+
* On Linux and macOS: `process.exit(code)`, as always.
|
|
5
|
+
*
|
|
6
|
+
* On Windows, `process.exit()` called right after a network request can abort
|
|
7
|
+
* Node with a libuv assertion (`!(handle->flags & UV_HANDLE_CLOSING)`,
|
|
8
|
+
* `src\win\async.c`, line 76): the results are printed, then the process dies
|
|
9
|
+
* with exit code 0xC0000409 (-1073740791) instead of the one the command chose,
|
|
10
|
+
* which a script or CI step reads as a crash. Shown on Windows 11 26H2 with
|
|
11
|
+
* Node 24.14.1 (2026-11-29) with plain Node, no Wasit: `fetch` to an RPC, then
|
|
12
|
+
* `process.exit(2)` at once, aborted; the same with `process.exitCode = 2` and
|
|
13
|
+
* no exit call, or with the exit 2 s later, ended with 2. Every Wasit command
|
|
14
|
+
* that reads a chain, a faucet or an RPC ended that way.
|
|
15
|
+
*
|
|
16
|
+
* So on Windows the code is set and the event loop is let drain: pending work
|
|
17
|
+
* (a DNS lookup, a socket closing) finishes first, and Node then exits with the
|
|
18
|
+
* code. A timer that does not keep the process alive ends, after the grace
|
|
19
|
+
* period, a process that something else holds open (and there the abort can
|
|
20
|
+
* still happen).
|
|
21
|
+
*
|
|
22
|
+
* Not covered: the exits before any network work (bad arguments, a missing
|
|
23
|
+
* key), which keep `process.exit`; and the exits on a signal (Ctrl+C during a
|
|
24
|
+
* run, in service.ts, and in `wasit serve`), which stop at once on purpose, so
|
|
25
|
+
* on Windows a Ctrl+C while a request is in flight may still abort.
|
|
26
|
+
*/
|
|
27
|
+
/** How long a Windows process may stay open after its command finished. */
|
|
28
|
+
export const WINDOWS_EXIT_GRACE_MS = 10_000;
|
|
29
|
+
const PROCESS = {
|
|
30
|
+
get platform() {
|
|
31
|
+
return process.platform;
|
|
32
|
+
},
|
|
33
|
+
exit: (code) => process.exit(code),
|
|
34
|
+
setExitCode: (code) => {
|
|
35
|
+
process.exitCode = code;
|
|
36
|
+
},
|
|
37
|
+
setTimer: (callback, ms) => setTimeout(callback, ms),
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Ends the command with `code`. On Windows it returns at once and the process
|
|
41
|
+
* ends when the event loop is empty, so the caller must return right after it
|
|
42
|
+
* and run nothing else.
|
|
43
|
+
*/
|
|
44
|
+
export function finish(code, deps = PROCESS) {
|
|
45
|
+
if (deps.platform !== "win32") {
|
|
46
|
+
deps.exit(code);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
deps.setExitCode(code);
|
|
50
|
+
deps.setTimer(() => deps.exit(code), WINDOWS_EXIT_GRACE_MS).unref();
|
|
51
|
+
}
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,14 @@ import { CLI_VERSION } from "./version.js";
|
|
|
8
8
|
import { registerWalletCommand } from "./wallet-command.js";
|
|
9
9
|
import { DEFAULT_SERVE_NETWORK, MODE_DESCRIPTIONS, SERVE_MODES, SERVE_NETWORKS, createServeServer, validateServeOptions, } from "./serve.js";
|
|
10
10
|
import { executeCiReport } from "./ci-report-command.js";
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { colorDepth, colorEnabled, lineWidth,
|
|
11
|
+
import { note, report } from "./output.js";
|
|
12
|
+
import { liveX402Test } from "./test-live.js";
|
|
13
|
+
import { colorDepth, colorEnabled, lineWidth, styler } from "./style.js";
|
|
14
|
+
import { finish } from "./exit.js";
|
|
14
15
|
import { executeRun } from "./run.js";
|
|
15
|
-
import {
|
|
16
|
+
import { DEFAULT_CONFIG_FILE, executeInit } from "./init-command.js";
|
|
17
|
+
import { LIVE_KEY_SETUP } from "./init-keys.js";
|
|
18
|
+
import { CHECK_CATALOGUE, PROTOCOL_IDS, deniedEnvValues, paymentChainFor, runMppChannelSuite, runMppChargeSuite, runX402PaymentChecks, runX402ReadChecks, sanitizeText, } from "@wasit-dev/core";
|
|
16
19
|
const require = createRequire(import.meta.url);
|
|
17
20
|
/**
|
|
18
21
|
* Loads `.env` from the working directory exactly as `import "dotenv/config"`
|
|
@@ -58,6 +61,7 @@ program
|
|
|
58
61
|
.addHelpText("after", `
|
|
59
62
|
Examples:
|
|
60
63
|
$ wasit checks
|
|
64
|
+
$ wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me
|
|
61
65
|
$ wasit test --target https://api.example.com/paid-endpoint --read-only
|
|
62
66
|
$ wasit mpp-charge --target https://api.example.com/paid-endpoint --payer-key S...
|
|
63
67
|
$ wasit mpp-channel --target https://api.example.com/paid-endpoint
|
|
@@ -68,20 +72,22 @@ Run "wasit <command> --help" for that command's own options and cost notes.
|
|
|
68
72
|
Add --json to test/mpp-charge/mpp-channel for machine-readable output.
|
|
69
73
|
Full check catalogue (every check ID, spec reference, pass criteria):
|
|
70
74
|
https://github.com/wasit-dev/wasit/blob/main/docs/CHECKS.md`);
|
|
71
|
-
// `.env` is loaded before a command's action, as it always was, with
|
|
72
|
-
// exceptions (spec A8 #2, A-A01): `wasit run` does not load it in CI, where
|
|
73
|
-
// working directory is a checked-out pull request and a `.env` it added
|
|
74
|
-
// steer the run;
|
|
75
|
-
//
|
|
75
|
+
// `.env` is loaded before a command's action, as it always was, with three
|
|
76
|
+
// exceptions (spec A8 #2, A-A01, B5): `wasit run` does not load it in CI, where
|
|
77
|
+
// the working directory is a checked-out pull request and a `.env` it added
|
|
78
|
+
// could steer the run; nor with --mainnet, whose key comes from the shell's
|
|
79
|
+
// WASIT_MAINNET_PAYER_SECRET only, never from a file in the service's folder
|
|
80
|
+
// that an agent could read; `wasit ci-report` never does, it has no use for it.
|
|
81
|
+
// CI is read from the real environment, before any `.env` could change it.
|
|
76
82
|
program.hook("preAction", (_program, action) => {
|
|
77
83
|
const name = action.name();
|
|
78
84
|
if (name === "ci-report")
|
|
79
85
|
return;
|
|
80
|
-
if (name === "run" && inCi(process.env))
|
|
86
|
+
if (name === "run" && (inCi(process.env) || action.opts()["mainnet"] === true))
|
|
81
87
|
return;
|
|
82
88
|
loadDotenv();
|
|
83
89
|
});
|
|
84
|
-
/** Waits until what was written to stdout and stderr has been handed to the system, so
|
|
90
|
+
/** Waits until what was written to stdout and stderr has been handed to the system, so the exit (see `finish`) cannot cut a long report. */
|
|
85
91
|
async function flushOutput() {
|
|
86
92
|
await Promise.all([process.stdout, process.stderr].map((stream) => new Promise((resolve) => stream.write("", () => resolve()))));
|
|
87
93
|
}
|
|
@@ -176,7 +182,8 @@ or NO_COLOR gives the plain text; FORCE_COLOR=1 colours a pipe.`)
|
|
|
176
182
|
// A person at a terminal gets the coloured, live output; a pipe, CI, NO_COLOR
|
|
177
183
|
// and --json get the plain text below, unchanged.
|
|
178
184
|
if (!jsonMode && colorEnabled(process.stdout, process.env)) {
|
|
179
|
-
|
|
185
|
+
finish(await liveX402Test(opts, shape, { stream: process.stdout, env: process.env }));
|
|
186
|
+
return;
|
|
180
187
|
}
|
|
181
188
|
const results = await runX402ReadChecks({ target: opts.target, ...shape });
|
|
182
189
|
// Each chain reads its own payer key: a Stellar secret is no use on EVM.
|
|
@@ -200,7 +207,7 @@ or NO_COLOR gives the plain text; FORCE_COLOR=1 colours a pipe.`)
|
|
|
200
207
|
})));
|
|
201
208
|
}
|
|
202
209
|
// One endpoint: a service Wasit could not grade exits 2, not 0 (spec A8 #3).
|
|
203
|
-
|
|
210
|
+
finish(report(results, jsonMode, { protocol: "x402" }));
|
|
204
211
|
});
|
|
205
212
|
program
|
|
206
213
|
.command("run")
|
|
@@ -210,7 +217,8 @@ program
|
|
|
210
217
|
.option("--endpoint <name>", "Run only this endpoint, by name. Repeatable.", (value, previous) => [...previous, value], [])
|
|
211
218
|
.option("--read-only", "Run the unpaid challenge checks (X402-01..05) only. They send no payment and sign nothing. Without it (and without --dry-run) the run is the payment tier.", false)
|
|
212
219
|
.option("--dry-run", "Print what the payment checks would sign: per endpoint the payee, the asset, the amount of each signature and the worst case, " +
|
|
213
|
-
"against the caps ($1 a payment, $5 a run, lower with maxRunUsd). Reads each x402 endpoint's unpaid challenge
|
|
220
|
+
"against the caps ($1 a payment, $5 a run, lower with maxRunUsd). Reads each x402 endpoint's unpaid challenge, and " +
|
|
221
|
+
"on stellar:testnet each MPP charge endpoint's; " +
|
|
214
222
|
"uses no key, sends no payment, signs nothing. Exit 2 when a paying run would be refused. Not with --read-only.", false)
|
|
215
223
|
.option("--json", "Print the report as JSON instead of text", false)
|
|
216
224
|
.option("--out <file>", "Write the JSON report to this file as well")
|
|
@@ -218,8 +226,17 @@ program
|
|
|
218
226
|
"The service does not receive Wasit's key variables, header variables or WASIT_RPC_URL.", false)
|
|
219
227
|
.option("--start-if-local", "Like --start, but only when service.start is set and the environment is on this machine (localhost, 127.x.x.x or [::1]); " +
|
|
220
228
|
"otherwise the configured baseUrl is read as it is, which is how a deployed endpoint is checked. Not with --start.", false)
|
|
221
|
-
.option("--baseline <file>", "The report of the default branch: an endpoint graded there that is unsupported or without a verdict now is a regression (exit 1)"
|
|
222
|
-
|
|
229
|
+
.option("--baseline <file>", "The report of the default branch: an endpoint graded there that is unsupported or without a verdict now is a regression (exit 1), " +
|
|
230
|
+
"unless this run's tier skipped every check of it (an MPP endpoint on a pull request, or a run without its key)")
|
|
231
|
+
.option("--mainnet", "Pay real USDC on stellar:pubnet (x402 only). Runs only when every rule holds: the environment is on stellar:pubnet with " +
|
|
232
|
+
"operatedByMe true and pinned payTo and asset (mainnet USDC); the key is in WASIT_MAINNET_PAYER_SECRET and in no other " +
|
|
233
|
+
"variable; an https RPC for stellar:pubnet is set (rpcUrl or WASIT_RPC_URL); the payer holds at most $10.00 of USDC; " +
|
|
234
|
+
"no other mainnet run holds the lock; in GitHub Actions, the run is started by hand on the default branch on a " +
|
|
235
|
+
"GitHub-hosted runner, tests a deployed service and has no other key variable set. Otherwise exit 2 before anything " +
|
|
236
|
+
"is started, sent or signed. With --mainnet, wasit run does not read .env: the variables come from the shell. " +
|
|
237
|
+
"Not with --read-only.", false)
|
|
238
|
+
.option("--ledger-dir <dir>", "With --mainnet: the folder of the run ledger (wasit-ledger-<UTC time>.json, every signature written before the key " +
|
|
239
|
+
"signs) and of the lock that keeps a second mainnet run from starting beside it. Default: the working directory.")
|
|
223
240
|
.addHelpText("after", `
|
|
224
241
|
Examples:
|
|
225
242
|
$ wasit run --read-only
|
|
@@ -228,13 +245,25 @@ Examples:
|
|
|
228
245
|
$ wasit run --read-only --start-if-local --env mainnet
|
|
229
246
|
$ wasit run --dry-run --start
|
|
230
247
|
$ wasit run --start (payment tier: STELLAR_PRIVATE_KEY on stellar:testnet)
|
|
248
|
+
$ wasit run --start (MPP: MPP_PAYER_SECRET, COMMITMENT_SECRET_HEX on stellar:testnet)
|
|
249
|
+
$ wasit run --dry-run --env mainnet (the plan on stellar:pubnet: no key is read)
|
|
250
|
+
$ wasit run --mainnet --env mainnet (real funds: WASIT_MAINNET_PAYER_SECRET on stellar:pubnet)
|
|
231
251
|
|
|
232
252
|
Exit codes: 0 every graded endpoint conforms; 1 an endpoint does not conform, or one
|
|
233
253
|
graded on the baseline is not graded now; 2 no verdict (nothing could be graded, a
|
|
234
254
|
check could not run, the config or the service could not be used, or the payment
|
|
235
255
|
tier was asked for and did not pay: no payer key, or operatedByMe not true).
|
|
236
|
-
The payment tier pays on test networks
|
|
256
|
+
The payment tier pays on test networks: at most $1.00 a payment and $5.00 a run
|
|
237
257
|
(lower with maxRunUsd), only the pinned payTo and asset when the config pins them.
|
|
258
|
+
On stellar:pubnet it pays only with --mainnet: the first line says MAINNET RUN; the
|
|
259
|
+
plan reads the payer's balances on the RPC and public Horizon first, and refuses a
|
|
260
|
+
payer holding less than the run needs to finish its checks (the prices plus the
|
|
261
|
+
highest price again; a warning below the worst case); every signature
|
|
262
|
+
is in the run ledger; one refusal stops the whole run (exit 2); at the end the run
|
|
263
|
+
waits until every authorization it signed has expired (up to about five minutes),
|
|
264
|
+
reads the payer's balances again and says whether they match the ledger: consistent;
|
|
265
|
+
explained (more USDC left than the run verified settled, within the payments of
|
|
266
|
+
checks that FAILed: exit 1, by the checks); or inconsistent (exit 2).
|
|
238
267
|
In GitHub Actions it pays only on push to the default branch, schedule and
|
|
239
268
|
workflow_dispatch; a pull request runs the read-only checks, and a payer key set on
|
|
240
269
|
a run that may not pay is refused before the service starts. In another CI (CI set,
|
|
@@ -244,6 +273,15 @@ X402-11 runs for an endpoint with a reject case, on Stellar: it sends a valid pa
|
|
|
244
273
|
with the request the service must refuse, then reads the chain until that payment's
|
|
245
274
|
authorization has expired, up to six minutes; a lifetime above 300 s or below 30 s is
|
|
246
275
|
not signed, and an authorization signed to outlive 300 s is not sent.
|
|
276
|
+
MPP endpoints are paid in the payment tier on stellar:testnet only, by the same rules:
|
|
277
|
+
MPP-01 (charge) with MPP_PAYER_SECRET, planned from its unpaid challenge and held to the
|
|
278
|
+
same caps, in the same budget as x402; MPP-10, 11, 12 and 14 (channel) with
|
|
279
|
+
COMMITMENT_SECRET_HEX, with the channel and its expected terms from the config: with a
|
|
280
|
+
channel in the config, commitments are signed for it only, and a route whose challenge
|
|
281
|
+
names another gets none. MPP-13 (close) is never run by wasit run. The network and the
|
|
282
|
+
channel come from the config: MPP_STELLAR_NETWORK and CHANNEL_CONTRACT are not read. An
|
|
283
|
+
MPP endpoint is sent a plain GET: one with a method, a body or headers is not sent
|
|
284
|
+
anything. A mainnet run pays its x402 endpoints only.
|
|
247
285
|
In CI (CI or GITHUB_ACTIONS set) a .env file in the working directory is not read.`)
|
|
248
286
|
.exitOverride(exitTwoOnUsageError)
|
|
249
287
|
.action(async (opts) => {
|
|
@@ -261,6 +299,7 @@ In CI (CI or GITHUB_ACTIONS set) a .env file in the working directory is not rea
|
|
|
261
299
|
startIfLocal: opts.startIfLocal === true,
|
|
262
300
|
...(opts.baseline === undefined ? {} : { baseline: opts.baseline }),
|
|
263
301
|
mainnet: opts.mainnet === true,
|
|
302
|
+
...(opts.ledgerDir === undefined ? {} : { ledgerDir: opts.ledgerDir }),
|
|
264
303
|
}, { env: process.env, stdout: (line) => console.log(line), stderr: (line) => console.error(line) });
|
|
265
304
|
}
|
|
266
305
|
catch (error) {
|
|
@@ -269,7 +308,110 @@ In CI (CI or GITHUB_ACTIONS set) a .env file in the working directory is not rea
|
|
|
269
308
|
code = 2;
|
|
270
309
|
}
|
|
271
310
|
await flushOutput();
|
|
272
|
-
|
|
311
|
+
finish(code);
|
|
312
|
+
});
|
|
313
|
+
program
|
|
314
|
+
.command("init")
|
|
315
|
+
.description("Write a wasit.config.json for one paid route of a service you operate, from one unpaid request to the route")
|
|
316
|
+
.option("--url <url>", "The URL of one paid route, e.g. http://127.0.0.1:3000/api/weather (at a terminal, init asks for what you leave out)")
|
|
317
|
+
.option("--operated-by-me", "Confirm that you operate the service. Wasit tests only services their operator runs: without it nothing is written", false)
|
|
318
|
+
.option("--name <name>", "The endpoint's name (default: the last part of the path)")
|
|
319
|
+
.option("--method <method>", "The route's HTTP method (default: GET)")
|
|
320
|
+
.option("--body-file <file>", "A JSON file with the request body, written into the config as a JSON value (not with GET)")
|
|
321
|
+
.option("--network <id>", "Choose this test network (CAIP-2) among the ones the route offers; with --no-read, the network written (default: stellar:testnet)")
|
|
322
|
+
.option("--protocol <name>", "Choose this protocol among the ones the route offers: x402, mpp-charge or mpp-channel")
|
|
323
|
+
.option("--no-read", "Do not ask the route anything: write it as x402 from the flags alone")
|
|
324
|
+
.option("--env <name>", "The environment's name (default: local, for a URL on this machine)")
|
|
325
|
+
.option("--start <command>", "The command that starts the service, for wasit run --start")
|
|
326
|
+
.option("--ready-url <url>", "With --start: the address on this machine to wait for (default: the route's URL, on this machine)")
|
|
327
|
+
.option("--ready-timeout <seconds>", "With --start: how long to wait, 1 to 600 (default: 60)")
|
|
328
|
+
.option("--reject-header <header>", 'A header of the request the route must refuse (X402-11), as "Name: value". Repeatable.', (value, previous) => [...previous, value], [])
|
|
329
|
+
.option("--reject-body-file <file>", "A JSON file with the body of the request the route must refuse (X402-11)")
|
|
330
|
+
.option("--reject-note <text>", "One line on why the route must refuse that request")
|
|
331
|
+
.option("--config <path>", "The config file", DEFAULT_CONFIG_FILE)
|
|
332
|
+
.option("--force", "Replace the config file instead of adding the endpoint to it", false)
|
|
333
|
+
.option("--setup-keys", "Stellar testnet: set up the key the route's payment checks read, in .env (also adds .env to .gitignore when git does not ignore it)")
|
|
334
|
+
.option("--no-setup-keys", "Do not set up a key, and do not ask")
|
|
335
|
+
.addHelpText("after", `
|
|
336
|
+
Examples:
|
|
337
|
+
$ wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me
|
|
338
|
+
$ wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me --setup-keys
|
|
339
|
+
$ wasit init --url http://127.0.0.1:3000/api/chat --method POST --body-file body.json --operated-by-me --start "npm start"
|
|
340
|
+
$ wasit init --url http://127.0.0.1:3000/mpp/chat --operated-by-me --protocol mpp-charge
|
|
341
|
+
|
|
342
|
+
init sends the route one unpaid request (its method and body, and the
|
|
343
|
+
WASIT_HEADER_* headers wasit run sends), follows at most one redirect inside its
|
|
344
|
+
origin, and pays and signs nothing. Its 402 tells x402 from MPP and gives the
|
|
345
|
+
protocol, the network, the receiving address and asset (pinned) and an MPP
|
|
346
|
+
channel. A route that answers 200, 500 or 503, or does not answer, writes
|
|
347
|
+
nothing: --no-read writes it from the flags alone, as x402.
|
|
348
|
+
An existing config is added to (one more endpoint), never overwritten: --force
|
|
349
|
+
replaces it. A route the config already has exactly as given, in the same
|
|
350
|
+
environment, is left as it is, so init can run again (to set up its key, say).
|
|
351
|
+
Mainnet is not written in this version, and neither is a header of
|
|
352
|
+
the route: send a credential in a WASIT_HEADER_<NAME> variable. A URL whose query
|
|
353
|
+
has a parameter named like a credential (api_key, token, sig), given with --url or
|
|
354
|
+
reached by the redirect, is refused. After writing, init prints what it read from
|
|
355
|
+
your service, what you gave, what it filled in by default and what it did not read,
|
|
356
|
+
then the next command.
|
|
357
|
+
|
|
358
|
+
Key setup (Stellar testnet only; --setup-keys, or a yes at a terminal), after
|
|
359
|
+
the config is written: first it checks that git will not commit .env (not
|
|
360
|
+
tracked, and ignored: else .env is added to .gitignore, or no key is written).
|
|
361
|
+
A key already set is kept and its account only read. Otherwise init makes a
|
|
362
|
+
testnet key (x402: STELLAR_PRIVATE_KEY; MPP charge: MPP_PAYER_SECRET), adds it
|
|
363
|
+
to .env without showing the secret, funds it with Friendbot and swaps 10 test
|
|
364
|
+
XLM for test USDC on the public test exchange, then prints a status table. For
|
|
365
|
+
an MPP channel it makes no key: COMMITMENT_SECRET_HEX must be the key the
|
|
366
|
+
channel was opened with. On other test networks it names the variable and the
|
|
367
|
+
faucet. The key setup never changes the exit code.
|
|
368
|
+
Exit codes: 0 the config has the route (written now, or already there as
|
|
369
|
+
given); 2 init refused, and nothing was written.`)
|
|
370
|
+
.exitOverride(exitTwoOnUsageError)
|
|
371
|
+
.action(async (opts) => {
|
|
372
|
+
let code;
|
|
373
|
+
// Questions only at a terminal (C1); in a script or a pipe init asks nothing and names the missing flags (C5).
|
|
374
|
+
const rl = process.stdin.isTTY === true && process.stdout.isTTY === true
|
|
375
|
+
? (await import("node:readline/promises")).createInterface({ input: process.stdin, output: process.stdout })
|
|
376
|
+
: undefined;
|
|
377
|
+
try {
|
|
378
|
+
code = await executeInit({
|
|
379
|
+
...(opts.url === undefined ? {} : { url: opts.url }),
|
|
380
|
+
operatedByMe: opts.operatedByMe === true,
|
|
381
|
+
...(opts.name === undefined ? {} : { name: opts.name }),
|
|
382
|
+
...(opts.method === undefined ? {} : { method: opts.method }),
|
|
383
|
+
...(opts.bodyFile === undefined ? {} : { bodyFile: opts.bodyFile }),
|
|
384
|
+
...(opts.network === undefined ? {} : { network: opts.network }),
|
|
385
|
+
...(opts.protocol === undefined ? {} : { protocol: opts.protocol }),
|
|
386
|
+
...(opts.env === undefined ? {} : { env: opts.env }),
|
|
387
|
+
...(opts.start === undefined ? {} : { start: opts.start }),
|
|
388
|
+
...(opts.readyUrl === undefined ? {} : { readyUrl: opts.readyUrl }),
|
|
389
|
+
...(opts.readyTimeout === undefined ? {} : { readyTimeout: opts.readyTimeout }),
|
|
390
|
+
rejectHeader: opts.rejectHeader,
|
|
391
|
+
...(opts.rejectBodyFile === undefined ? {} : { rejectBodyFile: opts.rejectBodyFile }),
|
|
392
|
+
...(opts.rejectNote === undefined ? {} : { rejectNote: opts.rejectNote }),
|
|
393
|
+
config: opts.config,
|
|
394
|
+
force: opts.force === true,
|
|
395
|
+
read: opts.read !== false,
|
|
396
|
+
...(typeof opts.setupKeys === "boolean" ? { setupKeys: opts.setupKeys } : {}),
|
|
397
|
+
}, {
|
|
398
|
+
env: process.env,
|
|
399
|
+
stdout: (line) => console.log(line),
|
|
400
|
+
stderr: (line) => console.error(line),
|
|
401
|
+
...(rl === undefined ? {} : { ask: (question) => rl.question(question) }),
|
|
402
|
+
keys: LIVE_KEY_SETUP,
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
catch (error) {
|
|
406
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
407
|
+
console.error(sanitizeText(`wasit init: unexpected error: ${message}`, { redact: deniedEnvValues(process.env) }));
|
|
408
|
+
code = 2;
|
|
409
|
+
}
|
|
410
|
+
finally {
|
|
411
|
+
rl?.close();
|
|
412
|
+
}
|
|
413
|
+
await flushOutput();
|
|
414
|
+
finish(code);
|
|
273
415
|
});
|
|
274
416
|
program
|
|
275
417
|
.command("ci-report")
|
|
@@ -303,7 +445,7 @@ program
|
|
|
303
445
|
code = 2;
|
|
304
446
|
}
|
|
305
447
|
await flushOutput();
|
|
306
|
-
|
|
448
|
+
finish(code);
|
|
307
449
|
});
|
|
308
450
|
program
|
|
309
451
|
.command("serve")
|
|
@@ -418,7 +560,7 @@ that channel.`)
|
|
|
418
560
|
...(Number.isInteger(refundWaitingPeriod) ? { refundWaitingPeriod } : {}),
|
|
419
561
|
},
|
|
420
562
|
});
|
|
421
|
-
|
|
563
|
+
finish(report(results, jsonMode, terminalStyle(jsonMode)));
|
|
422
564
|
});
|
|
423
565
|
/** Colours for the MPP commands' text output, when a person is at the terminal. */
|
|
424
566
|
function terminalStyle(jsonMode) {
|
|
@@ -427,75 +569,6 @@ function terminalStyle(jsonMode) {
|
|
|
427
569
|
width: lineWidth(process.stdout),
|
|
428
570
|
};
|
|
429
571
|
}
|
|
430
|
-
/**
|
|
431
|
-
* `wasit test` for a person at a terminal: the same checks, notes and exit code
|
|
432
|
-
* as the plain output, drawn live (a RUNNING line with a timer while a check is
|
|
433
|
-
* in flight, each result as it arrives, the counts and the duration at the end).
|
|
434
|
-
*/
|
|
435
|
-
async function liveX402Test(opts, shape) {
|
|
436
|
-
const secrets = deniedEnvValues(process.env);
|
|
437
|
-
const live = new LiveReport({
|
|
438
|
-
stream: process.stdout,
|
|
439
|
-
live: liveEnabled(process.stdout, process.env),
|
|
440
|
-
depth: colorDepth(process.env),
|
|
441
|
-
clean: (text) => sanitizeText(text, { redact: secrets }),
|
|
442
|
-
});
|
|
443
|
-
const target = opts["target"];
|
|
444
|
-
const network = opts["network"];
|
|
445
|
-
live.header(CLI_VERSION, "x402 conformance", [
|
|
446
|
-
["target", `${target}${shape.method !== undefined ? ` ${shape.method.toUpperCase()}` : ""}`],
|
|
447
|
-
["network", network],
|
|
448
|
-
]);
|
|
449
|
-
live.phase("challenge", [["no payment"]]);
|
|
450
|
-
live.running("X402-01..05", "Challenge checks");
|
|
451
|
-
const results = await runX402ReadChecks({ target, ...shape, onResult: (result) => live.result(result) });
|
|
452
|
-
live.gap();
|
|
453
|
-
const keyEnv = paymentChainFor(network)?.payerKeyEnv ?? "STELLAR_PRIVATE_KEY";
|
|
454
|
-
const payerKey = opts["payerKey"] ?? process.env[keyEnv];
|
|
455
|
-
if (opts["readOnly"] === true) {
|
|
456
|
-
live.phase("payment", [["not run"]]);
|
|
457
|
-
live.note("--read-only set: the payment checks were not run.");
|
|
458
|
-
}
|
|
459
|
-
else if (!payerKey) {
|
|
460
|
-
live.phase("payment", [["not run"]]);
|
|
461
|
-
live.note(`No payer key: set ${keyEnv} in .env or pass --payer-key. The payment checks were not run.`);
|
|
462
|
-
}
|
|
463
|
-
else if (networkClass(network) !== "test") {
|
|
464
|
-
// Not a test network: the guard refuses the payment checks before anything
|
|
465
|
-
// is signed (the PREFLIGHT line says why), so no money moves.
|
|
466
|
-
live.phase("payment", [[network], ["not a test network: refused", "danger"]]);
|
|
467
|
-
}
|
|
468
|
-
else {
|
|
469
|
-
live.phase("payment", [[network], ["testnet funds move", "warning"]]);
|
|
470
|
-
live.note(`When the target offers a ${network} option, X402-06 settles a real payment and X402-07..10 send ` +
|
|
471
|
-
"payments it must refuse.");
|
|
472
|
-
}
|
|
473
|
-
if (opts["readOnly"] !== true && payerKey) {
|
|
474
|
-
const order = X402_PAYMENT_CHECK_IDS;
|
|
475
|
-
const startAt = (index) => {
|
|
476
|
-
const id = order[index];
|
|
477
|
-
if (id !== undefined)
|
|
478
|
-
live.running(id, catalogueEntry(id)?.name ?? id);
|
|
479
|
-
};
|
|
480
|
-
startAt(0);
|
|
481
|
-
results.push(...(await runX402PaymentChecks({
|
|
482
|
-
target,
|
|
483
|
-
network,
|
|
484
|
-
payerSecretKey: payerKey,
|
|
485
|
-
...(opts["rpcUrl"] ? { rpcUrl: opts["rpcUrl"] } : {}),
|
|
486
|
-
...shape,
|
|
487
|
-
onResult: (result) => {
|
|
488
|
-
live.result(result);
|
|
489
|
-
const index = order.indexOf(result.id);
|
|
490
|
-
if (index >= 0)
|
|
491
|
-
startAt(index + 1);
|
|
492
|
-
},
|
|
493
|
-
onProgress: (line) => live.progress(line),
|
|
494
|
-
})));
|
|
495
|
-
}
|
|
496
|
-
live.finish(results, endpointOutcome(results, "x402"), verdictNotes(results, "x402"));
|
|
497
|
-
return exitCodeFor(results, "x402");
|
|
498
|
-
}
|
|
499
572
|
program
|
|
500
573
|
.command("mpp-charge")
|
|
501
574
|
.description("Run the MPP charge-mode check (MPP-01) against a target service")
|
|
@@ -526,7 +599,7 @@ a real payment and moves testnet funds, because charge mode has no dry run.`)
|
|
|
526
599
|
payerSecretKey,
|
|
527
600
|
...(opts.rpcUrl ? { rpcUrl: opts.rpcUrl } : {}),
|
|
528
601
|
});
|
|
529
|
-
|
|
602
|
+
finish(report(results, jsonMode, terminalStyle(jsonMode)));
|
|
530
603
|
});
|
|
531
604
|
registerWalletCommand(program);
|
|
532
605
|
const isBareInteractiveInvocation = process.argv.length <= 2 && process.stdout.isTTY === true;
|