@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,292 +0,0 @@
1
- import {
2
- BTCR2_DID_UPDATE_PAYLOAD_CONTEXT,
3
- DidUpdateInvocation,
4
- DidUpdatePayload,
5
- INVALID_DID_DOCUMENT,
6
- INVALID_DID_UPDATE,
7
- INVALID_PUBLIC_KEY_TYPE,
8
- Logger,
9
- MethodError,
10
- NOT_FOUND,
11
- PatchOperation,
12
- ProofOptions
13
- } from '@did-btcr2/common';
14
- import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
15
- import { CompressedSecp256k1PublicKey, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
16
- import { Kms } from '@did-btcr2/kms';
17
- import type { DidService } from '@web5/dids';
18
- import { BeaconService } from '../../interfaces/beacon.js';
19
- import { Appendix } from '../../utils/appendix.js';
20
- import { DidDocument, DidVerificationMethod } from '../../utils/did-document.js';
21
- import { SignalsMetadata } from '../../utils/types.js';
22
- import { BeaconFactory } from '../beacon/factory.js';
23
- import { Identifier } from '../identifier.js';
24
-
25
- export interface ConstructUpdateParams {
26
- identifier: string;
27
- sourceDocument: DidDocument;
28
- sourceVersionId: number;
29
- patch: PatchOperation[];
30
- }
31
-
32
- export interface UpdateParams extends ConstructUpdateParams {
33
- verificationMethodId: string;
34
- beaconIds: string[];
35
- }
36
-
37
- export type InvokePayloadParams = {
38
- identifier: string;
39
- didUpdatePayload: DidUpdatePayload;
40
- verificationMethod: DidVerificationMethod;
41
- }
42
-
43
- /**
44
- * Implements {@link https://dcdpr.github.io/did-btcr2/#update | 4.3 Update}.
45
- *
46
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD
47
- * data format, signed by a verificationMethod that has the authority to make
48
- * the update as specified in the previous DID document. Capability invocations
49
- * for updates MUST be authorized using Data Integrity following the
50
- * bip340-jcs-2025 cryptosuite with a proofPurpose of capabilityInvocation.
51
- *
52
- * @class Update
53
- * @type {Update}
54
- */
55
- export class Update {
56
- /**
57
- * Implements {@link https://dcdpr.github.io/did-btcr2/#construct-did-update-payload | 4.3.1 Construct DID Update Payload}.
58
- *
59
- * The Construct DID Update Payload algorithm applies the documentPatch to the sourceDocument and verifies the
60
- * resulting targetDocument is a conformant DID document. It takes in a Identifier, sourceDocument,
61
- * sourceVersionId, and documentPatch objects. It returns an unsigned DID Update Payload.
62
- *
63
- * @param {ConstructPayloadParams} params See {@link ConstructPayloadParams} for more details.
64
- * @param {string} params.identifier The did-btcr2 identifier to use for verification.
65
- * @param {DidDocument} params.sourceDocument The source document to be updated.
66
- * @param {string} params.sourceVersionId The versionId of the source document.
67
- * @param {DidDocumentPatch} params.patch The JSON patch to be applied to the source document.
68
- * @returns {Promise<DidUpdatePayload>} The constructed DidUpdatePayload object.
69
- * @throws {MethodError} InvalidDid if sourceDocument.id does not match identifier.
70
- */
71
- public static async construct({
72
- identifier,
73
- sourceDocument,
74
- sourceVersionId,
75
- patch,
76
- }: {
77
- identifier: string;
78
- sourceDocument: DidDocument;
79
- sourceVersionId: number;
80
- patch: PatchOperation[];
81
- }): Promise<DidUpdatePayload> {
82
-
83
- // 1. Check that sourceDocument.id equals identifier else MUST raise invalidDIDUpdate error.
84
- if (sourceDocument.id !== identifier) {
85
- throw new MethodError(
86
- INVALID_DID_UPDATE,
87
- 'Source document id does not match identifier',
88
- { sourceDocument, identifier}
89
- );
90
- }
91
-
92
- // 2. Initialize didUpdatePayload to an empty object.
93
- const didUpdatePayload: DidUpdatePayload = {
94
- // 3. Set didUpdatePayload.@context to the following list
95
- '@context' : BTCR2_DID_UPDATE_PAYLOAD_CONTEXT,
96
- // 4. Set didUpdatePayload.patch to documentPatch.
97
- patch,
98
- targetHash : '',
99
- targetVersionId : 0,
100
- sourceHash : '',
101
- };
102
- // TODO: Need to add btcr2 context. ["https://w3id.org/zcap/v1", "https://w3id.org/security/data-integrity/v2", "https://w3id.org/json-ld-patch/v1"]
103
-
104
- // 5. Set targetDocument to the result of applying the documentPatch to the sourceDocument, following the JSON Patch
105
- // specification.
106
- const targetDocument = JSON.patch.apply(sourceDocument, patch) as DidDocument;
107
-
108
- // 6. Validate targetDocument is a conformant DID document, else MUST raise invalidDIDUpdate error.
109
- DidDocument.validate(targetDocument);
110
-
111
- // 7. Set sourceHashBytes to the result of passing sourceDocument into the JSON Canonicalization and Hash algorithm.
112
- // 8. Set didUpdatePayload.sourceHash to the base58-btc Multibase encoding of sourceHashBytes.
113
- didUpdatePayload.sourceHash = (await JSON.canonicalization.process(sourceDocument, 'base58')).slice(1);
114
- // TODO: Question - is base58btc the correct encoding scheme?
115
-
116
- // 9. Set targetHashBytes to the result of passing targetDocument into the JSON Canonicalization and Hash algorithm.
117
- // 10. Set didUpdatePayload.targetHash to the base58-btc Multibase encoding of targetHashBytes.
118
- didUpdatePayload.targetHash = (await JSON.canonicalization.process(targetDocument, 'base58')).slice(1);
119
-
120
- // 11. Set didUpdatePayload.targetVersionId to sourceVersionId + 1.
121
- didUpdatePayload.targetVersionId = sourceVersionId + 1;
122
-
123
- // 12. Return updatePayload.
124
- return didUpdatePayload;
125
- }
126
-
127
- /**
128
- * {@link https://dcdpr.github.io/did-btcr2/#invoke-did-update-payload | 4.3.2 Invoke DID Update Payload}.
129
- *
130
- * The Invoke DID Update Payload algorithm takes in a Identifier, an unsigned didUpdatePayload, and a
131
- * verificationMethod. It retrieves the privateKeyBytes for the verificationMethod and adds a capability invocation in
132
- * the form of a Data Integrity proof following the Authorization Capabilities (ZCAP-LD) and VC Data Integrity
133
- * specifications. It returns the invoked DID Update Payload.
134
- *
135
- * @param {InvokePayloadParams} params Required params for calling the invokePayload method
136
- * @param {string} params.identifier The did-btcr2 identifier to derive the root capability from
137
- * @param {DidUpdatePayload} params.didUpdatePayload The updatePayload object to be signed
138
- * @param {DidVerificationMethod} params.verificationMethod The verificationMethod object to be used for signing
139
- * @returns {DidUpdateInvocation} Did update payload secured with a proof => DidUpdateInvocation
140
- * @throws {MethodError} if the privateKeyBytes are invalid
141
- */
142
- public static async invoke({
143
- identifier,
144
- didUpdatePayload,
145
- verificationMethod
146
- }: {
147
- identifier: string;
148
- didUpdatePayload: DidUpdatePayload;
149
- verificationMethod: DidVerificationMethod;
150
- }): Promise<DidUpdateInvocation> {
151
- // Deconstruct the verificationMethod
152
- const { id: fullId, controller, publicKeyMultibase, secretKeyMultibase } = verificationMethod;
153
-
154
- // Validate the verificationMethod
155
- if(!publicKeyMultibase) {
156
- throw new MethodError(
157
- 'Invalid publicKeyMultibase: cannot be undefined',
158
- INVALID_PUBLIC_KEY_TYPE, verificationMethod
159
- );
160
- }
161
-
162
- // 1. Set privateKeyBytes to the result of retrieving the private key bytes
163
- // associated with the verificationMethod value.
164
- // 1.1 Let id be the fragment portion of verificationMethod.id.
165
- const id = fullId.slice(fullId.indexOf('#'));
166
-
167
- // 1.2 Retrieve the key pair from the KMS or from the secretKeyMultibase
168
- const components = Identifier.decode(id);
169
- const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
170
- const keys = secretKeyMultibase
171
- ? new SchnorrKeyPair({ secretKey: Secp256k1SecretKey.decode(secretKeyMultibase) })
172
- : await Kms.getKey(keyUri as string);
173
- if (!keys) {
174
- throw new MethodError(
175
- 'No privateKey found in kms or vm',
176
- NOT_FOUND, verificationMethod
177
- );
178
- }
179
-
180
- // 1.3 Set multikey to the result of passing verificationMethod and privateKeyBytes into the Multikey Creation algorithm.
181
- const multikey = SchnorrMultikey.create({ id, controller, keys });
182
-
183
- // 1.4 If the privateKey is not found, throw an error
184
- if (!multikey) {
185
- throw new MethodError(
186
- 'Failed to create multikey from verification method',
187
- 'MULTKEY_CREATE_FAILED', verificationMethod
188
- );
189
- }
190
-
191
- // 2. Set rootCapability to the result of passing Identifier into the Derive Root Capability from did:btcr2
192
- // Identifier algorithm.
193
- const rootCapability = Appendix.deriveRootCapability(identifier);
194
- const cryptosuite = 'bip340-jcs-2025';
195
- // 3. Initialize proofOptions to an empty object.
196
- // 4. Set proofOptions.type to DataIntegrityProof.
197
- // 5. Set proofOptions.cryptosuite to schnorr-secp256k1-jcs-2025.
198
- // 6. Set proofOptions.verificationMethod to verificationMethod.id.
199
- // 7. Set proofOptions.proofPurpose to capabilityInvocation.
200
- // 8. Set proofOptions.capability to rootCapability.id.
201
- // 9. Set proofOptions.capabilityAction to Write.
202
- const options: ProofOptions = {
203
- cryptosuite,
204
- type : 'DataIntegrityProof',
205
- verificationMethod : fullId,
206
- proofPurpose : 'capabilityInvocation',
207
- capability : rootCapability.id,
208
- capabilityAction : 'Write',
209
- };
210
-
211
- // 10. Set cryptosuite to the result of executing the Cryptosuite Instantiation algorithm from the BIP340 Data
212
- // Integrity specification passing in proofOptions.
213
- const diproof = multikey.toCryptosuite(cryptosuite).toDataIntegrityProof();
214
-
215
- // 12. Set didUpdateInvocation to the result of executing the Add Proof algorithm from VC Data Integrity passing
216
- // didUpdatePayload as the input document, cryptosuite, and the set of proofOptions.
217
- // 13. Return didUpdateInvocation.
218
- return await diproof.addProof({ document: didUpdatePayload, options });
219
- }
220
-
221
- /**
222
- * Implements {@link https://dcdpr.github.io/did-btcr2/#announce-did-update | 4.3.3 Announce DID Update}.
223
- *
224
- * The Announce DID Update algorithm retrieves beaconServices from the sourceDocument and calls the Broadcast DID
225
- * Update algorithm corresponding to the type of the Beacon. It takes in a Identifier, sourceDocument, an array of
226
- * beaconIds, and a didUpdateInvocation. It returns an array of signalsMetadata, containing the necessary
227
- * data to validate the Beacon Signal against the didUpdateInvocation.
228
- *
229
- * @param {AnnounceUpdatePayloadParams} params Required params for calling the announcePayload method
230
- * @param {DidDocument} params.sourceDocument The did-btcr2 did document to derive the root capability from
231
- * @param {string[]} params.beaconIds The didUpdatePayload object to be signed
232
- * @param {DidUpdateInvocation} params.didUpdatePayload The verificationMethod object to be used for signing
233
- * @returns {SignalsMetadata} The signalsMetadata object containing data to validate the Beacon Signal
234
- * @throws {MethodError} if the beaconService type is invalid
235
- */
236
- public static async announce({
237
- sourceDocument,
238
- beaconIds,
239
- didUpdateInvocation
240
- }: {
241
- sourceDocument: DidDocument;
242
- beaconIds: string[];
243
- didUpdateInvocation: DidUpdateInvocation;
244
- }): Promise<SignalsMetadata> {
245
- // 1. Set beaconServices to an empty array.
246
- const beaconServices: BeaconService[] = [];
247
-
248
- // 2. signalMetadata to an empty array.
249
- let signalsMetadata;
250
-
251
- // 3. For beaconId in beaconIds:
252
- for (const beaconId of beaconIds) {
253
- // 3.1 Find the beacon services in the sourceDocument
254
- const beaconService = sourceDocument.service.find((s: DidService) => s.id === beaconId);
255
-
256
- // 3.2 If no beaconService MUST throw beaconNotFound error.
257
- if (!beaconService) {
258
- throw new MethodError('Not found: sourceDocument does not contain beaconId', INVALID_DID_DOCUMENT, { beaconId });
259
- }
260
-
261
- // 3.3 Push beaconService to beaconServices.
262
- beaconServices.push(beaconService);
263
- }
264
-
265
- // 4. For beaconService in beaconServices:
266
- for (const beaconService of beaconServices) {
267
- // 4.1 Set signalMetadata to null.
268
- // 4.2 If beaconService.type == SingletonBeacon:
269
- // 4.2.1 Set signalMetadata to the result of passing beaconService and didUpdateInvocation to the Broadcast
270
- // Singleton Beacon Signal algorithm.
271
- // 4.3 Else If beaconService.type == CIDAggregateBeacon:
272
- // 4.3.1 Set signalMetadata to the result of passing Identifier, beaconService and didUpdateInvocation to
273
- // the Broadcast CIDAggregate Beacon Signal algorithm.
274
- // 4.4 Else If beaconService.type == SMTAggregateBeacon:
275
- // 4.4.1 Set signalMetadata to the result of passing Identifier, beaconService and didUpdateInvocation to
276
- // the Broadcast SMTAggregate Beacon Signal algorithm.
277
- // 4.5 Else:
278
- // 4.5.1 MUST throw invalidBeacon error.
279
- const beacon = BeaconFactory.establish(beaconService);
280
- signalsMetadata = await beacon.broadcastSignal(didUpdateInvocation);
281
- }
282
- if(!signalsMetadata) {
283
- throw new MethodError(
284
- 'Invalid beacon: no signalsMetadata found',
285
- INVALID_DID_DOCUMENT, { beaconServices }
286
- );
287
- }
288
- Logger.debug('signalsMetadata', signalsMetadata);
289
- // Return the signalsMetadata
290
- return signalsMetadata;
291
- }
292
- }
@@ -1,137 +0,0 @@
1
- import { RawTransactionRest, RawTransactionV2 } from '@did-btcr2/bitcoin';
2
- import { DidUpdatePayload, UnixTimestamp } from '@did-btcr2/common';
3
- import { DidServiceEndpoint, DidService as IDidService } from '@web5/dids';
4
- import { SidecarData, SignalsMetadata } from '../utils/types.js';
5
-
6
- /**
7
- * Beacon interface
8
- * @interface IBeacon
9
- * @type {IBeacon}
10
- */
11
- export interface IBeacon {
12
- /**
13
- * A unique identifier for the Beacon
14
- * @type {string}
15
- */
16
- id: string;
17
-
18
- /**
19
- * The type of the Beacon
20
- * @type {string}
21
- */
22
- type: string;
23
-
24
- /**
25
- * The service endpoint of the Beacon
26
- * @type {string}
27
- */
28
- serviceEndpoint: DidServiceEndpoint;
29
-
30
- /**
31
- * Returns the Beacon Service object
32
- * @type {BeaconService}
33
- */
34
- service: BeaconService;
35
-
36
- /**
37
- * Generates a Beacon Signal Transaction
38
- * @param {string} didUpdatePayload The DID update payload
39
- * @returns {BeaconSignal} The Beacon Signal
40
- */
41
- generateSignal(didUpdatePayload: string): BeaconSignal;
42
-
43
- /**
44
- * Processes a Beacon Signal.
45
- * @param {RawTransactionV2} signal The raw transaction
46
- * @param {SidecarData} signalsMetadata The signals metadata from the sidecar data
47
- * @returns {Promise<DidUpdatePayload | undefined>} The DID update payload
48
- */
49
- processSignal(signal: RawTransactionV2, signalsMetadata: SignalsMetadata): Promise<DidUpdatePayload | undefined>;
50
-
51
-
52
- /**
53
- * Broadcasts a signal.
54
- * @param {DidUpdatePayload} didUpdatePayload The DID update payload.
55
- * @returns {Promise<SignalMetadata>} The signal metadata.
56
- */
57
- broadcastSignal(didUpdatePayload: DidUpdatePayload): Promise<SignalsMetadata>;
58
- }
59
-
60
- export interface BeaconService extends IDidService {
61
- serviceEndpoint: DidServiceEndpoint;
62
- casType?: string;
63
- }
64
-
65
- export interface BeaconServiceAddress extends BeaconService {
66
- address: string;
67
- }
68
- export interface BeaconSignal {
69
- beaconId: string;
70
- beaconType: string;
71
- beaconAddress: string;
72
- tx: RawTransactionRest | RawTransactionV2;
73
- blockheight: number;
74
- blocktime: UnixTimestamp;
75
- }
76
-
77
- /**
78
- * Implements {@link https://dcdpr.github.io/did-btcr2/#update-beacons | 5. Beacons}.
79
- * Beacons are the mechanism by which a DID controller announces an update to their DID document by broadcasting an
80
- * attestation to this update onto the public Bitcoin network. Beacons are identified by a Bitcoin address and emit
81
- * Beacon Signals by broadcasting a valid Bitcoin transaction that spends from this Beacon address. These transactions
82
- * include attestations to a set of didUpdatePayloads, either in the form of Content Identifiers (CIDs) or Sparse Merkle
83
- * Tree (SMT) roots. Beacons are included as a service in DID documents, with the Service Endpoint identifying a Bitcoin
84
- * address to watch for Beacon Signals. All Beacon Signals broadcast from this Beacon MUST be processed as part of
85
- * resolution (see Read). The type of the Beacon service in the DID document defines how Beacon Signals SHOULD be
86
- * processed.
87
- * did:btcr2 supports different Beacon Types, with each type defining a set of algorithms for:
88
- * 1. How a Beacon can be established and added as a service to a DID document.
89
- * 2. How attestations to DID updates are broadcast within Beacon Signals.
90
- * 3. How a resolver processes a Beacon Signal, identifying, verifying, and applying the authorized mutations to a
91
- * DID document for a specific DID.
92
- * This is an extendable mechanism, such that in the future new Beacon Types could be added. It would be up to the
93
- * resolver to determine if the Beacon Type is a mechanism they support and are willing to trust. If they are unable to
94
- * support a Beacon Type and a DID they are resolving uses that type then the DID MUST be treated as invalid.
95
- * The current, active Beacons of a DID document are specified in the document’s service property. By updating the DID
96
- * document, a DID controller can change the set of Beacons they can use to broadcast updates to their DID document over
97
- * time. Resolution of a DID MUST process signals from all Beacons identified in the latest DID document and apply them
98
- * in order determined by the version specified by the didUpdatePayload.
99
- * All resolvers of did:btcr2 DIDs MUST support the core Beacon Types defined in this specification.
100
- *
101
- * @abstract
102
- * @class Beacon
103
- * @type {Beacon}
104
- */
105
- export abstract class Beacon implements IBeacon {
106
- public id: string;
107
- public type: string;
108
- public serviceEndpoint: DidServiceEndpoint;
109
- public sidecar?: SidecarData;
110
-
111
- constructor({ id, type, serviceEndpoint }: BeaconService, sidecar?: SidecarData) {
112
- this.id = id;
113
- this.type = type;
114
- this.serviceEndpoint = serviceEndpoint;
115
- this.sidecar = sidecar;
116
- }
117
-
118
- /**
119
- * Returns the Beacon Service object.
120
- */
121
- abstract get service(): BeaconService;
122
-
123
- /**
124
- * Generates a Beacon Signal (implemented by subclasses).
125
- */
126
- abstract generateSignal(didUpdatePayload: string): BeaconSignal;
127
-
128
- /**
129
- * Processes a Beacon Signal (implemented by subclasses).
130
- */
131
- abstract processSignal(signal: RawTransactionRest | RawTransactionV2, signalsMetadata: SignalsMetadata): Promise<DidUpdatePayload | undefined>
132
-
133
- /**
134
- * Broadcasts a Beacon Signal (implemented by subclasses).
135
- */
136
- abstract broadcastSignal(didUpdatePayload: DidUpdatePayload): Promise<SignalsMetadata>;
137
- }
@@ -1,33 +0,0 @@
1
- import { UnixTimestamp } from '@did-btcr2/common';
2
- import { DidResolutionOptions as IDidResolutionOptions } from '@web5/dids';
3
- import { DidDocument } from '../utils/did-document.js';
4
- import { SidecarData } from '../utils/types.js';
5
-
6
- /**
7
- * Options for resolving a DID Document
8
- * @param {?number} versionId The versionId for resolving the DID Document
9
- * @param {?UnixTimestamp} versionTime The versionTime for resolving the DID Document
10
- * @param {?SidecarData} sidecarData The sidecar data for resolving the DID Document
11
- */
12
- export interface DidResolutionOptions extends IDidResolutionOptions {
13
- versionId?: number
14
- versionTime?: UnixTimestamp;
15
- sidecarData?: SidecarData;
16
- network?: string;
17
- }
18
- export interface RootCapability {
19
- '@context': string;
20
- id: string;
21
- controller: string;
22
- invocationTarget: string;
23
- }
24
- export interface ReadBlockchainParams {
25
- contemporaryDidDocument: DidDocument;
26
- contemporaryBlockHeight: number | 1;
27
- currentVersionId: number | 1;
28
- targetVersionId?: number;
29
- targetBlockHeight: number;
30
- updateHashHistory: string[];
31
- sidecarData?: SidecarData;
32
- options?: DidResolutionOptions;
33
- }
@@ -1,41 +0,0 @@
1
- import { DidUpdatePayload, ProofBytes } from '@did-btcr2/common';
2
- import { BeaconService } from '../interfaces/beacon.js';
3
- import { DidDocument } from './did-document.js';
4
- import { BlockV3 } from '@did-btcr2/bitcoin';
5
-
6
- export type FindNextSignals = {
7
- block: BlockV3;
8
- beacons: BeaconService[]
9
- };
10
- export type Metadata = {
11
- didUpdate: DidUpdatePayload;
12
- proofs?: string;
13
- };
14
- export type SignalSidecarData = Metadata;
15
- export interface Sidecar {
16
- did: string;
17
- }
18
- export type SignalsMetadata = { [signalId: string]: Metadata; };
19
- export interface SingletonSidecar extends Sidecar {
20
- signalsMetadata: SignalsMetadata;
21
- }
22
- export interface CIDAggregateSidecar extends Sidecar {
23
- initialDocument: DidDocument;
24
- signalsMetadata: SignalsMetadata;
25
- cidUpdates: Array<string>;
26
- }
27
- export interface SMTAggregateSidecar extends Sidecar {
28
- initialDocument: DidDocument;
29
- signalsMetadata: SignalsMetadata;
30
- smtProof: ProofBytes;
31
- }
32
- export type BeaconSidecarData<T> =
33
- T extends 'SingletonBeacon' ? SingletonSidecar :
34
- T extends 'CIDAggregateBeacon' ? CIDAggregateSidecar :
35
- T extends 'SMTAggregateBeacon' ? SMTAggregateSidecar :
36
- T;
37
- export type SidecarData = BeaconSidecarData<SingletonSidecar | CIDAggregateSidecar | SMTAggregateSidecar>;
38
- export type GetSigningMethodParams = {
39
- didDocument: DidDocument;
40
- methodId?: string;
41
- };
File without changes
File without changes