@did-btcr2/cli 0.14.0 → 0.15.0

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 (52) hide show
  1. package/README.md +61 -13
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/cjs/index.js +637 -54
  4. package/dist/esm/src/cli.js +23 -2
  5. package/dist/esm/src/cli.js.map +1 -1
  6. package/dist/esm/src/commands/config.js +124 -8
  7. package/dist/esm/src/commands/config.js.map +1 -1
  8. package/dist/esm/src/commands/create.js +10 -1
  9. package/dist/esm/src/commands/create.js.map +1 -1
  10. package/dist/esm/src/commands/deactivate.js +14 -2
  11. package/dist/esm/src/commands/deactivate.js.map +1 -1
  12. package/dist/esm/src/commands/profile.js +5 -3
  13. package/dist/esm/src/commands/profile.js.map +1 -1
  14. package/dist/esm/src/commands/update.js +14 -2
  15. package/dist/esm/src/commands/update.js.map +1 -1
  16. package/dist/esm/src/config-schema.js +149 -0
  17. package/dist/esm/src/config-schema.js.map +1 -0
  18. package/dist/esm/src/config.js +506 -39
  19. package/dist/esm/src/config.js.map +1 -1
  20. package/dist/esm/src/keystore/paths.js +3 -2
  21. package/dist/esm/src/keystore/paths.js.map +1 -1
  22. package/dist/esm/src/output.js +49 -0
  23. package/dist/esm/src/output.js.map +1 -1
  24. package/dist/esm/src/types.js +11 -0
  25. package/dist/esm/src/types.js.map +1 -1
  26. package/dist/types/src/cli.d.ts.map +1 -1
  27. package/dist/types/src/commands/config.d.ts.map +1 -1
  28. package/dist/types/src/commands/create.d.ts.map +1 -1
  29. package/dist/types/src/commands/deactivate.d.ts.map +1 -1
  30. package/dist/types/src/commands/profile.d.ts.map +1 -1
  31. package/dist/types/src/commands/update.d.ts.map +1 -1
  32. package/dist/types/src/config-schema.d.ts +24 -0
  33. package/dist/types/src/config-schema.d.ts.map +1 -0
  34. package/dist/types/src/config.d.ts +219 -5
  35. package/dist/types/src/config.d.ts.map +1 -1
  36. package/dist/types/src/keystore/paths.d.ts.map +1 -1
  37. package/dist/types/src/output.d.ts +22 -0
  38. package/dist/types/src/output.d.ts.map +1 -1
  39. package/dist/types/src/types.d.ts +32 -0
  40. package/dist/types/src/types.d.ts.map +1 -1
  41. package/package.json +5 -5
  42. package/src/cli.ts +25 -2
  43. package/src/commands/config.ts +135 -8
  44. package/src/commands/create.ts +13 -1
  45. package/src/commands/deactivate.ts +22 -2
  46. package/src/commands/profile.ts +5 -3
  47. package/src/commands/update.ts +22 -2
  48. package/src/config-schema.ts +178 -0
  49. package/src/config.ts +676 -43
  50. package/src/keystore/paths.ts +3 -2
  51. package/src/output.ts +53 -0
  52. package/src/types.ts +22 -0
