@did-btcr2/method 0.25.3 → 0.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (406) hide show
  1. package/README.md +86 -233
  2. package/dist/.tsbuildinfo +1 -0
  3. package/dist/browser.js +129207 -122358
  4. package/dist/browser.mjs +129235 -122386
  5. package/dist/cjs/index.js +5332 -43
  6. package/dist/esm/core/aggregation/cohort.js +178 -0
  7. package/dist/esm/core/aggregation/cohort.js.map +1 -0
  8. package/dist/esm/core/aggregation/errors.js +22 -0
  9. package/dist/esm/core/aggregation/errors.js.map +1 -0
  10. package/dist/esm/core/{beacon/aggregation/cohort → aggregation}/messages/base.js +0 -1
  11. package/dist/esm/core/aggregation/messages/base.js.map +1 -0
  12. package/dist/esm/core/aggregation/messages/constants.js +26 -0
  13. package/dist/esm/core/aggregation/messages/constants.js.map +1 -0
  14. package/dist/esm/core/aggregation/messages/factories.js +113 -0
  15. package/dist/esm/core/aggregation/messages/factories.js.map +1 -0
  16. package/dist/esm/core/aggregation/messages/guards.js +37 -0
  17. package/dist/esm/core/aggregation/messages/guards.js.map +1 -0
  18. package/dist/esm/core/aggregation/messages/index.js +5 -0
  19. package/dist/esm/core/aggregation/messages/index.js.map +1 -0
  20. package/dist/esm/core/aggregation/participant.js +376 -0
  21. package/dist/esm/core/aggregation/participant.js.map +1 -0
  22. package/dist/esm/core/aggregation/phases.js +39 -0
  23. package/dist/esm/core/aggregation/phases.js.map +1 -0
  24. package/dist/esm/core/aggregation/runner/events.js +2 -0
  25. package/dist/esm/core/aggregation/runner/events.js.map +1 -0
  26. package/dist/esm/core/aggregation/runner/index.js +5 -0
  27. package/dist/esm/core/aggregation/runner/index.js.map +1 -0
  28. package/dist/esm/core/aggregation/runner/participant-runner.js +282 -0
  29. package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -0
  30. package/dist/esm/core/aggregation/runner/service-runner.js +290 -0
  31. package/dist/esm/core/aggregation/runner/service-runner.js.map +1 -0
  32. package/dist/esm/core/aggregation/runner/typed-emitter.js +80 -0
  33. package/dist/esm/core/aggregation/runner/typed-emitter.js.map +1 -0
  34. package/dist/esm/core/aggregation/service.js +416 -0
  35. package/dist/esm/core/aggregation/service.js.map +1 -0
  36. package/dist/esm/core/aggregation/signing-session.js +133 -0
  37. package/dist/esm/core/aggregation/signing-session.js.map +1 -0
  38. package/dist/esm/core/aggregation/transport/didcomm.js +32 -0
  39. package/dist/esm/core/aggregation/transport/didcomm.js.map +1 -0
  40. package/dist/esm/core/aggregation/transport/error.js +12 -0
  41. package/dist/esm/core/aggregation/transport/error.js.map +1 -0
  42. package/dist/esm/core/aggregation/transport/factory.js +20 -0
  43. package/dist/esm/core/aggregation/transport/factory.js.map +1 -0
  44. package/dist/esm/core/aggregation/transport/index.js +6 -0
  45. package/dist/esm/core/aggregation/transport/index.js.map +1 -0
  46. package/dist/esm/core/aggregation/transport/nostr.js +262 -0
  47. package/dist/esm/core/aggregation/transport/nostr.js.map +1 -0
  48. package/dist/esm/core/aggregation/transport/transport.js +2 -0
  49. package/dist/esm/core/aggregation/transport/transport.js.map +1 -0
  50. package/dist/esm/core/beacon/beacon.js +80 -0
  51. package/dist/esm/core/beacon/beacon.js.map +1 -1
  52. package/dist/esm/core/beacon/cas-beacon.js +21 -60
  53. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  54. package/dist/esm/core/beacon/error.js +0 -10
  55. package/dist/esm/core/beacon/error.js.map +1 -1
  56. package/dist/esm/core/beacon/fee-estimator.js +30 -0
  57. package/dist/esm/core/beacon/fee-estimator.js.map +1 -0
  58. package/dist/esm/core/beacon/signal-discovery.js +1 -1
  59. package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
  60. package/dist/esm/core/beacon/singleton-beacon.js +13 -56
  61. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  62. package/dist/esm/core/beacon/smt-beacon.js +85 -9
  63. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  64. package/dist/esm/core/beacon/utils.js.map +1 -1
  65. package/dist/esm/core/identifier.js +13 -0
  66. package/dist/esm/core/identifier.js.map +1 -1
  67. package/dist/esm/core/resolver.js +50 -35
  68. package/dist/esm/core/resolver.js.map +1 -1
  69. package/dist/esm/core/update.js.map +1 -1
  70. package/dist/esm/did-btcr2.js +1 -1
  71. package/dist/esm/did-btcr2.js.map +1 -1
  72. package/dist/esm/index.js +14 -24
  73. package/dist/esm/index.js.map +1 -1
  74. package/dist/esm/utils/appendix.js +7 -6
  75. package/dist/esm/utils/appendix.js.map +1 -1
  76. package/dist/esm/utils/did-document-builder.js.map +1 -1
  77. package/dist/esm/utils/did-document.js +2 -2
  78. package/dist/esm/utils/did-document.js.map +1 -1
  79. package/dist/types/core/aggregation/cohort.d.ts +94 -0
  80. package/dist/types/core/aggregation/cohort.d.ts.map +1 -0
  81. package/dist/types/core/aggregation/errors.d.ts +14 -0
  82. package/dist/types/core/aggregation/errors.d.ts.map +1 -0
  83. package/dist/types/core/{beacon/aggregation/cohort → aggregation}/messages/base.d.ts +7 -1
  84. package/dist/types/core/aggregation/messages/base.d.ts.map +1 -0
  85. package/dist/types/core/aggregation/messages/constants.d.ts +23 -0
  86. package/dist/types/core/aggregation/messages/constants.d.ts.map +1 -0
  87. package/dist/types/core/aggregation/messages/factories.d.ts +177 -0
  88. package/dist/types/core/aggregation/messages/factories.d.ts.map +1 -0
  89. package/dist/types/core/aggregation/messages/guards.d.ts +11 -0
  90. package/dist/types/core/aggregation/messages/guards.d.ts.map +1 -0
  91. package/dist/types/core/aggregation/messages/index.d.ts +5 -0
  92. package/dist/types/core/aggregation/messages/index.d.ts.map +1 -0
  93. package/dist/types/core/aggregation/participant.d.ts +101 -0
  94. package/dist/types/core/aggregation/participant.d.ts.map +1 -0
  95. package/dist/types/core/aggregation/phases.d.ts +49 -0
  96. package/dist/types/core/aggregation/phases.d.ts.map +1 -0
  97. package/dist/types/core/aggregation/runner/events.d.ts +89 -0
  98. package/dist/types/core/aggregation/runner/events.d.ts.map +1 -0
  99. package/dist/types/core/aggregation/runner/index.d.ts +5 -0
  100. package/dist/types/core/aggregation/runner/index.d.ts.map +1 -0
  101. package/dist/types/core/aggregation/runner/participant-runner.d.ts +107 -0
  102. package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -0
  103. package/dist/types/core/aggregation/runner/service-runner.d.ts +102 -0
  104. package/dist/types/core/aggregation/runner/service-runner.d.ts.map +1 -0
  105. package/dist/types/core/aggregation/runner/typed-emitter.d.ts +41 -0
  106. package/dist/types/core/aggregation/runner/typed-emitter.d.ts.map +1 -0
  107. package/dist/types/core/aggregation/service.d.ts +112 -0
  108. package/dist/types/core/aggregation/service.d.ts.map +1 -0
  109. package/dist/types/core/aggregation/signing-session.d.ts +69 -0
  110. package/dist/types/core/aggregation/signing-session.d.ts.map +1 -0
  111. package/dist/types/core/aggregation/transport/didcomm.d.ts +20 -0
  112. package/dist/types/core/aggregation/transport/didcomm.d.ts.map +1 -0
  113. package/dist/types/core/{beacon/aggregation/communication → aggregation/transport}/error.d.ts +2 -2
  114. package/dist/types/core/aggregation/transport/error.d.ts.map +1 -0
  115. package/dist/types/core/aggregation/transport/factory.d.ts +13 -0
  116. package/dist/types/core/aggregation/transport/factory.d.ts.map +1 -0
  117. package/dist/types/core/aggregation/transport/index.d.ts +6 -0
  118. package/dist/types/core/aggregation/transport/index.d.ts.map +1 -0
  119. package/dist/types/core/aggregation/transport/nostr.d.ts +55 -0
  120. package/dist/types/core/aggregation/transport/nostr.d.ts.map +1 -0
  121. package/dist/types/core/aggregation/transport/transport.d.ts +37 -0
  122. package/dist/types/core/aggregation/transport/transport.d.ts.map +1 -0
  123. package/dist/types/core/beacon/beacon.d.ts +41 -6
  124. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  125. package/dist/types/core/beacon/cas-beacon.d.ts +23 -11
  126. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  127. package/dist/types/core/beacon/error.d.ts +0 -6
  128. package/dist/types/core/beacon/error.d.ts.map +1 -1
  129. package/dist/types/core/beacon/factory.d.ts +2 -2
  130. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  131. package/dist/types/core/beacon/fee-estimator.d.ts +40 -0
  132. package/dist/types/core/beacon/fee-estimator.d.ts.map +1 -0
  133. package/dist/types/core/beacon/interfaces.d.ts +11 -3
  134. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  135. package/dist/types/core/beacon/signal-discovery.d.ts +3 -3
  136. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
  137. package/dist/types/core/beacon/singleton-beacon.d.ts +14 -7
  138. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  139. package/dist/types/core/beacon/smt-beacon.d.ts +32 -12
  140. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  141. package/dist/types/core/beacon/utils.d.ts +4 -4
  142. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  143. package/dist/types/core/identifier.d.ts +10 -2
  144. package/dist/types/core/identifier.d.ts.map +1 -1
  145. package/dist/types/core/interfaces.d.ts +4 -4
  146. package/dist/types/core/interfaces.d.ts.map +1 -1
  147. package/dist/types/core/resolver.d.ts +19 -9
  148. package/dist/types/core/resolver.d.ts.map +1 -1
  149. package/dist/types/core/types.d.ts +6 -5
  150. package/dist/types/core/types.d.ts.map +1 -1
  151. package/dist/types/core/update.d.ts +5 -5
  152. package/dist/types/core/update.d.ts.map +1 -1
  153. package/dist/types/did-btcr2.d.ts +6 -6
  154. package/dist/types/did-btcr2.d.ts.map +1 -1
  155. package/dist/types/index.d.ts +9 -24
  156. package/dist/types/index.d.ts.map +1 -1
  157. package/dist/types/utils/appendix.d.ts +7 -7
  158. package/dist/types/utils/appendix.d.ts.map +1 -1
  159. package/dist/types/utils/did-document-builder.d.ts +3 -2
  160. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  161. package/dist/types/utils/did-document.d.ts +3 -3
  162. package/dist/types/utils/did-document.d.ts.map +1 -1
  163. package/package.json +35 -33
  164. package/src/core/aggregation/cohort.ts +247 -0
  165. package/src/core/aggregation/errors.ts +25 -0
  166. package/src/core/{beacon/aggregation/cohort → aggregation}/messages/base.ts +8 -3
  167. package/src/core/aggregation/messages/constants.ts +28 -0
  168. package/src/core/aggregation/messages/factories.ts +240 -0
  169. package/src/core/aggregation/messages/guards.ts +55 -0
  170. package/src/core/aggregation/messages/index.ts +4 -0
  171. package/src/core/aggregation/participant.ts +510 -0
  172. package/src/core/aggregation/phases.ts +82 -0
  173. package/src/core/aggregation/runner/events.ts +77 -0
  174. package/src/core/aggregation/runner/index.ts +4 -0
  175. package/src/core/aggregation/runner/participant-runner.ts +360 -0
  176. package/src/core/aggregation/runner/service-runner.ts +365 -0
  177. package/src/core/aggregation/runner/typed-emitter.ts +87 -0
  178. package/src/core/aggregation/service.ts +547 -0
  179. package/src/core/aggregation/signing-session.ts +209 -0
  180. package/src/core/aggregation/transport/didcomm.ts +42 -0
  181. package/src/core/aggregation/transport/error.ts +13 -0
  182. package/src/core/aggregation/transport/factory.ts +29 -0
  183. package/src/core/aggregation/transport/index.ts +5 -0
  184. package/src/core/aggregation/transport/nostr.ts +333 -0
  185. package/src/core/aggregation/transport/transport.ts +46 -0
  186. package/src/core/beacon/beacon.ts +126 -6
  187. package/src/core/beacon/cas-beacon.ts +39 -83
  188. package/src/core/beacon/error.ts +0 -12
  189. package/src/core/beacon/factory.ts +2 -2
  190. package/src/core/beacon/fee-estimator.ts +52 -0
  191. package/src/core/beacon/interfaces.ts +13 -4
  192. package/src/core/beacon/signal-discovery.ts +5 -4
  193. package/src/core/beacon/singleton-beacon.ts +21 -81
  194. package/src/core/beacon/smt-beacon.ts +113 -15
  195. package/src/core/beacon/utils.ts +6 -4
  196. package/src/core/identifier.ts +20 -2
  197. package/src/core/interfaces.ts +4 -4
  198. package/src/core/resolver.ts +84 -53
  199. package/src/core/types.ts +6 -5
  200. package/src/core/update.ts +11 -7
  201. package/src/did-btcr2.ts +12 -10
  202. package/src/index.ts +15 -29
  203. package/src/utils/appendix.ts +14 -16
  204. package/src/utils/did-document-builder.ts +3 -2
  205. package/src/utils/did-document.ts +10 -8
  206. package/dist/cjs/core/beacon/aggregation/cohort/index.js +0 -237
  207. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +0 -1
  208. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +0 -26
  209. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  210. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  211. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  212. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js +0 -98
  213. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  214. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  215. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  216. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  217. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  218. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  219. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  220. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  221. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  222. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  223. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  224. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  225. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  226. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  227. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  228. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  229. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  230. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  231. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  232. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  233. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  234. package/dist/cjs/core/beacon/aggregation/cohort/status.js +0 -8
  235. package/dist/cjs/core/beacon/aggregation/cohort/status.js.map +0 -1
  236. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  237. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  238. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +0 -246
  239. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  240. package/dist/cjs/core/beacon/aggregation/communication/error.js +0 -12
  241. package/dist/cjs/core/beacon/aggregation/communication/error.js.map +0 -1
  242. package/dist/cjs/core/beacon/aggregation/communication/factory.js +0 -21
  243. package/dist/cjs/core/beacon/aggregation/communication/factory.js.map +0 -1
  244. package/dist/cjs/core/beacon/aggregation/communication/service.js +0 -2
  245. package/dist/cjs/core/beacon/aggregation/communication/service.js.map +0 -1
  246. package/dist/cjs/core/beacon/aggregation/coordinator.js +0 -343
  247. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +0 -1
  248. package/dist/cjs/core/beacon/aggregation/participant.js +0 -435
  249. package/dist/cjs/core/beacon/aggregation/participant.js.map +0 -1
  250. package/dist/cjs/core/beacon/aggregation/session/index.js +0 -244
  251. package/dist/cjs/core/beacon/aggregation/session/index.js.map +0 -1
  252. package/dist/cjs/core/beacon/aggregation/session/status.js +0 -11
  253. package/dist/cjs/core/beacon/aggregation/session/status.js.map +0 -1
  254. package/dist/cjs/core/beacon/beacon.js +0 -25
  255. package/dist/cjs/core/beacon/beacon.js.map +0 -1
  256. package/dist/cjs/core/beacon/cas-beacon.js +0 -152
  257. package/dist/cjs/core/beacon/cas-beacon.js.map +0 -1
  258. package/dist/cjs/core/beacon/error.js +0 -37
  259. package/dist/cjs/core/beacon/error.js.map +0 -1
  260. package/dist/cjs/core/beacon/factory.js +0 -29
  261. package/dist/cjs/core/beacon/factory.js.map +0 -1
  262. package/dist/cjs/core/beacon/interfaces.js +0 -2
  263. package/dist/cjs/core/beacon/interfaces.js.map +0 -1
  264. package/dist/cjs/core/beacon/signal-discovery.js +0 -183
  265. package/dist/cjs/core/beacon/signal-discovery.js.map +0 -1
  266. package/dist/cjs/core/beacon/singleton-beacon.js +0 -107
  267. package/dist/cjs/core/beacon/singleton-beacon.js.map +0 -1
  268. package/dist/cjs/core/beacon/smt-beacon.js +0 -39
  269. package/dist/cjs/core/beacon/smt-beacon.js.map +0 -1
  270. package/dist/cjs/core/beacon/utils.js +0 -163
  271. package/dist/cjs/core/beacon/utils.js.map +0 -1
  272. package/dist/cjs/core/identifier.js +0 -248
  273. package/dist/cjs/core/identifier.js.map +0 -1
  274. package/dist/cjs/core/interfaces.js +0 -2
  275. package/dist/cjs/core/interfaces.js.map +0 -1
  276. package/dist/cjs/core/resolver.js +0 -476
  277. package/dist/cjs/core/resolver.js.map +0 -1
  278. package/dist/cjs/core/types.js +0 -2
  279. package/dist/cjs/core/types.js.map +0 -1
  280. package/dist/cjs/core/update.js +0 -112
  281. package/dist/cjs/core/update.js.map +0 -1
  282. package/dist/cjs/did-btcr2.js +0 -193
  283. package/dist/cjs/did-btcr2.js.map +0 -1
  284. package/dist/cjs/index.js.map +0 -1
  285. package/dist/cjs/utils/appendix.js +0 -203
  286. package/dist/cjs/utils/appendix.js.map +0 -1
  287. package/dist/cjs/utils/did-document-builder.js +0 -60
  288. package/dist/cjs/utils/did-document-builder.js.map +0 -1
  289. package/dist/cjs/utils/did-document.js +0 -424
  290. package/dist/cjs/utils/did-document.js.map +0 -1
  291. package/dist/esm/core/beacon/aggregation/cohort/index.js +0 -237
  292. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +0 -1
  293. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  294. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  295. package/dist/esm/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  296. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js +0 -98
  297. package/dist/esm/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  298. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  299. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  300. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  301. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  302. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  303. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  304. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  305. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  306. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  307. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  308. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  309. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  310. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  311. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  312. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  313. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  314. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  315. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  316. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  317. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  318. package/dist/esm/core/beacon/aggregation/cohort/status.js +0 -8
  319. package/dist/esm/core/beacon/aggregation/cohort/status.js.map +0 -1
  320. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  321. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  322. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +0 -246
  323. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  324. package/dist/esm/core/beacon/aggregation/communication/error.js +0 -12
  325. package/dist/esm/core/beacon/aggregation/communication/error.js.map +0 -1
  326. package/dist/esm/core/beacon/aggregation/communication/factory.js +0 -21
  327. package/dist/esm/core/beacon/aggregation/communication/factory.js.map +0 -1
  328. package/dist/esm/core/beacon/aggregation/communication/service.js +0 -2
  329. package/dist/esm/core/beacon/aggregation/communication/service.js.map +0 -1
  330. package/dist/esm/core/beacon/aggregation/coordinator.js +0 -343
  331. package/dist/esm/core/beacon/aggregation/coordinator.js.map +0 -1
  332. package/dist/esm/core/beacon/aggregation/participant.js +0 -435
  333. package/dist/esm/core/beacon/aggregation/participant.js.map +0 -1
  334. package/dist/esm/core/beacon/aggregation/session/index.js +0 -244
  335. package/dist/esm/core/beacon/aggregation/session/index.js.map +0 -1
  336. package/dist/esm/core/beacon/aggregation/session/status.js +0 -11
  337. package/dist/esm/core/beacon/aggregation/session/status.js.map +0 -1
  338. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +0 -136
  339. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +0 -1
  340. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +0 -1
  341. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts +0 -11
  342. package/dist/types/core/beacon/aggregation/cohort/messages/constants.d.ts.map +0 -1
  343. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +0 -65
  344. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +0 -1
  345. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +0 -29
  346. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +0 -1
  347. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +0 -26
  348. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +0 -1
  349. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +0 -24
  350. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +0 -1
  351. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +0 -20
  352. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +0 -1
  353. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +0 -25
  354. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +0 -1
  355. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +0 -25
  356. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +0 -1
  357. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +0 -26
  358. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +0 -1
  359. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +0 -26
  360. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +0 -1
  361. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +0 -26
  362. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +0 -1
  363. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +0 -27
  364. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +0 -1
  365. package/dist/types/core/beacon/aggregation/cohort/status.d.ts +0 -8
  366. package/dist/types/core/beacon/aggregation/cohort/status.d.ts.map +0 -1
  367. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +0 -89
  368. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +0 -1
  369. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +0 -103
  370. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +0 -1
  371. package/dist/types/core/beacon/aggregation/communication/error.d.ts.map +0 -1
  372. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +0 -10
  373. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +0 -1
  374. package/dist/types/core/beacon/aggregation/communication/service.d.ts +0 -36
  375. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +0 -1
  376. package/dist/types/core/beacon/aggregation/coordinator.d.ts +0 -116
  377. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +0 -1
  378. package/dist/types/core/beacon/aggregation/participant.d.ts +0 -192
  379. package/dist/types/core/beacon/aggregation/participant.d.ts.map +0 -1
  380. package/dist/types/core/beacon/aggregation/session/index.d.ts +0 -156
  381. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +0 -1
  382. package/dist/types/core/beacon/aggregation/session/status.d.ts +0 -11
  383. package/dist/types/core/beacon/aggregation/session/status.d.ts.map +0 -1
  384. package/src/core/beacon/aggregation/cohort/index.ts +0 -304
  385. package/src/core/beacon/aggregation/cohort/messages/constants.ts +0 -12
  386. package/src/core/beacon/aggregation/cohort/messages/index.ts +0 -143
  387. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +0 -43
  388. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +0 -39
  389. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +0 -34
  390. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +0 -33
  391. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +0 -35
  392. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +0 -38
  393. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +0 -39
  394. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +0 -39
  395. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +0 -39
  396. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +0 -40
  397. package/src/core/beacon/aggregation/cohort/status.ts +0 -7
  398. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +0 -147
  399. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +0 -321
  400. package/src/core/beacon/aggregation/communication/error.ts +0 -13
  401. package/src/core/beacon/aggregation/communication/factory.ts +0 -25
  402. package/src/core/beacon/aggregation/communication/service.ts +0 -42
  403. package/src/core/beacon/aggregation/coordinator.ts +0 -415
  404. package/src/core/beacon/aggregation/participant.ts +0 -512
  405. package/src/core/beacon/aggregation/session/index.ts +0 -300
  406. package/src/core/beacon/aggregation/session/status.ts +0 -18
