@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
@@ -1,301 +0,0 @@
1
- import * as musig2 from '@scure/btc-signer/musig2';
2
- import { Transaction } from 'bitcoinjs-lib';
3
- import { AggregateBeaconError } from '../../error.js';
4
- import type { AggregateBeaconCohort } from '../cohort/index.js';
5
- import { BeaconCohortAuthorizationRequestMessage } from '../cohort/messages/sign/authorization-request.js';
6
- import type { SIGNING_SESSION_STATUS_TYPE } from './status.js';
7
- import { SIGNING_SESSION_STATUS } from './status.js';
8
-
9
- /**
10
- * Convert a big-endian byte array into a bigint.
11
- * @param bytes - The input Uint8Array representing a big-endian integer.
12
- * @returns The integer value as a bigint.
13
- */
14
- export function bigEndianToInt(bytes: Uint8Array): bigint {
15
- return bytes.reduce((num, b) => (num << 8n) + BigInt(b), 0n);
16
- }
17
-
18
- /**
19
- * Convert a bigint to a big-endian Uint8Array of specified length.
20
- * @param xInit - The bigint to convert.
21
- * @param length - The desired length of the output array in bytes.
22
- * @returns A Uint8Array representing the bigint in big-endian form.
23
- */
24
- export function intToBigEndian(xInit: bigint, length: number): Uint8Array {
25
- let x = xInit;
26
- const result = new Uint8Array(length);
27
- for (let i = length - 1; i >= 0; i--) {
28
- result[i] = Number(x & 0xffn);
29
- x >>= 8n;
30
- }
31
- return result;
32
- }
33
-
34
- type PublicKeyHex = string;
35
- type Nonce = Uint8Array;
36
- type NonceContributions = Map<PublicKeyHex, Nonce>;
37
- type PartialSignatures = Map<string, Uint8Array>;
38
- type ProcessedRequests = Record<string, string>;
39
-
40
- export interface SigningSession {
41
- id?: string;
42
- cohort: AggregateBeaconCohort;
43
- pendingTx: Transaction;
44
- nonceContributions?: NonceContributions;
45
- aggregatedNonce?: Uint8Array;
46
- partialSignatures?: PartialSignatures;
47
- signature?: Uint8Array;
48
- status?: SIGNING_SESSION_STATUS_TYPE;
49
- processedRequests?: ProcessedRequests;
50
- nonceSecrets?: bigint;
51
- }
52
- export class BeaconCohortSigningSession implements SigningSession {
53
- /**
54
- * Unique identifier for the signing session.
55
- * @type {string}
56
- */
57
- public id: string;
58
-
59
- /**
60
- * DID of the coordinator.
61
- * @type {AggregateBeaconCohort}
62
- */
63
- public cohort: AggregateBeaconCohort;
64
-
65
- /**
66
- * Pending transaction to be signed.
67
- * @type {Transaction}
68
- */
69
- public pendingTx: Transaction;
70
-
71
- /**
72
- * Map of nonce contributions from participants.
73
- * @type {Map<PublicKeyHex, Nonce>}
74
- */
75
- public nonceContributions: Map<PublicKeyHex, Nonce> = new Map();
76
-
77
- /**
78
- * Aggregated nonce from all participants.
79
- * @type {Uint8Array}
80
- */
81
- public aggregatedNonce?: Uint8Array;
82
-
83
- /**
84
- * Map of partial signatures from participants.
85
- * @type {Map<string, Uint8Array>}
86
- */
87
- public partialSignatures: Map<string, Uint8Array> = new Map();
88
-
89
- /**
90
- * Final signature for the transaction.
91
- * @type {Uint8Array}
92
- */
93
- public signature?: Uint8Array;
94
-
95
- /**
96
- * Current status of the signing session.
97
- * @type {SIGNING_SESSION_STATUS_TYPE}
98
- */
99
- public status: SIGNING_SESSION_STATUS_TYPE;
100
-
101
- /**
102
- * Map of processed requests from participants.
103
- * @type {Record<string, string>}
104
- */
105
- public processedRequests: Record<string, string>;
106
-
107
- /**
108
- * Secrets for nonces contributed by participants.
109
- * @type {Array<bigint>}
110
- */
111
- public nonceSecrets?: bigint;
112
-
113
- /**
114
- * Musig2 session for signing operations.
115
- * @type {musig2.Session}
116
- */
117
- public musig2Session?: musig2.Session;
118
-
119
- /**
120
- * Creates a new instance of BeaconCohortSigningSession.
121
- * @param {SigningSession} params Parameters to initialize the signing session.
122
- * @param {Transaction} params.pendingTx The pending transaction to be signed.
123
- * @param {string} [params.id] Optional unique identifier for the signing session. If not provided, a new UUID will be generated.
124
- * @param {AggregateBeaconCohort} [params.cohort] The cohort associated with the signing session.
125
- * @param {Record<string, string>} [params.processedRequests] Map of processed requests from participants.
126
- * @param {SIGNING_SESSION_STATUS_TYPE} [params.status] The current status of the signing session. Defaults to AWAITING_NONCE_CONTRIBUTIONS.
127
- */
128
- constructor({ id, cohort, pendingTx, processedRequests, status }: SigningSession) {
129
- this.id = id || crypto.randomUUID();
130
- this.cohort = cohort;
131
- this.pendingTx = pendingTx;
132
- this.processedRequests = processedRequests || {};
133
- this.status = status || SIGNING_SESSION_STATUS.AWAITING_NONCE_CONTRIBUTIONS;
134
- }
135
-
136
- /**
137
- * Gets the authorization request message for a participant.
138
- * @param {string} to The public key of the participant to whom the request is sent.
139
- * @param {string} from The public key of the participant sending the request.
140
- * @returns {AuthorizationRequest} The authorization request message.
141
- */
142
- public getAuthorizationRequest(to: string, from: string): BeaconCohortAuthorizationRequestMessage {
143
- const txHex = this.pendingTx instanceof Transaction ? this.pendingTx?.toHex() : this.pendingTx;
144
- return new BeaconCohortAuthorizationRequestMessage({
145
- to,
146
- from,
147
- sessionId : this.id,
148
- cohortId : this.cohort?.id,
149
- pendingTx : txHex,
150
- });
151
- }
152
-
153
- /**
154
- * Adds a nonce contribution from a participant to the session.
155
- * @param {string} from The public key of the participant contributing the nonce.
156
- * @param {Array<string>} nonceContribution The nonce contribution from the participant.
157
- * @throws {Error} If the session is not awaiting nonce contributions or if the contribution is invalid.
158
- */
159
- public addNonceContribution(from: string, nonceContribution: Uint8Array): void {
160
- if(this.status !== SIGNING_SESSION_STATUS.AWAITING_NONCE_CONTRIBUTIONS) {
161
- throw new AggregateBeaconError(`Nonce contributions already received. Current status: ${this.status}`);
162
- }
163
-
164
- if(nonceContribution.length !== 2) {
165
- throw new AggregateBeaconError(`Invalid nonce contribution. Expected 2 points, received ${nonceContribution.length}.`);
166
- }
167
-
168
- if (this.nonceContributions.get(from)) {
169
- console.warn(`WARNING: Nonce contribution already received from ${from}.`);
170
- }
171
-
172
- this.nonceContributions.set(from, nonceContribution);
173
-
174
- if(this.nonceContributions.size === this.cohort?.participants.length) {
175
- this.status = SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED;
176
- }
177
- }
178
-
179
- /**
180
- * Generates the aggregated nonce from all nonce contributions for the session.
181
- * @returns {Uint8Array} The aggregated nonce.
182
- * @throws {AggregateBeaconError} If not all nonce contributions have been received.
183
- */
184
- public generateAggregatedNonce(): Uint8Array {
185
- if(this.status !== SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED) {
186
- const missing = this.cohort?.participants.length - this.nonceContributions.size;
187
- throw new AggregateBeaconError(
188
- `Missing ${missing} nonce contributions. ` +
189
- `Received ${this.cohort?.participants.length} of ${this.nonceContributions.size} nonce contributions. ` +
190
- `Current status: ${this.status}`,
191
- 'NONCE_CONTRIBUTION_ERROR', this.toJSON()
192
- );
193
- }
194
- const sortedPubkeys = musig2.sortKeys(this.cohort.cohortKeys);
195
- const keyAggContext = musig2.keyAggregate(sortedPubkeys);
196
- const aggPubkey = musig2.keyAggExport(keyAggContext);
197
- this.aggregatedNonce = musig2.nonceAggregate(this.cohort.cohortKeys.map(key => musig2.nonceGen(key, undefined, aggPubkey, this.cohort.trMerkleRoot).public));
198
- this.musig2Session = new musig2.Session(this.aggregatedNonce, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
199
- return this.aggregatedNonce;
200
- }
201
-
202
- /**
203
- * Adds a partial signature from a participant to the session.
204
- * @param {string} from The public key of the participant contributing the partial signature.
205
- * @param {Uint8Array} partialSignature The partial signature from the participant.
206
- */
207
- public addPartialSignature(from: string, partialSignature: Uint8Array): void {
208
- if(this.status !== SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES) {
209
- throw new AggregateBeaconError(`Partial signatures not expected. Current status: ${this.status}`);
210
- }
211
-
212
- if(this.partialSignatures.get(from)) {
213
- console.warn(`WARNING: Partial signature already received from ${from}.`);
214
- }
215
-
216
- this.partialSignatures.set(from, partialSignature);
217
- }
218
-
219
- /**
220
- * Generates the final signature from all partial signatures.
221
- * @returns {Uint8Array} The final aggregated signature.
222
- */
223
- public async generateFinalSignature(): Promise<Uint8Array> {
224
- if(this.status !== SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED) {
225
- throw new AggregateBeaconError(`Partial signatures not received. Current status: ${this.status}`);
226
- }
227
-
228
- const inputIdx = (this.pendingTx?.ins?.length || 0) - 1;
229
- if (inputIdx < 0) {
230
- throw new AggregateBeaconError('No inputs in the pending transaction to sign.');
231
- }
232
-
233
- const prevoutScript = this.pendingTx?.ins[inputIdx].script;
234
- if (!prevoutScript) {
235
- throw new AggregateBeaconError('Previous output script is missing for the input to sign.');
236
- }
237
-
238
- const sigSum = [...this.partialSignatures.values()].reduce((sum, sig) => sum + bigEndianToInt(sig), 0n);
239
- console.info(`Aggregated Signature computed: ${sigSum}`);
240
-
241
- this.aggregatedNonce ??= this.generateAggregatedNonce();
242
-
243
- const session = new musig2.Session(this.aggregatedNonce!, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
244
- this.signature = session.partialSigAgg([...this.partialSignatures.values()]);
245
-
246
- return this.signature;
247
- }
248
-
249
- /**
250
- * Generates a partial signature for the session using the participant's secret key.
251
- * @param {Uint8Array} participantSk The secret key of the participant.
252
- * @returns {Uint8Array} The partial signature generated by the participant.
253
- */
254
- public generatePartialSignature(participantSk: Uint8Array): Uint8Array {
255
- if (!this.aggregatedNonce) {
256
- throw new AggregateBeaconError('Aggregated nonce is not available. Please generate it first.');
257
- }
258
- const sigHash = this.pendingTx?.hashForSignature(0, this.pendingTx?.ins[0].script, Transaction.SIGHASH_DEFAULT);
259
- if(!sigHash) {
260
- throw new AggregateBeaconError('Signature hash is not available. Please ensure the transaction is properly set up.');
261
- }
262
- const session = new musig2.Session(this.aggregatedNonce!, this.cohort.cohortKeys, this.cohort.trMerkleRoot);
263
- return session.sign(this.aggregatedNonce, participantSk);
264
- }
265
-
266
- /**
267
- * Converts the signing session instance to a JSON object representation.
268
- * @returns {BeaconCohortSigningSession} The JSON object representation of the signing session.
269
- */
270
- public toJSON(): Partial<BeaconCohortSigningSession> {
271
- return {
272
- id : this.id,
273
- cohort : this.cohort,
274
- pendingTx : this.pendingTx,
275
- nonceContributions : this.nonceContributions,
276
- aggregatedNonce : this.aggregatedNonce,
277
- partialSignatures : this.partialSignatures,
278
- signature : this.signature,
279
- status : this.status,
280
- processedRequests : this.processedRequests,
281
- nonceSecrets : this.nonceSecrets,
282
- musig2Session : this.musig2Session
283
- };
284
- }
285
-
286
- /**
287
- * Checks if the signing session is a completed state.
288
- * @returns {boolean} True if the session is complete, false otherwise.
289
- */
290
- public isComplete(): boolean {
291
- return this.status === SIGNING_SESSION_STATUS.SIGNATURE_COMPLETE;
292
- }
293
-
294
- /**
295
- * Checks if the signing session is in a failed state.
296
- * @returns {boolean} True if the session has failed, false otherwise.
297
- */
298
- public isFailed(): boolean {
299
- return this.status === SIGNING_SESSION_STATUS.FAILED;
300
- }
301
- }
@@ -1,18 +0,0 @@
1
- export type SIGNING_SESSION_STATUS_TYPE =
2
- | 'AWAITING_NONCE_CONTRIBUTIONS'
3
- | 'NONCE_CONTRIBUTION_SENT'
4
- | 'NONCE_CONTRIBUTIONS_RECEIVED'
5
- | 'AWAITING_PARTIAL_SIGNATURES'
6
- | 'PARTIAL_SIGNATURES_RECEIVED'
7
- | 'SIGNATURE_COMPLETE'
8
- | 'FAILED'
9
-
10
- export enum SIGNING_SESSION_STATUS {
11
- AWAITING_NONCE_CONTRIBUTIONS = 'AWAITING_NONCE_CONTRIBUTIONS',
12
- NONCE_CONTRIBUTION_SENT = 'NONCE_CONTRIBUTION_SENT',
13
- NONCE_CONTRIBUTIONS_RECEIVED = 'NONCE_CONTRIBUTIONS_RECEIVED',
14
- AWAITING_PARTIAL_SIGNATURES = 'AWAITING_PARTIAL_SIGNATURES',
15
- PARTIAL_SIGNATURES_RECEIVED = 'PARTIAL_SIGNATURES_RECEIVED',
16
- SIGNATURE_COMPLETE = 'SIGNATURE_COMPLETE',
17
- FAILED = 'FAILED',
18
- }
@@ -1,158 +0,0 @@
1
- import type {
2
- KeyBytes,
3
- PatchOperation} from '@did-btcr2/common';
4
- import {
5
- canonicalHash,
6
- INVALID_DID_UPDATE,
7
- JSONPatch,
8
- UpdateError
9
- } from '@did-btcr2/common';
10
- import type {
11
- DataIntegrityConfig,
12
- SignedBTCR2Update,
13
- UnsignedBTCR2Update
14
- } from '@did-btcr2/cryptosuite';
15
- import {
16
- SchnorrMultikey
17
- } from '@did-btcr2/cryptosuite';
18
- import type { Btcr2DidDocument, DidVerificationMethod } from '../utils/did-document.js';
19
- import { DidDocument } from '../utils/did-document.js';
20
- import { BeaconFactory } from './beacon/factory.js';
21
- import type { BeaconService } from './beacon/interfaces.js';
22
- import type { BitcoinConnection } from '@did-btcr2/bitcoin';
23
-
24
- /**
25
- * Implements {@link https://dcdpr.github.io/did-btcr2/operations/update.html | 7.3 Update}.
26
- *
27
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD
28
- * data format, signed by a verificationMethod that has the authority to make
29
- * the update as specified in the previous DID document. Capability invocations
30
- * for updates MUST be authorized using Data Integrity following the
31
- * bip340-jcs-2025 cryptosuite with a proofPurpose of capabilityInvocation.
32
- *
33
- * @class Update
34
- * @type {Update}
35
- */
36
- export class Update {
37
- /**
38
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
39
- * This process constructs a BTCR2 Unsigned Update conformant to the spec template.
40
- *
41
- * @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
42
- * @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
43
- * @param {number} sourceVersionId The version ID of the source document.
44
- * @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
45
- * @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
46
- */
47
- static construct(
48
- sourceDocument: Btcr2DidDocument,
49
- patches: PatchOperation[],
50
- sourceVersionId: number,
51
- ): UnsignedBTCR2Update {
52
- // Initialize an unsigned update conformant to btcr2 spec.
53
- const unsignedUpdate: UnsignedBTCR2Update = {
54
- '@context' : [
55
- 'https://w3id.org/security/v2',
56
- 'https://w3id.org/zcap/v1',
57
- 'https://w3id.org/json-ld-patch/v1',
58
- 'https://btcr2.dev/context/v1'
59
- ],
60
- patch : patches,
61
- targetHash : '',
62
- targetVersionId : sourceVersionId + 1,
63
- sourceHash : canonicalHash(sourceDocument),
64
- };
65
-
66
- // Apply all JSON patches to sourceDocument.
67
- const targetDocument = JSONPatch.apply(sourceDocument, patches);
68
-
69
- try {
70
- // Ensure the targetDocument is conformant to DID Core v1.1.
71
- DidDocument.isValid(targetDocument);
72
- } catch (error) {
73
- // If validation fails, throw an UpdateError with INVALID_DID_UPDATE.
74
- throw new UpdateError(
75
- 'Error validating targetDocument: ' + (error instanceof Error ? error.message : String(error)),
76
- INVALID_DID_UPDATE, targetDocument
77
- );
78
- }
79
-
80
- // Set the targetHash by canonicalizing the targetDocument and encoding it in base64url.
81
- unsignedUpdate.targetHash = canonicalHash(targetDocument);
82
-
83
- // Return unsignedUpdate.
84
- return unsignedUpdate;
85
- }
86
-
87
- /**
88
- * Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
89
- * This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
90
- *
91
- * @param {string} did The did-btcr2 identifier to derive the root capability from
92
- * @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
93
- * @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
94
- * @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
95
- * @throws {UpdateError} if the privateKeyBytes are invalid
96
- */
97
- static sign(
98
- did: string,
99
- unsignedUpdate: UnsignedBTCR2Update,
100
- verificationMethod: DidVerificationMethod,
101
- secretKey: KeyBytes,
102
- ): SignedBTCR2Update {
103
- // Parse the controller from the verificationMethod
104
- const controller = verificationMethod.controller;
105
- // Parse the fragment from the vmId
106
- const id = verificationMethod.id.slice(verificationMethod.id.indexOf('#'));
107
-
108
- // Construct a Schnorr Multikey
109
- const multikey = SchnorrMultikey.fromSecretKey(id, controller, secretKey);
110
-
111
- // Define the Data Integrity proof config
112
- const config: DataIntegrityConfig = {
113
- '@context' : [
114
- 'https://w3id.org/security/v2',
115
- 'https://w3id.org/zcap/v1',
116
- 'https://w3id.org/json-ld-patch/v1',
117
- 'https://btcr2.dev/context/v1'
118
- ],
119
- cryptosuite : 'bip340-jcs-2025',
120
- type : 'DataIntegrityProof',
121
- verificationMethod : verificationMethod.id,
122
- proofPurpose : 'capabilityInvocation',
123
- capability : `urn:zcap:root:${encodeURIComponent(did)}`,
124
- capabilityAction : 'Write',
125
- };
126
-
127
- // Go from multikey => cryptosuite => diproof
128
- const diproof = multikey.toCryptosuite().toDataIntegrityProof();
129
-
130
- // Use the config to add a proof to the unsigned update
131
- return diproof.addProof(unsignedUpdate, config);
132
- }
133
-
134
- /**
135
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
136
- * BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
137
- * @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
138
- * @param {SignedBTCR2Update} update The signed update object to be announced.
139
- * @param {KeyBytes} secretKey The private key used to sign the update for announcement.
140
- * @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
141
- * @throws {UpdateError} if the beaconService type is invalid
142
- */
143
- static async announce(
144
- beaconService: BeaconService,
145
- update: SignedBTCR2Update,
146
- secretKey: KeyBytes,
147
- bitcoin: BitcoinConnection
148
- ): Promise<SignedBTCR2Update> {
149
- // Establish a beacon object
150
- const beacon = BeaconFactory.establish(beaconService);
151
-
152
- // Broadcast the update
153
- const result = await beacon.broadcastSignal(update, secretKey, bitcoin);
154
-
155
- // Return the sidecarData
156
- return result;
157
- }
158
- }