@did-btcr2/method 0.19.0 → 0.22.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.
- package/README.md +223 -1
- package/dist/browser.js +3496 -4202
- package/dist/browser.mjs +3496 -4202
- package/dist/cjs/core/beacon/beacon.js +25 -0
- package/dist/cjs/core/beacon/beacon.js.map +1 -0
- package/dist/cjs/core/beacon/cas-beacon.js +20 -36
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/error.js +4 -4
- package/dist/cjs/core/beacon/error.js.map +1 -1
- package/dist/cjs/core/beacon/factory.js +5 -7
- package/dist/cjs/core/beacon/factory.js.map +1 -1
- package/dist/cjs/core/beacon/interfaces.js +1 -31
- package/dist/cjs/core/beacon/interfaces.js.map +1 -1
- package/dist/cjs/core/beacon/signal-discovery.js +183 -0
- package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
- package/dist/cjs/core/beacon/singleton.js +56 -86
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js +22 -39
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/utils.js +4 -9
- package/dist/cjs/core/beacon/utils.js.map +1 -1
- package/dist/cjs/core/resolve.js +121 -307
- package/dist/cjs/core/resolve.js.map +1 -1
- package/dist/cjs/core/update.js +62 -154
- package/dist/cjs/core/update.js.map +1 -1
- package/dist/cjs/did-btcr2.js +100 -91
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/appendix.js +6 -15
- package/dist/cjs/utils/appendix.js.map +1 -1
- package/dist/cjs/utils/did-document-builder.js +5 -6
- package/dist/cjs/utils/did-document-builder.js.map +1 -1
- package/dist/cjs/utils/did-document.js +42 -38
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/esm/core/beacon/beacon.js +25 -0
- package/dist/esm/core/beacon/beacon.js.map +1 -0
- package/dist/esm/core/beacon/cas-beacon.js +20 -36
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/error.js +4 -4
- package/dist/esm/core/beacon/error.js.map +1 -1
- package/dist/esm/core/beacon/factory.js +5 -7
- package/dist/esm/core/beacon/factory.js.map +1 -1
- package/dist/esm/core/beacon/interfaces.js +1 -31
- package/dist/esm/core/beacon/interfaces.js.map +1 -1
- package/dist/esm/core/beacon/signal-discovery.js +183 -0
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
- package/dist/esm/core/beacon/singleton.js +56 -86
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +22 -39
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/beacon/utils.js +4 -9
- package/dist/esm/core/beacon/utils.js.map +1 -1
- package/dist/esm/core/resolve.js +121 -307
- package/dist/esm/core/resolve.js.map +1 -1
- package/dist/esm/core/update.js +62 -154
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +100 -91
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/appendix.js +6 -15
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js +5 -6
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +42 -38
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +44 -0
- package/dist/types/core/beacon/beacon.d.ts.map +1 -0
- package/dist/types/core/beacon/cas-beacon.d.ts +19 -30
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/error.d.ts +2 -2
- package/dist/types/core/beacon/error.d.ts.map +1 -1
- package/dist/types/core/beacon/factory.d.ts +4 -6
- package/dist/types/core/beacon/factory.d.ts.map +1 -1
- package/dist/types/core/beacon/interfaces.d.ts +7 -46
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
- package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
- package/dist/types/core/beacon/singleton.d.ts +17 -30
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +21 -33
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/utils.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +1 -8
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolve.d.ts +34 -47
- package/dist/types/core/resolve.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +21 -8
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/update.d.ts +30 -73
- package/dist/types/core/update.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +44 -47
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +5 -1
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +26 -21
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +8 -7
- package/src/core/beacon/beacon.ts +58 -0
- package/src/core/beacon/cas-beacon.ts +30 -44
- package/src/core/beacon/error.ts +5 -6
- package/src/core/beacon/factory.ts +7 -9
- package/src/core/beacon/interfaces.ts +7 -64
- package/src/core/beacon/signal-discovery.ts +237 -0
- package/src/core/beacon/singleton.ts +78 -100
- package/src/core/beacon/smt-beacon.ts +32 -49
- package/src/core/beacon/utils.ts +16 -13
- package/src/core/interfaces.ts +1 -9
- package/src/core/resolve.ts +163 -395
- package/src/core/types.ts +25 -8
- package/src/core/update.ts +91 -236
- package/src/did-btcr2.ts +154 -116
- package/src/index.ts +8 -1
- package/src/utils/appendix.ts +8 -22
- package/src/utils/did-document-builder.ts +5 -7
- package/src/utils/did-document.ts +80 -73
package/README.md
CHANGED
|
@@ -4,4 +4,226 @@ TypeScript implementation of [did:btcr2 DID Method](https://dcdpr.github.io/did-
|
|
|
4
4
|
|
|
5
5
|
## Documentation
|
|
6
6
|
|
|
7
|
-
Visit [btcr2.dev](https://btcr2.dev/impls/ts) to learn more about how to use [@did-btcr2/method](https://www.npmjs.com/package/@did-btcr2/method).
|
|
7
|
+
Visit [btcr2.dev](https://btcr2.dev/impls/ts) to learn more about how to use [@did-btcr2/method](https://www.npmjs.com/package/@did-btcr2/method).
|
|
8
|
+
|
|
9
|
+
## Test Vector Generator
|
|
10
|
+
|
|
11
|
+
An incremental CLI tool for generating did:btcr2 test vectors. It produces JSON files that mirror the structure expected by the test suite under `lib/data/`.
|
|
12
|
+
|
|
13
|
+
The `create` step runs offline. All subsequent steps only need `--hash` — the type and network are derived from the DID itself.
|
|
14
|
+
|
|
15
|
+
### Quick Start
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
# From packages/method/
|
|
19
|
+
|
|
20
|
+
# 1. Create a new DID (only step that takes --type and --network)
|
|
21
|
+
pnpm generate:vector -- --type key --network regtest
|
|
22
|
+
|
|
23
|
+
# 2. Add update vectors (use the hash printed by step 1)
|
|
24
|
+
pnpm generate:vector -- --step update --hash <hash>
|
|
25
|
+
|
|
26
|
+
# 3. Add resolve vectors (offline — builds sidecar input)
|
|
27
|
+
pnpm generate:vector -- --step resolve --hash <hash>
|
|
28
|
+
|
|
29
|
+
# 4. Announce update to Bitcoin (requires live node)
|
|
30
|
+
source .env
|
|
31
|
+
pnpm generate:vector -- --step announce --hash <hash>
|
|
32
|
+
|
|
33
|
+
# 5. Resolve against live Bitcoin node
|
|
34
|
+
pnpm generate:vector -- --step resolve-live --hash <hash>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### CLI Flags
|
|
38
|
+
|
|
39
|
+
| Flag | Values | Default | Description |
|
|
40
|
+
|------|--------|---------|-------------|
|
|
41
|
+
| `--step` | `create`, `update`, `resolve`, `announce`, `resolve-live` | `create` | Which step to run |
|
|
42
|
+
| `--type` | `key`, `external` | `key` | DID identifier type — **create only** |
|
|
43
|
+
| `--network` | `regtest`, `bitcoin`, `mutinynet`, etc. | `regtest` | Bitcoin network — **create only** |
|
|
44
|
+
| `--genesis` | hex string | prompt / auto-generate | Genesis bytes hex — **create only** (see below) |
|
|
45
|
+
| `--hash` | 8-char short hash | — | Vector identifier (required for all steps except `create`) |
|
|
46
|
+
| `--interactive` | flag (no value) | off | Enable interactive patch builder (used with `update`) |
|
|
47
|
+
|
|
48
|
+
> After `create`, the hash uniquely identifies the vector. The script finds the directory
|
|
49
|
+
> automatically and derives the type and network from the stored DID.
|
|
50
|
+
|
|
51
|
+
### Steps
|
|
52
|
+
|
|
53
|
+
#### `create`
|
|
54
|
+
|
|
55
|
+
Creates a DID and writes the initial vector files. The `--genesis` flag behavior depends on the `--type`:
|
|
56
|
+
|
|
57
|
+
- **k1**: `--genesis` is a compressed public key hex. If omitted, prompts for one. If blank, auto-generates a keypair.
|
|
58
|
+
- **x1**: `--genesis` is a SHA-256 hash hex of a genesis document. If omitted, prompts for a JSON genesis document or hex hash. If blank, auto-generates a keypair and default genesis document.
|
|
59
|
+
|
|
60
|
+
```bash
|
|
61
|
+
# Auto-generate everything
|
|
62
|
+
pnpm generate:vector -- --type key --network regtest
|
|
63
|
+
pnpm generate:vector -- --type external --network regtest
|
|
64
|
+
|
|
65
|
+
# Bring your own genesis bytes
|
|
66
|
+
pnpm generate:vector -- --type key --network regtest --genesis 02abc...def
|
|
67
|
+
pnpm generate:vector -- --type external --network regtest --genesis 82830a78...f83a99
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
**Outputs:**
|
|
71
|
+
```
|
|
72
|
+
lib/data/{network}/{type}/{hash}/
|
|
73
|
+
create/input.json # { idType, version, network, genesisBytes }
|
|
74
|
+
create/output.json # { did }
|
|
75
|
+
other.json # { genesisKeys: { secret, public }, genesisDocument? }
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
The `--hash` for subsequent steps is printed to the console.
|
|
79
|
+
|
|
80
|
+
#### `update`
|
|
81
|
+
|
|
82
|
+
Reads back the create output, rebuilds the source document, constructs and signs an update.
|
|
83
|
+
|
|
84
|
+
**Without `--interactive`:** applies a default patch that rotates the first SingletonBeacon service endpoint (P2PKH key rotation).
|
|
85
|
+
|
|
86
|
+
**With `--interactive`:** prompts for JSON Patch operations with smart auto-generation (see below).
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
pnpm generate:vector -- --step update --hash <hash>
|
|
90
|
+
pnpm generate:vector -- --step update --hash <hash> --interactive
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
**Outputs:**
|
|
94
|
+
```
|
|
95
|
+
lib/data/{network}/{type}/{hash}/
|
|
96
|
+
update/input.json # { sourceDocument, patches, sourceVersionId, ... }
|
|
97
|
+
update/output.json # { signedUpdate }
|
|
98
|
+
other.json # (updated with generated keys)
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
#### `resolve`
|
|
102
|
+
|
|
103
|
+
Assembles a sidecar from the signed update (and genesis document for x1 types) and writes the resolve input. Offline — no Bitcoin node needed.
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
pnpm generate:vector -- --step resolve --hash <hash>
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
**Outputs:**
|
|
110
|
+
```
|
|
111
|
+
lib/data/{network}/{type}/{hash}/
|
|
112
|
+
resolve/input.json # { did, resolutionOptions: { sidecar } }
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
#### `announce`
|
|
116
|
+
|
|
117
|
+
Broadcasts the signed update to Bitcoin via the beacon service. **Requires a live Bitcoin node.**
|
|
118
|
+
|
|
119
|
+
```bash
|
|
120
|
+
source .env
|
|
121
|
+
pnpm generate:vector -- --step announce --hash <hash>
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
Reads `update/input.json` (for the beacon service and signing material) and `update/output.json` (for the signed update), then calls `Update.announce()` to broadcast to Bitcoin.
|
|
125
|
+
|
|
126
|
+
#### `resolve-live`
|
|
127
|
+
|
|
128
|
+
Resolves the DID against a live Bitcoin node and writes the resolution result. **Requires a live Bitcoin node.**
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
source .env
|
|
132
|
+
pnpm generate:vector -- --step resolve-live --hash <hash>
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
Reads `resolve/input.json`, injects the Bitcoin driver, calls `DidBtcr2.resolve()`, and writes the result.
|
|
136
|
+
|
|
137
|
+
**Outputs:**
|
|
138
|
+
```
|
|
139
|
+
lib/data/{network}/{type}/{hash}/
|
|
140
|
+
resolve/output.json # { didDocument, didResolutionMetadata, didDocumentMetadata }
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
> Both `announce` and `resolve-live` require `BITCOIN_NETWORK_CONFIG` to be set with
|
|
144
|
+
> connection info for the DID's network. Source your `.env` file or export it directly.
|
|
145
|
+
> The script validates the connection before proceeding and exits cleanly if misconfigured.
|
|
146
|
+
|
|
147
|
+
### Interactive Mode
|
|
148
|
+
|
|
149
|
+
Pass `--interactive` to the `update` step to build custom patches. The tool detects common patch targets and auto-generates values.
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
pnpm generate:vector -- --step update --hash <hash> --interactive
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
#### Service patches (`/service/<n>`)
|
|
156
|
+
|
|
157
|
+
When `add` or `replace` targets a path like `/service/0`, the tool:
|
|
158
|
+
|
|
159
|
+
1. Prompts for **address type** (`p2pkh`, `p2wpkh`, `p2tr`) — defaults to `p2pkh`
|
|
160
|
+
2. Prompts for **pubkey hex** — leave empty to auto-generate a new keypair
|
|
161
|
+
3. Derives the Bitcoin address and builds the complete service object
|
|
162
|
+
|
|
163
|
+
```
|
|
164
|
+
--- Add a JSON Patch operation ---
|
|
165
|
+
op: add
|
|
166
|
+
path: /service/1
|
|
167
|
+
Detected service patch — auto-generating value.
|
|
168
|
+
address type (p2pkh | p2wpkh | p2tr) [p2pkh]: p2wpkh
|
|
169
|
+
pubkey hex (leave empty to auto-generate):
|
|
170
|
+
Auto-generated keypair (stored as "service-service-1")
|
|
171
|
+
Added: {"op":"add","path":"/service/1","value":{"id":"did:btcr2:...#service-1","type":"SingletonBeacon","serviceEndpoint":"bitcoin:bcrt1q..."}}
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
#### Verification method patches (`/verificationMethod/<n>`)
|
|
175
|
+
|
|
176
|
+
When `add` or `replace` targets a path like `/verificationMethod/1`, the tool:
|
|
177
|
+
|
|
178
|
+
1. Prompts for an **id fragment** (e.g. `someNewId` or `#someNewId`) — defaults to `key-1`, `key-2`, etc.
|
|
179
|
+
2. Validates the id is unique against existing verification methods
|
|
180
|
+
3. Prompts for **pubkey hex** — leave empty to auto-generate
|
|
181
|
+
4. Builds the complete verification method object with `publicKeyMultibase`
|
|
182
|
+
|
|
183
|
+
```
|
|
184
|
+
--- Add a JSON Patch operation ---
|
|
185
|
+
op: add
|
|
186
|
+
path: /verificationMethod/1
|
|
187
|
+
Detected verificationMethod patch — auto-generating value.
|
|
188
|
+
id fragment (e.g. "someNewId" or "#someNewId") [key-1]: recoveryKey
|
|
189
|
+
pubkey hex (leave empty to auto-generate):
|
|
190
|
+
Auto-generated keypair (stored as "verificationMethod-verificationMethod-1")
|
|
191
|
+
Added: {"op":"add","path":"/verificationMethod/1","value":{"id":"did:btcr2:...#recoveryKey","type":"Multikey","controller":"did:btcr2:...","publicKeyMultibase":"zQ3sh..."}}
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
#### Other patches
|
|
195
|
+
|
|
196
|
+
For any path not matching the above patterns, or for operations like `remove`, `move`, `copy`, the tool falls back to manual JSON value input.
|
|
197
|
+
|
|
198
|
+
### Key Storage
|
|
199
|
+
|
|
200
|
+
All generated and user-provided keys are persisted in `other.json` for later reuse:
|
|
201
|
+
|
|
202
|
+
- **Auto-generated keys** include both `secret` and `public` hex values
|
|
203
|
+
- **User-provided keys** store the `public` hex with an empty `secret` field for you to fill in if needed
|
|
204
|
+
|
|
205
|
+
```json
|
|
206
|
+
{
|
|
207
|
+
"genesisKeys": { "secret": "...", "public": "..." },
|
|
208
|
+
"newBeaconKeys": { "secret": "...", "public": "..." },
|
|
209
|
+
"generatedKeys": {
|
|
210
|
+
"service-service-1": { "secret": "...", "public": "..." },
|
|
211
|
+
"verificationMethod-verificationMethod-1": { "secret": "", "public": "..." }
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
### Output Directory Structure
|
|
217
|
+
|
|
218
|
+
```
|
|
219
|
+
lib/data/{network}/{type}/{hash}/
|
|
220
|
+
create/
|
|
221
|
+
input.json
|
|
222
|
+
output.json
|
|
223
|
+
update/
|
|
224
|
+
input.json
|
|
225
|
+
output.json
|
|
226
|
+
resolve/
|
|
227
|
+
input.json
|
|
228
|
+
other.json
|
|
229
|
+
```
|