@did-btcr2/method 0.18.1 → 0.20.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 (291) hide show
  1. package/dist/browser.js +4917 -6487
  2. package/dist/browser.mjs +4917 -6487
  3. package/dist/cjs/core/beacon/aggregation/cohort/index.js +3 -3
  4. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -1
  5. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +1 -9
  6. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
  7. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +2 -1
  8. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
  9. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +2 -1
  10. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
  11. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +2 -1
  12. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
  13. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +2 -1
  14. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
  15. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +2 -1
  16. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
  17. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +2 -1
  18. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
  19. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +2 -1
  20. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
  21. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +2 -1
  22. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
  23. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +2 -1
  24. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
  25. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +2 -1
  26. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
  27. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +36 -18
  28. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  29. package/dist/cjs/core/beacon/aggregation/coordinator.js +14 -14
  30. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
  31. package/dist/cjs/core/beacon/aggregation/participant.js +4 -3
  32. package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
  33. package/dist/cjs/core/beacon/aggregation/session/index.js +1 -1
  34. package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
  35. package/dist/cjs/core/beacon/beacon.js +25 -0
  36. package/dist/cjs/core/beacon/beacon.js.map +1 -0
  37. package/dist/cjs/core/beacon/cas-beacon.js +39 -0
  38. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -0
  39. package/dist/cjs/core/beacon/error.js +4 -4
  40. package/dist/cjs/core/beacon/error.js.map +1 -1
  41. package/dist/cjs/core/beacon/factory.js +10 -11
  42. package/dist/cjs/core/beacon/factory.js.map +1 -1
  43. package/dist/cjs/core/beacon/interfaces.js +2 -0
  44. package/dist/cjs/core/beacon/interfaces.js.map +1 -0
  45. package/dist/cjs/core/beacon/signal-discovery.js +183 -0
  46. package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
  47. package/dist/cjs/core/beacon/singleton.js +75 -178
  48. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  49. package/dist/cjs/core/beacon/smt-beacon.js +39 -0
  50. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -0
  51. package/dist/cjs/core/beacon/utils.js +71 -114
  52. package/dist/cjs/core/beacon/utils.js.map +1 -1
  53. package/dist/cjs/core/identifier.js +18 -21
  54. package/dist/cjs/core/identifier.js.map +1 -1
  55. package/dist/cjs/core/interfaces.js +2 -0
  56. package/dist/cjs/core/interfaces.js.map +1 -0
  57. package/dist/cjs/core/resolve.js +321 -0
  58. package/dist/cjs/core/resolve.js.map +1 -0
  59. package/dist/cjs/{utils → core}/types.js.map +1 -1
  60. package/dist/cjs/core/update.js +113 -0
  61. package/dist/cjs/core/update.js.map +1 -0
  62. package/dist/cjs/did-btcr2.js +168 -129
  63. package/dist/cjs/did-btcr2.js.map +1 -1
  64. package/dist/cjs/index.js +17 -16
  65. package/dist/cjs/index.js.map +1 -1
  66. package/dist/cjs/utils/appendix.js +16 -33
  67. package/dist/cjs/utils/appendix.js.map +1 -1
  68. package/dist/cjs/utils/did-document-builder.js +5 -0
  69. package/dist/cjs/utils/did-document-builder.js.map +1 -1
  70. package/dist/cjs/utils/did-document.js +62 -72
  71. package/dist/cjs/utils/did-document.js.map +1 -1
  72. package/dist/cjs/utils/general.js +1 -1
  73. package/dist/cjs/utils/general.js.map +1 -1
  74. package/dist/esm/core/beacon/aggregation/cohort/index.js +3 -3
  75. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
  76. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js +1 -9
  77. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
  78. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +2 -1
  79. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
  80. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +2 -1
  81. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
  82. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +2 -1
  83. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
  84. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +2 -1
  85. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
  86. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +2 -1
  87. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
  88. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +2 -1
  89. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
  90. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +2 -1
  91. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
  92. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +2 -1
  93. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
  94. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +2 -1
  95. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
  96. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +2 -1
  97. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
  98. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +36 -18
  99. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  100. package/dist/esm/core/beacon/aggregation/coordinator.js +14 -14
  101. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  102. package/dist/esm/core/beacon/aggregation/participant.js +4 -3
  103. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  104. package/dist/esm/core/beacon/aggregation/session/index.js +1 -1
  105. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
  106. package/dist/esm/core/beacon/beacon.js +25 -0
  107. package/dist/esm/core/beacon/beacon.js.map +1 -0
  108. package/dist/esm/core/beacon/cas-beacon.js +39 -0
  109. package/dist/esm/core/beacon/cas-beacon.js.map +1 -0
  110. package/dist/esm/core/beacon/error.js +4 -4
  111. package/dist/esm/core/beacon/error.js.map +1 -1
  112. package/dist/esm/core/beacon/factory.js +10 -11
  113. package/dist/esm/core/beacon/factory.js.map +1 -1
  114. package/dist/esm/core/beacon/interfaces.js +2 -0
  115. package/dist/esm/core/beacon/interfaces.js.map +1 -0
  116. package/dist/esm/core/beacon/signal-discovery.js +183 -0
  117. package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
  118. package/dist/esm/core/beacon/singleton.js +75 -178
  119. package/dist/esm/core/beacon/singleton.js.map +1 -1
  120. package/dist/esm/core/beacon/smt-beacon.js +39 -0
  121. package/dist/esm/core/beacon/smt-beacon.js.map +1 -0
  122. package/dist/esm/core/beacon/utils.js +71 -114
  123. package/dist/esm/core/beacon/utils.js.map +1 -1
  124. package/dist/esm/core/identifier.js +18 -21
  125. package/dist/esm/core/identifier.js.map +1 -1
  126. package/dist/esm/core/interfaces.js +2 -0
  127. package/dist/esm/core/interfaces.js.map +1 -0
  128. package/dist/esm/core/resolve.js +321 -0
  129. package/dist/esm/core/resolve.js.map +1 -0
  130. package/dist/esm/{utils → core}/types.js.map +1 -1
  131. package/dist/esm/core/update.js +113 -0
  132. package/dist/esm/core/update.js.map +1 -0
  133. package/dist/esm/did-btcr2.js +168 -129
  134. package/dist/esm/did-btcr2.js.map +1 -1
  135. package/dist/esm/index.js +17 -16
  136. package/dist/esm/index.js.map +1 -1
  137. package/dist/esm/utils/appendix.js +16 -33
  138. package/dist/esm/utils/appendix.js.map +1 -1
  139. package/dist/esm/utils/did-document-builder.js +5 -0
  140. package/dist/esm/utils/did-document-builder.js.map +1 -1
  141. package/dist/esm/utils/did-document.js +62 -72
  142. package/dist/esm/utils/did-document.js.map +1 -1
  143. package/dist/esm/utils/general.js +1 -1
  144. package/dist/esm/utils/general.js.map +1 -1
  145. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -1
  146. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +0 -7
  147. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -1
  148. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -1
  149. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -1
  150. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -1
  151. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -1
  152. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -1
  153. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -1
  154. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -1
  155. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -1
  156. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -1
  157. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -1
  158. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +13 -5
  159. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
  160. package/dist/types/core/beacon/aggregation/coordinator.d.ts +17 -29
  161. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  162. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  163. package/dist/types/core/beacon/beacon.d.ts +44 -0
  164. package/dist/types/core/beacon/beacon.d.ts.map +1 -0
  165. package/dist/types/core/beacon/cas-beacon.d.ts +36 -0
  166. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -0
  167. package/dist/types/core/beacon/error.d.ts +2 -2
  168. package/dist/types/core/beacon/error.d.ts.map +1 -1
  169. package/dist/types/core/beacon/factory.d.ts +4 -5
  170. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  171. package/dist/types/core/beacon/interfaces.d.ts +59 -0
  172. package/dist/types/core/beacon/interfaces.d.ts.map +1 -0
  173. package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
  174. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
  175. package/dist/types/core/beacon/singleton.d.ts +20 -76
  176. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  177. package/dist/types/core/beacon/smt-beacon.d.ts +36 -0
  178. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -0
  179. package/dist/types/core/beacon/utils.d.ts +19 -97
  180. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  181. package/dist/types/core/identifier.d.ts.map +1 -1
  182. package/dist/types/core/interfaces.d.ts +87 -0
  183. package/dist/types/core/interfaces.d.ts.map +1 -0
  184. package/dist/types/core/resolve.d.ts +89 -0
  185. package/dist/types/core/resolve.d.ts.map +1 -0
  186. package/dist/types/core/types.d.ts +84 -0
  187. package/dist/types/core/types.d.ts.map +1 -0
  188. package/dist/types/core/update.d.ts +51 -0
  189. package/dist/types/core/update.d.ts.map +1 -0
  190. package/dist/types/did-btcr2.d.ts +70 -89
  191. package/dist/types/did-btcr2.d.ts.map +1 -1
  192. package/dist/types/index.d.ts +17 -16
  193. package/dist/types/index.d.ts.map +1 -1
  194. package/dist/types/utils/appendix.d.ts +5 -10
  195. package/dist/types/utils/appendix.d.ts.map +1 -1
  196. package/dist/types/utils/did-document-builder.d.ts +6 -1
  197. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  198. package/dist/types/utils/did-document.d.ts +46 -42
  199. package/dist/types/utils/did-document.d.ts.map +1 -1
  200. package/package.json +6 -6
  201. package/src/core/beacon/aggregation/cohort/index.ts +3 -3
  202. package/src/core/beacon/aggregation/cohort/messages/base.ts +1 -12
  203. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +2 -2
  204. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +2 -2
  205. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +2 -2
  206. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +2 -2
  207. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +2 -2
  208. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +2 -2
  209. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +2 -2
  210. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +2 -2
  211. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +2 -2
  212. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +2 -2
  213. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +43 -21
  214. package/src/core/beacon/aggregation/coordinator.ts +41 -29
  215. package/src/core/beacon/aggregation/participant.ts +4 -3
  216. package/src/core/beacon/aggregation/session/index.ts +1 -1
  217. package/src/core/beacon/beacon.ts +58 -0
  218. package/src/core/beacon/cas-beacon.ts +53 -0
  219. package/src/core/beacon/error.ts +5 -6
  220. package/src/core/beacon/factory.ts +12 -16
  221. package/src/core/beacon/interfaces.ts +67 -0
  222. package/src/core/beacon/signal-discovery.ts +237 -0
  223. package/src/core/beacon/singleton.ts +107 -197
  224. package/src/core/beacon/smt-beacon.ts +53 -0
  225. package/src/core/beacon/utils.ts +95 -182
  226. package/src/core/identifier.ts +21 -24
  227. package/src/core/interfaces.ts +93 -0
  228. package/src/core/resolve.ts +463 -0
  229. package/src/core/types.ts +95 -0
  230. package/src/core/update.ts +154 -0
  231. package/src/did-btcr2.ts +255 -159
  232. package/src/index.ts +19 -22
  233. package/src/utils/appendix.ts +26 -44
  234. package/src/utils/did-document-builder.ts +6 -1
  235. package/src/utils/did-document.ts +105 -113
  236. package/src/utils/general.ts +1 -1
  237. package/dist/cjs/core/beacon/cid-aggregate.js +0 -116
  238. package/dist/cjs/core/beacon/cid-aggregate.js.map +0 -1
  239. package/dist/cjs/core/beacon/smt-aggregate.js +0 -126
  240. package/dist/cjs/core/beacon/smt-aggregate.js.map +0 -1
  241. package/dist/cjs/core/crud/deactivate.js +0 -14
  242. package/dist/cjs/core/crud/deactivate.js.map +0 -1
  243. package/dist/cjs/core/crud/read.js +0 -679
  244. package/dist/cjs/core/crud/read.js.map +0 -1
  245. package/dist/cjs/core/crud/update.js +0 -194
  246. package/dist/cjs/core/crud/update.js.map +0 -1
  247. package/dist/cjs/interfaces/beacon.js +0 -41
  248. package/dist/cjs/interfaces/beacon.js.map +0 -1
  249. package/dist/cjs/interfaces/crud.js +0 -2
  250. package/dist/cjs/interfaces/crud.js.map +0 -1
  251. package/dist/esm/core/beacon/cid-aggregate.js +0 -116
  252. package/dist/esm/core/beacon/cid-aggregate.js.map +0 -1
  253. package/dist/esm/core/beacon/smt-aggregate.js +0 -126
  254. package/dist/esm/core/beacon/smt-aggregate.js.map +0 -1
  255. package/dist/esm/core/crud/deactivate.js +0 -14
  256. package/dist/esm/core/crud/deactivate.js.map +0 -1
  257. package/dist/esm/core/crud/read.js +0 -679
  258. package/dist/esm/core/crud/read.js.map +0 -1
  259. package/dist/esm/core/crud/update.js +0 -194
  260. package/dist/esm/core/crud/update.js.map +0 -1
  261. package/dist/esm/interfaces/beacon.js +0 -41
  262. package/dist/esm/interfaces/beacon.js.map +0 -1
  263. package/dist/esm/interfaces/crud.js +0 -2
  264. package/dist/esm/interfaces/crud.js.map +0 -1
  265. package/dist/types/core/beacon/cid-aggregate.d.ts +0 -102
  266. package/dist/types/core/beacon/cid-aggregate.d.ts.map +0 -1
  267. package/dist/types/core/beacon/smt-aggregate.d.ts +0 -111
  268. package/dist/types/core/beacon/smt-aggregate.d.ts.map +0 -1
  269. package/dist/types/core/crud/deactivate.d.ts +0 -13
  270. package/dist/types/core/crud/deactivate.d.ts.map +0 -1
  271. package/dist/types/core/crud/read.d.ts +0 -334
  272. package/dist/types/core/crud/read.d.ts.map +0 -1
  273. package/dist/types/core/crud/update.d.ts +0 -93
  274. package/dist/types/core/crud/update.d.ts.map +0 -1
  275. package/dist/types/interfaces/beacon.d.ts +0 -116
  276. package/dist/types/interfaces/beacon.d.ts.map +0 -1
  277. package/dist/types/interfaces/crud.d.ts +0 -32
  278. package/dist/types/interfaces/crud.d.ts.map +0 -1
  279. package/dist/types/utils/types.d.ts +0 -38
  280. package/dist/types/utils/types.d.ts.map +0 -1
  281. package/src/canonicalize.d.ts +0 -6
  282. package/src/core/beacon/cid-aggregate.ts +0 -153
  283. package/src/core/beacon/smt-aggregate.ts +0 -135
  284. package/src/core/crud/deactivate.ts +0 -13
  285. package/src/core/crud/read.ts +0 -948
  286. package/src/core/crud/update.ts +0 -292
  287. package/src/interfaces/beacon.ts +0 -137
  288. package/src/interfaces/crud.ts +0 -33
  289. package/src/utils/types.ts +0 -41
  290. /package/dist/cjs/{utils → core}/types.js +0 -0
  291. /package/dist/esm/{utils → core}/types.js +0 -0
