@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.
- package/dist/browser.js +715 -1445
- package/dist/browser.mjs +715 -1445
- package/dist/cjs/core/beacon/beacon.js +25 -0
- package/dist/cjs/core/beacon/beacon.js.map +1 -0
- package/dist/cjs/core/beacon/cas-beacon.js +20 -36
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/error.js +4 -4
- package/dist/cjs/core/beacon/error.js.map +1 -1
- package/dist/cjs/core/beacon/factory.js +5 -7
- package/dist/cjs/core/beacon/factory.js.map +1 -1
- package/dist/cjs/core/beacon/interfaces.js +1 -31
- package/dist/cjs/core/beacon/interfaces.js.map +1 -1
- package/dist/cjs/core/beacon/signal-discovery.js +183 -0
- package/dist/cjs/core/beacon/signal-discovery.js.map +1 -0
- package/dist/cjs/core/beacon/singleton.js +54 -81
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js +22 -39
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/utils.js +4 -9
- package/dist/cjs/core/beacon/utils.js.map +1 -1
- package/dist/cjs/core/resolve.js +87 -277
- package/dist/cjs/core/resolve.js.map +1 -1
- package/dist/cjs/core/update.js +62 -153
- package/dist/cjs/core/update.js.map +1 -1
- package/dist/cjs/did-btcr2.js +80 -75
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/utils/appendix.js +6 -15
- package/dist/cjs/utils/appendix.js.map +1 -1
- package/dist/cjs/utils/did-document-builder.js +5 -0
- package/dist/cjs/utils/did-document-builder.js.map +1 -1
- package/dist/cjs/utils/did-document.js +11 -14
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/esm/core/beacon/beacon.js +25 -0
- package/dist/esm/core/beacon/beacon.js.map +1 -0
- package/dist/esm/core/beacon/cas-beacon.js +20 -36
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/error.js +4 -4
- package/dist/esm/core/beacon/error.js.map +1 -1
- package/dist/esm/core/beacon/factory.js +5 -7
- package/dist/esm/core/beacon/factory.js.map +1 -1
- package/dist/esm/core/beacon/interfaces.js +1 -31
- package/dist/esm/core/beacon/interfaces.js.map +1 -1
- package/dist/esm/core/beacon/signal-discovery.js +183 -0
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -0
- package/dist/esm/core/beacon/singleton.js +54 -81
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +22 -39
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/beacon/utils.js +4 -9
- package/dist/esm/core/beacon/utils.js.map +1 -1
- package/dist/esm/core/resolve.js +87 -277
- package/dist/esm/core/resolve.js.map +1 -1
- package/dist/esm/core/update.js +62 -153
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +80 -75
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +3 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/utils/appendix.js +6 -15
- package/dist/esm/utils/appendix.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js +5 -0
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +11 -14
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +44 -0
- package/dist/types/core/beacon/beacon.d.ts.map +1 -0
- package/dist/types/core/beacon/cas-beacon.d.ts +19 -30
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/error.d.ts +2 -2
- package/dist/types/core/beacon/error.d.ts.map +1 -1
- package/dist/types/core/beacon/factory.d.ts +4 -6
- package/dist/types/core/beacon/factory.d.ts.map +1 -1
- package/dist/types/core/beacon/interfaces.d.ts +7 -46
- package/dist/types/core/beacon/interfaces.d.ts.map +1 -1
- package/dist/types/core/beacon/signal-discovery.d.ts +25 -0
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -0
- package/dist/types/core/beacon/singleton.d.ts +16 -29
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +21 -33
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/utils.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +1 -8
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolve.d.ts +27 -43
- package/dist/types/core/resolve.d.ts.map +1 -1
- package/dist/types/core/types.d.ts +21 -8
- package/dist/types/core/types.d.ts.map +1 -1
- package/dist/types/core/update.d.ts +30 -73
- package/dist/types/core/update.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +37 -44
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +3 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/utils/appendix.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +5 -0
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +16 -14
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/core/beacon/beacon.ts +58 -0
- package/src/core/beacon/cas-beacon.ts +30 -44
- package/src/core/beacon/error.ts +5 -6
- package/src/core/beacon/factory.ts +7 -9
- package/src/core/beacon/interfaces.ts +7 -64
- package/src/core/beacon/signal-discovery.ts +237 -0
- package/src/core/beacon/singleton.ts +74 -94
- package/src/core/beacon/smt-beacon.ts +32 -49
- package/src/core/beacon/utils.ts +16 -13
- package/src/core/interfaces.ts +1 -9
- package/src/core/resolve.ts +116 -360
- package/src/core/types.ts +25 -8
- package/src/core/update.ts +90 -235
- package/src/did-btcr2.ts +131 -95
- package/src/index.ts +8 -1
- package/src/utils/appendix.ts +8 -22
- package/src/utils/did-document-builder.ts +5 -0
- 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 {
|
|
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
|
-
/**
|
|
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
|
|
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
|
|
108
|
-
* @param {ResolutionOptions} 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 {
|
|
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(
|
|
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.
|
|
147
|
+
const sidecarData = Resolve.sidecarData(resolutionOptions.sidecar);
|
|
143
148
|
|
|
144
|
-
//
|
|
145
|
-
if(!resolutionOptions
|
|
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.
|
|
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.
|
|
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.
|
|
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/#
|
|
225
|
-
* See {@link
|
|
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
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
* @param
|
|
244
|
-
* @param {
|
|
245
|
-
* @param {
|
|
246
|
-
* @param {string
|
|
247
|
-
* @
|
|
248
|
-
* @
|
|
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
|
-
|
|
251
|
-
|
|
252
|
-
|
|
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
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
//
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
|
297
|
+
throw new UpdateError(
|
|
298
|
+
'Invalid verificationMethod: not found in source document',
|
|
299
|
+
INVALID_DID_DOCUMENT, {sourceDocument, verificationMethodId}
|
|
300
|
+
);
|
|
285
301
|
}
|
|
286
302
|
|
|
287
|
-
//
|
|
288
|
-
// 3.1 verificationMethod.type == Multikey
|
|
303
|
+
// Validate the verificationMethod is of type 'Multikey'
|
|
289
304
|
if (verificationMethod.type !== 'Multikey') {
|
|
290
|
-
throw new
|
|
305
|
+
throw new UpdateError(
|
|
306
|
+
'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
|
|
307
|
+
INVALID_DID_DOCUMENT, verificationMethod
|
|
308
|
+
);
|
|
291
309
|
}
|
|
292
310
|
|
|
293
|
-
//
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
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
|
-
//
|
|
300
|
-
|
|
301
|
-
|
|
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
|
-
//
|
|
304
|
-
//
|
|
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
|
-
//
|
|
308
|
-
return
|
|
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 {
|
|
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
|
-
|
|
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
|
-
|
|
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';
|
package/src/utils/appendix.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { HashBytes
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
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
|
|