@did-btcr2/cli 0.15.0 → 0.17.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 (76) hide show
  1. package/README.md +47 -6
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/cjs/index.js +836 -122
  4. package/dist/esm/src/cli.js +7 -4
  5. package/dist/esm/src/cli.js.map +1 -1
  6. package/dist/esm/src/commands/config.js +11 -15
  7. package/dist/esm/src/commands/config.js.map +1 -1
  8. package/dist/esm/src/commands/create.js +4 -1
  9. package/dist/esm/src/commands/create.js.map +1 -1
  10. package/dist/esm/src/commands/deactivate.js +3 -1
  11. package/dist/esm/src/commands/deactivate.js.map +1 -1
  12. package/dist/esm/src/commands/index.js +2 -0
  13. package/dist/esm/src/commands/index.js.map +1 -1
  14. package/dist/esm/src/commands/init.js +69 -0
  15. package/dist/esm/src/commands/init.js.map +1 -0
  16. package/dist/esm/src/commands/keystore.js +180 -0
  17. package/dist/esm/src/commands/keystore.js.map +1 -0
  18. package/dist/esm/src/commands/profile.js +1 -1
  19. package/dist/esm/src/commands/profile.js.map +1 -1
  20. package/dist/esm/src/commands/update.js +3 -1
  21. package/dist/esm/src/commands/update.js.map +1 -1
  22. package/dist/esm/src/config.js +109 -31
  23. package/dist/esm/src/config.js.map +1 -1
  24. package/dist/esm/src/keystore/file-key-store.js +388 -32
  25. package/dist/esm/src/keystore/file-key-store.js.map +1 -1
  26. package/dist/esm/src/keystore/passphrase.js +53 -10
  27. package/dist/esm/src/keystore/passphrase.js.map +1 -1
  28. package/dist/esm/src/keystore/paths.js +6 -18
  29. package/dist/esm/src/keystore/paths.js.map +1 -1
  30. package/dist/esm/src/keystore/session.js +250 -0
  31. package/dist/esm/src/keystore/session.js.map +1 -0
  32. package/dist/esm/src/paths.js +71 -0
  33. package/dist/esm/src/paths.js.map +1 -0
  34. package/dist/esm/src/types.js.map +1 -1
  35. package/dist/types/src/cli.d.ts.map +1 -1
  36. package/dist/types/src/commands/config.d.ts.map +1 -1
  37. package/dist/types/src/commands/create.d.ts.map +1 -1
  38. package/dist/types/src/commands/deactivate.d.ts.map +1 -1
  39. package/dist/types/src/commands/index.d.ts +2 -0
  40. package/dist/types/src/commands/index.d.ts.map +1 -1
  41. package/dist/types/src/commands/init.d.ts +13 -0
  42. package/dist/types/src/commands/init.d.ts.map +1 -0
  43. package/dist/types/src/commands/keystore.d.ts +11 -0
  44. package/dist/types/src/commands/keystore.d.ts.map +1 -0
  45. package/dist/types/src/commands/update.d.ts.map +1 -1
  46. package/dist/types/src/config.d.ts +38 -14
  47. package/dist/types/src/config.d.ts.map +1 -1
  48. package/dist/types/src/keystore/file-key-store.d.ts +102 -10
  49. package/dist/types/src/keystore/file-key-store.d.ts.map +1 -1
  50. package/dist/types/src/keystore/passphrase.d.ts +26 -1
  51. package/dist/types/src/keystore/passphrase.d.ts.map +1 -1
  52. package/dist/types/src/keystore/paths.d.ts +6 -10
  53. package/dist/types/src/keystore/paths.d.ts.map +1 -1
  54. package/dist/types/src/keystore/session.d.ts +105 -0
  55. package/dist/types/src/keystore/session.d.ts.map +1 -0
  56. package/dist/types/src/paths.d.ts +64 -0
  57. package/dist/types/src/paths.d.ts.map +1 -0
  58. package/dist/types/src/types.d.ts +53 -0
  59. package/dist/types/src/types.d.ts.map +1 -1
  60. package/package.json +3 -3
  61. package/src/cli.ts +8 -3
  62. package/src/commands/config.ts +12 -14
  63. package/src/commands/create.ts +4 -1
  64. package/src/commands/deactivate.ts +3 -1
  65. package/src/commands/index.ts +2 -0
  66. package/src/commands/init.ts +80 -0
  67. package/src/commands/keystore.ts +232 -0
  68. package/src/commands/profile.ts +1 -1
  69. package/src/commands/update.ts +3 -1
  70. package/src/config.ts +118 -35
  71. package/src/keystore/file-key-store.ts +498 -43
  72. package/src/keystore/passphrase.ts +71 -8
  73. package/src/keystore/paths.ts +6 -19
  74. package/src/keystore/session.ts +303 -0
  75. package/src/paths.ts +92 -0
  76. package/src/types.ts +16 -1
