@did-btcr2/method 0.26.0 → 0.28.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 (297) hide show
  1. package/README.md +118 -236
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/browser.js +27665 -23764
  4. package/dist/browser.mjs +27665 -23764
  5. package/dist/cjs/index.js +2661 -2239
  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 +286 -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/core/updater.js +269 -0
  67. package/dist/esm/core/updater.js.map +1 -0
  68. package/dist/esm/did-btcr2.js +30 -42
  69. package/dist/esm/did-btcr2.js.map +1 -1
  70. package/dist/esm/index.js +16 -25
  71. package/dist/esm/index.js.map +1 -1
  72. package/dist/types/core/aggregation/cohort.d.ts +94 -0
  73. package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
  74. package/dist/types/core/aggregation/errors.d.ts +14 -0
  75. package/dist/types/core/aggregation/errors.d.ts.map +1 -0
  76. package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
  77. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
  78. package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
  79. package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
  80. package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
  81. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
  82. package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
  83. package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
  84. package/dist/types/core/aggregation/messages/index.d.ts +5 -0
  85. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
  86. package/dist/types/core/aggregation/participant.d.ts +101 -0
  87. package/dist/types/core/aggregation/participant.d.ts.map +1 -0
  88. package/dist/types/core/aggregation/phases.d.ts +49 -0
  89. package/dist/types/core/aggregation/phases.d.ts.map +1 -0
  90. package/dist/types/core/aggregation/runner/events.d.ts +89 -0
  91. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
  92. package/dist/types/core/aggregation/runner/index.d.ts +5 -0
  93. package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
  94. package/dist/types/core/aggregation/runner/participant-runner.d.ts +111 -0
  95. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
  96. package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
  97. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
  98. package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
  99. package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
  100. package/dist/types/core/aggregation/service.d.ts +112 -0
  101. package/dist/types/core/aggregation/service.d.ts.map +1 -0
  102. package/dist/types/core/aggregation/signing-session.d.ts +69 -0
  103. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
  104. package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
  105. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
  106. package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
  107. package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
  108. package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
  109. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
  110. package/dist/types/core/aggregation/transport/index.d.ts +6 -0
  111. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
  112. package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
  113. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
  114. package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
  115. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
  116. package/dist/types/core/beacon/beacon.d.ts +37 -2
  117. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  118. package/dist/types/core/beacon/cas-beacon.d.ts +19 -7
  119. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  120. package/dist/types/core/beacon/error.d.ts +0 -6
  121. package/dist/types/core/beacon/error.d.ts.map +1 -1
  122. package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
  123. package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
  124. package/dist/types/core/beacon/interfaces.d.ts +8 -0
  125. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  126. package/dist/types/core/beacon/singleton-beacon.d.ts +9 -2
  127. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  128. package/dist/types/core/beacon/smt-beacon.d.ts +27 -7
  129. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  130. package/dist/types/core/identifier.d.ts +8 -0
  131. package/dist/types/core/identifier.d.ts.map +1 -1
  132. package/dist/types/core/interfaces.d.ts +2 -2
  133. package/dist/types/core/resolver.d.ts +11 -1
  134. package/dist/types/core/resolver.d.ts.map +1 -1
  135. package/dist/types/core/updater.d.ts +178 -0
  136. package/dist/types/core/updater.d.ts.map +1 -0
  137. package/dist/types/did-btcr2.d.ts +23 -23
  138. package/dist/types/did-btcr2.d.ts.map +1 -1
  139. package/dist/types/index.d.ts +11 -25
  140. package/dist/types/index.d.ts.map +1 -1
  141. package/package.json +31 -30
  142. package/src/core/aggregation/cohort.ts +247 -0
  143. package/src/core/aggregation/errors.ts +25 -0
  144. package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
  145. package/src/core/aggregation/messages/constants.ts +28 -0
  146. package/src/core/aggregation/messages/factories.ts +240 -0
  147. package/src/core/aggregation/messages/guards.ts +55 -0
  148. package/src/core/aggregation/messages/index.ts +4 -0
  149. package/src/core/aggregation/participant.ts +510 -0
  150. package/src/core/aggregation/phases.ts +82 -0
  151. package/src/core/aggregation/runner/events.ts +77 -0
  152. package/src/core/aggregation/runner/index.ts +4 -0
  153. package/src/core/aggregation/runner/participant-runner.ts +364 -0
  154. package/src/core/aggregation/runner/service-runner.ts +365 -0
  155. package/src/core/aggregation/runner/typed-emitter.ts +87 -0
  156. package/src/core/aggregation/service.ts +547 -0
  157. package/src/core/aggregation/signing-session.ts +209 -0
  158. package/src/core/aggregation/transport/didcomm.ts +42 -0
  159. package/src/core/aggregation/transport/error.ts +13 -0
  160. package/src/core/aggregation/transport/factory.ts +29 -0
  161. package/src/core/aggregation/transport/index.ts +5 -0
  162. package/src/core/aggregation/transport/nostr.ts +333 -0
  163. package/src/core/aggregation/transport/transport.ts +46 -0
  164. package/src/core/beacon/beacon.ts +122 -2
  165. package/src/core/beacon/cas-beacon.ts +28 -76
  166. package/src/core/beacon/error.ts +0 -12
  167. package/src/core/beacon/fee-estimator.ts +52 -0
  168. package/src/core/beacon/interfaces.ts +10 -1
  169. package/src/core/beacon/singleton-beacon.ts +14 -75
  170. package/src/core/beacon/smt-beacon.ts +109 -11
  171. package/src/core/identifier.ts +17 -0
  172. package/src/core/interfaces.ts +2 -2
  173. package/src/core/resolver.ts +25 -2
  174. package/src/core/updater.ts +415 -0
  175. package/src/did-btcr2.ts +36 -66
  176. package/src/index.ts +17 -30
  177. package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
  178. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
  179. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  180. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  181. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  182. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
  183. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  184. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  185. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  186. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  187. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  188. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  189. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  190. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  191. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  192. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  193. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  194. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  195. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  196. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  197. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  198. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  199. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  200. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  201. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  202. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  203. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  204. package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
  205. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
  206. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  207. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  208. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -245
  209. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  210. package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
  211. package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
  212. package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
  213. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
  214. package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
  215. package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
  216. package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
  217. package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
  218. package/dist/esm/core/beacon/aggregation/participant.js +0 -435
  219. package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
  220. package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
  221. package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
  222. package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
  223. package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
  224. package/dist/esm/core/update.js +0 -112
  225. package/dist/esm/core/update.js.map +0 -1
  226. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
  227. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
  228. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
  229. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
  230. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
  231. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
  232. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
  233. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
  234. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
  235. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
  236. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
  237. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
  238. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
  239. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
  240. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
  241. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
  242. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
  243. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
  244. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
  245. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
  246. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
  247. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
  248. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
  249. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
  250. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
  251. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
  252. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
  253. package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
  254. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
  255. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
  256. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
  257. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
  258. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
  259. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
  260. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
  261. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
  262. package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
  263. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
  264. package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
  265. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
  266. package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
  267. package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
  268. package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
  269. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
  270. package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
  271. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
  272. package/dist/types/core/update.d.ts +0 -52
  273. package/dist/types/core/update.d.ts.map +0 -1
  274. package/src/core/beacon/aggregation/cohort/index.ts +0 -305
  275. package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
  276. package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
  277. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -44
  278. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -40
  279. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -35
  280. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -34
  281. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -36
  282. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -39
  283. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -40
  284. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -40
  285. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -40
  286. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -41
  287. package/src/core/beacon/aggregation/cohort/status.ts +0 -7
  288. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -148
  289. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -323
  290. package/src/core/beacon/aggregation/communication/error.ts +0 -13
  291. package/src/core/beacon/aggregation/communication/factory.ts +0 -25
  292. package/src/core/beacon/aggregation/communication/service.ts +0 -42
  293. package/src/core/beacon/aggregation/coordinator.ts +0 -419
  294. package/src/core/beacon/aggregation/participant.ts +0 -517
  295. package/src/core/beacon/aggregation/session/index.ts +0 -301
  296. package/src/core/beacon/aggregation/session/status.ts +0 -18
  297. package/src/core/update.ts +0 -158
