@did-btcr2/method 0.23.0 → 0.25.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 (160) hide show
  1. package/README.md +96 -50
  2. package/dist/browser.js +36332 -37280
  3. package/dist/browser.mjs +36331 -37279
  4. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +1 -1
  5. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
  6. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +1 -1
  7. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  8. package/dist/cjs/core/beacon/aggregation/coordinator.js +40 -44
  9. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
  10. package/dist/cjs/core/beacon/aggregation/participant.js +35 -38
  11. package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
  12. package/dist/cjs/core/beacon/aggregation/session/index.js +3 -4
  13. package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
  14. package/dist/cjs/core/beacon/beacon.js.map +1 -1
  15. package/dist/cjs/core/beacon/cas-beacon.js +119 -7
  16. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
  17. package/dist/cjs/core/beacon/factory.js +1 -1
  18. package/dist/cjs/core/beacon/factory.js.map +1 -1
  19. package/dist/cjs/core/beacon/{singleton.js → singleton-beacon.js} +19 -27
  20. package/dist/cjs/core/beacon/singleton-beacon.js.map +1 -0
  21. package/dist/cjs/core/beacon/smt-beacon.js +1 -1
  22. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
  23. package/dist/cjs/core/identifier.js +1 -1
  24. package/dist/cjs/core/identifier.js.map +1 -1
  25. package/dist/{esm/core/resolve.js → cjs/core/resolver.js} +244 -92
  26. package/dist/cjs/core/resolver.js.map +1 -0
  27. package/dist/cjs/core/update.js +7 -7
  28. package/dist/cjs/core/update.js.map +1 -1
  29. package/dist/cjs/did-btcr2.js +34 -94
  30. package/dist/cjs/did-btcr2.js.map +1 -1
  31. package/dist/cjs/index.js +2 -3
  32. package/dist/cjs/index.js.map +1 -1
  33. package/dist/cjs/utils/did-document.js +9 -19
  34. package/dist/cjs/utils/did-document.js.map +1 -1
  35. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +1 -1
  36. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
  37. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +1 -1
  38. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  39. package/dist/esm/core/beacon/aggregation/coordinator.js +40 -44
  40. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  41. package/dist/esm/core/beacon/aggregation/participant.js +35 -38
  42. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  43. package/dist/esm/core/beacon/aggregation/session/index.js +3 -4
  44. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
  45. package/dist/esm/core/beacon/beacon.js.map +1 -1
  46. package/dist/esm/core/beacon/cas-beacon.js +119 -7
  47. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  48. package/dist/esm/core/beacon/factory.js +1 -1
  49. package/dist/esm/core/beacon/factory.js.map +1 -1
  50. package/dist/esm/core/beacon/{singleton.js → singleton-beacon.js} +19 -27
  51. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -0
  52. package/dist/esm/core/beacon/smt-beacon.js +1 -1
  53. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  54. package/dist/esm/core/identifier.js +1 -1
  55. package/dist/esm/core/identifier.js.map +1 -1
  56. package/dist/{cjs/core/resolve.js → esm/core/resolver.js} +244 -92
  57. package/dist/esm/core/resolver.js.map +1 -0
  58. package/dist/esm/core/update.js +7 -7
  59. package/dist/esm/core/update.js.map +1 -1
  60. package/dist/esm/did-btcr2.js +34 -94
  61. package/dist/esm/did-btcr2.js.map +1 -1
  62. package/dist/esm/index.js +2 -3
  63. package/dist/esm/index.js.map +1 -1
  64. package/dist/esm/utils/did-document.js +9 -19
  65. package/dist/esm/utils/did-document.js.map +1 -1
  66. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -0
  67. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +1 -0
  68. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +1 -0
  69. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +1 -0
  70. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +1 -0
  71. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +2 -2
  72. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -1
  73. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +1 -0
  74. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +1 -0
  75. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +1 -0
  76. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +1 -0
  77. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +1 -0
  78. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +1 -0
  79. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +1 -0
  80. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +1 -0
  81. package/dist/types/core/beacon/aggregation/cohort/status.d.ts +1 -0
  82. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +4 -3
  83. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -1
  84. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +5 -3
  85. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
  86. package/dist/types/core/beacon/aggregation/communication/error.d.ts +1 -0
  87. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +1 -0
  88. package/dist/types/core/beacon/aggregation/communication/service.d.ts +3 -2
  89. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +1 -1
  90. package/dist/types/core/beacon/aggregation/coordinator.d.ts +1 -0
  91. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  92. package/dist/types/core/beacon/aggregation/participant.d.ts +1 -0
  93. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  94. package/dist/types/core/beacon/aggregation/session/index.d.ts +1 -0
  95. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -1
  96. package/dist/types/core/beacon/aggregation/session/status.d.ts +1 -0
  97. package/dist/types/core/beacon/beacon.d.ts +10 -4
  98. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  99. package/dist/types/core/beacon/cas-beacon.d.ts +27 -7
  100. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  101. package/dist/types/core/beacon/error.d.ts +1 -0
  102. package/dist/types/core/beacon/factory.d.ts +1 -0
  103. package/dist/types/core/beacon/interfaces.d.ts +1 -0
  104. package/dist/types/core/beacon/signal-discovery.d.ts +1 -0
  105. package/dist/types/core/beacon/{singleton.d.ts → singleton-beacon.d.ts} +7 -5
  106. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -0
  107. package/dist/types/core/beacon/smt-beacon.d.ts +5 -3
  108. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  109. package/dist/types/core/beacon/utils.d.ts +1 -0
  110. package/dist/types/core/identifier.d.ts +1 -0
  111. package/dist/types/core/interfaces.d.ts +6 -15
  112. package/dist/types/core/interfaces.d.ts.map +1 -1
  113. package/dist/types/core/resolver.d.ts +167 -0
  114. package/dist/types/core/resolver.d.ts.map +1 -0
  115. package/dist/types/core/types.d.ts +1 -0
  116. package/dist/types/core/update.d.ts +4 -3
  117. package/dist/types/core/update.d.ts.map +1 -1
  118. package/dist/types/did-btcr2.d.ts +17 -16
  119. package/dist/types/did-btcr2.d.ts.map +1 -1
  120. package/dist/types/index.d.ts +3 -3
  121. package/dist/types/index.d.ts.map +1 -1
  122. package/dist/types/utils/appendix.d.ts +1 -0
  123. package/dist/types/utils/did-document-builder.d.ts +1 -0
  124. package/dist/types/utils/did-document.d.ts +2 -6
  125. package/dist/types/utils/did-document.d.ts.map +1 -1
  126. package/package.json +5 -5
  127. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +1 -1
  128. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +4 -3
  129. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +4 -3
  130. package/src/core/beacon/aggregation/communication/service.ts +2 -2
  131. package/src/core/beacon/aggregation/coordinator.ts +40 -44
  132. package/src/core/beacon/aggregation/participant.ts +38 -40
  133. package/src/core/beacon/aggregation/session/index.ts +3 -4
  134. package/src/core/beacon/beacon.ts +9 -5
  135. package/src/core/beacon/cas-beacon.ts +156 -10
  136. package/src/core/beacon/factory.ts +1 -1
  137. package/src/core/beacon/{singleton.ts → singleton-beacon.ts} +20 -36
  138. package/src/core/beacon/smt-beacon.ts +4 -3
  139. package/src/core/identifier.ts +1 -1
  140. package/src/core/interfaces.ts +5 -16
  141. package/src/core/resolver.ts +706 -0
  142. package/src/core/update.ts +9 -9
  143. package/src/did-btcr2.ts +37 -130
  144. package/src/index.ts +2 -3
  145. package/src/utils/did-document.ts +10 -18
  146. package/dist/cjs/core/beacon/singleton.js.map +0 -1
  147. package/dist/cjs/core/resolve.js.map +0 -1
  148. package/dist/cjs/utils/general.js +0 -195
  149. package/dist/cjs/utils/general.js.map +0 -1
  150. package/dist/esm/core/beacon/singleton.js.map +0 -1
  151. package/dist/esm/core/resolve.js.map +0 -1
  152. package/dist/esm/utils/general.js +0 -195
  153. package/dist/esm/utils/general.js.map +0 -1
  154. package/dist/types/core/beacon/singleton.d.ts.map +0 -1
  155. package/dist/types/core/resolve.d.ts +0 -92
  156. package/dist/types/core/resolve.d.ts.map +0 -1
  157. package/dist/types/utils/general.d.ts +0 -85
  158. package/dist/types/utils/general.d.ts.map +0 -1
  159. package/src/core/resolve.ts +0 -474
  160. package/src/utils/general.ts +0 -204