@@ -1,14 +1,24 @@
1
- import { BitcoinConnection } from '@did-btcr2/bitcoin';
2
- import { KeyBytes } from '@did-btcr2/common';
3
- import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
4
- import type { BeaconProcessResult } from '../resolver.js';
5
- import { SidecarData } from '../types.js';
1
+ import type { BitcoinConnection } from '@did-btcr2/bitcoin';
2
+ import { canonicalize } from '@did-btcr2/common';
3
+ import type { KeyBytes } from '@did-btcr2/common';
4
+ import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
5
+ import { blockHash, BTCR2MerkleTree, didToIndex, hexToHash, verifySerializedProof } from '@did-btcr2/smt';
6
+ import { randomBytes } from '@noble/hashes/utils';
7
+ import type { BeaconProcessResult, DataNeed } from '../resolver.js';
8
+ import type { SidecarData } from '../types.js';
9
+ import type { BroadcastOptions } from './beacon.js';
6
10
  import { Beacon } from './beacon.js';
7
11
  import { SMTBeaconError } from './error.js';
8
- import { BeaconService, BeaconSignal } from './interfaces.js';
12
+ import type { BeaconService, BeaconSignal, BlockMetadata } from './interfaces.js';
9
13
 
10
14
  /**
11
- * Implements {@link https://dcdpr.github.io/did-btcr2/terminology.html#smt-beacon | SMTBeacon}.
15
+ * Implements {@link https://dcdpr.github.io/did-btcr2/terminology.html#smt-beacon | SMT Beacon}.
16
+ *
17
+ * An SMT (Sparse Merkle Tree) Beacon aggregates updates for multiple DIDs
18
+ * into a single Merkle root hash broadcast on-chain via OP_RETURN.
19
+ * During resolution, the SMT Proof from the sidecar is verified against the
20
+ * on-chain root, and the proof's updateId is used to retrieve the signed update.
21
+ *
12
22
  * @class SMTBeacon
13
23
  * @type {SMTBeacon}
14
24
  * @extends {Beacon}
@@ -24,31 +34,119 @@ export class SMTBeacon extends Beacon {
24
34
 
25
35
  /**
26
36
  * Implements {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-smt-beacon | 7.2.e.1 Process SMT Beacon}.
37
+ *
38
+ * For each signal, the signalBytes contain the hex-encoded SMT root hash.
39
+ * This method looks up the SMT Proof from the sidecar by root hash,
40
+ * validates the Merkle inclusion proof, and retrieves the corresponding
41
+ * signed update using the proof's updateId.
42
+ *
27
43
  * @param {Array<BeaconSignal>} signals The array of Beacon Signals to process.
28
44
  * @param {SidecarData} sidecar The sidecar data associated with the SMT Beacon.
29
- * @returns {BeaconProcessResult} The processed signals.
30
- * @throws {SMTBeaconError} if processing fails.
45
+ * @returns {BeaconProcessResult} Successfully resolved updates and any data needs.
46
+ * @throws {SMTBeaconError} if proof verification fails or proof is malformed.
31
47
  */
