@did-btcr2/method 0.17.2 → 0.18.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 (366) hide show
  1. package/dist/browser.js +30124 -19552
  2. package/dist/browser.mjs +30123 -19551
  3. package/dist/cjs/core/beacon/aggregation/cohort/index.js +225 -0
  4. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -0
  5. package/dist/{esm/core/beacon/aggregation → cjs/core/beacon/aggregation/cohort}/messages/base.js +3 -11
  6. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -0
  7. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js +11 -0
  8. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js.map +1 -0
  9. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js +98 -0
  10. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js.map +1 -0
  11. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +30 -0
  12. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -0
  13. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +28 -0
  14. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -0
  15. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +26 -0
  16. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -0
  17. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +22 -0
  18. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -0
  19. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +27 -0
  20. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -0
  21. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +28 -0
  22. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -0
  23. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +29 -0
  24. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -0
  25. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +29 -0
  26. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -0
  27. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +29 -0
  28. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -0
  29. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +30 -0
  30. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -0
  31. package/dist/cjs/core/beacon/aggregation/cohort/status.js.map +1 -0
  32. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +126 -0
  33. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -0
  34. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +230 -0
  35. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -0
  36. package/dist/cjs/core/beacon/aggregation/communication/error.js +12 -0
  37. package/dist/cjs/core/beacon/aggregation/communication/error.js.map +1 -0
  38. package/dist/cjs/core/beacon/aggregation/communication/factory.js +21 -0
  39. package/dist/cjs/core/beacon/aggregation/communication/factory.js.map +1 -0
  40. package/dist/cjs/core/beacon/aggregation/communication/service.js.map +1 -0
  41. package/dist/cjs/core/beacon/aggregation/coordinator.js +282 -56
  42. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
  43. package/dist/cjs/core/beacon/aggregation/participant.js +435 -1
  44. package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
  45. package/dist/cjs/core/beacon/aggregation/session/index.js +233 -0
  46. package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -0
  47. package/dist/cjs/core/beacon/aggregation/session/status.js +11 -0
  48. package/dist/cjs/core/beacon/aggregation/session/status.js.map +1 -0
  49. package/dist/cjs/core/beacon/cid-aggregate.js.map +1 -1
  50. package/dist/cjs/core/beacon/error.js +37 -0
  51. package/dist/cjs/core/beacon/error.js.map +1 -0
  52. package/dist/cjs/core/beacon/factory.js.map +1 -1
  53. package/dist/cjs/core/beacon/singleton.js +8 -5
  54. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  55. package/dist/cjs/core/beacon/smt-aggregate.js.map +1 -1
  56. package/dist/cjs/{utils/beacons.js → core/beacon/utils.js} +4 -4
  57. package/dist/cjs/core/beacon/utils.js.map +1 -0
  58. package/dist/cjs/core/crud/read.js +2 -9
  59. package/dist/cjs/core/crud/read.js.map +1 -1
  60. package/dist/cjs/core/crud/update.js +18 -19
  61. package/dist/cjs/core/crud/update.js.map +1 -1
  62. package/dist/{esm/utils → cjs/core}/identifier.js +18 -3
  63. package/dist/cjs/core/identifier.js.map +1 -0
  64. package/dist/cjs/did-btcr2.js +2 -2
  65. package/dist/cjs/did-btcr2.js.map +1 -1
  66. package/dist/cjs/index.js +28 -6
  67. package/dist/cjs/index.js.map +1 -1
  68. package/dist/cjs/interfaces/beacon.js.map +1 -1
  69. package/dist/cjs/utils/appendix.js +2 -3
  70. package/dist/cjs/utils/appendix.js.map +1 -1
  71. package/dist/cjs/utils/did-document.js +4 -6
  72. package/dist/cjs/utils/did-document.js.map +1 -1
  73. package/dist/cjs/utils/types.js +2 -0
  74. package/dist/cjs/utils/types.js.map +1 -0
  75. package/dist/esm/core/beacon/aggregation/cohort/index.js +225 -0
  76. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -0
  77. package/dist/{cjs/core/beacon/aggregation → esm/core/beacon/aggregation/cohort}/messages/base.js +3 -11
  78. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -0
  79. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +11 -0
  80. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +1 -0
  81. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +98 -0
  82. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +1 -0
  83. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +30 -0
  84. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -0
  85. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +28 -0
  86. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -0
  87. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +26 -0
  88. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -0
  89. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +22 -0
  90. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -0
  91. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +27 -0
  92. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -0
  93. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +28 -0
  94. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -0
  95. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +29 -0
  96. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -0
  97. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +29 -0
  98. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -0
  99. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +29 -0
  100. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -0
  101. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +30 -0
  102. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -0
  103. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +1 -0
  104. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +126 -0
  105. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -0
  106. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +230 -0
  107. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -0
  108. package/dist/esm/core/beacon/aggregation/communication/error.js +12 -0
  109. package/dist/esm/core/beacon/aggregation/communication/error.js.map +1 -0
  110. package/dist/esm/core/beacon/aggregation/communication/factory.js +21 -0
  111. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +1 -0
  112. package/dist/esm/core/beacon/aggregation/communication/service.js.map +1 -0
  113. package/dist/esm/core/beacon/aggregation/coordinator.js +282 -56
  114. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  115. package/dist/esm/core/beacon/aggregation/participant.js +435 -1
  116. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  117. package/dist/esm/core/beacon/aggregation/session/index.js +233 -0
  118. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -0
  119. package/dist/esm/core/beacon/aggregation/session/status.js +11 -0
  120. package/dist/esm/core/beacon/aggregation/session/status.js.map +1 -0
  121. package/dist/esm/core/beacon/cid-aggregate.js.map +1 -1
  122. package/dist/esm/core/beacon/error.js +37 -0
  123. package/dist/esm/core/beacon/error.js.map +1 -0
  124. package/dist/esm/core/beacon/factory.js.map +1 -1
  125. package/dist/esm/core/beacon/singleton.js +8 -5
  126. package/dist/esm/core/beacon/singleton.js.map +1 -1
  127. package/dist/esm/core/beacon/smt-aggregate.js.map +1 -1
  128. package/dist/esm/{utils/beacons.js → core/beacon/utils.js} +4 -4
  129. package/dist/esm/core/beacon/utils.js.map +1 -0
  130. package/dist/esm/core/crud/read.js +2 -9
  131. package/dist/esm/core/crud/read.js.map +1 -1
  132. package/dist/esm/core/crud/update.js +18 -19
  133. package/dist/esm/core/crud/update.js.map +1 -1
  134. package/dist/{cjs/utils → esm/core}/identifier.js +18 -3
  135. package/dist/esm/core/identifier.js.map +1 -0
  136. package/dist/esm/did-btcr2.js +2 -2
  137. package/dist/esm/did-btcr2.js.map +1 -1
  138. package/dist/esm/index.js +28 -6
  139. package/dist/esm/index.js.map +1 -1
  140. package/dist/esm/interfaces/beacon.js.map +1 -1
  141. package/dist/esm/utils/appendix.js +2 -3
  142. package/dist/esm/utils/appendix.js.map +1 -1
  143. package/dist/esm/utils/did-document.js +4 -6
  144. package/dist/esm/utils/did-document.js.map +1 -1
  145. package/dist/esm/utils/types.js +2 -0
  146. package/dist/esm/utils/types.js.map +1 -0
  147. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +135 -0
  148. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -0
  149. package/dist/types/core/beacon/aggregation/{messages → cohort/messages}/base.d.ts +13 -8
  150. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -0
  151. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +10 -0
  152. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +1 -0
  153. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +64 -0
  154. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +1 -0
  155. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +28 -0
  156. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -0
  157. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +26 -0
  158. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -0
  159. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +23 -0
  160. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -0
  161. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +19 -0
  162. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -0
  163. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +24 -0
  164. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -0
  165. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +24 -0
  166. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -0
  167. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +25 -0
  168. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -0
  169. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +25 -0
  170. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -0
  171. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +25 -0
  172. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -0
  173. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +26 -0
  174. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -0
  175. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +1 -0
  176. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +88 -0
  177. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -0
  178. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +93 -0
  179. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -0
  180. package/dist/types/core/beacon/aggregation/communication/error.d.ts +7 -0
  181. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +1 -0
  182. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +9 -0
  183. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +1 -0
  184. package/dist/types/core/beacon/aggregation/communication/service.d.ts +35 -0
  185. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +1 -0
  186. package/dist/types/core/beacon/aggregation/coordinator.d.ts +79 -26
  187. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  188. package/dist/types/core/beacon/aggregation/participant.d.ts +190 -0
  189. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  190. package/dist/types/core/beacon/aggregation/session/index.d.ts +155 -0
  191. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -0
  192. package/dist/types/core/beacon/aggregation/session/status.d.ts +10 -0
  193. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +1 -0
  194. package/dist/types/core/beacon/cid-aggregate.d.ts +3 -4
  195. package/dist/types/core/beacon/cid-aggregate.d.ts.map +1 -1
  196. package/dist/types/core/beacon/error.d.ts +22 -0
  197. package/dist/types/core/beacon/error.d.ts.map +1 -0
  198. package/dist/types/core/beacon/factory.d.ts +2 -3
  199. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  200. package/dist/types/core/beacon/singleton.d.ts +2 -3
  201. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  202. package/dist/types/core/beacon/smt-aggregate.d.ts +3 -4
  203. package/dist/types/core/beacon/smt-aggregate.d.ts.map +1 -1
  204. package/dist/types/{utils/beacons.d.ts → core/beacon/utils.d.ts} +3 -3
  205. package/dist/types/core/beacon/utils.d.ts.map +1 -0
  206. package/dist/types/core/crud/read.d.ts +3 -3
  207. package/dist/types/core/crud/read.d.ts.map +1 -1
  208. package/dist/types/core/crud/update.d.ts +1 -1
  209. package/dist/types/core/crud/update.d.ts.map +1 -1
  210. package/dist/types/{utils → core}/identifier.d.ts +24 -3
  211. package/dist/types/core/identifier.d.ts.map +1 -0
  212. package/dist/types/did-btcr2.d.ts +1 -1
  213. package/dist/types/did-btcr2.d.ts.map +1 -1
  214. package/dist/types/index.d.ts +28 -6
  215. package/dist/types/index.d.ts.map +1 -1
  216. package/dist/types/interfaces/beacon.d.ts +65 -5
  217. package/dist/types/interfaces/beacon.d.ts.map +1 -1
  218. package/dist/types/interfaces/crud.d.ts +1 -1
  219. package/dist/types/interfaces/crud.d.ts.map +1 -1
  220. package/dist/types/utils/appendix.d.ts +2 -10
  221. package/dist/types/utils/appendix.d.ts.map +1 -1
  222. package/dist/types/utils/did-document-builder.d.ts +1 -1
  223. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  224. package/dist/types/utils/did-document.d.ts +1 -1
  225. package/dist/types/utils/did-document.d.ts.map +1 -1
  226. package/dist/types/{types/crud.d.ts → utils/types.d.ts} +2 -2
  227. package/dist/types/utils/types.d.ts.map +1 -0
  228. package/package.json +4 -3
  229. package/src/core/beacon/aggregation/cohort/index.ts +292 -0
  230. package/src/core/beacon/aggregation/{messages → cohort/messages}/base.ts +14 -16
  231. package/src/core/beacon/aggregation/cohort/messages/constants.ts +12 -0
  232. package/src/core/beacon/aggregation/cohort/messages/index.ts +143 -0
  233. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +43 -0
  234. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +39 -0
  235. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +34 -0
  236. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +33 -0
  237. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +35 -0
  238. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +38 -0
  239. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +39 -0
  240. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +39 -0
  241. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +39 -0
  242. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +40 -0
  243. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +153 -0
  244. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +300 -0
  245. package/src/core/beacon/aggregation/communication/error.ts +13 -0
  246. package/src/core/beacon/aggregation/communication/factory.ts +25 -0
  247. package/src/core/beacon/aggregation/communication/service.ts +42 -0
  248. package/src/core/beacon/aggregation/coordinator.ts +338 -67
  249. package/src/core/beacon/aggregation/participant.ts +512 -0
  250. package/src/core/beacon/aggregation/session/index.ts +289 -0
  251. package/src/core/beacon/aggregation/session/status.ts +18 -0
  252. package/src/core/beacon/cid-aggregate.ts +4 -5
  253. package/src/core/beacon/error.ts +44 -0
  254. package/src/core/beacon/factory.ts +2 -3
  255. package/src/core/beacon/singleton.ts +10 -8
  256. package/src/core/beacon/smt-aggregate.ts +4 -5
  257. package/src/{utils/beacons.ts → core/beacon/utils.ts} +5 -5
  258. package/src/core/crud/read.ts +7 -16
  259. package/src/core/crud/update.ts +25 -22
  260. package/src/{utils → core}/identifier.ts +35 -5
  261. package/src/did-btcr2.ts +4 -4
  262. package/src/index.ts +36 -8
  263. package/src/interfaces/beacon.ts +75 -5
  264. package/src/interfaces/crud.ts +1 -1
  265. package/src/utils/appendix.ts +3 -11
  266. package/src/utils/did-document-builder.ts +1 -1
  267. package/src/utils/did-document.ts +4 -7
  268. package/src/{types/crud.ts → utils/types.ts} +2 -2
  269. package/dist/cjs/core/beacon/aggregation/messages/advert.js +0 -24
  270. package/dist/cjs/core/beacon/aggregation/messages/advert.js.map +0 -1
  271. package/dist/cjs/core/beacon/aggregation/messages/base.js.map +0 -1
  272. package/dist/cjs/core/beacon/aggregation/messages/cohort-set.js +0 -25
  273. package/dist/cjs/core/beacon/aggregation/messages/cohort-set.js.map +0 -1
  274. package/dist/cjs/core/beacon/aggregation/messages/keygen.js +0 -8
  275. package/dist/cjs/core/beacon/aggregation/messages/keygen.js.map +0 -1
  276. package/dist/cjs/core/beacon/aggregation/messages/opt-in.js +0 -23
  277. package/dist/cjs/core/beacon/aggregation/messages/opt-in.js.map +0 -1
  278. package/dist/cjs/core/beacon/aggregation/messages/sign.js +0 -7
  279. package/dist/cjs/core/beacon/aggregation/messages/sign.js.map +0 -1
  280. package/dist/cjs/core/beacon/aggregation/models/cohort/index.js +0 -92
  281. package/dist/cjs/core/beacon/aggregation/models/cohort/index.js.map +0 -1
  282. package/dist/cjs/core/beacon/aggregation/models/cohort/status.js.map +0 -1
  283. package/dist/cjs/core/beacon/aggregation/protocol/nostr.js +0 -57
  284. package/dist/cjs/core/beacon/aggregation/protocol/nostr.js.map +0 -1
  285. package/dist/cjs/core/beacon/aggregation/protocol/service.js.map +0 -1
  286. package/dist/cjs/core/key-manager/index.js +0 -290
  287. package/dist/cjs/core/key-manager/index.js.map +0 -1
  288. package/dist/cjs/core/key-manager/interface.js +0 -2
  289. package/dist/cjs/core/key-manager/interface.js.map +0 -1
  290. package/dist/cjs/interfaces/ibeacon.js +0 -2
  291. package/dist/cjs/interfaces/ibeacon.js.map +0 -1
  292. package/dist/cjs/types/crud.js +0 -2
  293. package/dist/cjs/types/crud.js.map +0 -1
  294. package/dist/cjs/utils/beacons.js.map +0 -1
  295. package/dist/cjs/utils/identifier.js.map +0 -1
  296. package/dist/esm/core/beacon/aggregation/messages/advert.js +0 -24
  297. package/dist/esm/core/beacon/aggregation/messages/advert.js.map +0 -1
  298. package/dist/esm/core/beacon/aggregation/messages/base.js.map +0 -1
  299. package/dist/esm/core/beacon/aggregation/messages/cohort-set.js +0 -25
  300. package/dist/esm/core/beacon/aggregation/messages/cohort-set.js.map +0 -1
  301. package/dist/esm/core/beacon/aggregation/messages/keygen.js +0 -8
  302. package/dist/esm/core/beacon/aggregation/messages/keygen.js.map +0 -1
  303. package/dist/esm/core/beacon/aggregation/messages/opt-in.js +0 -23
  304. package/dist/esm/core/beacon/aggregation/messages/opt-in.js.map +0 -1
  305. package/dist/esm/core/beacon/aggregation/messages/sign.js +0 -7
  306. package/dist/esm/core/beacon/aggregation/messages/sign.js.map +0 -1
  307. package/dist/esm/core/beacon/aggregation/models/cohort/index.js +0 -92
  308. package/dist/esm/core/beacon/aggregation/models/cohort/index.js.map +0 -1
  309. package/dist/esm/core/beacon/aggregation/models/cohort/status.js.map +0 -1
  310. package/dist/esm/core/beacon/aggregation/protocol/nostr.js +0 -57
  311. package/dist/esm/core/beacon/aggregation/protocol/nostr.js.map +0 -1
  312. package/dist/esm/core/beacon/aggregation/protocol/service.js.map +0 -1
  313. package/dist/esm/core/key-manager/index.js +0 -290
  314. package/dist/esm/core/key-manager/index.js.map +0 -1
  315. package/dist/esm/core/key-manager/interface.js +0 -2
  316. package/dist/esm/core/key-manager/interface.js.map +0 -1
  317. package/dist/esm/interfaces/ibeacon.js +0 -2
  318. package/dist/esm/interfaces/ibeacon.js.map +0 -1
  319. package/dist/esm/types/crud.js +0 -2
  320. package/dist/esm/types/crud.js.map +0 -1
  321. package/dist/esm/utils/beacons.js.map +0 -1
  322. package/dist/esm/utils/identifier.js.map +0 -1
  323. package/dist/types/core/beacon/aggregation/messages/advert.d.ts +0 -22
  324. package/dist/types/core/beacon/aggregation/messages/advert.d.ts.map +0 -1
  325. package/dist/types/core/beacon/aggregation/messages/base.d.ts.map +0 -1
  326. package/dist/types/core/beacon/aggregation/messages/cohort-set.d.ts +0 -23
  327. package/dist/types/core/beacon/aggregation/messages/cohort-set.d.ts.map +0 -1
  328. package/dist/types/core/beacon/aggregation/messages/keygen.d.ts +0 -6
  329. package/dist/types/core/beacon/aggregation/messages/keygen.d.ts.map +0 -1
  330. package/dist/types/core/beacon/aggregation/messages/opt-in.d.ts +0 -22
  331. package/dist/types/core/beacon/aggregation/messages/opt-in.d.ts.map +0 -1
  332. package/dist/types/core/beacon/aggregation/messages/sign.d.ts +0 -5
  333. package/dist/types/core/beacon/aggregation/messages/sign.d.ts.map +0 -1
  334. package/dist/types/core/beacon/aggregation/models/cohort/index.d.ts +0 -77
  335. package/dist/types/core/beacon/aggregation/models/cohort/index.d.ts.map +0 -1
  336. package/dist/types/core/beacon/aggregation/models/cohort/status.d.ts.map +0 -1
  337. package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts +0 -36
  338. package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts.map +0 -1
  339. package/dist/types/core/beacon/aggregation/protocol/service.d.ts +0 -6
  340. package/dist/types/core/beacon/aggregation/protocol/service.d.ts.map +0 -1
  341. package/dist/types/core/key-manager/index.d.ts +0 -145
  342. package/dist/types/core/key-manager/index.d.ts.map +0 -1
  343. package/dist/types/core/key-manager/interface.d.ts +0 -113
  344. package/dist/types/core/key-manager/interface.d.ts.map +0 -1
  345. package/dist/types/interfaces/ibeacon.d.ts +0 -65
  346. package/dist/types/interfaces/ibeacon.d.ts.map +0 -1
  347. package/dist/types/types/crud.d.ts.map +0 -1
  348. package/dist/types/utils/beacons.d.ts.map +0 -1
  349. package/dist/types/utils/identifier.d.ts.map +0 -1
  350. package/src/core/beacon/aggregation/messages/advert.ts +0 -36
  351. package/src/core/beacon/aggregation/messages/cohort-set.ts +0 -37
  352. package/src/core/beacon/aggregation/messages/keygen.ts +0 -8
  353. package/src/core/beacon/aggregation/messages/opt-in.ts +0 -35
  354. package/src/core/beacon/aggregation/messages/sign.ts +0 -7
  355. package/src/core/beacon/aggregation/models/cohort/index.ts +0 -112
  356. package/src/core/beacon/aggregation/protocol/nostr.ts +0 -81
  357. package/src/core/beacon/aggregation/protocol/service.ts +0 -6
  358. package/src/core/key-manager/index.ts +0 -364
  359. package/src/core/key-manager/interface.ts +0 -129
  360. package/src/interfaces/ibeacon.ts +0 -75
  361. /package/dist/cjs/core/beacon/aggregation/{models/cohort → cohort}/status.js +0 -0
  362. /package/dist/cjs/core/beacon/aggregation/{protocol → communication}/service.js +0 -0
  363. /package/dist/esm/core/beacon/aggregation/{models/cohort → cohort}/status.js +0 -0
  364. /package/dist/esm/core/beacon/aggregation/{protocol → communication}/service.js +0 -0
  365. /package/dist/types/core/beacon/aggregation/{models/cohort → cohort}/status.d.ts +0 -0
  366. /package/src/core/beacon/aggregation/{models/cohort → cohort}/status.ts +0 -0