package/README.md CHANGED
@@ -1,275 +1,157 @@
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
40
- ```
41
-
42
- ### CLI Reference
43
-
10
+ pnpm add @did-btcr2/method
44
11
  ```
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
12
 
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 |
13
+ ## What's in the Box
70
14
 
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.
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
+ | Update a DID (sans-I/O state machine) | `DidBtcr2.update()` → `Updater` |
20
+ | Update utilities (construct, sign, announce) | `Updater.construct()`, `Updater.sign()`, `Updater.announce()` |
21
+ | Beacon types (Singleton, CAS, SMT) | `SingletonBeacon`, `CASBeacon`, `SMTBeacon` |
22
+ | Fee estimation (pluggable) | `FeeEstimator`, `StaticFeeEstimator` |
23
+ | Multi-party aggregation (MuSig2) | `AggregationServiceRunner`, `AggregationParticipantRunner` |
24
+ | Transport abstraction (Nostr, DIDComm stub) | `Transport`, `NostrTransport` |
25
+ | DID document types and builders | `Btcr2DidDocument`, `DidDocumentBuilder` |
73
26
 
74
- ### Actions
27
+ ## Quick Start
75
28
 
76
- #### `create`
29
+ ### Create a DID
77
30
 
78
- Creates a DID and writes the initial vector files. The `--genesis` flag behavior depends on the `--type`:
31
+ ```typescript
32
+ import { DidBtcr2 } from '@did-btcr2/method';
33
+ import { SchnorrKeyPair } from '@did-btcr2/keypair';
79
34
 
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
91
- ```
92
-
93
- **Outputs:**
35
+ // Deterministic (k-type) the identifier IS the public key
36
+ const keys = SchnorrKeyPair.generate();
37
+ const did = DidBtcr2.create(keys.publicKey.compressed, {
38
+ idType : 'KEY',
39
+ network : 'mutinynet',
40
+ });
41
+ // did:btcr2:k1q5p...
94
42
  ```
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
43
 
105
- Reads back the create output, rebuilds the source document, constructs and signs an update.
44
+ ### Resolve a DID
106
45
 
107
- **Without `--interactive`:** applies a default patch that rotates the first SingletonBeacon service endpoint (P2PKH key rotation).
46
+ `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
47
 
