@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
@@ -1,4 +1,4 @@
1
- import { HashBytes, W3C_ZCAP_V1 } from '@did-btcr2/common';
1
+ import { HashBytes } from '@did-btcr2/common';
2
2
  import { strings } from '@helia/strings';
3
3
  import {
4
4
  DidDocument,
@@ -11,7 +11,7 @@ import {
11
11
  import { createHelia } from 'helia';
12
12
  import { CID } from 'multiformats';
13
13
  import { create as createDigest } from 'multiformats/hashes/digest';
14
- import { RootCapability } from '../interfaces/crud.js';
14
+ import { RootCapability } from '../core/interfaces.js';
15
15
 
16
16
  /**
17
17
  * Implements {@link https://dcdpr.github.io/did-btcr2/#appendix | 9. Appendix} methods.
@@ -109,27 +109,13 @@ export class Appendix {
109
109
  * }
110
110
  * ```
111
111
  */
112
- public static deriveRootCapability(identifier: string): RootCapability {
113
- // 1. Define rootCapability as an empty object.
114
- const rootCapability = {} as RootCapability;
115
-
116
- // 2. Set rootCapability.@context to ‘https://w3id.org/zcap/v1’.
117
- rootCapability['@context'] = W3C_ZCAP_V1;
118
-
119
- // 3. Set encodedIdentifier to result of calling algorithm encodeURIComponent(identifier).
120
- const encodedIdentifier = encodeURIComponent(identifier);
121
-
122
- // 4. Set rootCapability.id to urn:zcap:root:${encodedIdentifier}.
123
- rootCapability.id = `urn:zcap:root:${encodedIdentifier}`;
124
-
125
- // 5. Set rootCapability.controller to identifier.
126
- rootCapability.controller = identifier;
127
-
128
- // 6. Set rootCapability.invocationTarget to identifier.
129
- rootCapability.invocationTarget = identifier;
130
-
131
- // 7. Return rootCapability.
132
- return rootCapability;
112
+ static deriveRootCapability(identifier: string): RootCapability {
113
+ return {
114
+ '@context' : 'https://w3id.org/zcap/v1',
115
+ id : `urn:zcap:root:${encodeURIComponent(identifier)}`,
116
+ controller : identifier,
117
+ invocationTarget : identifier,
118
+ };
133
119
  }
134
120
 
135
121
 
@@ -173,7 +159,7 @@ export class Appendix {
173
159
  * }
174
160
  * }
175
161
  */
176
- public static derefernceRootCapabilityIdentifier(capabilityId: string): RootCapability {
162
+ public static dereferenceZcapId(capabilityId: string): RootCapability {
177
163
  // 1. Set rootCapability to an empty object.
178
164
  const rootCapability = {} as RootCapability;
179
165
 
@@ -221,28 +207,24 @@ export class Appendix {
221
207
  }
222
208
 
223
209
  /**
224
- * Implements {@link https://dcdpr.github.io/did-btcr2/#fetch-content-from-addressable-storage | 9.3. Fetch Content from Addressable Storage}.
225
- *
226
- * The Fetch Content from Addressable Storage function takes in SHA256 hash of some content, hashBytes, converts these
227
- * bytes to a IPFS v1 Content Identifier and attempts to retrieve the identified content from Content Addressable
228
- * Storage (CAS). It returns the retrieved content or null.
229
- *
230
- * @param {HashBytes} hashBytes The SHA256 hash of the content to be fetched.
231
- * @returns {string} The fetched content or null if not found.
210
+ * Implements CAS Lookup Step from {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-beacon-signals | 7.2.e Process Beacon Signals }.
211
+ * @param {HashBytes} hashBytes The hash bytes to look up in the CAS system.
212
+ * @returns {Promise<string | undefined>} The content fetched from the CAS system, or undefined if not found.
232
213
  */
233
- public static async fetchFromCas(hashBytes: HashBytes): Promise<string | undefined> {
234
- // 1. Set cid to the result of converting hashBytes to an IPFS v1 CID.
214
+ static async fetchFromCas(hashBytes: HashBytes): Promise<string | undefined> {
215
+ // Construct CID from hash bytes
235
216
  const cid = CID.create(1, 1, createDigest(1, hashBytes));
236
217
 
237
- // Create a Helia node connection to IPFS
238
- const helia = strings(await createHelia());
218
+ // Connect to IPFS/Helia node
219
+ const helia = await createHelia();
220
+ const node = strings(helia);
239
221
 
240
- // 2. Set content to the result of fetching the cid from a CAS system. Which CAS systems checked is up to implementation.
241
- // TODO: Is this right? Are implementations just supposed to check all CAS they trust?'
242
- const content = await helia.get(cid, {});
243
-
244
- // 3. If content for cid cannot be found, set content to null.
245
- // 4. Return content.
246
- return content;
222
+ // Return the IPFS get result
223
+ return await node.get(cid, {});
247
224
  }
248
- }
225
+ }
226
+
227
+
228
+
229
+
230
+
@@ -1,7 +1,12 @@
1
1
  import { DidDocumentError, INVALID_DID_DOCUMENT } from '@did-btcr2/common';
2
- import { BeaconService } from '../interfaces/beacon.js';
2
+ import { BeaconService } from '../core/beacon/interfaces.js';
3
3
  import { DidDocument, DidVerificationMethod } from './did-document.js';
4
4
 
5
+ /**
6
+ * A builder class for constructing DID Documents.
7
+ * @type {DidDocumentBuilder}
8
+ * @class DidDocumentBuilder
9
+ */
5
10
  export class DidDocumentBuilder {
6
11
  private document: Partial<DidDocument> = {};
7
12
 
@@ -2,19 +2,21 @@ import { getNetwork } from '@did-btcr2/bitcoin';
2
2
  import {
3
3
  BTCR2_DID_DOCUMENT_CONTEXT,
4
4
  DidDocumentError,
5
- ID_PLACEHOLDER_VALUE,
6
5
  IdentifierTypes,
7
6
  INVALID_DID_DOCUMENT,
8
7
  JSONObject,
9
- KeyBytes,
8
+ JSONUtils,
9
+ KeyBytes
10
10
  } from '@did-btcr2/common';
11
11
  import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
12
- import { DidService, DidDocument as IIDidDocument, DidVerificationMethod as IIDidVerificationMethod } from '@web5/dids';
13
- import { BeaconService } from '../interfaces/beacon.js';
12
+ import { DidDocument as W3CDidDocument, DidVerificationMethod as W3CDidVerificationMethod } from '@web5/dids';
13
+ import { BeaconService } from '../core/beacon/interfaces.js';
14
14
  import { BeaconUtils } from '../core/beacon/utils.js';
15
15
  import { Identifier } from '../core/identifier.js';
16
16
  import { Appendix } from './appendix.js';
17
+ import { payments } from 'bitcoinjs-lib';
17
18
 
19
+ export const ID_PLACEHOLDER_VALUE = 'did:btcr2:_';
18
20
  export const BECH32M_CHARS = '';
19
21
  export const DID_REGEX = /did:btcr2:(x1[qpzry9x8gf2tvdw0s3jn54khce6mua7l]*)/g;
20
22
 
@@ -34,7 +36,10 @@ export type VerificationRelationships = {
34
36
  capabilityDelegation?: Array<string | DidVerificationMethod>;
35
37
  }
36
38
 
37
- export interface IDidVerificationMethod extends IIDidVerificationMethod {
39
+ /** Loose type for unvalidated DID document-like input objects. */
40
+ export type DidDocumentLike = Partial<Btcr2DidDocument>;
41
+
42
+ export interface Btcr2VerificationMethod extends W3CDidVerificationMethod {
38
43
  id: string;
39
44
  type: string;
40
45
  controller: string;
@@ -48,14 +53,14 @@ export interface IDidVerificationMethod extends IIDidVerificationMethod {
48
53
  * @type {DidVerificationMethod}
49
54
  *
50
55
  */
51
- export class DidVerificationMethod implements IDidVerificationMethod {
56
+ export class DidVerificationMethod implements Btcr2VerificationMethod {
52
57
  id: string;
53
58
  type: string;
54
59
  controller: string;
55
60
  publicKeyMultibase: string;
56
61
  secretKeyMultibase?: string | undefined;
57
62
 
58
- constructor({ id, type, controller, publicKeyMultibase, secretKeyMultibase }: IDidVerificationMethod) {
63
+ constructor({ id, type, controller, publicKeyMultibase, secretKeyMultibase }: Btcr2VerificationMethod) {
59
64
  this.id = id;
60
65
  this.type = type;
61
66
  this.controller = controller;
@@ -70,9 +75,9 @@ export class DidVerificationMethod implements IDidVerificationMethod {
70
75
 
71
76
  /**
72
77
  * BTCR2 DID Document Interface
73
- * @interface IDidDocument
74
- * @type {IDidDocument}
75
- * @extends {IIDidDocument}
78
+ * @interface Btcr2DidDocument
79
+ * @type {Btcr2DidDocument}
80
+ * @extends {W3CDidDocument}
76
81
  * @property {string} id - The identifier of the DID Document.
77
82
  * @property {Array<string>} [controller] - The controller of the DID Document.
78
83
  * @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
@@ -83,7 +88,7 @@ export class DidVerificationMethod implements IDidVerificationMethod {
83
88
  * @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
84
89
  * @property {Array<BeaconService>} service - The services of the DID Document.
85
90
  */
86
- export interface IDidDocument extends IIDidDocument {
91
+ export interface Btcr2DidDocument extends W3CDidDocument {
87
92
  id: string;
88
93
  controller?: Array<string>;
89
94
  '@context'?: Array<string | JSONObject>;
@@ -99,7 +104,7 @@ export interface IDidDocument extends IIDidDocument {
99
104
  * BTCR2 DID Document extends the DidDocument class adding helper methods and properties
100
105
  * @class DidDocument
101
106
  * @type {DidDocument}
102
- * @implements {IDidDocument}
107
+ * @implements {Btcr2DidDocument}
103
108
  * @property {string} id - The identifier of the DID Document.
104
109
  * @property {Array<string>} [controller] - The controller of the DID Document.
105
110
  * @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
@@ -110,7 +115,7 @@ export interface IDidDocument extends IIDidDocument {
110
115
  * @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
111
116
  * @property {Array<BeaconService>} service - The services of the DID Document.
112
117
  */
113
- export class DidDocument implements IDidDocument {
118
+ export class DidDocument implements Btcr2DidDocument {
114
119
  id: string;
115
120
  controller?: Array<string>;
116
121
  '@context'?: Array<string | JSONObject> = BTCR2_DID_DOCUMENT_CONTEXT;
@@ -120,18 +125,22 @@ export class DidDocument implements IDidDocument {
120
125
  capabilityInvocation?: Array<string | DidVerificationMethod>;
121
126
  capabilityDelegation?: Array<string | DidVerificationMethod>;
122
127
  service: Array<BeaconService>;
128
+ deactivated?: boolean;
123
129
 
124
- constructor(document: IDidDocument) {
130
+ constructor(document: Btcr2DidDocument) {
125
131
  // Set the ID and ID type
126
- const idType = document.id.includes('k1')
132
+ const idType = document.id.includes('k')
127
133
  ? IdentifierTypes.KEY
128
134
  : IdentifierTypes.EXTERNAL;
129
135
 
130
136
  // Validate ID and parts for non-intermediate
131
- const isIntermediate = document.id === ID_PLACEHOLDER_VALUE;
137
+ const isGenesis = document.id === ID_PLACEHOLDER_VALUE;
138
+
132
139
  // Deconstruct the document parts for validation
133
140
  const { id, controller, verificationMethod: vm, service } = document;
134
- if (!isIntermediate) {
141
+
142
+ // If not genesis, validate core properties
143
+ if (!isGenesis) {
135
144
  if (!DidDocument.isValidId(id)) {
136
145
  throw new DidDocumentError(`Invalid id: ${id}`, INVALID_DID_DOCUMENT, document);
137
146
  }
@@ -172,29 +181,19 @@ export class DidDocument implements IDidDocument {
172
181
  // Sanitize the DID Document
173
182
  DidDocument.sanitize(this);
174
183
  // If the DID Document is not an intermediateDocument, validate it
175
- if (!isIntermediate) {
184
+ if (!isGenesis) {
176
185
  DidDocument.validate(this);
177
186
  } else {
178
- this.validateIntermediate();
187
+ this.validateGenesis();
179
188
  }
180
189
  }
181
190
 
182
191
  /**
183
192
  * Convert the DidDocument to a JSON object.
184
- * @returns {JSONObject} The JSON representation of the DidDocument.
193
+ * @returns {DidDocument} The JSON representation of the DidDocument.
185
194
  */
186
- public json(): JSONObject {
187
- return {
188
- id : this.id,
189
- controller : this.controller,
190
- '@context' : this['@context'],
191
- verificationMethod : this.verificationMethod,
192
- authentication : this.authentication,
193
- assertionMethod : this.assertionMethod,
194
- capabilityInvocation : this.capabilityInvocation,
195
- capabilityDelegation : this.capabilityDelegation,
196
- service : this.service
197
- };
195
+ public json(): DidDocument {
196
+ return Object.fromEntries(Object.entries(this)) as DidDocument;
198
197
  }
199
198
 
200
199
  /**
@@ -222,7 +221,7 @@ export class DidDocument implements IDidDocument {
222
221
  })
223
222
  ],
224
223
  service
225
- } as IDidDocument;
224
+ } as Btcr2DidDocument;
226
225
  return new DidDocument(document);
227
226
  }
228
227
 
@@ -232,7 +231,7 @@ export class DidDocument implements IDidDocument {
232
231
  * @returns {DidDocument} A new DidDocument.
233
232
  */
234
233
  public static fromExternalIdentifier(data: ExternalData): DidDocument {
235
- return new DidDocument(data as IDidDocument);
234
+ return new DidDocument(data as Btcr2DidDocument);
236
235
  }
237
236
 
238
237
 
@@ -255,7 +254,7 @@ export class DidDocument implements IDidDocument {
255
254
  * @returns {boolean} True if the DID document is valid.
256
255
  * @throws {DidDocumentError} If any validation check fails.
257
256
  */
258
- public static isValid(didDocument: DidDocument): boolean {
257
+ public static isValid(didDocument: DidDocumentLike): boolean {
259
258
  if (!this.isValidContext(didDocument?.['@context'])) {
260
259
  throw new DidDocumentError('Invalid "@context"', INVALID_DID_DOCUMENT, didDocument);
261
260
  }
@@ -280,7 +279,7 @@ export class DidDocument implements IDidDocument {
280
279
  * @param {DidDocument['@context']} context The context to validate.
281
280
  * @returns {boolean} True if the context is valid.
282
281
  */
283
- private static isValidContext(context: DidDocument['@context']): boolean {
282
+ private static isValidContext(context: unknown): boolean {
284
283
  if(!context) return false;
285
284
  if(!Array.isArray(context)) return false;
286
285
  if(!context.every(ctx => typeof ctx === 'string' && BTCR2_DID_DOCUMENT_CONTEXT.includes(ctx))) return false;
@@ -293,7 +292,8 @@ export class DidDocument implements IDidDocument {
293
292
  * @param {string} id The id to validate.
294
293
  * @returns {boolean} True if the id is valid.
295
294
  */
296
- private static isValidId(id: string): boolean {
295
+ private static isValidId(id: unknown): boolean {
296
+ if (typeof id !== 'string') return false;
297
297
  try {
298
298
  Identifier.decode(id);
299
299
  return true;
@@ -320,7 +320,7 @@ export class DidDocument implements IDidDocument {
320
320
  * @param {DidVerificationMethod[]} verificationMethod The verification methods to validate.
321
321
  * @returns {boolean} True if the verification methods are valid.
322
322
  */
323
- private static isValidVerificationMethods(verificationMethod: IIDidVerificationMethod[]): boolean {
323
+ private static isValidVerificationMethods(verificationMethod: unknown): boolean {
324
324
  return Array.isArray(verificationMethod) && verificationMethod.every(Appendix.isDidVerificationMethod);
325
325
  }
326
326
 
@@ -330,7 +330,7 @@ export class DidDocument implements IDidDocument {
330
330
  * @param {DidService[]} service The services to validate.
331
331
  * @returns {boolean} True if the services are valid.
332
332
  */
333
- private static isValidServices(service: DidService[]): boolean {
333
+ private static isValidServices(service: unknown): boolean {
334
334
  return Array.isArray(service) && service.every(BeaconUtils.isBeaconService);
335
335
  }
336
336
 
@@ -340,33 +340,25 @@ export class DidDocument implements IDidDocument {
340
340
  * @param {DidDocument} didDocument The DID Document to validate.
341
341
  * @returns {boolean} True if the verification relationships are valid.
342
342
  */
343
- public static isValidVerificationRelationships(didDocument: DidDocument): boolean {
344
- // Define the available verification relationships
345
- const possibleVerificationRelationships: (keyof DidDocument)[] = [
343
+ public static isValidVerificationRelationships(didDocument: DidDocumentLike): boolean {
344
+ const possibleVerificationRelationships = [
346
345
  'authentication',
347
346
  'assertionMethod',
348
347
  'capabilityInvocation',
349
348
  'capabilityDelegation'
350
- ];
351
-
352
- // Get the DID Document keys
353
- const verificationRelationships = Object.keys(didDocument) as Array<keyof DidDocument>;
354
-
355
- // Filter the DID Document keys to only those that are in the available verification relationships
356
- const availableVerificationRelationships = possibleVerificationRelationships.filter(
357
- key => verificationRelationships.includes(key as keyof DidDocument)
358
- ) as (keyof DidDocument)[];
359
-
360
- // Check if all available verification relationships are valid
361
- return availableVerificationRelationships.every((key) =>
362
- // Check if the key exists in the DID Document
363
- didDocument[key] &&
364
- // Check if the key is an array
365
- Array.isArray(didDocument[key]) &&
366
- // Check that every value in the array is a string or DidVerificationMethod
367
- didDocument[key].every(
368
- entry => typeof entry === 'string' || Appendix.isDidVerificationMethod(entry)
369
- ));
349
+ ] as const;
350
+
351
+ const keys = Object.keys(didDocument);
352
+ const availableKeys = possibleVerificationRelationships.filter(key => keys.includes(key));
353
+
354
+ return availableKeys.every((key) => {
355
+ const value = didDocument[key];
356
+ return value &&
357
+ Array.isArray(value) &&
358
+ value.every(
359
+ (entry) => typeof entry === 'string' || Appendix.isDidVerificationMethod(entry)
360
+ );
361
+ });
370
362
  }
371
363
 
372
364
  /**
@@ -374,10 +366,10 @@ export class DidDocument implements IDidDocument {
374
366
  * @returns {DidDocument} Validated DID Document.
375
367
  * @throws {DidDocumentError} If the DID Document is invalid.
376
368
  */
377
- public static validate(didDocument: DidDocument | IntermediateDidDocument): DidDocument {
369
+ public static validate(didDocument: any): DidDocument {
378
370
  // Validate the DID Document
379
371
  if (didDocument.id === ID_PLACEHOLDER_VALUE) {
380
- (didDocument as IntermediateDidDocument).validateIntermediate();
372
+ (didDocument as GenesisDocument).validateGenesis();
381
373
  } else {
382
374
  DidDocument.isValid(didDocument);
383
375
  }
@@ -386,111 +378,117 @@ export class DidDocument implements IDidDocument {
386
378
  }
387
379
 
388
380
  /**
389
- * Validate the IntermediateDidDocument.
390
- * @returns {boolean} True if the IntermediateDidDocument is valid.
381
+ * Validate the GenesisDocument.
382
+ * @returns {boolean} True if the GenesisDocument is valid.
391
383
  */
392
- public validateIntermediate(): boolean {
384
+ public validateGenesis(): boolean {
393
385
  // Validate the id
394
386
  if(this.id !== ID_PLACEHOLDER_VALUE) {
395
- throw new DidDocumentError('Invalid IntermediateDidDocument ID', INVALID_DID_DOCUMENT, this);
387
+ throw new DidDocumentError('Invalid GenesisDocument ID', INVALID_DID_DOCUMENT, this);
396
388
  }
397
389
  // Validate the controller
398
390
  if(!this.controller?.every(c => c === ID_PLACEHOLDER_VALUE)) {
399
- throw new DidDocumentError('Invalid IntermediateDidDocument controller', INVALID_DID_DOCUMENT, this);
391
+ throw new DidDocumentError('Invalid GenesisDocument controller', INVALID_DID_DOCUMENT, this);
400
392
  }
401
393
  // Validate the verificationMethod
402
394
  if(!this.verificationMethod.every(vm => vm.id.includes(ID_PLACEHOLDER_VALUE) && vm.controller === ID_PLACEHOLDER_VALUE)) {
403
- throw new DidDocumentError('Invalid IntermediateDidDocument verificationMethod', INVALID_DID_DOCUMENT, this);
395
+ throw new DidDocumentError('Invalid GenesisDocument verificationMethod', INVALID_DID_DOCUMENT, this);
404
396
  }
405
397
  // Validate the service
406
398
  if(!this.service.every(svc => svc.id.includes(ID_PLACEHOLDER_VALUE))) {
407
- throw new DidDocumentError('Invalid IntermediateDidDocument service', INVALID_DID_DOCUMENT, this);
399
+ throw new DidDocumentError('Invalid GenesisDocument service', INVALID_DID_DOCUMENT, this);
408
400
  }
409
401
  if(!DidDocument.isValidVerificationRelationships(this)) {
410
402
  // Return true if all validations pass
411
- throw new DidDocumentError('Invalid IntermediateDidDocument assertionMethod', INVALID_DID_DOCUMENT, this);
403
+ throw new DidDocumentError('Invalid GenesisDocument assertionMethod', INVALID_DID_DOCUMENT, this);
412
404
  }
413
405
 
414
406
  return true;
415
407
  }
416
408
 
417
409
  /**
418
- * Convert the DidDocument to an IntermediateDidDocument.
419
- * @returns {IntermediateDidDocument} The IntermediateDidDocument representation of the DidDocument.
410
+ * Convert the DidDocument to an GenesisDocument.
411
+ * @returns {GenesisDocument} The GenesisDocument representation of the DidDocument.
420
412
  */
421
- public toIntermediate(): IntermediateDidDocument {
413
+ public toIntermediate(): GenesisDocument {
422
414
  if(this.id.includes('k1')) {
423
415
  throw new DidDocumentError('Cannot convert a key identifier to an intermediate document', INVALID_DID_DOCUMENT, this);
424
416
  }
425
- return new IntermediateDidDocument(this);
417
+ return new GenesisDocument(this);
418
+ }
419
+ }
420
+
421
+ export class Document {
422
+ public static isValid(didDocument: DidDocument | GenesisDocument): boolean {
423
+ return new DidDocument(didDocument).validateGenesis();
426
424
  }
427
425
  }
428
426
 
427
+
429
428
  /**
430
- * IntermediateDidDocument extends the DidDocument class for creating and managing intermediate DID documents.
429
+ * GenesisDocument extends the DidDocument class for creating and managing intermediate DID documents.
431
430
  * This class is used to create a minimal DID document with a placeholder ID.
432
431
  * It is used in the process of creating a new DID document.
433
- * @class IntermediateDidDocument
432
+ * @class GenesisDocument
434
433
  * @extends {DidDocument}
435
434
  */
436
- export class IntermediateDidDocument extends DidDocument {
437
- constructor(document: JSONObject) {
438
- super(document as IDidDocument);
435
+ export class GenesisDocument extends DidDocument {
436
+ constructor(document: object | DidDocument) {
437
+ super(document as DidDocument);
439
438
  }
440
439
 
441
440
  /**
442
- * Convert the IntermediateDidDocument to a DidDocument by replacing the placeholder value with the provided DID.
441
+ * Convert the GenesisDocument to a DidDocument by replacing the placeholder value with the provided DID.
443
442
  * @param did The DID to replace the placeholder value in the document.
444
443
  * @returns {DidDocument} A new DidDocument with the placeholder value replaced by the provided DID.
445
444
  */
446
445
  public toDidDocument(did: string): DidDocument {
447
446
  const stringThis = JSON.stringify(this).replaceAll(ID_PLACEHOLDER_VALUE, did);
448
- const parseThis = JSON.parse(stringThis) as IDidDocument;
447
+ const parseThis = JSON.parse(stringThis) as Btcr2DidDocument;
449
448
  return new DidDocument(parseThis);
450
449
  }
451
450
 
452
451
 
453
452
  /**
454
- * Create an IntermediateDidDocument from a DidDocument by replacing the DID with a placeholder value.
453
+ * Create an GenesisDocument from a DidDocument by replacing the DID with a placeholder value.
455
454
  * @param {DidDocument} didDocument The DidDocument to convert.
456
- * @returns {IntermediateDidDocument} The IntermediateDidDocument representation of the DidDocument.
455
+ * @returns {GenesisDocument} The GenesisDocument representation of the DidDocument.
457
456
  */
458
- public static fromDidDocument(didDocument: DidDocument): IntermediateDidDocument {
459
- const intermediateDocument = JSON.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE) as IDidDocument;
460
- return new IntermediateDidDocument(intermediateDocument);
457
+ public static fromDidDocument(didDocument: DidDocument): GenesisDocument {
458
+ const intermediateDocument = JSONUtils.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE) as Btcr2DidDocument;
459
+ return new GenesisDocument(intermediateDocument);
461
460
  }
462
461
 
463
462
  /**
464
- * Create a minimal IntermediateDidDocument with a placeholder ID.
463
+ * Create a minimal GenesisDocument with a placeholder ID.
465
464
  * @param {Array<DidVerificationMethod>} verificationMethod The public key in multibase format.
466
465
  * @param {VerificationRelationships} relationships The public key in multibase format.
467
466
  * @param {Array<BeaconService>} service The service to be included in the document.
468
- * @returns {IntermediateDidDocument} A new IntermediateDidDocument with the placeholder ID.
467
+ * @returns {GenesisDocument} A new GenesisDocument with the placeholder ID.
469
468
  */
470
469
  public static create(
471
470
  verificationMethod: Array<DidVerificationMethod>,
472
471
  relationships: VerificationRelationships,
473
472
  service: Array<BeaconService>
474
- ): IntermediateDidDocument {
473
+ ): GenesisDocument {
475
474
  const id = ID_PLACEHOLDER_VALUE;
476
- return new IntermediateDidDocument({ id, ...relationships, verificationMethod, service, });
475
+ return new GenesisDocument({ id, ...relationships, verificationMethod, service, });
477
476
  }
478
477
 
479
478
  /**
480
- * Create a minimal IntermediateDidDocument from a public key.
479
+ * Create a minimal GenesisDocument from a public key.
481
480
  * @param {KeyBytes} publicKey The public key in bytes format.
482
- * @returns {IntermediateDidDocument} A new IntermediateDidDocument with the placeholder ID.
481
+ * @returns {GenesisDocument} A new GenesisDocument with the placeholder ID.
483
482
  */
484
- public static fromPublicKey(publicKey: KeyBytes, network: string): IntermediateDidDocument {
483
+ public static fromPublicKey(publicKey: KeyBytes, network: string): GenesisDocument {
485
484
  const pk = new CompressedSecp256k1PublicKey(publicKey);
486
485
  const id = ID_PLACEHOLDER_VALUE;
487
- const service = BeaconUtils.generateBeaconService({
488
- id : `${id}#key-0`,
489
- publicKey : pk.compressed,
490
- network : getNetwork(network),
491
- addressType : 'p2pkh',
492
- type : 'SingletonBeacon',
493
- });
486
+ const address = payments.p2pkh({ pubkey: pk.compressed, network: getNetwork(network) })?.address;
487
+ const services = [{
488
+ id : `${id}#key-0`,
489
+ serviceEndpoint : `bitcoin:${address}`,
490
+ type : 'SingletonBeacon',
491
+ }];
494
492
 
495
493
  const relationships = {
496
494
  authentication : [`${id}#key-0`],
@@ -507,21 +505,15 @@ export class IntermediateDidDocument extends DidDocument {
507
505
  }
508
506
  ];
509
507
 
510
- return IntermediateDidDocument.create(verificationMethod, relationships, [service]);
508
+ return GenesisDocument.create(verificationMethod, relationships, services);
511
509
  }
512
510
 
513
511
  /**
514
512
  * Taken an object, convert it to an IntermediateDocuemnt and then to a DidDocument.
515
- * @param {JSONObject} object The JSON object to convert.
513
+ * @param {object | DidDocument} object The JSON object to convert.
516
514
  * @returns {DidDocument} The created DidDocument.
517
515
  */
518
- public static fromJSON(object: JSONObject): IntermediateDidDocument {
519
- return new IntermediateDidDocument(object as IDidDocument);
516
+ public static fromJSON(object: object | DidDocument): GenesisDocument {
517
+ return new GenesisDocument(object as Btcr2DidDocument);
520
518
  }
521
- }
522
-
523
- export class Document {
524
- public static isValid(didDocument: DidDocument | IntermediateDidDocument): boolean {
525
- return new DidDocument(didDocument).validateIntermediate();
526
- }
527
- }
519
+ }
@@ -36,7 +36,7 @@ export class GeneralUtils {
36
36
  */
37
37
  static bigintToBuffer(value: bigint): Buffer {
38
38
  const hex = value.toString(16).padStart(64, '0');
39
- return Buffer.fromHex(hex);
39
+ return Buffer.from(hex, 'hex');
40
40
  }
41
41
 
42
42
  /**