@did-btcr2/method 0.26.0 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +86 -233
  2. package/dist/.tsbuildinfo +1 -1
  3. package/dist/browser.js +24111 -20342
  4. package/dist/browser.mjs +24111 -20342
  5. package/dist/cjs/index.js +2463 -2174
  6. package/dist/esm/core/aggregation/cohort.js +178 -0
  7. package/dist/esm/core/aggregation/cohort.js.map +1 -0
  8. package/dist/esm/core/aggregation/errors.js +22 -0
  9. package/dist/esm/core/aggregation/errors.js.map +1 -0
  10. package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
  11. package/dist/esm/core/aggregation/messages/base.js.map +1 -0
  12. package/dist/esm/core/aggregation/messages/constants.js +26 -0
  13. package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
  14. package/dist/esm/core/aggregation/messages/factories.js +113 -0
  15. package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
  16. package/dist/esm/core/aggregation/messages/guards.js +37 -0
  17. package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
  18. package/dist/esm/core/aggregation/messages/index.js +5 -0
  19. package/dist/esm/core/aggregation/messages/index.js.map +1 -0
  20. package/dist/esm/core/aggregation/participant.js +376 -0
  21. package/dist/esm/core/aggregation/participant.js.map +1 -0
  22. package/dist/esm/core/aggregation/phases.js +39 -0
  23. package/dist/esm/core/aggregation/phases.js.map +1 -0
  24. package/dist/esm/core/aggregation/runner/events.js +2 -0
  25. package/dist/esm/core/aggregation/runner/events.js.map +1 -0
  26. package/dist/esm/core/aggregation/runner/index.js +5 -0
  27. package/dist/esm/core/aggregation/runner/index.js.map +1 -0
  28. package/dist/esm/core/aggregation/runner/participant-runner.js +282 -0
  29. package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
  30. package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
  31. package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
  32. package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
  33. package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
  34. package/dist/esm/core/aggregation/service.js +416 -0
  35. package/dist/esm/core/aggregation/service.js.map +1 -0
  36. package/dist/esm/core/aggregation/signing-session.js +133 -0
  37. package/dist/esm/core/aggregation/signing-session.js.map +1 -0
  38. package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
  39. package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
  40. package/dist/esm/core/aggregation/transport/error.js +12 -0
  41. package/dist/esm/core/aggregation/transport/error.js.map +1 -0
  42. package/dist/esm/core/aggregation/transport/factory.js +20 -0
  43. package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
  44. package/dist/esm/core/aggregation/transport/index.js +6 -0
  45. package/dist/esm/core/aggregation/transport/index.js.map +1 -0
  46. package/dist/esm/core/aggregation/transport/nostr.js +262 -0
  47. package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
  48. package/dist/esm/core/aggregation/transport/transport.js +2 -0
  49. package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
  50. package/dist/esm/core/beacon/beacon.js +80 -0
  51. package/dist/esm/core/beacon/beacon.js.map +1 -1
  52. package/dist/esm/core/beacon/cas-beacon.js +15 -56
  53. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  54. package/dist/esm/core/beacon/error.js +0 -10
  55. package/dist/esm/core/beacon/error.js.map +1 -1
  56. package/dist/esm/core/beacon/fee-estimator.js +30 -0
  57. package/dist/esm/core/beacon/fee-estimator.js.map +1 -0
  58. package/dist/esm/core/beacon/singleton-beacon.js +10 -53
  59. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  60. package/dist/esm/core/beacon/smt-beacon.js +85 -9
  61. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  62. package/dist/esm/core/identifier.js +13 -0
  63. package/dist/esm/core/identifier.js.map +1 -1
  64. package/dist/esm/core/resolver.js +9 -0
  65. package/dist/esm/core/resolver.js.map +1 -1
  66. package/dist/esm/index.js +14 -24
  67. package/dist/esm/index.js.map +1 -1
  68. package/dist/types/core/aggregation/cohort.d.ts +94 -0
  69. package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
  70. package/dist/types/core/aggregation/errors.d.ts +14 -0
  71. package/dist/types/core/aggregation/errors.d.ts.map +1 -0
  72. package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
  73. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
  74. package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
  75. package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
  76. package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
  77. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
  78. package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
  79. package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
  80. package/dist/types/core/aggregation/messages/index.d.ts +5 -0
  81. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
  82. package/dist/types/core/aggregation/participant.d.ts +101 -0
  83. package/dist/types/core/aggregation/participant.d.ts.map +1 -0
  84. package/dist/types/core/aggregation/phases.d.ts +49 -0
  85. package/dist/types/core/aggregation/phases.d.ts.map +1 -0
  86. package/dist/types/core/aggregation/runner/events.d.ts +89 -0
  87. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
  88. package/dist/types/core/aggregation/runner/index.d.ts +5 -0
  89. package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
  90. package/dist/types/core/aggregation/runner/participant-runner.d.ts +107 -0
  91. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
  92. package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
  93. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
  94. package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
  95. package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
  96. package/dist/types/core/aggregation/service.d.ts +112 -0
  97. package/dist/types/core/aggregation/service.d.ts.map +1 -0
  98. package/dist/types/core/aggregation/signing-session.d.ts +69 -0
  99. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
  100. package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
  101. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
  102. package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
  103. package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
  104. package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
  105. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
  106. package/dist/types/core/aggregation/transport/index.d.ts +6 -0
  107. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
  108. package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
  109. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
  110. package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
  111. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
  112. package/dist/types/core/beacon/beacon.d.ts +37 -2
  113. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  114. package/dist/types/core/beacon/cas-beacon.d.ts +19 -7
  115. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  116. package/dist/types/core/beacon/error.d.ts +0 -6
  117. package/dist/types/core/beacon/error.d.ts.map +1 -1
  118. package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
  119. package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
  120. package/dist/types/core/beacon/interfaces.d.ts +8 -0
  121. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  122. package/dist/types/core/beacon/singleton-beacon.d.ts +9 -2
  123. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  124. package/dist/types/core/beacon/smt-beacon.d.ts +27 -7
  125. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  126. package/dist/types/core/identifier.d.ts +8 -0
  127. package/dist/types/core/identifier.d.ts.map +1 -1
  128. package/dist/types/core/interfaces.d.ts +2 -2
  129. package/dist/types/core/resolver.d.ts +11 -1
  130. package/dist/types/core/resolver.d.ts.map +1 -1
  131. package/dist/types/index.d.ts +9 -24
  132. package/dist/types/index.d.ts.map +1 -1
  133. package/package.json +31 -30
  134. package/src/core/aggregation/cohort.ts +247 -0
  135. package/src/core/aggregation/errors.ts +25 -0
  136. package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
  137. package/src/core/aggregation/messages/constants.ts +28 -0
  138. package/src/core/aggregation/messages/factories.ts +240 -0
  139. package/src/core/aggregation/messages/guards.ts +55 -0
  140. package/src/core/aggregation/messages/index.ts +4 -0
  141. package/src/core/aggregation/participant.ts +510 -0
  142. package/src/core/aggregation/phases.ts +82 -0
  143. package/src/core/aggregation/runner/events.ts +77 -0
  144. package/src/core/aggregation/runner/index.ts +4 -0
  145. package/src/core/aggregation/runner/participant-runner.ts +360 -0
  146. package/src/core/aggregation/runner/service-runner.ts +365 -0
  147. package/src/core/aggregation/runner/typed-emitter.ts +87 -0
  148. package/src/core/aggregation/service.ts +547 -0
  149. package/src/core/aggregation/signing-session.ts +209 -0
  150. package/src/core/aggregation/transport/didcomm.ts +42 -0
  151. package/src/core/aggregation/transport/error.ts +13 -0
  152. package/src/core/aggregation/transport/factory.ts +29 -0
  153. package/src/core/aggregation/transport/index.ts +5 -0
  154. package/src/core/aggregation/transport/nostr.ts +333 -0
  155. package/src/core/aggregation/transport/transport.ts +46 -0
  156. package/src/core/beacon/beacon.ts +122 -2
  157. package/src/core/beacon/cas-beacon.ts +28 -76
  158. package/src/core/beacon/error.ts +0 -12
  159. package/src/core/beacon/fee-estimator.ts +52 -0
  160. package/src/core/beacon/interfaces.ts +10 -1
  161. package/src/core/beacon/singleton-beacon.ts +14 -75
  162. package/src/core/beacon/smt-beacon.ts +109 -11
  163. package/src/core/identifier.ts +17 -0
  164. package/src/core/interfaces.ts +2 -2
  165. package/src/core/resolver.ts +25 -2
  166. package/src/index.ts +15 -29
  167. package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
  168. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
  169. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  170. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  171. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  172. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
  173. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  174. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  175. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  176. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  177. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  178. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  179. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  180. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  181. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  182. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  183. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  184. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  185. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  186. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  187. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  188. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  189. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  190. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  191. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  192. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  193. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  194. package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
  195. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
  196. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  197. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  198. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -245
  199. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  200. package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
  201. package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
  202. package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
  203. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
  204. package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
  205. package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
  206. package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
  207. package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
  208. package/dist/esm/core/beacon/aggregation/participant.js +0 -435
  209. package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
  210. package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
  211. package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
  212. package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
  213. package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
  214. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
  215. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
  216. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
  217. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
  218. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
  219. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
  220. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
  221. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
  222. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
  223. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
  224. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
  225. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
  226. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
  227. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
  228. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
  229. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
  230. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
  231. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
  232. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
  233. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
  234. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
  235. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
  236. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
  237. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
  238. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
  239. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
  240. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
  241. package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
  242. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
  243. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
  244. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
  245. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
  246. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
  247. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
  248. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
  249. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
  250. package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
  251. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
  252. package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
  253. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
  254. package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
  255. package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
  256. package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
  257. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
  258. package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
  259. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
  260. package/src/core/beacon/aggregation/cohort/index.ts +0 -305
  261. package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
  262. package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
  263. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -44
  264. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -40
  265. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -35
  266. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -34
  267. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -36
  268. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -39
  269. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -40
  270. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -40
  271. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -40
  272. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -41
  273. package/src/core/beacon/aggregation/cohort/status.ts +0 -7
  274. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -148
  275. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -323
  276. package/src/core/beacon/aggregation/communication/error.ts +0 -13
  277. package/src/core/beacon/aggregation/communication/factory.ts +0 -25
  278. package/src/core/beacon/aggregation/communication/service.ts +0 -42
  279. package/src/core/beacon/aggregation/coordinator.ts +0 -419
  280. package/src/core/beacon/aggregation/participant.ts +0 -517
  281. package/src/core/beacon/aggregation/session/index.ts +0 -301
  282. package/src/core/beacon/aggregation/session/status.ts +0 -18
