@did-btcr2/method 0.18.0 → 0.19.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 (262) hide show
  1. package/dist/browser.js +5240 -6079
  2. package/dist/browser.mjs +5240 -6079
  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/cas-beacon.js +55 -0
  36. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -0
  37. package/dist/cjs/core/beacon/factory.js +11 -10
  38. package/dist/cjs/core/beacon/factory.js.map +1 -1
  39. package/dist/cjs/core/beacon/interfaces.js +32 -0
  40. package/dist/cjs/core/beacon/interfaces.js.map +1 -0
  41. package/dist/cjs/core/beacon/singleton.js +59 -135
  42. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  43. package/dist/cjs/core/beacon/smt-beacon.js +56 -0
  44. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -0
  45. package/dist/cjs/core/beacon/utils.js +67 -105
  46. package/dist/cjs/core/beacon/utils.js.map +1 -1
  47. package/dist/cjs/core/identifier.js +18 -21
  48. package/dist/cjs/core/identifier.js.map +1 -1
  49. package/dist/cjs/core/interfaces.js +2 -0
  50. package/dist/cjs/core/interfaces.js.map +1 -0
  51. package/dist/cjs/core/resolve.js +511 -0
  52. package/dist/cjs/core/resolve.js.map +1 -0
  53. package/dist/cjs/{utils → core}/types.js.map +1 -1
  54. package/dist/cjs/core/{crud/update.js → update.js} +62 -52
  55. package/dist/cjs/core/update.js.map +1 -0
  56. package/dist/cjs/did-btcr2.js +109 -75
  57. package/dist/cjs/did-btcr2.js.map +1 -1
  58. package/dist/cjs/index.js +14 -15
  59. package/dist/cjs/index.js.map +1 -1
  60. package/dist/cjs/utils/appendix.js +10 -18
  61. package/dist/cjs/utils/appendix.js.map +1 -1
  62. package/dist/cjs/utils/did-document.js +51 -58
  63. package/dist/cjs/utils/did-document.js.map +1 -1
  64. package/dist/cjs/utils/general.js +1 -1
  65. package/dist/cjs/utils/general.js.map +1 -1
  66. package/dist/esm/core/beacon/aggregation/cohort/index.js +3 -3
  67. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
  68. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js +1 -9
  69. package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
  70. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +2 -1
  71. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
  72. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +2 -1
  73. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
  74. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +2 -1
  75. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
  76. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +2 -1
  77. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
  78. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +2 -1
  79. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
  80. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +2 -1
  81. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
  82. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +2 -1
  83. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
  84. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +2 -1
  85. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
  86. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js +2 -1
  87. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
  88. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +2 -1
  89. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
  90. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +36 -18
  91. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  92. package/dist/esm/core/beacon/aggregation/coordinator.js +14 -14
  93. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  94. package/dist/esm/core/beacon/aggregation/participant.js +4 -3
  95. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  96. package/dist/esm/core/beacon/aggregation/session/index.js +1 -1
  97. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
  98. package/dist/esm/core/beacon/cas-beacon.js +55 -0
  99. package/dist/esm/core/beacon/cas-beacon.js.map +1 -0
  100. package/dist/esm/core/beacon/factory.js +11 -10
  101. package/dist/esm/core/beacon/factory.js.map +1 -1
  102. package/dist/esm/core/beacon/interfaces.js +32 -0
  103. package/dist/esm/core/beacon/interfaces.js.map +1 -0
  104. package/dist/esm/core/beacon/singleton.js +59 -135
  105. package/dist/esm/core/beacon/singleton.js.map +1 -1
  106. package/dist/esm/core/beacon/smt-beacon.js +56 -0
  107. package/dist/esm/core/beacon/smt-beacon.js.map +1 -0
  108. package/dist/esm/core/beacon/utils.js +67 -105
  109. package/dist/esm/core/beacon/utils.js.map +1 -1
  110. package/dist/esm/core/identifier.js +18 -21
  111. package/dist/esm/core/identifier.js.map +1 -1
  112. package/dist/esm/core/interfaces.js +2 -0
  113. package/dist/esm/core/interfaces.js.map +1 -0
  114. package/dist/esm/core/resolve.js +511 -0
  115. package/dist/esm/core/resolve.js.map +1 -0
  116. package/dist/esm/{utils → core}/types.js.map +1 -1
  117. package/dist/esm/core/{crud/update.js → update.js} +62 -52
  118. package/dist/esm/core/update.js.map +1 -0
  119. package/dist/esm/did-btcr2.js +109 -75
  120. package/dist/esm/did-btcr2.js.map +1 -1
  121. package/dist/esm/index.js +14 -15
  122. package/dist/esm/index.js.map +1 -1
  123. package/dist/esm/utils/appendix.js +10 -18
  124. package/dist/esm/utils/appendix.js.map +1 -1
  125. package/dist/esm/utils/did-document.js +51 -58
  126. package/dist/esm/utils/did-document.js.map +1 -1
  127. package/dist/esm/utils/general.js +1 -1
  128. package/dist/esm/utils/general.js.map +1 -1
  129. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -1
  130. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +0 -7
  131. package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -1
  132. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -1
  133. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -1
  134. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -1
  135. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -1
  136. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -1
  137. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -1
  138. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -1
  139. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -1
  140. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -1
  141. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -1
  142. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +13 -5
  143. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
  144. package/dist/types/core/beacon/aggregation/coordinator.d.ts +17 -29
  145. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  146. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  147. package/dist/types/core/beacon/cas-beacon.d.ts +47 -0
  148. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -0
  149. package/dist/types/core/beacon/factory.d.ts +5 -4
  150. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  151. package/dist/types/core/beacon/interfaces.d.ts +98 -0
  152. package/dist/types/core/beacon/interfaces.d.ts.map +1 -0
  153. package/dist/types/core/beacon/singleton.d.ts +22 -65
  154. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  155. package/dist/types/core/beacon/smt-beacon.d.ts +48 -0
  156. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -0
  157. package/dist/types/core/beacon/utils.d.ts +19 -97
  158. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  159. package/dist/types/core/identifier.d.ts.map +1 -1
  160. package/dist/types/core/interfaces.d.ts +94 -0
  161. package/dist/types/core/interfaces.d.ts.map +1 -0
  162. package/dist/types/core/resolve.d.ts +105 -0
  163. package/dist/types/core/resolve.d.ts.map +1 -0
  164. package/dist/types/core/types.d.ts +71 -0
  165. package/dist/types/core/types.d.ts.map +1 -0
  166. package/dist/types/core/{crud/update.d.ts → update.d.ts} +21 -20
  167. package/dist/types/core/update.d.ts.map +1 -0
  168. package/dist/types/did-btcr2.d.ts +45 -57
  169. package/dist/types/did-btcr2.d.ts.map +1 -1
  170. package/dist/types/index.d.ts +14 -15
  171. package/dist/types/index.d.ts.map +1 -1
  172. package/dist/types/utils/appendix.d.ts +5 -10
  173. package/dist/types/utils/appendix.d.ts.map +1 -1
  174. package/dist/types/utils/did-document-builder.d.ts +1 -1
  175. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  176. package/dist/types/utils/did-document.d.ts +31 -29
  177. package/dist/types/utils/did-document.d.ts.map +1 -1
  178. package/package.json +5 -5
  179. package/src/core/beacon/aggregation/cohort/index.ts +3 -3
  180. package/src/core/beacon/aggregation/cohort/messages/base.ts +1 -12
  181. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +2 -2
  182. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +2 -2
  183. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +2 -2
  184. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +2 -2
  185. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +2 -2
  186. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +2 -2
  187. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +2 -2
  188. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +2 -2
  189. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +2 -2
  190. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +2 -2
  191. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +43 -21
  192. package/src/core/beacon/aggregation/coordinator.ts +41 -29
  193. package/src/core/beacon/aggregation/participant.ts +4 -3
  194. package/src/core/beacon/aggregation/session/index.ts +1 -1
  195. package/src/core/beacon/cas-beacon.ts +67 -0
  196. package/src/core/beacon/factory.ts +13 -15
  197. package/src/core/beacon/interfaces.ts +124 -0
  198. package/src/core/beacon/singleton.ts +75 -145
  199. package/src/core/beacon/smt-beacon.ts +70 -0
  200. package/src/core/beacon/utils.ts +80 -170
  201. package/src/core/identifier.ts +21 -24
  202. package/src/core/interfaces.ts +101 -0
  203. package/src/core/resolve.ts +707 -0
  204. package/src/core/types.ts +78 -0
  205. package/src/core/{crud/update.ts → update.ts} +75 -68
  206. package/src/did-btcr2.ts +152 -92
  207. package/src/index.ts +14 -24
  208. package/src/utils/appendix.ts +18 -22
  209. package/src/utils/did-document-builder.ts +1 -1
  210. package/src/utils/did-document.ts +67 -71
  211. package/src/utils/general.ts +1 -1
  212. package/dist/cjs/core/beacon/cid-aggregate.js +0 -116
  213. package/dist/cjs/core/beacon/cid-aggregate.js.map +0 -1
  214. package/dist/cjs/core/beacon/smt-aggregate.js +0 -126
  215. package/dist/cjs/core/beacon/smt-aggregate.js.map +0 -1
  216. package/dist/cjs/core/crud/deactivate.js +0 -14
  217. package/dist/cjs/core/crud/deactivate.js.map +0 -1
  218. package/dist/cjs/core/crud/read.js +0 -679
  219. package/dist/cjs/core/crud/read.js.map +0 -1
  220. package/dist/cjs/core/crud/update.js.map +0 -1
  221. package/dist/cjs/interfaces/beacon.js +0 -41
  222. package/dist/cjs/interfaces/beacon.js.map +0 -1
  223. package/dist/cjs/interfaces/crud.js +0 -2
  224. package/dist/cjs/interfaces/crud.js.map +0 -1
  225. package/dist/esm/core/beacon/cid-aggregate.js +0 -116
  226. package/dist/esm/core/beacon/cid-aggregate.js.map +0 -1
  227. package/dist/esm/core/beacon/smt-aggregate.js +0 -126
  228. package/dist/esm/core/beacon/smt-aggregate.js.map +0 -1
  229. package/dist/esm/core/crud/deactivate.js +0 -14
  230. package/dist/esm/core/crud/deactivate.js.map +0 -1
  231. package/dist/esm/core/crud/read.js +0 -679
  232. package/dist/esm/core/crud/read.js.map +0 -1
  233. package/dist/esm/core/crud/update.js.map +0 -1
  234. package/dist/esm/interfaces/beacon.js +0 -41
  235. package/dist/esm/interfaces/beacon.js.map +0 -1
  236. package/dist/esm/interfaces/crud.js +0 -2
  237. package/dist/esm/interfaces/crud.js.map +0 -1
  238. package/dist/types/core/beacon/cid-aggregate.d.ts +0 -102
  239. package/dist/types/core/beacon/cid-aggregate.d.ts.map +0 -1
  240. package/dist/types/core/beacon/smt-aggregate.d.ts +0 -111
  241. package/dist/types/core/beacon/smt-aggregate.d.ts.map +0 -1
  242. package/dist/types/core/crud/deactivate.d.ts +0 -13
  243. package/dist/types/core/crud/deactivate.d.ts.map +0 -1
  244. package/dist/types/core/crud/read.d.ts +0 -334
  245. package/dist/types/core/crud/read.d.ts.map +0 -1
  246. package/dist/types/core/crud/update.d.ts.map +0 -1
  247. package/dist/types/interfaces/beacon.d.ts +0 -116
  248. package/dist/types/interfaces/beacon.d.ts.map +0 -1
  249. package/dist/types/interfaces/crud.d.ts +0 -32
  250. package/dist/types/interfaces/crud.d.ts.map +0 -1
  251. package/dist/types/utils/types.d.ts +0 -38
  252. package/dist/types/utils/types.d.ts.map +0 -1
  253. package/src/canonicalize.d.ts +0 -6
  254. package/src/core/beacon/cid-aggregate.ts +0 -153
  255. package/src/core/beacon/smt-aggregate.ts +0 -135
  256. package/src/core/crud/deactivate.ts +0 -13
  257. package/src/core/crud/read.ts +0 -948
  258. package/src/interfaces/beacon.ts +0 -137
  259. package/src/interfaces/crud.ts +0 -33
  260. package/src/utils/types.ts +0 -41
  261. /package/dist/cjs/{utils → core}/types.js +0 -0
  262. /package/dist/esm/{utils → core}/types.js +0 -0
