@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
@@ -1,512 +0,0 @@
1
- import { KeyBytes, Maybe } from '@did-btcr2/common';
2
- import { bytesToHex } from '@noble/hashes/utils';
3
- import { HDKey } from '@scure/bip32';
4
- import { mnemonicToSeedSync } from '@scure/bip39';
5
- import * as musig2 from '@scure/btc-signer/musig2';
6
- import { Transaction } from 'bitcoinjs-lib';
7
- import { BeaconParticipantError } from '../error.js';
8
- import { AggregateBeaconCohort } from './cohort/index.js';
9
- import {
10
- BEACON_COHORT_ADVERT,
11
- BEACON_COHORT_AGGREGATED_NONCE,
12
- BEACON_COHORT_AUTHORIZATION_REQUEST,
13
- BEACON_COHORT_OPT_IN_ACCEPT,
14
- BEACON_COHORT_READY
15
- } from './cohort/messages/constants.js';
16
- import { BeaconCohortAdvertMessage, CohortAdvertMessage } from './cohort/messages/keygen/cohort-advert.js';
17
- import { BeaconCohortReadyMessage, CohortReadyMessage } from './cohort/messages/keygen/cohort-ready.js';
18
- import { BeaconCohortOptInAcceptMessage, CohortOptInAcceptMessage } from './cohort/messages/keygen/opt-in-accept.js';
19
- import { BeaconCohortOptInMessage } from './cohort/messages/keygen/opt-in.js';
20
- import { BeaconCohortSubscribeMessage } from './cohort/messages/keygen/subscribe.js';
21
- import { BeaconCohortAggregatedNonceMessage, CohortAggregatedNonceMessage } from './cohort/messages/sign/aggregated-nonce.js';
22
- import { BeaconCohortAuthorizationRequestMessage, CohortAuthorizationRequestMessage } from './cohort/messages/sign/authorization-request.js';
23
- import { BeaconCohortNonceContributionMessage } from './cohort/messages/sign/nonce-contribution.js';
24
- import { BeaconCohortRequestSignatureMessage } from './cohort/messages/sign/request-signature.js';
25
- import { BeaconCohortSignatureAuthorizationMessage } from './cohort/messages/sign/signature-authorization.js';
26
- import { COHORT_STATUS } from './cohort/status.js';
27
- import { NostrAdapter } from './communication/adapter/nostr.js';
28
- import { CommunicationService } from './communication/service.js';
29
- import { BeaconCohortSigningSession } from './session/index.js';
30
-
31
- type Seed = KeyBytes;
32
- type Mnemonic = string;
33
-
34
- type SessionId = string;
35
- type ActiveSigningSessions = Map<SessionId, BeaconCohortSigningSession>;
36
-
37
- type CohortId = string;
38
- type KeyIndex = number;
39
- type CohortKeyState = Map<CohortId, KeyIndex>;
40
-
41
- type BeaconParticipantParams = {
42
- ent: Seed | Mnemonic;
43
- protocol?: CommunicationService;
44
- did: string;
45
- name?: string
46
- }
47
- /**
48
- * Represents a participant in the did:btc1 Beacon Aggregation protocol.
49
- * @class BeaconParticipant
50
- * @type {BeaconParticipant}
51
- */
52
- export class BeaconParticipant {
53
- /**
54
- * The name of the BeaconParticipant service.
55
- * @type {string}
56
- */
57
- public name: string;
58
-
59
- /**
60
- * The DID of the BeaconParticipant.
61
- * @type {Array<string>}
62
- */
63
- public did: string;
64
-
65
- /**
66
- * The communication protocol used by the BeaconParticipant.
67
- * @type {CommunicationService}
68
- */
69
- public protocol: CommunicationService;
70
-
71
- /**
72
- * The HD key used by the BeaconParticipant.
73
- * @type {HDKey}
74
- */
75
- public hdKey: HDKey;
76
-
77
- /**
78
- * The current index for the beacon key.
79
- * @type {number}
80
- */
81
- public beaconKeyIndex: number = 0;
82
-
83
- /**
84
- * The coordinator DIDs that the participant is subscribed to.
85
- * @type {Array<string>}
86
- */
87
- public coordinatorDids: Array<string> = new Array<string>();
88
-
89
- /**
90
- * The cohorts that the participant is part of.
91
- * @type {Array<AggregateBeaconCohort>}
92
- */
93
- public cohorts: Array<AggregateBeaconCohort> = new Array<AggregateBeaconCohort>();
94
-
95
- /**
96
- * A mapping of Cohort IDs to HDKey indexes (CohortId => KeyIndex).
97
- * @type {CohortKeyState}
98
- */
99
- public cohortKeyState: CohortKeyState = new Map<CohortId, KeyIndex>();
100
-
101
- /**
102
- * A mapping of active Session IDs to their sessions (sessionId => BeaconCohortSigningSession).
103
- * @type {ActiveSigningSessions}
104
- */
105
- public activeSigningSessions: ActiveSigningSessions = new Map<string, BeaconCohortSigningSession>();
106
-
107
- /**
108
- * Creates an instance of BeaconParticipant.
109
- * @param {BeaconParticipantParams} params The parameters for the participant.
110
- * @param {Seed | Mnemonic} params.ent The seed or mnemonic to derive the HD key.
111
- * @param {CommunicationService} params.protocol The communication protocol to use.
112
- * @param {string} params.did The DID of the participant.
113
- * @param {string} [params.name] Optional name for the participant. If not provided, a random name will be generated.
114
- */
115
- constructor({ ent, protocol, did, name }: BeaconParticipantParams) {
116
- this.did = did;
117
- this.name = name || `btcr2-beacon-participant-${crypto.randomUUID()}`;
118
- this.beaconKeyIndex = this.cohortKeyState.size;
119
-
120
- this.hdKey = ent instanceof Uint8Array
121
- ? HDKey.fromMasterSeed(ent)
122
- : HDKey.fromMasterSeed(mnemonicToSeedSync(ent));
123
-
124
- const { publicKey: pk, privateKey: secret } = this.hdKey.deriveChild(this.beaconKeyIndex);
125
- if(!pk || !secret) {
126
- throw new BeaconParticipantError(
127
- `Failed to derive HD key for participant ${this.name} at index ${this.beaconKeyIndex}`,
128
- 'CONSTRUCTOR_ERROR', { public: pk, secret }
129
- );
130
- }
131
- this.protocol = protocol || new NostrAdapter();
132
- this.protocol.setKeys({ public: pk, secret });
133
- this.cohortKeyState.set('__UNSET__', this.beaconKeyIndex);
134
- console.debug(`BeaconParticipant initialized with DID: ${this.did}, Name: ${this.name}, Key Index: ${this.beaconKeyIndex}`);
135
- }
136
-
137
- /**
138
- * Setup and start the BeaconParticipant communication protocol..
139
- * @returns {void}
140
- */
141
- public start(): void {
142
- console.info(`Setting up BeaconParticipant ${this.name} (${this.did}) on ${this.protocol.name} ...`);
143
- this.protocol.registerMessageHandler(BEACON_COHORT_ADVERT, this._handleCohortAdvert.bind(this));
144
- this.protocol.registerMessageHandler(BEACON_COHORT_OPT_IN_ACCEPT, this._handleSubscribeAccept.bind(this));
145
- this.protocol.registerMessageHandler(BEACON_COHORT_READY, this._handleCohortReady.bind(this));
146
- this.protocol.registerMessageHandler(BEACON_COHORT_AUTHORIZATION_REQUEST, this._handleAuthorizationRequest.bind(this));
147
- this.protocol.registerMessageHandler(BEACON_COHORT_AGGREGATED_NONCE, this._handleAggregatedNonce.bind(this));
148
- this.protocol.start();
149
- }
150
-
151
- /**
152
- * Retrieves the HD key for a specific cohort based on its ID.
153
- * @param {string} cohortId The ID of the cohort for which to retrieve the key.
154
- * @returns {HDKey} The HD key for the cohort, or throws an error if not found.
155
- * @throws {BeaconParticipantError} If the cohort key state is not found for the given cohort ID.
156
- */
157
- public getCohortKey(cohortId: string): HDKey {
158
- const keyIndex = this.cohortKeyState.get(cohortId);
159
- if(keyIndex === undefined) {
160
- throw new BeaconParticipantError(`Cohort key state for cohort ${cohortId} not found.`, 'COHORT_KEY_NOT_FOUND');
161
- }
162
- return this.hdKey.deriveChild(keyIndex);
163
- }
164
-
165
- /**
166
- * Sets the state of the cohort key for a given cohort ID and key index.
167
- * @param {string} cohortId The ID of the cohort for which to set the key state.
168
- * @returns {void}
169
- */
170
- public setCohortKey(cohortId: string): void {
171
- if(this.cohortKeyState.size > 0) {
172
- this.beaconKeyIndex = this.cohortKeyState.size + 1;
173
- }
174
- if(this.cohortKeyState.has(cohortId)) {
175
- console.warn(`Cohort key state for cohort ${cohortId} already exists. Updating key index.`);
176
- }
177
- this.cohortKeyState.set(cohortId, this.beaconKeyIndex);
178
- console.info(`Cohort key state updated. Next beacon key index: ${this.beaconKeyIndex + 1}`);
179
- }
180
-
181
- /**
182
- * Finalizes the placeholder "__UNSET__" key and assigns it to the provided cohortId.
183
- * If no "__UNSET__" entry exists, throws an error.
184
- * If cohortId already exists, logs a warning and does nothing.
185
- * @param {string} cohortId The ID of the cohort to finalize the unset key for.
186
- * @throws {BeaconParticipantError} If no "__UNSET__" cohort key state is found.
187
- * @returns {void}
188
- */
189
- public finalizeUnsetCohortKey(cohortId: string): void {
190
- const unsetKey = '__UNSET__';
191
-
192
- if (!this.cohortKeyState.has(unsetKey)) {
193
- throw new BeaconParticipantError(
194
- `No '__UNSET__' cohort key to finalize for ${this.did}`,
195
- 'UNSET_KEY_NOT_FOUND'
196
- );
197
- }
198
-
199
- if (this.cohortKeyState.has(cohortId)) {
200
- console.warn(`Cohort key state already exists for ${cohortId}. Skipping migration from '__UNSET__'.`);
201
- this.cohortKeyState.delete(unsetKey);
202
- return;
203
- }
204
-
205
- this.setCohortKey(cohortId);
206
- this.cohortKeyState.delete(unsetKey);
207
-
208
- console.info(`Finalized '__UNSET__' CohortKeyState with ${cohortId} for ${this.did}`);
209
- }
210
-
211
- /**
212
- * Handle subscription acceptance from a coordinator.
213
- * @param {CohortOptInAcceptMessage} message The message containing the subscription acceptance.
214
- * @returns {Promise<void>}
215
- */
216
- private async _handleSubscribeAccept(message: Maybe<CohortOptInAcceptMessage>): Promise<void> {
217
- const subscribeAcceptMessage = BeaconCohortOptInAcceptMessage.fromJSON(message);
218
- const coordinatorDid = subscribeAcceptMessage.from;
219
- if (!this.coordinatorDids.includes(coordinatorDid)) {
220
- this.coordinatorDids.push(coordinatorDid);
221
- }
222
- }
223
-
224
- /**
225
- * Handles a cohort advertisement message.
226
- * @param {Maybe<BeaconCohortAdvertMessage>} message The cohort advertisement message.
227
- * @returns {Promise<void>}
228
- */
229
- public async _handleCohortAdvert(message: Maybe<CohortAdvertMessage>): Promise<void> {
230
- console.debug('_handleCohortAdvert', message);
231
- const cohortAdvertMessage = BeaconCohortAdvertMessage.fromJSON(message);
232
- console.info(`Received new cohort announcement from ${cohortAdvertMessage.from}`, cohortAdvertMessage);
233
-
234
- const cohortId = cohortAdvertMessage.body?.cohortId;
235
- if (!cohortId) {
236
- console.warn('Received malformed cohort advert message: missing cohortId', cohortAdvertMessage);
237
- return;
238
- }
239
-
240
- const network = cohortAdvertMessage.body?.network;
241
- if (!network) {
242
- console.warn('Received malformed cohort advert message: missing network', cohortAdvertMessage);
243
- return;
244
- }
245
-
246
- const minParticipants = cohortAdvertMessage.body?.cohortSize;
247
- if (!cohortId || !network || !minParticipants) {
248
- console.warn('Received malformed cohort advert message: missing minParticipants', cohortAdvertMessage);
249
- return;
250
- }
251
-
252
- const from = cohortAdvertMessage.from;
253
- const cohort = new AggregateBeaconCohort(
254
- {
255
- network,
256
- minParticipants,
257
- id : cohortId,
258
- coordinatorDid : from,
259
- }
260
- );
261
- this.cohorts.push(cohort);
262
- await this.joinCohort(cohort.id, from);
263
- }
264
-
265
- /**
266
- * Handles a cohort set message.
267
- * @param {Maybe<CohortReadyMessage>} message The cohort set message.
268
- * @returns {Promise<void>}
269
- */
270
- public async _handleCohortReady(message: Maybe<CohortReadyMessage>): Promise<void> {
271
- const cohortSetMessage = BeaconCohortReadyMessage.fromJSON(message);
272
- const cohortId = cohortSetMessage.body?.cohortId;
273
- const cohort = this.cohorts.find(c => c.id === cohortId);
274
- if (!cohortId || !cohort) {
275
- console.warn(`Cohort with ID ${cohortId} not found or not joined by participant ${this.did}.`);
276
- return;
277
- }
278
- this.finalizeUnsetCohortKey(cohortId);
279
- const participantPkBytes = this.getCohortKey(cohortId).publicKey;
280
- if(!participantPkBytes) {
281
- console.error(`Failed to derive public key for cohort ${cohortId}`);
282
- return;
283
- }
284
- const participantPk = bytesToHex(participantPkBytes);
285
- const beaconAddress = cohortSetMessage.body?.beaconAddress;
286
- if(!beaconAddress) {
287
- console.error(`Beacon address not provided in cohort set message for ${cohortId}`);
288
- return;
289
- }
290
- const cohortKeys = cohortSetMessage.body?.cohortKeys;
291
- if(!cohortKeys) {
292
- console.error(`Cohort keys not provided in cohort set message for ${cohortId}`);
293
- return;
294
- }
295
- const keys = cohortKeys.map(key => bytesToHex(new Uint8Array(key)));
296
- cohort.validateCohort([participantPk], keys, beaconAddress);
297
- console.info(`BeaconParticipant w/ pk ${participantPk} successfully joined cohort ${cohortId} with beacon address ${beaconAddress}.`);
298
- console.info(`Cohort status: ${cohort.status}`);
299
- }
300
-
301
- /**
302
- * Handles an authorization request message.
303
- * @param {Maybe<CohortAuthorizationRequestMessage>} message The authorization request message.
304
- * @returns {Promise<void>}
305
- */
306
- public async _handleAuthorizationRequest(message: Maybe<CohortAuthorizationRequestMessage>): Promise<void> {
307
- const authRequest = BeaconCohortAuthorizationRequestMessage.fromJSON(message);
308
- const cohort = this.cohorts.find(c => c.id === authRequest.body?.cohortId);
309
- if (!cohort) {
310
- console.warn(`Authorization request for unknown cohort ${authRequest.body?.cohortId} from ${authRequest.from}`);
311
- return;
312
- }
313
- const id = authRequest.body?.sessionId;
314
- if (!id) {
315
- console.warn(`Authorization request missing session ID from ${authRequest.from}`);
316
- return;
317
- }
318
- const pendingTx = authRequest.body?.pendingTx;
319
- if (!pendingTx) {
320
- console.warn(`Authorization request missing pending transaction from ${authRequest.from}`);
321
- return;
322
- }
323
- const session = new BeaconCohortSigningSession({
324
- cohort,
325
- id,
326
- pendingTx : Transaction.fromHex(pendingTx),
327
- });
328
- this.activeSigningSessions.set(session.id, session);
329
- const nonceContribution = this.generateNonceContribution(cohort, session);
330
- await this.sendNonceContribution(cohort, nonceContribution, session);
331
- }
332
-
333
- /**
334
- * Handles an aggregated nonce message.
335
- * @param {Maybe<CohortAggregatedNonceMessage>} message The aggregated nonce message.
336
- * @returns {Promise<void>}
337
- */
338
- public async _handleAggregatedNonce(message: Maybe<CohortAggregatedNonceMessage>): Promise<void> {
339
- const aggNonceMessage = BeaconCohortAggregatedNonceMessage.fromJSON(message);
340
- const sessionId = aggNonceMessage.body?.sessionId;
341
- if (!sessionId) {
342
- console.warn(`Aggregated nonce message missing session ID from ${aggNonceMessage.from}`);
343
- return;
344
- }
345
- const session = this.activeSigningSessions.get(sessionId);
346
- if (!session) {
347
- console.warn(`Aggregated nonce message received for unknown session ${sessionId}`);
348
- return;
349
- }
350
- const aggregatedNonce = aggNonceMessage.body?.aggregatedNonce;
351
- if (!aggregatedNonce) {
352
- console.warn(`Aggregated nonce message missing aggregated nonce from ${aggNonceMessage.from}`);
353
- return;
354
- }
355
- session.aggregatedNonce = aggregatedNonce;
356
- const participantSk = this.getCohortKey(session.cohort.id).privateKey;
357
- if(!participantSk) {
358
- console.error(`Failed to derive secret key for cohort ${session.cohort.id}`);
359
- return;
360
- }
361
- const partialSig = session.generatePartialSignature(participantSk);
362
- await this.sendPartialSignature(session, partialSig);
363
- };
364
-
365
- /**
366
- * Subscribes to a coordinator's messages.
367
- * @param {string} coordinatorDid The DID of the coordinator to subscribe to.
368
- * @returns {Promise<void>}
369
- */
370
- public async subscribeToCoordinator(coordinatorDid: string): Promise<any> {
371
- if(this.coordinatorDids.includes(coordinatorDid)) {
372
- console.info(`Already subscribed to coordinator ${coordinatorDid}`);
373
- return;
374
- }
375
- const subMessage = new BeaconCohortSubscribeMessage({ to: coordinatorDid, from: this.did });
376
- return await this.protocol.sendMessage(subMessage, this.did, coordinatorDid);
377
- }
378
-
379
- /**
380
- * Joins a cohort with the given ID and coordinator DID.
381
- * @param {string} cohortId The ID of the cohort to join.
382
- * @param {string} coordinatorDid The DID of the cohort coordinator.
383
- * @returns {Promise<void>}
384
- */
385
- public async joinCohort(cohortId: string, coordinatorDid: string): Promise<void> {
386
- console.info(`BeaconParticipant ${this.did} joining cohort ${cohortId} with coordinator ${coordinatorDid}`);
387
- this.finalizeUnsetCohortKey(cohortId);
388
- const cohort = this.cohorts.find(c => c.id === cohortId);
389
- if (!cohort) {
390
- console.warn(`Cohort with ID ${cohortId} not found.`);
391
- return;
392
- }
393
- const pk = this.getCohortKey(cohortId).publicKey;
394
- if(!pk) {
395
- console.error(`Failed to derive public key for cohort ${cohortId} at index ${this.beaconKeyIndex}`);
396
- return;
397
- }
398
- this.setCohortKey(cohortId);
399
- const optInMessage = new BeaconCohortOptInMessage({
400
- cohortId,
401
- participantPk : pk,
402
- from : this.did,
403
- to : coordinatorDid,
404
- });
405
-
406
- await this.protocol.sendMessage(optInMessage, this.did, coordinatorDid);
407
- cohort.status = COHORT_STATUS.COHORT_OPTED_IN;
408
- }
409
-
410
- /**
411
- * Requests a signature for the given cohort and data.
412
- * @param {string} cohortId The ID of the cohort for which to request a signature.
413
- * @param {string} data The data for which to request a signature.
414
- * @returns {Promise<boolean>} Whether the signature request was successful.
415
- */
416
- public async requestCohortSignature(cohortId: string, data: string): Promise<boolean> {
417
- const cohort = this.cohorts.find(c => c.id === cohortId);
418
- if (!cohort) {
419
- console.warn(`Cohort with ID ${cohortId} not found.`);
420
- return false;
421
- }
422
- if(cohort.status !== COHORT_STATUS.COHORT_SET_STATUS) {
423
- console.warn(`Cohort ${cohortId} not in a set state. Current status: ${cohort.status}`);
424
- return false;
425
- }
426
- const reqSigMessage = new BeaconCohortRequestSignatureMessage({
427
- to : cohort.coordinatorDid,
428
- from : this.did,
429
- data,
430
- cohortId
431
- });
432
- await this.protocol.sendMessage(reqSigMessage, this.did, cohort.coordinatorDid);
433
- return true;
434
- }
435
-
436
- /**
437
- * Generates a nonce contribution for the given cohort and session.
438
- * @param {AggregateBeaconCohort} cohort The cohort for which to generate the nonce contribution.
439
- * @param {BeaconCohortSigningSession} session The session for which to generate the nonce contribution.
440
- * @returns {Promise<string[]>} An array of nonce points in hexadecimal format.
441
- */
442
- public generateNonceContribution(cohort: AggregateBeaconCohort, session: BeaconCohortSigningSession): Uint8Array {
443
- const cohortKey = this.getCohortKey(cohort.id);
444
- if (!cohortKey) {
445
- throw new BeaconParticipantError(
446
- `Cohort key state not found for cohort ${cohort.id}`,
447
- 'COHORT_KEY_NOT_FOUND', cohortKey
448
- );
449
- }
450
- const { publicKey, privateKey } = cohortKey;
451
- if(!publicKey || !privateKey) {
452
- throw new BeaconParticipantError(
453
- `Failed to derive public key for cohort ${cohort.id}`,
454
- 'PARTICIPANT_PK_NOT_FOUND', cohortKey
455
- );
456
- }
457
- session.aggregatedNonce ??= session.generateAggregatedNonce();
458
- return musig2.nonceGen(publicKey, privateKey, session.aggregatedNonce, cohort.trMerkleRoot).public;
459
- }
460
-
461
- /**
462
- * Sends a nonce contribution message to the cohort coordinator.
463
- * @param {AggregateBeaconCohort} cohort The cohort to which the nonce contribution is sent.
464
- * @param {Uint8Array} nonceContribution The nonce contribution points in hexadecimal format.
465
- * @param {BeaconCohortSigningSession} session The session associated with the nonce contribution.
466
- */
467
- public async sendNonceContribution(
468
- cohort: AggregateBeaconCohort,
469
- nonceContribution: Uint8Array,
470
- session: BeaconCohortSigningSession
471
- ): Promise<void> {
472
- const nonceContributionMessage = BeaconCohortNonceContributionMessage.fromJSON({
473
- to : cohort.coordinatorDid,
474
- from : this.did,
475
- sessionId : session.id,
476
- cohortId : cohort.id,
477
- nonceContribution
478
- });
479
- await this.protocol.sendMessage(nonceContributionMessage, this.did, cohort.coordinatorDid);
480
- console.info(`Nonce contribution sent for session ${session.id} in cohort ${cohort.id} by participant ${this.did}`);
481
- }
482
-
483
- /**
484
- * Sends a partial signature for the given session.
485
- * @param {BeaconCohortSigningSession} session The session for which the partial signature is sent.
486
- * @param {Uint8Array} partialSig The partial signature to send.
487
- * @returns {Promise<void>}
488
- */
489
- public async sendPartialSignature(session: BeaconCohortSigningSession, partialSig: Uint8Array): Promise<void> {
490
- const sigAuthMessage = new BeaconCohortSignatureAuthorizationMessage({
491
- to : session.cohort.coordinatorDid,
492
- from : this.did,
493
- cohortId : session.cohort.id,
494
- sessionId : session.id,
495
- partialSignature : partialSig,
496
- });
497
- await this.protocol.sendMessage(sigAuthMessage, this.did, session.cohort.coordinatorDid);
498
- console.info(`Partial signature sent for session ${session.id} in cohort ${session.cohort.id} by participant ${this.did}`);
499
- }
500
-
501
- /**
502
- * Initializes a new BeaconParticipant instance.
503
- * @param {Seed | Mnemonic} ent The secret key used for signing.
504
- * @param {CommunicationService} protocol The communication protocol used by the participant.
505
- * @param {string} [name] The name of the participant.
506
- * @param {string} [did] The decentralized identifier (DID) of the participant.
507
- * @returns {BeaconParticipant} A new instance of BeaconParticipant.
508
- */
509
- public static initialize(ent: Seed | Mnemonic, protocol: CommunicationService, did: string, name?: string): BeaconParticipant {
510
- return new BeaconParticipant({ent, protocol, name, did});
511
- }
512
- }