@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
package/src/did-btcr2.ts CHANGED
@@ -1,154 +1,229 @@
1
+ import { BitcoinNetworkConnection } from '@did-btcr2/bitcoin';
1
2
  import {
3
+ Canonicalization,
2
4
  DocumentBytes,
5
+ HexString,
6
+ IdentifierHrp,
3
7
  INVALID_DID_DOCUMENT,
8
+ INVALID_DID_UPDATE,
4
9
  KeyBytes,
5
10
  METHOD_NOT_SUPPORTED,
6
11
  MethodError,
12
+ MISSING_UPDATE_DATA,
7
13
  PatchOperation,
8
- W3C_DID_RESOLUTION_V1,
14
+ ResolveError,
15
+ UpdateError
9
16
  } from '@did-btcr2/common';
10
- import type { DidResolutionResult } from '@web5/dids';
17
+ import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
11
18
  import {
12
19
  Did,
13
20
  DidError,
14
21
  DidErrorCode,
15
22
  DidMethod,
23
+ DidResolutionResult,
16
24
  EMPTY_DID_RESOLUTION_RESULT
17
25
  } from '@web5/dids';
18
26
  import { initEccLib } from 'bitcoinjs-lib';
19
27
  import * as tinysecp from 'tiny-secp256k1';
20
- import { Resolve } from './core/crud/read.js';
21
- import { Update } from './core/crud/update.js';
22
- import { DidResolutionOptions } from './interfaces/crud.js';
23
- import { DidDocument, DidVerificationMethod } from './utils/did-document.js';
24
- import { SignalsMetadata } from './utils/types.js';
28
+ import { BeaconService } from './core/beacon/interfaces.js';
29
+ import { BeaconUtils } from './core/beacon/utils.js';
25
30
  import { Identifier } from './core/identifier.js';
31
+ import { ResolutionOptions } from './core/interfaces.js';
32
+ import { Resolve } from './core/resolve.js';
33
+ import { Update } from './core/update.js';
26
34
  import { Appendix } from './utils/appendix.js';
35
+ import { Btcr2DidDocument, DidVerificationMethod } from './utils/did-document.js';
36
+
37
+ // TODO: convert to API driver?
38
+ export const canonicalization = new Canonicalization();
27
39
 
28
40
  export type Btcr2Identifier = string;
29
41
 
30
42
  export interface DidCreateOptions {
43
+ /** Type of identifier to create (key or external) */
44
+ idType: 'KEY' | 'EXTERNAL';
31
45
  /** DID BTCR2 Version Number */
32
46
  version?: number;
33
47
  /** Bitcoin Network */
34
48
  network?: string;
35
49
  }
36
50
 
51
+ // TODO: convert to API driver?
37
52
  /** Initialize tiny secp256k1 */
38
53
  initEccLib(tinysecp);
39
54
 
40
55
  /**
41
56
  * Implements {@link https://dcdpr.github.io/did-btcr2 | did:btcr2 DID Method Specification}.
42
- * did:btcr2 is a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce
43
- * changes to the DID document. It improves on prior work by allowing: zero-cost off-chain DID creation; aggregated
44
- * updates for scalable on-chain update costs; long-term identifiers that can support frequent updates; private
45
- * communication of the DID document; private DID resolution; and non-repudiation appropriate for serious contracts.
57
+ * did:btcr2 is a censorship-resistant Decentralized Identifier (DID) method using
58
+ * the Bitcoin blockchain as a Verifiable Data Registry to announce changes to the
59
+ * DID document. It supports zero-cost off-chain DID creation; aggregated updates
60
+ * for scalable on-chain update costs; long-term identifiers that can support
61
+ * frequent updates; private communication of the DID document; private DID resolution;
62
+ * and non-repudiation.
46
63
  *
47
64
  * @class DidBtcr2
48
65
  * @type {DidBtcr2}
49
66
  * @implements {DidMethod}
50
67
  */