@@ -0,0 +1,13 @@
1
+ import { MethodError } from '@did-btcr2/common';
2
+
3
+ export class CommunicationServiceError extends MethodError {
4
+ constructor(message: string, type: string = 'CommunicationServiceError', data?: Record<string, any>) {
5
+ super(message, type, data);
6
+ }
7
+ }
8
+
9
+ export class CommunicationAdapterError extends MethodError {
10
+ constructor(message: string, type: string = 'CommunicationAdapterError', data?: Record<string, any>) {
11
+ super(message, type, data);
12
+ }
13
+ }
@@ -0,0 +1,25 @@
1
+ import { NotImplementedError } from '@did-btcr2/common';
2
+ import { NostrAdapter } from './adapter/nostr.js';
3
+ import { CommunicationServiceError } from './error.js';
4
+ import { CommunicationService, Service } from './service.js';
5
+
6
+ /**
7
+ * Communication Factory pattern to create Communication Service instances.
8
+ * @class CommunicationFactory
9
+ * @type {CommunicationFactory}
10
+ */
11
+ export class CommunicationFactory {
12
+ static establish(service: Service): CommunicationService {
13
+ switch (service.type) {
14
+ case 'nostr':
15
+ return new NostrAdapter();
16
+ case 'didcomm':
17
+ throw new NotImplementedError('DID Comm service not implemented yet.');
18
+ default:
19
+ throw new CommunicationServiceError(
20
+ `Invalid service type ${service.type}`,
21
+ 'INVALID_BEACON_ERROR', { service }
22
+ );
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,42 @@
1
+ import { Maybe } from '@did-btcr2/common';
2
+ import { AggregateBeaconMessageType } from '../cohort/messages/index.js';
3
+ import { RawSchnorrKeyPair } from '@did-btcr2/keypair';
4
+
5
+ /**
6
+ * ServiceAdapterConfig defines the configuration structure for the Nostr communication service.
7
+ * It includes relay URLs, key pairs, and components for identity generation.
8
+ * @interface ServiceAdapterConfig
9
+ * @extends {Record<string, any>}
10
+ * @type {ServiceAdapterConfig}
11
+ */
12
+ export interface ServiceAdapterConfig extends Record<string, any> {
13
+ keys: ServiceAdapterIdentity<any>;
14
+ did: string;
15
+ }
16
+
17
+ export type SyncMessageHandler = (msg: any) => void;
18
+ export type AsyncMessageHandler = (msg: any) => Promise<void>;
19
+ export type MessageHandler = SyncMessageHandler | AsyncMessageHandler;
20
+
21
+ export type CommunicationServiceType = 'nostr' | 'didcomm';
22
+ export type ServiceAdapterConfigType<T extends ServiceAdapterConfig> = T;
23
+ export interface Service {
24
+ type: CommunicationServiceType;
25
+ keys: ServiceAdapterIdentity<RawSchnorrKeyPair>;
26
+ did: string;
27
+ name?: string;
28
+ }
29
+ export type ServiceAdapter<T extends CommunicationService> = T;
30
+ export type ServiceAdapterIdentity<T extends RawSchnorrKeyPair> = T;
31
+ export interface CommunicationService {
32
+ name: string;
33
+ start(): void;
34
+ setKeys(keys: ServiceAdapterIdentity<RawSchnorrKeyPair>): void;
35
+ registerMessageHandler(messageType: string, handler: MessageHandler): void;
36
+ sendMessage(
37
+ message: Maybe<AggregateBeaconMessageType>,
38
+ sender: string,
39
+ recipient?: string
40
+ ): Promise<void | Promise<string>[]>;
41
+ generateIdentity(keys?: RawSchnorrKeyPair): ServiceAdapterConfigType<ServiceAdapterConfig>;
42
+ }
@@ -1,135 +1,406 @@
1
- import { Base } from './messages/base.js';
2
- import { OptInMessage } from './messages/opt-in.js';
3
- import { OPT_IN, SUBSCRIBE, SUBSCRIBE_ACCEPT } from './messages/keygen.js';
4
- import { Musig2Cohort } from './models/cohort/index.js';
5
- import { NostrAdapter } from './protocol/nostr.js';
6
- import { ProtocolService } from './protocol/service.js';
7
- import { NONCE_CONTRIBUTION, REQUEST_SIGNATURE, SIGNATURE_AUTHORIZATION } from './messages/sign.js';
1
+ import { Logger, Maybe } from '@did-btcr2/common';
2
+ import { RawSchnorrKeyPair } from '@did-btcr2/keypair';
3
+ import { BeaconCoordinatorError } from '../error.js';
4
+ import { AggregateBeaconCohort } from './cohort/index.js';
5
+ import {
6
+ BEACON_COHORT_ADVERT,
7
+ BEACON_COHORT_NONCE_CONTRIBUTION,
8
+ BEACON_COHORT_OPT_IN,
9
+ BEACON_COHORT_OPT_IN_ACCEPT,
10
+ BEACON_COHORT_REQUEST_SIGNATURE,
11
+ BEACON_COHORT_SIGNATURE_AUTHORIZATION
12
+ } from './cohort/messages/constants.js';
13
+ import { BeaconCohortAdvertMessage } from './cohort/messages/keygen/cohort-advert.js';
14
+ import { BeaconCohortReadyMessage } from './cohort/messages/keygen/cohort-ready.js';
15
+ import { BeaconCohortOptInMessage, CohortOptInMessage } from './cohort/messages/keygen/opt-in.js';
16
+ import { BeaconCohortAggregatedNonceMessage } from './cohort/messages/sign/aggregated-nonce.js';
17
+ import { BeaconCohortNonceContributionMessage, CohortNonceContributionMessage } from './cohort/messages/sign/nonce-contribution.js';
18
+ import { BeaconCohortRequestSignatureMessage, CohortRequestSignatureMessage } from './cohort/messages/sign/request-signature.js';
19
+ import { BeaconCohortSignatureAuthorizationMessage, CohortSignatureAuthorizationMessage } from './cohort/messages/sign/signature-authorization.js';
20
+ import { NostrAdapter } from './communication/adapter/nostr.js';
21
+ import { CommunicationFactory } from './communication/factory.js';
22
+ import { CommunicationService, Service, ServiceAdapterIdentity } from './communication/service.js';
23
+ import { BeaconCohortSigningSession } from './session/index.js';
24
+ import { SIGNING_SESSION_STATUS } from './session/status.js';
8
25
 
26
+ type BeaconCoordinatorParams = {
27
+ protocol?: CommunicationService;
28
+ did: string;
29
+ keys: ServiceAdapterIdentity<RawSchnorrKeyPair>
30
+ name?: string;
31
+ }
9
32
  /**
10
33
  * The BeaconCoordinator class is responsible for managing the coordination of beacon aggregation.
11
34
  * @class BeaconCoordinator
12
35
  * @type {BeaconCoordinator}
13
36
  */
37
+
14
38
  export class BeaconCoordinator {
15
39
  /**
16
40
  * The name of the BeaconCoordinator service.
17
41
  * @type {string}
18
42
  */
19
- public name: string = 'BeaconCoordinator';
43
+ public name: string;
20
44
 
21
45
  /**
22
46
  * The DID of the BeaconCoordinator.
23
47
  * @type {Array<string>}
24
48
  */
25
- public did: string = '';
49
+ public did: string;
26
50
 
27
51
  /**
28
- * The protocol service used for communication.
29
- * @type {ProtocolService}
52
+ * The communication protocol used by the BeaconCoordinator.
53
+ * @type {CommunicationService}
30
54
  */
31
- public protocol: ProtocolService;
55
+ public protocol: CommunicationService;
32
56
 
33
57
  /**
34
- * List of subscribers to the BeaconCoordinator service.
58
+ * List of subscribers engaged in a Musig2 Cohort signing session with the BeaconCoordinator.
35
59
  * @type {Array<string>}
36
60
  */
37
- public cohorts: Array<Musig2Cohort> = [];
61
+ public cohorts: Array<AggregateBeaconCohort> = [];
38
62
 
39
63
  /**
40
- * List of subscribers to the BeaconCoordinator service.
41
- * @type {Array<string>}
64
+ * Active signing sessions for the BeaconCoordinator.
65
+ * @type {Record<string, BeaconCohortSigningSession>}
42
66
  */
43
- private subscribers: string[] = [];
67
+ public activeSigningSessions: Map<string, BeaconCohortSigningSession> = new Map();
44
68
 
45
69
  /**
46
70
  * Constructs a new BeaconCoordinator instance.
47
- * @param {ProtocolService} protocol The protocol service used for communication.
48
- * @param {string} [did] Optional DID to use for the coordinator. If not provided, a new DID will be generated.
71
+ * @param {BeaconCoordinatorParams} params The parameters for the coordinator.
72
+ * @param {CommunicationService} params.protocol The protocol service used for communication.
73
+ * @param {string} [params.name] Optional name for the coordinator. If not provided, a default name will be generated.
74
+ * @param {string} [params.did] Optional DID to use for the coordinator. If not provided, a new DID will be generated.
75
+ * @param {ServiceAdapterIdentity<RawKeyPair>} params.keys The keys used for cryptographic operations.
49
76
  */
50
-
51
- constructor(protocol: ProtocolService, did?: string) {
52
- this.protocol = protocol ?? new NostrAdapter();
53
- this.setup(did);
77
+ constructor(params: BeaconCoordinatorParams) {
78
+ this.name = params.name || `btcr2-beacon-coordinator-${crypto.randomUUID()}`;
79
+ this.did = params.did;
80
+ this.protocol = params.protocol || new NostrAdapter();
81
+ this.protocol.setKeys(params.keys);
54
82
  }
55
83
 
56
84
  /**
57
- * Sets up the BeaconCoordinator by registering message handlers and optionally generating a DID.
85
+ * Setup and start the BeaconCoordinator communication protocol.
58
86
  * @returns {void}
59
87
  */
60
- public setup(did?: string): void {
61
- this.did = did || this.protocol.generateIdentity();
62
- this.protocol.registerMessageHandler(SUBSCRIBE, this._handleSubscribe.bind(this));
63
- this.protocol.registerMessageHandler(OPT_IN, this._handleOptIn.bind(this));
64
- this.protocol.registerMessageHandler(REQUEST_SIGNATURE, this._handleSubscribe.bind(this));
65
- this.protocol.registerMessageHandler(NONCE_CONTRIBUTION, this._handleSubscribe.bind(this));
66
- this.protocol.registerMessageHandler(SIGNATURE_AUTHORIZATION, this._handleSubscribe.bind(this));
67
- }
68
-
69
- /**
70
- * Initializes the BeaconCoordinator by setting up the protocol and starting it.
71
- * @param {string} [did] Optional DID to use for the coordinator. If not provided, the existing DID will be used.
72
- */
73
- async initialize(did?: string): Promise<void> {
74
- this.setup(did);
75
- await this.protocol.start();
76
- }
77
-
78
- /**
79
- * Handles subscription requests from other participants.
80
- * @param {Base} message The message containing the subscription request.
81
- * @returns {Promise<void>}
82
- */
83
- private async _handleSubscribe(message: Base): Promise<void> {
84
- const sender = message.from;
85
- if (!this.subscribers.includes(sender)) {
86
- this.subscribers.push(sender);
87
- await this.acceptSubscription(sender);
88
- }
88
+ public start(): void {
89
+ Logger.info(`Setting up BeaconCoordinator ${this.name} (${this.did}) on ${this.protocol.name} ...`);
90
+ this.protocol.registerMessageHandler(BEACON_COHORT_OPT_IN, this._handleOptIn.bind(this));
91
+ this.protocol.registerMessageHandler(BEACON_COHORT_REQUEST_SIGNATURE, this._handleRequestSignature.bind(this));
92
+ this.protocol.registerMessageHandler(BEACON_COHORT_NONCE_CONTRIBUTION, this._handleNonceContribution.bind(this));
93
+ this.protocol.registerMessageHandler(BEACON_COHORT_SIGNATURE_AUTHORIZATION, this._handleSignatureAuthorization.bind(this));
94
+ this.protocol.start();
89
95
  }
90
96
 
91
97
  /**
92
98
  * Handles opt-in requests from participants to join a cohort.
93
- * @param {any} message The message containing the opt-in request.
99
+ * @param {OptInMessage} message The message containing the opt-in request.
94
100
  * @returns {Promise<void>}
95
101
  */
96
- private async _handleOptIn(message: any): Promise<void> {
97
- const optIn = OptInMessage.fromJSON(message);
98
- const cohortId = optIn.cohortId;
102
+ private async _handleOptIn(message: CohortOptInMessage): Promise<void> {
103
+ const optIn = BeaconCohortOptInMessage.fromJSON(message);
104
+ const cohortId = optIn.body?.cohortId;
99
105
  const participant = optIn.from;
100
- const participantPk = optIn.participantPk;
106
+ const participantPk = optIn.body?.participantPk;
107
+ if(!cohortId || !participant || !participantPk) {
108
+ Logger.warn(`Invalid opt-in message from ${participant}: missing cohortId, participant or participantPk`);
109
+ return;
110
+ }
101
111
  const cohort = this.cohorts.find(c => c.id === cohortId);
102
112
  if (cohort && !cohort.participants.includes(participant)) {
103
113
  cohort.participants.push(participant);
104
114
  cohort.cohortKeys.push(participantPk);
105
115
  await this.acceptSubscription(participant);
116
+ // If the cohort has enough participants, start the key generation process.
106
117
  if (cohort.participants.length >= cohort.minParticipants) {
107
118
  await this._startKeyGeneration(cohort);
108
119
  }
109
120
  }
110
121
  }
111
122
 
123
+ /**
124
+ * Handles request signature messages from participants.
125
+ * @private
126
+ * @param {CohortRequestSignatureMessage} message The message containing the request signature.
127
+ * @returns {Promise<void>}
128
+ */
129
+ private async _handleRequestSignature(message: Maybe<CohortRequestSignatureMessage>): Promise<void> {
130
+ const signatureRequest = BeaconCohortRequestSignatureMessage.fromJSON(message);
131
+ const cohortId = signatureRequest.body?.cohortId;
132
+ if (!cohortId) {
133
+ Logger.warn(`Signature request missing cohort ID from ${signatureRequest.from}`);
134
+ return;
135
+ }
136
+ const cohort = this.cohorts.find(c => c.id === cohortId);
137
+ if (!cohort) {
138
+ Logger.error(`Cohort with ID ${cohortId} not found.`);
139
+ return;
140
+ }
141
+ cohort.addSignatureRequest(signatureRequest);
142
+ Logger.info(`Received signature request from ${signatureRequest.from} for cohort ${cohortId}.`);
143
+ }
144
+
145
+ /**
146
+ * Handles nonce contribution messages from participants.
147
+ * @param {CohortNonceContributionMessage} message The message containing the nonce contribution.
148
+ * @returns {Promise<void>}
149
+ */
150
+ private async _handleNonceContribution(message: CohortNonceContributionMessage): Promise<void> {
151
+ // Cast message to NonceContributionMessage type.
152
+ const nonceContribMessage = BeaconCohortNonceContributionMessage.fromJSON(message);
153
+ const cohortId = nonceContribMessage.body?.cohortId;
154
+ if (!cohortId) {
155
+ Logger.warn(`Nonce contribution message missing cohort ID from ${nonceContribMessage.from}`);
156
+ return;
157
+ }
158
+ const sessionId = nonceContribMessage.body?.sessionId;
159
+ if (!sessionId) {
160
+ Logger.warn(`Nonce contribution message missing session ID from ${nonceContribMessage.from}`);
161
+ return;
162
+ }
163
+ // Get the signing session using the cohort ID from the message.
164
+ const signingSession = this.activeSigningSessions.get(cohortId || sessionId);
165
+
166
+ // If the signing session does not exist, log an error and return.
167
+ if(!signingSession) {
168
+ Logger.error(`Session ${cohortId || sessionId} not found.`);
169
+ return;
170
+ }
171
+
172
+ // If the message.cohortId does not match the signingSession.cohortId, throw an error.
173
+ if(cohortId !== signingSession.cohort.id) {
174
+ throw new BeaconCoordinatorError(
175
+ `Nonce contribution for wrong cohort: ${signingSession.cohort.id} != ${cohortId}`,
176
+ 'NONCE_CONTRIBUTION_ERROR', message
177
+ );
178
+ }
179
+ const nonceContribution = nonceContribMessage.body?.nonceContribution;
180
+ if(!nonceContribution) {
181
+ Logger.warn(`Nonce contribution message missing nonce contribution from ${nonceContribMessage.from}`);
182
+ return;
183
+ }
184
+ // Add the nonce contribution to the signing session.
185
+ signingSession.addNonceContribution(nonceContribMessage.from, nonceContribution);
186
+ Logger.info(`Nonce contribution received from ${nonceContribMessage.from} for session ${sessionId}.`);
187
+
188
+ if (signingSession.status !== SIGNING_SESSION_STATUS.NONCE_CONTRIBUTIONS_RECEIVED) {
189
+ await this.sendAggregatedNonce(signingSession);
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Handles signature authorization messages from participants.
195
+ * @param {Maybe<CohortSignatureAuthorizationMessage>} message The message containing the signature authorization request.
196
+ * @returns {Promise<void>}
197
+ */
198
+ private async _handleSignatureAuthorization(message: Maybe<CohortSignatureAuthorizationMessage>): Promise<void> {
199
+ const sigAuthMessage = BeaconCohortSignatureAuthorizationMessage.fromJSON(message);
200
+ const cohortId = sigAuthMessage.body?.cohortId;
201
+ if (!cohortId) {
202
+ Logger.warn(`Signature authorization message missing cohort ID from ${sigAuthMessage.from}`);
203
+ return;
204
+ }
205
+ const sessionId = sigAuthMessage.body?.sessionId;
206
+ if (!sessionId) {
207
+ Logger.warn(`Signature authorization message missing session ID from ${sigAuthMessage.from}`);
208
+ return;
209
+ }
210
+ const signingSession = this.activeSigningSessions.get(cohortId || sessionId);
211
+ if (!signingSession) {
212
+ Logger.error(`Session ${sessionId} not found.`);
213
+ return;
214
+ }
215
+
216
+ if(signingSession.id !== sessionId) {
217
+ throw new BeaconCoordinatorError(
218
+ `Signature authorization for wrong session: ${signingSession.id} != ${sessionId}`,
219
+ 'SIGNATURE_AUTHORIZATION_ERROR', message
220
+ );
221
+ }
222
+
223
+ if(signingSession.status !== SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES) {
224
+ throw new BeaconCoordinatorError(
225
+ `Partial signature received but not expected. Current status: ${signingSession.status}`,
226
+ 'SIGNATURE_AUTHORIZATION_ERROR', message
227
+ );
228
+ }
229
+ const partialSignature = sigAuthMessage.body?.partialSignature;
230
+ if (!partialSignature) {
231
+ Logger.warn(`Signature authorization message missing partial signature from ${sigAuthMessage.from}`);
232
+ return;
233
+ }
234
+ // Add the signature authorization to the signing session.
235
+ signingSession.addPartialSignature(sigAuthMessage.from, partialSignature);
236
+ Logger.info(`Received partial signature from ${sigAuthMessage.from} for session ${sessionId}.`);
237
+
238
+ if(signingSession.partialSignatures.size === signingSession.cohort.participants.length) {
239
+ signingSession.status = SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED;
240
+ }
241
+
242
+ if (signingSession.status === SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED) {
243
+ const signature = await signingSession.generateFinalSignature();
244
+ Logger.info(`Final signature ${signature.toHex()} generated for session ${signingSession.id}`);
245
+ }
246
+ }
247
+
112
248
  /**
113
249
  * Starts the key generation process for a cohort once it has enough participants.
114
250
  * @param {Musig2Cohort} cohort The cohort for which to start key generation.
115
251
  * @returns {Promise<void>}
116
252
  */
117
- private async _startKeyGeneration(cohort: Musig2Cohort): Promise<void> {
253
+ private async _startKeyGeneration(cohort: AggregateBeaconCohort): Promise<void> {
254
+ Logger.info(`Starting key generation for cohort ${cohort.id} with participants: ${cohort.participants.join(', ')}`);
118
255
  cohort.finalize();
256
+ for(const participant of cohort.participants) {
257
+ const message = cohort.getCohortReadyMessage(participant, this.did);
258
+ Logger.info(`Sending BEACON_COHORT_READY message to ${participant}`);
259
+ await this.protocol.sendMessage(message, participant, this.did);
260
+ }
261
+ Logger.info(`Finished sending BEACON_COHORT_READY message to ${cohort.participants.length} participants`);
119
262
  }
120
263
 
121
264
  /**
122
265
  * Accepts a subscription request from a participant.
123
- * @param {string} sender The DID of the participant requesting the subscription.
266
+ * @param {string} participant The DID of the participant requesting the subscription.
124
267
  * @returns {Promise<void>}
125
268
  */
126
- public async acceptSubscription(sender: string): Promise<void> {
127
- console.log(`Accepting subscription from ${sender}`);
128
- const response = {
129
- type : SUBSCRIBE_ACCEPT,
130
- to : sender,
269
+ public async acceptSubscription(participant: string): Promise<void> {
270
+ Logger.info(`Accepting subscription from ${participant}`);
271
+ const message = {
272
+ type : BEACON_COHORT_OPT_IN_ACCEPT,
273
+ to : participant,
131
274
  from : this.did
132
275
  };
133
- await this.protocol.sendMessage(response, sender, this.did);
276
+ await this.protocol.sendMessage(message, this.did, participant);
134
277
  }
135
- }
278
+
279
+ /**
280
+ * Sends the aggregated nonce to all participants in the session.
281
+ * @param {BeaconCohortSigningSession} session The session containing the aggregated nonce.
282
+ * @returns {Promise<void>}
283
+ */
284
+ public async sendAggregatedNonce(session: BeaconCohortSigningSession): Promise<void> {
285
+ const aggregatedNonce = session.generateAggregatedNonce();
286
+ Logger.info(`Aggregated Nonces for session ${session.id}:`, aggregatedNonce);
287
+
288
+ session.status = SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES;
289
+ for (const participant of session.cohort.participants) {
290
+ const message = new BeaconCohortAggregatedNonceMessage({
291
+ to : participant,
292
+ from : this.did,
293
+ cohortId : session.cohort.id,
294
+ sessionId : session.id,
295
+ aggregatedNonce : aggregatedNonce
296
+ });
297
+ Logger.info(`Sending AGGREGATED_NONCE message to ${participant}`);
298
+ await this.protocol.sendMessage(message, participant, this.did);
299
+ }
300
+ Logger.info(`Successfully sent aggregated nonce message to all participants in session ${session.id}.`);
301
+ }
302
+
303
+ /**
304
+ * Announces a new cohort to all subscribers.
305
+ * @param {number} minParticipants The minimum number of participants required for the cohort.
306
+ * @param {string} [network='mutinynet'] The network on which the cohort operates (default is 'signet').
307
+ * @param {string} [beaconType='SMTAggregateBeacon'] The type of beacon to be used (default is 'SMTAggregateBeacon').
308
+ * @returns {Promise<AggregateBeaconCohort>} The newly created cohort.
309
+ */
310
+ public async advertiseCohort(
311
+ minParticipants: number,
312
+ network: string = 'mutinynet',
313
+ beaconType: string = 'SMTAggregateBeacon'
314
+ ): Promise<AggregateBeaconCohort> {
315
+ const cohort = new AggregateBeaconCohort({ minParticipants, network, beaconType });
316
+ Logger.info(`Advertising new cohort ${cohort.id} ...`);
317
+ this.cohorts.push(cohort);
318
+ const message = new BeaconCohortAdvertMessage({
319
+ from : this.did,
320
+ cohortId : cohort.id,
321
+ cohortSize : cohort.minParticipants,
322
+ network : cohort.network,
323
+ beaconType
324
+ });
325
+ Logger.info(`Sending ${BEACON_COHORT_ADVERT} message to network ...`, message);
326
+ await this.protocol.sendMessage(message, this.did);
327
+ Logger.info(`Cohort ${cohort.id} advertised successfully.`);
328
+ return cohort;
329
+ }
330
+
331
+
332
+ /**
333
+ * Announces to all subscribers a cohort is ready for signing.
334
+ * @param {string} cohortId The minimum number of participants required for the cohort.
335
+ * @returns {Promise<AggregateBeaconCohort>} The newly created cohort.
336
+ */
337
+ public async announceCohortReady(cohortId: string): Promise<AggregateBeaconCohort> {
338
+ const cohort = this.cohorts.find(c => c.id === cohortId);
339
+ if (!cohort) {
340
+ Logger.error(`Cohort with ID ${cohortId} not found.`);
341
+ throw new BeaconCoordinatorError(
342
+ `Cohort with ID ${cohortId} not found.`,
343
+ 'COHORT_NOT_FOUND', { cohortId }
344
+ );
345
+ }
346
+ Logger.info(`Announcing cohort ${cohort.id} to ${cohort.participants.length} subscribers...`);
347
+ this.cohorts.push(cohort);
348
+ for (const participant of cohort.participants) {
349
+ const message = new BeaconCohortReadyMessage({
350
+ to : participant,
351
+ from : this.did,
352
+ cohortId : cohort.id,
353
+ beaconAddress : cohort.beaconAddress,
354
+ cohortKeys : cohort.cohortKeys,
355
+ });
356
+ Logger.info(`Sending ${BEACON_COHORT_ADVERT} message to ${participant}`);
357
+
358
+ await this.protocol.sendMessage(message, this.did, participant);
359
+ }
360
+ return cohort;
361
+ }
362
+
363
+ /**
364
+ * Starts a signing session for a given cohort.
365
+ * @param {string} cohortId The ID of the cohort for which to start a signing session.
366
+ * @returns {Promise<BeaconCohortSigningSession>} The started signing session.
367
+ * @throws {BeaconCoordinatorError} If the cohort with the given ID is not found.
368
+ */
369
+ public async startSigningSession(cohortId: string): Promise<BeaconCohortSigningSession> {
370
+ Logger.info(`Attempting to start signing session for cohort ${cohortId}`);
371
+ const cohort = this.cohorts.find(c => c.id === cohortId);
372
+ if (!cohort) {
373
+ Logger.error(`Cohort with ID ${cohortId} not found.`);
374
+ throw new BeaconCoordinatorError(`Cohort with ID ${cohortId} not found.`, 'COHORT_NOT_FOUND');
375
+ }
376
+ Logger.info(`Cohort ${cohortId} found. Starting signing session.`);
377
+ const signingSession = cohort.startSigningSession();
378
+ Logger.info(`Starting signing session ${signingSession.id} for cohort ${cohortId}`);
379
+ for (const participant of cohort.participants) {
380
+ const msg = signingSession.getAuthorizationRequest(participant, this.did);
381
+ Logger.info(`Sending authorization request to ${participant}`);
382
+ await this.protocol.sendMessage(msg, this.did, participant).catch(error => {
383
+ Logger.error(`Error sending authorization request to ${participant}: ${error.message}`);
384
+ });
385
+ }
386
+ this.activeSigningSessions.set(cohortId, signingSession);
387
+ Logger.info(`Signing session ${signingSession.id} started for cohort ${cohortId}`);
388
+ return signingSession;
389
+ }
390
+
391
+ /**
392
+ * Static initialization method for the BeaconCoordinator.
393
+ * @param {Service} service The communication service configuration.
394
+ * @returns {BeaconCoordinator} Initialized BeaconCoordinator instance.
395
+ */
396
+ public static initialize(service: Service): BeaconCoordinator {
397
+ const communicationService = CommunicationFactory.establish(service);
398
+ const coordinator = new BeaconCoordinator({
399
+ protocol : communicationService,
400
+ did : service.did,
401
+ keys : service.keys,
402
+ });
403
+ Logger.info(`BeaconCoordinator ${coordinator.name} initialized with DID ${coordinator.did}. Run .start() to listen for messages`);
404
+ return coordinator;
405
+ }
406
+ }