@did-btcr2/method 0.25.3 → 0.26.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 (233) hide show
  1. package/dist/.tsbuildinfo +1 -0
  2. package/dist/browser.js +125307 -122227
  3. package/dist/browser.mjs +125266 -122186
  4. package/dist/cjs/index.js +5043 -43
  5. package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
  6. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +1 -1
  7. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +1 -1
  8. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +1 -1
  9. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +1 -1
  10. package/dist/esm/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +1 -1
  11. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +1 -1
  12. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +1 -1
  13. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +1 -1
  14. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +1 -1
  15. package/dist/esm/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +1 -1
  16. package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
  17. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +1 -2
  18. package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
  19. package/dist/esm/core/beacon/aggregation/coordinator.js.map +1 -1
  20. package/dist/esm/core/beacon/aggregation/participant.js.map +1 -1
  21. package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
  22. package/dist/esm/core/beacon/cas-beacon.js +6 -4
  23. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  24. package/dist/esm/core/beacon/signal-discovery.js +1 -1
  25. package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
  26. package/dist/esm/core/beacon/singleton-beacon.js +3 -3
  27. package/dist/esm/core/beacon/singleton-beacon.js.map +1 -1
  28. package/dist/esm/core/beacon/utils.js.map +1 -1
  29. package/dist/esm/core/identifier.js.map +1 -1
  30. package/dist/esm/core/resolver.js +41 -35
  31. package/dist/esm/core/resolver.js.map +1 -1
  32. package/dist/esm/core/update.js.map +1 -1
  33. package/dist/esm/did-btcr2.js +1 -1
  34. package/dist/esm/did-btcr2.js.map +1 -1
  35. package/dist/esm/utils/appendix.js +7 -6
  36. package/dist/esm/utils/appendix.js.map +1 -1
  37. package/dist/esm/utils/did-document-builder.js.map +1 -1
  38. package/dist/esm/utils/did-document.js +2 -2
  39. package/dist/esm/utils/did-document.js.map +1 -1
  40. package/dist/types/core/beacon/aggregation/cohort/index.d.ts +2 -2
  41. package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -1
  42. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts +10 -10
  43. package/dist/types/core/beacon/aggregation/cohort/messages/index.d.ts.map +1 -1
  44. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts +1 -1
  45. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.d.ts.map +1 -1
  46. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts +1 -1
  47. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.d.ts.map +1 -1
  48. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts +1 -1
  49. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.d.ts.map +1 -1
  50. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts +1 -1
  51. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/opt-in.d.ts.map +1 -1
  52. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts +1 -1
  53. package/dist/types/core/beacon/aggregation/cohort/messages/keygen/subscribe.d.ts.map +1 -1
  54. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts +1 -1
  55. package/dist/types/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.d.ts.map +1 -1
  56. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts +1 -1
  57. package/dist/types/core/beacon/aggregation/cohort/messages/sign/authorization-request.d.ts.map +1 -1
  58. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts +1 -1
  59. package/dist/types/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.d.ts.map +1 -1
  60. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts +1 -1
  61. package/dist/types/core/beacon/aggregation/cohort/messages/sign/request-signature.d.ts.map +1 -1
  62. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts +1 -1
  63. package/dist/types/core/beacon/aggregation/cohort/messages/sign/signature-authorization.d.ts.map +1 -1
  64. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts +4 -4
  65. package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -1
  66. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts +6 -6
  67. package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
  68. package/dist/types/core/beacon/aggregation/communication/factory.d.ts +1 -1
  69. package/dist/types/core/beacon/aggregation/communication/factory.d.ts.map +1 -1
  70. package/dist/types/core/beacon/aggregation/communication/service.d.ts +3 -3
  71. package/dist/types/core/beacon/aggregation/communication/service.d.ts.map +1 -1
  72. package/dist/types/core/beacon/aggregation/coordinator.d.ts +3 -3
  73. package/dist/types/core/beacon/aggregation/coordinator.d.ts.map +1 -1
  74. package/dist/types/core/beacon/aggregation/participant.d.ts +6 -6
  75. package/dist/types/core/beacon/aggregation/participant.d.ts.map +1 -1
  76. package/dist/types/core/beacon/aggregation/session/index.d.ts +2 -2
  77. package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -1
  78. package/dist/types/core/beacon/beacon.d.ts +5 -5
  79. package/dist/types/core/beacon/beacon.d.ts.map +1 -1
  80. package/dist/types/core/beacon/cas-beacon.d.ts +5 -5
  81. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  82. package/dist/types/core/beacon/factory.d.ts +2 -2
  83. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  84. package/dist/types/core/beacon/interfaces.d.ts +3 -3
  85. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  86. package/dist/types/core/beacon/signal-discovery.d.ts +3 -3
  87. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
  88. package/dist/types/core/beacon/singleton-beacon.d.ts +5 -5
  89. package/dist/types/core/beacon/singleton-beacon.d.ts.map +1 -1
  90. package/dist/types/core/beacon/smt-beacon.d.ts +5 -5
  91. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  92. package/dist/types/core/beacon/utils.d.ts +4 -4
  93. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  94. package/dist/types/core/identifier.d.ts +2 -2
  95. package/dist/types/core/identifier.d.ts.map +1 -1
  96. package/dist/types/core/interfaces.d.ts +2 -2
  97. package/dist/types/core/interfaces.d.ts.map +1 -1
  98. package/dist/types/core/resolver.d.ts +8 -8
  99. package/dist/types/core/resolver.d.ts.map +1 -1
  100. package/dist/types/core/types.d.ts +6 -5
  101. package/dist/types/core/types.d.ts.map +1 -1
  102. package/dist/types/core/update.d.ts +5 -5
  103. package/dist/types/core/update.d.ts.map +1 -1
  104. package/dist/types/did-btcr2.d.ts +6 -6
  105. package/dist/types/did-btcr2.d.ts.map +1 -1
  106. package/dist/types/utils/appendix.d.ts +7 -7
  107. package/dist/types/utils/appendix.d.ts.map +1 -1
  108. package/dist/types/utils/did-document-builder.d.ts +3 -2
  109. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  110. package/dist/types/utils/did-document.d.ts +3 -3
  111. package/dist/types/utils/did-document.d.ts.map +1 -1
  112. package/package.json +7 -6
  113. package/src/core/beacon/aggregation/cohort/index.ts +3 -2
  114. package/src/core/beacon/aggregation/cohort/messages/index.ts +10 -10
  115. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.ts +2 -1
  116. package/src/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.ts +2 -1
  117. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.ts +2 -1
  118. package/src/core/beacon/aggregation/cohort/messages/keygen/opt-in.ts +2 -1
  119. package/src/core/beacon/aggregation/cohort/messages/keygen/subscribe.ts +2 -1
  120. package/src/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.ts +2 -1
  121. package/src/core/beacon/aggregation/cohort/messages/sign/authorization-request.ts +2 -1
  122. package/src/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.ts +2 -1
  123. package/src/core/beacon/aggregation/cohort/messages/sign/request-signature.ts +2 -1
  124. package/src/core/beacon/aggregation/cohort/messages/sign/signature-authorization.ts +2 -1
  125. package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +5 -4
  126. package/src/core/beacon/aggregation/communication/adapter/nostr.ts +9 -7
  127. package/src/core/beacon/aggregation/communication/factory.ts +1 -1
  128. package/src/core/beacon/aggregation/communication/service.ts +3 -3
  129. package/src/core/beacon/aggregation/coordinator.ts +12 -8
  130. package/src/core/beacon/aggregation/participant.ts +12 -7
  131. package/src/core/beacon/aggregation/session/index.ts +3 -2
  132. package/src/core/beacon/beacon.ts +5 -5
  133. package/src/core/beacon/cas-beacon.ts +13 -9
  134. package/src/core/beacon/factory.ts +2 -2
  135. package/src/core/beacon/interfaces.ts +3 -3
  136. package/src/core/beacon/signal-discovery.ts +5 -4
  137. package/src/core/beacon/singleton-beacon.ts +8 -7
  138. package/src/core/beacon/smt-beacon.ts +5 -5
  139. package/src/core/beacon/utils.ts +6 -4
  140. package/src/core/identifier.ts +3 -2
  141. package/src/core/interfaces.ts +2 -2
  142. package/src/core/resolver.ts +59 -51
  143. package/src/core/types.ts +6 -5
  144. package/src/core/update.ts +11 -7
  145. package/src/did-btcr2.ts +12 -10
  146. package/src/utils/appendix.ts +14 -16
  147. package/src/utils/did-document-builder.ts +3 -2
  148. package/src/utils/did-document.ts +10 -8
  149. package/dist/cjs/core/beacon/aggregation/cohort/index.js +0 -237
  150. package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +0 -1
  151. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +0 -26
  152. package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +0 -1
  153. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js +0 -11
  154. package/dist/cjs/core/beacon/aggregation/cohort/messages/constants.js.map +0 -1
  155. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js +0 -98
  156. package/dist/cjs/core/beacon/aggregation/cohort/messages/index.js.map +0 -1
  157. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js +0 -31
  158. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-advert.js.map +0 -1
  159. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js +0 -29
  160. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/cohort-ready.js.map +0 -1
  161. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js +0 -27
  162. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in-accept.js.map +0 -1
  163. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js +0 -23
  164. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/opt-in.js.map +0 -1
  165. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js +0 -28
  166. package/dist/cjs/core/beacon/aggregation/cohort/messages/keygen/subscribe.js.map +0 -1
  167. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js +0 -29
  168. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/aggregated-nonce.js.map +0 -1
  169. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js +0 -30
  170. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/authorization-request.js.map +0 -1
  171. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js +0 -30
  172. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js.map +0 -1
  173. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js +0 -30
  174. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/request-signature.js.map +0 -1
  175. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js +0 -31
  176. package/dist/cjs/core/beacon/aggregation/cohort/messages/sign/signature-authorization.js.map +0 -1
  177. package/dist/cjs/core/beacon/aggregation/cohort/status.js +0 -8
  178. package/dist/cjs/core/beacon/aggregation/cohort/status.js.map +0 -1
  179. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +0 -121
  180. package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +0 -1
  181. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +0 -246
  182. package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +0 -1
  183. package/dist/cjs/core/beacon/aggregation/communication/error.js +0 -12
  184. package/dist/cjs/core/beacon/aggregation/communication/error.js.map +0 -1
  185. package/dist/cjs/core/beacon/aggregation/communication/factory.js +0 -21
  186. package/dist/cjs/core/beacon/aggregation/communication/factory.js.map +0 -1
  187. package/dist/cjs/core/beacon/aggregation/communication/service.js +0 -2
  188. package/dist/cjs/core/beacon/aggregation/communication/service.js.map +0 -1
  189. package/dist/cjs/core/beacon/aggregation/coordinator.js +0 -343
  190. package/dist/cjs/core/beacon/aggregation/coordinator.js.map +0 -1
  191. package/dist/cjs/core/beacon/aggregation/participant.js +0 -435
  192. package/dist/cjs/core/beacon/aggregation/participant.js.map +0 -1
  193. package/dist/cjs/core/beacon/aggregation/session/index.js +0 -244
  194. package/dist/cjs/core/beacon/aggregation/session/index.js.map +0 -1
  195. package/dist/cjs/core/beacon/aggregation/session/status.js +0 -11
  196. package/dist/cjs/core/beacon/aggregation/session/status.js.map +0 -1
  197. package/dist/cjs/core/beacon/beacon.js +0 -25
  198. package/dist/cjs/core/beacon/beacon.js.map +0 -1
  199. package/dist/cjs/core/beacon/cas-beacon.js +0 -152
  200. package/dist/cjs/core/beacon/cas-beacon.js.map +0 -1
  201. package/dist/cjs/core/beacon/error.js +0 -37
  202. package/dist/cjs/core/beacon/error.js.map +0 -1
  203. package/dist/cjs/core/beacon/factory.js +0 -29
  204. package/dist/cjs/core/beacon/factory.js.map +0 -1
  205. package/dist/cjs/core/beacon/interfaces.js +0 -2
  206. package/dist/cjs/core/beacon/interfaces.js.map +0 -1
  207. package/dist/cjs/core/beacon/signal-discovery.js +0 -183
  208. package/dist/cjs/core/beacon/signal-discovery.js.map +0 -1
  209. package/dist/cjs/core/beacon/singleton-beacon.js +0 -107
  210. package/dist/cjs/core/beacon/singleton-beacon.js.map +0 -1
  211. package/dist/cjs/core/beacon/smt-beacon.js +0 -39
  212. package/dist/cjs/core/beacon/smt-beacon.js.map +0 -1
  213. package/dist/cjs/core/beacon/utils.js +0 -163
  214. package/dist/cjs/core/beacon/utils.js.map +0 -1
  215. package/dist/cjs/core/identifier.js +0 -248
  216. package/dist/cjs/core/identifier.js.map +0 -1
  217. package/dist/cjs/core/interfaces.js +0 -2
  218. package/dist/cjs/core/interfaces.js.map +0 -1
  219. package/dist/cjs/core/resolver.js +0 -476
  220. package/dist/cjs/core/resolver.js.map +0 -1
  221. package/dist/cjs/core/types.js +0 -2
  222. package/dist/cjs/core/types.js.map +0 -1
  223. package/dist/cjs/core/update.js +0 -112
  224. package/dist/cjs/core/update.js.map +0 -1
  225. package/dist/cjs/did-btcr2.js +0 -193
  226. package/dist/cjs/did-btcr2.js.map +0 -1
  227. package/dist/cjs/index.js.map +0 -1
  228. package/dist/cjs/utils/appendix.js +0 -203
  229. package/dist/cjs/utils/appendix.js.map +0 -1
  230. package/dist/cjs/utils/did-document-builder.js +0 -60
  231. package/dist/cjs/utils/did-document-builder.js.map +0 -1
  232. package/dist/cjs/utils/did-document.js +0 -424
  233. package/dist/cjs/utils/did-document.js.map +0 -1