package/README.md CHANGED
@@ -87,12 +87,14 @@ Required flags: `-s/--source-document`, `--source-version-id`, `-p/--patches`, `
87
87
  | `-m, --verification-method-id <id>` | DID document verification method ID |
88
88
  | `-b, --beacon-id <json>` | Beacon ID as a JSON string |
89
89
  | `--publish-to-cas <mode>` | Publish update artifacts to a writable CAS before broadcast: `auto`, `always`, or `never` (default: `never`). See [Publishing updates to CAS](#publishing-updates-to-cas) |
90
+ | `--fee-rate <satsPerVByte>` | Fee rate in sats/vByte for the beacon transaction (default: `5`). Raise it under congestion so the transaction confirms (also `BTCR2_FEE_RATE`, profile `btc.feeRate`) |
91
+ | `--change-address <address>` | Send transaction change to this address instead of the beacon address, so a DID's announcements are not linked on-chain (profile `btc.changeAddress`) |
90
92
 
91
93
  ### deactivate (alias: delete)
92
94
 
93
95
  Permanently deactivates a DID. This is irreversible. Deactivation applies the `{ "op": "add", "path": "/deactivated", "value": true }` patch and routes through the same signed-update path as `update`, so it also signs via the keystore.
94
96
 
95
- Required flags: `-s/--source-document`, `--source-version-id`, `-m/--verification-method-id`, `-b/--beacon-id`. Optional: `--publish-to-cas <mode>` (same as `update`).
97
+ Required flags: `-s/--source-document`, `--source-version-id`, `-m/--verification-method-id`, `-b/--beacon-id`. Optional: `--publish-to-cas <mode>`, `--fee-rate <satsPerVByte>`, `--change-address <address>` (same as `update`).
96
98
 
97
99
  ### key
98
100
 
@@ -117,10 +119,14 @@ Read and write CLI configuration.
117
119
  | Subcommand | Alias | Description |
118
120
  |---|---|---|
119
121
  | `config init` | - | Create a default config file with one profile per network. `--force` overwrites |
120
- | `config get [path]` | - | Print a value at a dotted path, or the whole config |
121
- | `config set <path> <value>` | - | Set a value at a dotted path (value parsed as JSON when valid, else a string) |
122
+ | `config get [path]` | - | Print a value at a dotted path, or the whole config. Secret values are redacted; `--show-secrets` reveals them |
123
+ | `config set <path> <value>` | - | Set a value at a dotted path (value parsed as JSON when valid, else a string). An invalid enum for a known key is rejected; an unknown path warns but writes |
122
124
  | `config unset <path>` | - | Delete a value at a dotted path |
123
- | `config list` | `ls` | Print the entire config file |
125
+ | `config list` | `ls` | Print the entire config file. Secret values are redacted; `--show-secrets` reveals them |
126
+ | `config validate` | - | Report unknown keys, invalid enum values, and an unsupported schema version |
127
+ | `config effective` | - | Print the resolved connection config with per-value provenance (`flag`/`env`/`file`/`default`). `-n, --network <n>` selects the network; `--show-secrets` reveals the RPC password |
128
+ | `config path` | - | Print the resolved config-file and keystore paths |
129
+ | `config doctor` | - | Probe reachability of the resolved endpoints (read-only; touches the network). `-n, --network <n>` selects the network |
124
130
 
125
131
  ### profile
126
132
 
@@ -214,7 +220,7 @@ Override precedence, highest wins: CLI flags, then environment variables, then c
214
220
  | Flag | Description |
215
221
  |---|---|
216
222
  | `-v, --version` | Output the current version |
217
- | `-o, --output <format>` | Output format: `json` or `text` (default: `text`) |
223
+ | `-o, --output <format>` | Output format: `json` or `text` (default: config `defaults.output`, else `text`) |
218
224
  | `--verbose` | Verbose output |
219
225
  | `--quiet` | Suppress non-essential output |
220
226
  | `-c, --config <path>` | Path to config file (default: `$XDG_CONFIG_HOME/btcr2/config.json`) |
@@ -222,9 +228,14 @@ Override precedence, highest wins: CLI flags, then environment variables, then c
222
228
  | `--btc-rest <url>` | Override Bitcoin REST endpoint (Esplora API) |
223
229
  | `--btc-rpc-url <url>` | Override Bitcoin Core RPC endpoint |
224
230
  | `--btc-rpc-user <user>` | Bitcoin Core RPC username |
225
- | `--btc-rpc-pass <pass>` | Bitcoin Core RPC password |
231
+ | `--btc-rpc-pass <pass>` | Bitcoin Core RPC password (accepts an `env:<VAR>` or `file:<path>` secret reference) |
232
+ | `--btc-rpc-wallet <name>` | Bitcoin Core wallet name for wallet-scoped RPCs (`/wallet/<name>`) |
233
+ | `--btc-rpc-header <header>` | Extra Bitcoin Core RPC header `"Key: Value"` (repeatable) |
234
+ | `--btc-rest-header <header>` | Extra Bitcoin REST header `"Key: Value"` (repeatable), e.g. an API key |
235
+ | `--btc-timeout <ms>` | Bitcoin REST/RPC request timeout in milliseconds (default: unbounded) |
226
236
  | `--cas-gateway <url>` | IPFS HTTP gateway for CAS reads (read-only) |
227
237
  | `--cas-rpc-url <url>` | IPFS HTTP RPC endpoint for a writable CAS (reads + writes; enables `--publish-to-cas`) |
238
+ | `--cas-timeout <ms>` | CAS request timeout in milliseconds (default: `30000`; `0` disables) |
228
239
  | `--keystore <path>` | Path to the keystore file (default: `$XDG_DATA_HOME/btcr2/keystore.json`) |
229
240
  | `--passphrase-file <path>` | Read the keystore passphrase from a file (unattended use) |
230
241
  | `--signing-key <ref>` | Key for create/update/deactivate signing: a URN, fingerprint prefix, or name |
@@ -237,35 +248,72 @@ Override precedence, highest wins: CLI flags, then environment variables, then c
237
248
  | `BTCR2_BTC_RPC_URL` | `--btc-rpc-url` |
238
249
  | `BTCR2_BTC_RPC_USER` | `--btc-rpc-user` |
239
250
  | `BTCR2_BTC_RPC_PASS` | `--btc-rpc-pass` |
251
+ | `BTCR2_BTC_RPC_PASS_FILE` | file whose contents are the RPC password |
240
252
  | `BTCR2_CAS_GATEWAY` | `--cas-gateway` |
241
253
  | `BTCR2_CAS_RPC_URL` | `--cas-rpc-url` |
254
+ | `BTCR2_BTC_TIMEOUT` | `--btc-timeout` |
255
+ | `BTCR2_CAS_TIMEOUT` | `--cas-timeout` |
256
+ | `BTCR2_FEE_RATE` | `--fee-rate` |
257
+ | `BTCR2_OUTPUT` | `-o, --output` |
242
258
 
243
259
  ### Config file
244
260
 
245
- Default location: `$XDG_CONFIG_HOME/btcr2/config.json` (falls back to `~/.config/btcr2/config.json`).
261
+ Default location: `$XDG_CONFIG_HOME/btcr2/config.json` (falls back to `~/.config/btcr2/config.json`). An empty `$XDG_CONFIG_HOME` is treated as unset. A malformed config file fails loudly (the CLI never silently falls back to public endpoints, and never overwrites an unparseable file).
246
262
 
247
- Profiles are matched by network name when `--profile` is not specified. For example, resolving a regtest DID automatically selects the `"regtest"` profile.
263
+ Profiles are matched by network name when `--profile` is not specified. For example, resolving a regtest DID automatically selects the `"regtest"` profile. A profile that is not named after a network can declare its network with a `network` field.
248
264
 
249
265
  ```json