@@ -1,148 +0,0 @@
1
- import { NotImplementedError } from '@did-btcr2/common';
2
- import type { RawSchnorrKeyPair} from '@did-btcr2/keypair';
3
- import { SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
4
- import { Identifier } from '../../../../identifier.js';
5
- import type { AggregateBeaconMessageType } from '../../cohort/messages/index.js';
6
- import type { BaseMessage } from '../../cohort/messages/base.js';
7
- import type { CommunicationService, MessageHandler, ServiceAdapterConfig, ServiceAdapterIdentity } from '../service.js';
8
-
9
- /**
10
- * DidCommAdapterConfig is a configuration class for the DidCommAdapter.
11
- * It holds the necessary parameters to connect to Nostr relays and manage keys.
12
- * @class DidCommAdapterConfig
13
- * @implements {ServiceAdapterConfig}
14
- * @type {DidCommAdapterConfig}
15
- */
16
- export class DidCommAdapterConfig implements ServiceAdapterConfig {
17
- public keys: RawSchnorrKeyPair;
18
- public components: {
19
- idType: string;
20
- version: number;
21
- network: string;
22
- };
23
- public did: string;
24
- public coordinatorDids: string[];
25
-
26
- /**
27
- * Constructs a new DidCommAdapterConfig instance.
28
- * @param {Partial<ServiceAdapterConfig>} [config] Optional configuration parameters to initialize the adapter.
29
- * @constructor
30
- * @type {DidCommAdapterConfig}
31
- */
32
- constructor(config?: Partial<ServiceAdapterConfig>) {
33
- this.keys = config?.keys || SchnorrKeyPair.generate().raw,
34
- this.components = config?.components || {
35
- version : 1,
36
- idType : 'KEY',
37
- network : 'mutinynet'
38
- };
39
- this.did = config?.did || Identifier.encode(this.keys.public, this.components);
40
- this.coordinatorDids = config?.coordinatorDids || [];
41
- }
42
- }
43
-
44
- /**
45
- * DidCommAdapter implements the CommunicationService interface for DidComm protocol.
46
- * It handles message sending, receiving, and identity generation using DidComm.
47
- * @class DidCommAdapter
48
- * @implements {CommunicationService}
49
- * @type {DidCommAdapter}
50
- */
51
- export class DidCommAdapter implements CommunicationService {
52
- /**
53
- * The name of the communication service.
54
- * @type {string}
55
- */
56
- public name: string = 'didcomm';
57
-
58
- /**
59
- * The configuration for the DidComm adapter.
60
- * @type {DidCommAdapterConfig}
61
- */
62
- public config: DidCommAdapterConfig;
63
-
64
- /**
65
- * A map of message handlers for different message types.
66
- * @type {Map<string, MessageHandler>}
67
- */
68
- private handlers: Map<string, MessageHandler> = new Map();
69
-
70
- /**
71
- * Constructs a new DidCommAdapter instance with the provided configuration.
72
- * @param {DidCommAdapterConfig} [config] The configuration for the Nostr adapter.
73
- */
74
- constructor(config: DidCommAdapterConfig = {} as DidCommAdapterConfig) {
75
- this.config = new DidCommAdapterConfig(config);
76
- }
77
-
78
- /**
79
- * Starts the DidComm service.
80
- * @returns {void} Returns the DidCommAdapter instance for method chaining.
81
- */
82
- public start(): void {
83
- throw new NotImplementedError('DidCommAdapter is not implemented. Use NostrAdapter instead.');
84
- }
85
-
86
- /**
87
- * Sets the keys used for Nostr communication.
88
- * @param {ServiceAdapterIdentity<NostrKeys>} keys The keys to set.
89
- */
90
- public setKeys(keys: ServiceAdapterIdentity<RawSchnorrKeyPair>): void {
91
- this.config.keys = keys;
92
- }
93
-
94
- /**
95
- * Registers a message handler for a specific message type.
96
- * @param {string} messageType The type of message to handle.
97
- * @param {MessageHandler} handler The handler function that processes the message.
98
- */
99
- public registerMessageHandler(messageType: string, handler: MessageHandler): void {
100
- this.handlers.set(messageType, handler);
101
- }
102
-
103
- /**
104
- * Sends a message to a recipient using the Nostr protocol.
105
- * This method is a placeholder and should be implemented with actual Nostr message sending logic.
106
- * @param {AggregateBeaconMessageType} _message The message to send, typically containing the content and metadata.
107
- * @param {string} _recipient The public key or identifier of the recipient.
108
- * @param {string} _sender The public key or identifier of the sender.
109
- * @returns {Promise<void>} A promise that resolves when the message is sent.
110
- */
111
- public async sendMessage(
112
- _message: AggregateBeaconMessageType | BaseMessage,
113
- _recipient: string,
114
- _sender: string
115
- ): Promise<void | Promise<string>[]> {
116
- throw new NotImplementedError('DidCommAdapter.start() is not implemented. Use NostrAdapter instead.');
117
- }
118
-
119
- /**
120
- * Generates a DidComm identity.
121
- * @param {RawKeyPair} [keys] Optional keys to use for identity generation.
122
- * @returns {ServiceAdapterConfig} The generated DidComm identity configuration.
123
- */
124
- public generateIdentity(keys?: RawSchnorrKeyPair): ServiceAdapterConfig {
125
- if(!keys) {
126
- this.config.keys.secret = Secp256k1SecretKey.random();
127
- this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
128
- this.config.did = Identifier.encode(this.config.keys.public,
129
- {
130
- idType : this.config.components.idType || 'KEY',
131
- version : this.config.components.version || 1,
132
- network : this.config.components.network || 'regtest',
133
- }
134
- );
135
- return this.config as ServiceAdapterConfig;
136
- }
137
-
138
- this.config.keys = keys;
139
- this.config.did = Identifier.encode(this.config.keys.public,
140
- {
141
- idType : this.config.components.idType || 'KEY',
142
- version : this.config.components.version || 1,
143
- network : this.config.components.network || 'regtest',
144
- }
145
- );
146
- return this.config as ServiceAdapterConfig;
147
- }
148
- }
@@ -1,323 +0,0 @@
1
- // TODO: Finish nostr adapter implementation. Rethink patterns used.
2
-
3
- import type { Did } from '@did-btcr2/common';
4
- import type { RawSchnorrKeyPair} from '@did-btcr2/keypair';
5
- import { CompressedSecp256k1PublicKey, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
6
- import { bytesToHex } from '@noble/hashes/utils';
7
- import { nonceGen } from '@scure/btc-signer/musig2';
8
- import type { Event, EventTemplate, Filter} from 'nostr-tools';
9
- import { finalizeEvent, nip44, SimplePool } from 'nostr-tools';
10
- import { Identifier } from '../../../../identifier.js';
11
- import {
12
- BEACON_COHORT_ADVERT,
13
- BEACON_COHORT_AGGREGATED_NONCE,
14
- BEACON_COHORT_AUTHORIZATION_REQUEST,
15
- BEACON_COHORT_NONCE_CONTRIBUTION,
16
- BEACON_COHORT_OPT_IN,
17
- BEACON_COHORT_OPT_IN_ACCEPT,
18
- BEACON_COHORT_READY,
19
- BEACON_COHORT_REQUEST_SIGNATURE,
20
- BEACON_COHORT_SIGNATURE_AUTHORIZATION
21
- } from '../../cohort/messages/constants.js';
22
- import type { AggregateBeaconMessageType } from '../../cohort/messages/index.js';
23
- import { AggregateBeaconMessage } from '../../cohort/messages/index.js';
24
- import type { BaseMessage } from '../../cohort/messages/base.js';
25
- import { CommunicationAdapterError } from '../error.js';
26
- import type { CommunicationService, MessageHandler, ServiceAdapter, ServiceAdapterConfig, ServiceAdapterIdentity } from '../service.js';
27
-
28
- /**
29
- * TODO: Determine set of default Nostr relays to use.
30
- * DEFAULT_NOSTR_RELAYS provides a list of default Nostr relay URLs for communication.
31
- * These relays are used to connect to the Nostr network for sending and receiving messages.
32
- * @constant {Array<string>} DEFAULT_NOSTR_RELAYS
33
- */
34
- export const DEFAULT_NOSTR_RELAYS = [
35
- 'wss://relay.damus.io',
36
- // 'wss://nos.lol',
37
- // 'wss://relay.snort.social',
38
- // 'wss://nostr-pub.wellorder.net',
39
- ];
40
-
41
- /**
42
- * NostrAdapterConfig defines the configuration structure for the Nostr communication adapter.
43
- * It includes relay URLs, key pairs, and components for identity generation.
44
- * @interface NostrAdapterConfig
45
- * @type {NostrAdapterConfig}
46
- */
47
- export interface NostrAdapterConfig {
48
- keys: RawSchnorrKeyPair;
49
- did?: string;
50
- components: {
51
- idType?: string;
52
- version?: number;
53
- network?: string;
54
- };
55
- relays: string[];
56
- [key: string]: any;
57
- }
58
-
59
- /**
60
- * NostrAdapter implements the CommunicationService interface for Nostr protocol communication.
61
- * It provides methods for starting the service, sending messages, and handling incoming events.
62
- * @class NostrAdapter
63
- * @type {NostrAdapter}
64
- * @implements {CommunicationService}
65
- */
66
- export class NostrAdapter implements CommunicationService {
67
- /**
68
- * The name of the NostrAdapter service.
69
- * @type {string}
70
- */
71
- name: string = 'nostr';
72
-
73
- /**
74
- * The configuration for the NostrAdapter.
75
- * @type {NostrAdapterConfig}
76
- */
77
- config: NostrAdapterConfig;
78
-
79
- /**
80
- * A map of message handlers for different message types.
81
- * @type {Map<string, MessageHandler>}
82
- */
83
- #handlers: Map<string, MessageHandler> = new Map();
84
-
85
- /**
86
- * The SimplePool instance for managing Nostr subscriptions.
87
- * @type {SimplePool}
88
- */
89
- pool?: SimplePool;
90
-
91
- /**
92
- * Constructs a new NostrAdapter instance with the given configuration.
93
- * @param {NostrAdapterConfig} config - The configuration for the NostrAdapter.
94
- * If no configuration is provided, a new key pair is generated and default relays are used.
95
- * @constructor
96
- */
97
- constructor(config: NostrAdapterConfig = { keys: {} as RawSchnorrKeyPair, components: {}, relays: DEFAULT_NOSTR_RELAYS }) {
98
- this.config = config;
99
- this.config.keys = this.config.keys || SchnorrKeyPair.generate().raw;
100
- this.config.did = config.did || Identifier.encode(this.config.keys.public!, {
101
- idType : config.components.idType || 'KEY',
102
- version : config.components.version || 1,
103
- network : config.components.network || 'signet'
104
- });
105
- }
106
-
107
- /**
108
- * Sets the keys for the NostrAdapter.
109
- * @param {ServiceAdapterIdentity<RawSchnorrKeyPair>} keys - The key pair to set.
110
- */
111
- public setKeys(keys: ServiceAdapterIdentity<RawSchnorrKeyPair>): void {
112
- this.config.keys = keys;
113
- }
114
-
115
-
116
- /**
117
- * TODO: Complete this method. Figure out best subscription patterns.
118
- * Starts the Nostr communication service by subscribing to relays.
119
- * @returns {ServiceAdapter<NostrAdapter>} Returns the NostrAdapter instance for method chaining.
120
- */
121
- public start(): ServiceAdapter<NostrAdapter> {
122
- this.pool = new SimplePool();
123
-
124
- this.pool.subscribe(this.config.relays, { kinds: [1] } as Filter, {
125
- onclose : (reasons: string[]) => console.log('Subscription to kind 1 closed', reasons),
126
- onevent : this.onEvent.bind(this),
127
- });
128
-
129
- // this.pool.subscribe(this.config.relays, { kinds: [1059] } as Filter, {
130
- // onclose : (reasons: string[]) => console.log('Subscription to kind 1059 closed for reasons:', reasons),
131
- // onevent : this.onEvent.bind(this),
132
- // oneose : () => { Logger.info('EOSE kinds 1059'); }
133
- // });
134
-
135
- return this;
136
- }
137
-
138
-
139
- /**
140
- * TODO: Complete this method. Figure out best way to filter incoming nostr events.
141
- * Handles incoming Nostr events and dispatches them to the appropriate message handler.
142
- * @param {Event} event The Nostr event received from the relay.
143
- */
144
- private async onEvent(event: Event): Promise<void> {
145
- // Logger.debug('nostr.onEvent: event.tags', event.tags);
146
- // Dispatch the event to the registered handler
147
- const ptags = event.tags.filter(([name, _]) => name === 'p') ?? [];
148
- // Logger.debug('nostr.onEvent: event.tags.find => ptags', ptags);
149
-
150
- for(const [p, pk] of ptags ){
151
- if(pk === 'b71d3052dcdc8ba4564388948b655b58aaa7f37497ef1fc98829f9191adc8f85') {
152
- console.debug('nostr.onEvent: event.tags.find => p, pk', p, pk);
153
- }
154
- }
155
- // if(!type && !value) {
156
- // // Logger.warn(`Event ${event.id} does not have a valid tag, skipping handler dispatch.`);
157
- // return;
158
- // }
159
- // Logger.debug('nostr.onEvent: event.tags.find => type, value', type, value);
160
-
161
- // Logger.debug('nostr.onEvent: event', event);
162
- // Logger.debug('nostr.onEvent: event.tags', event.tags);
163
-
164
- // if(event.kind === 1 && !AggregateBeaconMessage.isKeyGenMessageValue(value)) {
165
- // Logger.warn(`Event ${event.id} is not a key generation message type: ${value}, skipping handler dispatch.`);
166
- // return;
167
- // }
168
-
169
- // if(event.kind === 1059 && !AggregateBeaconMessage.isSignMessageValue(value)) {
170
- // Logger.warn(`Event ${event.id} has an invalid title tag: ${value}, skipping handler dispatch.`);
171
- // return;
172
- // }
173
-
174
- // const handler = this.handlers.get(value);
175
- // if (!handler) {
176
- // Logger.warn(`No handler found for message with tag value: ${value}`);
177
- // return;
178
- // }
179
-
180
- // await handler(event);
181
- }
182
-
183
- /**
184
- * Registers a message handler for a specific message type.
185
- * @param {string} messageType The type of message to handle.
186
- * @param {MessageHandler} handler The handler function that processes the message.
187
- */
188
- public registerMessageHandler(messageType: string, handler: MessageHandler): void {
189
- this.#handlers.set(messageType, handler);
190
- }
191
-
192
-
193
- /**
194
- * TODO: Clean up and complete this method.
195
- * Sends a message to a recipient using the Nostr protocol.
196
- * This method is a placeholder and should be implemented with actual Nostr message sending logic.
197
- * @param {AggregateBeaconMessageType} message The message to send, typically containing the content and metadata.
198
- * @param {Did} from The identifier of the sender.
199
- * @param {Did} [to] The identifier of the recipient.
200
- * @returns {Promise<void>} A promise that resolves when the message is sent.
201
- */
202
- public async sendMessage(message: AggregateBeaconMessageType | BaseMessage, from: Did, to?: Did): Promise<void | Promise<string>[]> {
203
- // Check if the sender and recipient DIDs are valid identifiers
204
- if(
205
- [from, to]
206
- .filter(did => !!did)
207
- .every(did => !Identifier.isValid(did!))
208
- ) {
209
- console.error(`Invalid identifiers: sender ${from}, recipient ${to}`);
210
- throw new CommunicationAdapterError(
211
- `Invalid identifiers: sender ${from}, recipient ${to}`,
212
- 'SEND_MESSAGE_ERROR', { adapter: this.name }
213
- );
214
- }
215
- // Decode the sender and recipient DIDs to get their genesis bytes in hex
216
- const sender = new CompressedSecp256k1PublicKey(Identifier.decode(from).genesisBytes);
217
- console.info(`Sending message from ${sender}:`, message);
218
-
219
- // if(message.type === BEACON_COHORT_SUBSCRIBE_ACCEPT) {
220
- // this.config.coordinatorDids.push(recipient);
221
- // }
222
-
223
- const tags = [['p', bytesToHex(sender.x)]];
224
- if(to) {
225
- const recipient = new CompressedSecp256k1PublicKey(Identifier.decode(to).genesisBytes);
226
- tags.push(['p', bytesToHex(recipient.x)]);
227
- }
228
- const { type } = message as any ?? {};
229
- if(!type) {
230
- console.error('Message type is undefined:', message);
231
- throw new CommunicationAdapterError(
232
- 'Message type is undefined',
233
- 'SEND_MESSAGE_ERROR', { adapter: this.name }
234
- );
235
- }
236
-
237
- if(AggregateBeaconMessage.isKeyGenMessageValue(type)) {
238
- switch(type) {
239
- case BEACON_COHORT_ADVERT:
240
- console.info('Add tag', ['BEACON_COHORT_ADVERT', type]);
241
- break;
242
- case BEACON_COHORT_OPT_IN:
243
- console.info('Add tag', ['BEACON_COHORT_OPT_IN', type]);
244
- break;
245
- case BEACON_COHORT_OPT_IN_ACCEPT:
246
- console.info('Add tag', ['BEACON_COHORT_OPT_IN_ACCEPT', type]);
247
- break;
248
- case BEACON_COHORT_READY:
249
- console.info('Add tag', ['BEACON_COHORT_READY', type]);
250
- break;
251
- }
252
- const event = finalizeEvent({
253
- kind : 1,
254
- created_at : Math.floor(Date.now() / 1000),
255
- tags,
256
- content : JSON.stringify(message)
257
- } as EventTemplate, this.config.keys.secret!);
258
- console.info(`Sending message kind 1 event ...`, event);
259
- return this.pool?.publish(this.config.relays, event);
260
- }
261
-
262
- if(AggregateBeaconMessage.isSignMessageValue(type)) {
263
- switch(type) {
264
- case BEACON_COHORT_REQUEST_SIGNATURE:
265
- console.info('Add tag', ['BEACON_COHORT_REQUEST_SIGNATURE', type]);
266
- break;
267
- case BEACON_COHORT_AUTHORIZATION_REQUEST:
268
- console.info('Add tag', ['BEACON_COHORT_AUTHORIZATION_REQUEST', type]);
269
- break;
270
- case BEACON_COHORT_NONCE_CONTRIBUTION:
271
- console.info('Add tag', ['BEACON_COHORT_NONCE_CONTRIBUTION', type]);
272
- break;
273
- case BEACON_COHORT_AGGREGATED_NONCE:
274
- console.info('Add tag', ['BEACON_COHORT_AGGREGATED_NONCE', type]);
275
- break;
276
- case BEACON_COHORT_SIGNATURE_AUTHORIZATION:
277
- console.info('Add tag', ['BEACON_COHORT_SIGNATURE_AUTHORIZATION', type]);
278
- break;
279
- }
280
- const { publicKey, secretKey } = SchnorrKeyPair.generate();
281
- const content = nip44.encrypt(JSON.stringify(message), secretKey.bytes, nonceGen(publicKey.x).public);
282
- console.debug('NostrAdapter content:', content);
283
-
284
- const event = finalizeEvent({ content, tags, kind: 1059 } as EventTemplate, this.config.keys.secret!);
285
- console.debug('NostrAdapter event:', event);
286
-
287
- return this.pool?.publish(this.config.relays, event);
288
- }
289
-
290
- console.error(`Unsupported message type: ${type}`);
291
- }
292
-
293
- /**
294
- * TODO: Determine if this method is needed.
295
- * Generates a Nostr identity using the Secp256k1SecretKey and Identifier classes.
296
- * @param {RawSchnorrKeyPair} [keys] Optional keys to use for identity generation.
297
- * @returns {ServiceAdapterConfig} The generated Nostr identity configuration.
298
- */
299
- public generateIdentity(keys?: RawSchnorrKeyPair): ServiceAdapterConfig {
300
- if(!keys) {
301
- this.config.keys.secret = Secp256k1SecretKey.random();
302
- this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
303
- this.config.did = Identifier.encode(this.config.keys.public,
304
- {
305
- idType : this.config.components.idType || 'KEY',
306
- version : this.config.components.version || 1,
307
- network : this.config.components.network || 'signet',
308
- }
309
- );
310
- return this.config as ServiceAdapterConfig;
311
- }
312
-
313
- this.config.keys = keys;
314
- this.config.did = Identifier.encode(this.config.keys.public,
315
- {
316
- idType : this.config.components.idType || 'KEY',
317
- version : this.config.components.version || 1,
318
- network : this.config.components.network || 'signet',
319
- }
320
- );
321
- return this.config as ServiceAdapterConfig;
322
- }
323
- }
@@ -1,13 +0,0 @@
1
- import { MethodError } from '@did-btcr2/common';
2
-
3
- export class CommunicationServiceError extends MethodError {
4
- constructor(message: string, type: string = 'CommunicationServiceError', data?: Record<string, any>) {
5
- super(message, type, data);
6
- }
7
- }
8
-
9
- export class CommunicationAdapterError extends MethodError {
10
- constructor(message: string, type: string = 'CommunicationAdapterError', data?: Record<string, any>) {
11
- super(message, type, data);
12
- }
13
- }
@@ -1,25 +0,0 @@
1
- import { NotImplementedError } from '@did-btcr2/common';
2
- import { NostrAdapter } from './adapter/nostr.js';
3
- import { CommunicationServiceError } from './error.js';
4
- import type { CommunicationService, Service } from './service.js';
5
-
6
- /**
7
- * Communication Factory pattern to create Communication Service instances.
8
- * @class CommunicationFactory
9
- * @type {CommunicationFactory}
10
- */
11
- export class CommunicationFactory {
12
- static establish(service: Service): CommunicationService {
13
- switch (service.type) {
14
- case 'nostr':
15
- return new NostrAdapter();
16
- case 'didcomm':
17
- throw new NotImplementedError('DID Comm service not implemented yet.');
18
- default:
19
- throw new CommunicationServiceError(
20
- `Invalid service type ${service.type}`,
21
- 'INVALID_BEACON_ERROR', { service }
22
- );
23
- }
24
- }
25
- }
@@ -1,42 +0,0 @@
1
- import type { AggregateBeaconMessageType } from '../cohort/messages/index.js';
2
- import type { BaseMessage } from '../cohort/messages/base.js';
3
- import type { RawSchnorrKeyPair } from '@did-btcr2/keypair';
4
-
5
- /**
6
- * ServiceAdapterConfig defines the configuration structure for the Nostr communication service.
7
- * It includes relay URLs, key pairs, and components for identity generation.
8
- * @interface ServiceAdapterConfig
9
- * @extends {Record<string, any>}
10
- * @type {ServiceAdapterConfig}
11
- */
12
- export interface ServiceAdapterConfig extends Record<string, any> {
13
- keys: ServiceAdapterIdentity<any>;
14
- did: string;
15
- }
16
-
17
- export type SyncMessageHandler = (msg: any) => void;
18
- export type AsyncMessageHandler = (msg: any) => Promise<void>;
19
- export type MessageHandler = SyncMessageHandler | AsyncMessageHandler;
20
-
21
- export type CommunicationServiceType = 'nostr' | 'didcomm';
22
- export type ServiceAdapterConfigType<T extends ServiceAdapterConfig> = T;
23
- export interface Service {
24
- type: CommunicationServiceType;
25
- keys: ServiceAdapterIdentity<RawSchnorrKeyPair>;
26
- did: string;
27
- name?: string;
28
- }
29
- export type ServiceAdapter<T extends CommunicationService> = T;
30
- export type ServiceAdapterIdentity<T extends RawSchnorrKeyPair> = T;
31
- export interface CommunicationService {
32
- name: string;
33
- start(): void;
34
- setKeys(keys: ServiceAdapterIdentity<RawSchnorrKeyPair>): void;
35
- registerMessageHandler(messageType: string, handler: MessageHandler): void;
36
- sendMessage(
37
- message: AggregateBeaconMessageType | BaseMessage,
38
- sender: string,
39
- recipient?: string
40
- ): Promise<void | Promise<string>[]>;
41
- generateIdentity(keys?: RawSchnorrKeyPair): ServiceAdapterConfigType<ServiceAdapterConfig>;
42
- }