@@ -90,7 +90,7 @@ export class AggregateBeaconCohort implements BeaconCohort {
90
90
  public beaconAddress: string = '';
91
91
 
92
92
  /**
93
- * Type of beacon used in the cohort (default is 'SMTAggregateBeacon').
93
+ * Type of beacon used in the cohort (default is 'SMTBeacon').
94
94
  * @type {string}
95
95
  */
96
96
  public beaconType: string;
@@ -110,7 +110,7 @@ export class AggregateBeaconCohort implements BeaconCohort {
110
110
  this.coordinatorDid = coordinatorDid || '';
111
111
  this.status = status as COHORT_STATUS_TYPE || COHORT_STATUS.COHORT_ADVERTISED;
112
112
  this.network = network;
113
- this.beaconType = beaconType || 'SMTAggregateBeacon';
113
+ this.beaconType = beaconType || 'SMTBeacon';
114
114
  }
115
115
 
116
116
  set cohortKeys(keys: Array<Uint8Array>) {
@@ -287,6 +287,6 @@ export class AggregateBeaconCohort implements BeaconCohort {
287
287
  * @returns {BeaconCohort} The JSON object representation of the cohort.
288
288
  */
289
289
  public json(): BeaconCohort {
290
- return Object.json(this) as BeaconCohort;
290
+ return Object.fromEntries(Object.entries(this)) as BeaconCohort;
291
291
  }
292
292
  }
@@ -1,5 +1,3 @@
1
- import { Maybe } from '@did-btcr2/common';
2
-
3
1
  export const MESSAGE_PREFIX = 'https://btcr2.tools/';
4
2
 
5
3
  export type BaseBody = {
@@ -38,20 +36,11 @@ export class BaseMessage {
38
36
  this.body = body;
39
37
  }
40
38
 
41
- /**
42
- * Creates a BaseMessage from a JSON object.
43
- * @param {Maybe<Base>} data The JSON object to initialize the BaseMessage.
44
- * @returns {BaseMessage} The initialized BaseMessage.
45
- */
46
- public static fromJSON(data: Maybe<Base>): BaseMessage {
47
- return new BaseMessage(data);
48
- }
49
-
50
39
  /**
51
40
  * Converts a BaseMessage to a JSON object.
52
41
  * @returns {Base} The JSON representation of the BaseMessage.
53
42
  */
54
43
  public json(): Base {
55
- return Object.json(this) as Base;
44
+ return Object.fromEntries(Object.entries(this)) as Base;
56
45
  }
57
46
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_ADVERT } from '../constants.js';
4
4
 
@@ -34,7 +34,7 @@ export class BeaconCohortAdvertMessage extends BaseMessage {
34
34
  * @returns {BeaconCohortAdvertMessage} The new BeaconCohortAdvertMessage.
35
35
  */
36
36
  public static fromJSON(data: Maybe<CohortAdvertMessage>): BeaconCohortAdvertMessage {
37
- const message = JSON.parse(data);
37
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
38
38
  if (message.type !== BEACON_COHORT_ADVERT){
39
39
  throw new Error(`Invalid type: ${message.type}`);
40
40
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_READY } from '../constants.js';
4
4
 
@@ -30,7 +30,7 @@ export class BeaconCohortReadyMessage extends BaseMessage {
30
30
  * @returns {BeaconCohortReadyMessage} The new BeaconCohortReadyMessage.
31
31
  */
32
32
  public static fromJSON(data: Maybe<CohortReadyMessage>): BeaconCohortReadyMessage {
33
- const message = JSON.parse(data);
33
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
34
34
  if (message.type !== BEACON_COHORT_READY) {
35
35
  throw new Error(`Invalid type: ${message.type}`);
36
36
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_OPT_IN_ACCEPT } from '../constants.js';
4
4
 
@@ -25,7 +25,7 @@ export class BeaconCohortOptInAcceptMessage extends BaseMessage {
25
25
  * @returns {BeaconCohortOptInAcceptMessage} The new BeaconCohortOptInAcceptMessage.
26
26
  */
27
27
  public static fromJSON(data: Maybe<CohortOptInAcceptMessage>): BeaconCohortOptInAcceptMessage {
28
- const message = JSON.parse(data);
28
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
29
29
  if (message.type != BEACON_COHORT_OPT_IN_ACCEPT) {
30
30
  throw new Error(`Invalid type: ${message.type}`);
31
31
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_OPT_IN } from '../constants.js';
4
4
 
@@ -24,7 +24,7 @@ export class BeaconCohortOptInMessage extends BaseMessage {
24
24
  * @returns {BeaconCohortOptInMessage} The new BeaconCohortOptInMessage.
25
25
  */
26
26
  public static fromJSON(data: Maybe<CohortOptInMessage>): BeaconCohortOptInMessage {
27
- const message = JSON.parse(data);
27
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
28
28
  if (message.type != BEACON_COHORT_OPT_IN) {
29
29
  throw new Error(`Invalid type: ${message.type}`);
30
30
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_OPT_IN_ACCEPT } from '../constants.js';
4
4
 
@@ -26,7 +26,7 @@ export class BeaconCohortSubscribeMessage extends BaseMessage {
26
26
  * @returns {BeaconCohortSubscribeMessage} The serialized SubscribeMessage.
27
27
  */
28
28
  public static fromJSON(data: Maybe<CohortSubscribeMessage>): BeaconCohortSubscribeMessage {
29
- const message = JSON.parse(data);
29
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
30
30
  if (message.type != BEACON_COHORT_OPT_IN_ACCEPT) {
31
31
  throw new Error(`Invalid type: ${message.type}`);
32
32
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_AGGREGATED_NONCE } from '../constants.js';
4
4
 
@@ -29,7 +29,7 @@ export class BeaconCohortAggregatedNonceMessage extends BaseMessage {
29
29
  * @returns {BeaconCohortAggregatedNonceMessage} The new BeaconCohortAggregatedNonceMessage.
30
30
  */
31
31
  public static fromJSON(data: Maybe<CohortAggregatedNonceMessage>): BeaconCohortAggregatedNonceMessage {
32
- const message = JSON.parse(data);
32
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
33
33
  if (message.type != BEACON_COHORT_AGGREGATED_NONCE) {
34
34
  throw new Error(`Invalid type: ${message.type}`);
35
35
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_AUTHORIZATION_REQUEST } from '../constants.js';
4
4
 
@@ -30,7 +30,7 @@ export class BeaconCohortAuthorizationRequestMessage extends BaseMessage {
30
30
  * @returns {BeaconCohortAuthorizationRequestMessage} The serialized BeaconCohortAuthorizationRequestMessage.
31
31
  */
32
32
  public static fromJSON(data: Maybe<CohortAuthorizationRequestMessage>): BeaconCohortAuthorizationRequestMessage {
33
- const message = JSON.parse(data);
33
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
34
34
  if (message.type != BEACON_COHORT_AUTHORIZATION_REQUEST) {
35
35
  throw new Error(`Invalid type: ${message.type}`);
36
36
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_NONCE_CONTRIBUTION } from '../constants.js';
4
4
 
@@ -30,7 +30,7 @@ export class BeaconCohortNonceContributionMessage extends BaseMessage {
30
30
  * @returns {BeaconCohortNonceContributionMessage} The new BeaconCohortNonceContributionMessage.
31
31
  */
32
32
  public static fromJSON(data: Maybe<CohortNonceContributionMessage>): BeaconCohortNonceContributionMessage {
33
- const message = JSON.parse(data);
33
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
34
34
  if (message.type != BEACON_COHORT_NONCE_CONTRIBUTION) {
35
35
  throw new Error(`Invalid type: ${message.type}`);
36
36
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_REQUEST_SIGNATURE } from '../constants.js';
4
4
 
@@ -30,7 +30,7 @@ export class BeaconCohortRequestSignatureMessage extends BaseMessage {
30
30
  * @returns {BeaconCohortRequestSignatureMessage} The new BeaconCohortRequestSignatureMessage.
31
31
  */
32
32
  public static fromJSON(data: Maybe<CohortRequestSignatureMessage>): BeaconCohortRequestSignatureMessage {
33
- const message = JSON.parse(data);
33
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
34
34
  if (message.type != BEACON_COHORT_REQUEST_SIGNATURE) {
35
35
  throw new Error(`Invalid type: ${message.type}`);
36
36
  }
@@ -1,4 +1,4 @@
1
- import { Maybe } from '@did-btcr2/common';
1
+ import { JSONUtils, Maybe } from '@did-btcr2/common';
2
2
  import { BaseMessage } from '../base.js';
3
3
  import { BEACON_COHORT_SIGNATURE_AUTHORIZATION } from '../constants.js';
4
4
 
@@ -31,7 +31,7 @@ export class BeaconCohortSignatureAuthorizationMessage extends BaseMessage {
31
31
  * @returns {BeaconCohortSignatureAuthorizationMessage} The serialized BeaconCohortSignatureAuthorizationMessage.
32
32
  */
33
33
  public static fromJSON(data: Maybe<CohortSignatureAuthorizationMessage>): BeaconCohortSignatureAuthorizationMessage {
34
- const message = JSON.parse(data);
34
+ const message = JSONUtils.isParsable(data) ? JSON.parse(data) : data;
35
35
  if (message.type != BEACON_COHORT_SIGNATURE_AUTHORIZATION) {
36
36
  throw new Error(`Invalid type: ${message.type}`);
37
37
  }
@@ -1,3 +1,5 @@
1
+ // TODO: Finish nostr adapter implementation. Rethink patterns used.
2
+
1
3
  import { Did, Maybe } from '@did-btcr2/common';
2
4
  import { CompressedSecp256k1PublicKey, RawSchnorrKeyPair, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
3
5
  import { nonceGen } from '@scure/btc-signer/musig2';
@@ -20,6 +22,7 @@ import { CommunicationAdapterError } from '../error.js';
20
22
  import { CommunicationService, MessageHandler, ServiceAdapter, ServiceAdapterConfig, ServiceAdapterIdentity } from '../service.js';
21
23
 
22
24
  /**
25
+ * TODO: Determine set of default Nostr relays to use.
23
26
  * DEFAULT_NOSTR_RELAYS provides a list of default Nostr relay URLs for communication.
24
27
  * These relays are used to connect to the Nostr network for sending and receiving messages.
25
28
  * @constant {Array<string>} DEFAULT_NOSTR_RELAYS
@@ -49,30 +52,37 @@ export interface NostrAdapterConfig {
49
52
  [key: string]: any;
50
53
  }
51
54
 
55
+ /**
56
+ * NostrAdapter implements the CommunicationService interface for Nostr protocol communication.
57
+ * It provides methods for starting the service, sending messages, and handling incoming events.
58
+ * @class NostrAdapter
59
+ * @type {NostrAdapter}
60
+ * @implements {CommunicationService}
61
+ */
52
62
  export class NostrAdapter implements CommunicationService {
53
63
  /**
54
64
  * The name of the NostrAdapter service.
55
65
  * @type {string}
56
66
  */
57
- public name: string = 'nostr';
67
+ name: string = 'nostr';
58
68
 
59
69
  /**
60
70
  * The configuration for the NostrAdapter.
61
71
  * @type {NostrAdapterConfig}
62
72
  */
63
- public config: NostrAdapterConfig;
73
+ config: NostrAdapterConfig;
64
74
 
65
75
  /**
66
76
  * A map of message handlers for different message types.
67
77
  * @type {Map<string, MessageHandler>}
68
78
  */
69
- private handlers: Map<string, MessageHandler> = new Map();
79
+ #handlers: Map<string, MessageHandler> = new Map();
70
80
 
71
81
  /**
72
82
  * The SimplePool instance for managing Nostr subscriptions.
73
83
  * @type {SimplePool}
74
84
  */
75
- public pool?: SimplePool;
85
+ pool?: SimplePool;
76
86
 
77
87
  /**
78
88
  * Constructs a new NostrAdapter instance with the given configuration.
@@ -101,6 +111,7 @@ export class NostrAdapter implements CommunicationService {
101
111
 
102
112
 
103
113
  /**
114
+ * TODO: Complete this method. Figure out best subscription patterns.
104
115
  * Starts the Nostr communication service by subscribing to relays.
105
116
  * @returns {ServiceAdapter<NostrAdapter>} Returns the NostrAdapter instance for method chaining.
106
117
  */
@@ -123,6 +134,7 @@ export class NostrAdapter implements CommunicationService {
123
134
 
124
135
 
125
136
  /**
137
+ * TODO: Complete this method. Figure out best way to filter incoming nostr events.
126
138
  * Handles incoming Nostr events and dispatches them to the appropriate message handler.
127
139
  * @param {Event} event The Nostr event received from the relay.
128
140
  */
@@ -171,11 +183,12 @@ export class NostrAdapter implements CommunicationService {
171
183
  * @param {MessageHandler} handler The handler function that processes the message.
172
184
  */
173
185
  public registerMessageHandler(messageType: string, handler: MessageHandler): void {
174
- this.handlers.set(messageType, handler);
186
+ this.#handlers.set(messageType, handler);
175
187
  }
176
188
 
177
189
 
178
190
  /**
191
+ * TODO: Clean up and complete this method.
179
192
  * Sends a message to a recipient using the Nostr protocol.
180
193
  * This method is a placeholder and should be implemented with actual Nostr message sending logic.
181
194
  * @param {Maybe<AggregateBeaconMessageType>} message The message to send, typically containing the content and metadata.
@@ -184,13 +197,13 @@ export class NostrAdapter implements CommunicationService {
184
197
  * @returns {Promise<void>} A promise that resolves when the message is sent.
185
198
  */
186
199
  public async sendMessage(message: Maybe<AggregateBeaconMessageType>, from: Did, to?: Did): Promise<void | Promise<string>[]> {
187
- // Check if the sender and recipient DIDs are valid Btc1 identifiers
200
+ // Check if the sender and recipient DIDs are valid identifiers
188
201
  if(
189
202
  [from, to]
190
203
  .filter(did => !!did)
191
204
  .every(did => !Identifier.isValid(did!))
192
205
  ) {
193
- console.error(`Invalid Btc1 identifiers: sender ${from}, recipient ${to}`);
206
+ console.error(`Invalid identifiers: sender ${from}, recipient ${to}`);
194
207
  throw new CommunicationAdapterError(
195
208
  `Invalid identifiers: sender ${from}, recipient ${to}`,
196
209
  'SEND_MESSAGE_ERROR', { adapter: this.name }
@@ -209,20 +222,28 @@ export class NostrAdapter implements CommunicationService {
209
222
  const recipient = new CompressedSecp256k1PublicKey(Identifier.decode(to).genesisBytes);
210
223
  tags.push(['p', Buffer.from(recipient.x).toString('hex')]);
211
224
  }
225
+ const { type } = message as any ?? {};
226
+ if(!type) {
227
+ console.error('Message type is undefined:', message);
228
+ throw new CommunicationAdapterError(
229
+ 'Message type is undefined',
230
+ 'SEND_MESSAGE_ERROR', { adapter: this.name }
231
+ );
232
+ }
212
233
 
213
- if(AggregateBeaconMessage.isKeyGenMessageValue(message.type)) {
214
- switch(message.type) {
234
+ if(AggregateBeaconMessage.isKeyGenMessageValue(type)) {
235
+ switch(type) {
215
236
  case BEACON_COHORT_ADVERT:
216
- console.info('Add tag', ['BEACON_COHORT_ADVERT', message.type]);
237
+ console.info('Add tag', ['BEACON_COHORT_ADVERT', type]);
217
238
  break;
218
239
  case BEACON_COHORT_OPT_IN:
219
- console.info('Add tag', ['BEACON_COHORT_OPT_IN', message.type]);
240
+ console.info('Add tag', ['BEACON_COHORT_OPT_IN', type]);
220
241
  break;
221
242
  case BEACON_COHORT_OPT_IN_ACCEPT:
222
- console.info('Add tag', ['BEACON_COHORT_OPT_IN_ACCEPT', message.type]);
243
+ console.info('Add tag', ['BEACON_COHORT_OPT_IN_ACCEPT', type]);
223
244
  break;
224
245
  case BEACON_COHORT_READY:
225
- console.info('Add tag', ['BEACON_COHORT_READY', message.type]);
246
+ console.info('Add tag', ['BEACON_COHORT_READY', type]);
226
247
  break;
227
248
  }
228
249
  const event = finalizeEvent({
@@ -235,22 +256,22 @@ export class NostrAdapter implements CommunicationService {
235
256
  return this.pool?.publish(this.config.relays, event);
236
257
  }
237
258
 
238
- if(AggregateBeaconMessage.isSignMessageValue(message.type)) {
239
- switch(message.type) {
259
+ if(AggregateBeaconMessage.isSignMessageValue(type)) {
260
+ switch(type) {
240
261
  case BEACON_COHORT_REQUEST_SIGNATURE:
241
- console.info('Add tag', ['BEACON_COHORT_REQUEST_SIGNATURE', message.type]);
262
+ console.info('Add tag', ['BEACON_COHORT_REQUEST_SIGNATURE', type]);
242
263
  break;
243
264
  case BEACON_COHORT_AUTHORIZATION_REQUEST:
244
- console.info('Add tag', ['BEACON_COHORT_AUTHORIZATION_REQUEST', message.type]);
265
+ console.info('Add tag', ['BEACON_COHORT_AUTHORIZATION_REQUEST', type]);
245
266
  break;
246
267
  case BEACON_COHORT_NONCE_CONTRIBUTION:
247
- console.info('Add tag', ['BEACON_COHORT_NONCE_CONTRIBUTION', message.type]);
268
+ console.info('Add tag', ['BEACON_COHORT_NONCE_CONTRIBUTION', type]);
248
269
  break;
249
270
  case BEACON_COHORT_AGGREGATED_NONCE:
250
- console.info('Add tag', ['BEACON_COHORT_AGGREGATED_NONCE', message.type]);
271
+ console.info('Add tag', ['BEACON_COHORT_AGGREGATED_NONCE', type]);
251
272
  break;
252
273
  case BEACON_COHORT_SIGNATURE_AUTHORIZATION:
253
- console.info('Add tag', ['BEACON_COHORT_SIGNATURE_AUTHORIZATION', message.type]);
274
+ console.info('Add tag', ['BEACON_COHORT_SIGNATURE_AUTHORIZATION', type]);
254
275
  break;
255
276
  }
256
277
  const { publicKey, secretKey } = SchnorrKeyPair.generate();
@@ -263,10 +284,11 @@ export class NostrAdapter implements CommunicationService {
263
284
  return this.pool?.publish(this.config.relays, event);
264
285
  }
265
286
 
266
- console.error(`Unsupported message type: ${message.type}`);
287
+ console.error(`Unsupported message type: ${type}`);
267
288
  }
268
289
 
269
290
  /**
291
+ * TODO: Determine if this method is needed.
270
292
  * Generates a Nostr identity using the Secp256k1SecretKey and Identifier classes.
271
293
  * @param {RawSchnorrKeyPair} [keys] Optional keys to use for identity generation.
272
294
  * @returns {ServiceAdapterConfig} The generated Nostr identity configuration.
@@ -23,7 +23,15 @@ import { CommunicationService, Service, ServiceAdapterIdentity } from './communi
23
23
  import { BeaconCohortSigningSession } from './session/index.js';
24
24
  import { SIGNING_SESSION_STATUS } from './session/status.js';
25
25
 
26
- type BeaconCoordinatorParams = {
26
+ /**
27
+ * Parameters for initializing a BeaconCoordinator.
28
+ * @type {BeaconCoordinatorParams}
29
+ * @property {CommunicationService} [protocol] - The communication protocol to be used.
30
+ * @property {string} did - The Decentralized Identifier (DID) for the coordinator.
31
+ * @property {ServiceAdapterIdentity<RawSchnorrKeyPair>} keys - The keys used for cryptographic operations.
32
+ * @property {string} [name] - Optional name for the coordinator.
33
+ */
34
+ export type BeaconCoordinatorParams = {
27
35
  protocol?: CommunicationService;
28
36
  did: string;
29
37
  keys: ServiceAdapterIdentity<RawSchnorrKeyPair>
@@ -34,37 +42,36 @@ type BeaconCoordinatorParams = {
34
42
  * @class BeaconCoordinator
35
43
  * @type {BeaconCoordinator}
36
44
  */
37
-
38
45
  export class BeaconCoordinator {
39
46
  /**
40
47
  * The name of the BeaconCoordinator service.
41
48
  * @type {string}
42
49
  */
43
- public name: string;
50
+ name: string;
44
51
 
45
52
  /**
46
53
  * The DID of the BeaconCoordinator.
47
54
  * @type {Array<string>}
48
55
  */
49
- public did: string;
56
+ did: string;
50
57
 
51
58
  /**
52
59
  * The communication protocol used by the BeaconCoordinator.
53
60
  * @type {CommunicationService}
54
61
  */
55
- public protocol: CommunicationService;
62
+ protocol: CommunicationService;
56
63
 
57
64
  /**
58
65
  * List of subscribers engaged in a Musig2 Cohort signing session with the BeaconCoordinator.
59
66
  * @type {Array<string>}
60
67
  */
61
- public cohorts: Array<AggregateBeaconCohort> = [];
68
+ cohorts: Array<AggregateBeaconCohort> = [];
62
69
 
63
70
  /**
64
71
  * Active signing sessions for the BeaconCoordinator.
65
72
  * @type {Record<string, BeaconCohortSigningSession>}
66
73
  */
67
- public activeSigningSessions: Map<string, BeaconCohortSigningSession> = new Map();
74
+ activeSigningSessions: Map<string, BeaconCohortSigningSession> = new Map();
68
75
 
69
76
  /**
70
77
  * Constructs a new BeaconCoordinator instance.
@@ -74,23 +81,28 @@ export class BeaconCoordinator {
74
81
  * @param {string} [params.did] Optional DID to use for the coordinator. If not provided, a new DID will be generated.
75
82
  * @param {ServiceAdapterIdentity<RawKeyPair>} params.keys The keys used for cryptographic operations.
76
83
  */
77
- constructor(params: BeaconCoordinatorParams) {
78
- this.name = params.name || `btcr2-beacon-coordinator-${crypto.randomUUID()}`;
84
+ constructor(params: {
85
+ did: string;
86
+ keys: ServiceAdapterIdentity<RawSchnorrKeyPair>
87
+ protocol?: CommunicationService;
88
+ name?: string;
89
+ }) {
79
90
  this.did = params.did;
80
91
  this.protocol = params.protocol || new NostrAdapter();
81
92
  this.protocol.setKeys(params.keys);
93
+ this.name = params.name || `btcr2-beacon-coordinator-${crypto.randomUUID()}`;
82
94
  }
83
95
 
84
96
  /**
85
97
  * Setup and start the BeaconCoordinator communication protocol.
86
98
  * @returns {void}
87
99
  */
88
- public start(): void {
100
+ start(): void {
89
101
  Logger.info(`Setting up BeaconCoordinator ${this.name} (${this.did}) on ${this.protocol.name} ...`);
90
- this.protocol.registerMessageHandler(BEACON_COHORT_OPT_IN, this._handleOptIn.bind(this));
91
- this.protocol.registerMessageHandler(BEACON_COHORT_REQUEST_SIGNATURE, this._handleRequestSignature.bind(this));
92
- this.protocol.registerMessageHandler(BEACON_COHORT_NONCE_CONTRIBUTION, this._handleNonceContribution.bind(this));
93
- this.protocol.registerMessageHandler(BEACON_COHORT_SIGNATURE_AUTHORIZATION, this._handleSignatureAuthorization.bind(this));
102
+ this.protocol.registerMessageHandler(BEACON_COHORT_OPT_IN, this.#handleOptIn.bind(this));
103
+ this.protocol.registerMessageHandler(BEACON_COHORT_REQUEST_SIGNATURE, this.#handleRequestSignature.bind(this));
104
+ this.protocol.registerMessageHandler(BEACON_COHORT_NONCE_CONTRIBUTION, this.#handleNonceContribution.bind(this));
105
+ this.protocol.registerMessageHandler(BEACON_COHORT_SIGNATURE_AUTHORIZATION, this.#handleSignatureAuthorization.bind(this));
94
106
  this.protocol.start();
95
107
  }
96
108
 
@@ -99,7 +111,7 @@ export class BeaconCoordinator {
99
111
  * @param {OptInMessage} message The message containing the opt-in request.
100
112
  * @returns {Promise<void>}
101
113
  */
102
- private async _handleOptIn(message: CohortOptInMessage): Promise<void> {
114
+ async #handleOptIn(message: CohortOptInMessage): Promise<void> {
103
115
  const optIn = BeaconCohortOptInMessage.fromJSON(message);
104
116
  const cohortId = optIn.body?.cohortId;
105
117
  const participant = optIn.from;
@@ -126,7 +138,7 @@ export class BeaconCoordinator {
126
138
  * @param {CohortRequestSignatureMessage} message The message containing the request signature.
127
139
  * @returns {Promise<void>}
128
140
  */
129
- private async _handleRequestSignature(message: Maybe<CohortRequestSignatureMessage>): Promise<void> {
141
+ async #handleRequestSignature(message: Maybe<CohortRequestSignatureMessage>): Promise<void> {
130
142
  const signatureRequest = BeaconCohortRequestSignatureMessage.fromJSON(message);
131
143
  const cohortId = signatureRequest.body?.cohortId;
132
144
  if (!cohortId) {
@@ -147,7 +159,7 @@ export class BeaconCoordinator {
147
159
  * @param {CohortNonceContributionMessage} message The message containing the nonce contribution.
148
160
  * @returns {Promise<void>}
149
161
  */
150
- private async _handleNonceContribution(message: CohortNonceContributionMessage): Promise<void> {
162
+ async #handleNonceContribution(message: CohortNonceContributionMessage): Promise<void> {
151
163
  // Cast message to NonceContributionMessage type.
152
164
  const nonceContribMessage = BeaconCohortNonceContributionMessage.fromJSON(message);
153
165
  const cohortId = nonceContribMessage.body?.cohortId;
@@ -195,7 +207,7 @@ export class BeaconCoordinator {
195
207
  * @param {Maybe<CohortSignatureAuthorizationMessage>} message The message containing the signature authorization request.
196
208
  * @returns {Promise<void>}
197
209
  */
198
- private async _handleSignatureAuthorization(message: Maybe<CohortSignatureAuthorizationMessage>): Promise<void> {
210
+ async #handleSignatureAuthorization(message: Maybe<CohortSignatureAuthorizationMessage>): Promise<void> {
199
211
  const sigAuthMessage = BeaconCohortSignatureAuthorizationMessage.fromJSON(message);
200
212
  const cohortId = sigAuthMessage.body?.cohortId;
201
213
  if (!cohortId) {
@@ -216,14 +228,14 @@ export class BeaconCoordinator {
216
228
  if(signingSession.id !== sessionId) {
217
229
  throw new BeaconCoordinatorError(
218
230
  `Signature authorization for wrong session: ${signingSession.id} != ${sessionId}`,
219
- 'SIGNATURE_AUTHORIZATION_ERROR', message
231
+ 'SIGNATURE_AUTHORIZATION_ERROR', { original: message, converted: sigAuthMessage }
220
232
  );
221
233
  }
222
234
 
223
235
  if(signingSession.status !== SIGNING_SESSION_STATUS.AWAITING_PARTIAL_SIGNATURES) {
224
236
  throw new BeaconCoordinatorError(
225
237
  `Partial signature received but not expected. Current status: ${signingSession.status}`,
226
- 'SIGNATURE_AUTHORIZATION_ERROR', message
238
+ 'SIGNATURE_AUTHORIZATION_ERROR', { original: message, converted: sigAuthMessage }
227
239
  );
228
240
  }
229
241
  const partialSignature = sigAuthMessage.body?.partialSignature;
@@ -241,7 +253,7 @@ export class BeaconCoordinator {
241
253
 
242
254
  if (signingSession.status === SIGNING_SESSION_STATUS.PARTIAL_SIGNATURES_RECEIVED) {
243
255
  const signature = await signingSession.generateFinalSignature();
244
- Logger.info(`Final signature ${signature.toHex()} generated for session ${signingSession.id}`);
256
+ Logger.info(`Final signature ${Buffer.from(signature).toString('hex')} generated for session ${signingSession.id}`);
245
257
  }
246
258
  }
247
259
 
@@ -266,7 +278,7 @@ export class BeaconCoordinator {
266
278
  * @param {string} participant The DID of the participant requesting the subscription.
267
279
  * @returns {Promise<void>}
268
280
  */
269
- public async acceptSubscription(participant: string): Promise<void> {
281
+ async acceptSubscription(participant: string): Promise<void> {
270
282
  Logger.info(`Accepting subscription from ${participant}`);
271
283
  const message = {
272
284
  type : BEACON_COHORT_OPT_IN_ACCEPT,
@@ -281,7 +293,7 @@ export class BeaconCoordinator {
281
293
  * @param {BeaconCohortSigningSession} session The session containing the aggregated nonce.
282
294
  * @returns {Promise<void>}
283
295
  */
284
- public async sendAggregatedNonce(session: BeaconCohortSigningSession): Promise<void> {
296
+ async sendAggregatedNonce(session: BeaconCohortSigningSession): Promise<void> {
285
297
  const aggregatedNonce = session.generateAggregatedNonce();
286
298
  Logger.info(`Aggregated Nonces for session ${session.id}:`, aggregatedNonce);
287
299
 
@@ -304,13 +316,13 @@ export class BeaconCoordinator {
304
316
  * Announces a new cohort to all subscribers.
305
317
  * @param {number} minParticipants The minimum number of participants required for the cohort.
306
318
  * @param {string} [network='mutinynet'] The network on which the cohort operates (default is 'signet').
307
- * @param {string} [beaconType='SMTAggregateBeacon'] The type of beacon to be used (default is 'SMTAggregateBeacon').
319
+ * @param {string} [beaconType='SMTBeacon'] The type of beacon to be used (default is 'SMTBeacon').
308
320
  * @returns {Promise<AggregateBeaconCohort>} The newly created cohort.
309
321
  */
310
- public async advertiseCohort(
322
+ async advertiseCohort(
311
323
  minParticipants: number,
312
324
  network: string = 'mutinynet',
313
- beaconType: string = 'SMTAggregateBeacon'
325
+ beaconType: string = 'SMTBeacon'
314
326
  ): Promise<AggregateBeaconCohort> {
315
327
  const cohort = new AggregateBeaconCohort({ minParticipants, network, beaconType });
316
328
  Logger.info(`Advertising new cohort ${cohort.id} ...`);
@@ -334,7 +346,7 @@ export class BeaconCoordinator {
334
346
  * @param {string} cohortId The minimum number of participants required for the cohort.
335
347
  * @returns {Promise<AggregateBeaconCohort>} The newly created cohort.
336
348
  */
337
- public async announceCohortReady(cohortId: string): Promise<AggregateBeaconCohort> {
349
+ async announceCohortReady(cohortId: string): Promise<AggregateBeaconCohort> {
338
350
  const cohort = this.cohorts.find(c => c.id === cohortId);
339
351
  if (!cohort) {
340
352
  Logger.error(`Cohort with ID ${cohortId} not found.`);
@@ -366,7 +378,7 @@ export class BeaconCoordinator {
366
378
  * @returns {Promise<BeaconCohortSigningSession>} The started signing session.
367
379
  * @throws {BeaconCoordinatorError} If the cohort with the given ID is not found.
368
380
  */
369
- public async startSigningSession(cohortId: string): Promise<BeaconCohortSigningSession> {
381
+ async startSigningSession(cohortId: string): Promise<BeaconCohortSigningSession> {
370
382
  Logger.info(`Attempting to start signing session for cohort ${cohortId}`);
371
383
  const cohort = this.cohorts.find(c => c.id === cohortId);
372
384
  if (!cohort) {
@@ -393,7 +405,7 @@ export class BeaconCoordinator {
393
405
  * @param {Service} service The communication service configuration.
394
406
  * @returns {BeaconCoordinator} Initialized BeaconCoordinator instance.
395
407
  */
396
- public static initialize(service: Service): BeaconCoordinator {
408
+ static initialize(service: Service): BeaconCoordinator {
397
409
  const communicationService = CommunicationFactory.establish(service);
398
410
  const coordinator = new BeaconCoordinator({
399
411
  protocol : communicationService,
@@ -275,11 +275,12 @@ export class BeaconParticipant {
275
275
  return;
276
276
  }
277
277
  this.finalizeUnsetCohortKey(cohortId);
278
- const participantPk = this.getCohortKey(cohortId).publicKey?.toHex();
279
- if(!participantPk) {
278
+ const participantPkBytes = this.getCohortKey(cohortId).publicKey;
279
+ if(!participantPkBytes) {
280
280
  Logger.error(`Failed to derive public key for cohort ${cohortId}`);
281
281
  return;
282
282
  }
283
+ const participantPk = Buffer.from(participantPkBytes).toString('hex');
283
284
  const beaconAddress = cohortSetMessage.body?.beaconAddress;
284
285
  if(!beaconAddress) {
285
286
  Logger.error(`Beacon address not provided in cohort set message for ${cohortId}`);
@@ -290,7 +291,7 @@ export class BeaconParticipant {
290
291
  Logger.error(`Cohort keys not provided in cohort set message for ${cohortId}`);
291
292
  return;
292
293
  }
293
- const keys = cohortKeys.map(key => key.toHex());
294
+ const keys = cohortKeys.map(key => Buffer.from(key).toString('hex'));
294
295
  cohort.validateCohort([participantPk], keys, beaconAddress);
295
296
  Logger.info(`BeaconParticipant w/ pk ${participantPk} successfully joined cohort ${cohortId} with beacon address ${beaconAddress}.`);
296
297
  Logger.info(`Cohort status: ${cohort.status}`);
@@ -268,7 +268,7 @@ export class BeaconCohortSigningSession implements SigningSession {
268
268
  * @returns {BeaconCohortSigningSession} The JSON object representation of the signing session.
269
269
  */
270
270
  public json(): BeaconCohortSigningSession {
271
- return Object.json(this) as BeaconCohortSigningSession;
271
+ return Object.fromEntries(Object.entries(this)) as BeaconCohortSigningSession;
272
272
  }
273
273
 
274
274
  /**