@did-btcr2/cli 0.12.14 → 0.12.16
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 +114 -23
- package/dist/.tsbuildinfo +1 -1
- package/dist/cjs/index.js +2 -2
- package/dist/esm/src/cli.js +1 -1
- package/dist/esm/src/cli.js.map +1 -1
- package/dist/esm/src/config.js.map +1 -1
- package/dist/esm/src/keystore/resolve-key-ref.js +1 -1
- package/dist/esm/src/keystore/resolve-key-ref.js.map +1 -1
- package/dist/types/src/config.d.ts +0 -7
- package/dist/types/src/config.d.ts.map +1 -1
- package/package.json +5 -12
- package/src/cli.ts +1 -1
- package/src/config.ts +0 -7
- package/src/keystore/resolve-key-ref.ts +1 -1
package/README.md
CHANGED
|
@@ -6,11 +6,11 @@ Part of the [`did-btcr2-js`](https://github.com/dcdpr/did-btcr2-js) monorepo.
|
|
|
6
6
|
|
|
7
7
|
## Summary
|
|
8
8
|
|
|
9
|
-
This package provides the `btcr2` CLI for creating, resolving, updating, and deactivating did:btcr2 decentralized identifiers. It wraps the `@did-btcr2/api` SDK via dependency injection, using [commander.js](https://github.com/tj/commander.js/) for argument parsing.
|
|
9
|
+
This package provides the `btcr2` CLI for creating, resolving, updating, and deactivating did:btcr2 decentralized identifiers. It also manages an encrypted keystore of keypairs, reads and writes CLI configuration and profiles, and prints shell completion scripts. It wraps the `@did-btcr2/api` SDK via dependency injection, using [commander.js](https://github.com/tj/commander.js/) for argument parsing.
|
|
10
10
|
|
|
11
11
|
Out of the box, `btcr2 resolve` works with zero configuration. The Bitcoin network is derived from the DID itself, and public endpoints (mempool.space, ipfs.io) are used as defaults. Override endpoints via CLI flags, environment variables, or a config file.
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
Signing operations (`update`, `deactivate`, and generated `create` keys) read secret keys from an encrypted on-disk keystore. Choose a key with `--signing-key <ref>` or set an active key with `btcr2 key use <ref>`.
|
|
14
14
|
|
|
15
15
|
## Install
|
|
16
16
|
|
|
@@ -34,22 +34,34 @@ npx @did-btcr2/cli resolve -i did:btcr2:k1qq...
|
|
|
34
34
|
|
|
35
35
|
## Commands
|
|
36
36
|
|
|
37
|
-
| Command | Alias |
|
|
38
|
-
|
|
39
|
-
| `create` | - |
|
|
40
|
-
| `resolve` | `read` |
|
|
41
|
-
| `update` | - |
|
|
42
|
-
| `deactivate` | `delete` |
|
|
37
|
+
| Command | Alias | Description |
|
|
38
|
+
|---|---|---|
|
|
39
|
+
| `create` | - | Create an identifier and initial DID document |
|
|
40
|
+
| `resolve` | `read` | Resolve a DID document |
|
|
41
|
+
| `update` | - | Update a DID document (signs via the keystore) |
|
|
42
|
+
| `deactivate` | `delete` | Deactivate a DID permanently (signs via the keystore) |
|
|
43
|
+
| `key` | - | Manage keypairs in the encrypted keystore |
|
|
44
|
+
| `config` | - | Read and write CLI configuration |
|
|
45
|
+
| `profile` | - | Manage configuration profiles |
|
|
46
|
+
| `completion` | - | Print a shell completion script |
|
|
43
47
|
|
|
44
48
|
### create
|
|
45
49
|
|
|
46
|
-
|
|
50
|
+
Creates an identifier and initial DID document. Two identifier types, selected by `-t/--type`:
|
|
51
|
+
|
|
52
|
+
- **`k`** (deterministic): a 33-byte compressed secp256k1 public key. Three mutually-exclusive input modes:
|
|
53
|
+
- **generate** (neither `--bytes` nor `--signing-key`): mint a fresh key, persist it to the keystore, set it active, and print the identifier. Sealing the secret prompts for the keystore passphrase.
|
|
54
|
+
- **existing** (`--signing-key <ref>`): use a stored key's public key as the genesis bytes. Reading a public key never decrypts, so this never prompts.
|
|
55
|
+
- **raw** (`--bytes <hex>`): a 33-byte public key as hex. Offline and keystore-free.
|
|
56
|
+
- **`x`** (external): raw-bytes only, the 32-byte SHA-256 hash of a genesis document via `--bytes`.
|
|
47
57
|
|
|
48
58
|
| Flag | Description |
|
|
49
59
|
|---|---|
|
|
50
|
-
| `-t, --type <type>` | Identifier type: `k` (deterministic
|
|
51
|
-
| `-n, --network <network>` | Bitcoin network: `bitcoin`, `testnet3`, `testnet4`, `signet`, `mutinynet`, or `regtest` |
|
|
52
|
-
| `-b, --bytes <bytes>` | Genesis bytes as a hex string |
|
|
60
|
+
| `-t, --type <type>` | Identifier type: `k` (deterministic) or `x` (external). Default: `k` |
|
|
61
|
+
| `-n, --network <network>` | Bitcoin network: `bitcoin`, `testnet3`, `testnet4`, `signet`, `mutinynet`, or `regtest`. Default: config `defaults.network`, else the active profile's network, else `regtest` |
|
|
62
|
+
| `-b, --bytes <bytes>` | Genesis bytes as a hex string. For type=k, a 33-byte public key (omit to generate a key); for type=x, the 32-byte genesis-document hash |
|
|
63
|
+
|
|
64
|
+
`--signing-key <ref>` (global) selects a stored key for the existing-key mode; it applies only to `-t k`.
|
|
53
65
|
|
|
54
66
|
### resolve (alias: read)
|
|
55
67
|
|
|
@@ -61,26 +73,83 @@ Required flag: `-i/--identifier`. At most one of `-r` or `-p` may be given.
|
|
|
61
73
|
| `-r, --resolution-options <json>` | Resolution options as an inline JSON string |
|
|
62
74
|
| `-p, --resolution-options-path <path>` | Path to a JSON file containing resolution options |
|
|
63
75
|
|
|
64
|
-
### update
|
|
76
|
+
### update
|
|
65
77
|
|
|
66
|
-
|
|
78
|
+
Signs and broadcasts an update to a DID document. The signing key comes from the encrypted keystore (choose one with `--signing-key <ref>` or set an active key with `btcr2 key use`).
|
|
67
79
|
|
|
68
80
|
Required flags: `-s/--source-document`, `--source-version-id`, `-p/--patches`, `-m/--verification-method-id`, `-b/--beacon-id`.
|
|
69
81
|
|
|
70
|
-
|
|
82
|
+
| Flag | Description |
|
|
83
|
+
|---|---|
|
|
84
|
+
| `-s, --source-document <json>` | Source DID document as a JSON string |
|
|
85
|
+
| `--source-version-id <number>` | Source version ID as a non-negative integer |
|
|
86
|
+
| `-p, --patches <json>` | JSON Patch operations as a JSON array string |
|
|
87
|
+
| `-m, --verification-method-id <id>` | DID document verification method ID |
|
|
88
|
+
| `-b, --beacon-id <json>` | Beacon ID as a JSON string |
|
|
71
89
|
|
|
72
|
-
|
|
90
|
+
### deactivate (alias: delete)
|
|
91
|
+
|
|
92
|
+
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.
|
|
73
93
|
|
|
74
94
|
Required flags: `-s/--source-document`, `--source-version-id`, `-m/--verification-method-id`, `-b/--beacon-id`.
|
|
75
95
|
|
|
96
|
+
### key
|
|
97
|
+
|
|
98
|
+
Manage keypairs in the encrypted keystore. All subcommands operate offline (no Bitcoin connection).
|
|
99
|
+
|
|
100
|
+
| Subcommand | Alias | Description |
|
|
101
|
+
|---|---|---|
|
|
102
|
+
| `key generate` | - | Generate a new keypair and store it. Flags: `--name <name>`, `--set-active` |
|
|
103
|
+
| `key list` | `ls` | List stored keys (id, fingerprint, name, active) |
|
|
104
|
+
| `key show <ref>` | - | Show a key's public material and tags (never prints the secret) |
|
|
105
|
+
| `key import` | - | Import a secret from a hex file (`--secret-file`) or a public key as watch-only (`--public`). Flags: `--name`, `--set-active` |
|
|
106
|
+
| `key export <ref>` | - | Export public material by default; `--secret --out <path>` writes the secret to a new 0600 file |
|
|
107
|
+
| `key delete <ref>` | `rm` | Delete a key. `--force` deletes even the active key |
|
|
108
|
+
| `key use <ref>` | - | Set the active key, persisted across invocations |
|
|
109
|
+
|
|
110
|
+
A key reference is a full URN, a unique `name` tag, or a unique fingerprint prefix.
|
|
111
|
+
|
|
112
|
+
### config
|
|
113
|
+
|
|
114
|
+
Read and write CLI configuration.
|
|
115
|
+
|
|
116
|
+
| Subcommand | Alias | Description |
|
|
117
|
+
|---|---|---|
|
|
118
|
+
| `config init` | - | Create a default config file with one profile per network. `--force` overwrites |
|
|
119
|
+
| `config get [path]` | - | Print a value at a dotted path, or the whole config |
|
|
120
|
+
| `config set <path> <value>` | - | Set a value at a dotted path (value parsed as JSON when valid, else a string) |
|
|
121
|
+
| `config unset <path>` | - | Delete a value at a dotted path |
|
|
122
|
+
| `config list` | `ls` | Print the entire config file |
|
|
123
|
+
|
|
124
|
+
### profile
|
|
125
|
+
|
|
126
|
+
Manage configuration profiles.
|
|
127
|
+
|
|
128
|
+
| Subcommand | Alias | Description |
|
|
129
|
+
|---|---|---|
|
|
130
|
+
| `profile add <name>` | - | Add an empty profile |
|
|
131
|
+
| `profile use <name>` | - | Set the active profile (writes `defaults.profile`) |
|
|
132
|
+
| `profile show [name]` | - | Show a profile (defaults to the active profile) |
|
|
133
|
+
| `profile remove <name>` | `rm` | Remove a profile |
|
|
134
|
+
|
|
135
|
+
### completion
|
|
136
|
+
|
|
137
|
+
`btcr2 completion [shell]` prints a shell completion script (bash, zsh, or fish) to stdout. Defaults to bash. For example: `eval "$(btcr2 completion bash)"`.
|
|
138
|
+
|
|
76
139
|
## Usage
|
|
77
140
|
|
|
78
141
|
### Create a DID
|
|
79
142
|
|
|
80
143
|
```bash
|
|
81
|
-
#
|
|
144
|
+
# Generate a fresh key (type=k), store it in the keystore, and print the identifier
|
|
145
|
+
btcr2 create -n regtest
|
|
146
|
+
|
|
147
|
+
# Deterministic (type=k): from an explicit compressed secp256k1 public key (33 bytes hex)
|
|
82
148
|
btcr2 create -t k -n regtest -b 02aa...
|
|
83
149
|
|
|
150
|
+
# Deterministic (type=k): from a stored key's public key
|
|
151
|
+
btcr2 create -t k -n regtest --signing-key mykey
|
|
152
|
+
|
|
84
153
|
# External (type=x): from a SHA-256 hash of a genesis document (32 bytes hex)
|
|
85
154
|
btcr2 create -t x -n bitcoin -b bb...
|
|
86
155
|
```
|
|
@@ -104,17 +173,36 @@ btcr2 resolve -i did:btcr2:k1qq... -p resolution-options.json
|
|
|
104
173
|
btcr2 -o json resolve -i did:btcr2:k1qq...
|
|
105
174
|
```
|
|
106
175
|
|
|
107
|
-
### Update a DID
|
|
108
|
-
|
|
109
|
-
The command is registered and flags are validated, but it will always exit with an error:
|
|
176
|
+
### Update a DID
|
|
110
177
|
|
|
178
|
+
```bash
|
|
179
|
+
# Signs with the active keystore key (or one chosen via --signing-key)
|
|
180
|
+
btcr2 update \
|
|
181
|
+
-s "$(cat did.json)" \
|
|
182
|
+
--source-version-id 1 \
|
|
183
|
+
-p '[{"op":"add","path":"/service/-","value":{"id":"#svc","type":"X","serviceEndpoint":"https://x"}}]' \
|
|
184
|
+
-m 'did:btcr2:k1qq...#key-0' \
|
|
185
|
+
-b '{"id":"#beacon-0","type":"SingletonBeacon","serviceEndpoint":"bitcoin:bc1..."}'
|
|
111
186
|
```
|
|
112
|
-
|
|
187
|
+
|
|
188
|
+
### Deactivate a DID
|
|
189
|
+
|
|
190
|
+
```bash
|
|
191
|
+
# Irreversible. Applies the deactivation patch and signs via the keystore.
|
|
192
|
+
btcr2 deactivate \
|
|
193
|
+
-s "$(cat did.json)" \
|
|
194
|
+
--source-version-id 1 \
|
|
195
|
+
-m 'did:btcr2:k1qq...#key-0' \
|
|
196
|
+
-b '{"id":"#beacon-0","type":"SingletonBeacon","serviceEndpoint":"bitcoin:bc1..."}'
|
|
113
197
|
```
|
|
114
198
|
|
|
115
|
-
###
|
|
199
|
+
### Manage keys
|
|
116
200
|
|
|
117
|
-
|
|
201
|
+
```bash
|
|
202
|
+
btcr2 key generate --name mykey --set-active
|
|
203
|
+
btcr2 key list
|
|
204
|
+
btcr2 key use mykey
|
|
205
|
+
```
|
|
118
206
|
|
|
119
207
|
## Configuration
|
|
120
208
|
|
|
@@ -135,6 +223,9 @@ Override precedence, highest wins: CLI flags, then environment variables, then c
|
|
|
135
223
|
| `--btc-rpc-user <user>` | Bitcoin Core RPC username |
|
|
136
224
|
| `--btc-rpc-pass <pass>` | Bitcoin Core RPC password |
|
|
137
225
|
| `--cas-gateway <url>` | IPFS HTTP gateway for CAS reads |
|
|
226
|
+
| `--keystore <path>` | Path to the keystore file (default: `$XDG_DATA_HOME/btcr2/keystore.json`) |
|
|
227
|
+
| `--passphrase-file <path>` | Read the keystore passphrase from a file (unattended use) |
|
|
228
|
+
| `--signing-key <ref>` | Key for create/update/deactivate signing: a URN, fingerprint prefix, or name |
|
|
138
229
|
|
|
139
230
|
### Environment variables
|
|
140
231
|
|