@did-btcr2/method 0.25.3 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (406) hide show
  1. package/README.md +86 -233
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/browser.js +129207 -122358
  4. package/dist/browser.mjs +129235 -122386
  5. package/dist/cjs/index.js +5332 -43
  6. package/dist/esm/core/aggregation/cohort.js +178 -0
  7. package/dist/esm/core/aggregation/cohort.js.map +1 -0
  8. package/dist/esm/core/aggregation/errors.js +22 -0
  9. package/dist/esm/core/aggregation/errors.js.map +1 -0
  10. package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
  11. package/dist/esm/core/aggregation/messages/base.js.map +1 -0
  12. package/dist/esm/core/aggregation/messages/constants.js +26 -0
  13. package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
  14. package/dist/esm/core/aggregation/messages/factories.js +113 -0
  15. package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
  16. package/dist/esm/core/aggregation/messages/guards.js +37 -0
  17. package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
  18. package/dist/esm/core/aggregation/messages/index.js +5 -0
  19. package/dist/esm/core/aggregation/messages/index.js.map +1 -0
  20. package/dist/esm/core/aggregation/participant.js +376 -0
  21. package/dist/esm/core/aggregation/participant.js.map +1 -0
  22. package/dist/esm/core/aggregation/phases.js +39 -0
  23. package/dist/esm/core/aggregation/phases.js.map +1 -0
  24. package/dist/esm/core/aggregation/runner/events.js +2 -0
  25. package/dist/esm/core/aggregation/runner/events.js.map +1 -0
  26. package/dist/esm/core/aggregation/runner/index.js +5 -0
  27. package/dist/esm/core/aggregation/runner/index.js.map +1 -0
  28. package/dist/esm/core/aggregation/runner/participant-runner.js +282 -0
  29. package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
  30. package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
  31. package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
  32. package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
  33. package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
  34. package/dist/esm/core/aggregation/service.js +416 -0
  35. package/dist/esm/core/aggregation/service.js.map +1 -0
  36. package/dist/esm/core/aggregation/signing-session.js +133 -0
  37. package/dist/esm/core/aggregation/signing-session.js.map +1 -0
  38. package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
  39. package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
  40. package/dist/esm/core/aggregation/transport/error.js +12 -0
  41. package/dist/esm/core/aggregation/transport/error.js.map +1 -0
  42. package/dist/esm/core/aggregation/transport/factory.js +20 -0
  43. package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
  44. package/dist/esm/core/aggregation/transport/index.js +6 -0
  45. package/dist/esm/core/aggregation/transport/index.js.map +1 -0
  46. package/dist/esm/core/aggregation/transport/nostr.js +262 -0
  47. package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
  48. package/dist/esm/core/aggregation/transport/transport.js +2 -0
  49. package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
  50. package/dist/esm/core/beacon/beacon.js +80 -0
  51. package/dist/esm/core/beacon/beacon.js.map +1 -1
  52. package/dist/esm/core/beacon/cas-beacon.js +21 -60
  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/signal-discovery.js +1 -1
  59. package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
  60. package/dist/esm/core/beacon/singleton-beacon.js +13 -56
  61. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  62. package/dist/esm/core/beacon/smt-beacon.js +85 -9
  63. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  64. package/dist/esm/core/beacon/utils.js.map +1 -1
  65. package/dist/esm/core/identifier.js +13 -0
  66. package/dist/esm/core/identifier.js.map +1 -1
  67. package/dist/esm/core/resolver.js +50 -35
  68. package/dist/esm/core/resolver.js.map +1 -1
  69. package/dist/esm/core/update.js.map +1 -1
  70. package/dist/esm/did-btcr2.js +1 -1
  71. package/dist/esm/did-btcr2.js.map +1 -1
  72. package/dist/esm/index.js +14 -24
  73. package/dist/esm/index.js.map +1 -1
  74. package/dist/esm/utils/appendix.js +7 -6
  75. package/dist/esm/utils/appendix.js.map +1 -1
  76. package/dist/esm/utils/did-document-builder.js.map +1 -1
  77. package/dist/esm/utils/did-document.js +2 -2
  78. package/dist/esm/utils/did-document.js.map +1 -1
  79. package/dist/types/core/aggregation/cohort.d.ts +94 -0
  80. package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
  81. package/dist/types/core/aggregation/errors.d.ts +14 -0
  82. package/dist/types/core/aggregation/errors.d.ts.map +1 -0
  83. package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
  84. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
  85. package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
  86. package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
  87. package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
  88. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
  89. package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
  90. package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
  91. package/dist/types/core/aggregation/messages/index.d.ts +5 -0
  92. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
  93. package/dist/types/core/aggregation/participant.d.ts +101 -0
  94. package/dist/types/core/aggregation/participant.d.ts.map +1 -0
  95. package/dist/types/core/aggregation/phases.d.ts +49 -0
  96. package/dist/types/core/aggregation/phases.d.ts.map +1 -0
  97. package/dist/types/core/aggregation/runner/events.d.ts +89 -0
  98. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
  99. package/dist/types/core/aggregation/runner/index.d.ts +5 -0
  100. package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
  101. package/dist/types/core/aggregation/runner/participant-runner.d.ts +107 -0
  102. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
  103. package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
  104. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
  105. package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
  106. package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
  107. package/dist/types/core/aggregation/service.d.ts +112 -0
  108. package/dist/types/core/aggregation/service.d.ts.map +1 -0
  109. package/dist/types/core/aggregation/signing-session.d.ts +69 -0
  110. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
  111. package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
  112. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
  113. package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
  114. package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
  115. package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
  116. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
  117. package/dist/types/core/aggregation/transport/index.d.ts +6 -0
  118. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
  119. package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
  120. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
  121. package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
  122. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
  123. package/dist/types/core/beacon/beacon.d.ts +41 -6
  124. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  125. package/dist/types/core/beacon/cas-beacon.d.ts +23 -11
  126. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  127. package/dist/types/core/beacon/error.d.ts +0 -6
  128. package/dist/types/core/beacon/error.d.ts.map +1 -1
  129. package/dist/types/core/beacon/factory.d.ts +2 -2
  130. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  131. package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
  132. package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
  133. package/dist/types/core/beacon/interfaces.d.ts +11 -3
  134. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  135. package/dist/types/core/beacon/signal-discovery.d.ts +3 -3
  136. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
  137. package/dist/types/core/beacon/singleton-beacon.d.ts +14 -7
  138. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  139. package/dist/types/core/beacon/smt-beacon.d.ts +32 -12
  140. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  141. package/dist/types/core/beacon/utils.d.ts +4 -4
  142. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  143. package/dist/types/core/identifier.d.ts +10 -2
  144. package/dist/types/core/identifier.d.ts.map +1 -1
  145. package/dist/types/core/interfaces.d.ts +4 -4
  146. package/dist/types/core/interfaces.d.ts.map +1 -1
  147. package/dist/types/core/resolver.d.ts +19 -9
  148. package/dist/types/core/resolver.d.ts.map +1 -1
  149. package/dist/types/core/types.d.ts +6 -5
  150. package/dist/types/core/types.d.ts.map +1 -1
  151. package/dist/types/core/update.d.ts +5 -5
  152. package/dist/types/core/update.d.ts.map +1 -1
  153. package/dist/types/did-btcr2.d.ts +6 -6
  154. package/dist/types/did-btcr2.d.ts.map +1 -1
  155. package/dist/types/index.d.ts +9 -24
  156. package/dist/types/index.d.ts.map +1 -1
  157. package/dist/types/utils/appendix.d.ts +7 -7
  158. package/dist/types/utils/appendix.d.ts.map +1 -1
  159. package/dist/types/utils/did-document-builder.d.ts +3 -2
  160. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  161. package/dist/types/utils/did-document.d.ts +3 -3
  162. package/dist/types/utils/did-document.d.ts.map +1 -1
  163. package/package.json +35 -33
  164. package/src/core/aggregation/cohort.ts +247 -0
  165. package/src/core/aggregation/errors.ts +25 -0
  166. package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
  167. package/src/core/aggregation/messages/constants.ts +28 -0
  168. package/src/core/aggregation/messages/factories.ts +240 -0
  169. package/src/core/aggregation/messages/guards.ts +55 -0
  170. package/src/core/aggregation/messages/index.ts +4 -0
  171. package/src/core/aggregation/participant.ts +510 -0
  172. package/src/core/aggregation/phases.ts +82 -0
  173. package/src/core/aggregation/runner/events.ts +77 -0
  174. package/src/core/aggregation/runner/index.ts +4 -0
  175. package/src/core/aggregation/runner/participant-runner.ts +360 -0
  176. package/src/core/aggregation/runner/service-runner.ts +365 -0
  177. package/src/core/aggregation/runner/typed-emitter.ts +87 -0
  178. package/src/core/aggregation/service.ts +547 -0
  179. package/src/core/aggregation/signing-session.ts +209 -0
  180. package/src/core/aggregation/transport/didcomm.ts +42 -0
  181. package/src/core/aggregation/transport/error.ts +13 -0
  182. package/src/core/aggregation/transport/factory.ts +29 -0
  183. package/src/core/aggregation/transport/index.ts +5 -0
  184. package/src/core/aggregation/transport/nostr.ts +333 -0
  185. package/src/core/aggregation/transport/transport.ts +46 -0
  186. package/src/core/beacon/beacon.ts +126 -6
  187. package/src/core/beacon/cas-beacon.ts +39 -83
  188. package/src/core/beacon/error.ts +0 -12
  189. package/src/core/beacon/factory.ts +2 -2
  190. package/src/core/beacon/fee-estimator.ts +52 -0
  191. package/src/core/beacon/interfaces.ts +13 -4
  192. package/src/core/beacon/signal-discovery.ts +5 -4
  193. package/src/core/beacon/singleton-beacon.ts +21 -81
  194. package/src/core/beacon/smt-beacon.ts +113 -15
  195. package/src/core/beacon/utils.ts +6 -4
  196. package/src/core/identifier.ts +20 -2
  197. package/src/core/interfaces.ts +4 -4
  198. package/src/core/resolver.ts +84 -53
  199. package/src/core/types.ts +6 -5
  200. package/src/core/update.ts +11 -7
  201. package/src/did-btcr2.ts +12 -10
  202. package/src/index.ts +15 -29
  203. package/src/utils/appendix.ts +14 -16
  204. package/src/utils/did-document-builder.ts +3 -2
  205. package/src/utils/did-document.ts +10 -8
  206. package/dist/cjs/core/beacon/aggregation/cohort/index.js +0 -237
  207. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +0 -1
  208. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +0 -26
  209. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  210. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  211. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  212. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js +0 -98
  213. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  214. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  215. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  216. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  217. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  218. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  219. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  220. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  221. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  222. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  223. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  224. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  225. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  226. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  227. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  228. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  229. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  230. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  231. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  232. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  233. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  234. package/dist/cjs/core/beacon/aggregation/cohort/status.js +0 -8
  235. package/dist/cjs/core/beacon/aggregation/cohort/status.js.map +0 -1
  236. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  237. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  238. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +0 -246
  239. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  240. package/dist/cjs/core/beacon/aggregation/communication/error.js +0 -12
  241. package/dist/cjs/core/beacon/aggregation/communication/error.js.map +0 -1
  242. package/dist/cjs/core/beacon/aggregation/communication/factory.js +0 -21
  243. package/dist/cjs/core/beacon/aggregation/communication/factory.js.map +0 -1
  244. package/dist/cjs/core/beacon/aggregation/communication/service.js +0 -2
  245. package/dist/cjs/core/beacon/aggregation/communication/service.js.map +0 -1
  246. package/dist/cjs/core/beacon/aggregation/coordinator.js +0 -343
  247. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +0 -1
  248. package/dist/cjs/core/beacon/aggregation/participant.js +0 -435
  249. package/dist/cjs/core/beacon/aggregation/participant.js.map +0 -1
  250. package/dist/cjs/core/beacon/aggregation/session/index.js +0 -244
  251. package/dist/cjs/core/beacon/aggregation/session/index.js.map +0 -1
  252. package/dist/cjs/core/beacon/aggregation/session/status.js +0 -11
  253. package/dist/cjs/core/beacon/aggregation/session/status.js.map +0 -1
  254. package/dist/cjs/core/beacon/beacon.js +0 -25
  255. package/dist/cjs/core/beacon/beacon.js.map +0 -1
  256. package/dist/cjs/core/beacon/cas-beacon.js +0 -152
  257. package/dist/cjs/core/beacon/cas-beacon.js.map +0 -1
  258. package/dist/cjs/core/beacon/error.js +0 -37
  259. package/dist/cjs/core/beacon/error.js.map +0 -1
  260. package/dist/cjs/core/beacon/factory.js +0 -29
  261. package/dist/cjs/core/beacon/factory.js.map +0 -1
  262. package/dist/cjs/core/beacon/interfaces.js +0 -2
  263. package/dist/cjs/core/beacon/interfaces.js.map +0 -1
  264. package/dist/cjs/core/beacon/signal-discovery.js +0 -183
  265. package/dist/cjs/core/beacon/signal-discovery.js.map +0 -1
  266. package/dist/cjs/core/beacon/singleton-beacon.js +0 -107
  267. package/dist/cjs/core/beacon/singleton-beacon.js.map +0 -1
  268. package/dist/cjs/core/beacon/smt-beacon.js +0 -39
  269. package/dist/cjs/core/beacon/smt-beacon.js.map +0 -1
  270. package/dist/cjs/core/beacon/utils.js +0 -163
  271. package/dist/cjs/core/beacon/utils.js.map +0 -1
  272. package/dist/cjs/core/identifier.js +0 -248
  273. package/dist/cjs/core/identifier.js.map +0 -1
  274. package/dist/cjs/core/interfaces.js +0 -2
  275. package/dist/cjs/core/interfaces.js.map +0 -1
  276. package/dist/cjs/core/resolver.js +0 -476
  277. package/dist/cjs/core/resolver.js.map +0 -1
  278. package/dist/cjs/core/types.js +0 -2
  279. package/dist/cjs/core/types.js.map +0 -1
  280. package/dist/cjs/core/update.js +0 -112
  281. package/dist/cjs/core/update.js.map +0 -1
  282. package/dist/cjs/did-btcr2.js +0 -193
  283. package/dist/cjs/did-btcr2.js.map +0 -1
  284. package/dist/cjs/index.js.map +0 -1
  285. package/dist/cjs/utils/appendix.js +0 -203
  286. package/dist/cjs/utils/appendix.js.map +0 -1
  287. package/dist/cjs/utils/did-document-builder.js +0 -60
  288. package/dist/cjs/utils/did-document-builder.js.map +0 -1
  289. package/dist/cjs/utils/did-document.js +0 -424
  290. package/dist/cjs/utils/did-document.js.map +0 -1
  291. package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
  292. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
  293. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  294. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  295. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  296. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
  297. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  298. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  299. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  300. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  301. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  302. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  303. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  304. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  305. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  306. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  307. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  308. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  309. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  310. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  311. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  312. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  313. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  314. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  315. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  316. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  317. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  318. package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
  319. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
  320. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  321. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  322. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -246
  323. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  324. package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
  325. package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
  326. package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
  327. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
  328. package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
  329. package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
  330. package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
  331. package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
  332. package/dist/esm/core/beacon/aggregation/participant.js +0 -435
  333. package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
  334. package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
  335. package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
  336. package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
  337. package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
  338. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
  339. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
  340. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
  341. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
  342. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
  343. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
  344. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
  345. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
  346. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
  347. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
  348. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
  349. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
  350. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
  351. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
  352. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
  353. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
  354. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
  355. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
  356. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
  357. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
  358. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
  359. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
  360. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
  361. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
  362. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
  363. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
  364. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
  365. package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
  366. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
  367. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
  368. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
  369. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
  370. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
  371. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
  372. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
  373. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
  374. package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
  375. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
  376. package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
  377. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
  378. package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
  379. package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
  380. package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
  381. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
  382. package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
  383. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
  384. package/src/core/beacon/aggregation/cohort/index.ts +0 -304
  385. package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
  386. package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
  387. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -43
  388. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -39
  389. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -34
  390. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -33
  391. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -35
  392. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -38
  393. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -39
  394. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -39
  395. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -39
  396. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -40
  397. package/src/core/beacon/aggregation/cohort/status.ts +0 -7
  398. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -147
  399. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -321
  400. package/src/core/beacon/aggregation/communication/error.ts +0 -13
  401. package/src/core/beacon/aggregation/communication/factory.ts +0 -25
  402. package/src/core/beacon/aggregation/communication/service.ts +0 -42
  403. package/src/core/beacon/aggregation/coordinator.ts +0 -415
  404. package/src/core/beacon/aggregation/participant.ts +0 -512
  405. package/src/core/beacon/aggregation/session/index.ts +0 -300
  406. package/src/core/beacon/aggregation/session/status.ts +0 -18
