nirium-cli 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/README.md +402 -398
  2. package/bin/nirium.js +2103 -2092
  3. package/package.json +66 -66
package/README.md CHANGED
@@ -1,398 +1,402 @@
1
- # nirium-cli
2
-
3
- Scaffold Stellar agent projects, including one that charges for itself.
4
-
5
- ```bash
6
- npm install -g nirium-cli
7
- ```
8
-
9
- ## Charge for your API in five minutes
10
-
11
- ```bash
12
- nirium create x402 --name my-paid-api
13
- cd my-paid-api && npm install
14
- ```
15
-
16
- Fill two values in the generated `.env`:
17
-
18
- | Variable | Where it comes from |
19
- |---|---|
20
- | `STELLAR_PAY_TO` | the Stellar account that receives payments (`G...`) |
21
- | `X402_FACILITATOR_API_KEY` | free at [channels.openzeppelin.com/gen](https://channels.openzeppelin.com/gen) |
22
-
23
- The API key is not optional. The facilitator rejects unauthenticated servers
24
- on testnet as well as mainnet, so without it your routes never get as far as
25
- offering a 402.
26
-
27
- ```bash
28
- npm run dev
29
- ```
30
-
31
- Everything under `/premium` now bills before it answers. A caller without
32
- payment gets a 402 carrying the terms; one that pays gets the data, and the
33
- transfer settles on Stellar before your handler returns. No subscription, no
34
- card, no invoice, no human in the middle.
35
-
36
- The generated server is about ten lines, because `x402Serve()` from the
37
- [`nirium`](https://www.npmjs.com/package/nirium) SDK carries the facilitator
38
- client, the scheme registration and the route shape.
39
-
40
- **Usage telemetry (off by default):** `x402Serve()` sends Nirium nothing
41
- unless you turn it on. If you set `NIRIUM_X402SERVE_TELEMETRY=true` in the
42
- generated `.env`, it sends a small usage ping when the server starts and
43
- again every 50 requests or 10 minutes: your `STELLAR_PAY_TO` address, the
44
- network, the number of routes or requests, the SDK version, and a short hash
45
- of your `X402_FACILITATOR_API_KEY` (the first 16 characters of its SHA-256,
46
- never the key itself). The ping never blocks, delays or fails a charge, and
47
- it does not authorize or gate anything. Leave the variable unset and nothing
48
- is sent. (Checked against the code of `nirium` 0.16.1; `dist/` is identical to 0.16.0.)
49
-
50
- ## Listen to protocol signals
51
-
52
- ```bash
53
- nirium create bot --name my-agent # TypeScript
54
- nirium create bot --name my-agent -t py # Python
55
- ```
56
-
57
- Scaffolds a project that connects to a Nirium agent and prints incoming
58
- signals, which the autonomous loop produces on testnet. Defaults to `https://nirium-agent.fly.dev` (testnet); set
59
- `NIRIUM_API_URL` and `NIRIUM_API_KEY` in `.env` to point somewhere else.
60
-
61
- ## Pay an x402 endpoint from the terminal
62
-
63
- ```bash
64
- NIRIUM_SECRET_KEY=S... nirium pay https://your-api.example.com/premium/signals
65
- ```
66
-
67
- Signs and settles a real x402 payment against any endpoint that returns a
68
- 402, then prints the response. No scaffolding involved. This hits a live
69
- server directly, useful for testing a `nirium serve` instance or someone
70
- else's paid API without writing a client.
71
-
72
- Exits 0 only when the request after payment succeeds (`response.ok`); a
73
- 4xx or 5xx is printed and reported as a failure, in text and `--json`, and
74
- exits 1. The response payload is still printed either way, so you can see
75
- what the server said.
76
-
77
- There is no `--secret` flag: a key passed as a command-line argument sits
78
- in your shell history and in `ps`'s full command line for anyone else on
79
- the machine to read. There are three safe ways to give
80
- it the key: set `NIRIUM_SECRET_KEY`; run `nirium config set secretKey` with
81
- no value (a terminal asks for the key without showing it, or you can pipe
82
- it in through stdin) to save it once; or leave it unset and a terminal
83
- prompts for it each time. `nirium config set secretKey S...` with the key
84
- on the command line is refused and nothing is saved.
85
-
86
- | Option | Purpose |
87
- |---|---|
88
- | `-n, --network <network>` | `stellar:testnet` (default) or `stellar:pubnet` |
89
- | `--max-amount <usd>` | Refuse to pay more than this, e.g. `5` or `$0.50`. Rejects zero, negative and non-numeric values before any network call |
90
- | `--json` | Machine-readable result: status, duration, payer, tx hash, response body |
91
-
92
- `--max-amount` is compared in the units of whatever asset the server asks
93
- for, not converted. `"$5"` is 5 dollars only when the payment is in a
94
- dollar-pegged asset such as USDC, which is what Nirium's own endpoints
95
- charge in.
96
-
97
- The secret key never leaves your machine except as a signature: the CLI
98
- signs locally and sends the signed payment, not the key itself. Missing a
99
- secret key fails immediately with the three ways to supply one, before any
100
- network call happens.
101
-
102
- ## Spin up a local x402 test server
103
-
104
- ```bash
105
- FACILITATOR_API_KEY=<facilitator-key> nirium serve --pay-to G...
106
- # or just `nirium serve --pay-to G...` in a terminal: it asks for the key with a hidden prompt
107
- ```
108
-
109
- A one-command x402 server for testing `nirium pay` (or any x402 client)
110
- against, without scaffolding a whole project. Same facilitator requirement
111
- as `create x402`: get a free key at
112
- [channels.openzeppelin.com/gen](https://channels.openzeppelin.com/gen).
113
-
114
- | Option | Values | Default |
115
- |---|---|---|
116
- | `-P, --pay-to <address>` | Stellar `G...` address that receives payments | required |
117
- | `-p, --price <price>` | e.g. `$0.02` | `$0.02` |
118
- | `-port, --port <port>` | | `3000` |
119
- | `-r, --route <route>` | path to protect | `/api/v1/data` |
120
- | `-n, --network <network>` | `stellar:testnet` or `stellar:pubnet` | `stellar:testnet` |
121
-
122
- There is no `--api-key` flag: a key passed as a command-line argument sits in
123
- your shell history and in `ps`. The facilitator key comes from
124
- `FACILITATOR_API_KEY`, from `nirium config set facilitatorApiKey` (hidden
125
- prompt), or from a hidden prompt when `serve` runs in a terminal. `--pay-to`
126
- can also come from `nirium config set payTo`.
127
-
128
- ## Check an agent
129
-
130
- ```bash
131
- nirium status --url https://nirium-agent.fly.dev
132
- ```
133
-
134
- Calls the `/health` endpoint of an agent and prints whether it is running
135
- and for how long. It also prints a version and a network line, but they only
136
- carry a value when the agent reports one: the Nirium testnet agent's
137
- `/health` returns just `status`, `service` and `uptime` today, so those two
138
- lines are omitted rather than shown as `undefined`. `--url` points to the
139
- agent you want to check; `https://nirium-agent.fly.dev` is the Nirium
140
- testnet agent. Without `--url` it looks for an agent on your own machine at
141
- `http://localhost:3002` - the port `pnpm dev` runs the agent API on in this
142
- monorepo - so it reports "unreachable" if you are not running one there.
143
-
144
- Exits 0 only when `/health` answers 2xx; exits 1 if the agent is
145
- unreachable, times out, or answers with anything else.
146
-
147
- | Option | Purpose | Default |
148
- |---|---|---|
149
- | `-u, --url <url>` | Agent to check | `http://localhost:3002` |
150
- | `--json` | The raw `/health` fields plus `ok` | off |
151
- | `--timeout <ms>` | Give up after this many milliseconds instead of hanging | `5000` |
152
-
153
- ## Diagnose your x402 setup
154
-
155
- ```bash
156
- nirium doctor --network testnet
157
- ```
158
-
159
- Five checks against your actual environment before you find out the hard
160
- way in production: `payTo` is a well-formed public key (not a secret key
161
- pasted in the wrong field, a real mistake this catches), the facilitator
162
- API key authenticates against `channels.openzeppelin.com`, the Soroban RPC
163
- endpoint for your target network is reachable, `STELLAR_SECRET_KEY` (if
164
- set) is validly formatted, and MPP config (if set) is internally
165
- consistent. The MPP check only validates the values in your config; Nirium
166
- does not charge MPP payments on mainnet today. Reads from `.env` in the current directory by default.
167
-
168
- | Option | Purpose |
169
- |---|---|
170
- | `-n, --network <network>` | `testnet` (default) or `pubnet` |
171
- | `-c, --config <path>` | custom `.env`/config path |
172
- | `--seller <url>` | validate a remote x402 seller without paying |
173
- | `--json` | machine-readable report for CI |
174
-
175
- Exits non-zero if any check fails, so it's usable as a CI gate ahead of a
176
- deploy.
177
-
178
- ### Check a remote seller
179
-
180
- ```bash
181
- nirium doctor --seller https://your-api.example.com/premium/signals
182
- nirium doctor --seller https://your-api.example.com/premium/signals --json
183
- ```
184
-
185
- `--seller` does not read `.env` and does not run the local checks above. It
186
- also does not pay: the probe is a `GET` plus an `OPTIONS` preflight, and it
187
- never sends `PAYMENT-SIGNATURE`.
188
-
189
- Each line is pass or fail:
190
-
191
- | Check | Pass means |
192
- |---|---|
193
- | `challenge` | HTTP 402 with a decodable `PAYMENT-REQUIRED` header (base64 JSON, or raw JSON) |
194
- | `network` | every `accepts[]` entry has a well-formed network (`stellar:testnet`, `stellar:pubnet`, or another CAIP-2 id) |
195
- | `asset` | present; on Stellar, the SAC contract id (`C...`), not a symbol like `USDC` |
196
- | `amount` | a positive integer string in atomic units (`"1000000"`, not `"$0.02"`) |
197
- | `payTo` | present; on Stellar, a valid `G...` public key. A secret (`S...`) fails |
198
- | `resource-url` | `resource.url` is `https://`. `http://` fails even if you probed `http://127.0.0.1` |
199
- | `cors-preflight` | `OPTIONS` from a random `*.invalid` origin returns 2xx and allows that origin |
200
- | `cors-expose` | the 402 response exposes `PAYMENT-REQUIRED` and `PAYMENT-RESPONSE`. Headers listed only on the preflight do not count |
201
- | `cors-allow` | `PAYMENT-SIGNATURE` is listed in `Access-Control-Allow-Headers` |
202
-
203
- `--json` prints the same report (`ok`, `seller`, `network`, `checks`) for CI.
204
-
205
- ## Anchor a record
206
-
207
- ```bash
208
- nirium anchor --file evidence.json
209
- nirium anchor --hash <64-hex-sha256>
210
- nirium anchor --record '{"order":"A-12"}'
211
- ```
212
-
213
- Anchors a sha-256 hash (or a small JSON object, up to 8KB) to IPFS via an
214
- Audit Trail node's `POST /api/audit/log`, and prints back the CID.
215
-
216
- - `--file <path>` computes the sha-256 of the file locally and sends only
217
- the hash - the file's contents are never uploaded. IPFS cannot delete
218
- anything once pinned, so hashing locally means raw evidence never
219
- leaves your machine.
220
- - `--hash <hex>` sends a sha-256 you already have (64 hex chars, optional
221
- `sha-256:` prefix).
222
- - `--record <json>` anchors a small JSON object verbatim (max 8KB,
223
- enforced here before the request, not just by the server). Don't put
224
- personal data in it - an anchored record can never be deleted.
225
-
226
- Exactly one of the three is required. `--tx <hash>` and `--tag <label>`
227
- are optional and attached to the anchor as-is. There is no `--network`
228
- flag: the agent box anchoring the record decides its own network, and a
229
- client-supplied network field is rejected server-side anyway.
230
-
231
- | Option | Purpose | Default |
232
- |---|---|---|
233
- | `--file <path>` | anchor this file's sha-256 | none |
234
- | `--hash <hex>` | anchor this sha-256 directly | none |
235
- | `--record <json>` | anchor this small JSON object verbatim | none |
236
- | `--tx <hash>` | associate a transaction hash | none |
237
- | `--tag <label>` | free-form label | none |
238
- | `--sign` | attach an ed25519 attestation of which key produced this anchor | off |
239
- | `--key-env <VAR>` | env var holding the secret key to sign with (`--sign` only) | config store's `secretKey` |
240
- | `-u, --url <url>` | agent URL | `http://localhost:3002` |
241
- | `--json` | machine-readable result | off |
242
-
243
- On success, prints the CID, the content hash, the gateway URL, and a
244
- `nirium verify <cid>` suggestion so the anchor can be independently
245
- re-checked right away.
246
-
247
- ### Attesting who produced an anchor
248
-
249
- ```bash
250
- nirium config set secretKey # hidden prompt, stored in ~/.niriumrc.json
251
- nirium anchor --hash <64-hex> --sign
252
- # or, without touching the config store:
253
- NIRIUM_KEY=S... nirium anchor --hash <64-hex> --sign --key-env NIRIUM_KEY
254
- ```
255
-
256
- The CID alone proves the anchored fact wasn't altered; `--sign` proves
257
- *who* declared it. The secret key signs `nirium-audit-v1:<content_sha256>`
258
- locally with ed25519 - only the resulting signature and the derived
259
- public key (`G...`) ever leave this process, never the secret itself. If
260
- the node rejects the signature, nothing is anchored (`400`, exit non-zero).
261
- `nirium verify <cid>` independently re-checks it afterward and reports
262
- `SIGNATURE: VALID` against the same public key.
263
-
264
- ## Verify an audit record
265
-
266
- ```bash
267
- nirium verify <cid>
268
- ```
269
-
270
- Independently re-checks a Nirium audit document anchored to IPFS: fetches
271
- it from a gateway, recomputes its SHA-256 content hash, and, if the
272
- document carries an agent attestation, verifies the ed25519 signature
273
- over `nirium-audit-v1:<content_sha256>` against the declared signer's
274
- Stellar public key. Nothing here trusts the document's own claims about
275
- itself; both the hash and the signed statement are recomputed from the
276
- raw content, not read off the document.
277
-
278
- Hash-only anchors (no `record`, the recommended mode) have nothing to
279
- recompute: the document's `content_sha256` is the hash you submitted. Pass
280
- `--hash <hex>` or `--evidence <file>` to compare it with your own evidence;
281
- without either, the hash is reported as NOT CHECKED (not as a mismatch)
282
- and the signature is still verified over `nirium-audit-v1:<content_sha256>`.
283
- Signatures are accepted as base64 or hex, raw ed25519 or SEP-53
284
- (Freighter `signMessage`), like the anchoring node.
285
-
286
- `-g, --gateway <url>` is repeatable and tried in order as fallbacks. A
287
- `404` is retried on the *same* gateway up to `--retries` times with a
288
- short backoff first - a fresh pin can take a moment to propagate, so a
289
- 404 there doesn't mean the CID is wrong, just not there *yet*. Any other
290
- failure (a real error, or a timed-out request) moves straight to the
291
- next gateway instead, since retrying the same one won't help:
292
-
293
- ```bash
294
- nirium verify <cid> --gateway https://gateway.pinata.cloud --gateway https://ipfs.io --retries 3
295
- ```
296
-
297
- | Option | Purpose | Default |
298
- |---|---|---|
299
- | `-g, --gateway <url>` | IPFS gateway to fetch from - repeat for fallbacks | `https://gateway.pinata.cloud` |
300
- | `--retries <n>` | retries per gateway on a 404, with backoff | `2` |
301
- | `--timeout <ms>` | per-request timeout | `8000` |
302
- | `--json` | machine-readable result | off |
303
- | `--hash <hex>` | expected evidence hash for a hash-only anchor (`sha-256:` prefix optional) | none |
304
- | `--evidence <file>` | file whose SHA-256 is compared with the anchored hash | none |
305
-
306
- If every gateway comes back 404 after exhausting retries, that's
307
- reported as **NOT YET AVAILABLE** (`availability: "not_yet_available"`
308
- in `--json`) - distinct from a hash mismatch, because nothing was
309
- actually fetched to compare. A mix of real errors across gateways is
310
- reported as a gateway error instead. Both exit non-zero, same as before.
311
-
312
- Exits non-zero (and prints which check failed) if the hash doesn't match
313
- or the signature doesn't verify. A pass also requires that at least one
314
- of the two checks actually ran and succeeded, a matching `--hash`/
315
- `--evidence`, a valid agent signature, or both. If both were skipped
316
- (an unsigned hash-only anchor with no `--hash` or `--evidence`), nothing
317
- was verified, so `verify` prints `NOTHING VERIFIED`, exits non-zero, and
318
- sets `verified: false` in `--json`, instead of reporting a pass.
319
-
320
- ## Reporting: summaries and exports
321
-
322
- ```bash
323
- nirium report summary [--from <date>] [--to <date>] [--network <testnet|mainnet>] [--json]
324
- nirium report export anchors|payments|payroll [--from <date>] [--to <date>] [--limit <n>] [--csv out.csv] [--json]
325
- ```
326
-
327
- Thin client for the Reporting node's `GET /api/reporting/summary` and
328
- `GET /api/reporting/export` - an aggregation layer over what the
329
- protocol has already anchored (payroll runs, x402/MPP receipts, IPFS
330
- anchors). **This is institutional-format output, not certified
331
- regulatory reporting** - anything filed with an authority remains the
332
- caller's own responsibility (the server's own disclaimer is reprinted in
333
- both commands' output).
334
-
335
- `report summary` prints settled payroll runs and totals, payment
336
- receipts by gateway, and anchor counts for the period. `report export
337
- <type>` pulls the underlying rows:
338
-
339
- - Without `--csv`, rows print one per line on stdout. For `export
340
- anchors` specifically, that line is **just the CID** - nothing else -
341
- so it pipes straight into `nirium verify`:
342
-
343
- ```bash
344
- nirium report export anchors --from 2026-10-01 | xargs -n1 nirium verify
345
- ```
346
-
347
- The row count and disclaimer print to **stderr**, not stdout, so they
348
- never end up in that pipe.
349
- - With `--csv <file>`, the server's CSV is written to that file instead
350
- (nothing on stdout but a confirmation).
351
- - `--json` prints the full response (`type`, `period`, `rowCount`,
352
- `rows`, `disclaimer`) instead of one row per line; mutually exclusive
353
- with `--csv`.
354
-
355
- | Option (both subcommands) | Purpose | Default |
356
- |---|---|---|
357
- | `--from <date>` / `--to <date>` | ISO date period | 30-day window |
358
- | `--network <testnet\|mainnet>` | restrict to one network | all |
359
- | `-u, --url <url>` | agent URL | `http://localhost:3002` |
360
- | `--json` | machine-readable full response | off |
361
-
362
- | Option (`export` only) | Purpose | Default |
363
- |---|---|---|
364
- | `--limit <n>` | max rows (server caps at 1000) | server default |
365
- | `--csv <file>` | write the CSV export here instead of printing rows | off |
366
-
367
- ## Manage stored credentials
368
-
369
- ```bash
370
- nirium config set secretKey # hidden prompt; or pipe it: ... | nirium config set secretKey
371
- nirium config set facilitatorApiKey # same: never as an argument
372
- nirium config list
373
- nirium config get payTo
374
- nirium config delete facilitatorApiKey
375
- ```
376
-
377
- Stores `secretKey`, `payTo`, `network`, and `facilitatorApiKey` in
378
- `~/.niriumrc.json` (mode `600`) so `pay`, `serve`, and `doctor` don't need
379
- them repeated on every invocation. Command-line flags and environment
380
- variables still take priority when present. `list` and `get` mask secret
381
- values in their output; the raw file is never printed.
382
-
383
- ## Options
384
-
385
- | Option | Values | Default |
386
- |---|---|---|
387
- | `-n, --name <name>` | project directory name | `nirium-bot-v1` |
388
- | `-t, --template <template>` | `ts` or `py` (`bot` only) | `ts` |
389
-
390
- ## Links
391
-
392
- - [nirium.xyz](https://nirium.xyz)
393
- - [TypeScript SDK](https://www.npmjs.com/package/nirium) · [Python SDK](https://pypi.org/project/nirium/)
394
- - [Source and examples on GitHub](https://github.com/nirium-protocol/nirium)
395
-
396
- ## License
397
-
398
- Apache 2.0, Nirium Protocol
1
+ # nirium-cli
2
+
3
+ Scaffold Stellar agent projects, including one that charges for itself.
4
+
5
+ ```bash
6
+ npm install -g nirium-cli
7
+ ```
8
+
9
+ ## Charge for your API in five minutes
10
+
11
+ ```bash
12
+ nirium create x402 --name my-paid-api
13
+ cd my-paid-api && npm install
14
+ ```
15
+
16
+ Fill two values in the generated `.env`:
17
+
18
+ | Variable | Where it comes from |
19
+ |---|---|
20
+ | `STELLAR_PAY_TO` | the Stellar account that receives payments (`G...`) |
21
+ | `X402_FACILITATOR_API_KEY` | free at [channels.openzeppelin.com/gen](https://channels.openzeppelin.com/gen) |
22
+
23
+ The API key is not optional. The facilitator rejects unauthenticated servers
24
+ on testnet as well as mainnet, so without it your routes never get as far as
25
+ offering a 402.
26
+
27
+ ```bash
28
+ npm run dev
29
+ ```
30
+
31
+ Everything under `/premium` now bills before it answers. A caller without
32
+ payment gets a 402 carrying the terms; one that pays gets the data, and the
33
+ transfer settles on Stellar before your handler returns. No subscription, no
34
+ card, no invoice, no human in the middle.
35
+
36
+ The generated server is about ten lines, because `x402Serve()` from the
37
+ [`nirium`](https://www.npmjs.com/package/nirium) SDK carries the facilitator
38
+ client, the scheme registration and the route shape.
39
+
40
+ **Usage telemetry (off by default):** `x402Serve()` sends Nirium nothing
41
+ unless you turn it on. If you set `NIRIUM_X402SERVE_TELEMETRY=true` in the
42
+ generated `.env`, it sends a small usage ping when the server starts and
43
+ again every 50 requests or 10 minutes: your `STELLAR_PAY_TO` address, the
44
+ network, the number of routes or requests, the SDK version, and a short hash
45
+ of your `X402_FACILITATOR_API_KEY` (the first 16 characters of its SHA-256,
46
+ never the key itself). The ping never blocks, delays or fails a charge, and
47
+ it does not authorize or gate anything. Leave the variable unset and nothing
48
+ is sent. (Checked against the code of `nirium` 0.16.1; `dist/` is identical to 0.16.0.)
49
+
50
+ ## Listen to protocol signals
51
+
52
+ ```bash
53
+ nirium create bot --name my-agent # TypeScript
54
+ nirium create bot --name my-agent -t py # Python
55
+ ```
56
+
57
+ Scaffolds a project that connects to a Nirium agent and prints incoming
58
+ signals, which the autonomous loop produces on testnet. Defaults to `https://nirium-agent.fly.dev` (testnet); set
59
+ `NIRIUM_API_URL` and `NIRIUM_API_KEY` in `.env` to point somewhere else.
60
+
61
+ ## Pay an x402 endpoint from the terminal
62
+
63
+ ```bash
64
+ NIRIUM_SECRET_KEY=S... nirium pay https://your-api.example.com/premium/signals
65
+ ```
66
+
67
+ Signs and settles a real x402 payment against any endpoint that returns a
68
+ 402, then prints the response. No scaffolding involved. This hits a live
69
+ server directly, useful for testing a `nirium serve` instance or someone
70
+ else's paid API without writing a client.
71
+
72
+ Exits 0 only when the request after payment succeeds (`response.ok`); a
73
+ 4xx or 5xx is printed and reported as a failure, in text and `--json`, and
74
+ exits 1. The response payload is still printed either way, so you can see
75
+ what the server said.
76
+
77
+ There is no `--secret` flag: a key passed as a command-line argument sits
78
+ in your shell history and in `ps`'s full command line for anyone else on
79
+ the machine to read. There are three safe ways to give
80
+ it the key: set `NIRIUM_SECRET_KEY`; run `nirium config set secretKey` with
81
+ no value (a terminal asks for the key without showing it, or you can pipe
82
+ it in through stdin) to save it once; or leave it unset and a terminal
83
+ prompts for it each time. `nirium config set secretKey S...` with the key
84
+ on the command line is refused and nothing is saved.
85
+
86
+ | Option | Purpose |
87
+ |---|---|
88
+ | `-n, --network <network>` | `stellar:testnet` (default) or `stellar:pubnet` |
89
+ | `--max-amount <usd>` | Refuse to pay more than this, e.g. `5` or `$0.50`. Rejects zero, negative and non-numeric values before any network call |
90
+ | `--json` | Machine-readable result: status, duration, payer, tx hash, response body |
91
+
92
+ `--max-amount` is compared in the units of whatever asset the server asks
93
+ for, not converted. `"$5"` is 5 dollars only when the payment is in a
94
+ dollar-pegged asset such as USDC, which is what Nirium's own endpoints
95
+ charge in.
96
+
97
+ The secret key never leaves your machine except as a signature: the CLI
98
+ signs locally and sends the signed payment, not the key itself. Missing a
99
+ secret key fails immediately with the three ways to supply one, before any
100
+ network call happens.
101
+
102
+ ## Spin up a local x402 test server
103
+
104
+ ```bash
105
+ FACILITATOR_API_KEY=<facilitator-key> nirium serve --pay-to G...
106
+ # or just `nirium serve --pay-to G...` in a terminal: it asks for the key with a hidden prompt
107
+ ```
108
+
109
+ A one-command x402 server for testing `nirium pay` (or any x402 client)
110
+ against, without scaffolding a whole project. Same facilitator requirement
111
+ as `create x402`: get a free key at
112
+ [channels.openzeppelin.com/gen](https://channels.openzeppelin.com/gen).
113
+
114
+ | Option | Values | Default |
115
+ |---|---|---|
116
+ | `-P, --pay-to <address>` | Stellar `G...` address that receives payments | required |
117
+ | `-p, --price <price>` | e.g. `$0.02` | `$0.02` |
118
+ | `-port, --port <port>` | | `3000` |
119
+ | `-r, --route <route>` | path to protect | `/api/v1/data` |
120
+ | `-n, --network <network>` | `stellar:testnet` or `stellar:pubnet` | `stellar:testnet` |
121
+
122
+ There is no `--api-key` flag: a key passed as a command-line argument sits in
123
+ your shell history and in `ps`. The facilitator key comes from
124
+ `FACILITATOR_API_KEY`, from `nirium config set facilitatorApiKey` (hidden
125
+ prompt), or from a hidden prompt when `serve` runs in a terminal. `--pay-to`
126
+ can also come from `nirium config set payTo`.
127
+
128
+ ## Check an agent
129
+
130
+ ```bash
131
+ nirium status --url https://nirium-agent.fly.dev
132
+ ```
133
+
134
+ Calls the `/health` endpoint of an agent and prints whether it is running
135
+ and for how long. It also prints a version and a network line, but they only
136
+ carry a value when the agent reports one: the Nirium testnet agent's
137
+ `/health` returns just `status`, `service` and `uptime` today, so those two
138
+ lines are omitted rather than shown as `undefined`. `--url` points to the
139
+ agent you want to check; `https://nirium-agent.fly.dev` is the Nirium
140
+ testnet agent. Without `--url` it looks for an agent on your own machine at
141
+ `http://localhost:3002` - the port `pnpm dev` runs the agent API on in this
142
+ monorepo - so it reports "unreachable" if you are not running one there.
143
+
144
+ Exits 0 only when `/health` answers 2xx; exits 1 if the agent is
145
+ unreachable, times out, or answers with anything else.
146
+
147
+ | Option | Purpose | Default |
148
+ |---|---|---|
149
+ | `-u, --url <url>` | Agent to check | `http://localhost:3002` |
150
+ | `--json` | The raw `/health` fields plus `ok` | off |
151
+ | `--timeout <ms>` | Give up after this many milliseconds instead of hanging | `5000` |
152
+
153
+ ## Diagnose your x402 setup
154
+
155
+ ```bash
156
+ nirium doctor --network testnet
157
+ ```
158
+
159
+ Five checks against your actual environment before you find out the hard
160
+ way in production: `payTo` is a well-formed public key (not a secret key
161
+ pasted in the wrong field, a real mistake this catches), the facilitator
162
+ API key authenticates against `channels.openzeppelin.com`, the Soroban RPC
163
+ endpoint for your target network is reachable, `STELLAR_SECRET_KEY` (if
164
+ set) is validly formatted, and MPP config (if set) is internally
165
+ consistent. The MPP check only validates the values in your config; Nirium
166
+ does not charge MPP payments on mainnet today. Reads from `.env` in the current directory by default.
167
+
168
+ | Option | Purpose |
169
+ |---|---|
170
+ | `-n, --network <network>` | `testnet` (default) or `pubnet` |
171
+ | `-c, --config <path>` | custom `.env`/config path |
172
+ | `--seller <url>` | validate a remote x402 seller without paying |
173
+ | `--json` | machine-readable report for CI |
174
+
175
+ Exits non-zero if any check fails, so it's usable as a CI gate ahead of a
176
+ deploy.
177
+
178
+ ### Check a remote seller
179
+
180
+ ```bash
181
+ nirium doctor --seller https://your-api.example.com/premium/signals
182
+ nirium doctor --seller https://your-api.example.com/premium/signals --json
183
+ ```
184
+
185
+ `--seller` does not read `.env` and does not run the local checks above. It
186
+ also does not pay: the probe is a `GET` plus an `OPTIONS` preflight, and it
187
+ never sends `PAYMENT-SIGNATURE`.
188
+
189
+ Each line is pass or fail:
190
+
191
+ | Check | Pass means |
192
+ |---|---|
193
+ | `challenge` | HTTP 402 with a decodable `PAYMENT-REQUIRED` header (base64 JSON, or raw JSON) |
194
+ | `network` | every `accepts[]` entry has a well-formed network (`stellar:testnet`, `stellar:pubnet`, or another CAIP-2 id) |
195
+ | `asset` | present; on Stellar, the SAC contract id (`C...`), not a symbol like `USDC` |
196
+ | `amount` | a positive integer string in atomic units (`"1000000"`, not `"$0.02"`) |
197
+ | `payTo` | present; on Stellar, a valid `G...` public key. A secret (`S...`) fails |
198
+ | `resource-url` | `resource.url` is `https://`. `http://` fails even if you probed `http://127.0.0.1` |
199
+ | `cors-preflight` | `OPTIONS` from a random `*.invalid` origin returns 2xx and allows that origin |
200
+ | `cors-expose` | the 402 response exposes `PAYMENT-REQUIRED` and `PAYMENT-RESPONSE`. Headers listed only on the preflight do not count |
201
+ | `cors-allow` | `PAYMENT-SIGNATURE` is listed in `Access-Control-Allow-Headers` |
202
+
203
+ `--json` prints the same report (`ok`, `seller`, `network`, `checks`) for CI.
204
+
205
+ ## Anchor a record
206
+
207
+ ```bash
208
+ nirium anchor --file evidence.json
209
+ nirium anchor --hash <64-hex-sha256>
210
+ nirium anchor --record '{"order":"A-12"}'
211
+ ```
212
+
213
+ Anchors a sha-256 hash (or a small JSON object, up to 8KB) to IPFS via an
214
+ Audit Trail node's `POST /api/audit/log`, and prints back the CID.
215
+
216
+ - `--file <path>` computes the sha-256 of the file locally and sends only
217
+ the hash - the file's contents are never uploaded. IPFS cannot delete
218
+ anything once pinned, so hashing locally means raw evidence never
219
+ leaves your machine.
220
+ - `--hash <hex>` sends a sha-256 you already have (64 hex chars, optional
221
+ `sha-256:` prefix).
222
+ - `--record <json>` anchors a small JSON object verbatim (max 8KB,
223
+ enforced here before the request, not just by the server). Don't put
224
+ personal data in it - an anchored record can never be deleted.
225
+
226
+ Exactly one of the three is required. `--tx <hash>` and `--tag <label>`
227
+ are optional and attached to the anchor as-is. There is no `--network`
228
+ flag: the agent box anchoring the record decides its own network, and a
229
+ client-supplied network field is rejected server-side anyway.
230
+
231
+ | Option | Purpose | Default |
232
+ |---|---|---|
233
+ | `--file <path>` | anchor this file's sha-256 | none |
234
+ | `--hash <hex>` | anchor this sha-256 directly | none |
235
+ | `--record <json>` | anchor this small JSON object verbatim | none |
236
+ | `--tx <hash>` | associate a transaction hash | none |
237
+ | `--tag <label>` | free-form label | none |
238
+ | `--sign` | attach an ed25519 attestation of which key produced this anchor | off |
239
+ | `--key-env <VAR>` | env var holding the secret key to sign with (`--sign` only) | config store's `secretKey` |
240
+ | `-u, --url <url>` | agent URL | `http://localhost:3002` |
241
+ | `--json` | machine-readable result | off |
242
+
243
+ On success, prints the CID, the content hash, the gateway URL, and a
244
+ `nirium verify <cid>` suggestion so the anchor can be independently
245
+ re-checked right away.
246
+
247
+ ### Attesting who produced an anchor
248
+
249
+ ```bash
250
+ nirium config set secretKey # hidden prompt, stored in ~/.niriumrc.json
251
+ nirium anchor --hash <64-hex> --sign
252
+ # or, without touching the config store:
253
+ NIRIUM_KEY=S... nirium anchor --hash <64-hex> --sign --key-env NIRIUM_KEY
254
+ ```
255
+
256
+ The CID alone proves the anchored fact wasn't altered; `--sign` proves
257
+ *who* declared it. The secret key signs `nirium-audit-v1:<content_sha256>`
258
+ locally with ed25519 - only the resulting signature and the derived
259
+ public key (`G...`) ever leave this process, never the secret itself. If
260
+ the node rejects the signature, nothing is anchored (`400`, exit non-zero).
261
+ `nirium verify <cid>` independently re-checks it afterward and reports
262
+ `SIGNATURE: VALID` against the same public key.
263
+
264
+ ## Verify an audit record
265
+
266
+ ```bash
267
+ nirium verify <cid>
268
+ ```
269
+
270
+ Independently re-checks a Nirium audit document anchored to IPFS: fetches
271
+ it from a gateway, recomputes its SHA-256 content hash, and, if the
272
+ document carries an agent attestation, verifies the ed25519 signature
273
+ over `nirium-audit-v1:<content_sha256>` against the declared signer's
274
+ Stellar public key. Nothing here trusts the document's own claims about
275
+ itself; both the hash and the signed statement are recomputed from the
276
+ raw content, not read off the document.
277
+
278
+ Hash-only anchors (no `record`, the recommended mode) have nothing to
279
+ recompute: the document's `content_sha256` is the hash you submitted. Pass
280
+ `--hash <hex>` or `--evidence <file>` to compare it with your own evidence;
281
+ without either, the hash is reported as NOT CHECKED (not as a mismatch)
282
+ and the signature is still verified over `nirium-audit-v1:<content_sha256>`.
283
+ Signatures are accepted as base64 or hex, raw ed25519 or SEP-53
284
+ (Freighter `signMessage`), like the anchoring node.
285
+
286
+ `-g, --gateway <url>` is repeatable and tried in order as fallbacks. A
287
+ `404` is retried on the *same* gateway up to `--retries` times with a
288
+ short backoff first - a fresh pin can take a moment to propagate, so a
289
+ 404 there doesn't mean the CID is wrong, just not there *yet*. Any other
290
+ failure (a real error, or a timed-out request) moves straight to the
291
+ next gateway instead, since retrying the same one won't help.
292
+
293
+ With no `--gateway`, it tries Filebase's dedicated gateway, then Pinata,
294
+ then `ipfs.io`, then `dweb.link`. Shared public gateways often answer
295
+ `429` under load, so the dedicated one goes first:
296
+
297
+ ```bash
298
+ nirium verify <cid> --gateway https://gateway.pinata.cloud --gateway https://ipfs.io --retries 3
299
+ ```
300
+
301
+ | Option | Purpose | Default |
302
+ |---|---|---|
303
+ | `-g, --gateway <url>` | IPFS gateway to fetch from - repeat for fallbacks | `nirium.myfilebase.com`, then `gateway.pinata.cloud`, `ipfs.io`, `dweb.link` |
304
+ | `--retries <n>` | retries per gateway on a 404, with backoff | `2` |
305
+ | `--timeout <ms>` | per-request timeout | `8000` |
306
+ | `--json` | machine-readable result | off |
307
+ | `--hash <hex>` | expected evidence hash for a hash-only anchor (`sha-256:` prefix optional) | none |
308
+ | `--evidence <file>` | file whose SHA-256 is compared with the anchored hash | none |
309
+
310
+ If every gateway comes back 404 after exhausting retries, that's
311
+ reported as **NOT YET AVAILABLE** (`availability: "not_yet_available"`
312
+ in `--json`) - distinct from a hash mismatch, because nothing was
313
+ actually fetched to compare. A mix of real errors across gateways is
314
+ reported as a gateway error instead. Both exit non-zero, same as before.
315
+
316
+ Exits non-zero (and prints which check failed) if the hash doesn't match
317
+ or the signature doesn't verify. A pass also requires that at least one
318
+ of the two checks actually ran and succeeded, a matching `--hash`/
319
+ `--evidence`, a valid agent signature, or both. If both were skipped
320
+ (an unsigned hash-only anchor with no `--hash` or `--evidence`), nothing
321
+ was verified, so `verify` prints `NOTHING VERIFIED`, exits non-zero, and
322
+ sets `verified: false` in `--json`, instead of reporting a pass.
323
+
324
+ ## Reporting: summaries and exports
325
+
326
+ ```bash
327
+ nirium report summary [--from <date>] [--to <date>] [--network <testnet|mainnet>] [--json]
328
+ nirium report export anchors|payments|payroll [--from <date>] [--to <date>] [--limit <n>] [--csv out.csv] [--json]
329
+ ```
330
+
331
+ Thin client for the Reporting node's `GET /api/reporting/summary` and
332
+ `GET /api/reporting/export` - an aggregation layer over what the
333
+ protocol has already anchored (payroll runs, x402/MPP receipts, IPFS
334
+ anchors). **This is institutional-format output, not certified
335
+ regulatory reporting** - anything filed with an authority remains the
336
+ caller's own responsibility (the server's own disclaimer is reprinted in
337
+ both commands' output).
338
+
339
+ `report summary` prints settled payroll runs and totals, payment
340
+ receipts by gateway, and anchor counts for the period. `report export
341
+ <type>` pulls the underlying rows:
342
+
343
+ - Without `--csv`, rows print one per line on stdout. For `export
344
+ anchors` specifically, that line is **just the CID** - nothing else -
345
+ so it pipes straight into `nirium verify`:
346
+
347
+ ```bash
348
+ nirium report export anchors --from 2026-10-01 | xargs -n1 nirium verify
349
+ ```
350
+
351
+ The row count and disclaimer print to **stderr**, not stdout, so they
352
+ never end up in that pipe.
353
+ - With `--csv <file>`, the server's CSV is written to that file instead
354
+ (nothing on stdout but a confirmation).
355
+ - `--json` prints the full response (`type`, `period`, `rowCount`,
356
+ `rows`, `disclaimer`) instead of one row per line; mutually exclusive
357
+ with `--csv`.
358
+
359
+ | Option (both subcommands) | Purpose | Default |
360
+ |---|---|---|
361
+ | `--from <date>` / `--to <date>` | ISO date period | 30-day window |
362
+ | `--network <testnet\|mainnet>` | restrict to one network | all |
363
+ | `-u, --url <url>` | agent URL | `http://localhost:3002` |
364
+ | `--json` | machine-readable full response | off |
365
+
366
+ | Option (`export` only) | Purpose | Default |
367
+ |---|---|---|
368
+ | `--limit <n>` | max rows (server caps at 1000) | server default |
369
+ | `--csv <file>` | write the CSV export here instead of printing rows | off |
370
+
371
+ ## Manage stored credentials
372
+
373
+ ```bash
374
+ nirium config set secretKey # hidden prompt; or pipe it: ... | nirium config set secretKey
375
+ nirium config set facilitatorApiKey # same: never as an argument
376
+ nirium config list
377
+ nirium config get payTo
378
+ nirium config delete facilitatorApiKey
379
+ ```
380
+
381
+ Stores `secretKey`, `payTo`, `network`, and `facilitatorApiKey` in
382
+ `~/.niriumrc.json` (mode `600`) so `pay`, `serve`, and `doctor` don't need
383
+ them repeated on every invocation. Command-line flags and environment
384
+ variables still take priority when present. `list` and `get` mask secret
385
+ values in their output; the raw file is never printed.
386
+
387
+ ## Options
388
+
389
+ | Option | Values | Default |
390
+ |---|---|---|
391
+ | `-n, --name <name>` | project directory name | `nirium-bot-v1` |
392
+ | `-t, --template <template>` | `ts` or `py` (`bot` only) | `ts` |
393
+
394
+ ## Links
395
+
396
+ - [nirium.xyz](https://nirium.xyz)
397
+ - [TypeScript SDK](https://www.npmjs.com/package/nirium) · [Python SDK](https://pypi.org/project/nirium/)
398
+ - [Source and examples on GitHub](https://github.com/nirium-protocol/nirium)
399
+
400
+ ## License
401
+
402
+ Apache 2.0, Nirium Protocol