@did-btcr2/method 0.17.2 → 0.18.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 (366) hide show
  1. package/dist/browser.js +30124 -19552
  2. package/dist/browser.mjs +30123 -19551
  3. package/dist/cjs/core/beacon/aggregation/cohort/index.js +225 -0
  4. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -0
  5. package/dist/{esm/core/beacon/aggregation → cjs/core/beacon/aggregation/cohort}/messages/base.js +3 -11
  6. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -0
  7. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js +11 -0
  8. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js.map +1 -0
  9. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js +98 -0
  10. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js.map +1 -0
  11. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +30 -0
  12. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -0
  13. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +28 -0
  14. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -0
  15. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +26 -0
  16. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -0
  17. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +22 -0
  18. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -0
  19. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +27 -0
  20. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -0
  21. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +28 -0
  22. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -0
  23. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +29 -0
  24. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -0
  25. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +29 -0
  26. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -0
  27. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +29 -0
  28. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -0
  29. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +30 -0
  30. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -0
  31. package/dist/cjs/core/beacon/aggregation/cohort/status.js.map +1 -0
  32. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +126 -0
  33. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -0
  34. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +230 -0
  35. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -0
  36. package/dist/cjs/core/beacon/aggregation/communication/error.js +12 -0
  37. package/dist/cjs/core/beacon/aggregation/communication/error.js.map +1 -0
  38. package/dist/cjs/core/beacon/aggregation/communication/factory.js +21 -0
  39. package/dist/cjs/core/beacon/aggregation/communication/factory.js.map +1 -0
  40. package/dist/cjs/core/beacon/aggregation/communication/service.js.map +1 -0
  41. package/dist/cjs/core/beacon/aggregation/coordinator.js +282 -56
  42. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
  43. package/dist/cjs/core/beacon/aggregation/participant.js +435 -1
  44. package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
  45. package/dist/cjs/core/beacon/aggregation/session/index.js +233 -0
  46. package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -0
  47. package/dist/cjs/core/beacon/aggregation/session/status.js +11 -0
  48. package/dist/cjs/core/beacon/aggregation/session/status.js.map +1 -0
  49. package/dist/cjs/core/beacon/cid-aggregate.js.map +1 -1
  50. package/dist/cjs/core/beacon/error.js +37 -0
  51. package/dist/cjs/core/beacon/error.js.map +1 -0
  52. package/dist/cjs/core/beacon/factory.js.map +1 -1
  53. package/dist/cjs/core/beacon/singleton.js +8 -5
  54. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  55. package/dist/cjs/core/beacon/smt-aggregate.js.map +1 -1
  56. package/dist/cjs/{utils/beacons.js → core/beacon/utils.js} +4 -4
  57. package/dist/cjs/core/beacon/utils.js.map +1 -0
  58. package/dist/cjs/core/crud/read.js +2 -9
  59. package/dist/cjs/core/crud/read.js.map +1 -1
  60. package/dist/cjs/core/crud/update.js +18 -19
  61. package/dist/cjs/core/crud/update.js.map +1 -1
  62. package/dist/{esm/utils → cjs/core}/identifier.js +18 -3
  63. package/dist/cjs/core/identifier.js.map +1 -0
  64. package/dist/cjs/did-btcr2.js +2 -2
  65. package/dist/cjs/did-btcr2.js.map +1 -1
  66. package/dist/cjs/index.js +28 -6
  67. package/dist/cjs/index.js.map +1 -1
  68. package/dist/cjs/interfaces/beacon.js.map +1 -1
  69. package/dist/cjs/utils/appendix.js +2 -3
  70. package/dist/cjs/utils/appendix.js.map +1 -1
  71. package/dist/cjs/utils/did-document.js +4 -6
  72. package/dist/cjs/utils/did-document.js.map +1 -1
  73. package/dist/cjs/utils/types.js +2 -0
  74. package/dist/cjs/utils/types.js.map +1 -0
  75. package/dist/esm/core/beacon/aggregation/cohort/index.js +225 -0
  76. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -0
  77. package/dist/{cjs/core/beacon/aggregation → esm/core/beacon/aggregation/cohort}/messages/base.js +3 -11
  78. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -0
  79. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +11 -0
  80. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +1 -0
  81. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +98 -0
  82. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +1 -0
  83. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +30 -0
  84. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -0
  85. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +28 -0
  86. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -0
  87. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +26 -0
  88. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -0
  89. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +22 -0
  90. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -0
  91. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +27 -0
  92. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -0
  93. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +28 -0
  94. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -0
  95. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +29 -0
  96. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -0
  97. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +29 -0
  98. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -0
  99. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +29 -0
  100. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -0
  101. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +30 -0
  102. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -0
  103. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +1 -0
  104. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +126 -0
  105. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -0
  106. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +230 -0
  107. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -0
  108. package/dist/esm/core/beacon/aggregation/communication/error.js +12 -0
  109. package/dist/esm/core/beacon/aggregation/communication/error.js.map +1 -0
  110. package/dist/esm/core/beacon/aggregation/communication/factory.js +21 -0
  111. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +1 -0
  112. package/dist/esm/core/beacon/aggregation/communication/service.js.map +1 -0
  113. package/dist/esm/core/beacon/aggregation/coordinator.js +282 -56
  114. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  115. package/dist/esm/core/beacon/aggregation/participant.js +435 -1
  116. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  117. package/dist/esm/core/beacon/aggregation/session/index.js +233 -0
  118. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -0
  119. package/dist/esm/core/beacon/aggregation/session/status.js +11 -0
  120. package/dist/esm/core/beacon/aggregation/session/status.js.map +1 -0
  121. package/dist/esm/core/beacon/cid-aggregate.js.map +1 -1
  122. package/dist/esm/core/beacon/error.js +37 -0
  123. package/dist/esm/core/beacon/error.js.map +1 -0
  124. package/dist/esm/core/beacon/factory.js.map +1 -1
  125. package/dist/esm/core/beacon/singleton.js +8 -5
  126. package/dist/esm/core/beacon/singleton.js.map +1 -1
  127. package/dist/esm/core/beacon/smt-aggregate.js.map +1 -1
  128. package/dist/esm/{utils/beacons.js → core/beacon/utils.js} +4 -4
  129. package/dist/esm/core/beacon/utils.js.map +1 -0
  130. package/dist/esm/core/crud/read.js +2 -9
  131. package/dist/esm/core/crud/read.js.map +1 -1
  132. package/dist/esm/core/crud/update.js +18 -19
  133. package/dist/esm/core/crud/update.js.map +1 -1
  134. package/dist/{cjs/utils → esm/core}/identifier.js +18 -3
  135. package/dist/esm/core/identifier.js.map +1 -0
  136. package/dist/esm/did-btcr2.js +2 -2
  137. package/dist/esm/did-btcr2.js.map +1 -1
  138. package/dist/esm/index.js +28 -6
  139. package/dist/esm/index.js.map +1 -1
  140. package/dist/esm/interfaces/beacon.js.map +1 -1
  141. package/dist/esm/utils/appendix.js +2 -3
  142. package/dist/esm/utils/appendix.js.map +1 -1
  143. package/dist/esm/utils/did-document.js +4 -6
  144. package/dist/esm/utils/did-document.js.map +1 -1
  145. package/dist/esm/utils/types.js +2 -0
  146. package/dist/esm/utils/types.js.map +1 -0
  147. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +135 -0
  148. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -0
  149. package/dist/types/core/beacon/aggregation/{messages → cohort/messages}/base.d.ts +13 -8
  150. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -0
  151. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +10 -0
  152. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +1 -0
  153. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +64 -0
  154. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +1 -0
  155. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +28 -0
  156. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -0
  157. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +26 -0
  158. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -0
  159. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +23 -0
  160. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -0
  161. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +19 -0
  162. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -0
  163. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +24 -0
  164. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -0
  165. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +24 -0
  166. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -0
  167. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +25 -0
  168. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -0
  169. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +25 -0
  170. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -0
  171. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +25 -0
  172. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -0
  173. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +26 -0
  174. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -0
  175. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +1 -0
  176. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +88 -0
  177. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -0
  178. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +93 -0
  179. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -0
  180. package/dist/types/core/beacon/aggregation/communication/error.d.ts +7 -0
  181. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +1 -0
  182. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +9 -0
  183. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +1 -0
  184. package/dist/types/core/beacon/aggregation/communication/service.d.ts +35 -0
  185. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +1 -0
  186. package/dist/types/core/beacon/aggregation/coordinator.d.ts +79 -26
  187. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  188. package/dist/types/core/beacon/aggregation/participant.d.ts +190 -0
  189. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  190. package/dist/types/core/beacon/aggregation/session/index.d.ts +155 -0
  191. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -0
  192. package/dist/types/core/beacon/aggregation/session/status.d.ts +10 -0
  193. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +1 -0
  194. package/dist/types/core/beacon/cid-aggregate.d.ts +3 -4
  195. package/dist/types/core/beacon/cid-aggregate.d.ts.map +1 -1
  196. package/dist/types/core/beacon/error.d.ts +22 -0
  197. package/dist/types/core/beacon/error.d.ts.map +1 -0
  198. package/dist/types/core/beacon/factory.d.ts +2 -3
  199. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  200. package/dist/types/core/beacon/singleton.d.ts +2 -3
  201. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  202. package/dist/types/core/beacon/smt-aggregate.d.ts +3 -4
  203. package/dist/types/core/beacon/smt-aggregate.d.ts.map +1 -1
  204. package/dist/types/{utils/beacons.d.ts → core/beacon/utils.d.ts} +3 -3
  205. package/dist/types/core/beacon/utils.d.ts.map +1 -0
  206. package/dist/types/core/crud/read.d.ts +3 -3
  207. package/dist/types/core/crud/read.d.ts.map +1 -1
  208. package/dist/types/core/crud/update.d.ts +1 -1
  209. package/dist/types/core/crud/update.d.ts.map +1 -1
  210. package/dist/types/{utils → core}/identifier.d.ts +24 -3
  211. package/dist/types/core/identifier.d.ts.map +1 -0
  212. package/dist/types/did-btcr2.d.ts +1 -1
  213. package/dist/types/did-btcr2.d.ts.map +1 -1
  214. package/dist/types/index.d.ts +28 -6
  215. package/dist/types/index.d.ts.map +1 -1
  216. package/dist/types/interfaces/beacon.d.ts +65 -5
  217. package/dist/types/interfaces/beacon.d.ts.map +1 -1
  218. package/dist/types/interfaces/crud.d.ts +1 -1
  219. package/dist/types/interfaces/crud.d.ts.map +1 -1
  220. package/dist/types/utils/appendix.d.ts +2 -10
  221. package/dist/types/utils/appendix.d.ts.map +1 -1
  222. package/dist/types/utils/did-document-builder.d.ts +1 -1
  223. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  224. package/dist/types/utils/did-document.d.ts +1 -1
  225. package/dist/types/utils/did-document.d.ts.map +1 -1
  226. package/dist/types/{types/crud.d.ts → utils/types.d.ts} +2 -2
  227. package/dist/types/utils/types.d.ts.map +1 -0
  228. package/package.json +4 -3
  229. package/src/core/beacon/aggregation/cohort/index.ts +292 -0
  230. package/src/core/beacon/aggregation/{messages → cohort/messages}/base.ts +14 -16
  231. package/src/core/beacon/aggregation/cohort/messages/constants.ts +12 -0
  232. package/src/core/beacon/aggregation/cohort/messages/index.ts +143 -0
  233. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +43 -0
  234. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +39 -0
  235. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +34 -0
  236. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +33 -0
  237. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +35 -0
  238. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +38 -0
  239. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +39 -0
  240. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +39 -0
  241. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +39 -0
  242. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +40 -0
  243. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +153 -0
  244. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +300 -0
  245. package/src/core/beacon/aggregation/communication/error.ts +13 -0
  246. package/src/core/beacon/aggregation/communication/factory.ts +25 -0
  247. package/src/core/beacon/aggregation/communication/service.ts +42 -0
  248. package/src/core/beacon/aggregation/coordinator.ts +338 -67
  249. package/src/core/beacon/aggregation/participant.ts +512 -0
  250. package/src/core/beacon/aggregation/session/index.ts +289 -0
  251. package/src/core/beacon/aggregation/session/status.ts +18 -0
  252. package/src/core/beacon/cid-aggregate.ts +4 -5
  253. package/src/core/beacon/error.ts +44 -0
  254. package/src/core/beacon/factory.ts +2 -3
  255. package/src/core/beacon/singleton.ts +10 -8
  256. package/src/core/beacon/smt-aggregate.ts +4 -5
  257. package/src/{utils/beacons.ts → core/beacon/utils.ts} +5 -5
  258. package/src/core/crud/read.ts +7 -16
  259. package/src/core/crud/update.ts +25 -22
  260. package/src/{utils → core}/identifier.ts +35 -5
  261. package/src/did-btcr2.ts +4 -4
  262. package/src/index.ts +36 -8
  263. package/src/interfaces/beacon.ts +75 -5
  264. package/src/interfaces/crud.ts +1 -1
  265. package/src/utils/appendix.ts +3 -11
  266. package/src/utils/did-document-builder.ts +1 -1
  267. package/src/utils/did-document.ts +4 -7
  268. package/src/{types/crud.ts → utils/types.ts} +2 -2
  269. package/dist/cjs/core/beacon/aggregation/messages/advert.js +0 -24
  270. package/dist/cjs/core/beacon/aggregation/messages/advert.js.map +0 -1
  271. package/dist/cjs/core/beacon/aggregation/messages/base.js.map +0 -1
  272. package/dist/cjs/core/beacon/aggregation/messages/cohort-set.js +0 -25
  273. package/dist/cjs/core/beacon/aggregation/messages/cohort-set.js.map +0 -1
  274. package/dist/cjs/core/beacon/aggregation/messages/keygen.js +0 -8
  275. package/dist/cjs/core/beacon/aggregation/messages/keygen.js.map +0 -1
  276. package/dist/cjs/core/beacon/aggregation/messages/opt-in.js +0 -23
  277. package/dist/cjs/core/beacon/aggregation/messages/opt-in.js.map +0 -1
  278. package/dist/cjs/core/beacon/aggregation/messages/sign.js +0 -7
  279. package/dist/cjs/core/beacon/aggregation/messages/sign.js.map +0 -1
  280. package/dist/cjs/core/beacon/aggregation/models/cohort/index.js +0 -92
  281. package/dist/cjs/core/beacon/aggregation/models/cohort/index.js.map +0 -1
  282. package/dist/cjs/core/beacon/aggregation/models/cohort/status.js.map +0 -1
  283. package/dist/cjs/core/beacon/aggregation/protocol/nostr.js +0 -57
  284. package/dist/cjs/core/beacon/aggregation/protocol/nostr.js.map +0 -1
  285. package/dist/cjs/core/beacon/aggregation/protocol/service.js.map +0 -1
  286. package/dist/cjs/core/key-manager/index.js +0 -290
  287. package/dist/cjs/core/key-manager/index.js.map +0 -1
  288. package/dist/cjs/core/key-manager/interface.js +0 -2
  289. package/dist/cjs/core/key-manager/interface.js.map +0 -1
  290. package/dist/cjs/interfaces/ibeacon.js +0 -2
  291. package/dist/cjs/interfaces/ibeacon.js.map +0 -1
  292. package/dist/cjs/types/crud.js +0 -2
  293. package/dist/cjs/types/crud.js.map +0 -1
  294. package/dist/cjs/utils/beacons.js.map +0 -1
  295. package/dist/cjs/utils/identifier.js.map +0 -1
  296. package/dist/esm/core/beacon/aggregation/messages/advert.js +0 -24
  297. package/dist/esm/core/beacon/aggregation/messages/advert.js.map +0 -1
  298. package/dist/esm/core/beacon/aggregation/messages/base.js.map +0 -1
  299. package/dist/esm/core/beacon/aggregation/messages/cohort-set.js +0 -25
  300. package/dist/esm/core/beacon/aggregation/messages/cohort-set.js.map +0 -1
  301. package/dist/esm/core/beacon/aggregation/messages/keygen.js +0 -8
  302. package/dist/esm/core/beacon/aggregation/messages/keygen.js.map +0 -1
  303. package/dist/esm/core/beacon/aggregation/messages/opt-in.js +0 -23
  304. package/dist/esm/core/beacon/aggregation/messages/opt-in.js.map +0 -1
  305. package/dist/esm/core/beacon/aggregation/messages/sign.js +0 -7
  306. package/dist/esm/core/beacon/aggregation/messages/sign.js.map +0 -1
  307. package/dist/esm/core/beacon/aggregation/models/cohort/index.js +0 -92
  308. package/dist/esm/core/beacon/aggregation/models/cohort/index.js.map +0 -1
  309. package/dist/esm/core/beacon/aggregation/models/cohort/status.js.map +0 -1
  310. package/dist/esm/core/beacon/aggregation/protocol/nostr.js +0 -57
  311. package/dist/esm/core/beacon/aggregation/protocol/nostr.js.map +0 -1
  312. package/dist/esm/core/beacon/aggregation/protocol/service.js.map +0 -1
  313. package/dist/esm/core/key-manager/index.js +0 -290
  314. package/dist/esm/core/key-manager/index.js.map +0 -1
  315. package/dist/esm/core/key-manager/interface.js +0 -2
  316. package/dist/esm/core/key-manager/interface.js.map +0 -1
  317. package/dist/esm/interfaces/ibeacon.js +0 -2
  318. package/dist/esm/interfaces/ibeacon.js.map +0 -1
  319. package/dist/esm/types/crud.js +0 -2
  320. package/dist/esm/types/crud.js.map +0 -1
  321. package/dist/esm/utils/beacons.js.map +0 -1
  322. package/dist/esm/utils/identifier.js.map +0 -1
  323. package/dist/types/core/beacon/aggregation/messages/advert.d.ts +0 -22
  324. package/dist/types/core/beacon/aggregation/messages/advert.d.ts.map +0 -1
  325. package/dist/types/core/beacon/aggregation/messages/base.d.ts.map +0 -1
  326. package/dist/types/core/beacon/aggregation/messages/cohort-set.d.ts +0 -23
  327. package/dist/types/core/beacon/aggregation/messages/cohort-set.d.ts.map +0 -1
  328. package/dist/types/core/beacon/aggregation/messages/keygen.d.ts +0 -6
  329. package/dist/types/core/beacon/aggregation/messages/keygen.d.ts.map +0 -1
  330. package/dist/types/core/beacon/aggregation/messages/opt-in.d.ts +0 -22
  331. package/dist/types/core/beacon/aggregation/messages/opt-in.d.ts.map +0 -1
  332. package/dist/types/core/beacon/aggregation/messages/sign.d.ts +0 -5
  333. package/dist/types/core/beacon/aggregation/messages/sign.d.ts.map +0 -1
  334. package/dist/types/core/beacon/aggregation/models/cohort/index.d.ts +0 -77
  335. package/dist/types/core/beacon/aggregation/models/cohort/index.d.ts.map +0 -1
  336. package/dist/types/core/beacon/aggregation/models/cohort/status.d.ts.map +0 -1
  337. package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts +0 -36
  338. package/dist/types/core/beacon/aggregation/protocol/nostr.d.ts.map +0 -1
  339. package/dist/types/core/beacon/aggregation/protocol/service.d.ts +0 -6
  340. package/dist/types/core/beacon/aggregation/protocol/service.d.ts.map +0 -1
  341. package/dist/types/core/key-manager/index.d.ts +0 -145
  342. package/dist/types/core/key-manager/index.d.ts.map +0 -1
  343. package/dist/types/core/key-manager/interface.d.ts +0 -113
  344. package/dist/types/core/key-manager/interface.d.ts.map +0 -1
  345. package/dist/types/interfaces/ibeacon.d.ts +0 -65
  346. package/dist/types/interfaces/ibeacon.d.ts.map +0 -1
  347. package/dist/types/types/crud.d.ts.map +0 -1
  348. package/dist/types/utils/beacons.d.ts.map +0 -1
  349. package/dist/types/utils/identifier.d.ts.map +0 -1
  350. package/src/core/beacon/aggregation/messages/advert.ts +0 -36
  351. package/src/core/beacon/aggregation/messages/cohort-set.ts +0 -37
  352. package/src/core/beacon/aggregation/messages/keygen.ts +0 -8
  353. package/src/core/beacon/aggregation/messages/opt-in.ts +0 -35
  354. package/src/core/beacon/aggregation/messages/sign.ts +0 -7
  355. package/src/core/beacon/aggregation/models/cohort/index.ts +0 -112
  356. package/src/core/beacon/aggregation/protocol/nostr.ts +0 -81
  357. package/src/core/beacon/aggregation/protocol/service.ts +0 -6
  358. package/src/core/key-manager/index.ts +0 -364
  359. package/src/core/key-manager/interface.ts +0 -129
  360. package/src/interfaces/ibeacon.ts +0 -75
  361. /package/dist/cjs/core/beacon/aggregation/{models/cohort → cohort}/status.js +0 -0
  362. /package/dist/cjs/core/beacon/aggregation/{protocol → communication}/service.js +0 -0
  363. /package/dist/esm/core/beacon/aggregation/{models/cohort → cohort}/status.js +0 -0
  364. /package/dist/esm/core/beacon/aggregation/{protocol → communication}/service.js +0 -0
  365. /package/dist/types/core/beacon/aggregation/{models/cohort → cohort}/status.d.ts +0 -0
  366. /package/src/core/beacon/aggregation/{models/cohort → cohort}/status.ts +0 -0