250
266
  {
267
+ "schemaVersion": 1,
268
+ "defaults": {
269
+ "profile": "production",
270
+ "network": "bitcoin",
271
+ "output": "text"
272
+ },
251
273
  "profiles": {
252
274
  "regtest": {
253
275
  "btc": {
254
276
  "rest": "http://localhost:3000",
255
277
  "rpcUrl": "http://localhost:18443",
256
278
  "rpcUser": "polaruser",
257
- "rpcPass": "polarpass"
279
+ "rpcPass": "polarpass",
280
+ "wallet": "primary",
281
+ "feeRate": 5,
282
+ "timeoutMs": 30000
258
283
  }
259
284
  },
260
- "bitcoin": {
261
- "btc": { "rest": "https://my-mempool/api" },
262
- "cas": { "gateway": "https://ipfs.io", "rpcUrl": "http://127.0.0.1:5001" }
285
+ "production": {
286
+ "network": "bitcoin",
287
+ "btc": {
288
+ "rest": "https://my-mempool/api",
289
+ "headers": { "Authorization": "Bearer <api-key>" },
290
+ "feeRate": 20
291
+ },
292
+ "cas": { "gateway": "https://ipfs.io", "rpcUrl": "http://127.0.0.1:5001", "timeoutMs": 30000 },
293
+ "identity": { "keystore": "/secure/prod-keystore.json", "default": "did:btcr2:...#key-0" }
263
294
  }
264
295
  }
265
296
  }
266
297
  ```
267
298
 
268
- `cas.gateway` is a read-only IPFS HTTP gateway (used for reads). `cas.rpcUrl` is an IPFS HTTP RPC endpoint that supports writes; configure it to enable `--publish-to-cas`. When both are set, `rpcUrl` takes precedence.
299
+ Field notes:
300
+
301
+ - **`defaults`**: `profile` selects the active profile; `network` fixes the network `create` encodes when `-n` is absent; `output` sets the default output format. `schemaVersion` is stamped on every write; a file written by a newer CLI is refused.
302
+ - **`btc`**: `rest`/`rpcUrl`/`rpcUser`/`rpcPass` are endpoints and credentials; `wallet` targets a Bitcoin Core wallet (`/wallet/<name>`); `headers`/`rpcHeaders` add REST/RPC headers; `feeRate` (sats/vByte), `changeAddress`, and `timeoutMs` set broadcast and request behavior. The RPC url, user, and pass are resolved as one atomic unit, so a URL from a higher-precedence layer never inherits credentials from a lower one.
303
+ - **`cas`**: `gateway` is a read-only IPFS HTTP gateway; `cas.rpcUrl` is a writable IPFS HTTP RPC endpoint (enables `--publish-to-cas`; `rpcUrl` wins over `gateway`); `timeoutMs` bounds CAS operations (`0` disables).
304
+ - **`identity`**: `keystore` points the profile at its own keystore file, and `default` is the profile's default signing key. Both fall **below** the corresponding `--keystore` / `--signing-key` flags.
305
+
306
+ Use `config validate` to check a file, and `config effective` to see the resolved values with their provenance.
307
+
308
+ ### RPC password and secrets
309
+
310
+ `config get` and `config list` redact secret-looking values (RPC password and any `pass`/`secret`/`token` key) by default; pass `--show-secrets` to reveal them.
311
+
312
+ An `rpcPass` written directly into `config.json` is stored in cleartext (the file is mode 0600 but not encrypted). For anything sensitive, keep the secret out of the file with a reference or an RPC-URL-embedded credential:
313
+
314
+ - `"rpcPass": "env:MY_RPC_PASS"` reads the password from the `MY_RPC_PASS` environment variable.
315
+ - `"rpcPass": "file:/run/secrets/rpc-pass"` reads it from a file (a single trailing newline is trimmed).
316
+ - `BTCR2_BTC_RPC_PASS_FILE=/run/secrets/rpc-pass` names a file to read when no other RPC password source applies.
269
317
 
270
318
  ### Defaults
271
319