@@ -0,0 +1,78 @@
1
+ import { HexString } from '@did-btcr2/common';
2
+ import { BTCR2SignedUpdate } from '@did-btcr2/cryptosuite';
3
+ import { SMTProof } from './interfaces.js';
4
+
5
+ /**
6
+ * {@link https://dcdpr.github.io/did-btcr2/data-structures.html#cas-announcement | CAS Announcement }
7
+ * a data structure that maps DIDs to BTCR2 Signed Update hashes. All BTCR2 Signed
8
+ * Updates (data structure) MUST be hashed with the JSON Document Hashing algorithm.
9
+ * The concrete representation of this data structure will be published to a CAS.
10
+ * @example
11
+ * ```json
12
+ * {
13
+ * "did:btcr2:k1q5pa5tq86fzrl0ez32nh8e0ks4tzzkxnnmn8tdvxk04ahzt70u09dag02h0cp": "a4ayc_80_OGda4BO_1o_V0etpOqiLx1JwB5S3beHW0s",
14
+ * "did:btcr2:x1qhjw6jnhwcyu5wau4x0cpwvz74c3g82c3uaehqpaf7lzfgmnwsd7spmmf54": "1HNeOiZeFu7gP1lxi5tdAwGcB9i2xR-Q2jpmbuwTqzU",
15
+ * "did:btcr2:k1qgp5h79scv4sfqkzak5g6y89dsy3cq0pd2nussu2cm3zjfhn4ekwrucc4q7t7": "TgdAhWK-24tgzgXB3s_jrRa3IjCWfeAfZAt-Rym0n84"
16
+ * }
17
+ * ```
18
+ */
19
+ export type CASAnnouncement = {
20
+ [key: string]: string
21
+ }
22
+
23
+ /**
24
+ * See {@link https://dcdpr.github.io/did-btcr2/terminology.html#sidecar | Sidecar }
25
+ * for more details about the sidecar mechanism. See {@link https://dcdpr.github.io/did-btcr2/data-structures.html#sidecar-data | Sidecar Data}
26
+ * for more details about the data structure.
27
+ */
28
+ export type Sidecar = {
29
+ /**
30
+ * The context string "https://btcr2.dev/context/v1"
31
+ */
32
+ '@context'?: string,
33
+
34
+ /**
35
+ * Optional Genesis Did Document. Required when resolving did:btcr2 identifiers
36
+ * with `x` HRP.D
37
+ */
38
+ genesisDocument?: object;
39
+
40
+ /**
41
+ * Optional array of BTCR2 Signed Updates. Required if the DID being resolved
42
+ * has ever had a published BTCR2 Update.
43
+ */
44
+ updates?: Array<BTCR2SignedUpdate>
45
+
46
+ /**
47
+ * Optional array of CAS Announcements. Required if the DID being reslved has
48
+ * used a CAS Beacon to publish a BTCR2 Update.
49
+ */
50
+ casUpdates?: Array<CASAnnouncement>;
51
+
52
+ /**
53
+ * Optional array of SMT Proofs. Required if the DID being resolved has used
54
+ * an SMT Beacon to publish a BTCR2 Update.
55
+ */
56
+ smtProofs?: Array<SMTProof>;
57
+ };
58
+
59
+ /**
60
+ * The Sidecar data structure post-processing used for resolution.
61
+ */
62
+ export type SidecarData = {
63
+ /**
64
+ * Map of BTCR2 Signed Updates by their hash bytes.
65
+ * @type {Map<HexString, BTCR2SignedUpdate>}
66
+ */
67
+ updateMap: Map<HexString, BTCR2SignedUpdate>;
68
+ /**
69
+ * Map of CAS Announcements by their hash bytes.
70
+ * @type {Map<HexString, CASAnnouncement>}
71
+ */
72
+ casMap: Map<HexString, CASAnnouncement>;
73
+ /**
74
+ * Map of SMT Proofs by their ID.
75
+ * @type {Map<string, SMTProof>}
76
+ */
77
+ smtMap: Map<string, SMTProof>;
78
+ }
@@ -1,26 +1,23 @@
1
1
  import {
2
- BTCR2_DID_UPDATE_PAYLOAD_CONTEXT,
3
- DidUpdateInvocation,
4
- DidUpdatePayload,
5
2
  INVALID_DID_DOCUMENT,
6
3
  INVALID_DID_UPDATE,
7
4
  INVALID_PUBLIC_KEY_TYPE,
8
- Logger,
5
+ JSONPatch,
9
6
  MethodError,
10
7
  NOT_FOUND,
11
8
  PatchOperation,
12
- ProofOptions
9
+ UpdateError
13
10
  } from '@did-btcr2/common';