32
48
  processSignals(
33
49
  signals: Array<BeaconSignal>,
34
50
  sidecar: SidecarData
35
51
  ): BeaconProcessResult {
36
- throw new SMTBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signals, sidecar});
52
+ const updates = new Array<[SignedBTCR2Update, BlockMetadata]>();
53
+ const needs = new Array<DataNeed>();
54
+
55
+ // Extract the DID from the beacon service id (strip the #fragment)
56
+ const did = this.service.id.split('#')[0];
57
+
58
+ for(const signal of signals) {
59
+ // Signal bytes are the hex-encoded SMT root hash; smtMap is keyed by proof.id (also hex)
60
+ const smtProof = sidecar.smtMap.get(signal.signalBytes);
61
+
62
+ if(!smtProof) {
63
+ // SMT Proof not available — emit a need
64
+ needs.push({
65
+ kind : 'NeedSMTProof',
66
+ smtRootHash : signal.signalBytes,
67
+ beaconServiceId : this.service.id
68
+ });
69
+ continue;
70
+ }
71
+
72
+ // Non-inclusion proof — no update for this DID in this epoch, skip
73
+ if(!smtProof.updateId) {
74
+ continue;
75
+ }
76
+
77
+ // Nonce is required for proof verification
78
+ if(!smtProof.nonce) {
79
+ throw new SMTBeaconError(
80
+ 'SMT proof missing required nonce field.',
81
+ 'INVALID_SMT_PROOF', { smtProof, did }
82
+ );
83
+ }
84
+
85
+ // Verify Merkle inclusion: leaf = hash(hash(nonce) || updateId)
86
+ const index = didToIndex(did);
87
+ const candidateHash = blockHash(blockHash(hexToHash(smtProof.nonce)), hexToHash(smtProof.updateId));
88
+ const valid = verifySerializedProof(smtProof, index, candidateHash);
89
+
90
+ if(!valid) {
91
+ throw new SMTBeaconError(
92
+ 'SMT proof verification failed.',
93
+ 'INVALID_SMT_PROOF', { smtProof, did }
94
+ );
95
+ }
96
+
97
+ // Look up the signed update in sidecar updateMap (keyed by hex canonical hash)
98
+ const signedUpdate = sidecar.updateMap.get(smtProof.updateId);
99
+
100
+ if(!signedUpdate) {
101
+ // Signed update not available — emit a need
102
+ needs.push({
103
+ kind : 'NeedSignedUpdate',
104
+ updateHash : smtProof.updateId,
105
+ beaconServiceId : this.service.id
106
+ });
107
+ continue;
108
+ }
109
+
110
+ updates.push([signedUpdate, signal.blockMetadata]);
111
+ }
112
+
113
+ return { updates, needs };
37
114
  }