109
- **With `--interactive`:** prompts for JSON Patch operations with smart auto-generation (see below).
48
+ ```typescript
49
+ import { DidBtcr2 } from '@did-btcr2/method';
110
50
 
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.
51
+ const resolver = DidBtcr2.resolve(did, { sidecar });
52
+ let state = resolver.resolve();
112
53
 
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
- ```
132
-
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.**
136
-
137
- ```bash
138
- source .env
139
- pnpm generate:vector fund --hash <hash>
140
- pnpm generate:vector fund --hash <hash> --amount 0.01
141
- ```
142
-
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.
145
-
146
- #### `announce`
54
+ while (state.status === 'action-required') {
55
+ for (const need of state.needs) {
56
+ const data = await fetchData(need); // your I/O goes here
57
+ resolver.provide(need, data);
58
+ }
59
+ state = resolver.resolve();
60
+ }
147
61
 
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.
62
+ const { didDocument, metadata } = state.result;
63
+ ```
64
+
65
+ See [`src/core/resolver.ts`](./src/core/resolver.ts) for the full `DataNeed` union and phase transitions.
66
+
67
+ ### Update a DID
68
+
69
+ `DidBtcr2.update()` returns a sans-I/O state machine — the counterpart to the Resolver. The caller drives the update by fulfilling typed data needs (signing key, funding confirmation, broadcast).
70
+
71
+ ```typescript
72
+ import { DidBtcr2, Updater } from '@did-btcr2/method';
73
+
74
+ const updater = DidBtcr2.update({
75
+ sourceDocument,
76
+ patches : [{ op: 'add', path: '/service/-', value: newService }],
77
+ sourceVersionId : 1,
78
+ verificationMethodId : '#initialKey',
79
+ beaconId : '#beacon-0',
80
+ });
81
+
82
+ let state = updater.advance();
83
+ while (state.status === 'action-required') {
84
+ for (const need of state.needs) {
85
+ switch (need.kind) {
86
+ case 'NeedSigningKey':
87
+ updater.provide(need, secretKeyBytes);
88
+ break;
89
+ case 'NeedFunding':
90
+ // Check UTXOs at need.beaconAddress, fund if needed
91
+ updater.provide(need);
92
+ break;
93
+ case 'NeedBroadcast':
94
+ await Updater.announce(need.beaconService, need.signedUpdate, secretKey, bitcoin);
95
+ updater.provide(need);
96
+ break;
97
+ }
98
+ }
99
+ state = updater.advance();
100
+ }
149
101
 