package/README.md CHANGED
@@ -8,47 +8,70 @@ Visit [btcr2.dev](https://btcr2.dev/impls/ts) to learn more about how to use [@d
8
8
 
9
9
  ## Test Vector Generator
10
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/`.
11
+ An incremental CLI tool for generating did:btcr2 test vectors through a stepped workflow: `create` `update` (offline) `fund` `announce` `resolve`. It produces JSON files under `lib/data/`.
12
12
 
13
- The `create` step runs offline. All subsequent steps only need `--hash` — the type and network are derived from the DID itself.
13
+ The first positional argument is the action. `create` runs offline. All subsequent actions only need `--hash` — the type and network are derived from the DID itself.
14
14
 
15
15
  ### Quick Start
16
16
 
17
17
  ```bash
18
18
  # From packages/method/
19
19
 
20
- # 1. Create a new DID (only step that takes --type and --network)
21
- pnpm generate:vector -- --type key --network regtest
20
+ # 1. Create a new DID (only action that takes --type and --network)
21
+ pnpm generate:vector create
22
+ pnpm generate:vector create --type external --network mutinynet
22
23
 
23
- # 2. Add update vectors (use the hash printed by step 1)
24
- pnpm generate:vector -- --step update --hash <hash>
24
+ # 2. Construct and sign an update offline (use the hash printed by step 1)
25
+ pnpm generate:vector update --hash <hash> --offline
25
26
 
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)
27
+ # 3. Fund the beacon address(es)
30
28
  source .env