38
115
 
39
116
  /**
40
- * Broadcast CAS Beacon signal to the Bitcoin network.
117
+ * Broadcasts an SMT Beacon signal to the Bitcoin network.
118
+ *
119
+ * Builds a single-entry Sparse Merkle Tree from the signed update, then broadcasts the tree's
120
+ * root hash via OP_RETURN. For multi-party aggregation, use the {@link AggregationService}
121
+ * subsystem directly instead of this method. UTXO selection, PSBT construction, fee estimation,
122
+ * signing, and broadcast are delegated to {@link Beacon.buildSignAndBroadcast}.
123
+ *
41
124
  * @param {SignedBTCR2Update} signedUpdate The signed BTCR2 update to broadcast.
42
125
  * @param {KeyBytes} secretKey The secret key for signing the Bitcoin transaction.
43
126
  * @param {BitcoinConnection} bitcoin The Bitcoin network connection.
44
- * @return {Promise<SignedBTCR2Update>} The signed update that was broadcasted.
45
- * @throws {SMTBeaconError} if broadcasting fails.
127
+ * @param {BroadcastOptions} [options] Optional broadcast configuration (e.g. fee estimator).
128
+ * @return {Promise<SignedBTCR2Update>} The signed update that was broadcast.
129
+ * @throws {BeaconError} if the bitcoin address is invalid, unfunded, or UTXO cannot cover the fee.
46
130
  */
