@did-btcr2/method 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +86 -233
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/browser.js +24111 -20342
  4. package/dist/browser.mjs +24111 -20342
  5. package/dist/cjs/index.js +2463 -2174
  6. package/dist/esm/core/aggregation/cohort.js +178 -0
  7. package/dist/esm/core/aggregation/cohort.js.map +1 -0
  8. package/dist/esm/core/aggregation/errors.js +22 -0
  9. package/dist/esm/core/aggregation/errors.js.map +1 -0
  10. package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
  11. package/dist/esm/core/aggregation/messages/base.js.map +1 -0
  12. package/dist/esm/core/aggregation/messages/constants.js +26 -0
  13. package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
  14. package/dist/esm/core/aggregation/messages/factories.js +113 -0
  15. package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
  16. package/dist/esm/core/aggregation/messages/guards.js +37 -0
  17. package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
  18. package/dist/esm/core/aggregation/messages/index.js +5 -0
  19. package/dist/esm/core/aggregation/messages/index.js.map +1 -0
  20. package/dist/esm/core/aggregation/participant.js +376 -0
  21. package/dist/esm/core/aggregation/participant.js.map +1 -0
  22. package/dist/esm/core/aggregation/phases.js +39 -0
  23. package/dist/esm/core/aggregation/phases.js.map +1 -0
  24. package/dist/esm/core/aggregation/runner/events.js +2 -0
  25. package/dist/esm/core/aggregation/runner/events.js.map +1 -0
  26. package/dist/esm/core/aggregation/runner/index.js +5 -0
  27. package/dist/esm/core/aggregation/runner/index.js.map +1 -0
  28. package/dist/esm/core/aggregation/runner/participant-runner.js +282 -0
  29. package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
  30. package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
  31. package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
  32. package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
  33. package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
  34. package/dist/esm/core/aggregation/service.js +416 -0
  35. package/dist/esm/core/aggregation/service.js.map +1 -0
  36. package/dist/esm/core/aggregation/signing-session.js +133 -0
  37. package/dist/esm/core/aggregation/signing-session.js.map +1 -0
  38. package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
  39. package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
  40. package/dist/esm/core/aggregation/transport/error.js +12 -0
  41. package/dist/esm/core/aggregation/transport/error.js.map +1 -0
  42. package/dist/esm/core/aggregation/transport/factory.js +20 -0
  43. package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
  44. package/dist/esm/core/aggregation/transport/index.js +6 -0
  45. package/dist/esm/core/aggregation/transport/index.js.map +1 -0
  46. package/dist/esm/core/aggregation/transport/nostr.js +262 -0
  47. package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
  48. package/dist/esm/core/aggregation/transport/transport.js +2 -0
  49. package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
  50. package/dist/esm/core/beacon/beacon.js +80 -0
  51. package/dist/esm/core/beacon/beacon.js.map +1 -1
  52. package/dist/esm/core/beacon/cas-beacon.js +15 -56
  53. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  54. package/dist/esm/core/beacon/error.js +0 -10
  55. package/dist/esm/core/beacon/error.js.map +1 -1
  56. package/dist/esm/core/beacon/fee-estimator.js +30 -0
  57. package/dist/esm/core/beacon/fee-estimator.js.map +1 -0
  58. package/dist/esm/core/beacon/singleton-beacon.js +10 -53
  59. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  60. package/dist/esm/core/beacon/smt-beacon.js +85 -9
  61. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  62. package/dist/esm/core/identifier.js +13 -0
  63. package/dist/esm/core/identifier.js.map +1 -1
  64. package/dist/esm/core/resolver.js +9 -0
  65. package/dist/esm/core/resolver.js.map +1 -1
  66. package/dist/esm/index.js +14 -24
  67. package/dist/esm/index.js.map +1 -1
  68. package/dist/types/core/aggregation/cohort.d.ts +94 -0
  69. package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
  70. package/dist/types/core/aggregation/errors.d.ts +14 -0
  71. package/dist/types/core/aggregation/errors.d.ts.map +1 -0
  72. package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
  73. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
  74. package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
  75. package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
  76. package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
  77. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
  78. package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
  79. package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
  80. package/dist/types/core/aggregation/messages/index.d.ts +5 -0
  81. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
  82. package/dist/types/core/aggregation/participant.d.ts +101 -0
  83. package/dist/types/core/aggregation/participant.d.ts.map +1 -0
  84. package/dist/types/core/aggregation/phases.d.ts +49 -0
  85. package/dist/types/core/aggregation/phases.d.ts.map +1 -0
  86. package/dist/types/core/aggregation/runner/events.d.ts +89 -0
  87. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
  88. package/dist/types/core/aggregation/runner/index.d.ts +5 -0
  89. package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
  90. package/dist/types/core/aggregation/runner/participant-runner.d.ts +107 -0
  91. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
  92. package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
  93. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
  94. package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
  95. package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
  96. package/dist/types/core/aggregation/service.d.ts +112 -0
  97. package/dist/types/core/aggregation/service.d.ts.map +1 -0
  98. package/dist/types/core/aggregation/signing-session.d.ts +69 -0
  99. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
  100. package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
  101. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
  102. package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
  103. package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
  104. package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
  105. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
  106. package/dist/types/core/aggregation/transport/index.d.ts +6 -0
  107. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
  108. package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
  109. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
  110. package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
  111. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
  112. package/dist/types/core/beacon/beacon.d.ts +37 -2
  113. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  114. package/dist/types/core/beacon/cas-beacon.d.ts +19 -7
  115. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  116. package/dist/types/core/beacon/error.d.ts +0 -6
  117. package/dist/types/core/beacon/error.d.ts.map +1 -1
  118. package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
  119. package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
  120. package/dist/types/core/beacon/interfaces.d.ts +8 -0
  121. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  122. package/dist/types/core/beacon/singleton-beacon.d.ts +9 -2
  123. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  124. package/dist/types/core/beacon/smt-beacon.d.ts +27 -7
  125. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  126. package/dist/types/core/identifier.d.ts +8 -0
  127. package/dist/types/core/identifier.d.ts.map +1 -1
  128. package/dist/types/core/interfaces.d.ts +2 -2
  129. package/dist/types/core/resolver.d.ts +11 -1
  130. package/dist/types/core/resolver.d.ts.map +1 -1
  131. package/dist/types/index.d.ts +9 -24
  132. package/dist/types/index.d.ts.map +1 -1
  133. package/package.json +31 -30
  134. package/src/core/aggregation/cohort.ts +247 -0
  135. package/src/core/aggregation/errors.ts +25 -0
  136. package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
  137. package/src/core/aggregation/messages/constants.ts +28 -0
  138. package/src/core/aggregation/messages/factories.ts +240 -0
  139. package/src/core/aggregation/messages/guards.ts +55 -0
  140. package/src/core/aggregation/messages/index.ts +4 -0
  141. package/src/core/aggregation/participant.ts +510 -0
  142. package/src/core/aggregation/phases.ts +82 -0
  143. package/src/core/aggregation/runner/events.ts +77 -0
  144. package/src/core/aggregation/runner/index.ts +4 -0
  145. package/src/core/aggregation/runner/participant-runner.ts +360 -0
  146. package/src/core/aggregation/runner/service-runner.ts +365 -0
  147. package/src/core/aggregation/runner/typed-emitter.ts +87 -0
  148. package/src/core/aggregation/service.ts +547 -0
  149. package/src/core/aggregation/signing-session.ts +209 -0
  150. package/src/core/aggregation/transport/didcomm.ts +42 -0
  151. package/src/core/aggregation/transport/error.ts +13 -0
  152. package/src/core/aggregation/transport/factory.ts +29 -0
  153. package/src/core/aggregation/transport/index.ts +5 -0
  154. package/src/core/aggregation/transport/nostr.ts +333 -0
  155. package/src/core/aggregation/transport/transport.ts +46 -0
  156. package/src/core/beacon/beacon.ts +122 -2
  157. package/src/core/beacon/cas-beacon.ts +28 -76
  158. package/src/core/beacon/error.ts +0 -12
  159. package/src/core/beacon/fee-estimator.ts +52 -0
  160. package/src/core/beacon/interfaces.ts +10 -1
  161. package/src/core/beacon/singleton-beacon.ts +14 -75
  162. package/src/core/beacon/smt-beacon.ts +109 -11
  163. package/src/core/identifier.ts +17 -0
  164. package/src/core/interfaces.ts +2 -2
  165. package/src/core/resolver.ts +25 -2
  166. package/src/index.ts +15 -29
  167. package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
  168. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
  169. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  170. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  171. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  172. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
  173. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  174. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  175. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  176. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  177. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  178. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  179. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  180. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  181. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  182. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  183. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  184. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  185. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  186. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  187. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  188. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  189. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  190. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  191. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  192. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  193. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  194. package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
  195. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
  196. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  197. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  198. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -245
  199. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  200. package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
  201. package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
  202. package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
  203. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
  204. package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
  205. package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
  206. package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
  207. package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
  208. package/dist/esm/core/beacon/aggregation/participant.js +0 -435
  209. package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
  210. package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
  211. package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
  212. package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
  213. package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
  214. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
  215. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
  216. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
  217. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
  218. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
  219. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
  220. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
  221. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
  222. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
  223. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
  224. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
  225. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
  226. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
  227. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
  228. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
  229. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
  230. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
  231. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
  232. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
  233. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
  234. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
  235. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
  236. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
  237. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
  238. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
  239. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
  240. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
  241. package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
  242. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
  243. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
  244. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
  245. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
  246. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
  247. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
  248. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
  249. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
  250. package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
  251. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
  252. package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
  253. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
  254. package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
  255. package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
  256. package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
  257. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
  258. package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
  259. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
  260. package/src/core/beacon/aggregation/cohort/index.ts +0 -305
  261. package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
  262. package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
  263. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -44
  264. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -40
  265. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -35
  266. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -34
  267. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -36
  268. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -39
  269. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -40
  270. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -40
  271. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -40
  272. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -41
  273. package/src/core/beacon/aggregation/cohort/status.ts +0 -7
  274. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -148
  275. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -323
  276. package/src/core/beacon/aggregation/communication/error.ts +0 -13
  277. package/src/core/beacon/aggregation/communication/factory.ts +0 -25
  278. package/src/core/beacon/aggregation/communication/service.ts +0 -42
  279. package/src/core/beacon/aggregation/coordinator.ts +0 -419
  280. package/src/core/beacon/aggregation/participant.ts +0 -517
  281. package/src/core/beacon/aggregation/session/index.ts +0 -301
  282. package/src/core/beacon/aggregation/session/status.ts +0 -18
