@did-btcr2/method 0.18.1 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (291) hide show
  1. package/dist/browser.js +4917 -6487
  2. package/dist/browser.mjs +4917 -6487
  3. package/dist/cjs/core/beacon/aggregation/cohort/index.js +3 -3
  4. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -1
  5. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +1 -9
  6. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
  7. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +2 -1
  8. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
  9. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +2 -1
  10. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
  11. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +2 -1
  12. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
  13. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +2 -1
  14. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
  15. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +2 -1
  16. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
  17. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +2 -1
  18. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
  19. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +2 -1
  20. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
  21. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +2 -1
  22. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
  23. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +2 -1
  24. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
  25. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +2 -1
  26. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
  27. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +36 -18
  28. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  29. package/dist/cjs/core/beacon/aggregation/coordinator.js +14 -14
  30. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +1 -1
  31. package/dist/cjs/core/beacon/aggregation/participant.js +4 -3
  32. package/dist/cjs/core/beacon/aggregation/participant.js.map +1 -1
  33. package/dist/cjs/core/beacon/aggregation/session/index.js +1 -1
  34. package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
  35. package/dist/cjs/core/beacon/beacon.js +25 -0
  36. package/dist/cjs/core/beacon/beacon.js.map +1 -0
  37. package/dist/cjs/core/beacon/cas-beacon.js +39 -0
  38. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -0
  39. package/dist/cjs/core/beacon/error.js +4 -4
  40. package/dist/cjs/core/beacon/error.js.map +1 -1
  41. package/dist/cjs/core/beacon/factory.js +10 -11
  42. package/dist/cjs/core/beacon/factory.js.map +1 -1
  43. package/dist/cjs/core/beacon/interfaces.js +2 -0
  44. package/dist/cjs/core/beacon/interfaces.js.map +1 -0
  45. package/dist/cjs/core/beacon/signal-discovery.js +183 -0
  46. package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
  47. package/dist/cjs/core/beacon/singleton.js +75 -178
  48. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  49. package/dist/cjs/core/beacon/smt-beacon.js +39 -0
  50. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -0
  51. package/dist/cjs/core/beacon/utils.js +71 -114
  52. package/dist/cjs/core/beacon/utils.js.map +1 -1
  53. package/dist/cjs/core/identifier.js +18 -21
  54. package/dist/cjs/core/identifier.js.map +1 -1
  55. package/dist/cjs/core/interfaces.js +2 -0
  56. package/dist/cjs/core/interfaces.js.map +1 -0
  57. package/dist/cjs/core/resolve.js +321 -0
  58. package/dist/cjs/core/resolve.js.map +1 -0
  59. package/dist/cjs/{utils → core}/types.js.map +1 -1
  60. package/dist/cjs/core/update.js +113 -0
  61. package/dist/cjs/core/update.js.map +1 -0
  62. package/dist/cjs/did-btcr2.js +168 -129
  63. package/dist/cjs/did-btcr2.js.map +1 -1
  64. package/dist/cjs/index.js +17 -16
  65. package/dist/cjs/index.js.map +1 -1
  66. package/dist/cjs/utils/appendix.js +16 -33
  67. package/dist/cjs/utils/appendix.js.map +1 -1
  68. package/dist/cjs/utils/did-document-builder.js +5 -0
  69. package/dist/cjs/utils/did-document-builder.js.map +1 -1
  70. package/dist/cjs/utils/did-document.js +62 -72
  71. package/dist/cjs/utils/did-document.js.map +1 -1
  72. package/dist/cjs/utils/general.js +1 -1
  73. package/dist/cjs/utils/general.js.map +1 -1
  74. package/dist/esm/core/beacon/aggregation/cohort/index.js +3 -3
  75. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
  76. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js +1 -9
  77. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
  78. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +2 -1
  79. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
  80. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +2 -1
  81. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
  82. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +2 -1
  83. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
  84. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +2 -1
  85. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
  86. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +2 -1
  87. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
  88. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +2 -1
  89. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
  90. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +2 -1
  91. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
  92. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +2 -1
  93. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
  94. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +2 -1
  95. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
  96. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +2 -1
  97. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
  98. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +36 -18
  99. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  100. package/dist/esm/core/beacon/aggregation/coordinator.js +14 -14
  101. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  102. package/dist/esm/core/beacon/aggregation/participant.js +4 -3
  103. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  104. package/dist/esm/core/beacon/aggregation/session/index.js +1 -1
  105. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
  106. package/dist/esm/core/beacon/beacon.js +25 -0
  107. package/dist/esm/core/beacon/beacon.js.map +1 -0
  108. package/dist/esm/core/beacon/cas-beacon.js +39 -0
  109. package/dist/esm/core/beacon/cas-beacon.js.map +1 -0
  110. package/dist/esm/core/beacon/error.js +4 -4
  111. package/dist/esm/core/beacon/error.js.map +1 -1
  112. package/dist/esm/core/beacon/factory.js +10 -11
  113. package/dist/esm/core/beacon/factory.js.map +1 -1
  114. package/dist/esm/core/beacon/interfaces.js +2 -0
  115. package/dist/esm/core/beacon/interfaces.js.map +1 -0
  116. package/dist/esm/core/beacon/signal-discovery.js +183 -0
  117. package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
  118. package/dist/esm/core/beacon/singleton.js +75 -178
  119. package/dist/esm/core/beacon/singleton.js.map +1 -1
  120. package/dist/esm/core/beacon/smt-beacon.js +39 -0
  121. package/dist/esm/core/beacon/smt-beacon.js.map +1 -0
  122. package/dist/esm/core/beacon/utils.js +71 -114
  123. package/dist/esm/core/beacon/utils.js.map +1 -1
  124. package/dist/esm/core/identifier.js +18 -21
  125. package/dist/esm/core/identifier.js.map +1 -1
  126. package/dist/esm/core/interfaces.js +2 -0
  127. package/dist/esm/core/interfaces.js.map +1 -0
  128. package/dist/esm/core/resolve.js +321 -0
  129. package/dist/esm/core/resolve.js.map +1 -0
  130. package/dist/esm/{utils → core}/types.js.map +1 -1
  131. package/dist/esm/core/update.js +113 -0
  132. package/dist/esm/core/update.js.map +1 -0
  133. package/dist/esm/did-btcr2.js +168 -129
  134. package/dist/esm/did-btcr2.js.map +1 -1
  135. package/dist/esm/index.js +17 -16
  136. package/dist/esm/index.js.map +1 -1
  137. package/dist/esm/utils/appendix.js +16 -33
  138. package/dist/esm/utils/appendix.js.map +1 -1
  139. package/dist/esm/utils/did-document-builder.js +5 -0
  140. package/dist/esm/utils/did-document-builder.js.map +1 -1
  141. package/dist/esm/utils/did-document.js +62 -72
  142. package/dist/esm/utils/did-document.js.map +1 -1
  143. package/dist/esm/utils/general.js +1 -1
  144. package/dist/esm/utils/general.js.map +1 -1
  145. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -1
  146. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +0 -7
  147. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -1
  148. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -1
  149. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -1
  150. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -1
  151. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -1
  152. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -1
  153. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -1
  154. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -1
  155. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -1
  156. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -1
  157. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -1
  158. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +13 -5
  159. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
  160. package/dist/types/core/beacon/aggregation/coordinator.d.ts +17 -29
  161. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  162. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  163. package/dist/types/core/beacon/beacon.d.ts +44 -0
  164. package/dist/types/core/beacon/beacon.d.ts.map +1 -0
  165. package/dist/types/core/beacon/cas-beacon.d.ts +36 -0
  166. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -0
  167. package/dist/types/core/beacon/error.d.ts +2 -2
  168. package/dist/types/core/beacon/error.d.ts.map +1 -1
  169. package/dist/types/core/beacon/factory.d.ts +4 -5
  170. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  171. package/dist/types/core/beacon/interfaces.d.ts +59 -0
  172. package/dist/types/core/beacon/interfaces.d.ts.map +1 -0
  173. package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
  174. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
  175. package/dist/types/core/beacon/singleton.d.ts +20 -76
  176. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  177. package/dist/types/core/beacon/smt-beacon.d.ts +36 -0
  178. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -0
  179. package/dist/types/core/beacon/utils.d.ts +19 -97
  180. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  181. package/dist/types/core/identifier.d.ts.map +1 -1
  182. package/dist/types/core/interfaces.d.ts +87 -0
  183. package/dist/types/core/interfaces.d.ts.map +1 -0
  184. package/dist/types/core/resolve.d.ts +89 -0
  185. package/dist/types/core/resolve.d.ts.map +1 -0
  186. package/dist/types/core/types.d.ts +84 -0
  187. package/dist/types/core/types.d.ts.map +1 -0
  188. package/dist/types/core/update.d.ts +51 -0
  189. package/dist/types/core/update.d.ts.map +1 -0
  190. package/dist/types/did-btcr2.d.ts +70 -89
  191. package/dist/types/did-btcr2.d.ts.map +1 -1
  192. package/dist/types/index.d.ts +17 -16
  193. package/dist/types/index.d.ts.map +1 -1
  194. package/dist/types/utils/appendix.d.ts +5 -10
  195. package/dist/types/utils/appendix.d.ts.map +1 -1
  196. package/dist/types/utils/did-document-builder.d.ts +6 -1
  197. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  198. package/dist/types/utils/did-document.d.ts +46 -42
  199. package/dist/types/utils/did-document.d.ts.map +1 -1
  200. package/package.json +6 -6
  201. package/src/core/beacon/aggregation/cohort/index.ts +3 -3
  202. package/src/core/beacon/aggregation/cohort/messages/base.ts +1 -12
  203. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +2 -2
  204. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +2 -2
  205. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +2 -2
  206. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +2 -2
  207. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +2 -2
  208. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +2 -2
  209. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +2 -2
  210. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +2 -2
  211. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +2 -2
  212. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +2 -2
  213. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +43 -21
  214. package/src/core/beacon/aggregation/coordinator.ts +41 -29
  215. package/src/core/beacon/aggregation/participant.ts +4 -3
  216. package/src/core/beacon/aggregation/session/index.ts +1 -1
  217. package/src/core/beacon/beacon.ts +58 -0
  218. package/src/core/beacon/cas-beacon.ts +53 -0
  219. package/src/core/beacon/error.ts +5 -6
  220. package/src/core/beacon/factory.ts +12 -16
  221. package/src/core/beacon/interfaces.ts +67 -0
  222. package/src/core/beacon/signal-discovery.ts +237 -0
  223. package/src/core/beacon/singleton.ts +107 -197
  224. package/src/core/beacon/smt-beacon.ts +53 -0
  225. package/src/core/beacon/utils.ts +95 -182
  226. package/src/core/identifier.ts +21 -24
  227. package/src/core/interfaces.ts +93 -0
  228. package/src/core/resolve.ts +463 -0
  229. package/src/core/types.ts +95 -0
  230. package/src/core/update.ts +154 -0
  231. package/src/did-btcr2.ts +255 -159
  232. package/src/index.ts +19 -22
  233. package/src/utils/appendix.ts +26 -44
  234. package/src/utils/did-document-builder.ts +6 -1
  235. package/src/utils/did-document.ts +105 -113
  236. package/src/utils/general.ts +1 -1
  237. package/dist/cjs/core/beacon/cid-aggregate.js +0 -116
  238. package/dist/cjs/core/beacon/cid-aggregate.js.map +0 -1
  239. package/dist/cjs/core/beacon/smt-aggregate.js +0 -126
  240. package/dist/cjs/core/beacon/smt-aggregate.js.map +0 -1
  241. package/dist/cjs/core/crud/deactivate.js +0 -14
  242. package/dist/cjs/core/crud/deactivate.js.map +0 -1
  243. package/dist/cjs/core/crud/read.js +0 -679
  244. package/dist/cjs/core/crud/read.js.map +0 -1
  245. package/dist/cjs/core/crud/update.js +0 -194
  246. package/dist/cjs/core/crud/update.js.map +0 -1
  247. package/dist/cjs/interfaces/beacon.js +0 -41
  248. package/dist/cjs/interfaces/beacon.js.map +0 -1
  249. package/dist/cjs/interfaces/crud.js +0 -2
  250. package/dist/cjs/interfaces/crud.js.map +0 -1
  251. package/dist/esm/core/beacon/cid-aggregate.js +0 -116
  252. package/dist/esm/core/beacon/cid-aggregate.js.map +0 -1
  253. package/dist/esm/core/beacon/smt-aggregate.js +0 -126
  254. package/dist/esm/core/beacon/smt-aggregate.js.map +0 -1
  255. package/dist/esm/core/crud/deactivate.js +0 -14
  256. package/dist/esm/core/crud/deactivate.js.map +0 -1
  257. package/dist/esm/core/crud/read.js +0 -679
  258. package/dist/esm/core/crud/read.js.map +0 -1
  259. package/dist/esm/core/crud/update.js +0 -194
  260. package/dist/esm/core/crud/update.js.map +0 -1
  261. package/dist/esm/interfaces/beacon.js +0 -41
  262. package/dist/esm/interfaces/beacon.js.map +0 -1
  263. package/dist/esm/interfaces/crud.js +0 -2
  264. package/dist/esm/interfaces/crud.js.map +0 -1
  265. package/dist/types/core/beacon/cid-aggregate.d.ts +0 -102
  266. package/dist/types/core/beacon/cid-aggregate.d.ts.map +0 -1
  267. package/dist/types/core/beacon/smt-aggregate.d.ts +0 -111
  268. package/dist/types/core/beacon/smt-aggregate.d.ts.map +0 -1
  269. package/dist/types/core/crud/deactivate.d.ts +0 -13
  270. package/dist/types/core/crud/deactivate.d.ts.map +0 -1
  271. package/dist/types/core/crud/read.d.ts +0 -334
  272. package/dist/types/core/crud/read.d.ts.map +0 -1
  273. package/dist/types/core/crud/update.d.ts +0 -93
  274. package/dist/types/core/crud/update.d.ts.map +0 -1
  275. package/dist/types/interfaces/beacon.d.ts +0 -116
  276. package/dist/types/interfaces/beacon.d.ts.map +0 -1
  277. package/dist/types/interfaces/crud.d.ts +0 -32
  278. package/dist/types/interfaces/crud.d.ts.map +0 -1
  279. package/dist/types/utils/types.d.ts +0 -38
  280. package/dist/types/utils/types.d.ts.map +0 -1
  281. package/src/canonicalize.d.ts +0 -6
  282. package/src/core/beacon/cid-aggregate.ts +0 -153
  283. package/src/core/beacon/smt-aggregate.ts +0 -135
  284. package/src/core/crud/deactivate.ts +0 -13
  285. package/src/core/crud/read.ts +0 -948
  286. package/src/core/crud/update.ts +0 -292
  287. package/src/interfaces/beacon.ts +0 -137
  288. package/src/interfaces/crud.ts +0 -33
  289. package/src/utils/types.ts +0 -41
  290. /package/dist/cjs/{utils → core}/types.js +0 -0
  291. /package/dist/esm/{utils → core}/types.js +0 -0
