@did-btcr2/method 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (297) hide show
  1. package/README.md +118 -236
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/browser.js +27665 -23764
  4. package/dist/browser.mjs +27665 -23764
  5. package/dist/cjs/index.js +2661 -2239
  6. package/dist/esm/core/aggregation/cohort.js +178 -0
  7. package/dist/esm/core/aggregation/cohort.js.map +1 -0
  8. package/dist/esm/core/aggregation/errors.js +22 -0
  9. package/dist/esm/core/aggregation/errors.js.map +1 -0
  10. package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
  11. package/dist/esm/core/aggregation/messages/base.js.map +1 -0
  12. package/dist/esm/core/aggregation/messages/constants.js +26 -0
  13. package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
  14. package/dist/esm/core/aggregation/messages/factories.js +113 -0
  15. package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
  16. package/dist/esm/core/aggregation/messages/guards.js +37 -0
  17. package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
  18. package/dist/esm/core/aggregation/messages/index.js +5 -0
  19. package/dist/esm/core/aggregation/messages/index.js.map +1 -0
  20. package/dist/esm/core/aggregation/participant.js +376 -0
  21. package/dist/esm/core/aggregation/participant.js.map +1 -0
  22. package/dist/esm/core/aggregation/phases.js +39 -0
  23. package/dist/esm/core/aggregation/phases.js.map +1 -0
  24. package/dist/esm/core/aggregation/runner/events.js +2 -0
  25. package/dist/esm/core/aggregation/runner/events.js.map +1 -0
  26. package/dist/esm/core/aggregation/runner/index.js +5 -0
  27. package/dist/esm/core/aggregation/runner/index.js.map +1 -0
  28. package/dist/esm/core/aggregation/runner/participant-runner.js +286 -0
  29. package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
  30. package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
  31. package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
  32. package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
  33. package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
  34. package/dist/esm/core/aggregation/service.js +416 -0
  35. package/dist/esm/core/aggregation/service.js.map +1 -0
  36. package/dist/esm/core/aggregation/signing-session.js +133 -0
  37. package/dist/esm/core/aggregation/signing-session.js.map +1 -0
  38. package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
  39. package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
  40. package/dist/esm/core/aggregation/transport/error.js +12 -0
  41. package/dist/esm/core/aggregation/transport/error.js.map +1 -0
  42. package/dist/esm/core/aggregation/transport/factory.js +20 -0
  43. package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
  44. package/dist/esm/core/aggregation/transport/index.js +6 -0
  45. package/dist/esm/core/aggregation/transport/index.js.map +1 -0
  46. package/dist/esm/core/aggregation/transport/nostr.js +262 -0
  47. package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
  48. package/dist/esm/core/aggregation/transport/transport.js +2 -0
  49. package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
  50. package/dist/esm/core/beacon/beacon.js +80 -0
  51. package/dist/esm/core/beacon/beacon.js.map +1 -1
  52. package/dist/esm/core/beacon/cas-beacon.js +15 -56
  53. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  54. package/dist/esm/core/beacon/error.js +0 -10
  55. package/dist/esm/core/beacon/error.js.map +1 -1
  56. package/dist/esm/core/beacon/fee-estimator.js +30 -0
  57. package/dist/esm/core/beacon/fee-estimator.js.map +1 -0
  58. package/dist/esm/core/beacon/singleton-beacon.js +10 -53
  59. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  60. package/dist/esm/core/beacon/smt-beacon.js +85 -9
  61. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  62. package/dist/esm/core/identifier.js +13 -0
  63. package/dist/esm/core/identifier.js.map +1 -1
  64. package/dist/esm/core/resolver.js +9 -0
  65. package/dist/esm/core/resolver.js.map +1 -1
  66. package/dist/esm/core/updater.js +269 -0
  67. package/dist/esm/core/updater.js.map +1 -0
  68. package/dist/esm/did-btcr2.js +30 -42
  69. package/dist/esm/did-btcr2.js.map +1 -1
  70. package/dist/esm/index.js +16 -25
  71. package/dist/esm/index.js.map +1 -1
  72. package/dist/types/core/aggregation/cohort.d.ts +94 -0
  73. package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
  74. package/dist/types/core/aggregation/errors.d.ts +14 -0
  75. package/dist/types/core/aggregation/errors.d.ts.map +1 -0
  76. package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
  77. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
  78. package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
  79. package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
  80. package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
  81. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
  82. package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
  83. package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
  84. package/dist/types/core/aggregation/messages/index.d.ts +5 -0
  85. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
  86. package/dist/types/core/aggregation/participant.d.ts +101 -0
  87. package/dist/types/core/aggregation/participant.d.ts.map +1 -0
  88. package/dist/types/core/aggregation/phases.d.ts +49 -0
  89. package/dist/types/core/aggregation/phases.d.ts.map +1 -0
  90. package/dist/types/core/aggregation/runner/events.d.ts +89 -0
  91. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
  92. package/dist/types/core/aggregation/runner/index.d.ts +5 -0
  93. package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
  94. package/dist/types/core/aggregation/runner/participant-runner.d.ts +111 -0
  95. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
  96. package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
  97. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
  98. package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
  99. package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
  100. package/dist/types/core/aggregation/service.d.ts +112 -0
  101. package/dist/types/core/aggregation/service.d.ts.map +1 -0
  102. package/dist/types/core/aggregation/signing-session.d.ts +69 -0
  103. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
  104. package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
  105. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
  106. package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
  107. package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
  108. package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
  109. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
  110. package/dist/types/core/aggregation/transport/index.d.ts +6 -0
  111. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
  112. package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
  113. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
  114. package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
  115. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
  116. package/dist/types/core/beacon/beacon.d.ts +37 -2
  117. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  118. package/dist/types/core/beacon/cas-beacon.d.ts +19 -7
  119. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  120. package/dist/types/core/beacon/error.d.ts +0 -6
  121. package/dist/types/core/beacon/error.d.ts.map +1 -1
  122. package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
  123. package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
  124. package/dist/types/core/beacon/interfaces.d.ts +8 -0
  125. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  126. package/dist/types/core/beacon/singleton-beacon.d.ts +9 -2
  127. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  128. package/dist/types/core/beacon/smt-beacon.d.ts +27 -7
  129. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  130. package/dist/types/core/identifier.d.ts +8 -0
  131. package/dist/types/core/identifier.d.ts.map +1 -1
  132. package/dist/types/core/interfaces.d.ts +2 -2
  133. package/dist/types/core/resolver.d.ts +11 -1
  134. package/dist/types/core/resolver.d.ts.map +1 -1
  135. package/dist/types/core/updater.d.ts +178 -0
  136. package/dist/types/core/updater.d.ts.map +1 -0
  137. package/dist/types/did-btcr2.d.ts +23 -23
  138. package/dist/types/did-btcr2.d.ts.map +1 -1
  139. package/dist/types/index.d.ts +11 -25
  140. package/dist/types/index.d.ts.map +1 -1
  141. package/package.json +31 -30
  142. package/src/core/aggregation/cohort.ts +247 -0
  143. package/src/core/aggregation/errors.ts +25 -0
  144. package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
  145. package/src/core/aggregation/messages/constants.ts +28 -0
  146. package/src/core/aggregation/messages/factories.ts +240 -0
  147. package/src/core/aggregation/messages/guards.ts +55 -0
  148. package/src/core/aggregation/messages/index.ts +4 -0
  149. package/src/core/aggregation/participant.ts +510 -0
  150. package/src/core/aggregation/phases.ts +82 -0
  151. package/src/core/aggregation/runner/events.ts +77 -0
  152. package/src/core/aggregation/runner/index.ts +4 -0
  153. package/src/core/aggregation/runner/participant-runner.ts +364 -0
  154. package/src/core/aggregation/runner/service-runner.ts +365 -0
  155. package/src/core/aggregation/runner/typed-emitter.ts +87 -0
  156. package/src/core/aggregation/service.ts +547 -0
  157. package/src/core/aggregation/signing-session.ts +209 -0
  158. package/src/core/aggregation/transport/didcomm.ts +42 -0
  159. package/src/core/aggregation/transport/error.ts +13 -0
  160. package/src/core/aggregation/transport/factory.ts +29 -0
  161. package/src/core/aggregation/transport/index.ts +5 -0
  162. package/src/core/aggregation/transport/nostr.ts +333 -0
  163. package/src/core/aggregation/transport/transport.ts +46 -0
  164. package/src/core/beacon/beacon.ts +122 -2
  165. package/src/core/beacon/cas-beacon.ts +28 -76
  166. package/src/core/beacon/error.ts +0 -12
  167. package/src/core/beacon/fee-estimator.ts +52 -0
  168. package/src/core/beacon/interfaces.ts +10 -1
  169. package/src/core/beacon/singleton-beacon.ts +14 -75
  170. package/src/core/beacon/smt-beacon.ts +109 -11
  171. package/src/core/identifier.ts +17 -0
  172. package/src/core/interfaces.ts +2 -2
  173. package/src/core/resolver.ts +25 -2
  174. package/src/core/updater.ts +415 -0
  175. package/src/did-btcr2.ts +36 -66
  176. package/src/index.ts +17 -30
  177. package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
  178. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
  179. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  180. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  181. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  182. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
  183. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  184. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  185. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  186. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  187. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  188. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  189. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  190. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  191. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  192. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  193. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  194. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  195. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  196. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  197. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  198. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  199. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  200. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  201. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  202. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  203. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  204. package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
  205. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
  206. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  207. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  208. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -245
  209. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  210. package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
  211. package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
  212. package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
  213. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
  214. package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
  215. package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
  216. package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
  217. package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
  218. package/dist/esm/core/beacon/aggregation/participant.js +0 -435
  219. package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
  220. package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
  221. package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
  222. package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
  223. package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
  224. package/dist/esm/core/update.js +0 -112
  225. package/dist/esm/core/update.js.map +0 -1
  226. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
  227. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
  228. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
  229. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
  230. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
  231. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
  232. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
  233. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
  234. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
  235. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
  236. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
  237. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
  238. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
  239. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
  240. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
  241. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
  242. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
  243. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
  244. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
  245. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
  246. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
  247. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
  248. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
  249. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
  250. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
  251. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
  252. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
  253. package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
  254. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
  255. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
  256. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
  257. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
  258. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
  259. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
  260. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
  261. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
  262. package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
  263. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
  264. package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
  265. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
  266. package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
  267. package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
  268. package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
  269. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
  270. package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
  271. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
  272. package/dist/types/core/update.d.ts +0 -52
  273. package/dist/types/core/update.d.ts.map +0 -1
  274. package/src/core/beacon/aggregation/cohort/index.ts +0 -305
  275. package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
  276. package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
  277. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -44
  278. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -40
  279. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -35
  280. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -34
  281. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -36
  282. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -39
  283. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -40
  284. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -40
  285. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -40
  286. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -41
  287. package/src/core/beacon/aggregation/cohort/status.ts +0 -7
  288. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -148
  289. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -323
  290. package/src/core/beacon/aggregation/communication/error.ts +0 -13
  291. package/src/core/beacon/aggregation/communication/factory.ts +0 -25
  292. package/src/core/beacon/aggregation/communication/service.ts +0 -42
  293. package/src/core/beacon/aggregation/coordinator.ts +0 -419
  294. package/src/core/beacon/aggregation/participant.ts +0 -517
  295. package/src/core/beacon/aggregation/session/index.ts +0 -301
  296. package/src/core/beacon/aggregation/session/status.ts +0 -18
  297. package/src/core/update.ts +0 -158