@@ -0,0 +1,178 @@
1
+ import { canonicalHash, canonicalize, hash } from '@did-btcr2/common';
2
+ import { BTCR2MerkleTree } from '@did-btcr2/smt';
3
+ import { hexToBytes, randomBytes } from '@noble/hashes/utils';
4
+ import { keyAggExport, keyAggregate, sortKeys } from '@scure/btc-signer/musig2';
5
+ import { crypto as btcCrypto, payments } from 'bitcoinjs-lib';
6
+ import { AggregationCohortError } from './errors.js';
7
+ /**
8
+ * Represents an Aggregation Cohort — a set of Aggregation Participants who
9
+ * submitted cryptographic material to an Aggregation Service to coordinate
10
+ * signing of a shared n-of-n MuSig2 Bitcoin transaction.
11
+ *
12
+ * This is a pure data class — it holds cohort state and provides computation
13
+ * helpers (key aggregation, CAS Announcement building, SMT tree building).
14
+ * It performs no I/O and emits no messages. Both AggregationService and
15
+ * AggregationParticipant create their own AggregationCohort instances to
16
+ * track their respective views of the cohort state.
17
+ *
18
+ * @class AggregationCohort
19
+ */
20
+ export class AggregationCohort {
21
+ /** Unique identifier for the cohort. */
22
+ id;
23
+ /** DID of the Aggregation Service managing this cohort. */
24
+ serviceDid;
25
+ /** Minimum number of participants required to finalize the cohort. */
26
+ minParticipants;
27
+ /** Network on which the cohort operates (mainnet, mutinynet, etc.). */
28
+ network;
29
+ /** Type of beacon used in the cohort: 'CASBeacon' or 'SMTBeacon'. */
30
+ beaconType;
31
+ /** List of participant DIDs that have been accepted into the cohort. */
32
+ participants = [];
33
+ /** Sorted list of cohort participants' compressed public keys. */
34
+ #cohortKeys = [];
35
+ /** Taproot tweak (BIP-341 key-path-only). */
36
+ trMerkleRoot = new Uint8Array();
37
+ /** The n-of-n MuSig2 Taproot beacon address. */
38
+ beaconAddress = '';
39
+ /** Pending DID updates submitted by participants, keyed by DID. */
40
+ pendingUpdates = new Map();
41
+ /** CAS Beacon Announcement Map (DID → updateHash), set by buildCASAnnouncement(). */
42
+ casAnnouncement;
43
+ /** Per-participant SMT proofs, set by buildSMTTree(). */
44
+ smtProofs;
45
+ /** Signal bytes (32 bytes) for OP_RETURN: SHA-256 of CAS announcement OR SMT root. */
46
+ signalBytes;
47
+ /** Set of participant DIDs that have approved the aggregated data. */
48
+ validationAcks = new Set();
49
+ /** Set of participant DIDs that have rejected the aggregated data. */
50
+ validationRejections = new Set();
51
+ constructor({ id, minParticipants, serviceDid, network, beaconType }) {
52
+ this.id = id || crypto.randomUUID();
53
+ this.minParticipants = minParticipants || 2;
54
+ this.serviceDid = serviceDid || '';
55
+ this.network = network;
56
+ this.beaconType = beaconType || 'CASBeacon';
57
+ }
58
+ /** Sorted cohort keys (sorted on assignment per BIP-327). */
59
+ get cohortKeys() {
60
+ return this.#cohortKeys;
61
+ }
62
+ set cohortKeys(keys) {
63
+ this.#cohortKeys = sortKeys(keys);
64
+ }
65
+ /**
66
+ * Computes the n-of-n MuSig2 Taproot beacon address from cohort keys.
67
+ * Sets `trMerkleRoot` to the BIP-341 key-path-only tweak.
68
+ */
69
+ computeBeaconAddress() {
70
+ if (this.#cohortKeys.length === 0) {
71
+ throw new AggregationCohortError('Cannot compute beacon address: no cohort keys.', 'NO_COHORT_KEYS', { cohortId: this.id });
72
+ }
73
+ const keyAggContext = keyAggregate(this.#cohortKeys);
74
+ const aggPubkey = keyAggExport(keyAggContext);
75
+ const payment = payments.p2tr({ internalPubkey: aggPubkey });
76
+ // BIP-341: key-path-only P2TR has no script tree, so payment.hash is null.
77
+ // Compute the tweak: taggedHash("TapTweak", internalPubkey).
78
+ this.trMerkleRoot = payment.hash ?? btcCrypto.taggedHash('TapTweak', aggPubkey);
79
+ if (!payment.address) {
80
+ throw new AggregationCohortError('Failed to compute Taproot address', 'BEACON_ADDRESS_ERROR', { cohortId: this.id });
81
+ }
82
+ this.beaconAddress = payment.address;
83
+ return payment.address;
84
+ }
85
+ /**
86
+ * Validates that the participant's key is in the cohort and the beacon address
87
+ * matches the locally-computed one. Used by participants to verify cohort ready
88
+ * messages from the service.
89
+ */
90
+ validateMembership(participantPkHex, cohortKeysHex, expectedBeaconAddress) {
91
+ if (!cohortKeysHex.includes(participantPkHex)) {
92
+ throw new AggregationCohortError(`Participant key not found in cohort ${this.id}.`, 'COHORT_VALIDATION_ERROR', { cohortId: this.id, participantPkHex });
93
+ }
94
+ this.cohortKeys = cohortKeysHex.map(k => hexToBytes(k));
95
+ const computed = this.computeBeaconAddress();
96
+ if (computed !== expectedBeaconAddress) {
97
+ throw new AggregationCohortError(`Computed beacon address ${computed} does not match expected ${expectedBeaconAddress}.`, 'BEACON_ADDRESS_MISMATCH', { cohortId: this.id, computed, expected: expectedBeaconAddress });
98
+ }
99
+ }
100
+ addUpdate(participantDid, signedUpdate) {
101
+ if (!this.participants.includes(participantDid)) {
102
+ throw new AggregationCohortError(`Participant ${participantDid} is not in cohort ${this.id}.`, 'UNKNOWN_PARTICIPANT', { cohortId: this.id, participantDid });
103
+ }
104
+ this.pendingUpdates.set(participantDid, signedUpdate);
105
+ }
106
+ hasAllUpdates() {
107
+ return this.pendingUpdates.size === this.participants.length;
108
+ }
109
+ /**
110
+ * Builds a CAS Announcement Map from collected updates.
111
+ * Maps each participant DID → base64url canonical hash of their signed update.
112
+ * Computes signal bytes as SHA-256 of canonicalized announcement.
113
+ */
114
+ buildCASAnnouncement() {
115
+ if (!this.hasAllUpdates()) {
116
+ throw new AggregationCohortError('Cannot build CAS Announcement: not all updates collected.', 'INCOMPLETE_UPDATES', { cohortId: this.id, collected: this.pendingUpdates.size, total: this.participants.length });
117
+ }
118
+ const announcement = {};
119
+ for (const [did, signedUpdate] of this.pendingUpdates) {
120
+ announcement[did] = canonicalHash(signedUpdate);
121
+ }
122
+ this.casAnnouncement = announcement;
123
+ this.signalBytes = hash(canonicalize(announcement));
124
+ return announcement;
125
+ }
126
+ /**
127
+ * Builds an SMT tree from collected updates.
128
+ * Each entry uses a random 32-byte nonce + canonicalized signed update bytes.
129
+ * Stores per-participant proofs and the SMT root as signalBytes.
130
+ */
131
+ buildSMTTree() {
132
+ if (!this.hasAllUpdates()) {
133
+ throw new AggregationCohortError('Cannot build SMT tree: not all updates collected.', 'INCOMPLETE_UPDATES', { cohortId: this.id });
134
+ }
135
+ const tree = new BTCR2MerkleTree();
136
+ const entries = [];
137
+ const encoder = new TextEncoder();
138
+ for (const [did, signedUpdate] of this.pendingUpdates) {
139
+ const canonicalBytes = encoder.encode(canonicalize(signedUpdate));
140
+ const nonce = randomBytes(32);
141
+ entries.push({ did, nonce, signedUpdate: canonicalBytes });
142
+ }
143
+ tree.addEntries(entries);
144
+ tree.finalize();
145
+ this.signalBytes = tree.rootHash;
146
+ this.smtProofs = new Map();
147
+ for (const [did] of this.pendingUpdates) {
148
+ this.smtProofs.set(did, tree.proof(did));
149
+ }
150
+ return this.smtProofs;
151
+ }
152
+ addValidation(participantDid, approved) {
153
+ if (!this.participants.includes(participantDid)) {
154
+ throw new AggregationCohortError(`Unknown participant ${participantDid} in cohort ${this.id}.`, 'UNKNOWN_PARTICIPANT', { cohortId: this.id, participantDid });
155
+ }
156
+ if (approved) {
157
+ this.validationAcks.add(participantDid);
158
+ }
159
+ else {
160
+ this.validationRejections.add(participantDid);
161
+ }
162
+ }
163
+ /**
164
+ * True when every participant has either approved or rejected the aggregated data.
165
+ */
166
+ hasAllValidationResponses() {
167
+ return this.validationAcks.size + this.validationRejections.size === this.participants.length;
168
+ }
169
+ /**
170
+ * True when all participants approved. Note: differs from {@link hasAllValidationResponses} —
171
+ * this returns false if any participant rejected, even if all responses are in.
172
+ */
173
+ isFullyValidated() {
174
+ return this.validationRejections.size === 0
175
+ && this.validationAcks.size === this.participants.length;
176
+ }
177
+ }
178
+ //# sourceMappingURL=cohort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cohort.js","sourceRoot":"","sources":["../../../../src/core/aggregation/cohort.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,mBAAmB,CAAC;AAGtE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,MAAM,IAAI,SAAS,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAC;AAUrD;;;;;;;;;;;;GAYG;AACH,MAAM,OAAO,iBAAiB;IAC5B,wCAAwC;IACxC,EAAE,CAAS;IAEX,2DAA2D;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AAC,GAAG,CAAC,CAAC,CAAC;QAC3C,CAAC;QACD,OAAO,IAAI,CAAC,SAAS,CAAC;IACxB,CAAC;IAEM,aAAa,CAAC,cAAsB,EAAE,QAAiB;QAC5D,IAAG,CAAC,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC;YAC/C,MAAM,IAAI,sBAAsB,CAC9B,uBAAuB,cAAc,cAAc,IAAI,CAAC,EAAE,GAAG,EAC7D,qBAAqB,EAAE,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,EAAE,cAAc,EAAE,CAC7D,CAAC;QACJ,CAAC;QACD,IAAG,QAAQ,EAAE,CAAC;YACZ,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAC1C,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,oBAAoB,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IAED;;OAEG;IACI,yBAAyB;QAC9B,OAAO,IAAI,CAAC,cAAc,CAAC,IAAI,GAAG,IAAI,CAAC,oBAAoB,CAAC,IAAI,KAAK,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;IAChG,CAAC;IAED;;;OAGG;IACI,gBAAgB;QACrB,OAAO,IAAI,CAAC,oBAAoB,CAAC,IAAI,KAAK,CAAC;eACtC,IAAI,CAAC,cAAc,CAAC,IAAI,KAAK,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC;IAC7D,CAAC;CACF"}
@@ -0,0 +1,22 @@
1
+ import { MethodError } from '@did-btcr2/common';
2
+ export class AggregationServiceError extends MethodError {
3
+ constructor(message, type = 'AggregationServiceError', data) {
4
+ super(message, type, data);
5
+ }
6
+ }
7
+ export class AggregationParticipantError extends MethodError {
8
+ constructor(message, type = 'AggregationParticipantError', data) {
9
+ super(message, type, data);
10
+ }
11
+ }
12
+ export class AggregationCohortError extends MethodError {
13
+ constructor(message, type = 'AggregationCohortError', data) {
14
+ super(message, type, data);
15
+ }
16
+ }
17
+ export class SigningSessionError extends MethodError {
18
+ constructor(message, type = 'SigningSessionError', data) {
19
+ super(message, type, data);
20
+ }
21
+ }
22
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/core/aggregation/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAEhD,MAAM,OAAO,uBAAwB,SAAQ,WAAW;IACtD,YAAY,OAAe,EAAE,OAAe,yBAAyB,EAAE,IAA0B;QAC/F,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,2BAA4B,SAAQ,WAAW;IAC1D,YAAY,OAAe,EAAE,OAAe,6BAA6B,EAAE,IAA0B;QACnG,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,sBAAuB,SAAQ,WAAW;IACrD,YAAY,OAAe,EAAE,OAAe,wBAAwB,EAAE,IAA0B;QAC9F,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF;AAED,MAAM,OAAO,mBAAoB,SAAQ,WAAW;IAClD,YAAY,OAAe,EAAE,OAAe,qBAAqB,EAAE,IAA0B;QAC3F,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;IAC7B,CAAC;CACF"}
@@ -1,4 +1,3 @@
1
- export const MESSAGE_PREFIX = 'https://btcr2.tools/';
2
1
  export class BaseMessage {
3
2
  type;
4
3
  to;
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/messages/base.ts"],"names":[],"mappings":"AA8BA,MAAM,OAAO,WAAW;IACf,IAAI,CAAS;IACb,EAAE,CAAU;IACZ,IAAI,CAAS;IACb,IAAI,CAAY;IAEvB,YAAY,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,IAAI,EAAQ;QACxC,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED;;;OAGG;IACI,MAAM;QACX,OAAO;YACL,IAAI,EAAG,IAAI,CAAC,IAAI;YAChB,EAAE,EAAK,IAAI,CAAC,EAAE;YACd,IAAI,EAAG,IAAI,CAAC,IAAI;YAChB,IAAI,EAAG,IAAI,CAAC,IAAI;SACjB,CAAC;IACJ,CAAC;CACF"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Message type URLs for the did:btcr2 Aggregate Beacon protocol.
3
+ *
4
+ * Naming follows the spec (https://dcdpr.github.io/did-btcr2/beacons/aggregate-beacons.html):
5
+ * - Step 1 (Cohort Formation): COHORT_ADVERT, COHORT_OPT_IN, COHORT_OPT_IN_ACCEPT, COHORT_READY
6
+ * - Step 2 (Update Submission): SUBMIT_UPDATE
7
+ * - Step 3 (Aggregate & Validate): DISTRIBUTE_AGGREGATED_DATA, VALIDATION_ACK
8
+ * - Step 4 (Sign & Broadcast): AUTHORIZATION_REQUEST, NONCE_CONTRIBUTION,
9
+ * AGGREGATED_NONCE, SIGNATURE_AUTHORIZATION
10
+ */
11
+ export const AGGREGATION_MESSAGE_PREFIX = 'https://btcr2.dev/aggregation';
12
+ // Step 1: Cohort Formation
13
+ export const COHORT_ADVERT = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_advert`;
14
+ export const COHORT_OPT_IN = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_opt_in`;
15
+ export const COHORT_OPT_IN_ACCEPT = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_opt_in_accept`;
16
+ export const COHORT_READY = `${AGGREGATION_MESSAGE_PREFIX}/keygen/cohort_ready`;
17
+ // Step 2 + 3: Update Submission, Aggregation, Validation
18
+ export const SUBMIT_UPDATE = `${AGGREGATION_MESSAGE_PREFIX}/update/submit_update`;
19
+ export const DISTRIBUTE_AGGREGATED_DATA = `${AGGREGATION_MESSAGE_PREFIX}/update/distribute_aggregated_data`;
20
+ export const VALIDATION_ACK = `${AGGREGATION_MESSAGE_PREFIX}/update/validation_ack`;
21
+ // Step 4: Signing
22
+ export const AUTHORIZATION_REQUEST = `${AGGREGATION_MESSAGE_PREFIX}/sign/authorization_request`;
23
+ export const NONCE_CONTRIBUTION = `${AGGREGATION_MESSAGE_PREFIX}/sign/nonce_contribution`;
24
+ export const AGGREGATED_NONCE = `${AGGREGATION_MESSAGE_PREFIX}/sign/aggregated_nonce`;
25
+ export const SIGNATURE_AUTHORIZATION = `${AGGREGATION_MESSAGE_PREFIX}/sign/signature_authorization`;
26
+ //# sourceMappingURL=constants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"constants.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/messages/constants.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,+BAA+B,CAAC;AAE1E,2BAA2B;AAC3B,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,0BAA0B,uBAAuB,CAAC;AAClF,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,0BAA0B,uBAAuB,CAAC;AAClF,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,0BAA0B,8BAA8B,CAAC;AAChG,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,0BAA0B,sBAAsB,CAAC;AAEhF,yDAAyD;AACzD,MAAM,CAAC,MAAM,aAAa,GAAG,GAAG,0BAA0B,uBAAuB,CAAC;AAClF,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,0BAA0B,oCAAoC,CAAC;AAC5G,MAAM,CAAC,MAAM,cAAc,GAAG,GAAG,0BAA0B,wBAAwB,CAAC;AAEpF,kBAAkB;AAClB,MAAM,CAAC,MAAM,qBAAqB,GAAG,GAAG,0BAA0B,6BAA6B,CAAC;AAChG,MAAM,CAAC,MAAM,kBAAkB,GAAG,GAAG,0BAA0B,0BAA0B,CAAC;AAC1F,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,0BAA0B,wBAAwB,CAAC;AACtF,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,0BAA0B,+BAA+B,CAAC"}
@@ -0,0 +1,113 @@
1
+ import { BaseMessage } from './base.js';
2
+ import { AGGREGATED_NONCE, AUTHORIZATION_REQUEST, COHORT_ADVERT, COHORT_OPT_IN, COHORT_OPT_IN_ACCEPT, COHORT_READY, DISTRIBUTE_AGGREGATED_DATA, NONCE_CONTRIBUTION, SIGNATURE_AUTHORIZATION, SUBMIT_UPDATE, VALIDATION_ACK, } from './constants.js';
3
+ /**
4
+ * Factory function for creating a Cohort Advert message, which is used to announce the formation of
5
+ * a new cohort and invite participants to join.
6
+ * @param {CohortAdvertMessage} fields - The fields required to create a Cohort Advert message.
7
+ * @returns {BaseMessage} The created Cohort Advert message.
8
+ */
9
+ export function createCohortAdvertMessage(fields) {
10
+ const { from, ...body } = fields;
11
+ return new BaseMessage({ type: COHORT_ADVERT, from, body });
12
+ }
13
+ /**
14
+ * Factory function for creating a Cohort Opt-In message, which is sent by a participant to express
15
+ * interest in joining a cohort.
16
+ * @param {CohortOptInMessage} fields - The fields required to create a Cohort Opt-In message, which
17
+ * is sent by a participant to express interest in joining a cohort.
18
+ * @returns {BaseMessage} The created Cohort Opt-In message.
19
+ */
20
+ export function createCohortOptInMessage(fields) {
21
+ const { from, to, ...body } = fields;
22
+ return new BaseMessage({ type: COHORT_OPT_IN, from, to, body });
23
+ }
24
+ export function createCohortOptInAcceptMessage(fields) {
25
+ const { from, to, ...body } = fields;
26
+ return new BaseMessage({ type: COHORT_OPT_IN_ACCEPT, from, to, body });
27
+ }
28
+ export function createCohortReadyMessage(fields) {
29
+ const { from, to, ...body } = fields;
30
+ return new BaseMessage({ type: COHORT_READY, from, to, body });
31
+ }
32
+ /**
33
+ * Factory function for creating a Submit Update message, which is sent by a participant to submit
34
+ * their signed update for aggregation.
35
+ * @param {SubmitUpdateMessage} fields - The fields required to create a Submit Update message,
36
+ * which is sent by a participant to submit their signed update for aggregation.
37
+ * @returns {BaseMessage} The created Submit Update message.
38
+ */
39
+ export function createSubmitUpdateMessage(fields) {
40
+ const { from, to, ...body } = fields;
41
+ return new BaseMessage({ type: SUBMIT_UPDATE, from, to, body });
42
+ }
43
+ /**
44
+ * Factory function for creating a Distribute Aggregated Data message, which is sent by the
45
+ * aggregator to distribute the aggregated data to participants for validation.
46
+ * @param {DistributeAggregatedDataMessage} fields - The fields required to create a Distribute
47
+ * Aggregated Data message, which is sent by the aggregator to distribute the aggregated data to
48
+ * participants for validation.
49
+ * @returns {BaseMessage} The created Distribute Aggregated Data message.
50
+ */
51
+ export function createDistributeAggregatedDataMessage(fields) {
52
+ const { from, to, ...body } = fields;
53
+ return new BaseMessage({ type: DISTRIBUTE_AGGREGATED_DATA, from, to, body });
54
+ }
55
+ /**
56
+ * Factory function for creating a Validation Acknowledgment message, which is sent by a participant
57
+ * to acknowledge.
58
+ * @param {ValidationAckMessage} fields - The fields required to create a Validation Acknowledgment
59
+ * message, which is sent by a participant to acknowledge the validation of the aggregated data.
60
+ * @returns {BaseMessage} The created Validation Acknowledgment message.
61
+ */
62
+ export function createValidationAckMessage(fields) {
63
+ const { from, to, ...body } = fields;
64
+ return new BaseMessage({ type: VALIDATION_ACK, from, to, body });
65
+ }
66
+ /**
67
+ * Factory function for creating an Authorization Request message, which is sent by a participant to
68
+ * request authorization for their signature.
69
+ * @param {AuthorizationRequestMessage} fields - The fields required to create an Authorization
70
+ * Request message, which is sent by a participant to request authorization for their signature.
71
+ * @returns {BaseMessage} The created Authorization Request message.
72
+ */
73
+ export function createAuthorizationRequestMessage(fields) {
74
+ const { from, to, ...body } = fields;
75
+ return new BaseMessage({ type: AUTHORIZATION_REQUEST, from, to, body });
76
+ }
77
+ /**
78
+ * Factory function for creating a Nonce Contribution message, which is sent by a participant to
79
+ * contribute their nonce for the signature aggregation process.
80
+ * @param {NonceContributionMessage} fields - The fields required to create a Nonce Contribution
81
+ * message, which is sent by a participant to contribute their nonce for the signature aggregation
82
+ * process.
83
+ * @returns {BaseMessage} The created Nonce Contribution message.
84
+ */
85
+ export function createNonceContributionMessage(fields) {
86
+ const { from, to, ...body } = fields;
87
+ return new BaseMessage({ type: NONCE_CONTRIBUTION, from, to, body });
88
+ }
89
+ /**
90
+ * Factory function for creating an Aggregated Nonce message, which is sent by the aggregator to
91
+ * distribute the aggregated nonce to participants for the signature aggregation process.
92
+ * @param {AggregatedNonceMessage} fields - The fields required to create an Aggregated Nonce
93
+ * message, which is sent by the aggregator to distribute the aggregated nonce to participants for
94
+ * the signature aggregation process.
95
+ * @returns {BaseMessage} The created Aggregated Nonce message.
96
+ */
97
+ export function createAggregatedNonceMessage(fields) {
98
+ const { from, to, ...body } = fields;
99
+ return new BaseMessage({ type: AGGREGATED_NONCE, from, to, body });
100
+ }
101
+ /**
102
+ * Factory function for creating a Signature Authorization message, which is sent by a participant
103
+ * to authorize their partial signature for the signature aggregation process.
104
+ * @param {SignatureAuthorizationMessage} fields - The fields required to create a Signature
105
+ * Authorization message, which is sent by a participant to authorize their partial signature for
106
+ * the signature aggregation process.
107
+ * @returns {BaseMessage} The created Signature Authorization message.
108
+ */
109
+ export function createSignatureAuthorizationMessage(fields) {
110
+ const { from, to, ...body } = fields;
111
+ return new BaseMessage({ type: SIGNATURE_AUTHORIZATION, from, to, body });
112
+ }
113
+ //# sourceMappingURL=factories.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/messages/factories.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,gBAAgB,EA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IACzE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACrC,OAAO,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,gBAAgB,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AACrE,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,mCAAmC,CAAC,MAAqC;IACvF,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,GAAG,IAAI,EAAE,GAAG,MAAM,CAAC;IACrC,OAAO,IAAI,WAAW,CAAC,EAAE,IAAI,EAAE,uBAAuB,EAAE,IAAI,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC;AAC5E,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { AGGREGATED_NONCE, AUTHORIZATION_REQUEST, COHORT_ADVERT, COHORT_OPT_IN, COHORT_OPT_IN_ACCEPT, COHORT_READY, DISTRIBUTE_AGGREGATED_DATA, NONCE_CONTRIBUTION, SIGNATURE_AUTHORIZATION, SUBMIT_UPDATE, VALIDATION_ACK, } from './constants.js';
2
+ const KEYGEN_VALUES = new Set([
3
+ COHORT_ADVERT,
4
+ COHORT_OPT_IN,
5
+ COHORT_OPT_IN_ACCEPT,
6
+ COHORT_READY,
7
+ ]);
8
+ const UPDATE_VALUES = new Set([
9
+ SUBMIT_UPDATE,
10
+ DISTRIBUTE_AGGREGATED_DATA,
11
+ VALIDATION_ACK,
12
+ ]);
13
+ const SIGN_VALUES = new Set([
14
+ AUTHORIZATION_REQUEST,
15
+ NONCE_CONTRIBUTION,
16
+ AGGREGATED_NONCE,
17
+ SIGNATURE_AUTHORIZATION,
18
+ ]);
19
+ /**
20
+ * Checks if the provided type is a valid aggregation message type.
21
+ */
22
+ export function isAggregationMessageType(type) {
23
+ return KEYGEN_VALUES.has(type) || UPDATE_VALUES.has(type) || SIGN_VALUES.has(type);
24
+ }
25
+ /** Checks if the message type belongs to the keygen phase. */
26
+ export function isKeygenMessageType(type) {
27
+ return KEYGEN_VALUES.has(type);
28
+ }
29
+ /** Checks if the message type belongs to the update phase. */
30
+ export function isUpdateMessageType(type) {
31
+ return UPDATE_VALUES.has(type);
32
+ }
33
+ /** Checks if the message type belongs to the signing phase. */
34
+ export function isSignMessageType(type) {
35
+ return SIGN_VALUES.has(type);
36
+ }
37
+ //# sourceMappingURL=guards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"guards.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/messages/guards.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,qBAAqB,EACrB,aAAa,EACb,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,0BAA0B,EAC1B,kBAAkB,EAClB,uBAAuB,EACvB,aAAa,EACb,cAAc,GACf,MAAM,gBAAgB,CAAC;AAExB,MAAM,aAAa,GAAgB,IAAI,GAAG,CAAC;IACzC,aAAa;IACb,aAAa;IACb,oBAAoB;IACpB,YAAY;CACb,CAAC,CAAC;AAEH,MAAM,aAAa,GAAgB,IAAI,GAAG,CAAC;IACzC,aAAa;IACb,0BAA0B;IAC1B,cAAc;CACf,CAAC,CAAC;AAEH,MAAM,WAAW,GAAgB,IAAI,GAAG,CAAC;IACvC,qBAAqB;IACrB,kBAAkB;IAClB,gBAAgB;IAChB,uBAAuB;CACxB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,IAAY;IACnD,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACrF,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,8DAA8D;AAC9D,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AACjC,CAAC;AAED,+DAA+D;AAC/D,MAAM,UAAU,iBAAiB,CAAC,IAAY;IAC5C,OAAO,WAAW,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC"}
@@ -0,0 +1,5 @@
1
+ export * from './base.js';
2
+ export * from './constants.js';
3
+ export * from './factories.js';
4
+ export * from './guards.js';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/core/aggregation/messages/index.ts"],"names":[],"mappings":"AAAA,cAAc,WAAW,CAAC;AAC1B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,aAAa,CAAC"}