@@ -0,0 +1,58 @@
1
+ import { KeyBytes } from '@did-btcr2/common';
2
+ import { BitcoinNetworkConnection } from '../../../../bitcoin/dist/types/bitcoin.js';
3
+ import { SignedBTCR2Update } from '../../../../cryptosuite/dist/types/data-integrity-proof/interface.js';
4
+ import { SidecarData } from '../types.js';
5
+ import { BeaconService, BeaconSignal, BlockMetadata } from './interfaces.js';
6
+
7
+ /**
8
+ * Abstract base class for all BTCR2 Beacon types.
9
+ * A Beacon is a service listed in a BTCR2 DID document that informs resolvers
10
+ * how to find authentic updates to the DID.
11
+ *
12
+ * Beacons are lightweight typed wrappers around a {@link BeaconService} configuration.
13
+ * Dependencies (signals, sidecar data, bitcoin connection) are passed as method
14
+ * parameters rather than held as instance state.
15
+ *
16
+ * Use {@link BeaconFactory.establish} to create typed instances from service config.
17
+ *
18
+ * @abstract
19
+ * @class Beacon
20
+ * @type {Beacon}
21
+ */
22
+ export abstract class Beacon {
23
+ /**
24
+ * The Beacon service configuration parsed from the DID Document.
25
+ */
26
+ readonly service: BeaconService;
27
+
28
+ constructor(service: BeaconService) {
29
+ this.service = service;
30
+ }
31
+
32
+ /**
33
+ * Processes an array of Beacon Signals to extract BTCR2 Signed Updates.
34
+ * Used during the resolve path.
35
+ * @param {Array<BeaconSignal>} signals The beacon signals discovered on-chain.
36
+ * @param {SidecarData} sidecar The processed sidecar data containing update/CAS/SMT maps.
37
+ * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The updates announced by the signals.
38
+ */
39
+ abstract processSignals(
40
+ signals: Array<BeaconSignal>,
41
+ sidecar: SidecarData,
42
+ ): Promise<Array<[SignedBTCR2Update, BlockMetadata]>>;
43
+
44
+
45
+ /**
46
+ * Broadcasts a signed update as a Beacon Signal to the Bitcoin network.
47
+ * Used during the update path.
48
+ * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
49
+ * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
50
+ * @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
51
+ * @returns {Promise<SignedBTCR2Update>} The signed update that was broadcast.
52
+ */
53
+ abstract broadcastSignal(
54
+ signedUpdate: SignedBTCR2Update,
55
+ secretKey: KeyBytes,
56
+ bitcoin: BitcoinNetworkConnection
57
+ ): Promise<SignedBTCR2Update>;
58
+ }
@@ -0,0 +1,53 @@
1
+ import { BitcoinNetworkConnection } from '@did-btcr2/bitcoin';
2
+ import { KeyBytes } from '@did-btcr2/common';
3
+ import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
4
+ import { SidecarData } from '../types.js';
5
+ import { Beacon } from './beacon.js';
6
+ import { CASBeaconError } from './error.js';
7
+ import { BeaconService, BeaconSignal, BlockMetadata } from './interfaces.js';
8
+
9
+ /**
10
+ * Implements {@link https://dcdpr.github.io/did-btcr2/terminology.html#cas-beacon | CAS Beacon}.
11
+ * @class CASBeacon
12
+ * @type {CASBeacon}
13
+ * @extends {Beacon}
14
+ */
15
+ export class CASBeacon extends Beacon {
16
+ /**
17
+ * Creates an instance of CASBeacon.
18
+ * @param {BeaconService} service The service of the Beacon.
19
+ */
20
+ constructor(service: BeaconService) {
21
+ super({ ...service, type: 'CASBeacon' });
22
+ }
23
+
24
+ /**
25
+ * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-cas-beacon | 7.2.e.1 Process CAS Beacon}.
26
+ * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
27
+ * @param {SidecarData} sidecar The sidecar data associated with the CAS Beacon.
28
+ * @returns {Promise<Array<[SignedBTCR2Update, BlockMetadata]>>} The processed signals.
29
+ * @throws {CASBeaconError} if processing fails.
30
+ */
31
+ processSignals(
32
+ signals: Array<BeaconSignal>,
33
+ sidecar: SidecarData
34
+ ): Promise<Array<[SignedBTCR2Update, BlockMetadata]>> {
35
+ throw new CASBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, { signals, sidecar });
36
+ }
37
+
38
+ /**
39
+ * Broadcast CAS Beacon signal to the Bitcoin network.
40
+ * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
41
+ * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
42
+ * @param {BitcoinNetworkConnection} bitcoin The Bitcoin network connection.
43
+ * @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
44
+ * @throws {CASBeaconError} if broadcasting fails.
45
+ */
46
+ async broadcastSignal(
47
+ signedUpdate: SignedBTCR2Update,
48
+ secretKey: KeyBytes,
49
+ bitcoin: BitcoinNetworkConnection
50
+ ): Promise<SignedBTCR2Update> {
51
+ throw new CASBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signedUpdate, secretKey, bitcoin});
52
+ }
53
+ }
@@ -18,7 +18,6 @@ export class BeaconParticipantError extends MethodError {
18
18
  }