47
131
  async broadcastSignal(
48
132
  signedUpdate: SignedBTCR2Update,
49
133
  secretKey: KeyBytes,
50
- bitcoin: BitcoinConnection
134
+ bitcoin: BitcoinConnection,
135
+ options?: BroadcastOptions
51
136
  ): Promise<SignedBTCR2Update> {
52
- throw new SMTBeaconError('Method not implemented.', `METHOD_NOT_IMPLEMENTED`, {signedUpdate, secretKey, bitcoin});
137
+ // Extract the DID from the beacon service id (strip the #fragment)
138
+ const did = this.service.id.split('#')[0];
139
+
140
+ // Build a single-entry SMT from the signed update
141
+ const canonicalBytes = new TextEncoder().encode(canonicalize(signedUpdate));
142
+ const nonce = randomBytes(32);
143
+ const tree = new BTCR2MerkleTree();
144
+ tree.addEntries([{ did, nonce, signedUpdate: canonicalBytes }]);
145
+ tree.finalize();
146
+
147
+ // Root hash is the signal bytes for the OP_RETURN output
148
+ await this.buildSignAndBroadcast(tree.rootHash, secretKey, bitcoin, options);
149
+
150
+ return signedUpdate;
53
151
  }
54
152
  }
@@ -1,10 +1,12 @@
1
1
  import { getNetwork } from '@did-btcr2/bitcoin';
2
- import { DidMethodError, KeyBytes, Maybe, MethodError } from '@did-btcr2/common';
3
- import { networks, payments } from 'bitcoinjs-lib';
2
+ import type { KeyBytes, Maybe} from '@did-btcr2/common';
3
+ import { DidMethodError, MethodError } from '@did-btcr2/common';
4
+ import type { networks} from 'bitcoinjs-lib';
5
+ import { payments } from 'bitcoinjs-lib';
4
6
  import { Appendix } from '../../utils/appendix.js';
5
- import { DidDocument } from '../../utils/did-document.js';
7
+ import type { DidDocument } from '../../utils/did-document.js';
6
8
  import { Identifier } from '../identifier.js';
7
- import { BeaconService } from './interfaces.js';
9
+ import type { BeaconService } from './interfaces.js';
8
10
  import { BeaconError } from './error.js';
9
11
 
10
12
  /**
@@ -1,7 +1,8 @@
1
- import { BitcoinNetworkNames, Bytes, DocumentBytes, IdentifierError, IdentifierTypes, INVALID_DID, KeyBytes, METHOD_NOT_SUPPORTED, SchnorrKeyPairObject } from '@did-btcr2/common';
1
+ import type { Bytes, DocumentBytes, KeyBytes, SchnorrKeyPairObject } from '@did-btcr2/common';
2
+ import { BitcoinNetworkNames, IdentifierError, IdentifierTypes, INVALID_DID, METHOD_NOT_SUPPORTED } from '@did-btcr2/common';
2
3
  import { CompressedSecp256k1PublicKey, SchnorrKeyPair } from '@did-btcr2/keypair';
3
4
  import { bech32m } from '@scure/base';
4
- import { DidCreateOptions } from '../did-btcr2.js';
5
+ import type { DidCreateOptions } from '../did-btcr2.js';
5
6
 
6
7
  /**
7
8
  * Components of a did:btcr2 identifier.
@@ -290,6 +291,23 @@ export class Identifier {
290
291
  return { keyPair: keyPair.exportJSON(), did };
291
292
  }
292
293
 
294
+ /**
295
+ * Extracts the compressed secp256k1 public key from a KEY-type did:btcr2 identifier.
296
+ * @param {string} did The did:btcr2 identifier to extract the public key from.
297
+ * @returns {CompressedSecp256k1PublicKey} The compressed public key.
298
+ * @throws {IdentifierError} If the DID is EXTERNAL type (genesis bytes are a hash, not a pubkey).
299
+ */
300
+ static getPublicKey(did: string): CompressedSecp256k1PublicKey {
301
+ const { idType, genesisBytes } = Identifier.decode(did);
302
+ if(idType !== 'KEY') {
303
+ throw new IdentifierError(
304
+ `Cannot extract public key from EXTERNAL DID: ${did}. EXTERNAL DIDs encode a document hash, not a public key.`,
305
+ INVALID_DID, { did, idType }
306
+ );
307
+ }
308
+ return new CompressedSecp256k1PublicKey(genesisBytes);
309
+ }
310
+
293
311
  /**
294
312
  * Validates a did:btcr2 identifier.
295
313
  * @param {string} identifier The did:btcr2 identifier to validate.
@@ -1,5 +1,5 @@
1
- import { DidResolutionOptions } from '@web5/dids';
2
- import { Sidecar } from './types.js';
1
+ import type { DidResolutionOptions } from '@web5/dids';
2
+ import type { Sidecar } from './types.js';
3
3
 
4
4
  export interface RootCapability {
5
5
  '@context': string;
@@ -64,11 +64,11 @@ export interface SMTProof {
64
64
  */
65
65
  id: string;
66
66
  /**
67
- * Optional 256-bit nonce generated for each update. MUST be encoded as a string using the "base64url" [RFC4648] encoding.
67
+ * Optional 256-bit nonce generated for each update. Hex-encoded (64 chars).
68
68
  */
69
69
  nonce?: string;
70
70
  /**
71
- * Optional BTCR2 Signed Update (data structure) hashed with the JSON Document Hashing algorithm.
71
+ * Optional hex-encoded canonical hash of the BTCR2 Signed Update.
72
72
  */
73
73
  updateId?: string;