150
- ```bash
151
- source .env
152
- pnpm generate:vector announce --hash <hash>
102
+ const { signedUpdate } = state.result;
153
103
  ```
154
104
 
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.
105
+ See [`src/core/updater.ts`](./src/core/updater.ts) for the full `UpdaterDataNeed` union and phase transitions.
157
106
 
158
- #### `resolve`
107
+ ### Update Aggregation (Multi-Party MuSig2)
159
108
 
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).
109
+ 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:
161
110
 
162
- **With `--offline`:** writes only the sidecar input file without connecting to Bitcoin.
111
+ ```typescript
112
+ import { AggregationServiceRunner, NostrTransport } from '@did-btcr2/method';
163
113
 
164
- ```bash
165
- # Resolve against a live Bitcoin node
166
- source .env
167
- pnpm generate:vector resolve --hash <hash>
114
+ const transport = new NostrTransport({ relays: ['wss://relay.damus.io'] });
115
+ transport.registerActor(serviceDid, serviceKeys);
116
+ transport.start();
168
117
 
169
- # Offline build sidecar input only
170
- pnpm generate:vector resolve --hash <hash> --offline
171
- ```
118
+ const runner = new AggregationServiceRunner({
119
+ transport,
120
+ did : serviceDid,
121
+ keys : serviceKeys,
122
+ config : { minParticipants: 2, network: 'mutinynet', beaconType: 'CASBeacon' },
123
+ onProvideTxData: async ({ beaconAddress, signalBytes }) => buildBeaconTx(beaconAddress, signalBytes),
124
+ });
172
125
 
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)
126
+ runner.on('signing-complete', (result) => console.log('done'));
127
+ const result = await runner.run();
178
128
  ```
179
129
 
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.
130
+ 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).
182
131
 
183
- #### `list`
132
+ ## Architecture Principles
184
133
 
185
- Displays existing test vectors filtered by network and type. If `--network` or `--type` are not provided, prompts interactively.
134
+ - **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.
135
+ - **Layered APIs.** High-level facades (like `AggregationServiceRunner`) encapsulate boilerplate; low-level state machines stay available for tests, custom transports, and fine-grained control.
136
+ - **Pluggable transport.** The `Transport` interface decouples protocol logic from the wire format. Ships with `NostrTransport`; add your own for DIDComm, libp2p, or anything else.
137
+ - **Browser-compatible.** All code targets both Node.js (>= 22) and modern browsers. No Node-only APIs in the core.
186
138
 
187
- ```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.
139
+ ## Build & Test
195
140
 
196
141
  ```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..."}}
142
+ # From packages/method/
143
+ pnpm build # Compile ESM + CJS + browser bundle
144
+ pnpm build:tests # Compile tests to tests/compiled/
145
+ pnpm test # Run the test suite with coverage
146
+ pnpm lint # ESLint (zero warnings tolerated)
237
147
  ```
238
148
 
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.
149
+ Tests run from compiled JS, so run `pnpm build:tests` before `pnpm test` after any test changes.
242
150
 
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
151
+ ## Documentation
262
152
 
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
- ```
153
+ - **Package docs on btcr2.dev** — [btcr2.dev/impls/ts](https://btcr2.dev/impls/ts)
154
+ - **[`docs/beacon-system-overview.md`](./docs/beacon-system-overview.md)** — Beacon architecture, Singleton / CAS / SMT behavior, signal discovery
155
+ - **[`docs/aggregation.md`](./docs/aggregation.md)** — Multi-party aggregation protocol, Runner and state machine APIs, e2e examples
156
+ - **[`docs/test-vectors.md`](./docs/test-vectors.md)** — CLI tool for generating did:btcr2 test vectors via a stepped workflow
157
+ - **Source reference** — See JSDoc comments on public classes; the most important entry points are `DidBtcr2` (facade), `Resolver` (read path), `Updater` (write path), and the aggregation runners.