@did-btcr2/method 0.19.0 → 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 (119) hide show
  1. package/dist/browser.js +715 -1445
  2. package/dist/browser.mjs +715 -1445
  3. package/dist/cjs/core/beacon/beacon.js +25 -0
  4. package/dist/cjs/core/beacon/beacon.js.map +1 -0
  5. package/dist/cjs/core/beacon/cas-beacon.js +20 -36
  6. package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
  7. package/dist/cjs/core/beacon/error.js +4 -4
  8. package/dist/cjs/core/beacon/error.js.map +1 -1
  9. package/dist/cjs/core/beacon/factory.js +5 -7
  10. package/dist/cjs/core/beacon/factory.js.map +1 -1
  11. package/dist/cjs/core/beacon/interfaces.js +1 -31
  12. package/dist/cjs/core/beacon/interfaces.js.map +1 -1
  13. package/dist/cjs/core/beacon/signal-discovery.js +183 -0
  14. package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
  15. package/dist/cjs/core/beacon/singleton.js +54 -81
  16. package/dist/cjs/core/beacon/singleton.js.map +1 -1
  17. package/dist/cjs/core/beacon/smt-beacon.js +22 -39
  18. package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
  19. package/dist/cjs/core/beacon/utils.js +4 -9
  20. package/dist/cjs/core/beacon/utils.js.map +1 -1
  21. package/dist/cjs/core/resolve.js +87 -277
  22. package/dist/cjs/core/resolve.js.map +1 -1
  23. package/dist/cjs/core/update.js +62 -153
  24. package/dist/cjs/core/update.js.map +1 -1
  25. package/dist/cjs/did-btcr2.js +80 -75
  26. package/dist/cjs/did-btcr2.js.map +1 -1
  27. package/dist/cjs/index.js +3 -1
  28. package/dist/cjs/index.js.map +1 -1
  29. package/dist/cjs/utils/appendix.js +6 -15
  30. package/dist/cjs/utils/appendix.js.map +1 -1
  31. package/dist/cjs/utils/did-document-builder.js +5 -0
  32. package/dist/cjs/utils/did-document-builder.js.map +1 -1
  33. package/dist/cjs/utils/did-document.js +11 -14
  34. package/dist/cjs/utils/did-document.js.map +1 -1
  35. package/dist/esm/core/beacon/beacon.js +25 -0
  36. package/dist/esm/core/beacon/beacon.js.map +1 -0
  37. package/dist/esm/core/beacon/cas-beacon.js +20 -36
  38. package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
  39. package/dist/esm/core/beacon/error.js +4 -4
  40. package/dist/esm/core/beacon/error.js.map +1 -1
  41. package/dist/esm/core/beacon/factory.js +5 -7
  42. package/dist/esm/core/beacon/factory.js.map +1 -1
  43. package/dist/esm/core/beacon/interfaces.js +1 -31
  44. package/dist/esm/core/beacon/interfaces.js.map +1 -1
  45. package/dist/esm/core/beacon/signal-discovery.js +183 -0
  46. package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
  47. package/dist/esm/core/beacon/singleton.js +54 -81
  48. package/dist/esm/core/beacon/singleton.js.map +1 -1
  49. package/dist/esm/core/beacon/smt-beacon.js +22 -39
  50. package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
  51. package/dist/esm/core/beacon/utils.js +4 -9
  52. package/dist/esm/core/beacon/utils.js.map +1 -1
  53. package/dist/esm/core/resolve.js +87 -277
  54. package/dist/esm/core/resolve.js.map +1 -1
  55. package/dist/esm/core/update.js +62 -153
  56. package/dist/esm/core/update.js.map +1 -1
  57. package/dist/esm/did-btcr2.js +80 -75
  58. package/dist/esm/did-btcr2.js.map +1 -1
  59. package/dist/esm/index.js +3 -1
  60. package/dist/esm/index.js.map +1 -1
  61. package/dist/esm/utils/appendix.js +6 -15
  62. package/dist/esm/utils/appendix.js.map +1 -1
  63. package/dist/esm/utils/did-document-builder.js +5 -0
  64. package/dist/esm/utils/did-document-builder.js.map +1 -1
  65. package/dist/esm/utils/did-document.js +11 -14
  66. package/dist/esm/utils/did-document.js.map +1 -1
  67. package/dist/types/core/beacon/beacon.d.ts +44 -0
  68. package/dist/types/core/beacon/beacon.d.ts.map +1 -0
  69. package/dist/types/core/beacon/cas-beacon.d.ts +19 -30
  70. package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
  71. package/dist/types/core/beacon/error.d.ts +2 -2
  72. package/dist/types/core/beacon/error.d.ts.map +1 -1
  73. package/dist/types/core/beacon/factory.d.ts +4 -6
  74. package/dist/types/core/beacon/factory.d.ts.map +1 -1
  75. package/dist/types/core/beacon/interfaces.d.ts +7 -46
  76. package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
  77. package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
  78. package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
  79. package/dist/types/core/beacon/singleton.d.ts +16 -29
  80. package/dist/types/core/beacon/singleton.d.ts.map +1 -1
  81. package/dist/types/core/beacon/smt-beacon.d.ts +21 -33
  82. package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
  83. package/dist/types/core/beacon/utils.d.ts.map +1 -1
  84. package/dist/types/core/interfaces.d.ts +1 -8
  85. package/dist/types/core/interfaces.d.ts.map +1 -1
  86. package/dist/types/core/resolve.d.ts +27 -43
  87. package/dist/types/core/resolve.d.ts.map +1 -1
  88. package/dist/types/core/types.d.ts +21 -8
  89. package/dist/types/core/types.d.ts.map +1 -1
  90. package/dist/types/core/update.d.ts +30 -73
  91. package/dist/types/core/update.d.ts.map +1 -1
  92. package/dist/types/did-btcr2.d.ts +37 -44
  93. package/dist/types/did-btcr2.d.ts.map +1 -1
  94. package/dist/types/index.d.ts +3 -1
  95. package/dist/types/index.d.ts.map +1 -1
  96. package/dist/types/utils/appendix.d.ts.map +1 -1
  97. package/dist/types/utils/did-document-builder.d.ts +5 -0
  98. package/dist/types/utils/did-document-builder.d.ts.map +1 -1
  99. package/dist/types/utils/did-document.d.ts +16 -14
  100. package/dist/types/utils/did-document.d.ts.map +1 -1
  101. package/package.json +4 -4
  102. package/src/core/beacon/beacon.ts +58 -0
  103. package/src/core/beacon/cas-beacon.ts +30 -44
  104. package/src/core/beacon/error.ts +5 -6
  105. package/src/core/beacon/factory.ts +7 -9
  106. package/src/core/beacon/interfaces.ts +7 -64
  107. package/src/core/beacon/signal-discovery.ts +237 -0
  108. package/src/core/beacon/singleton.ts +74 -94
  109. package/src/core/beacon/smt-beacon.ts +32 -49
  110. package/src/core/beacon/utils.ts +16 -13
  111. package/src/core/interfaces.ts +1 -9
  112. package/src/core/resolve.ts +116 -360
  113. package/src/core/types.ts +25 -8
  114. package/src/core/update.ts +90 -235
  115. package/src/did-btcr2.ts +131 -95
  116. package/src/index.ts +8 -1
  117. package/src/utils/appendix.ts +8 -22
  118. package/src/utils/did-document-builder.ts +5 -0
  119. package/src/utils/did-document.ts +41 -45