14
- import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
11
+ import { BTCR2SignedUpdate, BTCR2UnsignedUpdate, DataIntegrityConfig, SchnorrMultikey } from '@did-btcr2/cryptosuite';
15
12
  import { CompressedSecp256k1PublicKey, SchnorrKeyPair, Secp256k1SecretKey } from '@did-btcr2/keypair';
16
13
  import { Kms } from '@did-btcr2/kms';
17
14
  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';
15
+ import { canonicalization } from '../did-btcr2.js';
16
+ import { Appendix } from '../utils/appendix.js';
17
+ import { DidDocument, DidVerificationMethod } from '../utils/did-document.js';
18
+ import { BeaconService } from './beacon/interfaces.js';
19
+ import { Identifier } from './identifier.js';
20
+ import { SidecarData } from './types.js';
24
21
 
25
22
  export interface ConstructUpdateParams {
26
23
  identifier: string;
@@ -36,7 +33,7 @@ export interface UpdateParams extends ConstructUpdateParams {
36
33
 
37
34
  export type InvokePayloadParams = {
38
35
  identifier: string;
39
- didUpdatePayload: DidUpdatePayload;
36
+ BTCR2SignedUpdate: BTCR2SignedUpdate;
40
37
  verificationMethod: DidVerificationMethod;
41
38
  }
42
39
 
@@ -65,7 +62,7 @@ export class Update {
65
62
  * @param {DidDocument} params.sourceDocument The source document to be updated.
66
63
  * @param {string} params.sourceVersionId The versionId of the source document.
67
64
  * @param {DidDocumentPatch} params.patch The JSON patch to be applied to the source document.
68
- * @returns {Promise<DidUpdatePayload>} The constructed DidUpdatePayload object.
65
+ * @returns {Promise<BTCR2SignedUpdate>} The constructed BTCR2SignedUpdate object.
69
66
  * @throws {MethodError} InvalidDid if sourceDocument.id does not match identifier.
70
67
  */
71
68
  public static async construct({
@@ -78,76 +75,79 @@ export class Update {
78
75
  sourceDocument: DidDocument;
79
76
  sourceVersionId: number;
80
77
  patch: PatchOperation[];
81
- }): Promise<DidUpdatePayload> {
78
+ }): Promise<BTCR2UnsignedUpdate> {
82
79
 
83
80
  // 1. Check that sourceDocument.id equals identifier else MUST raise invalidDIDUpdate error.
84
81
  if (sourceDocument.id !== identifier) {
85
- throw new MethodError(
86
- INVALID_DID_UPDATE,
87
- 'Source document id does not match identifier',
88
- { sourceDocument, identifier}
82
+ throw new UpdateError(
83
+ 'Identifier mismatch: sourceDocument.id !== identifier',
84
+ INVALID_DID_UPDATE, { sourceDocument, identifier }
89
85
  );
90
86
  }
91
87
 
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.
88
+ // 2. Initialize an unsigned update.
89
+ const unsignedUpdate: BTCR2UnsignedUpdate = {
90
+ // 3. Set BTCR2SignedUpdate.@context to the following list
91
+ '@context' : [
92
+ 'https://w3id.org/security/v2',
93
+ 'https://w3id.org/zcap/v1',
94
+ 'https://w3id.org/json-ld-patch/v1',
95
+ 'https://btcr2.dev/context/v1'
96
+ ],
97
+ // 4. Set BTCR2SignedUpdate.patch to documentPatch.
97
98
  patch,
98
99
  targetHash : '',
99
100
  targetVersionId : 0,
100
101
  sourceHash : '',
101
102
  };
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
103
 
104
104
  // 5. Set targetDocument to the result of applying the documentPatch to the sourceDocument, following the JSON Patch
105
105
  // specification.
106
- const targetDocument = JSON.patch.apply(sourceDocument, patch) as DidDocument;
106
+ const targetDocument = JSONPatch.apply(sourceDocument, patch) as DidDocument;
107
107
 
108
108
  // 6. Validate targetDocument is a conformant DID document, else MUST raise invalidDIDUpdate error.
109
109
  DidDocument.validate(targetDocument);
110
110
 
111
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);
112
+ // 8. Set BTCR2SignedUpdate.sourceHash to the base58-btc Multibase encoding of sourceHashBytes.
113
+ unsignedUpdate.sourceHash = (canonicalization.process(sourceDocument, { encoding: 'base58' })).slice(1);
114
114
  // TODO: Question - is base58btc the correct encoding scheme?
115
115
 
116
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);
117
+ // 10. Set BTCR2SignedUpdate.targetHash to the base58-btc Multibase encoding of targetHashBytes.
118
+ unsignedUpdate.targetHash = (canonicalization.process(targetDocument, { encoding: 'base58' })).slice(1);
119
119
 
120
- // 11. Set didUpdatePayload.targetVersionId to sourceVersionId + 1.
121
- didUpdatePayload.targetVersionId = sourceVersionId + 1;
120
+ // 11. Set BTCR2SignedUpdate.targetVersionId to sourceVersionId + 1.
121
+ unsignedUpdate.targetVersionId = sourceVersionId + 1;
122
122
 
123
123
  // 12. Return updatePayload.
124
- return didUpdatePayload;
124
+ return unsignedUpdate;
125
125
  }
126
126
 
127
127
  /**
128
128
  * {@link https://dcdpr.github.io/did-btcr2/#invoke-did-update-payload | 4.3.2 Invoke DID Update Payload}.
129
129
  *
130
- * The Invoke DID Update Payload algorithm takes in a Identifier, an unsigned didUpdatePayload, and a
130
+ * The Invoke DID Update Payload algorithm takes in a Identifier, an unsigned BTCR2SignedUpdate, and a
131
131
  * verificationMethod. It retrieves the privateKeyBytes for the verificationMethod and adds a capability invocation in
132
132
  * the form of a Data Integrity proof following the Authorization Capabilities (ZCAP-LD) and VC Data Integrity
133
133
  * specifications. It returns the invoked DID Update Payload.
134
134
  *
135
135
  * @param {InvokePayloadParams} params Required params for calling the invokePayload method
136
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
137
+ * @param {BTCR2SignedUpdate} params.BTCR2SignedUpdate The updatePayload object to be signed
138
138
  * @param {DidVerificationMethod} params.verificationMethod The verificationMethod object to be used for signing
139
- * @returns {DidUpdateInvocation} Did update payload secured with a proof => DidUpdateInvocation
139
+ * @returns {BTCR2SignedUpdate} Did update payload secured with a proof => BTCR2SignedUpdate
140
140
  * @throws {MethodError} if the privateKeyBytes are invalid
141
141
  */
142
142
  public static async invoke({
143
143
  identifier,
144
- didUpdatePayload,
144
+ unsignedUpdate,
145
145
  verificationMethod
146
146
  }: {
147
147
  identifier: string;
148
- didUpdatePayload: DidUpdatePayload;
148
+ unsignedUpdate: BTCR2UnsignedUpdate;
149
149
  verificationMethod: DidVerificationMethod;
150
- }): Promise<DidUpdateInvocation> {
150
+ }): Promise<BTCR2SignedUpdate> {
151
151
  // Deconstruct the verificationMethod
152
152
  const { id: fullId, controller, publicKeyMultibase, secretKeyMultibase } = verificationMethod;
153
153
 
@@ -169,7 +169,7 @@ export class Update {
169
169
  const keyUri = new CompressedSecp256k1PublicKey(components.genesisBytes).hex;
170
170
  const keys = secretKeyMultibase
171
171
  ? new SchnorrKeyPair({ secretKey: Secp256k1SecretKey.decode(secretKeyMultibase) })
172
- : await Kms.getKey(keyUri as string);
172
+ : Kms.getKey(keyUri as string);
173
173
  if (!keys) {
174
174
  throw new MethodError(
175
175
  'No privateKey found in kms or vm',
@@ -199,7 +199,13 @@ export class Update {
199
199
  // 7. Set proofOptions.proofPurpose to capabilityInvocation.
200
200
  // 8. Set proofOptions.capability to rootCapability.id.
201
201
  // 9. Set proofOptions.capabilityAction to Write.
202
- const options: ProofOptions = {
202
+ const config: DataIntegrityConfig = {
203
+ '@context' : [
204
+ 'https://w3id.org/security/v2',
205
+ 'https://w3id.org/zcap/v1',
206
+ 'https://w3id.org/json-ld-patch/v1',
207
+ 'https://btcr2.dev/context/v1'
208
+ ],
203
209
  cryptosuite,
204
210
  type : 'DataIntegrityProof',
205
211
  verificationMethod : fullId,
@@ -210,12 +216,12 @@ export class Update {
210
216
 
211
217
  // 10. Set cryptosuite to the result of executing the Cryptosuite Instantiation algorithm from the BIP340 Data
212
218
  // Integrity specification passing in proofOptions.
213
- const diproof = multikey.toCryptosuite(cryptosuite).toDataIntegrityProof();
219
+ const diproof = multikey.toCryptosuite().toDataIntegrityProof();
214
220
 
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 });
221
+ // 12. Set BTCR2SignedUpdate to the result of executing the Add Proof algorithm from VC Data Integrity passing
222
+ // BTCR2SignedUpdate as the input document, cryptosuite, and the set of proofOptions.
223
+ // 13. Return BTCR2SignedUpdate.
224
+ return await diproof.addProof(unsignedUpdate, config);
219
225
  }
220
226
 
221
227
  /**
@@ -223,30 +229,30 @@ export class Update {
223
229
  *
224
230
  * The Announce DID Update algorithm retrieves beaconServices from the sourceDocument and calls the Broadcast DID
225
231
  * 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.
232
+ * beaconIds, and a BTCR2SignedUpdate. It returns an array of signalsMetadata, containing the necessary
233
+ * data to validate the Beacon Signal against the BTCR2SignedUpdate.
228
234
  *
229
235
  * @param {AnnounceUpdatePayloadParams} params Required params for calling the announcePayload method
230
236
  * @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
237
+ * @param {string[]} params.beaconIds The BTCR2SignedUpdate object to be signed
238
+ * @param {BTCR2SignedUpdate} params.BTCR2SignedUpdate The verificationMethod object to be used for signing
239
+ * @returns {BTCR2SignedUpdate} The BTCR2SignedUpdate object containing data to validate the Beacon Signal
234
240
  * @throws {MethodError} if the beaconService type is invalid
235
241
  */
236
242
  public static async announce({
237
243
  sourceDocument,
238
244
  beaconIds,
239
- didUpdateInvocation
245
+ signedUpdate
240
246
  }: {
241
247
  sourceDocument: DidDocument;
242
248
  beaconIds: string[];
243
- didUpdateInvocation: DidUpdateInvocation;
244
- }): Promise<SignalsMetadata> {
249
+ signedUpdate: BTCR2SignedUpdate;
250
+ }): Promise<SidecarData> {
245
251
  // 1. Set beaconServices to an empty array.
246
252
  const beaconServices: BeaconService[] = [];
247
253
 
248
- // 2. signalMetadata to an empty array.
249
- let signalsMetadata;
254
+ // 2. sidecarData to an empty array.
255
+ let sidecarData: SidecarData | undefined;
250
256
 
251
257
  // 3. For beaconId in beaconIds:
252
258
  for (const beaconId of beaconIds) {
@@ -266,27 +272,28 @@ export class Update {
266
272
  for (const beaconService of beaconServices) {
267
273
  // 4.1 Set signalMetadata to null.
268
274
  // 4.2 If beaconService.type == SingletonBeacon:
269
- // 4.2.1 Set signalMetadata to the result of passing beaconService and didUpdateInvocation to the Broadcast
275
+ // 4.2.1 Set signalMetadata to the result of passing beaconService and BTCR2SignedUpdate to the Broadcast
270
276
  // 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
277
+ // 4.3 Else If beaconService.type == CASBeacon:
278
+ // 4.3.1 Set signalMetadata to the result of passing Identifier, beaconService and BTCR2SignedUpdate to
273
279
  // 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
280
+ // 4.4 Else If beaconService.type == SMTBeacon:
281
+ // 4.4.1 Set signalMetadata to the result of passing Identifier, beaconService and BTCR2SignedUpdate to
276
282
  // the Broadcast SMTAggregate Beacon Signal algorithm.
277
283
  // 4.5 Else:
278
284
  // 4.5.1 MUST throw invalidBeacon error.
279
- const beacon = BeaconFactory.establish(beaconService);
280
- signalsMetadata = await beacon.broadcastSignal(didUpdateInvocation);
285
+ // const beacon = BeaconFactory.establish(beaconService);
286
+ // sidecarData = await beacon.broadcastSignal(signedUpdate);
287
+ console.log('TODO: refactor this code', signedUpdate, beaconService);
281
288
  }
282
- if(!signalsMetadata) {
289
+ if(!sidecarData) {
283
290
  throw new MethodError(
284
- 'Invalid beacon: no signalsMetadata found',
291
+ 'Invalid beacon: no sidecarData found',
285
292
  INVALID_DID_DOCUMENT, { beaconServices }
286
293
  );
287
294
  }
288
- Logger.debug('signalsMetadata', signalsMetadata);
289
- // Return the signalsMetadata
290
- return signalsMetadata;
295
+
296
+ // Return the sidecarData
297
+ return sidecarData;
291
298
  }
292
299
  }