@@ -1,476 +0,0 @@
1
- import { getNetwork } from '@did-btcr2/bitcoin';
2
- import { canonicalHash, canonicalize, DateUtils, encode as encodeHash, decode as decodeHash, INVALID_DID_DOCUMENT, INVALID_DID_UPDATE, JSONPatch, JSONUtils, LATE_PUBLISHING_ERROR, ResolveError } from '@did-btcr2/common';
3
- import { BIP340Cryptosuite, BIP340DataIntegrityProof, SchnorrMultikey } from '@did-btcr2/cryptosuite';
4
- import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
5
- import { DidBtcr2 } from '../did-btcr2.js';
6
- import { Appendix } from '../utils/appendix.js';
7
- import { DidDocument, ID_PLACEHOLDER_VALUE } from '../utils/did-document.js';
8
- import { BeaconFactory } from './beacon/factory.js';
9
- import { BeaconUtils } from './beacon/utils.js';
10
- import { Identifier } from './identifier.js';
11
- /**
12
- * Different possible Resolver states representing phases in the resolution process.
13
- */
14
- var ResolverPhase;
15
- (function (ResolverPhase) {
16
- ResolverPhase["GenesisDocument"] = "GenesisDocument";
17
- ResolverPhase["BeaconDiscovery"] = "BeaconDiscovery";
18
- ResolverPhase["BeaconProcess"] = "BeaconProcess";
19
- ResolverPhase["ApplyUpdates"] = "ApplyUpdates";
20
- ResolverPhase["Complete"] = "Complete";
21
- })(ResolverPhase || (ResolverPhase = {}));
22
- /**
23
- * Sans-I/O state machine for did:btcr2 resolution.
24
- *
25
- * Created by {@link DidBtcr2.resolve} (the factory). The caller drives resolution
26
- * by repeatedly calling {@link resolve} and {@link provide}:
27
- *
28
- * ```typescript
29
- * const resolver = DidBtcr2.resolve(did, { sidecar });
30
- * let state = resolver.resolve();
31
- *
32
- * while (state.status === 'action-required') {
33
- * for (const need of state.needs) { ... fetch & provide ... }
34
- * state = resolver.resolve();
35
- * }
36
- * const { didDocument, metadata } = state.result;
37
- * ```
38
- *
39
- * The Resolver performs **zero I/O**. All external data (Bitcoin signals, CAS
40
- * data, genesis documents) flows through the advance/provide protocol.
41
- *
42
- * @class Resolver
43
- */
44
- export class Resolver {
45
- // --- Immutable inputs ---
46
- #didComponents;
47
- #versionId;
48
- #versionTime;
49
- /**
50
- * The specific phase the Resolver is current in.
51
- */
52
- #phase;
53
- #sidecarData;
54
- #currentDocument;
55
- #providedGenesisDocument = null;
56
- #beaconServicesSignals = new Map();
57
- #processedServices = new Set();
58
- #requestCache = new Set();
59
- #unsortedUpdates = [];
60
- #resolvedResponse = null;
61
- /**
62
- * @internal — Use {@link DidBtcr2.resolve} to create instances.
63
- */
64
- constructor(didComponents, sidecarData, currentDocument, options) {
65
- this.#didComponents = didComponents;
66
- this.#sidecarData = sidecarData;
67
- this.#currentDocument = currentDocument;
68
- this.#versionId = options?.versionId;
69
- this.#versionTime = options?.versionTime;
70
- // If a genesis document was provided (from sidecar), pre-seed it for validation
71
- if (options?.genesisDocument) {
72
- this.#providedGenesisDocument = options.genesisDocument;
73
- }
74
- // If current document was established by the factory, skip GenesisDocument phase
75
- this.#phase = currentDocument
76
- ? ResolverPhase.BeaconDiscovery
77
- : ResolverPhase.GenesisDocument;
78
- }
79
- /**
80
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-secp256k1-public-key | 7.2.d.1 if genesis bytes is a secp256k1 Public Key}.
81
- * @param {DidComponents} didComponents The decoded components of the did.
82
- * @returns {DidDocument} The resolved DID Document object.
83
- */
84
- static deterministic(didComponents) {
85
- // Deconstruct the bytes from the given components
86
- const genesisBytes = didComponents.genesisBytes;
87
- // Encode the did from the didComponents
88
- const did = Identifier.encode(genesisBytes, didComponents);
89
- // Construct a new CompressedSecp256k1PublicKey and deconstruct the publicKey and publicKeyMultibase
90
- const { multibase } = new CompressedSecp256k1PublicKey(genesisBytes);
91
- // Generate the service field for the DID Document
92
- const service = BeaconUtils.generateBeaconServices({
93
- id: did,
94
- publicKey: genesisBytes,
95
- network: getNetwork(didComponents.network),
96
- beaconType: 'SingletonBeacon'
97
- });
98
- return new DidDocument({
99
- id: did,
100
- verificationMethod: [{
101
- id: `${did}#initialKey`,
102
- type: 'Multikey',
103
- controller: did,
104
- publicKeyMultibase: multibase.encoded
105
- }],
106
- service
107
- });
108
- }
109
- /**
110
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#if-genesis_bytes-is-a-sha-256-hash | 7.2.d.2 if genesis_bytes is a SHA-256 Hash}.
111
- * @param {DidComponents} didComponents BTCR2 DID components used to resolve the DID Document
112
- * @param {object} genesisDocument The genesis document for resolving the DID Document.
113
- * @returns {DidDocument} The resolved DID Document object
114
- * @throws {ResolveError} InvalidDidDocument if not conformant to DID Core v1.1
115
- */
116
- static external(didComponents, genesisDocument) {
117
- // Encode the genesis bytes from the did components
118
- const genesisBytes = encodeHash(didComponents.genesisBytes);
119
- // Canonicalize and sha256 hash the currentDocument
120
- const genesisDocumentBytes = canonicalHash(genesisDocument);
121
- // If the genesisBytes do not match the hashBytes, throw an error
122
- if (genesisBytes !== genesisDocumentBytes) {
123
- throw new ResolveError(`Initial document mismatch: genesisBytes !== genesisDocumentBytes`, INVALID_DID_DOCUMENT, { genesisBytes, genesisDocumentBytes });
124
- }
125
- // Encode the did from the didComponents
126
- const did = Identifier.encode(decodeHash(genesisBytes), didComponents);
127
- // Replace the placeholder did with the did throughout the currentDocument.
128
- const currentDocument = JSON.parse(JSON.stringify(genesisDocument).replaceAll(ID_PLACEHOLDER_VALUE, did));
129
- // Return a W3C conformant DID Document
130
- return new DidDocument(currentDocument);
131
- }
132
- /**
133
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-sidecar-data | Process Sidecar Data}
134
- * @param {Sidecar} sidecar The sidecar data to process.
135
- * @returns {SidecarData} The processed sidecar data containing maps of updates, CAS announcements, and SMT proofs.
136
- */
137
- static sidecarData(sidecar = {}) {
138
- // BTCR2 Signed Updates map
139
- const updateMap = new Map();
140
- if (sidecar.updates?.length)
141
- for (const update of sidecar.updates) {
142
- updateMap.set(canonicalHash(update), update);
143
- }
144
- // CAS Announcements map
145
- const casMap = new Map();
146
- if (sidecar.casUpdates?.length)
147
- for (const update of sidecar.casUpdates) {
148
- casMap.set(canonicalHash(update), update);
149
- }
150
- // SMT Proofs map
151
- const smtMap = new Map();
152
- if (sidecar.smtProofs?.length)
153
- for (const proof of sidecar.smtProofs) {
154
- smtMap.set(proof.id, proof);
155
- }
156
- return { updateMap, casMap, smtMap };
157
- }
158
- /**
159
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process-updates | 7.2.f Process updates Array}.
160
- * @param {DidDocument} currentDocument The current DID Document to apply the updates to.
161
- * @param {Array<[SignedBTCR2Update, BlockMetadata]>} unsortedUpdates The unsorted array of BTCR2 Signed Updates and their associated Block Metadata.
162
- * @param {string} [versionTime] The optional version time to limit updates to.
163
- * @param {string} [versionId] The optional version id to limit updates to.
164
- * @returns {DidResolutionResponse} The updated DID Document, number of confirmations, and version id.
165
- */
166
- static updates(currentDocument, unsortedUpdates, versionTime, versionId) {
167
- // Start the version number being processed at 1
168
- let currentVersionId = 1;
169
- // Initialize an empty array to hold the update hashes
170
- const updateHashHistory = [];
171
- // 1. Sort updates by targetVersionId (ascending), using blockheight as tie-breaker
172
- const updates = unsortedUpdates.sort(([upd0, blk0], [upd1, blk1]) => upd0.targetVersionId - upd1.targetVersionId || blk0.height - blk1.height);
173
- // Create a default response object
174
- const response = {
175
- didDocument: currentDocument,
176
- metadata: {
177
- versionId: `${currentVersionId}`,
178
- confirmations: 0,
179
- updated: '',
180
- deactivated: currentDocument.deactivated || false
181
- }
182
- };
183
- // Iterate over each (update block) pair
184
- for (const [update, block] of updates) {
185
- // Get the hash of the current document
186
- const currentDocumentHash = canonicalHash(response.didDocument);
187
- // Safely convert block.time to timestamp
188
- const blocktime = DateUtils.blocktimeToTimestamp(block.time);
189
- // TODO: How to detect if block is unconfirmed and exit gracefully or return without it
190
- // Set the updated field to the blocktime of the current update
191
- response.metadata.updated = DateUtils.toISOStringNonFractional(blocktime);
192
- // Set confirmations to the block confirmations
193
- response.metadata.confirmations = block.confirmations;
194
- // if resolutionOptions.versionTime is defined and the blocktime is more recent, return currentDocument
195
- if (versionTime) {
196
- // Safely convert versionTime to timestamp
197
- if (blocktime > DateUtils.dateStringToTimestamp(versionTime)) {
198
- return response;
199
- }
200
- }
201
- // Check update.targetVersionId against currentVersionId
202
- // If update.targetVersionId <= currentVersionId, confirm duplicate update
203
- if (update.targetVersionId <= currentVersionId) {
204
- updateHashHistory.push(currentDocumentHash);
205
- this.confirmDuplicate(update, updateHashHistory);
206
- }
207
- // If update.targetVersionId == currentVersionId + 1, apply the update
208
- else if (update.targetVersionId === currentVersionId + 1) {
209
- // Check if update.sourceHash !== currentDocumentHash
210
- if (update.sourceHash !== currentDocumentHash) {
211
- // Raise an INVALID_DID_UPDATE error if they do not match
212
- throw new ResolveError(`Hash mismatch: update.sourceHash !== currentDocumentHash`, INVALID_DID_UPDATE, { sourceHash: update.sourceHash, currentDocumentHash });
213
- }
214
- // Apply the update to the currentDocument and set it in the response
215
- response.didDocument = this.applyUpdate(response.didDocument, update);
216
- // Create unsigned_update by removing the proof property from update.
217
- const unsignedUpdate = JSONUtils.deleteKeys(update, ['proof']);
218
- // Push the canonicalized unsigned update hash to the updateHashHistory
219
- updateHashHistory.push(canonicalHash(unsignedUpdate));
220
- }
221
- // If update.targetVersionId > currentVersionId + 1, throw LATE_PUBLISHING error
222
- else if (update.targetVersionId > currentVersionId + 1) {
223
- throw new ResolveError(`Version Id Mismatch: targetVersionId cannot be > currentVersionId + 1`, 'LATE_PUBLISHING_ERROR', {
224
- targetVersionId: update.targetVersionId,
225
- currentVersionId: currentVersionId + 1
226
- });
227
- }
228
- // Increment currentVersionId
229
- currentVersionId++;
230
- // Set response.versionId to be the new currentVersionId
231
- response.metadata.versionId = `${currentVersionId}`;
232
- // If resolutionOptions.versionId is defined and <= currentVersionId, return currentDocument
233
- const versionIdNumber = Number(versionId);
234
- if (!isNaN(versionIdNumber) && versionIdNumber <= currentVersionId) {
235
- return response;
236
- }
237
- // Check if the current document is deactivated before further processing
238
- if (response.didDocument.deactivated) {
239
- // Set the response deactivated flag to true
240
- response.metadata.deactivated = response.didDocument.deactivated;
241
- // If deactivated, stop processing further updates and return the response
242
- return response;
243
- }
244
- }
245
- // Return response data
246
- return response;
247
- }
248
- // ─── Private static: update internals ──────────────────────────────
249
- /**
250
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/#confirm-duplicate-update | 7.2.f.1 Confirm Duplicate Update}.
251
- * This step confirms that an update with a lower-than-expected targetVersionId is a true duplicate.
252
- * @param {SignedBTCR2Update} update The BTCR2 Signed Update to confirm as a duplicate.
253
- * @param {string[]} updateHashHistory The accumulated hash history for comparison.
254
- * @returns {void} Does not return a value, but throws an error if the update is not a valid duplicate.
255
- */
256
- static confirmDuplicate(update, updateHashHistory) {
257
- // Create unsigned_update by removing the proof property from update.
258
- const { proof: _, ...unsignedUpdate } = update;
259
- // Hash unsignedUpdate with JSON Document Hashing algorithm
260
- const unsignedUpdateHash = canonicalHash(unsignedUpdate);
261
- // Let historicalUpdateHash equal updateHashHistory[updateHashIndex].
262
- const historicalUpdateHash = updateHashHistory[update.targetVersionId - 2];
263
- // Check if the updateHash matches the historical hash
264
- if (updateHashHistory[update.targetVersionId - 2] !== unsignedUpdateHash) {
265
- throw new ResolveError(`Invalid duplicate: ${unsignedUpdateHash} does not match ${historicalUpdateHash}`, LATE_PUBLISHING_ERROR, { unsignedUpdateHash, updateHashHistory });
266
- }
267
- }
268
- /**
269
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#apply-update | 7.2.f.3 Apply Update}.
270
- * @param {DidDocument} currentDocument The current DID Document to apply the update to.
271
- * @param {SignedBTCR2Update} update The BTCR2 Signed Update to apply.
272
- * @returns {DidDocument} The updated DID Document after applying the update.
273
- * @throws {ResolveError} If the update is invalid or cannot be applied.
274
- */
275
- static applyUpdate(currentDocument, update) {
276
- // Get the capability id from the to update proof.
277
- const capabilityId = update.proof?.capability;
278
- // Since this field is optional, check that it exists
279
- if (!capabilityId) {
280
- // If it does not exist, throw INVALID_DID_UPDATE error
281
- throw new ResolveError('No root capability found in update', INVALID_DID_UPDATE, update);
282
- }
283
- // Get the root capability object by dereferencing the capabilityId
284
- const rootCapability = Appendix.dereferenceZcapId(capabilityId);
285
- // Deconstruct the invocationTarget and controller from the root capability
286
- const { invocationTarget, controller: rootController } = rootCapability;
287
- // Check that both invocationTarget and rootController equal currentDocument.id
288
- if (![invocationTarget, rootController].every((id) => id === currentDocument.id)) {
289
- // If they do not all match, throw INVALID_DID_UPDATE error
290
- throw new ResolveError('Invalid root capability', INVALID_DID_UPDATE, { rootCapability, currentDocument });
291
- }
292
- // Get the verificationMethod field from the update proof as verificationMethodId.
293
- const verificationMethodId = update.proof?.verificationMethod;
294
- // Since this field is optional, check that it exists
295
- if (!verificationMethodId) {
296
- // If it does not exist, throw INVALID_DID_UPDATE error
297
- throw new ResolveError('No verificationMethod found in update', INVALID_DID_UPDATE, update);
298
- }
299
- // Get the verificationMethod from the DID Document using the verificationMethodId.
300
- const vm = DidBtcr2.getSigningMethod(currentDocument, verificationMethodId);
301
- // Construct a new SchnorrMultikey.
302
- const multikey = SchnorrMultikey.fromVerificationMethod(vm);
303
- // Construct a new BIP340Cryptosuite with the SchnorrMultikey.
304
- const cryptosuite = new BIP340Cryptosuite(multikey);
305
- // Canonicalize the update
306
- const canonicalUpdate = canonicalize(update);
307
- // Construct a DataIntegrityProof with the cryptosuite
308
- const diProof = new BIP340DataIntegrityProof(cryptosuite);
309
- // Call the verifyProof method
310
- const verificationResult = diProof.verifyProof(canonicalUpdate, 'capabilityInvocation');
311
- // If the result is not verified, throw INVALID_DID_UPDATE error
312
- if (!verificationResult.verified) {
313
- throw new ResolveError('Invalid update: proof not verified', INVALID_DID_UPDATE, verificationResult);
314
- }
315
- // Apply the update.patch to the currentDocument to get the updatedDocument.
316
- const updatedDocument = JSONPatch.apply(currentDocument, update.patch);
317
- // Verify that updatedDocument is conformant to DID Core v1.1.
318
- DidDocument.validate(updatedDocument);
319
- // Canonicalize and hash the updatedDocument to get the currentDocumentHash.
320
- const currentDocumentHash = canonicalHash(updatedDocument);
321
- // Prepare the update targetHash for comparison with currentDocumentHash.
322
- const updateTargetHash = update.targetHash;
323
- // Make sure the update.targetHash equals currentDocumentHash.
324
- if (update.targetHash !== currentDocumentHash) {
325
- // If they do not match, throw INVALID_DID_UPDATE error.
326
- throw new ResolveError(`Invalid update: update.targetHash !== currentDocumentHash`, INVALID_DID_UPDATE, { updateTargetHash, currentDocumentHash });
327
- }
328
- // Return final updatedDocument.
329
- return updatedDocument;
330
- }
331
- // ─── Instance: state machine ───────────────────────────────────────
332
- /**
333
- * Advance the state machine. Returns either:
334
- * - `{ status: 'action-required', needs }` — caller must provide data via {@link provide}
335
- * - `{ status: 'resolved', result }` — resolution complete
336
- *
337
- * Analogous to Rust's `Resolver::resolve()`.
338
- */
339
- resolve() {
340
- // Internal loop — keeps advancing through phases until data is needed or done
341
- while (true) {
342
- switch (this.#phase) {
343
- // Phase: GenesisDocument
344
- // Only entered for EXTERNAL (x HRP) identifiers when genesis doc was not in sidecar.
345
- case ResolverPhase.GenesisDocument: {
346
- if (this.#providedGenesisDocument) {
347
- // Genesis doc was provided — establish the current document
348
- this.#currentDocument = Resolver.external(this.#didComponents, this.#providedGenesisDocument);
349
- this.#providedGenesisDocument = null;
350
- this.#phase = ResolverPhase.BeaconDiscovery;
351
- continue;
352
- }
353
- // Need genesis document from caller
354
- const genesisHash = encodeHash(this.#didComponents.genesisBytes);
355
- return {
356
- status: 'action-required',
357
- needs: [{ kind: 'NeedGenesisDocument', genesisHash }]
358
- };
359
- }
360
- // Phase: BeaconDiscovery
361
- // Extract beacon services, emit NeedBeaconSignals for addresses not yet queried.
362
- case ResolverPhase.BeaconDiscovery: {
363
- const beaconServices = BeaconUtils.getBeaconServices(this.#currentDocument);
364
- // Filter to services whose addresses haven't been requested yet
365
- const newServices = beaconServices.filter(service => {
366
- const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
367
- return !this.#requestCache.has(address);
368
- });
369
- if (newServices.length > 0) {
370
- // Mark addresses as requested so we don't re-request on subsequent rounds
371
- for (const service of newServices) {
372
- const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
373
- this.#requestCache.add(address);
374
- }
375
- return {
376
- status: 'action-required',
377
- needs: [{ kind: 'NeedBeaconSignals', beaconServices: newServices }]
378
- };
379
- }
380
- // No new beacon services to query — move to processing
381
- this.#phase = ResolverPhase.BeaconProcess;
382
- continue;
383
- }
384
- // Phase: BeaconProcess
385
- // Process each beacon's signals. Collect updates and data needs.
386
- case ResolverPhase.BeaconProcess: {
387
- const allNeeds = [];
388
- for (const [service, signals] of this.#beaconServicesSignals) {
389
- // Skip already-processed services and services with no signals
390
- if (this.#processedServices.has(service.id) || !signals.length)
391
- continue;
392
- // Establish a typed beacon and process its signals
393
- const beacon = BeaconFactory.establish(service);
394
- const result = beacon.processSignals(signals, this.#sidecarData);
395
- if (result.needs.length > 0) {
396
- // This service has unmet data needs — collect them
397
- allNeeds.push(...result.needs);
398
- }
399
- else {
400
- // All signals for this service resolved — collect updates, mark processed
401
- this.#unsortedUpdates.push(...result.updates);
402
- this.#processedServices.add(service.id);
403
- }
404
- }
405
- if (allNeeds.length > 0) {
406
- return { status: 'action-required', needs: allNeeds };
407
- }
408
- this.#phase = ResolverPhase.ApplyUpdates;
409
- continue;
410
- }
411
- // Phase: ApplyUpdates
412
- // Apply collected updates, then check for new beacon services (multi-round).
413
- case ResolverPhase.ApplyUpdates: {
414
- if (this.#unsortedUpdates.length > 0) {
415
- // Apply all collected updates to the current document
416
- this.#resolvedResponse = Resolver.updates(this.#currentDocument, this.#unsortedUpdates, this.#versionTime, this.#versionId);
417
- this.#currentDocument = this.#resolvedResponse.didDocument;
418
- this.#unsortedUpdates = [];
419
- // Check for new beacon services added by updates (multi-round discovery)
420
- const beaconServices = BeaconUtils.getBeaconServices(this.#currentDocument);
421
- const hasNewServices = beaconServices.some(service => {
422
- const address = BeaconUtils.parseBitcoinAddress(service.serviceEndpoint);
423
- return !this.#requestCache.has(address);
424
- });
425
- if (hasNewServices) {
426
- // Loop back to discover signals for new beacon services
427
- this.#phase = ResolverPhase.BeaconDiscovery;
428
- continue;
429
- }
430
- }
431
- this.#phase = ResolverPhase.Complete;
432
- continue;
433
- }
434
- // Phase: Complete
435
- case ResolverPhase.Complete: {
436
- return {
437
- status: 'resolved',
438
- result: this.#resolvedResponse ?? {
439
- didDocument: this.#currentDocument,
440
- metadata: {
441
- versionId: this.#versionId ?? '1',
442
- deactivated: this.#currentDocument.deactivated || false
443
- }
444
- }
445
- };
446
- }
447
- }
448
- }
449
- }
450
- provide(need, data) {
451
- switch (need.kind) {
452
- case 'NeedGenesisDocument': {
453
- this.#providedGenesisDocument = data;
454
- break;
455
- }
456
- case 'NeedBeaconSignals': {
457
- const signals = data;
458
- for (const [service, serviceSignals] of signals) {
459
- this.#beaconServicesSignals.set(service, serviceSignals);
460
- }
461
- break;
462
- }
463
- case 'NeedCASAnnouncement': {
464
- const announcement = data;
465
- this.#sidecarData.casMap.set(canonicalHash(announcement), announcement);
466
- break;
467
- }
468
- case 'NeedSignedUpdate': {
469
- const update = data;
470
- this.#sidecarData.updateMap.set(canonicalHash(update), update);
471
- break;
472
- }
473
- }
474
- }
475
- }
476
- //# sourceMappingURL=resolver.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"resolver.js","sourceRoot":"","sources":["../../../src/core/resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EACL,aAAa,EACb,YAAY,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O,EAAE,CAAC;oBAC/C,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;gBAC3D,CAAC;gBACD,MAAM;YACR,CAAC;YAED,KAAK,qBAAqB,CAAC,CAAC,CAAC;gBAC3B,MAAM,YAAY,GAAG,IAAuB,CAAC;gBAC7C,IAAI,CAAC,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,aAAa,CAAC,YAAY,CAAC,EAAE,YAAY,CAAC,CAAC;gBACxE,MAAM;YACR,CAAC;YAED,KAAK,kBAAkB,CAAC,CAAC,CAAC;gBACxB,MAAM,MAAM,GAAG,IAAyB,CAAC;gBACzC,IAAI,CAAC,YAAY,CAAC,SAAS,CAAC,GAAG,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;gBAC/D,MAAM;YACR,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/core/types.ts"],"names":[],"mappings":""}
@@ -1,112 +0,0 @@
1
- import { canonicalHash, INVALID_DID_UPDATE, JSONPatch, UpdateError } from '@did-btcr2/common';
2
- import { SchnorrMultikey } from '@did-btcr2/cryptosuite';
3
- import { DidDocument } from '../utils/did-document.js';
4
- import { BeaconFactory } from './beacon/factory.js';
5
- /**
6
- * Implements {@link https://dcdpr.github.io/did-btcr2/operations/update.html | 7.3 Update}.
7
- *
8
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD
9
- * data format, signed by a verificationMethod that has the authority to make
10
- * the update as specified in the previous DID document. Capability invocations
11
- * for updates MUST be authorized using Data Integrity following the
12
- * bip340-jcs-2025 cryptosuite with a proofPurpose of capabilityInvocation.
13
- *
14
- * @class Update
15
- * @type {Update}
16
- */
17
- export class Update {
18
- /**
19
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
20
- * This process constructs a BTCR2 Unsigned Update conformant to the spec template.
21
- *
22
- * @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
23
- * @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
24
- * @param {number} sourceVersionId The version ID of the source document.
25
- * @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
26
- * @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
27
- */
28
- static construct(sourceDocument, patches, sourceVersionId) {
29
- // Initialize an unsigned update conformant to btcr2 spec.
30
- const unsignedUpdate = {
31
- '@context': [
32
- 'https://w3id.org/security/v2',
33
- 'https://w3id.org/zcap/v1',
34
- 'https://w3id.org/json-ld-patch/v1',
35
- 'https://btcr2.dev/context/v1'
36
- ],
37
- patch: patches,
38
- targetHash: '',
39
- targetVersionId: sourceVersionId + 1,
40
- sourceHash: canonicalHash(sourceDocument),
41
- };
42
- // Apply all JSON patches to sourceDocument.
43
- const targetDocument = JSONPatch.apply(sourceDocument, patches);
44
- try {
45
- // Ensure the targetDocument is conformant to DID Core v1.1.
46
- DidDocument.isValid(targetDocument);
47
- }
48
- catch (error) {
49
- // If validation fails, throw an UpdateError with INVALID_DID_UPDATE.
50
- throw new UpdateError('Error validating targetDocument: ' + (error instanceof Error ? error.message : String(error)), INVALID_DID_UPDATE, targetDocument);
51
- }
52
- // Set the targetHash by canonicalizing the targetDocument and encoding it in base64url.
53
- unsignedUpdate.targetHash = canonicalHash(targetDocument);
54
- // Return unsignedUpdate.
55
- return unsignedUpdate;
56
- }
57
- /**
58
- * Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
59
- * This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
60
- *
61
- * @param {string} did The did-btcr2 identifier to derive the root capability from
62
- * @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
63
- * @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
64
- * @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
65
- * @throws {UpdateError} if the privateKeyBytes are invalid
66
- */
67
- static sign(did, unsignedUpdate, verificationMethod, secretKey) {
68
- // Parse the controller from the verificationMethod
69
- const controller = verificationMethod.controller;
70
- // Parse the fragment from the vmId
71
- const id = verificationMethod.id.slice(verificationMethod.id.indexOf('#'));
72
- // Construct a Schnorr Multikey
73
- const multikey = SchnorrMultikey.fromSecretKey(id, controller, secretKey);
74
- // Define the Data Integrity proof config
75
- const config = {
76
- '@context': [
77
- 'https://w3id.org/security/v2',
78
- 'https://w3id.org/zcap/v1',
79
- 'https://w3id.org/json-ld-patch/v1',
80
- 'https://btcr2.dev/context/v1'
81
- ],
82
- cryptosuite: 'bip340-jcs-2025',
83
- type: 'DataIntegrityProof',
84
- verificationMethod: verificationMethod.id,
85
- proofPurpose: 'capabilityInvocation',
86
- capability: `urn:zcap:root:${encodeURIComponent(did)}`,
87
- capabilityAction: 'Write',
88
- };
89
- // Go from multikey => cryptosuite => diproof
90
- const diproof = multikey.toCryptosuite().toDataIntegrityProof();
91
- // Use the config to add a proof to the unsigned update
92
- return diproof.addProof(unsignedUpdate, config);
93
- }
94
- /**
95
- * Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
96
- * BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
97
- * @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
98
- * @param {SignedBTCR2Update} update The signed update object to be announced.
99
- * @param {KeyBytes} secretKey The private key used to sign the update for announcement.
100
- * @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
101
- * @throws {UpdateError} if the beaconService type is invalid
102
- */
103
- static async announce(beaconService, update, secretKey, bitcoin) {
104
- // Establish a beacon object
105
- const beacon = BeaconFactory.establish(beaconService);
106
- // Broadcast the update
107
- const result = await beacon.broadcastSignal(update, secretKey, bitcoin);
108
- // Return the sidecarData
109
- return result;
110
- }
111
- }
112
- //# sourceMappingURL=update.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"update.js","sourceRoot":"","sources":["../../../src/core/update.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,SAAS,EAGT,WAAW,EACZ,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAEL,eAAe,EAGhB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAoB,WAAW,EAAyB,MAAM,0BAA0B,CAAC;AAChG,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD;;;;;;;;;;;GAWG;AACH,MAAM,OAAO,MAAM;IACjB;;;;;;;;;OASG;IACH,MAAM,CAAC,SAAS,CACd,cAAgC,EAChC,OAAyB,EACzB,eAAuB;QAEvB,0DAA0D;QAC1D,MAAM,cAAc,GAAwB;YAC1C,UAAU,EAAQ;gBAChB,8BAA8B;gBAC9B,0BAA0B;gBAC1B,mCAAmC;gBACnC,8BAA8B;aAC/B;YACD,KAAK,EAAa,OAAO;YACzB,UAAU,EAAQ,EAAE;YACpB,eAAe,EAAG,eAAe,GAAG,CAAC;YACrC,UAAU,EAAQ,aAAa,CAAC,cAAc,CAAC;SAChD,CAAC;QAEF,4CAA4C;QAC5C,MAAM,cAAc,GAAG,SAAS,CAAC,KAAK,CAAC,cAAc,EAAE,OAAO,CAAC,CAAC;QAEhE,IAAI,CAAC;YACH,4DAA4D;YAC5D,WAAW,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QACtC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,qEAAqE;YACrE,MAAM,IAAI,WAAW,CACnB,mCAAmC,GAAG,CAAC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAC9F,kBAAk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