@@ -1,305 +0,0 @@
1
- import { hexToBytes } from '@noble/hashes/utils';
2
- import { keyAggExport, keyAggregate, sortKeys } from '@scure/btc-signer/musig2';
3
- import { payments, Transaction } from 'bitcoinjs-lib';
4
- import { BeaconCoordinatorError } from '../../error.js';
5
- import { BeaconCohortSigningSession } from '../session/index.js';
6
- import { BeaconCohortReadyMessage } from './messages/keygen/cohort-ready.js';
7
- import type { BeaconCohortRequestSignatureMessage } from './messages/sign/request-signature.js';
8
- import type { COHORT_STATUS_TYPE } from './status.js';
9
- import { COHORT_STATUS } from './status.js';
10
-
11
- export type Musig2CohortObject = {
12
- id?: string;
13
- coordinatorDid?: string;
14
- minParticipants?: number;
15
- status?: COHORT_STATUS_TYPE;
16
- network: string;
17
- beaconType?: string;
18
- }
19
-
20
- export interface BeaconCohort {
21
- id?: string;
22
- coordinatorDid: string;
23
- minParticipants: number;
24
- status: COHORT_STATUS_TYPE;
25
- network: string;
26
- pendingSignatureRequests?: Record<string, string>;
27
- participants?: Array<string>;
28
- cohortKeys?: Array<Uint8Array>;
29
- trMerkleRoot?: Uint8Array;
30
- beaconAddress?: string;
31
- }
32
-
33
- export class AggregateBeaconCohort implements BeaconCohort {
34
- /**
35
- * Unique identifier for the cohort.
36
- * @type {string}
37
- */
38
- public id: string;
39
-
40
- /**
41
- * DID of the coordinator.
42
- * @type {string}
43
- */
44
- public coordinatorDid: string;
45
-
46
- /**
47
- * Minimum number of participants required to finalize the cohort.
48
- * @type {number}
49
- */
50
- public minParticipants: number;
51
-
52
- /**
53
- * Status of the cohort.
54
- * @type {string}
55
- */
56
- public status: COHORT_STATUS_TYPE;
57
-
58
- /**
59
- * Network on which the cohort operates (e.g., 'mainnet', 'testnet').
60
- * @type {string}
61
- */
62
- public network: string;
63
-
64
- /**
65
- * Pending signature requests, mapping participant DIDs to their pending signatures.
66
- * @type {Record<string, string>}
67
- */
68
- public pendingSignatureRequests: Record<string, string> = {};
69
-
70
- /**
71
- * List of participant DIDs.
72
- * @type {Array<string>}
73
- */
74
- public participants: Array<string> = new Array<string>();
75
-
76
- /**
77
- * List of cohort keys.
78
- * @type {Array<Uint8Array>}
79
- */
80
- public _cohortKeys: Array<Uint8Array> = new Array<Uint8Array>();
81
-
82
- /**
83
- * Taproot Merkle root for the cohort.
84
- * @type {Uint8Array}
85
- */
86
- public trMerkleRoot: Uint8Array = new Uint8Array();
87
-
88
- /**
89
- * Beacon address for the cohort, calculated from the Taproot multisig.
90
- * @type {string}
91
- */
92
- public beaconAddress: string = '';
93
-
94
- /**
95
- * Type of beacon used in the cohort (default is 'SMTBeacon').
96
- * @type {string}
97
- */
98
- public beaconType: string;
99
-
100
- /**
101
- * Creates a new Musig2Cohort instance.
102
- * @param {Musig2CohortObject} params Parameters for initializing the cohort.
103
- * @param {string} [params.id] Optional unique identifier for the cohort. If not provided, a random UUID will be generated.
104
- * @param {number} params.minParticipants Minimum number of participants required to finalize the cohort.
105
- * @param {string} [params.coordinatorDid] DID of the coordinator managing the cohort.
106
- * @param {string} params.status Initial status of the cohort (e.g., 'PENDING', 'COHORT_SET').
107
- * @param {string} params.network Network on which the cohort operates (e.g., 'mainnet', 'testnet').
108
- */
109
- constructor({ id, minParticipants, coordinatorDid, status, network, beaconType }: Musig2CohortObject) {
110
- this.id = id || crypto.randomUUID();
111
- this.minParticipants = minParticipants || 2;
112
- this.coordinatorDid = coordinatorDid || '';
113
- this.status = status as COHORT_STATUS_TYPE || COHORT_STATUS.COHORT_ADVERTISED;
114
- this.network = network;
115
- this.beaconType = beaconType || 'SMTBeacon';
116
- }
117
-
118
- set cohortKeys(keys: Array<Uint8Array>) {
119
- this.cohortKeys = sortKeys(keys);
120
- }
121
-
122
- public validateCohort(participantKeys: Array<string>, cohortKeys: Array<string>, beaconAddress: string): void {
123
- for(const key of participantKeys){
124
- if(!cohortKeys.includes(key)) {
125
- this.status = COHORT_STATUS.COHORT_FAILED;
126
- throw new BeaconCoordinatorError(
127
- `Participant key ${key} not found in cohort ${this.id}.`,
128
- 'COHORT_VALIDATION_ERROR',
129
- {
130
- cohortId : this.id,
131
- participantKeys : participantKeys,
132
- cohortKeys : cohortKeys,
133
- beaconAddress : beaconAddress
134
- }
135
- );
136
- }
137
- }
138
- this.cohortKeys = cohortKeys.map(key => hexToBytes(key));
139
- const calculatedAddress = this.calulateBeaconAddress();
140
- if (calculatedAddress !== beaconAddress) {
141
- this.status = COHORT_STATUS.COHORT_FAILED;
142
- throw new BeaconCoordinatorError(
143
- `Calculated beacon address ${calculatedAddress} does not match provided address ${beaconAddress}.`,
144
- 'COHORT_ADDRESS_MISMATCH_ERROR',
145
- {
146
- cohortId : this.id,
147
- calculatedAddress,
148
- providedAddress : beaconAddress
149
- }
150
- );
151
- }
152
- this.beaconAddress = beaconAddress;
153
- this.status = COHORT_STATUS.COHORT_SET_STATUS;
154
- }
155
-
156
- /**
157
- * Finalizes the cohort by checking if the minimum number of participants is met.
158
- * If the minimum is met, it sets the status to 'COHORT_SET_STATUS' and calculates the beacon address.
159
- * @throws {BeaconCoordinatorError} If the number of participants is less than the minimum required.
160
- * @returns {void}
161
- */
162
- public finalize(): void {
163
- if(this.participants.length < this.minParticipants) {
164
- throw new BeaconCoordinatorError(
165
- 'Not enough participants to finalize the cohort',
166
- 'FINALIZE_COHORT_ERROR',
167
- {
168
- cohortId : this.id,
169
- participants : this.participants,
170
- minParticipants : this.minParticipants
171
- }
172
- );
173
- }
174
- this.status = COHORT_STATUS.COHORT_SET_STATUS;
175
- this.beaconAddress = this.calulateBeaconAddress();
176
- }
177
-
178
- /**
179
- * Calculates the beacon Taproot multisig address for the cohort using participant keys.
180
- * @returns {string} The Taproot address for the cohort.
181
- * @throws {BeaconCoordinatorError} If the Taproot address cannot be calculated.
182
- */
183
- public calulateBeaconAddress(): string {
184
- const keyAggContext = keyAggregate(this.cohortKeys);
185
- const aggPubkey = keyAggExport(keyAggContext);
186
- const payment = payments.p2tr({ internalPubkey: aggPubkey });
187
- if(!payment.hash) {
188
- throw new BeaconCoordinatorError(
189
- 'Failed to calculate Taproot Merkle root',
190
- 'CALCULATE_BEACON_MERKLE_ROOT_ERROR',
191
- {
192
- cohortId : this.id,
193
- cohortKeys : this.cohortKeys,
194
- minParticipants : this.minParticipants
195
- }
196
- );
197
- }
198
- this.trMerkleRoot = payment.hash;
199
- if(!payment.address) {
200
- throw new BeaconCoordinatorError(
201
- 'Failed to calculate Taproot address',
202
- 'CALCULATE_BEACON_ADDRESS_ERROR',
203
- {
204
- cohortId : this.id,
205
- cohortKeys : this.cohortKeys,
206
- minParticipants : this.minParticipants
207
- }
208
- );
209
- }
210
- return payment.address;
211
- }
212
-
213
- /**
214
- * Generates a CohortReadyMessage to be sent to participants when the cohort is set.
215
- * @param {string} to The DID of the participant to whom the message is sent.
216
- * @param {string} from The DID of the coordinator sending the message.
217
- * @returns {BeaconCohortReadyMessage} The CohortReadyMessage containing the cohort details.
218
- */
219
- public getCohortReadyMessage(to: string, from: string): BeaconCohortReadyMessage {
220
- if(this.status !== COHORT_STATUS.COHORT_SET_STATUS) {
221
- throw new BeaconCoordinatorError('Cohort status not "COHORT_SET".');
222
- }
223
- return new BeaconCohortReadyMessage({
224
- to,
225
- from,
226
- cohortId : this.id,
227
- beaconAddress : this.beaconAddress,
228
- cohortKeys : this.cohortKeys,
229
- });
230
- }
231
-
232
- /**
233
- * Adds a signature request to the pending requests for the cohort.
234
- * @param {BeaconCohortRequestSignatureMessage} message The signature request message to add.
235
- * @throws {Error} If a signature request from the same participant already exists.
236
- */
237
- public addSignatureRequest(message: BeaconCohortRequestSignatureMessage): void {
238
- if(!this.validateSignatureRequest(message)) {
239
- throw new BeaconCoordinatorError(`No signature request from ${message.from} in cohort ${this.id}.`);
240
- }
241
-
242
- if(!message.body?.data) {
243
- throw new BeaconCoordinatorError(`No signature data in request from ${message.from} in cohort ${this.id}.`);
244
- }
245
-
246
- this.pendingSignatureRequests[message.from] = message.body.data;
247
- }
248
-
249
- /**
250
- * Validates a signature request message to ensure it is from a participant in the cohort.
251
- * @param {BeaconCohortRequestSignatureMessage} message The signature request message to validate.
252
- * @returns {boolean} True if the message is valid, false otherwise.
253
- */
254
- public validateSignatureRequest(message: BeaconCohortRequestSignatureMessage): boolean {
255
- const cohortId = message.body?.cohortId;
256
- if(cohortId !== this.id) {
257
- console.info(`Signature request for wrong cohort: ${cohortId}.`);
258
- return false;
259
- }
260
-
261
- if(!this.participants.includes(message.from)) {
262
- console.info(`Participant ${message.from} not in cohort ${this.id}.`);
263
- return false;
264
- }
265
-
266
- return true;
267
- }
268
-
269
- /**
270
- * Starts a signing session for the cohort.
271
- * @returns {BeaconCohortSigningSession} The request signature message for the signing session.
272
- */
273
- public startSigningSession(): BeaconCohortSigningSession {
274
- console.debug(`Starting signing session for cohort ${this.id} with status ${this.status}`);
275
- if(this.status !== COHORT_STATUS.COHORT_SET_STATUS) {
276
- throw new BeaconCoordinatorError(`Cohort ${this.id} is not set.`);
277
- }
278
- // const smtRootBytes = new Uint8Array(32).map(() => Math.floor(Math.random() * 256));
279
- const cohort = new AggregateBeaconCohort(this);
280
- return new BeaconCohortSigningSession({
281
- cohort,
282
- pendingTx : new Transaction(),
283
- processedRequests : this.pendingSignatureRequests,
284
- });
285
- }
286
-
287
- /**
288
- * Converts the cohort instance to a JSON object representation.
289
- * @returns {BeaconCohort} The JSON object representation of the cohort.
290
- */
291
- public toJSON(): BeaconCohort {
292
- return {
293
- id : this.id,
294
- coordinatorDid : this.coordinatorDid,
295
- minParticipants : this.minParticipants,
296
- status : this.status,
297
- network : this.network,
298
- pendingSignatureRequests : this.pendingSignatureRequests,
299
- participants : this.participants,
300
- cohortKeys : this.cohortKeys,
301
- trMerkleRoot : this.trMerkleRoot,
302
- beaconAddress : this.beaconAddress,
303
- };
304
- }
305
- }
@@ -1,12 +0,0 @@
1
- export const BEACON_COHORT_MESSAGE_PREFIX = 'https://btcr2.dev';
2
-
3
- export const BEACON_COHORT_ADVERT = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/keygen/beacon/cohort_advert`;
4
- export const BEACON_COHORT_OPT_IN = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/keygen/beacon/cohort_opt_in`;
5
- export const BEACON_COHORT_OPT_IN_ACCEPT = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/keygen/beacon/cohort_opt_in_accept`;
6
- export const BEACON_COHORT_READY = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/keygen/beacon/cohort_ready`;
7
-
8
- export const BEACON_COHORT_REQUEST_SIGNATURE = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_request_signature`;
9
- export const BEACON_COHORT_AUTHORIZATION_REQUEST = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_authorization_request`;
10
- export const BEACON_COHORT_NONCE_CONTRIBUTION = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_nonce_contribution`;
11
- export const BEACON_COHORT_AGGREGATED_NONCE = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_aggregated_nonce`;
12
- export const BEACON_COHORT_SIGNATURE_AUTHORIZATION = `${BEACON_COHORT_MESSAGE_PREFIX}/musig2/sign/beacon/cohort_signature_authorization`;
@@ -1,143 +0,0 @@
1
- import {
2
- BEACON_COHORT_ADVERT,
3
- BEACON_COHORT_AGGREGATED_NONCE,
4
- BEACON_COHORT_AUTHORIZATION_REQUEST,
5
- BEACON_COHORT_NONCE_CONTRIBUTION,
6
- BEACON_COHORT_OPT_IN,
7
- BEACON_COHORT_OPT_IN_ACCEPT,
8
- BEACON_COHORT_READY,
9
- BEACON_COHORT_REQUEST_SIGNATURE,
10
- BEACON_COHORT_SIGNATURE_AUTHORIZATION
11
- } from './constants.js';
12
- import type { CohortAdvertMessage } from './keygen/cohort-advert.js';
13
- import type { CohortReadyMessage } from './keygen/cohort-ready.js';
14
- import type { CohortOptInAcceptMessage } from './keygen/opt-in-accept.js';
15
- import type { CohortOptInMessage } from './keygen/opt-in.js';
16
- import type { CohortSubscribeMessage } from './keygen/subscribe.js';
17
- import type { CohortAggregatedNonceMessage } from './sign/aggregated-nonce.js';
18
- import type { CohortAuthorizationRequestMessage } from './sign/authorization-request.js';
19
- import type { CohortNonceContributionMessage } from './sign/nonce-contribution.js';
20
- import type { CohortRequestSignatureMessage } from './sign/request-signature.js';
21
- import type { CohortSignatureAuthorizationMessage } from './sign/signature-authorization.js';
22
-
23
- export type KeyGenMessageType =
24
- | CohortAdvertMessage
25
- | CohortReadyMessage
26
- | CohortOptInMessage
27
- | CohortOptInAcceptMessage
28
- | CohortSubscribeMessage;
29
-
30
- export type SignMessageType =
31
- | CohortAggregatedNonceMessage
32
- | CohortAuthorizationRequestMessage
33
- | CohortNonceContributionMessage
34
- | CohortRequestSignatureMessage
35
- | CohortSignatureAuthorizationMessage;
36
-
37
- export type AggregateBeaconMessageType = KeyGenMessageType | SignMessageType;
38
-
39
- /**
40
- * AggregateBeaconMessage is a utility class that provides constants and type checks
41
- * for various message types used in the aggregate beacon communication protocol.
42
- * It includes methods to validate message types and retrieve message types from objects.
43
- * @class AggregateBeaconMessage
44
- * @type {AggregateBeaconMessageType}
45
- */
46
- export class AggregateBeaconMessage {
47
- static BEACON_COHORT_ADVERT = BEACON_COHORT_ADVERT;
48
- static BEACON_COHORT_OPT_IN = BEACON_COHORT_OPT_IN;
49
- static BEACON_COHORT_READY = BEACON_COHORT_READY;
50
- static BEACON_COHORT_OPT_IN_ACCEPT = BEACON_COHORT_OPT_IN_ACCEPT;
51
-
52
- static BEACON_COHORT_KEY_GEN_MESSAGES: Map<string, string> = new Map([
53
- ['BEACON_COHORT_ADVERT', 'BEACON_COHORT_ADVERT'],
54
- ['BEACON_COHORT_OPT_IN', 'BEACON_COHORT_OPT_IN'],
55
- ['BEACON_COHORT_READY', 'BEACON_COHORT_READY'],
56
- ['BEACON_COHORT_OPT_IN_ACCEPT', 'BEACON_COHORT_OPT_IN_ACCEPT'],
57
- ]);
58
-
59
- static BEACON_COHORT_REQUEST_SIGNATURE = BEACON_COHORT_REQUEST_SIGNATURE;
60
- static BEACON_COHORT_AUTHORIZATION_REQUEST = BEACON_COHORT_AUTHORIZATION_REQUEST;
61
- static BEACON_COHORT_NONCE_CONTRIBUTION = BEACON_COHORT_NONCE_CONTRIBUTION;
62
- static BEACON_COHORT_AGGREGATED_NONCE = BEACON_COHORT_AGGREGATED_NONCE;
63
- static BEACON_COHORT_SIGNATURE_AUTHORIZATION = BEACON_COHORT_SIGNATURE_AUTHORIZATION;
64
-
65
- static BEACON_COHORT_SIGN_MESSAGES: Map<string, string> = new Map([
66
- ['BEACON_COHORT_REQUEST_SIGNATURE', 'BEACON_COHORT_REQUEST_SIGNATURE'],
67
- ['BEACON_COHORT_AUTHORIZATION_REQUEST', 'BEACON_COHORT_AUTHORIZATION_REQUEST'],
68
- ['BEACON_COHORT_NONCE_CONTRIBUTION', 'BEACON_COHORT_NONCE_CONTRIBUTION'],
69
- ['BEACON_COHORT_AGGREGATED_NONCE', 'BEACON_COHORT_AGGREGATED_NONCE'],
70
- ['BEACON_COHORT_SIGNATURE_AUTHORIZATION', 'BEACON_COHORT_SIGNATURE_AUTHORIZATION'],
71
- ]);
72
-
73
- static ALL_MESSAGES: string[] = [
74
- BEACON_COHORT_ADVERT,
75
- BEACON_COHORT_OPT_IN,
76
- BEACON_COHORT_READY,
77
- BEACON_COHORT_OPT_IN_ACCEPT,
78
- BEACON_COHORT_REQUEST_SIGNATURE,
79
- BEACON_COHORT_AUTHORIZATION_REQUEST,
80
- BEACON_COHORT_NONCE_CONTRIBUTION,
81
- BEACON_COHORT_AGGREGATED_NONCE,
82
- BEACON_COHORT_SIGNATURE_AUTHORIZATION
83
- ];
84
-
85
- /**
86
- * Checks if the name provided is a valid message name.
87
- * @param {string} type - The type of the message.
88
- * @returns
89
- */
90
- static isValidType(type: string): boolean {
91
- return this.BEACON_COHORT_KEY_GEN_MESSAGES.has(type) || this.BEACON_COHORT_SIGN_MESSAGES.has(type);
92
- }
93
-
94
- /**
95
- * Get the message value based on the type.
96
- * @param {string} type - The type (or name) of the message.
97
- * @returns {string | undefined} - The corresponding type value.
98
- */
99
- static getMessageValueByType(type: string): string | undefined {
100
- if(!this.isValidType(type)) {
101
- return undefined;
102
- }
103
- return this.BEACON_COHORT_KEY_GEN_MESSAGES.get(type) || this.BEACON_COHORT_SIGN_MESSAGES.get(type);
104
- }
105
-
106
- /**
107
- * Checks if the provided type is a valid AggregateBeaconMessageType.
108
- * @param {string} type - The message type to check.
109
- * @returns {boolean} - Returns true if the type is valid, otherwise false.
110
- */
111
- static isValidValue(type: string): boolean {
112
- return this.ALL_MESSAGES.includes(type);
113
- }
114
-
115
- /**
116
- * Checks if the provided type is a valid KeyGenMessageType.
117
- * @param {string} value - The message type to check.
118
- * @returns {boolean} - Returns true if the type is a key generation message type, otherwise false.
119
- */
120
- static isKeyGenMessageValue(value: string): boolean {
121
- return this.isValidValue(value) && [
122
- BEACON_COHORT_ADVERT,
123
- BEACON_COHORT_READY,
124
- BEACON_COHORT_OPT_IN,
125
- BEACON_COHORT_OPT_IN_ACCEPT,
126
- ].includes(value);
127
- }
128
-
129
- /**
130
- * Checks if the provided type is a valid SignMessageType.
131
- * @param {string} value - The message type to check.
132
- * @returns {boolean} - Returns true if the type is a sign message type, otherwise false.
133
- */
134
- static isSignMessageValue(value: string): boolean {
135
- return this.isValidValue(value) && [
136
- BEACON_COHORT_AGGREGATED_NONCE,
137
- BEACON_COHORT_AUTHORIZATION_REQUEST,
138
- BEACON_COHORT_NONCE_CONTRIBUTION,
139
- BEACON_COHORT_REQUEST_SIGNATURE,
140
- BEACON_COHORT_SIGNATURE_AUTHORIZATION
141
- ].includes(value);
142
- }
143
- }
@@ -1,44 +0,0 @@
1
- import type { Maybe } from '@did-btcr2/common';
2
- import { JSONUtils } from '@did-btcr2/common';
3
- import { BaseMessage } from '../base.js';
4
- import { BEACON_COHORT_ADVERT } from '../constants.js';
5
-
6
- export interface CohortAdvertMessage {
7
- type?: typeof BEACON_COHORT_ADVERT;
8
- id?: string;
9
- from: string;
10
- cohortId: string;
11
- cohortSize: number;
12
- beaconType: string;
13
- network: string;
14
- }
15
-
16
- /**
17
- * Represents a message advertising a cohort to potential participants.
18
- * @class BeaconCohortAdvertMessage
19
- * @extends BaseMessage
20
- * @type {BeaconCohortAdvertMessage}
21
- */
22
- export class BeaconCohortAdvertMessage extends BaseMessage {
23
- public id: string;
24
-
25
- constructor({ from, id, cohortId, cohortSize, beaconType, network }: CohortAdvertMessage) {
26
- const body = { cohortId, cohortSize, beaconType, network };
27
- const type = BEACON_COHORT_ADVERT;
28
- super({ from, body, type });
29
- this.id = id || `${type}/${cohortId}`;
30
- }
31
-
32
- /**
33
- * Initializes a BeaconCohortAdvertMessage from a possible CohortAdvertMessage object.
34
- * @param {CohortAdvertMessage} data The CohortAdvertMessage object to initialize the BeaconCohortAdvertMessage.
35
- * @returns {BeaconCohortAdvertMessage} The new BeaconCohortAdvertMessage.
36
- */
37
- public static fromJSON(data: Maybe<CohortAdvertMessage>): BeaconCohortAdvertMessage {
38
- const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
39
- if (message.type !== BEACON_COHORT_ADVERT){
40
- throw new Error(`Invalid type: ${message.type}`);
41
- }
42
- return new BeaconCohortAdvertMessage(message);
43
- }
44
- }
@@ -1,40 +0,0 @@
1
- import type { Maybe } from '@did-btcr2/common';
2
- import { JSONUtils } from '@did-btcr2/common';
3
- import { BaseMessage } from '../base.js';
4
- import { BEACON_COHORT_READY } from '../constants.js';
5
-
6
- export interface CohortReadyMessage {
7
- type?: string;
8
- to: string;
9
- from: string;
10
- cohortId: string;
11
- beaconAddress: string;
12
- cohortKeys: Array<Uint8Array>;
13
- }
14
-
15
- /**
16
- * Represents a message indicating that a cohort has met the required conditions.
17
- * @class BeaconCohortReadyMessage
18
- * @extends BaseMessage
19
- * @type {BeaconCohortReadyMessage}
20
- */
21
- export class BeaconCohortReadyMessage extends BaseMessage {
22
- constructor({ from, to, cohortId, beaconAddress, cohortKeys }: CohortReadyMessage) {
23
- const body = { cohortId, beaconAddress, cohortKeys };
24
- const type = BEACON_COHORT_READY;
25
- super({ from, to, body, type });
26
- }
27
-
28
- /**
29
- * Initializes an BeaconCohortReadyMessage from a given OptIn object.
30
- * @param {CohortReadyMessage} data The CohortReadyMessage object to initialize the BeaconCohortReadyMessage.
31
- * @returns {BeaconCohortReadyMessage} The new BeaconCohortReadyMessage.
32
- */
33
- public static fromJSON(data: Maybe<CohortReadyMessage>): BeaconCohortReadyMessage {
34
- const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
35
- if (message.type !== BEACON_COHORT_READY) {
36
- throw new Error(`Invalid type: ${message.type}`);
37
- }
38
- return new BeaconCohortReadyMessage(message);
39
- }
40
- }
@@ -1,35 +0,0 @@
1
- import type { Maybe } from '@did-btcr2/common';
2
- import { JSONUtils } from '@did-btcr2/common';
3
- import { BaseMessage } from '../base.js';
4
- import { BEACON_COHORT_OPT_IN_ACCEPT } from '../constants.js';
5
-
6
- export interface CohortOptInAcceptMessage {
7
- type?: typeof BEACON_COHORT_OPT_IN_ACCEPT;
8
- to: string;
9
- from: string;
10
- }
11
-
12
- /**
13
- * Represents a message for a coordinator accepting a participant subscribe to a cohort.
14
- * @class BeaconCohortOptInAcceptMessage
15
- * @extends BaseMessage
16
- * @type {BeaconCohortOptInAcceptMessage}
17
- */
18
- export class BeaconCohortOptInAcceptMessage extends BaseMessage {
19
- constructor({ to, from }: CohortOptInAcceptMessage) {
20
- super({ to, from, type: BEACON_COHORT_OPT_IN_ACCEPT });
21
- }
22
-
23
- /**
24
- * Initializes a BeaconCohortOptInAcceptMessage from a possible CohortOptInAcceptMessage object.
25
- * @param {CohortOptInAcceptMessage} data The CohortOptInAcceptMessage object to initialize the BeaconCohortOptInAcceptMessage.
26
- * @returns {BeaconCohortOptInAcceptMessage} The new BeaconCohortOptInAcceptMessage.
27
- */
28
- public static fromJSON(data: Maybe<CohortOptInAcceptMessage>): BeaconCohortOptInAcceptMessage {
29
- const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
30
- if (message.type != BEACON_COHORT_OPT_IN_ACCEPT) {
31
- throw new Error(`Invalid type: ${message.type}`);
32
- }
33
- return new BeaconCohortOptInAcceptMessage(message);
34
- }
35
- }
@@ -1,34 +0,0 @@
1
- import type { Maybe } from '@did-btcr2/common';
2
- import { JSONUtils } from '@did-btcr2/common';
3
- import { BaseMessage } from '../base.js';
4
- import { BEACON_COHORT_OPT_IN } from '../constants.js';
5
-
6
- export interface CohortOptInMessage {
7
- type?: typeof BEACON_COHORT_OPT_IN;
8
- to: string;
9
- from: string;
10
- cohortId: string;
11
- participantPk: Uint8Array;
12
- }
13
-
14
- export class BeaconCohortOptInMessage extends BaseMessage {
15
-
16
- constructor({ from, to, cohortId, participantPk }: CohortOptInMessage) {
17
- const body = { cohortId, participantPk };
18
- const type = BEACON_COHORT_OPT_IN;
19
- super({ from, to, body, type });
20
- }
21
-
22
- /**
23
- * Initializes a BeaconCohortOptInMessage from a possible CohortOptInMessage object.
24
- * @param {CohortOptInMessage} data The CohortOptInMessage object to initialize the BeaconCohortOptInMessage.
25
- * @returns {BeaconCohortOptInMessage} The new BeaconCohortOptInMessage.
26
- */
27
- public static fromJSON(data: Maybe<CohortOptInMessage>): BeaconCohortOptInMessage {
28
- const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
29
- if (message.type != BEACON_COHORT_OPT_IN) {
30
- throw new Error(`Invalid type: ${message.type}`);
31
- }
32
- return new BeaconCohortOptInMessage(message);
33
- }
34
- }
@@ -1,36 +0,0 @@
1
- import type { Maybe } from '@did-btcr2/common';
2
- import { JSONUtils } from '@did-btcr2/common';
3
- import { BaseMessage } from '../base.js';
4
- import { BEACON_COHORT_OPT_IN_ACCEPT } from '../constants.js';
5
-
6
- export interface CohortSubscribeMessage {
7
- type?: typeof BEACON_COHORT_OPT_IN_ACCEPT;
8
- to: string;
9
- from: string;
10
- }
11
-
12
- /**
13
- * Represents a message for subscribing to a cohort.
14
- * This message is sent by a coordinator to a participant to indicate acceptance in the cohort.
15
- * @class BeaconCohortSubscribeMessage
16
- * @extends BaseMessage
17
- * @type {BeaconCohortSubscribeMessage}
18
- */
19
- export class BeaconCohortSubscribeMessage extends BaseMessage {
20
- constructor({ to, from }: CohortSubscribeMessage) {
21
- super({ to, from, type: BEACON_COHORT_OPT_IN_ACCEPT });
22
- }
23
-
24
- /**
25
- * Initializes a BeaconCohortSubscribeMessage from a possible CohortSubscribeMessage object.
26
- * @param {CohortSubscribeMessage} data The Subscribe object to initialize the SubscribeMessage.
27
- * @returns {BeaconCohortSubscribeMessage} The serialized SubscribeMessage.
28
- */
29
- public static fromJSON(data: Maybe<CohortSubscribeMessage>): BeaconCohortSubscribeMessage {
30
- const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
31
- if (message.type != BEACON_COHORT_OPT_IN_ACCEPT) {
32
- throw new Error(`Invalid type: ${message.type}`);
33
- }
34
- return new BeaconCohortSubscribeMessage(message);
35
- }
36
- }