@did-btcr2/method 0.26.0 → 0.27.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 (282) hide show
  1. package/README.md +86 -233
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/browser.js +24111 -20342
  4. package/dist/browser.mjs +24111 -20342
  5. package/dist/cjs/index.js +2463 -2174
  6. package/dist/esm/core/aggregation/cohort.js +178 -0
  7. package/dist/esm/core/aggregation/cohort.js.map +1 -0
  8. package/dist/esm/core/aggregation/errors.js +22 -0
  9. package/dist/esm/core/aggregation/errors.js.map +1 -0
  10. package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
  11. package/dist/esm/core/aggregation/messages/base.js.map +1 -0
  12. package/dist/esm/core/aggregation/messages/constants.js +26 -0
  13. package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
  14. package/dist/esm/core/aggregation/messages/factories.js +113 -0
  15. package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
  16. package/dist/esm/core/aggregation/messages/guards.js +37 -0
  17. package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
  18. package/dist/esm/core/aggregation/messages/index.js +5 -0
  19. package/dist/esm/core/aggregation/messages/index.js.map +1 -0
  20. package/dist/esm/core/aggregation/participant.js +376 -0
  21. package/dist/esm/core/aggregation/participant.js.map +1 -0
  22. package/dist/esm/core/aggregation/phases.js +39 -0
  23. package/dist/esm/core/aggregation/phases.js.map +1 -0
  24. package/dist/esm/core/aggregation/runner/events.js +2 -0
  25. package/dist/esm/core/aggregation/runner/events.js.map +1 -0
  26. package/dist/esm/core/aggregation/runner/index.js +5 -0
  27. package/dist/esm/core/aggregation/runner/index.js.map +1 -0
  28. package/dist/esm/core/aggregation/runner/participant-runner.js +282 -0
  29. package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
  30. package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
  31. package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
  32. package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
  33. package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
  34. package/dist/esm/core/aggregation/service.js +416 -0
  35. package/dist/esm/core/aggregation/service.js.map +1 -0
  36. package/dist/esm/core/aggregation/signing-session.js +133 -0
  37. package/dist/esm/core/aggregation/signing-session.js.map +1 -0
  38. package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
  39. package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
  40. package/dist/esm/core/aggregation/transport/error.js +12 -0
  41. package/dist/esm/core/aggregation/transport/error.js.map +1 -0
  42. package/dist/esm/core/aggregation/transport/factory.js +20 -0
  43. package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
  44. package/dist/esm/core/aggregation/transport/index.js +6 -0
  45. package/dist/esm/core/aggregation/transport/index.js.map +1 -0
  46. package/dist/esm/core/aggregation/transport/nostr.js +262 -0
  47. package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
  48. package/dist/esm/core/aggregation/transport/transport.js +2 -0
  49. package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
  50. package/dist/esm/core/beacon/beacon.js +80 -0
  51. package/dist/esm/core/beacon/beacon.js.map +1 -1
  52. package/dist/esm/core/beacon/cas-beacon.js +15 -56
  53. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  54. package/dist/esm/core/beacon/error.js +0 -10
  55. package/dist/esm/core/beacon/error.js.map +1 -1
  56. package/dist/esm/core/beacon/fee-estimator.js +30 -0
  57. package/dist/esm/core/beacon/fee-estimator.js.map +1 -0
  58. package/dist/esm/core/beacon/singleton-beacon.js +10 -53
  59. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  60. package/dist/esm/core/beacon/smt-beacon.js +85 -9
  61. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  62. package/dist/esm/core/identifier.js +13 -0
  63. package/dist/esm/core/identifier.js.map +1 -1
  64. package/dist/esm/core/resolver.js +9 -0
  65. package/dist/esm/core/resolver.js.map +1 -1
  66. package/dist/esm/index.js +14 -24
  67. package/dist/esm/index.js.map +1 -1
  68. package/dist/types/core/aggregation/cohort.d.ts +94 -0
  69. package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
  70. package/dist/types/core/aggregation/errors.d.ts +14 -0
  71. package/dist/types/core/aggregation/errors.d.ts.map +1 -0
  72. package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
  73. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
  74. package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
  75. package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
  76. package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
  77. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
  78. package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
  79. package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
  80. package/dist/types/core/aggregation/messages/index.d.ts +5 -0
  81. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
  82. package/dist/types/core/aggregation/participant.d.ts +101 -0
  83. package/dist/types/core/aggregation/participant.d.ts.map +1 -0
  84. package/dist/types/core/aggregation/phases.d.ts +49 -0
  85. package/dist/types/core/aggregation/phases.d.ts.map +1 -0
  86. package/dist/types/core/aggregation/runner/events.d.ts +89 -0
  87. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
  88. package/dist/types/core/aggregation/runner/index.d.ts +5 -0
  89. package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
  90. package/dist/types/core/aggregation/runner/participant-runner.d.ts +107 -0
  91. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
  92. package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
  93. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
  94. package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
  95. package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
  96. package/dist/types/core/aggregation/service.d.ts +112 -0
  97. package/dist/types/core/aggregation/service.d.ts.map +1 -0
  98. package/dist/types/core/aggregation/signing-session.d.ts +69 -0
  99. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
  100. package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
  101. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
  102. package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
  103. package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
  104. package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
  105. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
  106. package/dist/types/core/aggregation/transport/index.d.ts +6 -0
  107. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
  108. package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
  109. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
  110. package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
  111. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
  112. package/dist/types/core/beacon/beacon.d.ts +37 -2
  113. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  114. package/dist/types/core/beacon/cas-beacon.d.ts +19 -7
  115. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  116. package/dist/types/core/beacon/error.d.ts +0 -6
  117. package/dist/types/core/beacon/error.d.ts.map +1 -1
  118. package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
  119. package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
  120. package/dist/types/core/beacon/interfaces.d.ts +8 -0
  121. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  122. package/dist/types/core/beacon/singleton-beacon.d.ts +9 -2
  123. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  124. package/dist/types/core/beacon/smt-beacon.d.ts +27 -7
  125. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  126. package/dist/types/core/identifier.d.ts +8 -0
  127. package/dist/types/core/identifier.d.ts.map +1 -1
  128. package/dist/types/core/interfaces.d.ts +2 -2
  129. package/dist/types/core/resolver.d.ts +11 -1
  130. package/dist/types/core/resolver.d.ts.map +1 -1
  131. package/dist/types/index.d.ts +9 -24
  132. package/dist/types/index.d.ts.map +1 -1
  133. package/package.json +31 -30
  134. package/src/core/aggregation/cohort.ts +247 -0
  135. package/src/core/aggregation/errors.ts +25 -0
  136. package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
  137. package/src/core/aggregation/messages/constants.ts +28 -0
  138. package/src/core/aggregation/messages/factories.ts +240 -0
  139. package/src/core/aggregation/messages/guards.ts +55 -0
  140. package/src/core/aggregation/messages/index.ts +4 -0
  141. package/src/core/aggregation/participant.ts +510 -0
  142. package/src/core/aggregation/phases.ts +82 -0
  143. package/src/core/aggregation/runner/events.ts +77 -0
  144. package/src/core/aggregation/runner/index.ts +4 -0
  145. package/src/core/aggregation/runner/participant-runner.ts +360 -0
  146. package/src/core/aggregation/runner/service-runner.ts +365 -0
  147. package/src/core/aggregation/runner/typed-emitter.ts +87 -0
  148. package/src/core/aggregation/service.ts +547 -0
  149. package/src/core/aggregation/signing-session.ts +209 -0
  150. package/src/core/aggregation/transport/didcomm.ts +42 -0
  151. package/src/core/aggregation/transport/error.ts +13 -0
  152. package/src/core/aggregation/transport/factory.ts +29 -0
  153. package/src/core/aggregation/transport/index.ts +5 -0
  154. package/src/core/aggregation/transport/nostr.ts +333 -0
  155. package/src/core/aggregation/transport/transport.ts +46 -0
  156. package/src/core/beacon/beacon.ts +122 -2
  157. package/src/core/beacon/cas-beacon.ts +28 -76
  158. package/src/core/beacon/error.ts +0 -12
  159. package/src/core/beacon/fee-estimator.ts +52 -0
  160. package/src/core/beacon/interfaces.ts +10 -1
  161. package/src/core/beacon/singleton-beacon.ts +14 -75
  162. package/src/core/beacon/smt-beacon.ts +109 -11
  163. package/src/core/identifier.ts +17 -0
  164. package/src/core/interfaces.ts +2 -2
  165. package/src/core/resolver.ts +25 -2
  166. package/src/index.ts +15 -29
  167. package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
  168. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
  169. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  170. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  171. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  172. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
  173. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  174. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  175. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  176. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  177. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  178. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  179. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  180. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  181. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  182. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  183. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  184. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  185. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  186. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  187. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  188. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  189. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  190. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  191. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  192. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  193. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  194. package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
  195. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
  196. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  197. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  198. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -245
  199. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  200. package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
  201. package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
  202. package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
  203. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
  204. package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
  205. package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
  206. package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
  207. package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
  208. package/dist/esm/core/beacon/aggregation/participant.js +0 -435
  209. package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
  210. package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
  211. package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
  212. package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
  213. package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
  214. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
  215. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
  216. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
  217. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
  218. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
  219. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
  220. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
  221. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
  222. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
  223. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
  224. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
  225. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
  226. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
  227. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
  228. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
  229. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
  230. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
  231. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
  232. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
  233. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
  234. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
  235. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
  236. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
  237. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
  238. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
  239. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
  240. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
  241. package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
  242. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
  243. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
  244. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
  245. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
  246. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
  247. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
  248. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
  249. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
  250. package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
  251. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
  252. package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
  253. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
  254. package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
  255. package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
  256. package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
  257. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
  258. package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
  259. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
  260. package/src/core/beacon/aggregation/cohort/index.ts +0 -305
  261. package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
  262. package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
  263. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -44
  264. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -40
  265. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -35
  266. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -34
  267. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -36
  268. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -39
  269. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -40
  270. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -40
  271. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -40
  272. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -41
  273. package/src/core/beacon/aggregation/cohort/status.ts +0 -7
  274. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -148
  275. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -323
  276. package/src/core/beacon/aggregation/communication/error.ts +0 -13
  277. package/src/core/beacon/aggregation/communication/factory.ts +0 -25
  278. package/src/core/beacon/aggregation/communication/service.ts +0 -42
  279. package/src/core/beacon/aggregation/coordinator.ts +0 -419
  280. package/src/core/beacon/aggregation/participant.ts +0 -517
  281. package/src/core/beacon/aggregation/session/index.ts +0 -301
  282. package/src/core/beacon/aggregation/session/status.ts +0 -18