74
74
  /**
@@ -1,6 +1,7 @@
1
1
  import { getNetwork } from '@did-btcr2/bitcoin';
2
2
  import {
3
3
  canonicalHash,
4
+ canonicalHashBytes,
4
5
  canonicalize,
5
6
  DateUtils,
6
7
  encode as encodeHash,
@@ -12,23 +13,28 @@ import {
12
13
  LATE_PUBLISHING_ERROR,
13
14
  ResolveError
14
15
  } from '@did-btcr2/common';
16
+ import type { HashBytes } from '@did-btcr2/common';
17
+ import type {
18
+ SignedBTCR2Update,
19
+ UnsignedBTCR2Update
20
+ } from '@did-btcr2/cryptosuite';
15
21
  import {
16
22
  BIP340Cryptosuite,
17
23
  BIP340DataIntegrityProof,
18
- SchnorrMultikey,
19
- SignedBTCR2Update,
20
- UnsignedBTCR2Update
24
+ SchnorrMultikey
21
25
  } from '@did-btcr2/cryptosuite';
22
26
  import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
23
27
  import { DidBtcr2 } from '../did-btcr2.js';
24
28
  import { Appendix } from '../utils/appendix.js';
25
29
  import { DidDocument, ID_PLACEHOLDER_VALUE } from '../utils/did-document.js';
26
30
  import { BeaconFactory } from './beacon/factory.js';
27
- import { BeaconService, BeaconSignal, BlockMetadata } from './beacon/interfaces.js';
31
+ import type { BeaconService, BeaconSignal, BlockMetadata } from './beacon/interfaces.js';
28
32
  import { BeaconUtils } from './beacon/utils.js';
29
- import { DidComponents, Identifier } from './identifier.js';
30
- import { SMTProof } from './interfaces.js';
31
- import { CASAnnouncement, Sidecar, SidecarData } from './types.js';
33
+ import type { DidComponents} from './identifier.js';
34
+ import { Identifier } from './identifier.js';
35
+ import type { SMTProof } from './interfaces.js';
36
+ import type { CASAnnouncement, Sidecar, SidecarData } from './types.js';
37
+ import { equalBytes } from '@noble/curves/utils.js';
32
38
 
33
39
  /**
34
40
  * The response object for DID Resolution.
@@ -46,7 +52,7 @@ export interface DidResolutionResponse {
46
52
  /** The resolver needs a genesis document whose hash matches genesisHash. */
47
53
  export interface NeedGenesisDocument {
48
54
  readonly kind: 'NeedGenesisDocument';
49
- /** Base64url-encoded SHA-256 hash from the DID identifier's genesisBytes. */
55
+ /** Hex-encoded SHA-256 hash from the DID identifier's genesisBytes. */
50
56
  readonly genesisHash: string;
51
57
  }
52
58
 