31
- pnpm generate:vector -- --step announce --hash <hash>
29
+ pnpm generate:vector fund --hash <hash>
30
+
31
+ # 4. Announce the signed update on-chain
32
+ pnpm generate:vector announce --hash <hash>
32
33
 
33
- # 5. Resolve against live Bitcoin node
34
- pnpm generate:vector -- --step resolve-live --hash <hash>
34
+ # 5. Resolve the DID against a live Bitcoin node
35
+ pnpm generate:vector resolve --hash <hash>
36
+
37
+ # List existing vectors
38
+ pnpm generate:vector list
39
+ pnpm generate:vector list --network regtest --type key
35
40
  ```
36
41
 
37
- ### CLI Flags
42
+ ### CLI Reference
38
43
 
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`) |
44
+ ```
45
+ pnpm generate:vector <action> [options]
46
+ ```
47
+
48
+ #### Actions
49
+
50
+ | Action | Description |
51
+ |--------|-------------|
52
+ | `create` | Create a new DID and initial test vector files |
53
+ | `update` | Construct and sign an update (optionally announce) |
54
+ | `fund` | Fund beacon address(es) via RPC `sendtoaddress` + mine a block |
55
+ | `announce` | Announce a previously signed update on-chain |
56
+ | `resolve` | Resolve a DID against a live Bitcoin node |
57
+ | `list` | Show existing test vectors |
58
+
59
+ #### Options
60
+
61
+ | Flag | Values | Default | Applies to | Description |
62
+ |------|--------|---------|------------|-------------|
63
+ | `--type` | `key`, `external` | `key` | `create`, `list` | DID identifier type |
64
+ | `--network` | `regtest`, `bitcoin`, `mutinynet`, etc. | `regtest` | `create`, `list` | Bitcoin network |
65
+ | `--genesis` | hex string | prompt / auto-generate | `create` | Genesis bytes hex (see below) |
66
+ | `--hash` | 8-char short hash | — | `update`, `fund`, `announce`, `resolve` | Vector identifier (required) |
67
+ | `--interactive` | flag (no value) | off | `update` | Enable interactive patch builder |
68
+ | `--amount` | BTC amount | `0.001` | `fund` | BTC amount to send to each beacon address |
69
+ | `--offline` | flag (no value) | off | `update`, `resolve` | Skip on-chain announcement or live resolution |
47
70
 
48
71
  > After `create`, the hash uniquely identifies the vector. The script finds the directory
49
72
  > automatically and derives the type and network from the stored DID.
50
73
 
51
- ### Steps
74
+ ### Actions
52
75
 
53
76
  #### `create`
54
77
 
@@ -59,12 +82,12 @@ Creates a DID and writes the initial vector files. The `--genesis` flag behavior
59
82
 
60
83
  ```bash
61
84
  # Auto-generate everything
62
- pnpm generate:vector -- --type key --network regtest
63
- pnpm generate:vector -- --type external --network regtest
85
+ pnpm generate:vector create
86
+ pnpm generate:vector create --type external --network regtest
64
87
 
65
88
  # 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
89
+ pnpm generate:vector create --type key --genesis 02abc...def
90
+ pnpm generate:vector create --type external --network regtest --genesis 82830a78...f83a99
68
91
  ```
69
92
 
70
93
  **Outputs:**
@@ -85,9 +108,18 @@ Reads back the create output, rebuilds the source document, constructs and signs
85
108
 
86
109
  **With `--interactive`:** prompts for JSON Patch operations with smart auto-generation (see below).
87
110
 
111
+ **With `--offline`:** builds and signs the update but skips the on-chain announcement. This is the typical workflow — use `fund` and `announce` as separate steps afterward.
112
+
113
+ **Without `--offline`:** also announces the update on-chain immediately (requires a funded beacon address and `BITCOIN_NETWORK_CONFIG`).
114
+
88
115
  ```bash
89
- pnpm generate:vector -- --step update --hash <hash>
90
- pnpm generate:vector -- --step update --hash <hash> --interactive
116
+ # Recommended: sign offline, then fund and announce separately
117
+ pnpm generate:vector update --hash <hash> --offline
118
+ pnpm generate:vector update --hash <hash> --offline --interactive
119
+
120
+ # Or sign and announce in one step (beacon must already be funded)
121
+ source .env
122
+ pnpm generate:vector update --hash <hash>
91
123
  ```