package/src/did-btcr2.ts CHANGED
@@ -2,15 +2,19 @@ import { BitcoinNetworkConnection } from '@did-btcr2/bitcoin';
2
2
  import {
3
3
  Canonicalization,
4
4
  DocumentBytes,
5
+ HexString,
5
6
  IdentifierHrp,
6
7
  INVALID_DID_DOCUMENT,
8
+ INVALID_DID_UPDATE,
7
9
  KeyBytes,
8
10
  METHOD_NOT_SUPPORTED,
9
11
  MethodError,
10
12
  MISSING_UPDATE_DATA,
11
13
  PatchOperation,
12
- ResolveError
14
+ ResolveError,
15
+ UpdateError
13
16
  } from '@did-btcr2/common';
17
+ import { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
14
18
  import {
15
19
  Did,
16
20
  DidError,
@@ -21,16 +25,16 @@ import {
21
25
  } from '@web5/dids';
22
26
  import { initEccLib } from 'bitcoinjs-lib';
23
27
  import * as tinysecp from 'tiny-secp256k1';
28
+ import { BeaconService } from './core/beacon/interfaces.js';
24
29
  import { BeaconUtils } from './core/beacon/utils.js';
25
30
  import { Identifier } from './core/identifier.js';
26
31
  import { ResolutionOptions } from './core/interfaces.js';
27
32
  import { Resolve } from './core/resolve.js';
28
- import { SidecarData } from './core/types.js';
29
33
  import { Update } from './core/update.js';
30
34
  import { Appendix } from './utils/appendix.js';
31
- import { DidDocument, DidVerificationMethod } from './utils/did-document.js';
35
+ import { Btcr2DidDocument, DidVerificationMethod } from './utils/did-document.js';
32
36
 
33
- // TODO: convert to API driver
37
+ // TODO: convert to API driver?
34
38
  export const canonicalization = new Canonicalization();
35
39
 
36
40
  export type Btcr2Identifier = string;
@@ -44,7 +48,7 @@ export interface DidCreateOptions {
44
48
  network?: string;
45
49
  }
46
50
 
47
- // TODO: convert to API driver
51
+ // TODO: convert to API driver?
48
52
  /** Initialize tiny secp256k1 */
49
53
  initEccLib(tinysecp);
50
54
 
@@ -62,7 +66,9 @@ initEccLib(tinysecp);
62
66
  * @implements {DidMethod}
63
67
  */
64
68
  export class DidBtcr2 implements DidMethod {
65
- /** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
69
+ /**
70
+ * Name of the DID method, as defined in the DID BTCR2 specification
71
+ */
66
72
  static methodName: string = 'btcr2';
67
73
 
68
74
  /**
@@ -95,7 +101,7 @@ export class DidBtcr2 implements DidMethod {
95
101
  }
96
102
 
97
103
  /**
98
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Resolve}.
104
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html | 7.2 Resolve}.
99
105
  * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
100
106
  * See {@link Resolve | Resolve (class)} for class implementation.
101
107
  *
@@ -104,14 +110,10 @@ export class DidBtcr2 implements DidMethod {
104
110
  * blockchain by Authorized Beacon Signals. The Initial DID Document is either
105
111
  * deterministically created from the DID or provided by Sidecar Data.
106
112
  *
107
- * @param {string} did a valid did:btcr2 identifier to be resolved
108
- * @param {ResolutionOptions} resolutionOptions see {@link https://www.w3.org/TR/did-1.0/#did-resolution-options | ResolutionOptions}
109
- * @param {number} resolutionOptions.versionId optional version of the identifier and/or DID document
110
- * @param {number} resolutionOptions.versionTime optional timestamp used during resolution as a bound for when to stop resolving
111
- * @param {DidDocument} resolutionOptions.sidecar optional data necessary for resolving a DID
113
+ * @param {string} did The did:btcr2 identifier to be resolved.
114
+ * @param {ResolutionOptions} resolutionOptions Options used during the resolution process.
112
115
  * @returns {Promise<DidResolutionResult>} Promise resolving to a DID Resolution Result containing the `targetDocument`
113
- * @throws {Error} if the resolution fails for any reason
114
- * @throws {DidError} InvalidDid if the identifier is invalid
116
+ * @throws {ResolveError} If the resolution process fails at any step.
115
117
  * @example
116
118
  * ```ts
117
119
  * const resolution = await DidBtcr2.resolve(
@@ -119,7 +121,10 @@ export class DidBtcr2 implements DidMethod {
119
121
  * )
120
122
  * ```
121
123
  */
122
- static async resolve(did: string, resolutionOptions: ResolutionOptions = {drivers: {}}): Promise<DidResolutionResult> {
124
+ static async resolve(
125
+ did: string,
126
+ resolutionOptions: ResolutionOptions = { drivers: {} }
127
+ ): Promise<DidResolutionResult> {
123
128
  try {
124
129
 
125
130
  // Initialize an empty DID Resolution Result
@@ -139,10 +144,13 @@ export class DidBtcr2 implements DidMethod {
139
144
  const didComponents = Identifier.decode(did);
140
145
 
141
146
  // Process sidecar if provided
142
- const sidecarData = Resolve.processSidecarData(resolutionOptions.sidecar);
147
+ const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
143
148
 
144
- // Establish a connection to a bitcoin network
145
- if(!resolutionOptions.drivers.bitcoin) {
149
+ // Check if bitcoin driver provided
150
+ if(!resolutionOptions?.drivers?.bitcoin) {
151
+ // If not, initialize default drivers
152
+ resolutionOptions.drivers = resolutionOptions.drivers || {};
153
+ // Set bitcoin driver to default BitcoinNetworkConnection
146
154
  resolutionOptions.drivers.bitcoin = new BitcoinNetworkConnection();
147
155
  // Set the network based on the decoded identifier
148
156
  resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
@@ -161,20 +169,22 @@ export class DidBtcr2 implements DidMethod {
161
169
  }
162
170
 
163
171
  // Establish the current document
164
- const currentDocument = await Resolve.establishCurrentDocument(didComponents, genesisDocument);
172
+ const currentDocument = await Resolve.currentDocument(didComponents, genesisDocument);
165
173
 
166
174
  // Extract all Beacon services from the current DID Document
167
175
  const beaconServices = currentDocument.service
168
176
  .filter(BeaconUtils.isBeaconService)
169
177
  .map(BeaconUtils.parseBeaconServiceEndpoint);
170
178
 
179
+ console.log('beaconServices', beaconServices);
180
+
171
181
  // Process the Beacon Signals to get the required updates
172
- const unsortedUpdates = await Resolve.processBeaconSignals(
182
+ const unsortedUpdates = await Resolve.beaconSignals(
173
183
  beaconServices,
174
184
  sidecarData,
175
- resolutionOptions.drivers.bitcoin,
176
- resolutionOptions.fullBlockchainTraversal
185
+ resolutionOptions.drivers.bitcoin
177
186
  );
187
+ console.log('unsortedUpdates', unsortedUpdates);
178
188
 
179
189
  // If no updates found, return the current document
180
190
  if(!unsortedUpdates.length) {
@@ -189,7 +199,7 @@ export class DidBtcr2 implements DidMethod {
189
199
  }
190
200
 
191
201
  // Process the updates to apply updates to bring the current DID Document to its more current state
192
- const result = await Resolve.processUpdatesArray(
202
+ const result = await Resolve.updates(
193
203
  currentDocument,
194
204
  unsortedUpdates,
195
205
  resolutionOptions.versionTime,
@@ -221,92 +231,118 @@ export class DidBtcr2 implements DidMethod {
221
231
  }
222
232
 
223
233
  /**
224
- * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#update | 4.3 Update}.
225
- * See {@link Update} for implementation details.
226
- *
227
- * An update to a did:btcr2 document is an invoked capability using the ZCAP-LD data format, signed by a
228
- * verificationMethod that has the authority to make the update as specified in the previous DID document. Capability
229
- * invocations for updates MUST be authorized using Data Integrity following the bip340-jcs-2025
230
- * cryptosuite with a proofPurpose of capabilityInvocation.
231
- *
232
- * The Update algorithm takes as inputs a Identifier, sourceDocument, sourceVersionId, documentPatch, a
233
- * verificationMethodId and an array of beaconIds. The sourceDocument is the DID document being updated. The
234
- * documentPatch is a JSON Patch object containing a set of transformations to be applied to the sourceDocument.
235
- * The result of these transformations MUST produce a DID document conformant to the DID Core specification. The
236
- * verificationMethodId is an identifier for a verificationMethod within the sourceDocument. The verificationMethod
237
- * identified MUST be a BIP340 Multikey. The beaconIds MUST identify service endpoints with one of the three Beacon
238
- * Types SingletonBeacon, CASBeacon, and SMTBeacon.
234
+ * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.3 Update}.
235
+ * See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
236
+ * See {@link Update | Update (class)} for class implementation.
239
237
  *
240
- * @param {UpdateParams} params Required parameters for the update operation.
241
- * @param {string} params.identifier The btcr2 identifier to be updated.
242
- * @param {DidDocument} params.sourceDocument The DID document being updated.
243
- * @param {string} params.sourceVersionId The versionId of the source document.
244
- * @param {PatchOperation} params.documentPatch The JSON patch to be applied to the source document.
245
- * @param {string} params.verificationMethodId The verificationMethod ID to sign the update
246
- * @param {string[]} params.beaconIds The beacon IDs to announce the update
247
- * @returns {Promise<void>} Promise resolving to void
248
- * @throws {MethodError} if the verificationMethod type is not `Multikey` or the publicKeyMultibase header is not `zQ3s`
238
+ * BTCR2 DID documents can be updated by anchoring BTCR2 Updates to Bitcoin transactions. These transactions MAY be
239
+ * published to the Bitcoin network. Any property in the DID document may be updated except the id. Doing so would
240
+ * invalidate the DID document.
241
+ * @param params An object containing the parameters for the update operation.
242
+ * @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
243
+ * @param {PatchOperation[]} params.patches The array of JSON Patch operations to apply to the sourceDocument.
244
+ * @param {string} params.sourceVersionId The version ID before applying the update.
245
+ * @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
246
+ * @param {string} params.beaconId The beacon ID associated with the update.
247
+ * @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
248
+ * @param {BitcoinNetworkConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
249
+ * @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
250
+ * @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
251
+ * header is not `zQ3s`
249
252
  */
250
- public static async update(params: {
251
- identifier: string;
252
- sourceDocument: DidDocument;
253
+ static async update({
254
+ sourceDocument,
255
+ patches,
256
+ sourceVersionId,
257
+ verificationMethodId,
258
+ beaconId,
259
+ signingMaterial,
260
+ bitcoin,
261
+ }: {
262
+ sourceDocument: Btcr2DidDocument;
263
+ patches: PatchOperation[];
253
264
  sourceVersionId: number;
254
- patch: PatchOperation[];
255
265
  verificationMethodId: string;
256
- beaconIds: string[];
257
- }): Promise<SidecarData> {
258
- // Deconstruct the params
259
- const {
260
- identifier,
261
- sourceDocument,
262
- sourceVersionId,
263
- patch,
264
- verificationMethodId: methodId,
265
- beaconIds,
266
- } = params;
267
-
268
- // 1. Set unsignedUpdate to the result of passing Identifier, sourceDocument,
269
- // sourceVersionId, and documentPatch into the Construct DID Update
270
- // Payload algorithm.
271
- const unsignedUpdate = await Update.construct({
272
- identifier,
273
- sourceDocument,
274
- sourceVersionId,
275
- patch,
276
- });
277
-
278
- // 2. Set verificationMethod to the result of retrieving the verificationMethod
279
- // from sourceDocument using the verificationMethodId.
280
- const verificationMethod = this.getSigningMethod(sourceDocument, methodId);
266
+ beaconId: string;
267
+ signingMaterial?: KeyBytes | HexString;
268
+ bitcoin?: BitcoinNetworkConnection;
269
+ }): Promise<SignedBTCR2Update> {
270
+ // TODO: provide KMS as alternative
271
+ // If no signingMaterial provided, throw an UpdateError with INVALID_DID_UPDATE.
272
+ if (!signingMaterial) {
273
+ throw new UpdateError(
274
+ 'Missing signing material for update',
275
+ INVALID_DID_UPDATE, {signingMaterial}
276
+ );
277
+ }
278
+
279
+ // Convert signingMaterial to bytes if it's a hex string
280
+ const secretKey = typeof signingMaterial === 'string'
281
+ ? Buffer.from(signingMaterial, 'hex')
282
+ : signingMaterial;
283
+
284
+ // Validate that the verificationMethodId is authorized for capabilityInvocation
285
+ if(!sourceDocument.capabilityInvocation?.some(vr => vr === verificationMethodId)) {
286
+ throw new UpdateError(
287
+ 'Invalid verificationMethodId: not authorized for capabilityInvocation',
288
+ INVALID_DID_DOCUMENT, sourceDocument
289
+ );
290
+ }
291
+
292
+ // Get the verification method to be used for signing the update
293
+ const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
281
294
 
282
295
  // Validate the verificationMethod exists in the sourceDocument
283
296
  if (!verificationMethod) {
284
- throw new MethodError('Verification method not found in did document', INVALID_DID_DOCUMENT, sourceDocument);
297
+ throw new UpdateError(
298
+ 'Invalid verificationMethod: not found in source document',
299
+ INVALID_DID_DOCUMENT, {sourceDocument, verificationMethodId}
300
+ );
285
301
  }
286
302
 
287
- // 3. Validate the verificationMethod is a BIP340 Multikey:
288
- // 3.1 verificationMethod.type == Multikey
303
+ // Validate the verificationMethod is of type 'Multikey'
289
304
  if (verificationMethod.type !== 'Multikey') {
290
- throw new MethodError('Invalid type: must be type "Multikey"', INVALID_DID_DOCUMENT, verificationMethod);
305
+ throw new UpdateError(
306
+ 'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
307
+ INVALID_DID_DOCUMENT, verificationMethod
308
+ );
291
309
  }
292
310
 
293
- // 3.2 verificationMethod.publicKeyMultibase[4] == zQ3s
294
- const mbasePrefix = verificationMethod.publicKeyMultibase?.slice(0, 4);
295
- if (mbasePrefix !== 'zQ3s') {
296
- throw new MethodError(`Invalid publicKeyMultibase prefix ${mbasePrefix}`, INVALID_DID_DOCUMENT, verificationMethod);
311
+ // Validate the publicKeyMultibase prefix is 'zQ3s'
312
+ if (verificationMethod.publicKeyMultibase?.slice(0, 4) !== 'zQ3s') {
313
+ throw new UpdateError(
314
+ 'Invalid verificationMethodId: publicKeyMultibase prefix must start with "zQ3s"',
315
+ INVALID_DID_DOCUMENT, verificationMethod
316
+ );
297
317
  }
298
318
 
299
- // 4. Set didUpdateInvocation to the result of passing Identifier, unsignedUpdate as didUpdatePayload, and
300
- // verificationMethod to the Invoke DID Update Payload algorithm.
301
- const signedUpdate = await Update.invoke({ identifier, verificationMethod, unsignedUpdate });
319
+ // Construct an unsigned update following the BTCR2 Update construction algorithm
320
+ const update = await Update.construct(sourceDocument, patches, sourceVersionId);
321
+
322
+ // Sign the unsigned update using the specified verification method
323
+ const signed = await Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
324
+
325
+ // Filter sourceDocument services to get beaconServices matching beaconIds
326
+ const beaconService = sourceDocument.service
327
+ .filter((service: BeaconService) => service.id === beaconId)
328
+ .filter((service: BeaconService): service is BeaconService => !!service)
329
+ .shift();
330
+
331
+ // If no matching beacon service found, throw an UpdateError with INVALID_DID_UPDATE.
332
+ if(!beaconService) {
333
+ throw new UpdateError(
334
+ 'No beacon service found for provided beaconId',
335
+ INVALID_DID_UPDATE, {sourceDocument, beaconId}
336
+ );
337
+ }
338
+ // If no bitcoin network connection provided, initialize default
339
+ bitcoin ??= new BitcoinNetworkConnection();
302
340
 
303
- // 5. Set signalsMetadata to the result of passing Identifier, sourceDocument, beaconIds and didUpdateInvocation
304
- // to the Announce DID Update algorithm.
305
- const signalsMetadata = await Update.announce({ sourceDocument, beaconIds, signedUpdate });
341
+ // Announce the signed update to the blockchain using the specified beacon(s)
342
+ // await Update.announce(beaconService, signed, secretKey, bitcoin);
306
343
 
307
- // 6. Return signalsMetadata. It is up to implementations to ensure that the signalsMetadata is persisted.
308
- return signalsMetadata;
309
- // TODO: Should we be applying the patch, producing a target did document and returning it?
344
+ // Return signed update if announced successfully
345
+ return signed;
310
346
  }
311
347
 
312
348
  /**
@@ -314,12 +350,12 @@ export class DidBtcr2 implements DidMethod {
314
350
  * for signing messages and credentials. If given, the `methodId` parameter is used to select the
315
351
  * verification method. If not given, the Identity Key's verification method with an ID fragment
316
352
  * of '#initialKey' is used.
317
- * @param {DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
353
+ * @param {Btcr2DidDocument} didDocument The DID Document of the `did:btcr2` identifier.
318
354
  * @param {string} [methodId] Optional verification method ID to be used for signing.
319
355
  * @returns {DidVerificationMethod} Promise resolving to the {@link DidVerificationMethod} object used for signing.
320
356
  * @throws {DidError} if the parsed did method does not match `btcr2` or signing method could not be determined.
321
357
  */
322
- public static getSigningMethod(didDocument: DidDocument, methodId?: string): DidVerificationMethod {
358
+ static getSigningMethod(didDocument: Btcr2DidDocument, methodId?: string): DidVerificationMethod {
323
359
  // Set the default methodId to the first assertionMethod if not given
324
360
  methodId ??= '#initialKey';
325
361
 
package/src/index.ts CHANGED
@@ -1,4 +1,6 @@
1
1
  export * from './core/beacon/aggregation/cohort/index.js';
2
+ export * from './core/beacon/aggregation/cohort/status.js';
3
+
2
4
  export * from './core/beacon/aggregation/cohort/messages/base.js';
3
5
  export * from './core/beacon/aggregation/cohort/messages/constants.js';
4
6
  export * from './core/beacon/aggregation/cohort/messages/index.js';
@@ -12,20 +14,25 @@ export * from './core/beacon/aggregation/cohort/messages/sign/authorization-requ
12
14
  export * from './core/beacon/aggregation/cohort/messages/sign/nonce-contribution.js';
13
15
  export * from './core/beacon/aggregation/cohort/messages/sign/request-signature.js';
14
16
  export * from './core/beacon/aggregation/cohort/messages/sign/signature-authorization.js';
15
- export * from './core/beacon/aggregation/cohort/status.js';
17
+
16
18
  export * from './core/beacon/aggregation/communication/adapter/did-comm.js';
17
19
  export * from './core/beacon/aggregation/communication/adapter/nostr.js';
20
+
18
21
  export * from './core/beacon/aggregation/communication/error.js';
19
22
  export * from './core/beacon/aggregation/communication/factory.js';
20
23
  export * from './core/beacon/aggregation/communication/service.js';
24
+
21
25
  export * from './core/beacon/aggregation/coordinator.js';
22
26
  export * from './core/beacon/aggregation/participant.js';
23
27
  export * from './core/beacon/aggregation/session/index.js';
24
28
  export * from './core/beacon/aggregation/session/status.js';
29
+
30
+ export * from './core/beacon/beacon.js';
25
31
  export * from './core/beacon/cas-beacon.js';
26
32
  export * from './core/beacon/error.js';
27
33
  export * from './core/beacon/factory.js';
28
34
  export * from './core/beacon/interfaces.js';
35
+ export * from './core/beacon/signal-discovery.js';
29
36
  export * from './core/beacon/singleton.js';
30
37
  export * from './core/beacon/smt-beacon.js';
31
38
  export * from './core/beacon/utils.js';
@@ -1,4 +1,4 @@
1
- import { HashBytes, W3C_ZCAP_V1 } from '@did-btcr2/common';
1
+ import { HashBytes } from '@did-btcr2/common';
2
2
  import { strings } from '@helia/strings';
3
3
  import {
4
4
  DidDocument,
@@ -109,27 +109,13 @@ export class Appendix {
109
109
  * }
110
110
  * ```
111
111
  */
112
- public static deriveRootCapability(identifier: string): RootCapability {
113
- // 1. Define rootCapability as an empty object.
114
- const rootCapability = {} as RootCapability;
115
-
116
- // 2. Set rootCapability.@context to ‘https://w3id.org/zcap/v1’.
117
- rootCapability['@context'] = W3C_ZCAP_V1;
118
-
119
- // 3. Set encodedIdentifier to result of calling algorithm encodeURIComponent(identifier).
120
- const encodedIdentifier = encodeURIComponent(identifier);
121
-
122
- // 4. Set rootCapability.id to urn:zcap:root:${encodedIdentifier}.
123
- rootCapability.id = `urn:zcap:root:${encodedIdentifier}`;
124
-
125
- // 5. Set rootCapability.controller to identifier.
126
- rootCapability.controller = identifier;
127
-
128
- // 6. Set rootCapability.invocationTarget to identifier.
129
- rootCapability.invocationTarget = identifier;
130
-
131
- // 7. Return rootCapability.
132
- return rootCapability;
112
+ static deriveRootCapability(identifier: string): RootCapability {
113
+ return {
114
+ '@context' : 'https://w3id.org/zcap/v1',
115
+ id : `urn:zcap:root:${encodeURIComponent(identifier)}`,
116
+ controller : identifier,
117
+ invocationTarget : identifier,
118
+ };
133
119
  }
134
120
 
135
121
 
@@ -2,6 +2,11 @@ import { DidDocumentError, INVALID_DID_DOCUMENT } from '@did-btcr2/common';
2
2
  import { BeaconService } from '../core/beacon/interfaces.js';
3
3
  import { DidDocument, DidVerificationMethod } from './did-document.js';
4
4
 
5
+ /**
6
+ * A builder class for constructing DID Documents.
7
+ * @type {DidDocumentBuilder}
8
+ * @class DidDocumentBuilder
9
+ */
5
10
  export class DidDocumentBuilder {
6
11
  private document: Partial<DidDocument> = {};
7
12