@@ -60,7 +66,7 @@ export interface NeedBeaconSignals {
60
66
  /** The resolver needs a CAS Announcement whose canonical hash matches announcementHash. */
61
67
  export interface NeedCASAnnouncement {
62
68
  readonly kind: 'NeedCASAnnouncement';
63
- /** Base64url-encoded canonical hash of the CAS Announcement. */
69
+ /** Hex-encoded canonical hash of the CAS Announcement. */
64
70
  readonly announcementHash: string;
65
71
  /** The beacon service that produced this signal. */
66
72
  readonly beaconServiceId: string;
@@ -69,14 +75,23 @@ export interface NeedCASAnnouncement {
69
75
  /** The resolver needs a SignedBTCR2Update whose canonical hash matches updateHash. */
70
76
  export interface NeedSignedUpdate {
71
77
  readonly kind: 'NeedSignedUpdate';
72
- /** Base64url-encoded canonical hash of the signed update. */
78
+ /** Hex-encoded canonical hash of the signed update. */
73
79
  readonly updateHash: string;
74
80
  /** The beacon service that produced this signal. */
75
81
  readonly beaconServiceId: string;
76
82
  }
77
83
 
84
+ /** The resolver needs an SMT Proof whose root hash matches smtRootHash. */
85
+ export interface NeedSMTProof {
86
+ readonly kind: 'NeedSMTProof';
87
+ /** Hex-encoded SHA-256 root hash of the Sparse Merkle Tree. */
88
+ readonly smtRootHash: string;
89
+ /** The beacon service that produced this signal. */
90
+ readonly beaconServiceId: string;
91
+ }
92
+
78
93
  /** Discriminated union of all data the resolver may request from the caller. */
79
- export type DataNeed = NeedGenesisDocument | NeedBeaconSignals | NeedCASAnnouncement | NeedSignedUpdate;
94
+ export type DataNeed = NeedGenesisDocument | NeedBeaconSignals | NeedCASAnnouncement | NeedSignedUpdate | NeedSMTProof;
80
95
 
81
96
  /**
82
97
  * Output of {@link Resolver.resolve}. Analogous to Rust's `ResolverState` enum.
@@ -220,22 +235,22 @@ export class Resolver {
220
235
  didComponents: DidComponents,
221
236
  genesisDocument: object,
222
237
  ): DidDocument {
223
- // Encode the genesis bytes from the did components
224
- const genesisBytes = encodeHash(didComponents.genesisBytes);
238
+ // Canonicalize and sha256 hash the genesis document
239
+ const genesisDocumentHash = canonicalHashBytes(genesisDocument);
225
240
 
226
- // Canonicalize and sha256 hash the currentDocument
227
- const genesisDocumentBytes = canonicalHash(genesisDocument);
228
-
229
- // If the genesisBytes do not match the hashBytes, throw an error
230
- if (genesisBytes !== genesisDocumentBytes) {
241
+ // Compare genesis bytes from identifier against the document hash (byte comparison)
242
+ if (!equalBytes(didComponents.genesisBytes, genesisDocumentHash)) {
231
243
  throw new ResolveError(
232
- `Initial document mismatch: genesisBytes !== genesisDocumentBytes`,
233
- INVALID_DID_DOCUMENT, { genesisBytes, genesisDocumentBytes }
244
+ `Initial document mismatch: genesisBytes !== genesisDocumentHash`,
245
+ INVALID_DID_DOCUMENT, {
246
+ genesisBytes : encodeHash(didComponents.genesisBytes, 'hex'),
247
+ genesisDocumentHash : encodeHash(genesisDocumentHash, 'hex')
248
+ }
234
249
  );
235
250
  }
236
251
 
237
252
  // Encode the did from the didComponents
238
- const did = Identifier.encode(decodeHash(genesisBytes), didComponents);
253
+ const did = Identifier.encode(didComponents.genesisBytes, didComponents);
239
254
 
240
255
  // Replace the placeholder did with the did throughout the currentDocument.
241
256
  const currentDocument = JSON.parse(
@@ -256,14 +271,14 @@ export class Resolver {
256
271
  const updateMap = new Map<string, SignedBTCR2Update>();
257
272
  if(sidecar.updates?.length)
258
273
  for(const update of sidecar.updates) {
259
- updateMap.set(canonicalHash(update), update);
274
+ updateMap.set(canonicalHash(update, { encoding: 'hex' }), update);
260
275
  }
261
276
 
262
277
  // CAS Announcements map
263
278
  const casMap = new Map<string, CASAnnouncement>();
264
279
  if(sidecar.casUpdates?.length)
265
280
  for(const update of sidecar.casUpdates) {
266
- casMap.set(canonicalHash(update), update);
281
+ casMap.set(canonicalHash(update, { encoding: 'hex' }), update);
267
282
  }
268
283
 
269
284
  // SMT Proofs map
@@ -293,8 +308,8 @@ export class Resolver {
293
308
  // Start the version number being processed at 1
294
309
  let currentVersionId = 1;
295
310
 
296
- // Initialize an empty array to hold the update hashes
297
- const updateHashHistory: string[] = [];
311
+ // Initialize an empty array to hold the update hashes (raw bytes)
312
+ const updateHashHistory: HashBytes[] = [];
298
313
 
299
314
  // 1. Sort updates by targetVersionId (ascending), using blockheight as tie-breaker
300
315
  const updates = unsortedUpdates.sort(([upd0, blk0], [upd1, blk1]) =>
@@ -314,8 +329,8 @@ export class Resolver {
314
329
 
315
330
  // Iterate over each (update block) pair
316
331
  for(const [update, block] of updates) {
317
- // Get the hash of the current document
318
- const currentDocumentHash = canonicalHash(response.didDocument);
332
+ // Get the hash of the current document as raw bytes
333
+ const currentDocumentHash = canonicalHashBytes(response.didDocument);
319
334
 
320
335
  // Safely convert block.time to timestamp
321
336
  const blocktime = DateUtils.blocktimeToTimestamp(block.time);
@@ -345,12 +360,15 @@ export class Resolver {
345
360
 
346
361
  // If update.targetVersionId == currentVersionId + 1, apply the update
347
362
  else if (update.targetVersionId === currentVersionId + 1) {
348
- // Check if update.sourceHash !== currentDocumentHash
349
- if (update.sourceHash !== currentDocumentHash) {
350
- // Raise an INVALID_DID_UPDATE error if they do not match
363
+ // Check if update.sourceHash !== currentDocumentHash (byte comparison)
364
+ const sourceHashBytes = decodeHash(update.sourceHash, 'base64urlnopad');
365
+ if (!equalBytes(sourceHashBytes, currentDocumentHash)) {
351
366
  throw new ResolveError(
352
367
  `Hash mismatch: update.sourceHash !== currentDocumentHash`,
353
- INVALID_DID_UPDATE, { sourceHash: update.sourceHash, currentDocumentHash }
368
+ INVALID_DID_UPDATE, {
369
+ sourceHash : update.sourceHash,
370
+ currentDocumentHash : encodeHash(currentDocumentHash, 'hex')
371
+ }
354
372
  );
355
373
  }
356
374
  // Apply the update to the currentDocument and set it in the response
@@ -358,8 +376,8 @@ export class Resolver {
358
376
 
359
377
  // Create unsigned_update by removing the proof property from update.
360
378
  const unsignedUpdate = JSONUtils.deleteKeys(update, ['proof']) as UnsignedBTCR2Update;
361
- // Push the canonicalized unsigned update hash to the updateHashHistory
362
- updateHashHistory.push(canonicalHash(unsignedUpdate));
379
+ // Push the canonicalized unsigned update hash bytes to the updateHashHistory
380
+ updateHashHistory.push(canonicalHashBytes(unsignedUpdate));
363
381
  }
364
382
 
365
383
  // If update.targetVersionId > currentVersionId + 1, throw LATE_PUBLISHING error
@@ -398,30 +416,31 @@ export class Resolver {
398
416
  return response;
399
417
  }
400
418
 
401
- // ─── Private static: update internals ──────────────────────────────
402
-
403
419
  /**
404
420
  * Implements subsection {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.f.1 Confirm Duplicate Update}.
405
421
  * This step confirms that an update with a lower-than-expected targetVersionId is a true duplicate.
406
422
  * @param {SignedBTCR2Update} update The BTCR2 Signed Update to confirm as a duplicate.
407
- * @param {string[]} updateHashHistory The accumulated hash history for comparison.
423
+ * @param {HashBytes[]} updateHashHistory The accumulated hash history for comparison.
408
424
  * @returns {void} Does not return a value, but throws an error if the update is not a valid duplicate.
409
425
  */
410
- private static confirmDuplicate(update: SignedBTCR2Update, updateHashHistory: string[]): void {
426
+ private static confirmDuplicate(update: SignedBTCR2Update, updateHashHistory: HashBytes[]): void {
411
427
  // Create unsigned_update by removing the proof property from update.
412
428
  const { proof: _, ...unsignedUpdate } = update;
413
429
 
414
- // Hash unsignedUpdate with JSON Document Hashing algorithm
415
- const unsignedUpdateHash = canonicalHash(unsignedUpdate);
430
+ // Hash unsignedUpdate with JSON Document Hashing algorithm (raw bytes)
431
+ const unsignedUpdateHash = canonicalHashBytes(unsignedUpdate);
416
432
 
417
433
  // Let historicalUpdateHash equal updateHashHistory[updateHashIndex].
418
434
  const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
419
435
 
420
- // Check if the updateHash matches the historical hash
421
- if (updateHashHistory[update.targetVersionId - 2] !== unsignedUpdateHash) {
436
+ // Check if the updateHash matches the historical hash (byte comparison)
437
+ if (!equalBytes(historicalUpdateHash, unsignedUpdateHash)) {
422
438
  throw new ResolveError(
423
- `Invalid duplicate: ${unsignedUpdateHash} does not match ${historicalUpdateHash}`,
424
- LATE_PUBLISHING_ERROR, { unsignedUpdateHash, updateHashHistory }
439
+ `Invalid duplicate: unsigned update hash does not match historical hash`,
440
+ LATE_PUBLISHING_ERROR, {
441
+ unsignedUpdateHash : encodeHash(unsignedUpdateHash, 'hex'),
442
+ historicalHash : encodeHash(historicalUpdateHash, 'hex')
443
+ }
425
444
  );
426
445
  }
427
446
  }
@@ -499,14 +518,14 @@ export class Resolver {
499
518
  // Verify that updatedDocument is conformant to DID Core v1.1.
500
519
  DidDocument.validate(updatedDocument);
501
520
 
502
- // Canonicalize and hash the updatedDocument to get the currentDocumentHash.
503
- const currentDocumentHash = canonicalHash(updatedDocument);
521
+ // Canonicalize and hash the updatedDocument to get the currentDocumentHash (raw bytes).
522
+ const currentDocumentHash = canonicalHashBytes(updatedDocument);
504
523
 
505
524
  // Prepare the update targetHash for comparison with currentDocumentHash.
506
- const updateTargetHash = update.targetHash;
525
+ const updateTargetHash = decodeHash(update.targetHash);
507
526
 
508
527
  // Make sure the update.targetHash equals currentDocumentHash.
509
- if (update.targetHash !== currentDocumentHash) {
528
+ if (!equalBytes(updateTargetHash, currentDocumentHash)) {
510
529
  // If they do not match, throw INVALID_DID_UPDATE error.
511
530
  throw new ResolveError(
512
531
  `Invalid update: update.targetHash !== currentDocumentHash`,
@@ -518,8 +537,6 @@ export class Resolver {
518
537
  return updatedDocument;
519
538
  }
520
539
 
521
- // ─── Instance: state machine ───────────────────────────────────────
522
-
523
540
  /**
524
541
  * Advance the state machine. Returns either:
525
542
  * - `{ status: 'action-required', needs }` — caller must provide data via {@link provide}
@@ -546,7 +563,7 @@ export class Resolver {
546
563
  }
547
564
 
548
565
  // Need genesis document from caller
549
- const genesisHash = encodeHash(this.#didComponents.genesisBytes);
566
+ const genesisHash = encodeHash(this.#didComponents.genesisBytes, 'hex');
550
567
  return {
551
568
  status : 'action-required',
552
569
  needs : [{ kind: 'NeedGenesisDocument', genesisHash }]
@@ -675,7 +692,8 @@ export class Resolver {
675
692
  provide(need: NeedBeaconSignals, data: Map<BeaconService, Array<BeaconSignal>>): void;
676
693
  provide(need: NeedCASAnnouncement, data: CASAnnouncement): void;
677
694
  provide(need: NeedSignedUpdate, data: SignedBTCR2Update): void;
678
- provide(need: DataNeed, data: object | Map<BeaconService, Array<BeaconSignal>> | CASAnnouncement | SignedBTCR2Update): void {
695
+ provide(need: NeedSMTProof, data: SMTProof): void;
696
+ provide(need: DataNeed, data: object | Map<BeaconService, Array<BeaconSignal>> | CASAnnouncement | SignedBTCR2Update | SMTProof): void {
679
697
  switch(need.kind) {
680
698
  case 'NeedGenesisDocument': {
681
699
  this.#providedGenesisDocument = data;
@@ -692,13 +710,26 @@ export class Resolver {
692
710
 
693
711
  case 'NeedCASAnnouncement': {
694
712
  const announcement = data as CASAnnouncement;
695
- this.#sidecarData.casMap.set(canonicalHash(announcement), announcement);
713
+ this.#sidecarData.casMap.set(canonicalHash(announcement, { encoding: 'hex' }), announcement);
696
714
  break;
697
715
  }
698
716
 
699
717
  case 'NeedSignedUpdate': {
700
718
  const update = data as SignedBTCR2Update;
701
- this.#sidecarData.updateMap.set(canonicalHash(update), update);
719
+ this.#sidecarData.updateMap.set(canonicalHash(update, { encoding: 'hex' }), update);
720
+ break;
721
+ }
722
+
723
+ case 'NeedSMTProof': {
724
+ const smtNeed = need as NeedSMTProof;
725
+ const proof = data as SMTProof;
726
+ if(proof.id !== smtNeed.smtRootHash) {
727
+ throw new ResolveError(
728
+ `SMT proof root hash mismatch: expected ${smtNeed.smtRootHash}, got ${proof.id}`,
729
+ INVALID_DID_UPDATE, { expected: smtNeed.smtRootHash, actual: proof.id }
730
+ );
731
+ }
732
+ this.#sidecarData.smtMap.set(smtNeed.smtRootHash, proof);
702
733
  break;
703
734
  }
704
735
  }
package/src/core/types.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { HexString } from '@did-btcr2/common';
2
- import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
3
- import { SMTProof } from './interfaces.js';
1
+ import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
2
+ import type { SMTProof } from './interfaces.js';
4
3
 
5
4
  /**
6
5
  * {@link https://dcdpr.github.io/did-btcr2/data-structures.html#cas-announcement | CAS Announcement }
@@ -58,12 +57,14 @@ export type Sidecar = {
58
57
 
59
58
  /**
60
59
  * The Sidecar data structure used for Singleton Beacons.
60
+ * Map keyed by hex-encoded canonical hash of the signed update.
61
61
  */
62
- export type SingletonBeaconSidecarData = Map<HexString, SignedBTCR2Update>;
62
+ export type SingletonBeaconSidecarData = Map<string, SignedBTCR2Update>;
63
63
  /**
64
64
  * The Sidecar data structure used for CAS Beacons.
65
+ * Map keyed by hex-encoded canonical hash of the CAS announcement.
65
66
  */
66
- export type CASBeaconSidecarData = Map<HexString, CASAnnouncement>;
67
+ export type CASBeaconSidecarData = Map<string, CASAnnouncement>;
67
68
  /**
68
69
  * The Sidecar data structure used for SMT Beacons.
69
70
  */
@@ -1,21 +1,25 @@
1
+ import type {
2
+ KeyBytes,
3
+ PatchOperation} from '@did-btcr2/common';
1
4
  import {
2
5
  canonicalHash,
3
6
  INVALID_DID_UPDATE,
4
7
  JSONPatch,
5
- KeyBytes,
6
- PatchOperation,
7
8
  UpdateError
8
9
  } from '@did-btcr2/common';
9
- import {
10
+ import type {
10
11
  DataIntegrityConfig,
11
- SchnorrMultikey,
12
12
  SignedBTCR2Update,
13
13
  UnsignedBTCR2Update
14
14
  } from '@did-btcr2/cryptosuite';
15
- import { Btcr2DidDocument, DidDocument, DidVerificationMethod } from '../utils/did-document.js';
15
+ import {
16
+ SchnorrMultikey
17
+ } from '@did-btcr2/cryptosuite';
18
+ import type { Btcr2DidDocument, DidVerificationMethod } from '../utils/did-document.js';
19
+ import { DidDocument } from '../utils/did-document.js';
16
20
  import { BeaconFactory } from './beacon/factory.js';
17
- import { BeaconService } from './beacon/interfaces.js';
18
- import { BitcoinConnection } from '@did-btcr2/bitcoin';
21
+ import type { BeaconService } from './beacon/interfaces.js';
22
+ import type { BitcoinConnection } from '@did-btcr2/bitcoin';
19
23
 
20
24
  /**
21
25
  * Implements {@link https://dcdpr.github.io/did-btcr2/operations/update.html | 7.3 Update}.
package/src/did-btcr2.ts CHANGED
@@ -1,33 +1,35 @@
1
- import { BitcoinConnection } from '@did-btcr2/bitcoin';
2
- import {
1
+ import type { BitcoinConnection } from '@did-btcr2/bitcoin';
2
+ import type {
3
3
  DocumentBytes,
4
4
  HexString,
5
+ KeyBytes,
6
+ PatchOperation} from '@did-btcr2/common';
7
+ import {
5
8
  IdentifierHrp,
6
9
  INVALID_DID_DOCUMENT,
7
10
  INVALID_DID_UPDATE,
8
- KeyBytes,
9
11
  METHOD_NOT_SUPPORTED,
10
12
  MethodError,
11
- PatchOperation,
12
13
  UpdateError
13
14
  } from '@did-btcr2/common';
14
- import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
15
+ import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
16
+ import type {
17
+ DidMethod} from '@web5/dids';
15
18
  import {
16
19
  Did,
17
20
  DidError,
18
- DidErrorCode,
19
- DidMethod,
21
+ DidErrorCode
20
22
  } from '@web5/dids';
21
23
  import * as ecc from '@bitcoinerlab/secp256k1';
22
24
  import { hexToBytes } from '@noble/hashes/utils';
23
25
  import { initEccLib } from 'bitcoinjs-lib';
24
- import { BeaconService } from './core/beacon/interfaces.js';
26
+ import type { BeaconService } from './core/beacon/interfaces.js';
25
27
  import { Identifier } from './core/identifier.js';
26
- import { ResolutionOptions } from './core/interfaces.js';
28
+ import type { ResolutionOptions } from './core/interfaces.js';
27
29
  import { Resolver } from './core/resolver.js';
28
30
  import { Update } from './core/update.js';
29
31
  import { Appendix } from './utils/appendix.js';
30
- import { Btcr2DidDocument, DidVerificationMethod } from './utils/did-document.js';
32
+ import type { Btcr2DidDocument, DidVerificationMethod } from './utils/did-document.js';
31
33
 
32
34
  export interface DidCreateOptions {
33
35
  /** Type of identifier to create (key or external) */