@@ -0,0 +1,35 @@
1
+ import { Maybe } from '@did-btcr2/common';
2
+ import { BaseMessage } from '../base.js';
3
+ import { BEACON_COHORT_OPT_IN_ACCEPT } from '../constants.js';
4
+
5
+ export interface CohortSubscribeMessage {
6
+ type?: typeof BEACON_COHORT_OPT_IN_ACCEPT;
7
+ to: string;
8
+ from: string;
9
+ }
10
+
11
+ /**
12
+ * Represents a message for subscribing to a cohort.
13
+ * This message is sent by a coordinator to a participant to indicate acceptance in the cohort.
14
+ * @class BeaconCohortSubscribeMessage
15
+ * @extends BaseMessage
16
+ * @type {BeaconCohortSubscribeMessage}
17
+ */
18
+ export class BeaconCohortSubscribeMessage extends BaseMessage {
19
+ constructor({ to, from }: CohortSubscribeMessage) {
20
+ super({ to, from, type: BEACON_COHORT_OPT_IN_ACCEPT });
21
+ }
22
+
23
+ /**
24
+ * Initializes a BeaconCohortSubscribeMessage from a possible CohortSubscribeMessage object.
25
+ * @param {CohortSubscribeMessage} data The Subscribe object to initialize the SubscribeMessage.
26
+ * @returns {BeaconCohortSubscribeMessage} The serialized SubscribeMessage.
27
+ */
28
+ public static fromJSON(data: Maybe<CohortSubscribeMessage>): BeaconCohortSubscribeMessage {
29
+ const message = JSON.parse(data);
30
+ if (message.type != BEACON_COHORT_OPT_IN_ACCEPT) {
31
+ throw new Error(`Invalid type: ${message.type}`);
32
+ }
33
+ return new BeaconCohortSubscribeMessage(message);
34
+ }
35
+ }
@@ -0,0 +1,38 @@
1
+ import { Maybe } from '@did-btcr2/common';
2
+ import { BaseMessage } from '../base.js';
3
+ import { BEACON_COHORT_AGGREGATED_NONCE } from '../constants.js';
4
+
5
+ export interface CohortAggregatedNonceMessage {
6
+ to: string;
7
+ from: string;
8
+ cohortId: string;
9
+ sessionId: string;
10
+ aggregatedNonce: Uint8Array;
11
+ }
12
+
13
+ /**
14
+ * Represents a message containing an aggregated nonce for a cohort in the Beacon protocol.
15
+ * @class BeaconCohortAggregatedNonceMessage
16
+ * @extends BaseMessage
17
+ * @type {BeaconCohortAggregatedNonceMessage}
18
+ */
19
+ export class BeaconCohortAggregatedNonceMessage extends BaseMessage {
20
+ constructor({ to, from, cohortId, sessionId, aggregatedNonce }: CohortAggregatedNonceMessage) {
21
+ const body = { cohortId, sessionId, aggregatedNonce };
22
+ const type = BEACON_COHORT_AGGREGATED_NONCE;
23
+ super({ to, from, body, type });
24
+ }
25
+
26
+ /**
27
+ * Initializes a BeaconCohortAggregatedNonceMessage from a given AggregatedNonce object.
28
+ * @param {CohortAggregatedNonceMessage} data The data object to initialize the BeaconCohortAggregatedNonceMessage.
29
+ * @returns {BeaconCohortAggregatedNonceMessage} The new BeaconCohortAggregatedNonceMessage.
30
+ */
31
+ public static fromJSON(data: Maybe<CohortAggregatedNonceMessage>): BeaconCohortAggregatedNonceMessage {
32
+ const message = JSON.parse(data);
33
+ if (message.type != BEACON_COHORT_AGGREGATED_NONCE) {
34
+ throw new Error(`Invalid type: ${message.type}`);
35
+ }
36
+ return new BeaconCohortAggregatedNonceMessage(message);
37
+ }
38
+ }
@@ -0,0 +1,39 @@
1
+ import { Maybe } from '@did-btcr2/common';
2
+ import { BaseMessage } from '../base.js';
3
+ import { BEACON_COHORT_AUTHORIZATION_REQUEST } from '../constants.js';
4
+
5
+ export interface CohortAuthorizationRequestMessage {
6
+ to: string;
7
+ from: string;
8
+ cohortId: string;
9
+ sessionId: string;
10
+ pendingTx: string;
11
+ }
12
+
13
+ /**
14
+ * Sends the unsigned PSBT that spends the Beacon UTXO (plus any SMT proofs).
15
+ * Asks the cohort to begin a MuSig2 signing session.
16
+ * @class BeaconCohortAuthorizationRequestMessage
17
+ * @extends BaseMessage
18
+ * @type {CohortAuthorizationRequestMessage}
19
+ */
20
+ export class BeaconCohortAuthorizationRequestMessage extends BaseMessage {
21
+ constructor({ to, from, cohortId, sessionId, pendingTx }: CohortAuthorizationRequestMessage) {
22
+ const body = { cohortId, sessionId, pendingTx };
23
+ const type = BEACON_COHORT_AUTHORIZATION_REQUEST;
24
+ super({ to, from, body, type });
25
+ }
26
+
27
+ /**
28
+ * Initializes a BeaconCohortAuthorizationRequestMessage from a given AuthorizationRequest object.
29
+ * @param {CohortAuthorizationRequestMessage} data The data object to initialize the BeaconCohortAuthorizationRequestMessage.
30
+ * @returns {BeaconCohortAuthorizationRequestMessage} The serialized BeaconCohortAuthorizationRequestMessage.
31
+ */
32
+ public static fromJSON(data: Maybe<CohortAuthorizationRequestMessage>): BeaconCohortAuthorizationRequestMessage {
33
+ const message = JSON.parse(data);
34
+ if (message.type != BEACON_COHORT_AUTHORIZATION_REQUEST) {
35
+ throw new Error(`Invalid type: ${message.type}`);
36
+ }
37
+ return new BeaconCohortAuthorizationRequestMessage(message);
38
+ }
39
+ }
@@ -0,0 +1,39 @@
1
+ import { Maybe } from '@did-btcr2/common';
2
+ import { BaseMessage } from '../base.js';
3
+ import { BEACON_COHORT_NONCE_CONTRIBUTION } from '../constants.js';
4
+
5
+ export interface CohortNonceContributionMessage {
6
+ to: string;
7
+ from: string;
8
+ cohortId: string;
9
+ sessionId: string;
10
+ nonceContribution: Uint8Array;
11
+ }
12
+
13
+ /**
14
+ * Represents a message containing a nonce contribution for a cohort participant.
15
+ * Participant → Coordinator. Participant sending their public nonce points for the ongoing signing session.
16
+ * @class BeaconCohortNonceContributionMessage
17
+ * @extends BaseMessage
18
+ * @type {BeaconCohortNonceContributionMessage}
19
+ */
20
+ export class BeaconCohortNonceContributionMessage extends BaseMessage {
21
+ constructor({ to, from, cohortId, sessionId, nonceContribution }: CohortNonceContributionMessage) {
22
+ const body = { cohortId, sessionId, nonceContribution };
23
+ const type = BEACON_COHORT_NONCE_CONTRIBUTION;
24
+ super({ to, from, body, type });
25
+ }
26
+
27
+ /**
28
+ * Initializes a NonceContributionMessage from a given CohortNonceContributionMessage object.
29
+ * @param {CohortNonceContributionMessage} data The data object to initialize the BeaconCohortNonceContributionMessage.
30
+ * @returns {BeaconCohortNonceContributionMessage} The new BeaconCohortNonceContributionMessage.
31
+ */
32
+ public static fromJSON(data: Maybe<CohortNonceContributionMessage>): BeaconCohortNonceContributionMessage {
33
+ const message = JSON.parse(data);
34
+ if (message.type != BEACON_COHORT_NONCE_CONTRIBUTION) {
35
+ throw new Error(`Invalid type: ${message.type}`);
36
+ }
37
+ return new BeaconCohortNonceContributionMessage(message);
38
+ }
39
+ }
@@ -0,0 +1,39 @@
1
+ import { Maybe } from '@did-btcr2/common';
2
+ import { BaseMessage } from '../base.js';
3
+ import { BEACON_COHORT_REQUEST_SIGNATURE } from '../constants.js';
4
+
5
+ export type CohortRequestSignatureMessage = {
6
+ to: string;
7
+ from: string;
8
+ cohortId: string;
9
+ sessionId?: string;
10
+ data: string;
11
+ }
12
+
13
+ /**
14
+ * Coordinator → Participants. Returns the aggregation of all participant nonces
15
+ * so each participant can produce a correct partial signature.
16
+ * @class BeaconCohortRequestSignatureMessage
17
+ * @extends BaseMessage
18
+ * @type {BeaconCohortRequestSignatureMessage}
19
+ */
20
+ export class BeaconCohortRequestSignatureMessage extends BaseMessage {
21
+ constructor({ to, from, cohortId, sessionId, data }: CohortRequestSignatureMessage) {
22
+ const body = { cohortId, sessionId, data };
23
+ const type = BEACON_COHORT_REQUEST_SIGNATURE;
24
+ super({ to, from, body, type });
25
+ }
26
+
27
+ /**
28
+ * Initializes an BeaconCohortRequestSignatureMessage from a possible CohortRequestSignatureMessage object.
29
+ * @param {CohortRequestSignatureMessage} data The data object to initialize the BeaconCohortRequestSignatureMessage.
30
+ * @returns {BeaconCohortRequestSignatureMessage} The new BeaconCohortRequestSignatureMessage.
31
+ */
32
+ public static fromJSON(data: Maybe<CohortRequestSignatureMessage>): BeaconCohortRequestSignatureMessage {
33
+ const message = JSON.parse(data);
34
+ if (message.type != BEACON_COHORT_REQUEST_SIGNATURE) {
35
+ throw new Error(`Invalid type: ${message.type}`);
36
+ }
37
+ return new BeaconCohortRequestSignatureMessage(message);
38
+ }
39
+ }
@@ -0,0 +1,40 @@
1
+ import { Maybe } from '@did-btcr2/common';
2
+ import { BaseMessage } from '../base.js';
3
+ import { BEACON_COHORT_SIGNATURE_AUTHORIZATION } from '../constants.js';
4
+
5
+ export type CohortSignatureAuthorizationMessage = {
6
+ to: string;
7
+ from: string;
8
+ cohortId: string;
9
+ sessionId: string;
10
+ partialSignature: Uint8Array;
11
+ }
12
+
13
+ /**
14
+ * Participant → Coordinator. Delivers the participant’s partial signature over
15
+ * the PSBT, authorizing the final Beacon signal (transaction) once all signatures
16
+ * are collected.
17
+ * @class BeaconCohortSignatureAuthorizationMessage
18
+ * @extends BaseMessage
19
+ * @type {BeaconCohortSignatureAuthorizationMessage}
20
+ */
21
+ export class BeaconCohortSignatureAuthorizationMessage extends BaseMessage {
22
+ constructor({ to, from, cohortId, sessionId, partialSignature }: CohortSignatureAuthorizationMessage) {
23
+ const body = { cohortId, sessionId, partialSignature };
24
+ const type = BEACON_COHORT_SIGNATURE_AUTHORIZATION;
25
+ super({ to, from, body, type });
26
+ }
27
+
28
+ /**
29
+ * Initializes an BeaconCohortSignatureAuthorizationMessage from a given CohortSignatureAuthorizationMessage object.
30
+ * @param {CohortSignatureAuthorizationMessage} data The data object to initialize the BeaconCohortSignatureAuthorizationMessage.
31
+ * @returns {BeaconCohortSignatureAuthorizationMessage} The serialized BeaconCohortSignatureAuthorizationMessage.
32
+ */
33
+ public static fromJSON(data: Maybe<CohortSignatureAuthorizationMessage>): BeaconCohortSignatureAuthorizationMessage {
34
+ const message = JSON.parse(data);
35
+ if (message.type != BEACON_COHORT_SIGNATURE_AUTHORIZATION) {
36
+ throw new Error(`Invalid type: ${message.type}`);
37
+ }
38
+ return new BeaconCohortSignatureAuthorizationMessage(message);
39
+ }
40
+ }
@@ -0,0 +1,153 @@
1
+ import { Maybe, NotImplementedError } from '@did-btcr2/common';
2
+ import { RawSchnorrKeyPair, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
3
+ import { Identifier } from '../../../../identifier.js';
4
+ import { AggregateBeaconMessageType } from '../../cohort/messages/index.js';
5
+ import { CommunicationService, MessageHandler, ServiceAdapterConfig, ServiceAdapterIdentity } from '../service.js';
6
+
7
+ /**
8
+ * DidCommAdapterConfig is a configuration class for the DidCommAdapter.
9
+ * It holds the necessary parameters to connect to Nostr relays and manage keys.
10
+ * @class DidCommAdapterConfig
11
+ * @implements {ServiceAdapterConfig}
12
+ * @type {DidCommAdapterConfig}
13
+ */
14
+ export class DidCommAdapterConfig implements ServiceAdapterConfig {
15
+ public keys: RawSchnorrKeyPair;
16
+ public components: {
17
+ idType: string;
18
+ version: number;
19
+ network: string;
20
+ };
21
+ public did: string;
22
+ public coordinatorDids: string[];
23
+
24
+ /**
25
+ * Constructs a new DidCommAdapterConfig instance.
26
+ * @param {Partial<ServiceAdapterConfig>} [config] Optional configuration parameters to initialize the adapter.
27
+ * @constructor
28
+ * @type {DidCommAdapterConfig}
29
+ */
30
+ constructor(config?: Partial<ServiceAdapterConfig>) {
31
+ this.keys = config?.keys || SchnorrKeyPair.generate().raw,
32
+ this.components = config?.components || {
33
+ version : 1,
34
+ idType : 'KEY',
35
+ network : 'mutinynet'
36
+ };
37
+ this.did = config?.did || Identifier.encode(
38
+ {
39
+ ...this.components,
40
+ genesisBytes : this.keys.public
41
+ }
42
+ );
43
+ this.coordinatorDids = config?.coordinatorDids || [];
44
+ }
45
+ }
46
+
47
+ /**
48
+ * DidCommAdapter implements the CommunicationService interface for DidComm protocol.
49
+ * It handles message sending, receiving, and identity generation using DidComm.
50
+ * @class DidCommAdapter
51
+ * @implements {CommunicationService}
52
+ * @type {DidCommAdapter}
53
+ */
54
+ export class DidCommAdapter implements CommunicationService {
55
+ /**
56
+ * The name of the communication service.
57
+ * @type {string}
58
+ */
59
+ public name: string = 'didcomm';
60
+
61
+ /**
62
+ * The configuration for the DidComm adapter.
63
+ * @type {DidCommAdapterConfig}
64
+ */
65
+ public config: DidCommAdapterConfig;
66
+
67
+ /**
68
+ * A map of message handlers for different message types.
69
+ * @type {Map<string, MessageHandler>}
70
+ */
71
+ private handlers: Map<string, MessageHandler> = new Map();
72
+
73
+ /**
74
+ * Constructs a new DidCommAdapter instance with the provided configuration.
75
+ * @param {DidCommAdapterConfig} [config] The configuration for the Nostr adapter.
76
+ */
77
+ constructor(config: DidCommAdapterConfig = {} as DidCommAdapterConfig) {
78
+ this.config = new DidCommAdapterConfig(config);
79
+ }
80
+
81
+ /**
82
+ * Starts the DidComm service.
83
+ * @returns {void} Returns the DidCommAdapter instance for method chaining.
84
+ */
85
+ public start(): void {
86
+ throw new NotImplementedError('DidCommAdapter is not implemented. Use NostrAdapter instead.');
87
+ }
88
+
89
+ /**
90
+ * Sets the keys used for Nostr communication.
91
+ * @param {ServiceAdapterIdentity<NostrKeys>} keys The keys to set.
92
+ */
93
+ public setKeys(keys: ServiceAdapterIdentity<RawSchnorrKeyPair>): void {
94
+ this.config.keys = keys;
95
+ }
96
+
97
+ /**
98
+ * Registers a message handler for a specific message type.
99
+ * @param {string} messageType The type of message to handle.
100
+ * @param {MessageHandler} handler The handler function that processes the message.
101
+ */
102
+ public registerMessageHandler(messageType: string, handler: MessageHandler): void {
103
+ this.handlers.set(messageType, handler);
104
+ }
105
+
106
+ /**
107
+ * Sends a message to a recipient using the Nostr protocol.
108
+ * This method is a placeholder and should be implemented with actual Nostr message sending logic.
109
+ * @param {Maybe<AggregateBeaconMessageType>} _message The message to send, typically containing the content and metadata.
110
+ * @param {string} _recipient The public key or identifier of the recipient.
111
+ * @param {string} _sender The public key or identifier of the sender.
112
+ * @returns {Promise<void>} A promise that resolves when the message is sent.
113
+ */
114
+ public async sendMessage(
115
+ _message: Maybe<AggregateBeaconMessageType>,
116
+ _recipient: string,
117
+ _sender: string
118
+ ): Promise<void | Promise<string>[]> {
119
+ throw new NotImplementedError('DidCommAdapter.start() is not implemented. Use NostrAdapter instead.');
120
+ }
121
+
122
+ /**
123
+ * Generates a DidComm identity.
124
+ * @param {RawKeyPair} [keys] Optional keys to use for identity generation.
125
+ * @returns {ServiceAdapterConfig} The generated DidComm identity configuration.
126
+ */
127
+ public generateIdentity(keys?: RawSchnorrKeyPair): ServiceAdapterConfig {
128
+ if(!keys) {
129
+ this.config.keys.secret = Secp256k1SecretKey.random();
130
+ this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
131
+ this.config.did = Identifier.encode(
132
+ {
133
+ idType : this.config.components.idType || 'KEY',
134
+ version : this.config.components.version || 1,
135
+ network : this.config.components.network || 'signet',
136
+ genesisBytes : this.config.keys.public
137
+ }
138
+ );
139
+ return this.config as ServiceAdapterConfig;
140
+ }
141
+
142
+ this.config.keys = keys;
143
+ this.config.did = Identifier.encode(
144
+ {
145
+ idType : this.config.components.idType || 'KEY',
146
+ version : this.config.components.version || 1,
147
+ network : this.config.components.network || 'signet',
148
+ genesisBytes : this.config.keys.public
149
+ }
150
+ );
151
+ return this.config as ServiceAdapterConfig;
152
+ }
153
+ }
@@ -0,0 +1,300 @@
1
+ import { Did, Maybe } from '@did-btcr2/common';
2
+ import { CompressedSecp256k1PublicKey, RawSchnorrKeyPair, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
3
+ import { nonceGen } from '@scure/btc-signer/musig2';
4
+ import { Event, EventTemplate, Filter, finalizeEvent, nip44 } from 'nostr-tools';
5
+ import { SimplePool } from 'nostr-tools/pool';
6
+ import { Identifier } from '../../../../identifier.js';
7
+ import {
8
+ BEACON_COHORT_ADVERT,
9
+ BEACON_COHORT_AGGREGATED_NONCE,
10
+ BEACON_COHORT_AUTHORIZATION_REQUEST,
11
+ BEACON_COHORT_NONCE_CONTRIBUTION,
12
+ BEACON_COHORT_OPT_IN,
13
+ BEACON_COHORT_OPT_IN_ACCEPT,
14
+ BEACON_COHORT_READY,
15
+ BEACON_COHORT_REQUEST_SIGNATURE,
16
+ BEACON_COHORT_SIGNATURE_AUTHORIZATION
17
+ } from '../../cohort/messages/constants.js';
18
+ import { AggregateBeaconMessage, AggregateBeaconMessageType } from '../../cohort/messages/index.js';
19
+ import { CommunicationAdapterError } from '../error.js';
20
+ import { CommunicationService, MessageHandler, ServiceAdapter, ServiceAdapterConfig, ServiceAdapterIdentity } from '../service.js';
21
+
22
+ /**
23
+ * DEFAULT_NOSTR_RELAYS provides a list of default Nostr relay URLs for communication.
24
+ * These relays are used to connect to the Nostr network for sending and receiving messages.
25
+ * @constant {Array<string>} DEFAULT_NOSTR_RELAYS
26
+ */
27
+ export const DEFAULT_NOSTR_RELAYS = [
28
+ 'wss://relay.damus.io',
29
+ // 'wss://nos.lol',
30
+ // 'wss://relay.snort.social',
31
+ // 'wss://nostr-pub.wellorder.net',
32
+ ];
33
+
34
+ /**
35
+ * NostrAdapterConfig defines the configuration structure for the Nostr communication adapter.
36
+ * It includes relay URLs, key pairs, and components for identity generation.
37
+ * @interface NostrAdapterConfig
38
+ * @type {NostrAdapterConfig}
39
+ */
40
+ export interface NostrAdapterConfig {
41
+ keys: RawSchnorrKeyPair;
42
+ did?: string;
43
+ components: {
44
+ idType?: string;
45
+ version?: number;
46
+ network?: string;
47
+ };
48
+ relays: string[];
49
+ [key: string]: any;
50
+ }
51
+
52
+ export class NostrAdapter implements CommunicationService {
53
+ /**
54
+ * The name of the NostrAdapter service.
55
+ * @type {string}
56
+ */
57
+ public name: string = 'nostr';
58
+
59
+ /**
60
+ * The configuration for the NostrAdapter.
61
+ * @type {NostrAdapterConfig}
62
+ */
63
+ public config: NostrAdapterConfig;
64
+
65
+ /**
66
+ * A map of message handlers for different message types.
67
+ * @type {Map<string, MessageHandler>}
68
+ */
69
+ private handlers: Map<string, MessageHandler> = new Map();
70
+
71
+ /**
72
+ * The SimplePool instance for managing Nostr subscriptions.
73
+ * @type {SimplePool}
74
+ */
75
+ public pool?: SimplePool;
76
+
77
+ /**
78
+ * Constructs a new NostrAdapter instance with the given configuration.
79
+ * @param {NostrAdapterConfig} config - The configuration for the NostrAdapter.
80
+ * If no configuration is provided, a new key pair is generated and default relays are used.
81
+ * @constructor
82
+ */
83
+ constructor(config: NostrAdapterConfig = { keys: {} as RawSchnorrKeyPair, components: {}, relays: DEFAULT_NOSTR_RELAYS }) {
84
+ this.config = config;
85
+ this.config.keys = this.config.keys || SchnorrKeyPair.generate().raw;
86
+ this.config.did = config.did || Identifier.encode({
87
+ idType : config.components.idType || 'KEY',
88
+ version : config.components.version || 1,
89
+ network : config.components.network || 'signet',
90
+ genesisBytes : this.config.keys.public!
91
+ });
92
+ }
93
+
94
+ /**
95
+ * Sets the keys for the NostrAdapter.
96
+ * @param {ServiceAdapterIdentity<RawSchnorrKeyPair>} keys - The key pair to set.
97
+ */
98
+ public setKeys(keys: ServiceAdapterIdentity<RawSchnorrKeyPair>): void {
99
+ this.config.keys = keys;
100
+ }
101
+
102
+
103
+ /**
104
+ * Starts the Nostr communication service by subscribing to relays.
105
+ * @returns {ServiceAdapter<NostrAdapter>} Returns the NostrAdapter instance for method chaining.
106
+ */
107
+ public start(): ServiceAdapter<NostrAdapter> {
108
+ this.pool = new SimplePool();
109
+
110
+ this.pool.subscribe(this.config.relays, { kinds: [1] } as Filter, {
111
+ onclose : (reasons: string[]) => console.log('Subscription to kind 1 closed', reasons),
112
+ onevent : this.onEvent.bind(this),
113
+ });
114
+
115
+ // this.pool.subscribe(this.config.relays, { kinds: [1059] } as Filter, {
116
+ // onclose : (reasons: string[]) => console.log('Subscription to kind 1059 closed for reasons:', reasons),
117
+ // onevent : this.onEvent.bind(this),
118
+ // oneose : () => { Logger.info('EOSE kinds 1059'); }
119
+ // });
120
+
121
+ return this;
122
+ }
123
+
124
+
125
+ /**
126
+ * Handles incoming Nostr events and dispatches them to the appropriate message handler.
127
+ * @param {Event} event The Nostr event received from the relay.
128
+ */
129
+ private async onEvent(event: Event): Promise<void> {
130
+ // Logger.debug('nostr.onEvent: event.tags', event.tags);
131
+ // Dispatch the event to the registered handler
132
+ const ptags = event.tags.filter(([name, _]) => name === 'p') ?? [];
133
+ // Logger.debug('nostr.onEvent: event.tags.find => ptags', ptags);
134
+
135
+ for(const [p, pk] of ptags ){
136
+ if(pk === 'b71d3052dcdc8ba4564388948b655b58aaa7f37497ef1fc98829f9191adc8f85') {
137
+ console.debug('nostr.onEvent: event.tags.find => p, pk', p, pk);
138
+ }
139
+ }
140
+ // if(!type && !value) {
141
+ // // Logger.warn(`Event ${event.id} does not have a valid tag, skipping handler dispatch.`);
142
+ // return;
143
+ // }
144
+ // Logger.debug('nostr.onEvent: event.tags.find => type, value', type, value);
145
+
146
+ // Logger.debug('nostr.onEvent: event', event);
147
+ // Logger.debug('nostr.onEvent: event.tags', event.tags);
148
+
149
+ // if(event.kind === 1 && !AggregateBeaconMessage.isKeyGenMessageValue(value)) {
150
+ // Logger.warn(`Event ${event.id} is not a key generation message type: ${value}, skipping handler dispatch.`);
151
+ // return;
152
+ // }
153
+
154
+ // if(event.kind === 1059 && !AggregateBeaconMessage.isSignMessageValue(value)) {
155
+ // Logger.warn(`Event ${event.id} has an invalid title tag: ${value}, skipping handler dispatch.`);
156
+ // return;
157
+ // }
158
+
159
+ // const handler = this.handlers.get(value);
160
+ // if (!handler) {
161
+ // Logger.warn(`No handler found for message with tag value: ${value}`);
162
+ // return;
163
+ // }
164
+
165
+ // await handler(event);
166
+ }
167
+
168
+ /**
169
+ * Registers a message handler for a specific message type.
170
+ * @param {string} messageType The type of message to handle.
171
+ * @param {MessageHandler} handler The handler function that processes the message.
172
+ */
173
+ public registerMessageHandler(messageType: string, handler: MessageHandler): void {
174
+ this.handlers.set(messageType, handler);
175
+ }
176
+
177
+
178
+ /**
179
+ * Sends a message to a recipient using the Nostr protocol.
180
+ * This method is a placeholder and should be implemented with actual Nostr message sending logic.
181
+ * @param {Maybe<AggregateBeaconMessageType>} message The message to send, typically containing the content and metadata.
182
+ * @param {Did} from The identifier of the sender.
183
+ * @param {Did} [to] The identifier of the recipient.
184
+ * @returns {Promise<void>} A promise that resolves when the message is sent.
185
+ */
186
+ 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
188
+ if(
189
+ [from, to]
190
+ .filter(did => !!did)
191
+ .every(did => !Identifier.isValid(did!))
192
+ ) {
193
+ console.error(`Invalid Btc1 identifiers: sender ${from}, recipient ${to}`);
194
+ throw new CommunicationAdapterError(
195
+ `Invalid identifiers: sender ${from}, recipient ${to}`,
196
+ 'SEND_MESSAGE_ERROR', { adapter: this.name }
197
+ );
198
+ }
199
+ // Decode the sender and recipient DIDs to get their genesis bytes in hex
200
+ const sender = new CompressedSecp256k1PublicKey(Identifier.decode(from).genesisBytes);
201
+ console.info(`Sending message from ${sender}:`, message);
202
+
203
+ // if(message.type === BEACON_COHORT_SUBSCRIBE_ACCEPT) {
204
+ // this.config.coordinatorDids.push(recipient);
205
+ // }
206
+
207
+ const tags = [['p', Buffer.from(sender.x).toString('hex')]];
208
+ if(to) {
209
+ const recipient = new CompressedSecp256k1PublicKey(Identifier.decode(to).genesisBytes);
210
+ tags.push(['p', Buffer.from(recipient.x).toString('hex')]);
211
+ }
212
+
213
+ if(AggregateBeaconMessage.isKeyGenMessageValue(message.type)) {
214
+ switch(message.type) {
215
+ case BEACON_COHORT_ADVERT:
216
+ console.info('Add tag', ['BEACON_COHORT_ADVERT', message.type]);
217
+ break;
218
+ case BEACON_COHORT_OPT_IN:
219
+ console.info('Add tag', ['BEACON_COHORT_OPT_IN', message.type]);
220
+ break;
221
+ case BEACON_COHORT_OPT_IN_ACCEPT:
222
+ console.info('Add tag', ['BEACON_COHORT_OPT_IN_ACCEPT', message.type]);
223
+ break;
224
+ case BEACON_COHORT_READY:
225
+ console.info('Add tag', ['BEACON_COHORT_READY', message.type]);
226
+ break;
227
+ }
228
+ const event = finalizeEvent({
229
+ kind : 1,
230
+ created_at : Math.floor(Date.now() / 1000),
231
+ tags,
232
+ content : JSON.stringify(message)
233
+ } as EventTemplate, this.config.keys.secret!);
234
+ console.info(`Sending message kind 1 event ...`, event);
235
+ return this.pool?.publish(this.config.relays, event);
236
+ }
237
+
238
+ if(AggregateBeaconMessage.isSignMessageValue(message.type)) {
239
+ switch(message.type) {
240
+ case BEACON_COHORT_REQUEST_SIGNATURE:
241
+ console.info('Add tag', ['BEACON_COHORT_REQUEST_SIGNATURE', message.type]);
242
+ break;
243
+ case BEACON_COHORT_AUTHORIZATION_REQUEST:
244
+ console.info('Add tag', ['BEACON_COHORT_AUTHORIZATION_REQUEST', message.type]);
245
+ break;
246
+ case BEACON_COHORT_NONCE_CONTRIBUTION:
247
+ console.info('Add tag', ['BEACON_COHORT_NONCE_CONTRIBUTION', message.type]);
248
+ break;
249
+ case BEACON_COHORT_AGGREGATED_NONCE:
250
+ console.info('Add tag', ['BEACON_COHORT_AGGREGATED_NONCE', message.type]);
251
+ break;
252
+ case BEACON_COHORT_SIGNATURE_AUTHORIZATION:
253
+ console.info('Add tag', ['BEACON_COHORT_SIGNATURE_AUTHORIZATION', message.type]);
254
+ break;
255
+ }
256
+ const { publicKey, secretKey } = SchnorrKeyPair.generate();
257
+ const content = nip44.encrypt(JSON.stringify(message), secretKey.bytes, nonceGen(publicKey.x).public);
258
+ console.debug('NostrAdapter content:', content);
259
+
260
+ const event = finalizeEvent({ content, tags, kind: 1059 } as EventTemplate, this.config.keys.secret!);
261
+ console.debug('NostrAdapter event:', event);
262
+
263
+ return this.pool?.publish(this.config.relays, event);
264
+ }
265
+
266
+ console.error(`Unsupported message type: ${message.type}`);
267
+ }
268
+
269
+ /**
270
+ * Generates a Nostr identity using the Secp256k1SecretKey and Identifier classes.
271
+ * @param {RawSchnorrKeyPair} [keys] Optional keys to use for identity generation.
272
+ * @returns {ServiceAdapterConfig} The generated Nostr identity configuration.
273
+ */
274
+ public generateIdentity(keys?: RawSchnorrKeyPair): ServiceAdapterConfig {
275
+ if(!keys) {
276
+ this.config.keys.secret = Secp256k1SecretKey.random();
277
+ this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
278
+ this.config.did = Identifier.encode(
279
+ {
280
+ idType : this.config.components.idType || 'KEY',
281
+ version : this.config.components.version || 1,
282
+ network : this.config.components.network || 'signet',
283
+ genesisBytes : this.config.keys.public
284
+ }
285
+ );
286
+ return this.config as ServiceAdapterConfig;
287
+ }
288
+
289
+ this.config.keys = keys;
290
+ this.config.did = Identifier.encode(
291
+ {
292
+ idType : this.config.components.idType || 'KEY',
293
+ version : this.config.components.version || 1,
294
+ network : this.config.components.network || 'signet',
295
+ genesisBytes : this.config.keys.public
296
+ }
297
+ );
298
+ return this.config as ServiceAdapterConfig;
299
+ }
300
+ }