51
68
  export class DidBtcr2 implements DidMethod {
52
- /** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
53
- public static methodName: string = 'btcr2';
54
-
55
69
  /**
56
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#create | 4.1 Create}.
57
- * See {@link Create} for implementation details.
58
- *
59
- * A did:btcr2 identifier and associated DID document can either be created deterministically from a cryptographic
60
- * seed, or it can be created from an arbitrary genesis intermediate DID document representation. In both cases,
61
- * DID creation can be undertaken in an offline manner, i.e., the DID controller does not need to interact with the
62
- * Bitcoin network to create their DID.
63
- * @param {CreateParams} params See {@link CreateParams} for details.
64
- * @param {IdType} params.idType Type of identifier to create (key or external).
65
- * @param {KeyBytes} params.pubKeyBytes Public key byte array used to create a btcr2 "key" identifier.
66
- * @param {IntermediateDocument} params.intermediateDocument DID Document used to create a btcr2 "external" identifier.
67
- * @param {DidCreateOptions} params.options See {@link DidCreateOptions} for create options.
68
- * @param {number} params.options.version Version number of the btcr2 method.
69
- * @param {string} params.options.network Bitcoin network name (mainnet, testnet, signet, regtest).
70
- * @returns {Promise<CreateResponse>} Promise resolving to a CreateResponse object.
71
- * @throws {DidBtcr2Error} if any of the checks fail
70
+ * Name of the DID method, as defined in the DID BTCR2 specification
72
71
  */
73
- public static async create(params: {
74
- idType: 'KEY' | 'EXTERNAL';
75
- genesisBytes: KeyBytes | DocumentBytes;
76
- options?: DidCreateOptions;
77
- }): Promise<Btcr2Identifier> {
78
- // Deconstruct the idType and options from the params
79
- const { idType, options = {} } = params;
72
+ static methodName: string = 'btcr2';
80
73
 
81
- // Deconstruct the version and network from the options, setting defaults if not given
82
- const { version = 1, network = 'bitcoin' } = options;
74
+ /**
75
+ * Implements section {@link https://dcdpr.github.io/did-btcr2/operations/create.html | 7.1 Create}.
76
+ * @param {KeyBytes | DocumentBytes} genesisBytes The bytes used to create the genesis document for a did:btcr2 identifier.
77
+ * This can be either the bytes of the genesis document itself or the bytes of a key that will be used to create the genesis document.
78
+ * @param {DidCreateOptions} options Options for creating the identifier, including the idType (key or external), version, and network.
79
+ * @param {string} options.idType The type of identifier to create, either 'KEY' or 'EXTERNAL'. Defaults to 'KEY'.
80
+ * @param {number} options.version The version number of the did:btcr2 specification to use for creating the identifier. Defaults to 1.
81
+ * @param {string} options.network The Bitcoin network to use for the identifier, e.g. 'bitcoin', 'testnet', etc. Defaults to 'bitcoin'.
82
+ * @returns {Promise<Btcr2Identifier>} Promise resolving to a Btcr2Identifier string.
83
+ * @throws {MethodError} if any of the checks fail
84
+ */
85
+ static async create(
86
+ genesisBytes: KeyBytes | DocumentBytes,
87
+ options?: DidCreateOptions
88
+ ): Promise<Btcr2Identifier> {
89
+ // Deconstruct the idType, version and network from the options, setting defaults if not given
90
+ const { idType, version = 1, network = 'bitcoin' } = options || {};
83
91
 
84
- // Set the genesisBytes from the params
85
- const genesisBytes = params.genesisBytes;
92
+ if(!idType) {
93
+ throw new MethodError(
94
+ 'idType is required for creating a did:btcr2 identifier',
95
+ INVALID_DID_DOCUMENT, options
96
+ );
97
+ }
86
98
 
99
+ // Call identifier encoding algorithm
87
100
  return Identifier.encode({ idType, genesisBytes, version, network });
88
101
  }
89
102
 
90
103
  /**
91
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Read}.
92
- * See {@link Resolve} for implementation details.
104
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
105
+ * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
106
+ * See {@link Resolve | Resolve (class)} for class implementation.
93
107
  *
94
- * The Read operation is an algorithm consisting of a series of subroutine algorithms executed by a resolver after a
95
- * resolution request identifying a specific did:btcr2 identifier is received from a client at Resolution Time. The
96
- * request MUST always contain the resolutionOptions object containing additional information to be used in resolution.
97
- * This object MAY be empty. See the DID Resolution specification for further details about the DID Resolution Options
98
- * object. The resolver then attempts to resolve the DID document of the identifier at a specific Target Time. The
99
- * Target Time is either provided in resolutionOptions or is set to the Resolution Time of the request.
108
+ * Resolving a did:btcr2 identifier iteratively builds a DID document by applying
109
+ * BTCR2 Updates to an Initial DID Document that have been committed to the Bitcoin
110
+ * blockchain by Authorized Beacon Signals. The Initial DID Document is either
111
+ * deterministically created from the DID or provided by Sidecar Data.
100
112
  *
101
- * @param {string} identifier a valid did:btcr2 identifier to be resolved
102
- * @param {DidResolutionOptions} [resolutionsOptions] see {@link https://www.w3.org/TR/did-1.0/#did-resolution-options | DidResolutionOptions}
103
- * @param {number} options.versionId the version of the identifier and/or DID document
104
- * @param {number} options.versionTime a timestamp used during resolution as a bound for when to stop resolving
105
- * @param {DidDocument} options.sidecarData data necessary for resolving a DID
106
- * @param {string} options.network Bitcoin network name (mainnet, testnet, signet, regtest).
107
- * @returns {DidResolutionResult} Promise resolving to a DID Resolution Result containing the `targetDocument`
108
- * @throws {Error} if the resolution fails for any reason
109
- * @throws {DidError} InvalidDid if the identifier is invalid
113
+ * @param {string} did The did:btcr2 identifier to be resolved.
114
+ * @param {ResolutionOptions} resolutionOptions Options used during the resolution process.
115
+ * @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
116
+ * @throws {ResolveError} If the resolution process fails at any step.
110
117
  * @example
111
118
  * ```ts
112
- * const resolution = await DidBtcr2.resolve('did:btcr2:k1q0dygyp3gz969tp46dychzy4q78c2k3js68kvyr0shanzg67jnuez2cfplh')
119
+ * const resolution = await DidBtcr2.resolve(
120
+ * 'did:btcr2:k1q0dygyp3gz969tp46dychzy4q78c2k3js68kvyr0shanzg67jnuez2cfplh'
121
+ * )
113
122
  * ```
114
123
  */
115
- public static async resolve(identifier: string, resolutionsOptions: DidResolutionOptions = {}): Promise<DidResolutionResult> {
124
+ static async resolve(
125
+ did: string,
126
+ resolutionOptions: ResolutionOptions = { drivers: {} }
127
+ ): Promise<DidResolutionResult> {
116
128
  try {
117
- // 1. Pass identifier to the did:btcr2 Identifier Decoding algorithm, retrieving idType, version, network, and genesisBytes.
118
- // 2. Set identifierComponents to a map of idType, version, network, and genesisBytes.
119
- const identifierComponents = Identifier.decode(identifier);
120
-
121
- // Set the network based on the decoded identifier
122
- resolutionsOptions.network ??= identifierComponents.network;
123
-
124
- // 3. Set initialDocument to the result of running the algorithm in Resolve Initial Document passing in the
125
- // identifier, identifierComponents and resolutionOptions.
126
- const initialDocument = await Resolve.initialDocument({ identifier, identifierComponents, resolutionsOptions });
127
129
 
128
- // 4. Set targetDocument to the result of running the algorithm in Resolve Target Document passing in
129
- // initialDocument and resolutionOptions.
130
- const targetDocument = await Resolve.targetDocument({ initialDocument, resolutionsOptions });
131
-
132
- // 5. Return targetDocument.
130
+ // Initialize an empty DID Resolution Result
133
131
  const didResolutionResult: DidResolutionResult = {
134
- '@context' : W3C_DID_RESOLUTION_V1,
132
+ '@context' : 'https://w3id.org/did-resolution/v1',
135
133
  didResolutionMetadata : { contentType: 'application/ld+json' },
136
- didDocumentMetadata : { created: new Date().getUTCDateTime() },
137
- didDocument : targetDocument,
134
+ didDocumentMetadata : {
135
+ deactivated : false,
136
+ updated : undefined,
137
+ versionId : resolutionOptions.versionId,
138
+ confirmations : undefined,
139
+ },
140
+ didDocument : null,
138
141
  };
139
142
 
143
+ // Decode the did to be resolved
144
+ const didComponents = Identifier.decode(did);
145
+
146
+ // Process sidecar if provided
147
+ const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
148
+
149
+ // Check if bitcoin driver provided
150
+ if(!resolutionOptions?.drivers?.bitcoin) {
151
+ // If not, initialize default drivers
152
+ resolutionOptions.drivers = resolutionOptions.drivers || {};
153
+ // Set bitcoin driver to default BitcoinNetworkConnection
154
+ resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection();
155
+ // Set the network based on the decoded identifier
156
+ resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
157
+ }
158
+
159
+ // Parse the genesis document from the resolution options if provided
160
+ const genesisDocument = resolutionOptions.sidecar?.genesisDocument;
161
+ // Since genesisDocument is optional, check if it exists
162
+ if(!genesisDocument) {
163
+ // If no genesisDocument and x HRP, throw MISSING_UPDATE_DATA error
164
+ if(didComponents.hrp === IdentifierHrp.x)
165
+ throw new ResolveError(
166
+ 'External resolution requires genesisDocument',
167
+ MISSING_UPDATE_DATA, { resolutionOptions }
168
+ );
169
+ }
170
+
171
+ // Establish the current document
172
+ const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
173
+
174
+ // Extract all Beacon services from the current DID Document
175
+ const beaconServices = currentDocument.service
176
+ .filter(BeaconUtils.isBeaconService)
177
+ .map(BeaconUtils.parseBeaconServiceEndpoint);
178
+
179
+ console.log('beaconServices', beaconServices);
180
+
181
+ // Process the Beacon Signals to get the required updates
182
+ const unsortedUpdates = await Resolve.beaconSignals(
183
+ beaconServices,
184
+ sidecarData,
185
+ resolutionOptions.drivers.bitcoin
186
+ );
187
+ console.log('unsortedUpdates', unsortedUpdates);
188
+
189
+ // If no updates found, return the current document
190
+ if(!unsortedUpdates.length) {
191
+ // Set the current document in the didResolutionResult
192
+ didResolutionResult.didDocument = currentDocument;
193
+
194
+ // Set the deactivated status in the didDocumentMetadata
195
+ didResolutionResult.didDocumentMetadata.deactivated = !!currentDocument.deactivated;
196
+
197
+ // Return the didResolutionResult early
198
+ return didResolutionResult;
199
+ }
200
+
201
+ // Process the updates to apply updates to bring the current DID Document to its more current state
202
+ const result = await Resolve.updates(
203
+ currentDocument,
204
+ unsortedUpdates,
205
+ resolutionOptions.versionTime,
206
+ resolutionOptions.versionId
207
+ );
208
+
209
+ // Set all of the required fields in the didResolutionResult
210
+ didResolutionResult.didDocument = result.currentDocument;
211
+ didResolutionResult.didDocumentMetadata.confirmations = result.confirmations;
212
+ didResolutionResult.didDocumentMetadata.versionId = result.versionId;
213
+ didResolutionResult.didDocumentMetadata.deactivated = !!result.currentDocument.deactivated;
214
+
140
215
  // Return didResolutionResult;
141
216
  return didResolutionResult;
142
217
  } catch (error: any) {
143
218
  console.error(error);
144
- // Rethrow any unexpected errors that are not a `DidError`.
145
- if (!(error instanceof DidError)) throw new Error(error);
219
+ // Rethrow any unexpected errors that are not a `ResolveError`.
220
+ if (!(error instanceof ResolveError)) throw new Error(error);
146
221
 
147
222
  // Return a DID Resolution Result with the appropriate error code.
148
223
  return {
149
224
  ...EMPTY_DID_RESOLUTION_RESULT,
150
225
  didResolutionMetadata : {
151
- error : error.code,
226
+ error : error.type,
152
227
  ...error.message && { errorMessage: error.message }
153
228
  }
154
229
  };
@@ -156,92 +231,118 @@ export class DidBtcr2 implements DidMethod {
156
231
  }
157
232
 
158
233
  /**
159
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#update | 4.3 Update}.
160
- * See {@link Update} for implementation details.
234
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.3 Update}.
235
+ * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
236
+ * See {@link Update | Update (class)} for class implementation.
161
237
  *
162
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD data format, signed by a
163
- * verificationMethod that has the authority to make the update as specified in the previous DID document. Capability
164
- * invocations for updates MUST be authorized using Data Integrity following the bip340-jcs-2025
165
- * cryptosuite with a proofPurpose of capabilityInvocation.
166
- *
167
- * The Update algorithm takes as inputs a Identifier, sourceDocument, sourceVersionId, documentPatch, a
168
- * verificationMethodId and an array of beaconIds. The sourceDocument is the DID document being updated. The
169
- * documentPatch is a JSON Patch object containing a set of transformations to be applied to the sourceDocument.
170
- * The result of these transformations MUST produce a DID document conformant to the DID Core specification. The
171
- * verificationMethodId is an identifier for a verificationMethod within the sourceDocument. The verificationMethod
172
- * identified MUST be a BIP340 Multikey. The beaconIds MUST identify service endpoints with one of the three Beacon
173
- * Types SingletonBeacon, CIDAggregateBeacon, and SMTAggregateBeacon.
174
- *
175
- * @param {UpdateParams} params Required parameters for the update operation.
176
- * @param {string} params.identifier The btcr2 identifier to be updated.
177
- * @param {DidDocument} params.sourceDocument The DID document being updated.
178
- * @param {string} params.sourceVersionId The versionId of the source document.
179
- * @param {PatchOperation} params.documentPatch The JSON patch to be applied to the source document.
180
- * @param {string} params.verificationMethodId The verificationMethod ID to sign the update
181
- * @param {string[]} params.beaconIds The beacon IDs to announce the update
182
- * @returns {Promise<void>} Promise resolving to void
183
- * @throws {MethodError} if the verificationMethod type is not `Multikey` or the publicKeyMultibase header is not `zQ3s`
238
+ * BTCR2 DID documents can be updated by anchoring BTCR2 Updates to Bitcoin transactions. These transactions MAY be
239
+ * published to the Bitcoin network. Any property in the DID document may be updated except the id. Doing so would
240
+ * invalidate the DID document.
241
+ * @param params An object containing the parameters for the update operation.
242
+ * @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
243
+ * @param {PatchOperation[]} params.patches The array of JSON Patch operations to apply to the sourceDocument.
244
+ * @param {string} params.sourceVersionId The version ID before applying the update.
245
+ * @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
246
+ * @param {string} params.beaconId The beacon ID associated with the update.
247
+ * @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
248
+ * @param {BitcoinNetworkConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
249
+ * @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
250
+ * @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
251
+ * header is not `zQ3s`
184
252
  */
185
- public static async update(params: {
186
- identifier: string;
187
- sourceDocument: DidDocument;
253
+ static async update({
254
+ sourceDocument,
255
+ patches,
256
+ sourceVersionId,
257
+ verificationMethodId,
258
+ beaconId,
259
+ signingMaterial,
260
+ bitcoin,
261
+ }: {
262
+ sourceDocument: Btcr2DidDocument;
263
+ patches: PatchOperation[];
188
264
  sourceVersionId: number;
189
- patch: PatchOperation[];
190
265
  verificationMethodId: string;
191
- beaconIds: string[];
192
- }): Promise<SignalsMetadata> {
193
- // Deconstruct the params
194
- const {
195
- identifier,
196
- sourceDocument,
197
- sourceVersionId,
198
- patch,
199
- verificationMethodId: methodId,
200
- beaconIds,
201
- } = params;
202
-
203
- // 1. Set unsignedUpdate to the result of passing Identifier, sourceDocument,
204
- // sourceVersionId, and documentPatch into the Construct DID Update
205
- // Payload algorithm.
206
- const didUpdatePayload = await Update.construct({
207
- identifier,
208
- sourceDocument,
209
- sourceVersionId,
210
- patch,
211
- });
212
-
213
- // 2. Set verificationMethod to the result of retrieving the verificationMethod
214
- // from sourceDocument using the verificationMethodId.
215
- const verificationMethod = this.getSigningMethod({ didDocument: sourceDocument, methodId, });
266
+ beaconId: string;
267
+ signingMaterial?: KeyBytes | HexString;
268
+ bitcoin?: BitcoinNetworkConnection;
269
+ }): Promise<SignedBTCR2Update> {
270
+ // TODO: provide KMS as alternative
271
+ // If no signingMaterial provided, throw an UpdateError with INVALID_DID_UPDATE.
272
+ if (!signingMaterial) {
273
+ throw new UpdateError(
274
+ 'Missing signing material for update',
275
+ INVALID_DID_UPDATE, {signingMaterial}
276
+ );
277
+ }
278
+
279
+ // Convert signingMaterial to bytes if it's a hex string
280
+ const secretKey = typeof signingMaterial === 'string'
281
+ ? Buffer.from(signingMaterial, 'hex')
282
+ : signingMaterial;
283
+
284
+ // Validate that the verificationMethodId is authorized for capabilityInvocation
285
+ if(!sourceDocument.capabilityInvocation?.some(vr => vr === verificationMethodId)) {
286
+ throw new UpdateError(
287
+ 'Invalid verificationMethodId: not authorized for capabilityInvocation',
288
+ INVALID_DID_DOCUMENT, sourceDocument
289
+ );
290
+ }
291
+
292
+ // Get the verification method to be used for signing the update
293
+ const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
216
294
 
217
295
  // Validate the verificationMethod exists in the sourceDocument
218
296
  if (!verificationMethod) {
219
- throw new MethodError('Verification method not found in did document', INVALID_DID_DOCUMENT, sourceDocument);
297
+ throw new UpdateError(
298
+ 'Invalid verificationMethod: not found in source document',
299
+ INVALID_DID_DOCUMENT, {sourceDocument, verificationMethodId}
300
+ );
220
301
  }
221
302
 
222
- // 3. Validate the verificationMethod is a BIP340 Multikey:
223
- // 3.1 verificationMethod.type == Multikey
303
+ // Validate the verificationMethod is of type 'Multikey'
224
304
  if (verificationMethod.type !== 'Multikey') {
225
- throw new MethodError('Invalid type: must be type "Multikey"', INVALID_DID_DOCUMENT, verificationMethod);
305
+ throw new UpdateError(
306
+ 'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
307
+ INVALID_DID_DOCUMENT, verificationMethod
308
+ );
226
309
  }
227
310
 
228
- // 3.2 verificationMethod.publicKeyMultibase[4] == zQ3s
229
- const mbasePrefix = verificationMethod.publicKeyMultibase?.slice(0, 4);
230
- if (mbasePrefix !== 'zQ3s') {
231
- throw new MethodError(`Invalid publicKeyMultibase prefix ${mbasePrefix}`, INVALID_DID_DOCUMENT, verificationMethod);
311
+ // Validate the publicKeyMultibase prefix is 'zQ3s'
312
+ if (verificationMethod.publicKeyMultibase?.slice(0, 4) !== 'zQ3s') {
313
+ throw new UpdateError(
314
+ 'Invalid verificationMethodId: publicKeyMultibase prefix must start with "zQ3s"',
315
+ INVALID_DID_DOCUMENT, verificationMethod
316
+ );
232
317
  }
233
318
 
234
- // 4. Set didUpdateInvocation to the result of passing Identifier, unsignedUpdate as didUpdatePayload, and
235
- // verificationMethod to the Invoke DID Update Payload algorithm.
236
- const didUpdateInvocation = await Update.invoke({ identifier, verificationMethod, didUpdatePayload, });
319
+ // Construct an unsigned update following the BTCR2 Update construction algorithm
320
+ const update = await Update.construct(sourceDocument, patches, sourceVersionId);
321
+
322
+ // Sign the unsigned update using the specified verification method
323
+ const signed = await Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
237
324
 
238
- // 5. Set signalsMetadata to the result of passing Identifier, sourceDocument, beaconIds and didUpdateInvocation
239
- // to the Announce DID Update algorithm.
240
- const signalsMetadata = await Update.announce({ sourceDocument, beaconIds, didUpdateInvocation, });
325
+ // Filter sourceDocument services to get beaconServices matching beaconIds
326
+ const beaconService = sourceDocument.service
327
+ .filter((service: BeaconService) => service.id === beaconId)
328
+ .filter((service: BeaconService): service is BeaconService => !!service)
329
+ .shift();
241
330
 
242
- // 6. Return signalsMetadata. It is up to implementations to ensure that the signalsMetadata is persisted.
243
- return signalsMetadata;
244
- // TODO: Should we be applying the patch, producing a target did document and returning it?
331
+ // If no matching beacon service found, throw an UpdateError with INVALID_DID_UPDATE.
332
+ if(!beaconService) {
333
+ throw new UpdateError(
334
+ 'No beacon service found for provided beaconId',
335
+ INVALID_DID_UPDATE, {sourceDocument, beaconId}
336
+ );
337
+ }
338
+ // If no bitcoin network connection provided, initialize default
339
+ bitcoin ??= new BitcoinNetworkConnection();
340
+
341
+ // Announce the signed update to the blockchain using the specified beacon(s)
342
+ // await Update.announce(beaconService, signed, secretKey, bitcoin);
343
+
344
+ // Return signed update if announced successfully
345
+ return signed;
245
346
  }
246
347
 
247
348
  /**
@@ -249,17 +350,12 @@ export class DidBtcr2 implements DidMethod {
249
350
  * for signing messages and credentials. If given, the `methodId` parameter is used to select the
250
351
  * verification method. If not given, the Identity Key's verification method with an ID fragment
251
352
  * of '#initialKey' is used.
252
- *
253
- * @param {{ didDocument: DidDocument; methodId?: string; }} params Parameters for the `getSigningMethod` method.
254
- * @param {DidDocument} params.didDocument DID Document to get the verification method from.
255
- * @param {string} params.methodId Optional ID of the verification method to use for signing.
353
+ * @param {Btcr2DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
354
+ * @param {string} [methodId] Optional verification method ID to be used for signing.
256
355
  * @returns {DidVerificationMethod} Promise resolving to the {@link DidVerificationMethod} object used for signing.
257
356
  * @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
258
357
  */
259
- public static getSigningMethod({ didDocument, methodId }: {
260
- didDocument: DidDocument;
261
- methodId?: string;
262
- }): DidVerificationMethod {
358
+ static getSigningMethod(didDocument: Btcr2DidDocument, methodId?: string): DidVerificationMethod {
263
359
  // Set the default methodId to the first assertionMethod if not given
264
360
  methodId ??= '#initialKey';
265
361
 
package/src/index.ts CHANGED
@@ -1,54 +1,51 @@
1
+ export * from './core/beacon/aggregation/cohort/index.js';
2
+ export * from './core/beacon/aggregation/cohort/status.js';
3
+
4
+ export * from './core/beacon/aggregation/cohort/messages/base.js';
5
+ export * from './core/beacon/aggregation/cohort/messages/constants.js';
6
+ export * from './core/beacon/aggregation/cohort/messages/index.js';
7
+ export * from './core/beacon/aggregation/cohort/messages/keygen//subscribe.js';
1
8
  export * from './core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js';
2
9
  export * from './core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js';
3
10
  export * from './core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js';
4
11
  export * from './core/beacon/aggregation/cohort/messages/keygen/opt-in.js';
5
- export * from './core/beacon/aggregation/cohort/messages/keygen//subscribe.js';
6
-
7
12
  export * from './core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js';
8
13
  export * from './core/beacon/aggregation/cohort/messages/sign/authorization-request.js';
9
14
  export * from './core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js';
10
15
  export * from './core/beacon/aggregation/cohort/messages/sign/request-signature.js';
11
16
  export * from './core/beacon/aggregation/cohort/messages/sign/signature-authorization.js';
12
17
 
13
- export * from './core/beacon/aggregation/cohort/messages/base.js';
14
- export * from './core/beacon/aggregation/cohort/messages/constants.js';
15
- export * from './core/beacon/aggregation/cohort/messages/index.js';
16
-
17
- export * from './core/beacon/aggregation/cohort/index.js';
18
- export * from './core/beacon/aggregation/cohort/status.js';
19
-
20
18
  export * from './core/beacon/aggregation/communication/adapter/did-comm.js';
21
19
  export * from './core/beacon/aggregation/communication/adapter/nostr.js';
20
+
22
21
  export * from './core/beacon/aggregation/communication/error.js';
23
22
  export * from './core/beacon/aggregation/communication/factory.js';
24
23
  export * from './core/beacon/aggregation/communication/service.js';
25
24
 
26
- export * from './core/beacon/aggregation/session/index.js';
27
- export * from './core/beacon/aggregation/session/status.js';
28
-
29
25
  export * from './core/beacon/aggregation/coordinator.js';
30
26
  export * from './core/beacon/aggregation/participant.js';
27
+ export * from './core/beacon/aggregation/session/index.js';
28
+ export * from './core/beacon/aggregation/session/status.js';
31
29
 
32
- export * from './core/beacon/cid-aggregate.js';
30
+ export * from './core/beacon/beacon.js';
31
+ export * from './core/beacon/cas-beacon.js';
33
32
  export * from './core/beacon/error.js';
34
33
  export * from './core/beacon/factory.js';
34
+ export * from './core/beacon/interfaces.js';
35
+ export * from './core/beacon/signal-discovery.js';
35
36
  export * from './core/beacon/singleton.js';
36
- export * from './core/beacon/smt-aggregate.js';
37
+ export * from './core/beacon/smt-beacon.js';
37
38
  export * from './core/beacon/utils.js';
38
39
 
39
- export * from './core/crud/deactivate.js';
40
- export * from './core/crud/read.js';
41
- export * from './core/crud/update.js';
42
-
43
40
  export * from './core/identifier.js';
44
-
45
- export * from './interfaces/beacon.js';
46
- export * from './interfaces/crud.js';
41
+ export * from './core/interfaces.js';
42
+ export * from './core/resolve.js';
43
+ export * from './core/types.js';
44
+ export * from './core/update.js';
47
45
 
48
46
  export * from './utils/appendix.js';
49
47
  export * from './utils/did-document-builder.js';
50
48
  export * from './utils/did-document.js';
51
49
  export * from './utils/general.js';
52
- export * from './utils/types.js';
53
50
 
54
51
  export * from './did-btcr2.js';