@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
@@ -1,81 +0,0 @@
1
- import { SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
2
- import { Filter } from 'nostr-tools';
3
- import { SimplePool, } from 'nostr-tools/pool';
4
- import { Identifier } from '../../../../utils/identifier.js';
5
- import { ProtocolService } from './service.js';
6
-
7
- export interface NostrAdapterConfig {
8
- keys: {
9
- secret?: Uint8Array;
10
- public?: Uint8Array;
11
- };
12
- did?: string;
13
- components: {
14
- idType?: string;
15
- version?: number;
16
- network?: string;
17
- };
18
- relays: string[];
19
- [key: string]: any;
20
- }
21
-
22
- export class NostrAdapter implements ProtocolService {
23
- public name: string = 'nostr';
24
- private config: NostrAdapterConfig;
25
- private handlers: Map<string, (msg: any) => Promise<void>> = new Map();
26
-
27
- constructor(config: NostrAdapterConfig = { keys: {}, components: {}, relays: ['wss://relay.damus.io'] }) {
28
- this.config = config;
29
- this.config.keys = this.config.keys || SchnorrKeyPair.generate().raw;
30
- this.config.did = config.did || Identifier.encode({
31
- idType : config.components.idType || 'KEY',
32
- version : config.components.version || 1,
33
- network : config.components.network || 'signet',
34
- genesisBytes : this.config.keys.public!
35
- });
36
- }
37
-
38
- async start(): Promise<void> {
39
- const pool = new SimplePool();
40
- pool.subscribe(this.config.relays, { pubkey: this.config.did, kinds: [1059] } as Filter, {
41
- onclose : (reasons: string[]) => console.log('Subscription closed for reasons:', reasons),
42
- onevent : async (event: any) => {
43
- console.log('Received event:', event);
44
- }
45
- });
46
- }
47
-
48
- registerMessageHandler(messageType: string, handler: (msg: any) => Promise<void>): void {
49
- this.handlers.set(messageType, handler);
50
- }
51
-
52
- /**
53
- * Sends a message to a recipient using the Nostr protocol.
54
- * This method is a placeholder and should be implemented with actual Nostr message sending logic.
55
- * @param message
56
- * @param recipient
57
- * @param sender
58
- */
59
- async sendMessage(message: object, recipient: string, sender: string): Promise<void> {
60
- // TODO: Implement message sending logic via Nostr
61
- console.log(`Sending message to ${recipient} from ${sender}:`, message);
62
- }
63
-
64
- /**
65
- * Generates a Nostr identity using the Secp256k1SecretKey and Identifier classes.
66
- * @returns {string} A BTCR2 DID used for communication over the nostr protocol
67
- */
68
- public generateIdentity(): string {
69
- this.config.keys.secret = Secp256k1SecretKey.random();
70
- this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
71
- this.config.did = Identifier.encode(
72
- {
73
- idType : this.config.components.idType || 'KEY',
74
- version : this.config.components.version || 1,
75
- network : this.config.components.network || 'signet',
76
- genesisBytes : this.config.keys.public
77
- }
78
- );
79
- return this.config.did;
80
- }
81
- }
@@ -1,6 +0,0 @@
1
- export interface ProtocolService {
2
- start(): Promise<void>;
3
- registerMessageHandler(messageType: string, handler: (msg: any) => Promise<void>): void;
4
- sendMessage(message: object, recipient: string, sender: string): Promise<void>;
5
- generateIdentity(): string;
6
- }
@@ -1,364 +0,0 @@
1
- import { AvailableNetworks } from '@did-btcr2/bitcoin';
2
- import {
3
- HashBytes,
4
- Hex,
5
- KeyBytes,
6
- KeyManagerError,
7
- Logger,
8
- MULTIBASE_URI_PREFIX,
9
- SchnorrKeyPairObject,
10
- SignatureBytes
11
- } from '@did-btcr2/common';
12
- import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
13
- import { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
14
- import { sha256 } from '@noble/hashes/sha2';
15
- import { KeyValueStore, MemoryStore } from '@web5/common';
16
- import { KeyIdentifier } from '@web5/crypto';
17
- import { Did } from '@web5/dids';
18
- import { Multibase } from 'multiformats';
19
- import { BitcoinSigner, CryptoSigner, IKeyManager, KeyManagerOptions, KeyManagerParams } from './interface.js';
20
-
21
- export interface SignerParams {
22
- multikey: SchnorrMultikey;
23
- network: keyof AvailableNetworks;
24
- };
25
-
26
- /**
27
- * Class for managing cryptographic keys for the B DID method.
28
- * @class KeyManager
29
- * @type {KeyManager}
30
- */
31
- export class KeyManager implements IKeyManager, CryptoSigner, BitcoinSigner {
32
- /**
33
- * Singleton instance of the KeyManager.
34
- * @private
35
- * @type {KeyManager}
36
- */
37
- static #instance?: KeyManager;
38
-
39
- /**
40
- * The `activeKeyUri` property is a string that represents the URI of the currently active key.
41
- * It is used to identify the key that will be used for signing and verifying operations.
42
- * This property is optional and can be set to a specific key URI when initializing the
43
- * `KeyManager` instance. If not set, the key manager will use the default key URI.
44
- * @type {KeyIdentifier}
45
- */
46
- public activeKeyUri?: KeyIdentifier;
47
-
48
- /**
49
- * The `_store` private variable in `KeyManager` is a `KeyValueStore` instance used for
50
- * storing and managing cryptographic keys. It allows the `KeyManager` class to save,
51
- * retrieve, and handle keys efficiently within the local Key Management System (KMS) context.
52
- * This variable can be configured to use different storage backends, like in-memory storage or
53
- * persistent storage, providing flexibility in key management according to the application's
54
- * requirements.
55
- * @private
56
- * @readonly
57
- * @type {KeyValueStore<KeyIdentifier, SchnorrKeyPair>} The key store for managing cryptographic keys.
58
- */
59
- private readonly _store: KeyValueStore<KeyIdentifier, SchnorrMultikey>;
60
-
61
- /**
62
- * Creates an instance of KeyManager.
63
- * @param {?KeyManagerParams} params The parameters to initialize the key manager.
64
- * @param {KeyValueStore<KeyIdentifier, SchnorrMultikey>} params.store An optional property to specify a custom
65
- * `KeyValueStore` instance for key management. If not provided, {@link KeyManager} uses a default `MemoryStore`
66
- * instance. This store is responsible for managing cryptographic keys, allowing them to be retrieved, stored, and
67
- * managed during cryptographic operations.
68
- * @param {KeyIdentifier} params.keyUri An optional property to specify the active key URI for the key manager.
69
- */
70
- constructor({ store, keyUri, keys }: KeyManagerParams = {}) {
71
- // Set the default key store to a MemoryStore instance
72
- this._store = store ?? new MemoryStore<KeyIdentifier, SchnorrMultikey>();
73
-
74
- // Import the keys into the key store
75
- if (keyUri && keys) {
76
- void this.importKey(keys, keyUri).then(() => {
77
- this.activeKeyUri = keyUri;
78
- });
79
- }
80
- }
81
-
82
- /**
83
- * Gets the singleton instance of the KeyManager.
84
- * @returns {KeyManager} The singleton instance of the KeyManager.
85
- */
86
- public static get instance(): KeyManager {
87
- // Check if the KeyManager instance is initialized
88
- if (!KeyManager.#instance) {
89
- throw new KeyManagerError('KeyManager not initialized. Call initialize() first.', 'KEY_MANAGER_NOT_INITIALIZED');
90
- }
91
- // Return the singleton instance
92
- const instance = KeyManager.#instance;
93
- return instance;
94
- }
95
-
96
- /**
97
- * Signs a transaction using the key associated with the key URI.
98
- * @param {Hex} txHex The transaction hex to sign.
99
- * @param {KeyIdentifier} keyUri The URI of the key to sign the transaction with.
100
- * @returns {Promise<Hex>} A promise resolving to the signed transaction hex.
101
- */
102
- signTransaction(txHex: Hex, keyUri?: KeyIdentifier): Promise<Hex> {
103
- throw new Error('Method not implemented.' + txHex + keyUri);
104
- }
105
-
106
- /**
107
- * Gets the key pair from the key store and returns a CompressedSecp256k1PublicKey.
108
- * @param {KeyIdentifier} keyUri The URI of the key to get the public key for.
109
- * @returns {Promise<CompressedSecp256k1PublicKey>} The public key associated with the key URI.
110
- */
111
- public async getPublicKey(keyUri?: KeyIdentifier): Promise<CompressedSecp256k1PublicKey> {
112
- // Use the active key URI if not provided
113
- const key = await this.getKey(keyUri);
114
-
115
- // Check if the key exists and has a public key
116
- if (!key?.publicKey) {
117
- throw new KeyManagerError(`Key not found for URI: ${keyUri}`, 'KEY_NOT_FOUND');
118
- }
119
-
120
- // Return the public key
121
- return key.publicKey;
122
- }
123
-
124
- /**
125
- * Signs the given data using the key associated with the key URI.
126
- * @param {Hex} data The data to sign.
127
- * @param {?KeyIdentifier} keyUri The URI of the key to sign the data with.
128
- * @returns {Promise<SignatureBytes>} A promise resolving to the signature of the data.
129
- */
130
- public async sign(data: Hex, keyUri?: KeyIdentifier): Promise<SignatureBytes> {
131
- // Get the key from the store
132
- const key = await this.getKey(keyUri);
133
-
134
- // Check if the key exists
135
- if (!key) {
136
- throw new KeyManagerError(`Key URI ${keyUri} not found`, 'KEY_NOT_FOUND');
137
- }
138
-
139
- // Check if the key can sign
140
- if(!key.signer) {
141
- throw new KeyManagerError(`Key URI ${keyUri} is not a signer`, 'KEY_NOT_SIGNER');
142
- }
143
-
144
- // Sign the data using the key and return the signature
145
- return key.sign(data);
146
- }
147
-
148
- /**
149
- * Verifies a signature using the key associated with the key URI.
150
- * @param {KeyIdentifier} keyUri The URI of the key to verify the signature with.
151
- * @param {SignatureBytes} signature The signature to verify.
152
- * @param {Hex} data The data to verify the signature with.
153
- * @returns {Promise<boolean>} A promise resolving to a boolean indicating the verification result.
154
- */
155
- public async verify(signature: SignatureBytes, data: Hex, keyUri?: KeyIdentifier): Promise<boolean> {
156
- // Get the key from the store
157
- const key = await this.getKey(keyUri);
158
-
159
- // Check if the key exists
160
- if (!key) {
161
- throw new KeyManagerError(`Key not found for URI: ${keyUri}`, 'KEY_NOT_FOUND');
162
- }
163
-
164
- // Verify the signature using the multikey
165
- return key.verify(signature, data);
166
- }
167
-
168
- /**
169
- * Gets the key pair from the key store.
170
- * @param {KeyIdentifier} keyUri The URI of the key to get.
171
- * @returns {Promise<SchnorrKeyPair>} The key pair associated with the key URI.
172
- * @throws {KeyManagerError} If the key is not found in the key store.
173
- */
174
- private async getKey(keyUri?: KeyIdentifier): Promise<SchnorrMultikey | undefined> {
175
- // Use the active key URI if not provided
176
- const uri = keyUri ?? this.activeKeyUri;
177
-
178
- // Throw an error if no key URI is provided or active
179
- if (!uri) {
180
- throw new KeyManagerError('No active key uri set.', 'ACTIVE_KEY_URI_NOT_SET');
181
- }
182
-
183
- // Get the key pair from the key store
184
- return await this._store.get(uri);
185
- }
186
-
187
- /**
188
- * Exports the full multikeypair from the key store.
189
- * @returns {Promise<SchnorrKeyPair>} The key pair associated with the key URI.
190
- * @throws {KeyManagerError} If the key is not found in the key store.
191
- */
192
- public async exportKey(keyUri?: KeyIdentifier): Promise<SchnorrMultikey | undefined> {
193
- // Get the key from the key store and return it
194
- return await this.getKey(keyUri);
195
- }
196
-
197
- /**
198
- * Imports a keypair to the store.
199
- * @param {SchnorrKeyPair} keys The keypair to import.
200
- * @param {KeyIdentifier} keyUri The URI of the key to import.
201
- * @param {KeyManagerOptions} options Relevant import options.
202
- * @param {boolean} options.active A flag to set the key as active (optional, default: false).
203
- * @returns {Promise<KeyIdentifier>} A promise that resolves to the key identifier of the imported key.
204
- */
205
- public async importKey(keys: SchnorrKeyPair, keyUri: string, options: KeyManagerOptions = {}): Promise<KeyIdentifier> {
206
- const parts = Did.parse(keyUri);
207
- if(!parts) {
208
- throw new KeyManagerError(
209
- 'Invalid key URI: must be valid, parsable BTCR2 identifier',
210
- 'INVALID_KEY_URI',
211
- { keyUri, parts }
212
- );
213
- }
214
-
215
- if(!parts.id) {
216
- throw new KeyManagerError(
217
- 'Invalid key URI: missing id part',
218
- 'INVALID_KEY_URI',
219
- { keyUri, parts }
220
- );
221
- }
222
-
223
- if(!parts.fragment) {
224
- throw new KeyManagerError(
225
- 'Invalid key URI: missing fragment part',
226
- 'INVALID_KEY_URI',
227
- { keyUri, parts }
228
- );
229
- }
230
- // Instantiate a new SchnorrMultikey with the provided keys
231
- const multikey = new SchnorrMultikey({ controller: parts.uri, id: `#${parts.fragment}`, keys });
232
-
233
- // Store the keypair in the key store
234
- await this._store.set(keyUri, multikey);
235
-
236
- // Set the key as active if required
237
- if (options.active) {
238
- this.activeKeyUri = keyUri;
239
- }
240
-
241
- // Return the key URI
242
- return keyUri;
243
- }
244
-
245
- /**
246
- * Computes the hash of the given data.
247
- * @param {Uint8Array} data The data to hash.
248
- * @returns {HashBytes} The hash of the data.
249
- */
250
- public digest(data: Uint8Array): HashBytes {
251
- return sha256(data);
252
- }
253
-
254
- /**
255
- * Computes the key URI of a given keypair.
256
- * @param {string} id The fragment identifier (e.g. 'key-1').
257
- * @param {string} [controller] The DID controller (e.g. 'did:btcr2:xyz').
258
- * @returns {KeyIdentifier} A full DID fragment URI (e.g. 'did:btcr2:xyz#key-1')
259
- */
260
- public static computeKeyUri(id: string, controller: string): KeyIdentifier {
261
- // Concat the id to the controller and return
262
- return `${controller}${id.startsWith('#') ? id : `#${id}`}`;
263
- }
264
-
265
- /**
266
- * Computes a multibase-compliant URI from a key.
267
- * @param key A SchnorrKeyPair, CompressedSecp256k1PublicKey, or multibase string
268
- * @returns {string} A multibase URI (e.g. 'urn:mb:zQ3s...')
269
- */
270
- public static toMultibaseUri(data: SchnorrKeyPair | CompressedSecp256k1PublicKey | Multibase<'zQ3s'>): string {
271
- const multibase = data instanceof SchnorrKeyPair
272
- ? data.publicKey.multibase
273
- : data instanceof CompressedSecp256k1PublicKey
274
- ? data.multibase
275
- : data;
276
-
277
- return `${MULTIBASE_URI_PREFIX}${multibase}`;
278
- }
279
-
280
- /**
281
- * Initializes a singleton KeyManager instance.
282
- * @param {SchnorrKeyPair} keys The keypair used to initialize the key manager.
283
- * @returns {void}
284
- */
285
- public static async initialize(keys: SchnorrKeyPair | SchnorrKeyPairObject, keyUri: string): Promise<KeyManager> {
286
- if(!(keys instanceof SchnorrKeyPair)) {
287
- keys = SchnorrKeyPair.fromJSON(keys);
288
- }
289
-
290
- // Check if the KeyManager instance is already initialized
291
- if (KeyManager.#instance) {
292
- Logger.warn('KeyManager global instance is already initialized.');
293
- return KeyManager.#instance;
294
- }
295
-
296
- // Check if the keypair is provided
297
- if(!keys) {
298
- // Log a warning message if not provided
299
- Logger.warn('keys not provided, generating ...');
300
- }
301
-
302
- // Generate a new keypair if not provided
303
- keys ??= SchnorrKeyPair.generate();
304
-
305
- // Initialize the singleton key manager with the keypair
306
- KeyManager.#instance = new KeyManager({ keys });
307
-
308
- // Import the keypair into the key store
309
- await KeyManager.#instance.importKey(keys, keyUri, { active: true });
310
-
311
- // Set the active key URI
312
- KeyManager.#instance.activeKeyUri = keyUri;
313
-
314
- // Log the active key URI
315
- Logger.info(`KeyManager initialized with Active Key URI: ${KeyManager.#instance.activeKeyUri}`);
316
-
317
- // Return the singleton instance
318
- return KeyManager.#instance;
319
- }
320
-
321
- /**
322
- * Retrieves a keypair from the key store using the provided key URI.
323
- * @public
324
- * @param {KeyIdentifier} keyUri The URI of the keypair to retrieve.
325
- * @returns {Promise<SchnorrKeyPair | undefined>} The retrieved keypair, or undefined if not found.
326
- */
327
- public static async getKeyPair(keyUri?: KeyIdentifier): Promise<SchnorrMultikey | undefined> {
328
- // Use the active key URI if not provided
329
- keyUri ??= KeyManager.#instance?.activeKeyUri;
330
- // Instantiate a new KeyManager with the default key store
331
- return await KeyManager.#instance?.getKey(keyUri);
332
- }
333
-
334
- public async getKeySigner(keyUri: KeyIdentifier, network: keyof AvailableNetworks): Promise<Signer> {
335
- const multikey = await this.getKey(keyUri);
336
- if(!multikey) {
337
- throw new KeyManagerError(`Key not found for URI: ${keyUri}`, 'KEY_NOT_FOUND');
338
- }
339
- return new Signer({ multikey, network });
340
- }
341
- }
342
-
343
- export class Signer {
344
- public multikey: SchnorrMultikey;
345
- public network: keyof AvailableNetworks;
346
-
347
- constructor(params: SignerParams) {
348
- this.multikey = params.multikey;
349
- this.network = params.network;
350
- }
351
-
352
- get publicKey(): KeyBytes {
353
- // Return the public key from the multikey
354
- return this.multikey.publicKey.compressed;
355
- }
356
-
357
- public sign(hash: Hex): SignatureBytes {
358
- return this.multikey.sign(hash, { scheme: 'ecdsa' });
359
- };
360
-
361
- public signSchnorr(hash: Hex): SignatureBytes {
362
- return this.multikey.sign(hash);
363
- }
364
- }
@@ -1,129 +0,0 @@
1
- import { HashBytes, Hex, SignatureBytes } from '@did-btcr2/common';
2
- import { Multikey, SchnorrMultikey } from '@did-btcr2/cryptosuite';
3
- import { SchnorrKeyPair, CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
4
- import { KeyValueStore } from '@web5/common';
5
-
6
- export type KeyManagerOptions = {
7
- importKey?: boolean;
8
- active?: boolean
9
- };
10
-
11
- /** Alias type for KeyManager keyUri */
12
- export type KeyIdentifier = string;
13
-
14
- /** Params for initializing a KeyManager class instance. */
15
- export type KeyManagerParams = {
16
- /**
17
- * An optional property to specify a custom `KeyValueStore` instance for key management. If not
18
- * provided, {@link KeyManager | `KeyManager`} uses a default `MemoryStore` instance.
19
- * This store is responsible for managing cryptographic keys, allowing them to be retrieved,
20
- * stored, and managed during cryptographic operations.
21
- * @type {KeyValueStore<KeyIdentifier, KeyPair>}
22
- */
23
- store?: KeyValueStore<KeyIdentifier, SchnorrMultikey>;
24
-
25
- /**
26
- * An optional property to specify a key URI for the key manager. If not provided, the key manager
27
- * will generate a key URI based on the public key of the key pair.
28
- * @type {KeyIdentifier}
29
- */
30
- keyUri?: KeyIdentifier;
31
-
32
- /**
33
- * An optional property to specify the DID contoller id.
34
- * @type {string}
35
- */
36
- id?: string;
37
-
38
- /**
39
- * An optional property to specify the DID controller.\
40
- * @type {string}
41
- */
42
- controller?: string;
43
-
44
- /**
45
- * An optional property to pass in an initial key pair
46
- * @type {SchnorrKeyPair}
47
- */
48
- keys?: SchnorrKeyPair;
49
- };
50
-
51
- export type GenerateKeyParams = {
52
- id: string;
53
- controller: string;
54
- options: KeyManagerOptions
55
- };
56
-
57
- /**
58
- * The interface for the KeyManager class.
59
- * @interface IKeyManager
60
- * @type {IKeyManager}
61
- */
62
- export interface IKeyManager {
63
- /**
64
- * The URI of the active key.
65
- * @type {KeyIdentifier}
66
- */
67
- activeKeyUri?: KeyIdentifier;
68
-
69
- /**
70
- * Exports the full key pair from the key store.
71
- * @param {KeyIdentifier} keyUri The URI of the key to export.
72
- * @returns {Promise<Multikey | undefined>} The key pair associated with the key URI.
73
- * @throws {KeyManagerError} If the key is not found in the key store.
74
- */
75
- exportKey(keyUri?: KeyIdentifier): Promise<Multikey | undefined>;
76
-
77
- /**
78
- * Gets the public key of a key pair.
79
- * @param {KeyIdentifier} keyUri The URI of the key to get the public key for.
80
- * @returns {Promise<CompressedSecp256k1PublicKey>} The public key of the key pair.
81
- */
82
- getPublicKey(keyUri: KeyIdentifier): Promise<CompressedSecp256k1PublicKey>;
83
-
84
- /**
85
- * Imports a key pair into the key store.
86
- * @param {SchnorrKeyPair} keyPair The key pair to import.
87
- * @param {string} keyUri The full DID controller + fragment identifier (e.g. 'did:btcr2:xyz#key-1').
88
- * @param {KeyManagerOptions} options The options for importing the key pair.
89
- * @param {boolean} options.active Whether to set the imported key as active.
90
- * @returns {Promise<KeyIdentifier>} A promise that resolves to the key identifier of the imported key.
91
- */
92
- importKey(keyPair: SchnorrKeyPair, keyUri: string, options: KeyManagerOptions): Promise<KeyIdentifier>;
93
- }
94
-
95
- export interface CryptoSigner {
96
- /**
97
- * Signs a message with a key pair.
98
- * @param {Hex} data The data to sign.
99
- * @param {?KeyIdentifier} keyUri The URI of the key to sign the data with.
100
- * @returns {Promise<SignatureBytes>} The signature of the input data.
101
- */
102
- sign(data: Hex, keyUri?: KeyIdentifier): Promise<SignatureBytes>;
103
-
104
- /**
105
- * Verifies if a signature was produced by a key pair.
106
- * @param {SignatureBytes} signature The signature to verify.
107
- * @param {Hex} data The data that was signed.
108
- * @param {?KeyIdentifier} keyUri The URI of the key to use for verification.
109
- * @returns {Promise<boolean>} A promise that resolves if the signature is valid, and rejects otherwise.
110
- */
111
- verify(signature: SignatureBytes, data: Hex, keyUri?: KeyIdentifier): Promise<boolean>;
112
-
113
- /**
114
- * Returns the sha256 hash of the input data.
115
- * @param {Uint8Array} data The data to hash.
116
- * @returns {HashBytes} The sha256 hash of the input data.
117
- */
118
- digest(data: Uint8Array): HashBytes;
119
- }
120
-
121
- export interface BitcoinSigner {
122
- /**
123
- * Signs a Bitcoin transaction with a key pair.
124
- * @param txHex The hex-encoded transaction to sign.
125
- * @param keyUri The URI of the key to sign the transaction with.
126
- * @returns {Promise<Hex>} A promise that resolves to the hex-encoded signed transaction.
127
- */
128
- signTransaction(txHex: Hex, keyUri?: KeyIdentifier): Promise<Hex>;
129
- }
@@ -1,75 +0,0 @@
1
- import { DidUpdatePayload, UnixTimestamp } from '@did-btcr2/common';
2
- import { DidServiceEndpoint, DidService as IDidService } from '@web5/dids';
3
- import { RawTransactionV2, RawTransactionRest } from '@did-btcr2/bitcoin';
4
- import { SignalsMetadata } from '../types/crud.js';
5
-
6
- /**
7
- * Beacon interface
8
- * @interface IBeacon
9
- * @type {IBeacon}
10
- */
11
- export interface IBeacon {
12
- /**
13
- * A unique identifier for the Beacon
14
- * @type {string}
15
- */
16
- id: string;
17
-
18
- /**
19
- * The type of the Beacon
20
- * @type {string}
21
- */
22
- type: string;
23
-
24
- /**
25
- * The service endpoint of the Beacon
26
- * @type {string}
27
- */
28
- serviceEndpoint: DidServiceEndpoint;
29
-
30
- /**
31
- * Returns the Beacon Service object
32
- * @type {BeaconService}
33
- */
34
- service: BeaconService;
35
-
36
- /**
37
- * Generates a Beacon Signal Transaction
38
- * @param {string} didUpdatePayload The DID update payload
39
- * @returns {BeaconSignal} The Beacon Signal
40
- */
41
- generateSignal(didUpdatePayload: string): BeaconSignal;
42
-
43
- /**
44
- * Processes a Beacon Signal.
45
- * @param {RawTransactionV2} signal The raw transaction
46
- * @param {SidecarData} signalsMetadata The signals metadata from the sidecar data
47
- * @returns {Promise<DidUpdatePayload | undefined>} The DID update payload
48
- */
49
- processSignal(signal: RawTransactionV2, signalsMetadata: SignalsMetadata): Promise<DidUpdatePayload | undefined>;
50
-
51
-
52
- /**
53
- * Broadcasts a signal.
54
- * @param {DidUpdatePayload} didUpdatePayload The DID update payload.
55
- * @returns {Promise<SignalMetadata>} The signal metadata.
56
- */
57
- broadcastSignal(didUpdatePayload: DidUpdatePayload): Promise<SignalsMetadata>;
58
- }
59
-
60
- export interface BeaconService extends IDidService {
61
- serviceEndpoint: DidServiceEndpoint;
62
- casType?: string;
63
- }
64
-
65
- export interface BeaconServiceAddress extends BeaconService {
66
- address: string;
67
- }
68
- export interface BeaconSignal {
69
- beaconId: string;
70
- beaconType: string;
71
- beaconAddress: string;
72
- tx: RawTransactionRest | RawTransactionV2;
73
- blockheight: number;
74
- blocktime: UnixTimestamp;
75
- }