@wasit-dev/cli 0.8.0-beta.1 → 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 +38 -11
- package/dist/index.js +153 -83
- 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/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/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.2**, 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.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
|
|
|
@@ -39,6 +39,13 @@ wasit test --target https://your-service.example.com/paid --read-only
|
|
|
39
39
|
|
|
40
40
|
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
41
|
|
|
42
|
+
For a whole service you operate, let Wasit write the config from one unpaid request to a route, then run the free checks:
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me # your service is running; init reads its 402
|
|
46
|
+
wasit run --read-only # what init prints as the next command for x402
|
|
47
|
+
```
|
|
48
|
+
|
|
42
49
|
## Commands
|
|
43
50
|
|
|
44
51
|
### `wasit test` — x402
|
|
@@ -52,7 +59,7 @@ wasit test --target <url> [options]
|
|
|
52
59
|
| `--target <url>` | required | Must include the scheme |
|
|
53
60
|
| `--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
61
|
| `--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
|
|
62
|
+
| `--rpc-url <url>` | testnet default | Soroban RPC the payment is built through and `X402-06`'s settlement is read from; https only |
|
|
56
63
|
| `--method <verb>` | `GET` | HTTP method the paid endpoint uses |
|
|
57
64
|
| `--body <json>` | — | Request body; implies `Content-Type: application/json` |
|
|
58
65
|
| `--header <name:value>` | — | Extra request header, repeatable |
|
|
@@ -73,7 +80,7 @@ wasit mpp-charge --target <url> [options]
|
|
|
73
80
|
| `--network <id>` | `MPP_STELLAR_NETWORK` | CAIP-2. Only a challenge on this network is paid; `stellar:testnet` only, any other network is refused |
|
|
74
81
|
| `--rpc-url <url>` | testnet default | Used for the payment and the settlement read; https only |
|
|
75
82
|
|
|
76
|
-
**Every run settles a real payment.**
|
|
83
|
+
**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
84
|
|
|
78
85
|
### `wasit mpp-channel` — MPP, channel mode
|
|
79
86
|
|
|
@@ -99,6 +106,21 @@ wasit mpp-channel --target <url> [options]
|
|
|
99
106
|
|
|
100
107
|
`--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
108
|
|
|
109
|
+
### `wasit init`: write the config for one route (new in 0.8.0-beta.2)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me
|
|
113
|
+
wasit init --url http://127.0.0.1:3000/api/chat --method POST --body-file body.json --operated-by-me --start "npm start"
|
|
114
|
+
wasit init --url http://127.0.0.1:3000/mpp/chat --operated-by-me --protocol mpp-charge
|
|
115
|
+
wasit init # at a terminal: asks for what you leave out
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
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.
|
|
119
|
+
|
|
120
|
+
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.
|
|
121
|
+
|
|
122
|
+
**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.
|
|
123
|
+
|
|
102
124
|
### `wasit run`: a whole service from `wasit.config.json` (new in 0.8.0-beta.1)
|
|
103
125
|
|
|
104
126
|
```bash
|
|
@@ -109,17 +131,21 @@ wasit run --start # the payment tier, on a test network
|
|
|
109
131
|
|
|
110
132
|
`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
133
|
|
|
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
|
|
134
|
+
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
135
|
|
|
114
136
|
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
137
|
|
|
138
|
+
**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.
|
|
139
|
+
|
|
140
|
+
**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.
|
|
141
|
+
|
|
116
142
|
### `wasit ci-report`: the pull request comment and the job summary (new in 0.8.0-beta.1)
|
|
117
143
|
|
|
118
144
|
```bash
|
|
119
145
|
wasit ci-report --report wasit-report.json --comment comment.md
|
|
120
146
|
```
|
|
121
147
|
|
|
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.
|
|
148
|
+
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
149
|
|
|
124
150
|
### `wasit checks` — the catalogue
|
|
125
151
|
|
|
@@ -141,7 +167,7 @@ Testnet-only helpers for the keys the subcommands above read from `.env`. `--net
|
|
|
141
167
|
|
|
142
168
|
`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
169
|
|
|
144
|
-
`create` prints a secret key to stdout — don't run it on a screen you're recording.
|
|
170
|
+
`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
171
|
|
|
146
172
|
### `wasit serve` — a paywall that misbehaves, for testing an agent that pays
|
|
147
173
|
|
|
@@ -196,17 +222,18 @@ A run with both a failure and an error exits `1` — a real finding outranks a m
|
|
|
196
222
|
|
|
197
223
|
| Env var | Used by |
|
|
198
224
|
|---|---|
|
|
199
|
-
| `STELLAR_PRIVATE_KEY` | `test` (x402 payment checks on Stellar) |
|
|
225
|
+
| `STELLAR_PRIVATE_KEY` | `test`, `run` (x402 payment checks on Stellar), `init --setup-keys` |
|
|
200
226
|
| `EVM_PRIVATE_KEY` | `test --network eip155:84532` or `eip155:11155111` (x402 payment checks on Base or Ethereum Sepolia) |
|
|
201
227
|
| `SVM_PRIVATE_KEY` | `test --network solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1` (x402 payment checks on Solana devnet) |
|
|
202
|
-
| `MPP_PAYER_SECRET` | `mpp-charge` |
|
|
228
|
+
| `MPP_PAYER_SECRET` | `mpp-charge`, `run` (MPP charge), `init --setup-keys` |
|
|
203
229
|
| `MPP_STELLAR_NETWORK` | `mpp-charge`, `mpp-channel` |
|
|
204
|
-
| `COMMITMENT_SECRET_HEX` | `mpp-channel` |
|
|
230
|
+
| `COMMITMENT_SECRET_HEX` | `mpp-channel`, `run` (MPP channel) |
|
|
205
231
|
| `CHANNEL_CONTRACT` | `mpp-channel` (optional assertion) |
|
|
206
232
|
| `CHANNEL_CONTRACT_DISPOSABLE` | `mpp-channel --allow-destructive` |
|
|
207
233
|
| `WASIT_USDC_DISTRIBUTOR_SECRET` | `wallet fund --asset usdc` (optional) |
|
|
234
|
+
| `WASIT_MAINNET_PAYER_SECRET` | `run --mainnet` only (beta): a dedicated account's secret, exported in the shell, never in `.env` |
|
|
208
235
|
|
|
209
|
-
All keys are **testnet only
|
|
236
|
+
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
237
|
|
|
211
238
|
## What's checked
|
|
212
239
|
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,13 @@ 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
14
|
import { executeRun } from "./run.js";
|
|
15
|
-
import {
|
|
15
|
+
import { DEFAULT_CONFIG_FILE, executeInit } from "./init-command.js";
|
|
16
|
+
import { LIVE_KEY_SETUP } from "./init-keys.js";
|
|
17
|
+
import { CHECK_CATALOGUE, PROTOCOL_IDS, deniedEnvValues, paymentChainFor, runMppChannelSuite, runMppChargeSuite, runX402PaymentChecks, runX402ReadChecks, sanitizeText, } from "@wasit-dev/core";
|
|
16
18
|
const require = createRequire(import.meta.url);
|
|
17
19
|
/**
|
|
18
20
|
* Loads `.env` from the working directory exactly as `import "dotenv/config"`
|
|
@@ -58,6 +60,7 @@ program
|
|
|
58
60
|
.addHelpText("after", `
|
|
59
61
|
Examples:
|
|
60
62
|
$ wasit checks
|
|
63
|
+
$ wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me
|
|
61
64
|
$ wasit test --target https://api.example.com/paid-endpoint --read-only
|
|
62
65
|
$ wasit mpp-charge --target https://api.example.com/paid-endpoint --payer-key S...
|
|
63
66
|
$ wasit mpp-channel --target https://api.example.com/paid-endpoint
|
|
@@ -68,16 +71,18 @@ Run "wasit <command> --help" for that command's own options and cost notes.
|
|
|
68
71
|
Add --json to test/mpp-charge/mpp-channel for machine-readable output.
|
|
69
72
|
Full check catalogue (every check ID, spec reference, pass criteria):
|
|
70
73
|
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
|
-
//
|
|
74
|
+
// `.env` is loaded before a command's action, as it always was, with three
|
|
75
|
+
// exceptions (spec A8 #2, A-A01, B5): `wasit run` does not load it in CI, where
|
|
76
|
+
// the working directory is a checked-out pull request and a `.env` it added
|
|
77
|
+
// could steer the run; nor with --mainnet, whose key comes from the shell's
|
|
78
|
+
// WASIT_MAINNET_PAYER_SECRET only, never from a file in the service's folder
|
|
79
|
+
// that an agent could read; `wasit ci-report` never does, it has no use for it.
|
|
80
|
+
// CI is read from the real environment, before any `.env` could change it.
|
|
76
81
|
program.hook("preAction", (_program, action) => {
|
|
77
82
|
const name = action.name();
|
|
78
83
|
if (name === "ci-report")
|
|
79
84
|
return;
|
|
80
|
-
if (name === "run" && inCi(process.env))
|
|
85
|
+
if (name === "run" && (inCi(process.env) || action.opts()["mainnet"] === true))
|
|
81
86
|
return;
|
|
82
87
|
loadDotenv();
|
|
83
88
|
});
|
|
@@ -176,7 +181,7 @@ or NO_COLOR gives the plain text; FORCE_COLOR=1 colours a pipe.`)
|
|
|
176
181
|
// A person at a terminal gets the coloured, live output; a pipe, CI, NO_COLOR
|
|
177
182
|
// and --json get the plain text below, unchanged.
|
|
178
183
|
if (!jsonMode && colorEnabled(process.stdout, process.env)) {
|
|
179
|
-
process.exit(await liveX402Test(opts, shape));
|
|
184
|
+
process.exit(await liveX402Test(opts, shape, { stream: process.stdout, env: process.env }));
|
|
180
185
|
}
|
|
181
186
|
const results = await runX402ReadChecks({ target: opts.target, ...shape });
|
|
182
187
|
// Each chain reads its own payer key: a Stellar secret is no use on EVM.
|
|
@@ -210,7 +215,8 @@ program
|
|
|
210
215
|
.option("--endpoint <name>", "Run only this endpoint, by name. Repeatable.", (value, previous) => [...previous, value], [])
|
|
211
216
|
.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
217
|
.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
|
|
218
|
+
"against the caps ($1 a payment, $5 a run, lower with maxRunUsd). Reads each x402 endpoint's unpaid challenge, and " +
|
|
219
|
+
"on stellar:testnet each MPP charge endpoint's; " +
|
|
214
220
|
"uses no key, sends no payment, signs nothing. Exit 2 when a paying run would be refused. Not with --read-only.", false)
|
|
215
221
|
.option("--json", "Print the report as JSON instead of text", false)
|
|
216
222
|
.option("--out <file>", "Write the JSON report to this file as well")
|
|
@@ -219,7 +225,15 @@ program
|
|
|
219
225
|
.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
226
|
"otherwise the configured baseUrl is read as it is, which is how a deployed endpoint is checked. Not with --start.", false)
|
|
221
227
|
.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
|
-
.option("--mainnet", "
|
|
228
|
+
.option("--mainnet", "Pay real USDC on stellar:pubnet (x402 only). Runs only when every rule holds: the environment is on stellar:pubnet with " +
|
|
229
|
+
"operatedByMe true and pinned payTo and asset (mainnet USDC); the key is in WASIT_MAINNET_PAYER_SECRET and in no other " +
|
|
230
|
+
"variable; an https RPC for stellar:pubnet is set (rpcUrl or WASIT_RPC_URL); the payer holds at most $10.00 of USDC; " +
|
|
231
|
+
"no other mainnet run holds the lock; in GitHub Actions, the run is started by hand on the default branch on a " +
|
|
232
|
+
"GitHub-hosted runner, tests a deployed service and has no other key variable set. Otherwise exit 2 before anything " +
|
|
233
|
+
"is started, sent or signed. With --mainnet, wasit run does not read .env: the variables come from the shell. " +
|
|
234
|
+
"Not with --read-only.", false)
|
|
235
|
+
.option("--ledger-dir <dir>", "With --mainnet: the folder of the run ledger (wasit-ledger-<UTC time>.json, every signature written before the key " +
|
|
236
|
+
"signs) and of the lock that keeps a second mainnet run from starting beside it. Default: the working directory.")
|
|
223
237
|
.addHelpText("after", `
|
|
224
238
|
Examples:
|
|
225
239
|
$ wasit run --read-only
|
|
@@ -228,13 +242,25 @@ Examples:
|
|
|
228
242
|
$ wasit run --read-only --start-if-local --env mainnet
|
|
229
243
|
$ wasit run --dry-run --start
|
|
230
244
|
$ wasit run --start (payment tier: STELLAR_PRIVATE_KEY on stellar:testnet)
|
|
245
|
+
$ wasit run --start (MPP: MPP_PAYER_SECRET, COMMITMENT_SECRET_HEX on stellar:testnet)
|
|
246
|
+
$ wasit run --dry-run --env mainnet (the plan on stellar:pubnet: no key is read)
|
|
247
|
+
$ wasit run --mainnet --env mainnet (real funds: WASIT_MAINNET_PAYER_SECRET on stellar:pubnet)
|
|
231
248
|
|
|
232
249
|
Exit codes: 0 every graded endpoint conforms; 1 an endpoint does not conform, or one
|
|
233
250
|
graded on the baseline is not graded now; 2 no verdict (nothing could be graded, a
|
|
234
251
|
check could not run, the config or the service could not be used, or the payment
|
|
235
252
|
tier was asked for and did not pay: no payer key, or operatedByMe not true).
|
|
236
|
-
The payment tier pays on test networks
|
|
253
|
+
The payment tier pays on test networks: at most $1.00 a payment and $5.00 a run
|
|
237
254
|
(lower with maxRunUsd), only the pinned payTo and asset when the config pins them.
|
|
255
|
+
On stellar:pubnet it pays only with --mainnet: the first line says MAINNET RUN; the
|
|
256
|
+
plan reads the payer's balances on the RPC and public Horizon first, and refuses a
|
|
257
|
+
payer holding less than the run needs to finish its checks (the prices plus the
|
|
258
|
+
highest price again; a warning below the worst case); every signature
|
|
259
|
+
is in the run ledger; one refusal stops the whole run (exit 2); at the end the run
|
|
260
|
+
waits until every authorization it signed has expired (up to about five minutes),
|
|
261
|
+
reads the payer's balances again and says whether they match the ledger: consistent;
|
|
262
|
+
explained (more USDC left than the run verified settled, within the payments of
|
|
263
|
+
checks that FAILed: exit 1, by the checks); or inconsistent (exit 2).
|
|
238
264
|
In GitHub Actions it pays only on push to the default branch, schedule and
|
|
239
265
|
workflow_dispatch; a pull request runs the read-only checks, and a payer key set on
|
|
240
266
|
a run that may not pay is refused before the service starts. In another CI (CI set,
|
|
@@ -244,6 +270,15 @@ X402-11 runs for an endpoint with a reject case, on Stellar: it sends a valid pa
|
|
|
244
270
|
with the request the service must refuse, then reads the chain until that payment's
|
|
245
271
|
authorization has expired, up to six minutes; a lifetime above 300 s or below 30 s is
|
|
246
272
|
not signed, and an authorization signed to outlive 300 s is not sent.
|
|
273
|
+
MPP endpoints are paid in the payment tier on stellar:testnet only, by the same rules:
|
|
274
|
+
MPP-01 (charge) with MPP_PAYER_SECRET, planned from its unpaid challenge and held to the
|
|
275
|
+
same caps, in the same budget as x402; MPP-10, 11, 12 and 14 (channel) with
|
|
276
|
+
COMMITMENT_SECRET_HEX, with the channel and its expected terms from the config: with a
|
|
277
|
+
channel in the config, commitments are signed for it only, and a route whose challenge
|
|
278
|
+
names another gets none. MPP-13 (close) is never run by wasit run. The network and the
|
|
279
|
+
channel come from the config: MPP_STELLAR_NETWORK and CHANNEL_CONTRACT are not read. An
|
|
280
|
+
MPP endpoint is sent a plain GET: one with a method, a body or headers is not sent
|
|
281
|
+
anything. A mainnet run pays its x402 endpoints only.
|
|
247
282
|
In CI (CI or GITHUB_ACTIONS set) a .env file in the working directory is not read.`)
|
|
248
283
|
.exitOverride(exitTwoOnUsageError)
|
|
249
284
|
.action(async (opts) => {
|
|
@@ -261,6 +296,7 @@ In CI (CI or GITHUB_ACTIONS set) a .env file in the working directory is not rea
|
|
|
261
296
|
startIfLocal: opts.startIfLocal === true,
|
|
262
297
|
...(opts.baseline === undefined ? {} : { baseline: opts.baseline }),
|
|
263
298
|
mainnet: opts.mainnet === true,
|
|
299
|
+
...(opts.ledgerDir === undefined ? {} : { ledgerDir: opts.ledgerDir }),
|
|
264
300
|
}, { env: process.env, stdout: (line) => console.log(line), stderr: (line) => console.error(line) });
|
|
265
301
|
}
|
|
266
302
|
catch (error) {
|
|
@@ -271,6 +307,109 @@ In CI (CI or GITHUB_ACTIONS set) a .env file in the working directory is not rea
|
|
|
271
307
|
await flushOutput();
|
|
272
308
|
process.exit(code);
|
|
273
309
|
});
|
|
310
|
+
program
|
|
311
|
+
.command("init")
|
|
312
|
+
.description("Write a wasit.config.json for one paid route of a service you operate, from one unpaid request to the route")
|
|
313
|
+
.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)")
|
|
314
|
+
.option("--operated-by-me", "Confirm that you operate the service. Wasit tests only services their operator runs: without it nothing is written", false)
|
|
315
|
+
.option("--name <name>", "The endpoint's name (default: the last part of the path)")
|
|
316
|
+
.option("--method <method>", "The route's HTTP method (default: GET)")
|
|
317
|
+
.option("--body-file <file>", "A JSON file with the request body, written into the config as a JSON value (not with GET)")
|
|
318
|
+
.option("--network <id>", "Choose this test network (CAIP-2) among the ones the route offers; with --no-read, the network written (default: stellar:testnet)")
|
|
319
|
+
.option("--protocol <name>", "Choose this protocol among the ones the route offers: x402, mpp-charge or mpp-channel")
|
|
320
|
+
.option("--no-read", "Do not ask the route anything: write it as x402 from the flags alone")
|
|
321
|
+
.option("--env <name>", "The environment's name (default: local, for a URL on this machine)")
|
|
322
|
+
.option("--start <command>", "The command that starts the service, for wasit run --start")
|
|
323
|
+
.option("--ready-url <url>", "With --start: the address on this machine to wait for (default: the route's URL, on this machine)")
|
|
324
|
+
.option("--ready-timeout <seconds>", "With --start: how long to wait, 1 to 600 (default: 60)")
|
|
325
|
+
.option("--reject-header <header>", 'A header of the request the route must refuse (X402-11), as "Name: value". Repeatable.', (value, previous) => [...previous, value], [])
|
|
326
|
+
.option("--reject-body-file <file>", "A JSON file with the body of the request the route must refuse (X402-11)")
|
|
327
|
+
.option("--reject-note <text>", "One line on why the route must refuse that request")
|
|
328
|
+
.option("--config <path>", "The config file", DEFAULT_CONFIG_FILE)
|
|
329
|
+
.option("--force", "Replace the config file instead of adding the endpoint to it", false)
|
|
330
|
+
.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)")
|
|
331
|
+
.option("--no-setup-keys", "Do not set up a key, and do not ask")
|
|
332
|
+
.addHelpText("after", `
|
|
333
|
+
Examples:
|
|
334
|
+
$ wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me
|
|
335
|
+
$ wasit init --url http://127.0.0.1:3000/api/weather --operated-by-me --setup-keys
|
|
336
|
+
$ wasit init --url http://127.0.0.1:3000/api/chat --method POST --body-file body.json --operated-by-me --start "npm start"
|
|
337
|
+
$ wasit init --url http://127.0.0.1:3000/mpp/chat --operated-by-me --protocol mpp-charge
|
|
338
|
+
|
|
339
|
+
init sends the route one unpaid request (its method and body, and the
|
|
340
|
+
WASIT_HEADER_* headers wasit run sends), follows at most one redirect inside its
|
|
341
|
+
origin, and pays and signs nothing. Its 402 tells x402 from MPP and gives the
|
|
342
|
+
protocol, the network, the receiving address and asset (pinned) and an MPP
|
|
343
|
+
channel. A route that answers 200, 500 or 503, or does not answer, writes
|
|
344
|
+
nothing: --no-read writes it from the flags alone, as x402.
|
|
345
|
+
An existing config is added to (one more endpoint), never overwritten: --force
|
|
346
|
+
replaces it. A route the config already has exactly as given, in the same
|
|
347
|
+
environment, is left as it is, so init can run again (to set up its key, say).
|
|
348
|
+
Mainnet is not written in this version, and neither is a header of
|
|
349
|
+
the route: send a credential in a WASIT_HEADER_<NAME> variable. A URL whose query
|
|
350
|
+
has a parameter named like a credential (api_key, token, sig), given with --url or
|
|
351
|
+
reached by the redirect, is refused. After writing, init prints what it read from
|
|
352
|
+
your service, what you gave, what it filled in by default and what it did not read,
|
|
353
|
+
then the next command.
|
|
354
|
+
|
|
355
|
+
Key setup (Stellar testnet only; --setup-keys, or a yes at a terminal), after
|
|
356
|
+
the config is written: first it checks that git will not commit .env (not
|
|
357
|
+
tracked, and ignored: else .env is added to .gitignore, or no key is written).
|
|
358
|
+
A key already set is kept and its account only read. Otherwise init makes a
|
|
359
|
+
testnet key (x402: STELLAR_PRIVATE_KEY; MPP charge: MPP_PAYER_SECRET), adds it
|
|
360
|
+
to .env without showing the secret, funds it with Friendbot and swaps 10 test
|
|
361
|
+
XLM for test USDC on the public test exchange, then prints a status table. For
|
|
362
|
+
an MPP channel it makes no key: COMMITMENT_SECRET_HEX must be the key the
|
|
363
|
+
channel was opened with. On other test networks it names the variable and the
|
|
364
|
+
faucet. The key setup never changes the exit code.
|
|
365
|
+
Exit codes: 0 the config has the route (written now, or already there as
|
|
366
|
+
given); 2 init refused, and nothing was written.`)
|
|
367
|
+
.exitOverride(exitTwoOnUsageError)
|
|
368
|
+
.action(async (opts) => {
|
|
369
|
+
let code;
|
|
370
|
+
// Questions only at a terminal (C1); in a script or a pipe init asks nothing and names the missing flags (C5).
|
|
371
|
+
const rl = process.stdin.isTTY === true && process.stdout.isTTY === true
|
|
372
|
+
? (await import("node:readline/promises")).createInterface({ input: process.stdin, output: process.stdout })
|
|
373
|
+
: undefined;
|
|
374
|
+
try {
|
|
375
|
+
code = await executeInit({
|
|
376
|
+
...(opts.url === undefined ? {} : { url: opts.url }),
|
|
377
|
+
operatedByMe: opts.operatedByMe === true,
|
|
378
|
+
...(opts.name === undefined ? {} : { name: opts.name }),
|
|
379
|
+
...(opts.method === undefined ? {} : { method: opts.method }),
|
|
380
|
+
...(opts.bodyFile === undefined ? {} : { bodyFile: opts.bodyFile }),
|
|
381
|
+
...(opts.network === undefined ? {} : { network: opts.network }),
|
|
382
|
+
...(opts.protocol === undefined ? {} : { protocol: opts.protocol }),
|
|
383
|
+
...(opts.env === undefined ? {} : { env: opts.env }),
|
|
384
|
+
...(opts.start === undefined ? {} : { start: opts.start }),
|
|
385
|
+
...(opts.readyUrl === undefined ? {} : { readyUrl: opts.readyUrl }),
|
|
386
|
+
...(opts.readyTimeout === undefined ? {} : { readyTimeout: opts.readyTimeout }),
|
|
387
|
+
rejectHeader: opts.rejectHeader,
|
|
388
|
+
...(opts.rejectBodyFile === undefined ? {} : { rejectBodyFile: opts.rejectBodyFile }),
|
|
389
|
+
...(opts.rejectNote === undefined ? {} : { rejectNote: opts.rejectNote }),
|
|
390
|
+
config: opts.config,
|
|
391
|
+
force: opts.force === true,
|
|
392
|
+
read: opts.read !== false,
|
|
393
|
+
...(typeof opts.setupKeys === "boolean" ? { setupKeys: opts.setupKeys } : {}),
|
|
394
|
+
}, {
|
|
395
|
+
env: process.env,
|
|
396
|
+
stdout: (line) => console.log(line),
|
|
397
|
+
stderr: (line) => console.error(line),
|
|
398
|
+
...(rl === undefined ? {} : { ask: (question) => rl.question(question) }),
|
|
399
|
+
keys: LIVE_KEY_SETUP,
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
catch (error) {
|
|
403
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
404
|
+
console.error(sanitizeText(`wasit init: unexpected error: ${message}`, { redact: deniedEnvValues(process.env) }));
|
|
405
|
+
code = 2;
|
|
406
|
+
}
|
|
407
|
+
finally {
|
|
408
|
+
rl?.close();
|
|
409
|
+
}
|
|
410
|
+
await flushOutput();
|
|
411
|
+
process.exit(code);
|
|
412
|
+
});
|
|
274
413
|
program
|
|
275
414
|
.command("ci-report")
|
|
276
415
|
.description("Write the pull request comment and the job summary from the report of wasit run")
|
|
@@ -427,75 +566,6 @@ function terminalStyle(jsonMode) {
|
|
|
427
566
|
width: lineWidth(process.stdout),
|
|
428
567
|
};
|
|
429
568
|
}
|
|
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
569
|
program
|
|
500
570
|
.command("mpp-charge")
|
|
501
571
|
.description("Run the MPP charge-mode check (MPP-01) against a target service")
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `wasit init`: a `wasit.config.json` for one paid route of a service its
|
|
3
|
+
* operator runs (spec C; W3-2 slices 2 and 3).
|
|
4
|
+
*
|
|
5
|
+
* Every answer is a flag, so the same command works in a script, in
|
|
6
|
+
* PowerShell and in cmd.exe: no answer needs shell quoting (a body comes from
|
|
7
|
+
* a file). The file is written by core's config writer, which takes only data
|
|
8
|
+
* that is certain and checks the result with the validator `wasit run` reads
|
|
9
|
+
* the file with (Najmi, 2026-11-15). What the writer is not given, this
|
|
10
|
+
* command fills from a fixed fallback table (init-skeleton-plan.md section 6),
|
|
11
|
+
* and says so: after writing it prints what it read from the service, what was
|
|
12
|
+
* given, what was filled in by default, and what was NOT read.
|
|
13
|
+
*
|
|
14
|
+
* Reading the route (C2, slice 3) is the default: one unpaid request with the
|
|
15
|
+
* route's method and body (and the `WASIT_HEADER_*` headers `wasit run` would
|
|
16
|
+
* send), one redirect inside the origin at most, no payment, no signature, no
|
|
17
|
+
* key. Its 402 tells x402 from MPP and fills in the protocol, the network, the
|
|
18
|
+
* pin (receiving address and asset) and an MPP channel. A route that answers
|
|
19
|
+
* 200, 500 or 503, or nothing, is said in plain words and nothing is written;
|
|
20
|
+
* `--no-read` writes the route from the flags alone, as x402 (slice 2).
|
|
21
|
+
*
|
|
22
|
+
* The testnet key setup (C4, slice 5, `init-keys.ts`) comes last, for a route
|
|
23
|
+
* on Stellar testnet: with `--setup-keys`, or a yes at a terminal. It writes the
|
|
24
|
+
* key the route's payment checks read into `.env` (never into the config, and
|
|
25
|
+
* never printed) after checking that git will not commit `.env`.
|
|
26
|
+
*
|
|
27
|
+
* Nothing is sent and nothing is written without `--operated-by-me`: Wasit
|
|
28
|
+
* tests only services their operator runs. Every flag is checked before the
|
|
29
|
+
* route is asked anything. An existing config is added to, never overwritten
|
|
30
|
+
* silently; `--force` replaces it. A route it already has exactly as given, in
|
|
31
|
+
* the same environment, is left as it is, byte for byte, and the run goes on
|
|
32
|
+
* (to the key setup): init can be run again on the same route. Mainnet is not written in this version, and
|
|
33
|
+
* nothing that could hold a secret is: an endpoint's headers are not written (a
|
|
34
|
+
* credential goes in `WASIT_HEADER_*`). What the service answered is data:
|
|
35
|
+
* printed through the sanitiser, never followed or run.
|
|
36
|
+
*
|
|
37
|
+
* `executeInit` does not call `process.exit` and does not read the process:
|
|
38
|
+
* the environment and the output are passed in, so it can be tested in-process.
|
|
39
|
+
*/
|
|
40
|
+
import { type KeySetupDeps } from "./init-keys.js";
|
|
41
|
+
export declare const DEFAULT_CONFIG_FILE = "wasit.config.json";
|
|
42
|
+
export interface InitCommandOptions {
|
|
43
|
+
readonly url?: string;
|
|
44
|
+
readonly operatedByMe: boolean;
|
|
45
|
+
readonly name?: string;
|
|
46
|
+
readonly method?: string;
|
|
47
|
+
readonly bodyFile?: string;
|
|
48
|
+
/** Chooses among the ways the route offers to pay; without reading, the network written. */
|
|
49
|
+
readonly network?: string;
|
|
50
|
+
/** Chooses among the ways the route offers to pay. */
|
|
51
|
+
readonly protocol?: string;
|
|
52
|
+
readonly env?: string;
|
|
53
|
+
readonly start?: string;
|
|
54
|
+
readonly readyUrl?: string;
|
|
55
|
+
readonly readyTimeout?: string;
|
|
56
|
+
/** `Name: value`, repeatable: the headers of the request the route must refuse (X402-11). */
|
|
57
|
+
readonly rejectHeader: readonly string[];
|
|
58
|
+
readonly rejectBodyFile?: string;
|
|
59
|
+
readonly rejectNote?: string;
|
|
60
|
+
readonly config: string;
|
|
61
|
+
readonly force: boolean;
|
|
62
|
+
/** Read the route's 402 (the default); false is `--no-read`: no request, x402 from the flags. */
|
|
63
|
+
readonly read: boolean;
|
|
64
|
+
/**
|
|
65
|
+
* The testnet key setup (C4): true is `--setup-keys`, false `--no-setup-keys`.
|
|
66
|
+
* Undefined: asked at a terminal, else not done.
|
|
67
|
+
*/
|
|
68
|
+
readonly setupKeys?: boolean;
|
|
69
|
+
}
|
|
70
|
+
export interface InitContext {
|
|
71
|
+
/** The `WASIT_HEADER_*` variables the read sends, and the values kept out of every printed line. */
|
|
72
|
+
readonly env: Readonly<Record<string, string | undefined>>;
|
|
73
|
+
/** One line at a time, the line break added by the caller. */
|
|
74
|
+
readonly stdout: (line: string) => void;
|
|
75
|
+
readonly stderr: (line: string) => void;
|
|
76
|
+
/** Where relative paths are read from and the config is written. Default: the working directory. */
|
|
77
|
+
readonly cwd?: string;
|
|
78
|
+
/** Tests only: how long the read waits for the route. Index never sets it. */
|
|
79
|
+
readonly readTimeoutMs?: number;
|
|
80
|
+
/**
|
|
81
|
+
* Asks one question and returns the answer. Given only when stdin and stdout
|
|
82
|
+
* are terminals (C1): without it, init asks nothing and names the flags that
|
|
83
|
+
* are missing (C5). Rejects when the input ends.
|
|
84
|
+
*/
|
|
85
|
+
readonly ask?: (question: string) => Promise<string>;
|
|
86
|
+
/** The outside world of the key setup (git, Friendbot, Horizon, the key generator). Needed when the key setup runs. */
|
|
87
|
+
readonly keys?: KeySetupDeps;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Runs `wasit init`. Returns the exit code: 0 the file has the route (written
|
|
91
|
+
* now, or already there as given and left as it is); 2 nothing was written (a
|
|
92
|
+
* flag is missing or wrong, the service is not yours, the route is not a
|
|
93
|
+
* paywall init can read, or the writer refused the data). The key setup runs
|
|
94
|
+
* after the file is written and never changes the exit code: what
|
|
95
|
+
* it could not do is in its status table, with the command that finishes it
|
|
96
|
+
* (Najmi, 2026-11-27).
|
|
97
|
+
*/
|
|
98
|
+
export declare function executeInit(given: InitCommandOptions, context: InitContext): Promise<number>;
|