package/README.md CHANGED
@@ -36,11 +36,13 @@ npx @did-btcr2/cli resolve -i did:btcr2:k1qq...
36
36
 
37
37
  | Command | Alias | Description |
38
38
  |---|---|---|
39
+ | `init` | - | Set up the btcr2 home: create the directory, a default config, and establish the keystore |
39
40
  | `create` | - | Create an identifier and initial DID document |
40
41
  | `resolve` | `read` | Resolve a DID document |
41
42
  | `update` | - | Update a DID document (signs via the keystore) |
42
43
  | `deactivate` | `delete` | Deactivate a DID permanently (signs via the keystore) |
43
- | `key` | - | Manage keypairs in the encrypted keystore |
44
+ | `key` | - | Manage keypairs in the keystore |
45
+ | `keystore` | - | Establish, inspect, and re-key the keystore |
44
46
  | `config` | - | Read and write CLI configuration |
45
47
  | `profile` | - | Manage configuration profiles |
46
48
  | `completion` | - | Print a shell completion script |
@@ -96,9 +98,29 @@ Permanently deactivates a DID. This is irreversible. Deactivation applies the `{
96
98
 
97
99
  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`).
98
100
 
101
+ ### init
102
+
103
+ `btcr2 init` is the one-command setup: it creates the btcr2 home directory, writes a default config if none exists, and establishes the keystore if none exists. It is idempotent (existing files are left untouched unless `--force`).
104
+
105
+ | Flag | Description |
106
+ |---|---|
107
+ | `--dev` | Establish an **unencrypted** dev keystore (plaintext keys, no passphrase). Testnet/regtest only; mainnet operations are refused |
108
+ | `--force` | Re-create the config and keystore even if they already exist |
109
+
110
+ By default `init` establishes an **encrypted** keystore and prompts (with confirmation) for a passphrase up front, so the first `key generate` never seals the keystore under an unconfirmed, mistyped passphrase. Supply the passphrase non-interactively with `BTCR2_KEYSTORE_PASSPHRASE` or `--passphrase-file` for scripted setup.
111
+
112
+ The workshop happy path:
113
+
114
+ ```bash
115
+ btcr2 init --dev --network mutinynet # (or: btcr2 init for an encrypted keystore)
116
+ btcr2 key generate --set-active
117
+ btcr2 create --network mutinynet
118
+ # ...fund the beacon, resolve, update, deactivate...
119
+ ```
120
+
99
121
  ### key
100
122
 
101
- Manage keypairs in the encrypted keystore. All subcommands operate offline (no Bitcoin connection).
123
+ Manage keypairs in the keystore. All subcommands operate offline (no Bitcoin connection).
102
124
 
103
125
  | Subcommand | Alias | Description |
104
126
  |---|---|---|