package/README.md CHANGED
@@ -1,275 +1,128 @@
1
- # Method
1
+ # @did-btcr2/method
2
2
 
3
- TypeScript implementation of [did:btcr2 DID Method](https://dcdpr.github.io/did-btcr2/).
3
+ TypeScript reference implementation of the [did:btcr2 DID Method](https://dcdpr.github.io/did-btcr2/) — a censorship-resistant Decentralized Identifier method using Bitcoin as a verifiable data registry.
4
4
 
5
- ## Documentation
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).
8
-
9
- ## Test Vector Generator
10
-
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
-
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.
5
+ This package is the core of the `did-btcr2-js` monorepo. It implements DID create/resolve/update operations, the three beacon types (Singleton, CAS, SMT), multi-party aggregation over MuSig2, and a pluggable transport layer for peer-to-peer coordination.
14
6
 
15
- ### Quick Start
7
+ ## Installation
16
8
 
17
9
  ```bash
18
- # From packages/method/
19
-
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
23
-
24
- # 2. Construct and sign an update offline (use the hash printed by step 1)
25
- pnpm generate:vector update --hash <hash> --offline
26
-
27
- # 3. Fund the beacon address(es)
28
- source .env
29
- pnpm generate:vector fund --hash <hash>
30
-
31
- # 4. Announce the signed update on-chain
32
- pnpm generate:vector announce --hash <hash>
33
-
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
10
+ pnpm add @did-btcr2/method
40
11
  ```
41
12
 
42
- ### CLI Reference
43
-
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
13
+ ## What's in the Box
60
14
 
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 |
15
+ | Feature | Entry point |
16
+ |---|---|
17
+ | Create a DID (offline, deterministic or external) | `DidBtcr2.create()` |
18
+ | Resolve a DID (sans-I/O state machine) | `DidBtcr2.resolve()` |
19
+ | Construct, sign, and announce updates | `Update.construct()`, `Update.sign()`, `Update.announce()` |
20
+ | Beacon types (Singleton, CAS, SMT) | `SingletonBeacon`, `CASBeacon`, `SMTBeacon` |
21
+ | Fee estimation (pluggable) | `FeeEstimator`, `StaticFeeEstimator` |
22
+ | Multi-party aggregation (MuSig2) | `AggregationServiceRunner`, `AggregationParticipantRunner` |
23
+ | Transport abstraction (Nostr, DIDComm stub) | `Transport`, `NostrTransport` |
24
+ | DID document types and builders | `Btcr2DidDocument`, `DidDocumentBuilder` |
70
25
 
71
- > After `create`, the hash uniquely identifies the vector. The script finds the directory
72
- > automatically and derives the type and network from the stored DID.
26
+ ## Quick Start
73
27
 
74
- ### Actions
28
+ ### Create a DID
75
29
 
76
- #### `create`
30
+ ```typescript
31
+ import { DidBtcr2 } from '@did-btcr2/method';
32
+ import { SchnorrKeyPair } from '@did-btcr2/keypair';
77
33
 
78
- Creates a DID and writes the initial vector files. The `--genesis` flag behavior depends on the `--type`:
79
-
80
- - **k1**: `--genesis` is a compressed public key hex. If omitted, prompts for one. If blank, auto-generates a keypair.
81
- - **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.
82
-
83
- ```bash
84
- # Auto-generate everything
85
- pnpm generate:vector create
86
- pnpm generate:vector create --type external --network regtest
87
-
88
- # Bring your own genesis bytes
89
- pnpm generate:vector create --type key --genesis 02abc...def
90
- pnpm generate:vector create --type external --network regtest --genesis 82830a78...f83a99
34
+ // Deterministic (k-type) the identifier IS the public key
35
+ const keys = SchnorrKeyPair.generate();
36
+ const did = DidBtcr2.create(keys.publicKey.compressed, {
37
+ idType : 'KEY',
38
+ network : 'mutinynet',
39
+ });
40
+ // did:btcr2:k1q5p...
91
41
  ```
92
42
 
93
- **Outputs:**
94
- ```
95
- lib/data/{network}/{type}/{hash}/
96
- create/input.json # { idType, version, network, genesisBytes }
97
- create/output.json # { did }
98
- other.json # { genesisKeys: { secret, public }, genesisDocument? }
99
- ```
100
-
101
- The `--hash` for subsequent steps is printed to the console.
102
-
103
- #### `update`
104
-
105
- Reads back the create output, rebuilds the source document, constructs and signs an update.
43
+ ### Resolve a DID
106
44
 
107
- **Without `--interactive`:** applies a default patch that rotates the first SingletonBeacon service endpoint (P2PKH key rotation).
45
+ `DidBtcr2.resolve()` returns a sans-I/O state machine. The caller drives resolution by fulfilling typed data needs (beacon signals, CAS announcements, signed updates).
108
46
 
109
- **With `--interactive`:** prompts for JSON Patch operations with smart auto-generation (see below).
47
+ ```typescript
48
+ import { DidBtcr2 } from '@did-btcr2/method';
110
49
 
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
-
115
- ```bash
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>
123
- ```
124
-
125
- **Outputs:**
126
- ```
127
- lib/data/{network}/{type}/{hash}/
128
- update/input.json # { sourceDocument, patches, sourceVersionId, ... }
129
- update/output.json # { signedUpdate }
130
- other.json # (updated with generated keys)
131
- ```
50
+ const resolver = DidBtcr2.resolve(did, { sidecar });
51
+ let state = resolver.resolve();
132
52
 
133
- #### `fund`
134
-
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.**
53
+ while (state.status === 'action-required') {
54
+ for (const need of state.needs) {
55
+ const data = await fetchData(need); // your I/O goes here
56
+ resolver.provide(need, data);
57
+ }
58
+ state = resolver.resolve();
59
+ }
136
60
 
137
- ```bash
138
- source .env
139
- pnpm generate:vector fund --hash <hash>
140
- pnpm generate:vector fund --hash <hash> --amount 0.01
61
+ const { didDocument, metadata } = state.result;
141
62
  ```
142
63
 
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.
64
+ See [`src/core/resolver.ts`](./src/core/resolver.ts) for the full `DataNeed` union and phase transitions.
145
65
 
146
- #### `announce`
66
+ ### Construct and Sign an Update
147
67
 
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.
68
+ ```typescript
69
+ import { Update, Resolver } from '@did-btcr2/method';
149
70
 
150
- ```bash
151
- source .env
152
- pnpm generate:vector announce --hash <hash>
71
+ const doc = Resolver.deterministic({ genesisBytes: keys.publicKey.compressed, /* ... */ });
72
+ const unsigned = await Update.construct(doc, [
73
+ { op: 'add', path: '/service/-', value: { /* new service */ } },
74
+ ], 1);
75
+ const signed = Update.sign(did, unsigned, doc.verificationMethod![0], keys.raw.secret!);
153
76
  ```
154
77
 
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.
78
+ ### Update Aggregation (Multi-Party MuSig2)
157
79
 
158
- #### `resolve`
80
+ Aggregation lets multiple DID controllers coordinate a single Bitcoin transaction that announces all of their updates at once, signed n-of-n with MuSig2. The high-level `Runner` API hides the message routing and decision plumbing:
159
81
 
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).
82
+ ```typescript
83
+ import { AggregationServiceRunner, NostrTransport } from '@did-btcr2/method';
161
84
 
162
- **With `--offline`:** writes only the sidecar input file without connecting to Bitcoin.
85
+ const transport = new NostrTransport({ relays: ['wss://relay.damus.io'] });
86
+ transport.registerActor(serviceDid, serviceKeys);
87
+ transport.start();
163
88
 
164
- ```bash
165
- # Resolve against a live Bitcoin node
166
- source .env
167
- pnpm generate:vector resolve --hash <hash>
89
+ const runner = new AggregationServiceRunner({
90
+ transport,
91
+ did : serviceDid,
92
+ keys : serviceKeys,
93
+ config : { minParticipants: 2, network: 'mutinynet', beaconType: 'CASBeacon' },
94
+ onProvideTxData: async ({ beaconAddress, signalBytes }) => buildBeaconTx(beaconAddress, signalBytes),
95
+ });
168
96
 
169
- # Offline build sidecar input only
170
- pnpm generate:vector resolve --hash <hash> --offline
97
+ runner.on('signing-complete', (result) => console.log('done'));
98
+ const result = await runner.run();
171
99
  ```
172
100
 
173
- **Outputs:**
174
- ```
175
- lib/data/{network}/{type}/{hash}/
176
- resolve/input.json # { did, resolutionOptions: { sidecar } }
177
- resolve/output.json # { didDocument, didResolutionMetadata, didDocumentMetadata } (live only)
178
- ```
101
+ The full step-by-step protocol walkthrough — service flow, participant flow, decision callbacks, events, the low-level state machine API, and production deployment notes — is in [`docs/aggregation.md`](./docs/aggregation.md).
179
102
 
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.
103
+ ## Architecture Principles
182
104
 
183
- #### `list`
105
+ - **Sans-I/O core.** Resolver, Updater, and aggregation state machines perform zero I/O. They compute state transitions and emit typed needs or messages. Callers handle all network operations.
106
+ - **Layered APIs.** High-level facades (like `AggregationServiceRunner`) encapsulate boilerplate; low-level state machines stay available for tests, custom transports, and fine-grained control.
107
+ - **Pluggable transport.** The `Transport` interface decouples protocol logic from the wire format. Ships with `NostrTransport`; add your own for DIDComm, libp2p, or anything else.
108
+ - **Browser-compatible.** All code targets both Node.js (>= 22) and modern browsers. No Node-only APIs in the core.
184
109
 
185
- Displays existing test vectors filtered by network and type. If `--network` or `--type` are not provided, prompts interactively.
110
+ ## Build & Test
186
111
 
187
112
  ```bash
188
- pnpm generate:vector list
189
- pnpm generate:vector list --network regtest --type key
190
- ```
191
-
192
- ### Interactive Mode
193
-
194
- Pass `--interactive` to the `update` step to build custom patches. The tool detects common patch targets and auto-generates values.
195
-
196
- ```bash
197
- pnpm generate:vector update --hash <hash> --interactive
198
- ```
199
-
200
- #### Service patches (`/service/<n>`)
201
-
202
- When `add` or `replace` targets a path like `/service/0`, the tool:
203
-
204
- 1. Prompts for **address type** (`p2pkh`, `p2wpkh`, `p2tr`) — defaults to `p2pkh`
205
- 2. Prompts for **pubkey hex** — leave empty to auto-generate a new keypair
206
- 3. Derives the Bitcoin address and builds the complete service object
207
-
208
- ```
209
- --- Add a JSON Patch operation ---
210
- op: add
211
- path: /service/1
212
- Detected service patch — auto-generating value.
213
- address type (p2pkh | p2wpkh | p2tr) [p2pkh]: p2wpkh
214
- pubkey hex (leave empty to auto-generate):
215
- Auto-generated keypair (stored as "service-service-1")
216
- Added: {"op":"add","path":"/service/1","value":{"id":"did:btcr2:...#service-1","type":"SingletonBeacon","serviceEndpoint":"bitcoin:bcrt1q..."}}
217
- ```
218
-
219
- #### Verification method patches (`/verificationMethod/<n>`)
220
-
221
- When `add` or `replace` targets a path like `/verificationMethod/1`, the tool:
222
-
223
- 1. Prompts for an **id fragment** (e.g. `someNewId` or `#someNewId`) — defaults to `key-1`, `key-2`, etc.
224
- 2. Validates the id is unique against existing verification methods
225
- 3. Prompts for **pubkey hex** — leave empty to auto-generate
226
- 4. Builds the complete verification method object with `publicKeyMultibase`
227
-
228
- ```
229
- --- Add a JSON Patch operation ---
230
- op: add
231
- path: /verificationMethod/1
232
- Detected verificationMethod patch — auto-generating value.
233
- id fragment (e.g. "someNewId" or "#someNewId") [key-1]: recoveryKey
234
- pubkey hex (leave empty to auto-generate):
235
- Auto-generated keypair (stored as "verificationMethod-verificationMethod-1")
236
- Added: {"op":"add","path":"/verificationMethod/1","value":{"id":"did:btcr2:...#recoveryKey","type":"Multikey","controller":"did:btcr2:...","publicKeyMultibase":"zQ3sh..."}}
113
+ # From packages/method/
114
+ pnpm build # Compile ESM + CJS + browser bundle
115
+ pnpm build:tests # Compile tests to tests/compiled/
116
+ pnpm test # Run the test suite with coverage
117
+ pnpm lint # ESLint (zero warnings tolerated)
237
118
  ```
238
119
 
239
- #### Other patches
240
-
241
- For any path not matching the above patterns, or for operations like `remove`, `move`, `copy`, the tool falls back to manual JSON value input.
120
+ Tests run from compiled JS, so run `pnpm build:tests` before `pnpm test` after any test changes.
242
121
 
243
- ### Key Storage
244
-
245
- All generated and user-provided keys are persisted in `other.json` for later reuse:
246
-
247
- - **Auto-generated keys** include both `secret` and `public` hex values
248
- - **User-provided keys** store the `public` hex with an empty `secret` field for you to fill in if needed
249
-
250
- ```json
251
- {
252
- "genesisKeys": { "secret": "...", "public": "..." },
253
- "newBeaconKeys": { "secret": "...", "public": "..." },
254
- "generatedKeys": {
255
- "service-service-1": { "secret": "...", "public": "..." },
256
- "verificationMethod-verificationMethod-1": { "secret": "", "public": "..." }
257
- }
258
- }
259
- ```
260
-
261
- ### Output Directory Structure
122
+ ## Documentation
262
123
 
263
- ```
264
- lib/data/{network}/{type}/{hash}/
265
- create/
266
- input.json
267
- output.json
268
- update/
269
- input.json
270
- output.json
271
- resolve/
272
- input.json
273
- output.json # (live mode only)
274
- other.json
275
- ```
124
+ - **Package docs on btcr2.dev** — [btcr2.dev/impls/ts](https://btcr2.dev/impls/ts)
125
+ - **[`docs/beacon-system-overview.md`](./docs/beacon-system-overview.md)** — Beacon architecture, Singleton / CAS / SMT behavior, signal discovery
126
+ - **[`docs/aggregation.md`](./docs/aggregation.md)** — Multi-party aggregation protocol, Runner and state machine APIs, e2e examples
127
+ - **[`docs/test-vectors.md`](./docs/test-vectors.md)** — CLI tool for generating did:btcr2 test vectors via a stepped workflow
128
+ - **Source reference** — See JSDoc comments on public classes; the most important entry points are `DidBtcr2` (facade), `Resolver` (read path), `Update` (write path), and the aggregation runners.