@@ -0,0 +1,80 @@
1
+ /**
2
+ * Tiny strongly-typed event emitter.
3
+ *
4
+ * Browser-compatible (no Node.js `events` module). Uses a generic event map
5
+ * to give compile-time safety on event names and listener signatures.
6
+ *
7
+ * @example
8
+ * type MyEvents = {
9
+ * 'connected': [{ host: string }];
10
+ * 'data': [Uint8Array];
11
+ * 'error': [Error];
12
+ * };
13
+ *
14
+ * class MyClient extends TypedEventEmitter<MyEvents> {
15
+ * doStuff() {
16
+ * this.emit('connected', { host: 'example.com' }); // ✓ typed
17
+ * this.emit('data', new Uint8Array([1, 2])); // ✓ typed
18
+ * }
19
+ * }
20
+ *
21
+ * const client = new MyClient();
22
+ * client.on('connected', ({ host }) => console.log(host)); // ✓ typed
23
+ */
24
+ export class TypedEventEmitter {
25
+ #listeners = new Map();
26
+ /** Subscribe to an event. */
27
+ on(event, listener) {
28
+ let set = this.#listeners.get(event);
29
+ if (!set) {
30
+ set = new Set();
31
+ this.#listeners.set(event, set);
32
+ }
33
+ set.add(listener);
34
+ return this;
35
+ }
36
+ /** Subscribe to an event, automatically unsubscribing after the first call. */
37
+ once(event, listener) {
38
+ const wrapped = ((...args) => {
39
+ this.off(event, wrapped);
40
+ listener(...args);
41
+ });
42
+ return this.on(event, wrapped);
43
+ }
44
+ /** Unsubscribe a specific listener. */
45
+ off(event, listener) {
46
+ this.#listeners.get(event)?.delete(listener);
47
+ return this;
48
+ }
49
+ /** Emit an event to all subscribed listeners. */
50
+ emit(event, ...args) {
51
+ const set = this.#listeners.get(event);
52
+ if (!set || set.size === 0)
53
+ return false;
54
+ for (const listener of set) {
55
+ try {
56
+ listener(...args);
57
+ }
58
+ catch (err) {
59
+ // Listener errors must not break other listeners
60
+ console.error(`Listener for event "${String(event)}" threw:`, err);
61
+ }
62
+ }
63
+ return true;
64
+ }
65
+ /** Remove all listeners (optionally for a specific event). */
66
+ removeAllListeners(event) {
67
+ if (event === undefined) {
68
+ this.#listeners.clear();
69
+ }
70
+ else {
71
+ this.#listeners.delete(event);
72
+ }
73
+ return this;
74
+ }
75
+ /** Number of listeners for an event. */
76
+ listenerCount(event) {
77
+ return this.#listeners.get(event)?.size ?? 0;
78
+ }
79
+ }
80
+ //# sourceMappingURL=typed-emitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typed-emitter.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/runner/typed-emitter.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAMH,M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;gBACH,QAAQ,CAAC,GAAG,IAAI,CAAC,CAAC;YACpB,CAAC;YAAC,OAAM,GAAG,EAAE,CAAC;gBACZ,iDAAiD;gBACjD,OAAO,CAAC,KAAK,CAAC,uBAAuB,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;YACrE,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,8DAA8D;IAC9D,kBAAkB,CAAyB,KAAS;QAClD,IAAG,KAAK,KAAK,SAAS,EAAE,CAAC;YACvB,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QAC1B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAChC,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED,wCAAwC;IACxC,aAAa,CAAyB,KAAQ;QAC5C,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE,IAAI,IAAI,CAAC,CAAC;IAC/C,CAAC;CACF"}
@@ -0,0 +1,416 @@
1
+ import { bytesToHex } from '@noble/hashes/utils';
2
+ import { AggregationCohort } from './cohort.js';
3
+ import { AggregationServiceError } from './errors.js';
4
+ import { COHORT_OPT_IN, NONCE_CONTRIBUTION, SIGNATURE_AUTHORIZATION, SUBMIT_UPDATE, VALIDATION_ACK, } from './messages/constants.js';
5
+ import { createAuthorizationRequestMessage, createCohortAdvertMessage, createCohortOptInAcceptMessage, createCohortReadyMessage, createDistributeAggregatedDataMessage, createAggregatedNonceMessage, } from './messages/factories.js';
6
+ import { ServiceCohortPhase } from './phases.js';
7
+ import { BeaconSigningSession } from './signing-session.js';
8
+ /**
9
+ * Sans-I/O state machine for an Aggregation Service.
10
+ *
11
+ * Manages multiple cohorts simultaneously. The service operator drives the
12
+ * state machine via `receive()` (for incoming messages) and explicit action
13
+ * methods (advertising, accepting opt-ins, finalizing keygen, building
14
+ * aggregated data, starting signing). All outgoing messages are returned for
15
+ * the caller to send via whatever transport.
16
+ *
17
+ * @class AggregationService
18
+ */
19
+ export class AggregationService {
20
+ did;
21
+ keys;
22
+ /** Per-cohort state, keyed by cohortId. */
23
+ #cohortStates = new Map();
24
+ constructor({ did, keys }) {
25
+ this.did = did;
26
+ this.keys = keys;
27
+ }
28
+ receive(message) {
29
+ const type = message.type;
30
+ switch (type) {
31
+ case COHORT_OPT_IN:
32
+ this.#handleOptIn(message);
33
+ break;
34
+ case SUBMIT_UPDATE:
35
+ this.#handleSubmitUpdate(message);
36
+ break;
37
+ case VALIDATION_ACK:
38
+ this.#handleValidationAck(message);
39
+ break;
40
+ case NONCE_CONTRIBUTION:
41
+ this.#handleNonceContribution(message);
42
+ break;
43
+ case SIGNATURE_AUTHORIZATION:
44
+ this.#handleSignatureAuthorization(message);
45
+ break;
46
+ default:
47
+ // Unknown message type — silently ignore
48
+ break;
49
+ }
50
+ }
51
+ /**
52
+ * Create a new cohort with the given config. Returns the cohort ID.
53
+ * Cohort starts in `Created` phase — call `advertise()` to broadcast.
54
+ */
55
+ createCohort(config) {
56
+ const cohort = new AggregationCohort({
57
+ serviceDid: this.did,
58
+ minParticipants: config.minParticipants,
59
+ network: config.network,
60
+ beaconType: config.beaconType,
61
+ });
62
+ this.#cohortStates.set(cohort.id, {
63
+ phase: ServiceCohortPhase.Created,
64
+ cohort,
65
+ config,
66
+ pendingOptIns: new Map(),
67
+ acceptedParticipants: new Set(),
68
+ });
69
+ return cohort.id;
70
+ }
71
+ /**
72
+ * Advertise a cohort to discover participants.
73
+ * Returns the advert message to broadcast.
74
+ */
75
+ advertise(cohortId) {
76
+ const state = this.#cohortStates.get(cohortId);
77
+ if (!state) {
78
+ throw new AggregationServiceError(`Cohort ${cohortId} not found.`, 'COHORT_NOT_FOUND', { cohortId });
79
+ }
80
+ if (state.phase !== ServiceCohortPhase.Created) {
81
+ throw new AggregationServiceError(`Cannot advertise cohort ${cohortId}: phase is ${state.phase}.`, 'INVALID_PHASE', { cohortId, phase: state.phase });
82
+ }
83
+ const message = createCohortAdvertMessage({
84
+ from: this.did,
85
+ cohortId,
86
+ cohortSize: state.config.minParticipants,
87
+ beaconType: state.config.beaconType,
88
+ network: state.config.network,
89
+ communicationPk: this.keys.publicKey.compressed,
90
+ });
91
+ state.phase = ServiceCohortPhase.Advertised;
92
+ return [message];
93
+ }
94
+ /** Pending opt-ins awaiting operator approval. */
95
+ pendingOptIns(cohortId) {
96
+ const state = this.#cohortStates.get(cohortId);
97
+ if (!state)
98
+ return new Map();
99
+ // Return only those not yet accepted
100
+ const map = new Map();
101
+ for (const [did, optIn] of state.pendingOptIns) {
102
+ if (!state.acceptedParticipants.has(did)) {
103
+ map.set(did, optIn);
104
+ }
105
+ }
106
+ return map;
107
+ }
108
+ #handleOptIn(message) {
109
+ const cohortId = message.body?.cohortId;
110
+ if (!cohortId)
111
+ return;
112
+ const state = this.#cohortStates.get(cohortId);
113
+ if (!state)
114
+ return;
115
+ if (state.phase !== ServiceCohortPhase.Advertised)
116
+ return;
117
+ const participantDid = message.from;
118
+ const participantPk = message.body?.participantPk;
119
+ const communicationPk = message.body?.communicationPk;
120
+ if (!participantPk || !communicationPk)
121
+ return;
122
+ state.pendingOptIns.set(participantDid, {
123
+ cohortId,
124
+ participantDid,
125
+ participantPk,
126
+ communicationPk,
127
+ });
128
+ }
129
+ /**
130
+ * Service operator accepts a participant's opt-in.
131
+ * Returns the accept message to send.
132
+ */
133
+ acceptParticipant(cohortId, participantDid) {
134
+ const state = this.#cohortStates.get(cohortId);
135
+ if (!state) {
136
+ throw new AggregationServiceError(`Cohort ${cohortId} not found.`, 'COHORT_NOT_FOUND', { cohortId });
137
+ }
138
+ const optIn = state.pendingOptIns.get(participantDid);
139
+ if (!optIn) {
140
+ throw new AggregationServiceError(`No pending opt-in from ${participantDid} for cohort ${cohortId}.`, 'NO_OPT_IN', { cohortId, participantDid });
141
+ }
142
+ if (state.acceptedParticipants.has(participantDid)) {
143
+ throw new AggregationServiceError(`Participant ${participantDid} already accepted into cohort ${cohortId}.`, 'ALREADY_ACCEPTED', { cohortId, participantDid });
144
+ }
145
+ state.acceptedParticipants.add(participantDid);
146
+ state.cohort.participants.push(participantDid);
147
+ state.cohort.cohortKeys = [...state.cohort.cohortKeys, optIn.participantPk];
148
+ return [createCohortOptInAcceptMessage({
149
+ from: this.did,
150
+ to: participantDid,
151
+ cohortId,
152
+ })];
153
+ }
154
+ /**
155
+ * Finalize cohort keygen: compute MuSig2 Taproot beacon address and send
156
+ * COHORT_READY messages to all accepted participants.
157
+ */
158
+ finalizeKeygen(cohortId) {
159
+ const state = this.#cohortStates.get(cohortId);
160
+ if (!state) {
161
+ throw new AggregationServiceError(`Cohort ${cohortId} not found.`, 'COHORT_NOT_FOUND', { cohortId });
162
+ }
163
+ if (state.phase !== ServiceCohortPhase.Advertised) {
164
+ throw new AggregationServiceError(`Cannot finalize keygen for cohort ${cohortId}: phase is ${state.phase}.`, 'INVALID_PHASE', { cohortId, phase: state.phase });
165
+ }
166
+ if (state.acceptedParticipants.size < state.config.minParticipants) {
167
+ throw new AggregationServiceError(`Cohort ${cohortId} has only ${state.acceptedParticipants.size} accepted participants, need ${state.config.minParticipants}.`, 'NOT_ENOUGH_PARTICIPANTS', { cohortId });
168
+ }
169
+ const beaconAddress = state.cohort.computeBeaconAddress();
170
+ state.phase = ServiceCohortPhase.CohortSet;
171
+ const messages = [];
172
+ for (const participantDid of state.cohort.participants) {
173
+ messages.push(createCohortReadyMessage({
174
+ from: this.did,
175
+ to: participantDid,
176
+ cohortId,
177
+ beaconAddress,
178
+ cohortKeys: state.cohort.cohortKeys,
179
+ }));
180
+ }
181
+ return messages;
182
+ }
183
+ /** Updates collected so far for a cohort. */
184
+ collectedUpdates(cohortId) {
185
+ const state = this.#cohortStates.get(cohortId);
186
+ if (!state)
187
+ return new Map();
188
+ return state.cohort.pendingUpdates;
189
+ }
190
+ #handleSubmitUpdate(message) {
191
+ const cohortId = message.body?.cohortId;
192
+ if (!cohortId)
193
+ return;
194
+ const state = this.#cohortStates.get(cohortId);
195
+ if (!state)
196
+ return;
197
+ if (state.phase !== ServiceCohortPhase.CohortSet && state.phase !== ServiceCohortPhase.CollectingUpdates)
198
+ return;
199
+ const signedUpdate = message.body?.signedUpdate;
200
+ if (!signedUpdate)
201
+ return;
202
+ state.cohort.addUpdate(message.from, signedUpdate);
203
+ if (state.phase === ServiceCohortPhase.CohortSet) {
204
+ state.phase = ServiceCohortPhase.CollectingUpdates;
205
+ }
206
+ if (state.cohort.hasAllUpdates()) {
207
+ state.phase = ServiceCohortPhase.UpdatesCollected;
208
+ }
209
+ }
210
+ /**
211
+ * Build the aggregated data structure (CAS Announcement or SMT tree) and
212
+ * return distribute messages to send to all participants for validation.
213
+ */
214
+ buildAndDistribute(cohortId) {
215
+ const state = this.#cohortStates.get(cohortId);
216
+ if (!state) {
217
+ throw new AggregationServiceError(`Cohort ${cohortId} not found.`, 'COHORT_NOT_FOUND', { cohortId });
218
+ }
219
+ if (state.phase !== ServiceCohortPhase.UpdatesCollected) {
220
+ throw new AggregationServiceError(`Cannot build aggregated data for cohort ${cohortId}: phase is ${state.phase}.`, 'INVALID_PHASE', { cohortId, phase: state.phase });
221
+ }
222
+ if (state.config.beaconType === 'CASBeacon') {
223
+ state.cohort.buildCASAnnouncement();
224
+ }
225
+ else if (state.config.beaconType === 'SMTBeacon') {
226
+ state.cohort.buildSMTTree();
227
+ }
228
+ else {
229
+ throw new AggregationServiceError(`Unsupported beacon type: ${state.config.beaconType}`, 'UNSUPPORTED_BEACON_TYPE', { cohortId, beaconType: state.config.beaconType });
230
+ }
231
+ const signalBytesHex = bytesToHex(state.cohort.signalBytes);
232
+ state.phase = ServiceCohortPhase.DataDistributed;
233
+ const messages = [];
234
+ for (const participantDid of state.cohort.participants) {
235
+ messages.push(createDistributeAggregatedDataMessage({
236
+ from: this.did,
237
+ to: participantDid,
238
+ cohortId,
239
+ beaconType: state.config.beaconType,
240
+ signalBytesHex,
241
+ casAnnouncement: state.config.beaconType === 'CASBeacon' ? state.cohort.casAnnouncement : undefined,
242
+ smtProof: state.config.beaconType === 'SMTBeacon' ? state.cohort.smtProofs?.get(participantDid) : undefined,
243
+ }));
244
+ }
245
+ return messages;
246
+ }
247
+ validationProgress(cohortId) {
248
+ const state = this.#cohortStates.get(cohortId);
249
+ if (!state) {
250
+ return { approved: new Set(), rejected: new Set(), pending: new Set(), total: 0 };
251
+ }
252
+ const approved = state.cohort.validationAcks;
253
+ const rejected = state.cohort.validationRejections;
254
+ const allParticipants = new Set(state.cohort.participants);
255
+ const responded = new Set([...approved, ...rejected]);
256
+ const pending = new Set([...allParticipants].filter(p => !responded.has(p)));
257
+ return {
258
+ approved,
259
+ rejected,
260
+ pending,
261
+ total: allParticipants.size,
262
+ };
263
+ }
264
+ #handleValidationAck(message) {
265
+ const cohortId = message.body?.cohortId;
266
+ if (!cohortId)
267
+ return;
268
+ const state = this.#cohortStates.get(cohortId);
269
+ if (!state)
270
+ return;
271
+ if (state.phase !== ServiceCohortPhase.DataDistributed)
272
+ return;
273
+ const approved = message.body?.approved;
274
+ if (approved === undefined)
275
+ return;
276
+ state.cohort.addValidation(message.from, approved);
277
+ // Transition to Validated only when all participants approved.
278
+ // Transition to Failed when all responses are in but at least one rejected.
279
+ if (state.cohort.isFullyValidated()) {
280
+ state.phase = ServiceCohortPhase.Validated;
281
+ }
282
+ else if (state.cohort.hasAllValidationResponses()) {
283
+ state.phase = ServiceCohortPhase.Failed;
284
+ }
285
+ }
286
+ /**
287
+ * Start a signing session by creating auth requests for all participants.
288
+ * The caller provides the transaction data — typically built via
289
+ * `buildBeaconTransaction()` against a Bitcoin connection.
290
+ */
291
+ startSigning(cohortId, txData) {
292
+ const state = this.#cohortStates.get(cohortId);
293
+ if (!state) {
294
+ throw new AggregationServiceError(`Cohort ${cohortId} not found.`, 'COHORT_NOT_FOUND', { cohortId });
295
+ }
296
+ if (state.phase !== ServiceCohortPhase.Validated) {
297
+ throw new AggregationServiceError(`Cannot start signing for cohort ${cohortId}: phase is ${state.phase}.`, 'INVALID_PHASE', { cohortId, phase: state.phase });
298
+ }
299
+ const session = new BeaconSigningSession({
300
+ cohort: state.cohort,
301
+ pendingTx: txData.tx,
302
+ prevOutScripts: txData.prevOutScripts,
303
+ prevOutValues: txData.prevOutValues,
304
+ });
305
+ state.signingSession = session;
306
+ state.phase = ServiceCohortPhase.SigningStarted;
307
+ const messages = [];
308
+ for (const participantDid of state.cohort.participants) {
309
+ messages.push(createAuthorizationRequestMessage({
310
+ from: this.did,
311
+ to: participantDid,
312
+ cohortId,
313
+ sessionId: session.id,
314
+ pendingTx: txData.tx.toHex(),
315
+ prevOutValue: txData.prevOutValues[0]?.toString() ?? '0',
316
+ }));
317
+ }
318
+ return messages;
319
+ }
320
+ #handleNonceContribution(message) {
321
+ const cohortId = message.body?.cohortId;
322
+ if (!cohortId)
323
+ return;
324
+ const state = this.#cohortStates.get(cohortId);
325
+ if (!state || !state.signingSession)
326
+ return;
327
+ if (state.phase !== ServiceCohortPhase.SigningStarted)
328
+ return;
329
+ const sessionId = message.body?.sessionId;
330
+ if (sessionId !== state.signingSession.id)
331
+ return;
332
+ const nonceContribution = message.body?.nonceContribution;
333
+ if (!nonceContribution)
334
+ return;
335
+ state.signingSession.addNonceContribution(message.from, nonceContribution);
336
+ if (state.signingSession.nonceContributions.size === state.cohort.participants.length) {
337
+ state.phase = ServiceCohortPhase.NoncesCollected;
338
+ }
339
+ }
340
+ /**
341
+ * Generate the aggregated nonce and return messages to send to participants.
342
+ * Call after `validationProgress(cohortId).approved.size === total`.
343
+ */
344
+ sendAggregatedNonce(cohortId) {
345
+ const state = this.#cohortStates.get(cohortId);
346
+ if (!state) {
347
+ throw new AggregationServiceError(`Cohort ${cohortId} not found.`, 'COHORT_NOT_FOUND', { cohortId });
348
+ }
349
+ if (state.phase !== ServiceCohortPhase.NoncesCollected || !state.signingSession) {
350
+ throw new AggregationServiceError(`Cannot send aggregated nonce for cohort ${cohortId}: phase is ${state.phase}.`, 'INVALID_PHASE', { cohortId, phase: state.phase });
351
+ }
352
+ const aggregatedNonce = state.signingSession.generateAggregatedNonce();
353
+ state.phase = ServiceCohortPhase.AwaitingPartialSigs;
354
+ const messages = [];
355
+ for (const participantDid of state.cohort.participants) {
356
+ messages.push(createAggregatedNonceMessage({
357
+ from: this.did,
358
+ to: participantDid,
359
+ cohortId,
360
+ sessionId: state.signingSession.id,
361
+ aggregatedNonce,
362
+ }));
363
+ }
364
+ return messages;
365
+ }
366
+ #handleSignatureAuthorization(message) {
367
+ const cohortId = message.body?.cohortId;
368
+ if (!cohortId)
369
+ return;
370
+ const state = this.#cohortStates.get(cohortId);
371
+ if (!state || !state.signingSession)
372
+ return;
373
+ if (state.phase !== ServiceCohortPhase.AwaitingPartialSigs)
374
+ return;
375
+ const sessionId = message.body?.sessionId;
376
+ if (sessionId !== state.signingSession.id)
377
+ return;
378
+ const partialSignature = message.body?.partialSignature;
379
+ if (!partialSignature)
380
+ return;
381
+ state.signingSession.addPartialSignature(message.from, partialSignature);
382
+ if (state.signingSession.partialSignatures.size === state.cohort.participants.length) {
383
+ // All partial sigs received — generate final signature
384
+ const signature = state.signingSession.generateFinalSignature();
385
+ // Set Taproot key-path witness
386
+ state.signingSession.pendingTx.setWitness(0, [signature]);
387
+ state.result = {
388
+ cohortId,
389
+ signature,
390
+ signedTx: state.signingSession.pendingTx,
391
+ };
392
+ state.phase = ServiceCohortPhase.Complete;
393
+ }
394
+ }
395
+ getResult(cohortId) {
396
+ return this.#cohortStates.get(cohortId)?.result;
397
+ }
398
+ getCohortPhase(cohortId) {
399
+ return this.#cohortStates.get(cohortId)?.phase;
400
+ }
401
+ getCohort(cohortId) {
402
+ return this.#cohortStates.get(cohortId)?.cohort;
403
+ }
404
+ /**
405
+ * Get the signing session ID for a cohort, if a signing session has been started.
406
+ * @param {string} cohortId - The cohort ID.
407
+ * @returns {string | undefined} The session ID, or undefined if no session is active.
408
+ */
409
+ getSigningSessionId(cohortId) {
410
+ return this.#cohortStates.get(cohortId)?.signingSession?.id;
411
+ }
412
+ get cohorts() {
413
+ return [...this.#cohortStates.values()].map(s => s.cohort);
414
+ }
415
+ }
416
+ //# sourceMappingURL=service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"service.js","sourceRoot":"","sources":["../../../../src/core/aggregation/service.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACb,cAAc,GACf,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,iCAAiC,EACjC,yBAAyB,EACzB,8BAA8B,EAC9B,wBAAwB,EACxB,qCAAqC,EACrC,4BAA4B,GAC7B,MAAM,yBAAyB,CAAC;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAuD5D;;;;;;;;;;GAUG;AACH,MAAM,OAAO,kBAAkB;IACpB,GAAG,CAAS;IACZ,IAAI,CAAiB;IAE9B,2CAA2C;IAC3C,aAAa,GAAoC,IAAI,GAAG,EAAE,CAAC;IAE3D,YAAY,EAAE,GAAG,EAAE,IAAI,EAA4B;QACjD,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAGD,OAAO,CAAC,OAAoB;QAC1B,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QAC1B,QAAO,IAAI,EAAE,CAAC;YACZ,KAAK,aAAa;gBAChB,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;gBAC3B,MAAM;YACR,KAAK,aAAa;gBAChB,IAAI,CAAC,mBAAmB,CAAC,OA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B,CAAC,QAAgB;QAClC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,QAAQ,CAAC,EAAE,cAAc,EAAE,EAAE,CAAC;IAC9D,CAAC;IAED,IAAI,OAAO;QACT,OAAO,CAAC,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;IAC7D,CAAC;CACF"}
@@ -0,0 +1,133 @@
1
+ import * as musig2 from '@scure/btc-signer/musig2';
2
+ import { Transaction } from 'bitcoinjs-lib';
3
+ import { SigningSessionError } from './errors.js';
4
+ import { SigningSessionPhase } from './phases.js';
5
+ /**
6
+ * MuSig2 signing session for a beacon transaction.
7
+ *
8
+ * Implements the BIP-327 signing protocol over a Taproot key-path-only
9
+ * transaction. The session is used by both AggregationService (collecting
10
+ * nonces and partial signatures, computing the final signature) and
11
+ * AggregationParticipant (generating their nonce and partial signature).
12
+ *
13
+ * @class BeaconSigningSession
14
+ */
15
+ export class BeaconSigningSession {
16
+ /** Unique identifier for this signing session. */
17
+ id;
18
+ /** The cohort this session signs for. */
19
+ cohort;
20
+ /** The Bitcoin transaction being signed. */
21
+ pendingTx;
22
+ /** Previous output scripts for Taproot sighash computation (BIP-341). */
23
+ prevOutScripts;
24
+ /** Previous output values for Taproot sighash computation. */
25
+ prevOutValues;
26
+ /** Map of participant publicKey-hex → public nonce contribution. */
27
+ nonceContributions = new Map();
28
+ /** Aggregated MuSig2 nonce (66 bytes). */
29
+ aggregatedNonce;
30
+ /** Map of participant DID → partial signature. */
31
+ partialSignatures = new Map();
32
+ /** Final 64-byte Schnorr signature. */
33
+ signature;
34
+ /** Current signing session phase. */
35
+ phase;
36
+ /** Participant's secret nonce (held only by the participant during signing). */
37
+ secretNonce;
38
+ constructor({ id, cohort, pendingTx, prevOutScripts, prevOutValues }) {
39
+ this.id = id || crypto.randomUUID();
40
+ this.cohort = cohort;
41
+ this.pendingTx = pendingTx;
42
+ this.prevOutScripts = prevOutScripts || [];
43
+ this.prevOutValues = prevOutValues || [];
44
+ this.phase = SigningSessionPhase.AwaitingNonceContributions;
45
+ }
46
+ /**
47
+ * Computes the Taproot sighash (BIP-341) for the first input.
48
+ */
49
+ get sigHash() {
50
+ if (!this.prevOutScripts.length || !this.prevOutValues.length) {
51
+ throw new SigningSessionError('Cannot compute sighash: missing prevOutScripts or prevOutValues.', 'SIGHASH_ERROR');
52
+ }
53
+ return this.pendingTx.hashForWitnessV1(0, this.prevOutScripts, this.prevOutValues, Transaction.SIGHASH_DEFAULT);
54
+ }
55
+ addNonceContribution(participantDid, nonceContribution) {
56
+ if (this.phase !== SigningSessionPhase.AwaitingNonceContributions) {
57
+ throw new SigningSessionError(`Nonce contributions not expected. Current phase: ${this.phase}`, 'INVALID_PHASE', { phase: this.phase });
58
+ }
59
+ if (nonceContribution.length !== 66) {
60
+ throw new SigningSessionError(`Invalid nonce contribution: expected 66 bytes, got ${nonceContribution.length}.`, 'INVALID_NONCE_LENGTH');
61
+ }
62
+ if (this.nonceContributions.has(participantDid)) {
63
+ throw new SigningSessionError(`Duplicate nonce contribution from ${participantDid}.`, 'DUPLICATE_NONCE');
64
+ }
65
+ this.nonceContributions.set(participantDid, nonceContribution);
66
+ if (this.nonceContributions.size === this.cohort.participants.length) {
67
+ this.phase = SigningSessionPhase.NonceContributionsReceived;
68
+ }
69
+ }
70
+ generateAggregatedNonce() {
71
+ if (this.phase !== SigningSessionPhase.NonceContributionsReceived) {
72
+ throw new SigningSessionError(`Cannot aggregate nonces: phase is ${this.phase}, expected NonceContributionsReceived.`, 'INVALID_PHASE');
73
+ }
74
+ this.aggregatedNonce = musig2.nonceAggregate([...this.nonceContributions.values()]);
75
+ this.phase = SigningSessionPhase.AwaitingPartialSignatures;
76
+ return this.aggregatedNonce;
77
+ }
78
+ addPartialSignature(participantDid, partialSig) {
79
+ if (this.phase !== SigningSessionPhase.AwaitingPartialSignatures) {
80
+ throw new SigningSessionError(`Partial signatures not expected. Current phase: ${this.phase}`, 'INVALID_PHASE');
81
+ }
82
+ if (this.partialSignatures.has(participantDid)) {
83
+ throw new SigningSessionError(`Duplicate partial signature from ${participantDid}.`, 'DUPLICATE_PARTIAL_SIG');
84
+ }
85
+ this.partialSignatures.set(participantDid, partialSig);
86
+ if (this.partialSignatures.size === this.cohort.participants.length) {
87
+ this.phase = SigningSessionPhase.PartialSignaturesReceived;
88
+ }
89
+ }
90
+ generateFinalSignature() {
91
+ if (this.phase !== SigningSessionPhase.PartialSignaturesReceived) {
92
+ throw new SigningSessionError(`Cannot generate final signature: phase is ${this.phase}.`, 'INVALID_PHASE');
93
+ }
94
+ if (!this.aggregatedNonce) {
95
+ throw new SigningSessionError('Aggregated nonce missing.', 'MISSING_AGGREGATED_NONCE');
96
+ }
97
+ const session = new musig2.Session(this.aggregatedNonce, this.cohort.cohortKeys, this.sigHash, [this.cohort.trMerkleRoot], [true]);
98
+ this.signature = session.partialSigAgg([...this.partialSignatures.values()]);
99
+ this.phase = SigningSessionPhase.Complete;
100
+ return this.signature;
101
+ }
102
+ /**
103
+ * Generates a fresh MuSig2 nonce contribution for the participant.
104
+ * Stores the secret nonce internally for use in `generatePartialSignature()`.
105
+ */
106
+ generateNonceContribution(participantPublicKey, participantSecretKey) {
107
+ const aggPublicKey = musig2.keyAggExport(musig2.keyAggregate(this.cohort.cohortKeys));
108
+ const nonces = musig2.nonceGen(participantPublicKey, participantSecretKey, aggPublicKey);
109
+ this.secretNonce = nonces.secret;
110
+ return nonces.public;
111
+ }
112
+ /**
113
+ * Generates a partial signature using the participant's secret key + secret nonce.
114
+ * Requires the aggregated nonce to have been set first (via the service).
115
+ */
116
+ generatePartialSignature(participantSecretKey) {
117
+ if (!this.aggregatedNonce) {
118
+ throw new SigningSessionError('Aggregated nonce not available.', 'MISSING_AGGREGATED_NONCE');
119
+ }
120
+ if (!this.secretNonce) {
121
+ throw new SigningSessionError('Secret nonce not available — generateNonceContribution() must be called first.', 'MISSING_SECRET_NONCE');
122
+ }
123
+ const session = new musig2.Session(this.aggregatedNonce, this.cohort.cohortKeys, this.sigHash, [this.cohort.trMerkleRoot], [true]);
124
+ return session.sign(this.secretNonce, participantSecretKey);
125
+ }
126
+ isComplete() {
127
+ return this.phase === SigningSessionPhase.Complete;
128
+ }
129
+ isFailed() {
130
+ return this.phase === SigningSessionPhase.Failed;
131
+ }
132
+ }
133
+ //# sourceMappingURL=signing-session.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"signing-session.js","sourceRoot":"","sources":["../../../../src/core/aggregation/signing-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,MAAM,0BAA0B,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAalD;;;;;;;;;GASG;AACH,MAAM,OAAO,oBAAoB;IAC/B,kDAAkD;IAC3C,EAAE,CAAS;IAElB,yCAAyC;IAClC,MAAM,CAAoB;IAEjC,4CAA4C;IACrC,SAAS,CAAc;IAE9B,yEAAyE;IAClE,cAAc,CAAe;IAEpC,8DAA8D;IACvD,aAAa,CAAW;IAE/B,oEAAoE;IAC7D,kBAAkB,GAA6B,IAAI,GAAG,EAAE,CAAC;IAEhE,0CAA0C;IACnC,eAAe,CAAc;IAEpC,kDAAkD;IAC3C,iBAAiB,GAA4B,IAAI,GAAG,EAAE,CAAC;IAE9D,uCAAuC;IAChC,SAAS,CAAc;IAE9B,qCAAqC;IAC9B,KAAK,CAA0B;IAEtC,gFAAgF;IACzE,WAAW,CAAc;IAEhC,YAAY,EAAE,EAAE,EAAE,MAAM,EAAE,SAAS,EAAE,cAAc,EAAE,aAAa,EAAwB;QACxF,IAAI,CAAC,EAAE,GAAG,EAAE,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QACpC,IAAI,CAAC,MAAM,G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