@@ -112,6 +134,18 @@ Manage keypairs in the encrypted keystore. All subcommands operate offline (no B
112
134
 
113
135
  A key reference is a full URN, a unique `name` tag, or a unique fingerprint prefix.
114
136
 
137
+ ### keystore
138
+
139
+ Establish, inspect, and re-key the keystore. These operate on the keystore file directly (no Bitcoin connection).
140
+
141
+ | Subcommand | Alias | Description |
142
+ |---|---|---|
143
+ | `keystore init` | - | Establish the keystore (encrypted by default; prompts and confirms the passphrase). `--dev` creates an unencrypted dev keystore; `--force` re-establishes an existing one (discards its keys) |
144
+ | `keystore status` | - | Show the resolved path, protection mode (`encrypted`/`dev`/`absent`), whether a passphrase is established, and the key count. Never decrypts or prompts |
145
+ | `keystore change-passphrase` | `passwd` | Re-seal every key under a new passphrase (encrypted keystores only). Prompts for the current passphrase, then a new one (with confirmation) |
146
+
147
+ **Encrypted vs dev keystores.** An encrypted keystore seals each secret with argon2id + XChaCha20-Poly1305 under one passphrase, and records a verifier so a mistyped passphrase fails loudly (with `Incorrect passphrase`) instead of sealing a key under an unknown or divergent passphrase. A **dev keystore** (`--dev`) stores secrets in plaintext and never prompts: it is for disposable testnet/regtest keys only, and the CLI **hard-refuses** to sign or generate a mainnet (`bitcoin`) key with one.
148
+
115
149
  ### config
116
150
 
117
151
  Read and write CLI configuration.
@@ -125,7 +159,7 @@ Read and write CLI configuration.
125
159
  | `config list` | `ls` | Print the entire config file. Secret values are redacted; `--show-secrets` reveals them |
126
160
  | `config validate` | - | Report unknown keys, invalid enum values, and an unsupported schema version |
127
161
  | `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 |
162
+ | `config path` | - | Print the resolved home directory, config-file, and keystore paths |
129
163
  | `config doctor` | - | Probe reachability of the resolved endpoints (read-only; touches the network). `-n, --network <n>` selects the network |
130
164
 
131
165
  ### profile
@@ -223,7 +257,8 @@ Override precedence, highest wins: CLI flags, then environment variables, then c
223
257
  | `-o, --output <format>` | Output format: `json` or `text` (default: config `defaults.output`, else `text`) |
224
258
  | `--verbose` | Verbose output |
225
259
  | `--quiet` | Suppress non-essential output |
226
- | `-c, --config <path>` | Path to config file (default: `$XDG_CONFIG_HOME/btcr2/config.json`) |
260
+ | `--home <dir>` | btcr2 home directory holding `config.json` + `keystore.json` (default: `~/.btcr2`, `%LOCALAPPDATA%\btcr2` on Windows; overrides `$BTCR2_HOME`) |
261
+ | `-c, --config <path>` | Path to config file (default: `<home>/config.json`) |
227
262
  | `--profile <name>` | Config profile name (default: auto-detected from network) |
228
263
  | `--btc-rest <url>` | Override Bitcoin REST endpoint (Esplora API) |
229
264
  | `--btc-rpc-url <url>` | Override Bitcoin Core RPC endpoint |
@@ -236,7 +271,7 @@ Override precedence, highest wins: CLI flags, then environment variables, then c
236
271
  | `--cas-gateway <url>` | IPFS HTTP gateway for CAS reads (read-only) |
237
272
  | `--cas-rpc-url <url>` | IPFS HTTP RPC endpoint for a writable CAS (reads + writes; enables `--publish-to-cas`) |
238
273
  | `--cas-timeout <ms>` | CAS request timeout in milliseconds (default: `30000`; `0` disables) |
239
- | `--keystore <path>` | Path to the keystore file (default: `$XDG_DATA_HOME/btcr2/keystore.json`) |
274
+ | `--keystore <path>` | Path to the keystore file (default: `<home>/keystore.json`) |
240
275
  | `--passphrase-file <path>` | Read the keystore passphrase from a file (unattended use) |
241
276
  | `--signing-key <ref>` | Key for create/update/deactivate signing: a URN, fingerprint prefix, or name |
242
277
 
@@ -255,10 +290,16 @@ Override precedence, highest wins: CLI flags, then environment variables, then c
255
290
  | `BTCR2_CAS_TIMEOUT` | `--cas-timeout` |
256
291
  | `BTCR2_FEE_RATE` | `--fee-rate` |
257
292
  | `BTCR2_OUTPUT` | `-o, --output` |
293
+ | `BTCR2_HOME` | `--home` |
294
+ | `BTCR2_KEYSTORE_PASSPHRASE` | keystore passphrase (unattended use) |
295
+
296
+ ### Home directory
297
+
298
+ The CLI keeps its config and keystore side by side in one home directory, resolved as `--home <dir>`, then `$BTCR2_HOME`, then the platform default: `~/.btcr2` on Linux/macOS and `%LOCALAPPDATA%\btcr2` on Windows. Both files live directly under it (`<home>/config.json`, `<home>/keystore.json`); `btcr2 config path` prints the resolved locations. `--config` and `--keystore` still override each file individually, so the historical XDG split can be reproduced explicitly.
258
299
 
259
300
  ### Config file
260
301
 
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).
302
+ Default location: `<home>/config.json`. A malformed config file fails loudly (the CLI never silently falls back to public endpoints, and never overwrites an unparseable file).
262
303
 
263
304
  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.
264
305