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