19
19
  }
20
20
 
21
-
22
21
  export class SingletonBeaconError extends MethodError {
23
22
  constructor(message: string, type: string = 'SingletonBeaconError', data?: Record<string, any>) {
24
23
  super(message, type, data);
@@ -31,14 +30,14 @@ export class AggregateBeaconError extends MethodError {
31
30
  }
32
31
  }
33
32
 
34
- export class CIDAggregateBeaconError extends MethodError {
35
- constructor(message: string, type: string = 'CIDAggregateBeaconError', data?: Record<string, any>) {
33
+ export class CASBeaconError extends MethodError {
34
+ constructor(message: string, type: string = 'CASBeaconError', data?: Record<string, any>) {
36
35
  super(message, type, data);
37
36
  }
38
37
  }
39
38
 
40
- export class SMTAggregateBeaconError extends MethodError {
41
- constructor(message: string, type: string = 'SMTAggregateBeaconError', data?: Record<string, any>) {
39
+ export class SMTBeaconError extends MethodError {
40
+ constructor(message: string, type: string = 'SMTBeaconError', data?: Record<string, any>) {
42
41
  super(message, type, data);
43
42
  }
44
- }
43
+ }
@@ -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 { Beacon } from './beacon.js';
3
+ import { CASBeacon } from './cas-beacon.js';
4
+ import { BeaconService } 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.
@@ -13,23 +13,19 @@ import { SMTAggregateBeacon } from './smt-aggregate.js';
13
13
  export class BeaconFactory {
14
14
  /**
15
15
  * Establish a Beacon instance based on the provided service and optional sidecar data.
16
- * @param {BeaconService} service - The beacon service configuration.
17
- * @param {SidecarData} [sidecar] - The optional sidecar data.
16
+ * @param {BeaconService} service The beacon service configuration.
18
17
  * @returns {Beacon} The established Beacon instance.
19
18
  */
20
- static establish(service: BeaconService, sidecar?: SidecarData): Beacon {
19
+ static establish(service: BeaconService): Beacon {
21
20
  switch (service.type) {
22
21
  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);
22
+ return new SingletonBeacon(service);
23
+ case 'CASBeacon':
24
+ return new CASBeacon(service);
25
+ case 'SMTBeacon':
26
+ return new SMTBeacon(service);
28
27
  default:
29
- throw new MethodError(
30
- 'Invalid Beacon Type',
31
- 'INVALID_BEACON_ERROR', { service, sidecar }
32
- );
28
+ throw new MethodError('Invalid Beacon Type', 'INVALID_BEACON_ERROR', service);
33
29
  }
34
30
  }
35
31
  }
@@ -0,0 +1,67 @@
1
+ import { RawTransactionRest, RawTransactionV2 } from '@did-btcr2/bitcoin';
2
+ import { UnixTimestamp } from '@did-btcr2/common';
3
+ import { DidServiceEndpoint, DidService } from '@web5/dids';
4
+
5
+ /**
6
+ * Represents a Beacon Service, which extends a W3C DID Service by setting serviceEndpoint
7
+ * as a single DidServiceEndpoint.
8
+ * @interface BeaconService
9
+ * @extends DidService
10
+ */
11
+ export interface BeaconService extends DidService {
12
+ serviceEndpoint: DidServiceEndpoint;
13
+ }
14
+
15
+ /**
16
+ * Represents a parsed Beacon Service, which extends the Beacon Service with a Bitcoin address.
17
+ * @interface ParsedBeaconService
18
+ * @extends BeaconService
19
+ */
20
+ export interface ParsedBeaconService extends BeaconService {
21
+ /**
22
+ * The Bitcoin address associated with this Beacon Service.
23
+ */
24
+ address: string;
25
+ }
26
+
27
+ /**
28
+ * Metadata about a Bitcoin block containing a Beacon Signal.
29
+ * @interface BlockMetadata
30
+ */
31
+ export interface BlockMetadata {
32
+ /**
33
+ * The block height at which the Beacon Signal was included.
34
+ */
35
+ height: number;
36
+
37
+ /**
38
+ * The timestamp of the block containing the Beacon Signal.
39
+ */
40
+ time: UnixTimestamp;
41
+
42
+ /**
43
+ * The number of confirmations for the block containing the Beacon Signal.
44
+ */
45
+ confirmations: number;
46
+ }
47
+
48
+ /**
49
+ * Represents a Beacon Signal, which is a transaction broadcasted by a Beacon to announce a DID update.
50
+ * @interface BeaconSignal
51
+ */
52
+ export interface BeaconSignal {
53
+ /**
54
+ * The raw Bitcoin transaction representing the Beacon Signal.
55
+ */
56
+ tx: RawTransactionRest | RawTransactionV2;
57
+
58
+ /**
59
+ * The beacon signal bytes hash (i.e. the hash of the BTCR2 update included in the Beacon Signal tx).
60
+ */
61
+ signalBytes: string;
62
+
63
+ /**
64
+ * Metadata about the block containing the Beacon Signal.
65
+ */
66
+ blockMetadata: BlockMetadata;
67
+ }
@@ -0,0 +1,237 @@
1
+ import {
2
+ BitcoinNetworkConnection,
3
+ BlockV3,
4
+ GENESIS_TX_ID,
5
+ RawTransactionV2,
6
+ TXIN_WITNESS_COINBASE
7
+ } from '@did-btcr2/bitcoin';
8
+ import { ResolveError } from '@did-btcr2/common';
9
+ import { BeaconService, BeaconSignal } from './interfaces.js';
10
+ import { BeaconUtils } from './utils.js';
11
+
12
+ /**
13
+ * Static utility class for discovering Beacon Signals on the Bitcoin blockchain.
14
+ * Extracted from {@link Resolve} for single-responsibility and independent testability.
15
+ *
16
+ * @class BeaconSignalDiscovery
17
+ */
18
+ export class BeaconSignalDiscovery {
19
+
20
+ /**
21
+ * Retrieves the beacon signals for the given array of BeaconService objects
22
+ * using an esplora/electrs REST API connection via a bitcoin I/O driver.
23
+ * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to retrieve signals for
24
+ * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for REST calls
25
+ * @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals
26
+ */
27
+ static async indexer(
28
+ beaconServices: Array<BeaconService>,
29
+ bitcoin: BitcoinNetworkConnection
30
+ ): Promise<Map<BeaconService, Array<BeaconSignal>>> {
31
+ const beaconServiceSignals = new Map<BeaconService, Array<BeaconSignal>>();
32
+
33
+ // Fetch the current block count once before the loop
34
+ const currentBlockCount = await bitcoin.network.rest.block.count();
35
+
36
+ // Iterate over each beacon
37
+ for (const beaconService of beaconServices) {
38
+ beaconServiceSignals.set(beaconService, []);
39
+ // Get the transactions for the beacon address via REST
40
+ const beaconSignals = await bitcoin.network.rest.address.getTxs(
41
+ beaconService.serviceEndpoint as string
42
+ );
43
+
44
+ // If no signals are found, continue
45
+ if (!beaconSignals || !beaconSignals.length) {
46
+ continue;
47
+ }
48
+
49
+ // Iterate over each signal
50
+ for (const beaconSignal of beaconSignals) {
51
+ // Get the last vout in the transaction
52
+ const signalVout = beaconSignal.vout.slice(-1)[0];
53
+
54
+ /**
55
+ * Look for OP_RETURN in last vout scriptpubkey_asm
56
+ * Vout (rest) format:
57
+ * {
58
+ * scriptpubkey: '6a20570f177c65e64fb5cf61180b664cdddf09ab76153c2b192e22006e5b22a3917a',
59
+ * scriptpubkey_asm: 'OP_RETURN OP_PUSHBYTES_32 570f177c65e64fb5cf61180b664cdddf09ab76153c2b192e22006e5b22a3917a',
60
+ * scriptpubkey_type: 'op_return',
61
+ * value: 0
62
+ * }
63
+ */
64
+ if(!signalVout || !signalVout.scriptpubkey_asm.includes('OP_RETURN')) {
65
+ continue;
66
+ }
67
+
68
+ // Construct output map for easier access
69
+ const outputMap = new Map<string, string | number>(Object.entries(signalVout));
70
+
71
+ // Grab the signal vout scriptpubkey
72
+ const signalVoutScriptPubkey = outputMap.get('scriptpubkey_asm') as string;
73
+
74
+ // If the signal vout scriptpubkey does not exist, continue to next signal
75
+ if(!signalVoutScriptPubkey){
76
+ continue;
77
+ }
78
+
79
+ // Extract hex string hash of the signal bytes from the scriptpubkey
80
+ const updateHash = signalVoutScriptPubkey.split(' ').slice(-1)[0];
81
+ if(!updateHash) {
82
+ continue;
83
+ }
84
+
85
+ // Use the pre-fetched block count instead of calling per-signal
86
+ const confirmations = currentBlockCount - beaconSignal.status.block_height + 1;
87
+
88
+ // Push the beacon signal object to the signals array for the beacon service
89
+ beaconServiceSignals.get(beaconService)?.push({
90
+ tx : beaconSignal,
91
+ signalBytes : updateHash,
92
+ blockMetadata : {
93
+ confirmations,
94
+ height : beaconSignal.status.block_height,
95
+ time : beaconSignal.status.block_time,
96
+ }
97
+ });
98
+ }
99
+ }
100
+
101
+ return beaconServiceSignals;
102
+ }
103
+
104
+ /**
105
+ * Traverse the full blockchain from genesis to chain top looking for beacon signals.
106
+ * @param {Array<BeaconService>} beaconServices Array of BeaconService objects to search for signals.
107
+ * @param {BitcoinNetworkConnection} bitcoin Bitcoin network connection to use for RPC calls.
108
+ * @returns {Promise<Map<BeaconService, Array<BeaconSignal>>>} Map of beacon service to its discovered signals.
109
+ */
110
+ static async fullnode(
111
+ beaconServices: Array<BeaconService>,
112
+ bitcoin: BitcoinNetworkConnection
113
+ ): Promise<Map<BeaconService, Array<BeaconSignal>>> {
114
+ const beaconServiceSignals = new Map<BeaconService, Array<BeaconSignal>>();
115
+
116
+ for(const beaconService of beaconServices) {
117
+ beaconServiceSignals.set(beaconService, []);
118
+ }
119
+
120
+ // Get the RPC connection from the bitcoin network
121
+ const rpc = bitcoin.network.rpc;
122
+
123
+ // Ensure that the RPC connection is available
124
+ if(!rpc) {
125
+ throw new ResolveError('RPC connection is not available', 'RPC_CONNECTION_ERROR', bitcoin);
126
+ }
127
+
128
+ // Get the current block height once before the loop
129
+ const targetHeight = await rpc.getBlockCount();
130
+
131
+ // Hoist the beacon services map before the loop
132
+ const beaconServicesMap = BeaconUtils.getBeaconServicesMap(beaconServices);
133
+
134
+ // Set genesis height
135
+ let height = 0;
136
+
137
+ // Opt into rpc connection to get the block data at the blockhash
138
+ let block = await bitcoin.network.rpc!.getBlock({ height }) as BlockV3;
139
+
140
+ console.info(`Searching for beacon signals, please wait ...`);
141
+ while (block.height <= targetHeight) {
142
+ // Iterate over each transaction in the block
143
+ for (const tx of block.tx) {
144
+ // If the txid is a coinbase, continue ...
145
+ if (tx.txid === GENESIS_TX_ID) {
146
+ continue;
147
+ }
148
+
149
+ // Iterate over each input in the transaction
150
+ for (const vin of tx.vin) {
151
+
152
+ // If the vin is a coinbase transaction, continue ...
153
+ if (vin.coinbase) {
154
+ continue;
155
+ }
156
+
157
+ // If the vin txinwitness contains a coinbase did, continue ...
158
+ if (vin.txinwitness && vin.txinwitness.length === 1 && vin.txinwitness[0] === TXIN_WITNESS_COINBASE) {
159
+ continue;
160
+ }
161
+
162
+ // If the txid from the vin is undefined, continue ...
163
+ if (!vin.txid) {
164
+ continue;
165
+ }
166
+
167
+ // If the vout from the vin is undefined, continue ...
168
+ if (vin.vout === undefined) {
169
+ continue;
170
+ }
171
+
172
+ // Get the previous output transaction data
173
+ const prevout = await rpc.getRawTransaction(vin.txid, 2) as RawTransactionV2;
174
+
175
+ // If the previous output vout at the vin.vout index is undefined, continue ...
176
+ if (!prevout.vout[vin.vout]) {
177
+ continue;
178
+ }
179
+
180
+ // Get the address from the scriptPubKey from the prevvout
181
+ const scriptPubKey = prevout.vout[vin.vout].scriptPubKey;
182
+
183
+ // If the scriptPubKey.address is undefined, continue ...
184
+ if (!scriptPubKey.address) {
185
+ continue;
186
+ }
187
+
188
+ // Use the hoisted beaconServicesMap instead of rebuilding per-vin
189
+ const beaconService = beaconServicesMap.get(scriptPubKey.address);
190
+ if (!beaconService) {
191
+ continue;
192
+ }
193
+
194
+ // Look for 'OP_RETURN' in the scriptPubKey asm
195
+ const txVoutScriptPubkeyAsm = prevout.vout[vin.vout].scriptPubKey.asm;
196
+ if(!txVoutScriptPubkeyAsm.includes('OP_RETURN')) {
197
+ continue;
198
+ }
199
+
200
+ // Log the found txid and beacon
201
+ console.info(`Tx ${tx.txid} contains beacon service address ${scriptPubKey.address} and OP_RETURN!`, tx);
202
+
203
+ // Extract hex string hash of the signal bytes from the scriptpubkey
204
+ const updateHash = txVoutScriptPubkeyAsm.split(' ').slice(-1)[0];
205
+ if(!updateHash) {
206
+ continue;
207
+ }
208
+
209
+ // Push the beacon signal object to the beacon signals array for that beacon service
210
+ beaconServiceSignals.get(beaconService)?.push({
211
+ tx,
212
+ signalBytes : updateHash,
213
+ blockMetadata : {
214
+ height : block.height,
215
+ time : block.time,
216
+ confirmations : block.confirmations
217
+ }
218
+ });
219
+ };
220
+ }
221
+
222
+ // Increment the height
223
+ height += 1;
224
+
225
+ // Use pre-fetched targetHeight instead of calling rpc.getBlockCount() every iteration
226
+ if(height > targetHeight) {
227
+ console.info(`Chain tip reached ${height}, breaking ...`);
228
+ break;
229
+ }
230
+
231
+ // Reset the block var to the next block data
232
+ block = await rpc.getBlock({ height }) as BlockV3;
233
+ }
234
+
235
+ return beaconServiceSignals;
236
+ }
237
+ }