92
124
 
93
125
  **Outputs:**
@@ -98,58 +130,71 @@ lib/data/{network}/{type}/{hash}/
98
130
  other.json # (updated with generated keys)
99
131
  ```
100
132
 
101
- #### `resolve`
133
+ #### `fund`
102
134
 
103
- Assembles a sidecar from the signed update (and genesis document for x1 types) and writes the resolve input. Offline no Bitcoin node needed.
135
+ Funds all beacon service addresses in the DID document via RPC `sendtoaddress`, then mines blocks to confirm the funding transaction(s). **Requires a live Bitcoin node with a loaded wallet.**
104
136
 
105
137
  ```bash
106
- pnpm generate:vector -- --step resolve --hash <hash>
138
+ source .env
139
+ pnpm generate:vector fund --hash <hash>
140
+ pnpm generate:vector fund --hash <hash> --amount 0.01
107
141
  ```
108
142
 
109
- **Outputs:**
110
- ```
111
- lib/data/{network}/{type}/{hash}/
112
- resolve/input.json # { did, resolutionOptions: { sidecar } }
113
- ```
143
+ > Requires `BITCOIN_NETWORK_CONFIG` to be set with connection info
144
+ > for the DID's network. Source your `.env` file or export it directly.
114
145
 
115
146
  #### `announce`
116
147
 
117
- Broadcasts the signed update to Bitcoin via the beacon service. **Requires a live Bitcoin node.**
148
+ Announces a previously signed update on-chain via the beacon service. Reads the signed update and beacon metadata from the `update` step's persisted files. Useful for retrying a failed announcement without re-running the full update pipeline.
118
149
 
119
150
  ```bash
120
151
  source .env
121
- pnpm generate:vector -- --step announce --hash <hash>
152
+ pnpm generate:vector announce --hash <hash>
122
153
  ```
123
154
 
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.
155
+ > Requires `BITCOIN_NETWORK_CONFIG` to be set with connection info
156
+ > for the DID's network. Source your `.env` file or export it directly.
125
157
 
126
- #### `resolve-live`
158
+ #### `resolve`
127
159
 
128
- Resolves the DID against a live Bitcoin node and writes the resolution result. **Requires a live Bitcoin node.**
160
+ Resolves a DID against a live Bitcoin node. Assembles a sidecar from the signed update (if the update step has been run) and the genesis document (for x1 types).
161
+
162
+ **With `--offline`:** writes only the sidecar input file without connecting to Bitcoin.
129
163
 
130
164
  ```bash
165
+ # Resolve against a live Bitcoin node
131
166
  source .env
132
- pnpm generate:vector -- --step resolve-live --hash <hash>
133
- ```
167
+ pnpm generate:vector resolve --hash <hash>
134
168
 
135
- Reads `resolve/input.json`, injects the Bitcoin driver, calls `DidBtcr2.resolve()`, and writes the result.
169
+ # Offline build sidecar input only
170
+ pnpm generate:vector resolve --hash <hash> --offline
171
+ ```
136
172
 
137
173
  **Outputs:**
138
174
  ```
139
175
  lib/data/{network}/{type}/{hash}/
140
- resolve/output.json # { didDocument, didResolutionMetadata, didDocumentMetadata }
176
+ resolve/input.json # { did, resolutionOptions: { sidecar } }
177
+ resolve/output.json # { didDocument, didResolutionMetadata, didDocumentMetadata } (live only)
141
178
  ```
142
179
 
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.
180
+ > Live resolution requires `BITCOIN_NETWORK_CONFIG` to be set with connection info
181
+ > for the DID's network. Source your `.env` file or export it directly.
182
+
183
+ #### `list`
184
+
185
+ Displays existing test vectors filtered by network and type. If `--network` or `--type` are not provided, prompts interactively.
186
+
187
+ ```bash
188
+ pnpm generate:vector list
189
+ pnpm generate:vector list --network regtest --type key
190
+ ```
146
191
 
147
192
  ### Interactive Mode
148
193
 
149
194
  Pass `--interactive` to the `update` step to build custom patches. The tool detects common patch targets and auto-generates values.
150
195
 
151
196
  ```bash
152
- pnpm generate:vector -- --step update --hash <hash> --interactive
197
+ pnpm generate:vector update --hash <hash> --interactive
153
198
  ```
154
199
 
155
200
  #### Service patches (`/service/<n>`)
@@ -225,5 +270,6 @@ lib/data/{network}/{type}/{hash}/
225
270
  output.json
226
271
  resolve/
227
272
  input.json
273
+ output.json # (live mode only)
228
274
  other.json
229
275
  ```