@did-btcr2/method 0.27.0 → 0.28.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/README.md +38 -9
- package/dist/.tsbuildinfo +1 -1
- package/dist/browser.js +194 -62
- package/dist/browser.mjs +194 -62
- package/dist/cjs/index.js +201 -68
- package/dist/esm/core/aggregation/runner/participant-runner.js +4 -0
- package/dist/esm/core/aggregation/runner/participant-runner.js.map +1 -1
- package/dist/esm/core/updater.js +269 -0
- package/dist/esm/core/updater.js.map +1 -0
- package/dist/esm/did-btcr2.js +30 -42
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/index.js +2 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/types/core/aggregation/runner/participant-runner.d.ts +4 -0
- package/dist/types/core/aggregation/runner/participant-runner.d.ts.map +1 -1
- package/dist/types/core/updater.d.ts +178 -0
- package/dist/types/core/updater.d.ts.map +1 -0
- package/dist/types/did-btcr2.d.ts +23 -23
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/index.d.ts +2 -1
- package/dist/types/index.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/core/aggregation/runner/participant-runner.ts +4 -0
- package/src/core/updater.ts +415 -0
- package/src/did-btcr2.ts +36 -66
- package/src/index.ts +2 -1
- package/dist/esm/core/update.js +0 -112
- package/dist/esm/core/update.js.map +0 -1
- package/dist/types/core/update.d.ts +0 -52
- package/dist/types/core/update.d.ts.map +0 -1
- package/src/core/update.ts +0 -158
package/src/did-btcr2.ts
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import type { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
2
1
|
import type {
|
|
3
2
|
DocumentBytes,
|
|
4
|
-
HexString,
|
|
5
3
|
KeyBytes,
|
|
6
4
|
PatchOperation} from '@did-btcr2/common';
|
|
7
5
|
import {
|
|
@@ -12,7 +10,6 @@ import {
|
|
|
12
10
|
MethodError,
|
|
13
11
|
UpdateError
|
|
14
12
|
} from '@did-btcr2/common';
|
|
15
|
-
import type { SignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
16
13
|
import type {
|
|
17
14
|
DidMethod} from '@web5/dids';
|
|
18
15
|
import {
|
|
@@ -21,13 +18,12 @@ import {
|
|
|
21
18
|
DidErrorCode
|
|
22
19
|
} from '@web5/dids';
|
|
23
20
|
import * as ecc from '@bitcoinerlab/secp256k1';
|
|
24
|
-
import { hexToBytes } from '@noble/hashes/utils';
|
|
25
21
|
import { initEccLib } from 'bitcoinjs-lib';
|
|
26
22
|
import type { BeaconService } from './core/beacon/interfaces.js';
|
|
27
23
|
import { Identifier } from './core/identifier.js';
|
|
28
24
|
import type { ResolutionOptions } from './core/interfaces.js';
|
|
29
25
|
import { Resolver } from './core/resolver.js';
|
|
30
|
-
import {
|
|
26
|
+
import { Updater } from './core/updater.js';
|
|
31
27
|
import { Appendix } from './utils/appendix.js';
|
|
32
28
|
import type { Btcr2DidDocument, DidVerificationMethod } from './utils/did-document.js';
|
|
33
29
|
|
|
@@ -140,55 +136,41 @@ export class DidBtcr2 implements DidMethod {
|
|
|
140
136
|
}
|
|
141
137
|
|
|
142
138
|
/**
|
|
143
|
-
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#
|
|
144
|
-
* See specification for the {@link https://dcdpr.github.io/did-btcr2/operations/resolve.html#process | Resolve Process}.
|
|
145
|
-
* See {@link Update | Update (class)} for class implementation.
|
|
139
|
+
* Entry point for section {@link https://dcdpr.github.io/did-btcr2/#update | 7.3 Update}.
|
|
146
140
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
141
|
+
* Factory method that validates the update parameters and returns a sans-I/O
|
|
142
|
+
* {@link Updater} state machine. The caller drives the updater through its
|
|
143
|
+
* phases (Construct → Sign → Broadcast → Complete) by calling `advance()` and
|
|
144
|
+
* `provide()`. The method package performs **zero I/O** — signing key retrieval
|
|
145
|
+
* (or KMS delegation) and the on-chain broadcast are the caller's responsibility.
|
|
146
|
+
*
|
|
147
|
+
* For a fully-wired version with Bitcoin broadcast and key handling, see
|
|
148
|
+
* `DidMethodApi.update()` in `@did-btcr2/api`.
|
|
149
|
+
*
|
|
150
|
+
* @param params Update construction parameters.
|
|
151
151
|
* @param {Btcr2DidDocument} params.sourceDocument The DID document being updated.
|
|
152
|
-
* @param {PatchOperation[]} params.patches The
|
|
153
|
-
* @param {
|
|
154
|
-
* @param {string} params.verificationMethodId The
|
|
155
|
-
* @param {string} params.beaconId The beacon ID
|
|
156
|
-
* @
|
|
157
|
-
* @
|
|
158
|
-
*
|
|
159
|
-
*
|
|
160
|
-
* header is not `zQ3s`
|
|
152
|
+
* @param {PatchOperation[]} params.patches The JSON Patch operations to apply.
|
|
153
|
+
* @param {number} params.sourceVersionId The version ID before applying the update.
|
|
154
|
+
* @param {string} params.verificationMethodId The verification method ID to sign with.
|
|
155
|
+
* @param {string} params.beaconId The beacon service ID to broadcast through.
|
|
156
|
+
* @returns {Updater} A sans-I/O state machine for driving the update.
|
|
157
|
+
* @throws {UpdateError} If the verification method is not authorized, not found,
|
|
158
|
+
* not of type `Multikey`, or does not have a `zQ3s` publicKeyMultibase prefix.
|
|
159
|
+
* Also throws if the beacon service is not found.
|
|
161
160
|
*/
|
|
162
|
-
static
|
|
161
|
+
static update({
|
|
163
162
|
sourceDocument,
|
|
164
163
|
patches,
|
|
165
164
|
sourceVersionId,
|
|
166
165
|
verificationMethodId,
|
|
167
166
|
beaconId,
|
|
168
|
-
signingMaterial,
|
|
169
|
-
bitcoin,
|
|
170
167
|
}: {
|
|
171
168
|
sourceDocument: Btcr2DidDocument;
|
|
172
169
|
patches: PatchOperation[];
|
|
173
170
|
sourceVersionId: number;
|
|
174
171
|
verificationMethodId: string;
|
|
175
172
|
beaconId: string;
|
|
176
|
-
|
|
177
|
-
bitcoin?: BitcoinConnection;
|
|
178
|
-
}): Promise<SignedBTCR2Update> {
|
|
179
|
-
// If no signingMaterial provided, throw an UpdateError with INVALID_DID_UPDATE.
|
|
180
|
-
if (!signingMaterial) {
|
|
181
|
-
throw new UpdateError(
|
|
182
|
-
'Missing signing material for update',
|
|
183
|
-
INVALID_DID_UPDATE, {signingMaterial}
|
|
184
|
-
);
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
// Convert signingMaterial to bytes if it's a hex string
|
|
188
|
-
const secretKey = typeof signingMaterial === 'string'
|
|
189
|
-
? hexToBytes(signingMaterial)
|
|
190
|
-
: signingMaterial;
|
|
191
|
-
|
|
173
|
+
}): Updater {
|
|
192
174
|
// Validate that the verificationMethodId is authorized for capabilityInvocation
|
|
193
175
|
if(!sourceDocument.capabilityInvocation?.some(vr => vr === verificationMethodId)) {
|
|
194
176
|
throw new UpdateError(
|
|
@@ -201,15 +183,15 @@ export class DidBtcr2 implements DidMethod {
|
|
|
201
183
|
const verificationMethod = this.getSigningMethod(sourceDocument, verificationMethodId);
|
|
202
184
|
|
|
203
185
|
// Validate the verificationMethod exists in the sourceDocument
|
|
204
|
-
if
|
|
186
|
+
if(!verificationMethod) {
|
|
205
187
|
throw new UpdateError(
|
|
206
188
|
'Invalid verificationMethod: not found in source document',
|
|
207
|
-
INVALID_DID_DOCUMENT, {sourceDocument, verificationMethodId}
|
|
189
|
+
INVALID_DID_DOCUMENT, { sourceDocument, verificationMethodId }
|
|
208
190
|
);
|
|
209
191
|
}
|
|
210
192
|
|
|
211
193
|
// Validate the verificationMethod is of type 'Multikey'
|
|
212
|
-
if
|
|
194
|
+
if(verificationMethod.type !== 'Multikey') {
|
|
213
195
|
throw new UpdateError(
|
|
214
196
|
'Invalid verificationMethod: verificationMethod.type must be "Multikey"',
|
|
215
197
|
INVALID_DID_DOCUMENT, verificationMethod
|
|
@@ -217,46 +199,34 @@ export class DidBtcr2 implements DidMethod {
|
|
|
217
199
|
}
|
|
218
200
|
|
|
219
201
|
// Validate the publicKeyMultibase prefix is 'zQ3s'
|
|
220
|
-
if
|
|
202
|
+
if(verificationMethod.publicKeyMultibase?.slice(0, 4) !== 'zQ3s') {
|
|
221
203
|
throw new UpdateError(
|
|
222
204
|
'Invalid verificationMethodId: publicKeyMultibase prefix must start with "zQ3s"',
|
|
223
205
|
INVALID_DID_DOCUMENT, verificationMethod
|
|
224
206
|
);
|
|
225
207
|
}
|
|
226
208
|
|
|
227
|
-
//
|
|
228
|
-
const update = Update.construct(sourceDocument, patches, sourceVersionId);
|
|
229
|
-
|
|
230
|
-
// Sign the unsigned update using the specified verification method
|
|
231
|
-
const signed = Update.sign(sourceDocument.id, update, verificationMethod, secretKey);
|
|
232
|
-
|
|
233
|
-
// Filter sourceDocument services to get beaconServices matching beaconIds
|
|
209
|
+
// Find the beacon service matching the given beaconId
|
|
234
210
|
const beaconService = sourceDocument.service
|
|
235
211
|
.filter((service: BeaconService) => service.id === beaconId)
|
|
236
212
|
.filter((service: BeaconService): service is BeaconService => !!service)
|
|
237
213
|
.shift();
|
|
238
214
|
|
|
239
|
-
// If no matching beacon service found, throw an UpdateError with INVALID_DID_UPDATE.
|
|
240
215
|
if(!beaconService) {
|
|
241
216
|
throw new UpdateError(
|
|
242
217
|
'No beacon service found for provided beaconId',
|
|
243
|
-
INVALID_DID_UPDATE, {sourceDocument, beaconId}
|
|
218
|
+
INVALID_DID_UPDATE, { sourceDocument, beaconId }
|
|
244
219
|
);
|
|
245
220
|
}
|
|
246
|
-
// Require an explicit bitcoin connection — no silent env-var fallback
|
|
247
|
-
if (!bitcoin) {
|
|
248
|
-
throw new UpdateError(
|
|
249
|
-
'Bitcoin connection required for update. Pass a configured `bitcoin` parameter '
|
|
250
|
-
+ 'or use DidBtcr2Api which injects it automatically.',
|
|
251
|
-
INVALID_DID_UPDATE, { beaconId }
|
|
252
|
-
);
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
// Announce the signed update to the blockchain using the specified beacon(s)
|
|
256
|
-
await Update.announce(beaconService, signed, secretKey, bitcoin);
|
|
257
221
|
|
|
258
|
-
// Return
|
|
259
|
-
return
|
|
222
|
+
// Return a sans-I/O state machine the caller will drive
|
|
223
|
+
return new Updater({
|
|
224
|
+
sourceDocument,
|
|
225
|
+
patches,
|
|
226
|
+
sourceVersionId,
|
|
227
|
+
verificationMethod,
|
|
228
|
+
beaconService,
|
|
229
|
+
});
|
|
260
230
|
}
|
|
261
231
|
|
|
262
232
|
/**
|
package/src/index.ts
CHANGED
|
@@ -14,6 +14,7 @@ export * from './core/beacon/beacon.js';
|
|
|
14
14
|
export * from './core/beacon/cas-beacon.js';
|
|
15
15
|
export * from './core/beacon/error.js';
|
|
16
16
|
export * from './core/beacon/factory.js';
|
|
17
|
+
export * from './core/beacon/fee-estimator.js';
|
|
17
18
|
export * from './core/beacon/interfaces.js';
|
|
18
19
|
export * from './core/beacon/signal-discovery.js';
|
|
19
20
|
export * from './core/beacon/singleton-beacon.js';
|
|
@@ -25,7 +26,7 @@ export * from './core/identifier.js';
|
|
|
25
26
|
export * from './core/interfaces.js';
|
|
26
27
|
export * from './core/resolver.js';
|
|
27
28
|
export * from './core/types.js';
|
|
28
|
-
export * from './core/
|
|
29
|
+
export * from './core/updater.js';
|
|
29
30
|
|
|
30
31
|
// Utils
|
|
31
32
|
export * from './utils/appendix.js';
|
package/dist/esm/core/update.js
DELETED
|
@@ -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":"AAGA,OAAO,E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O,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import type { KeyBytes, PatchOperation } from '@did-btcr2/common';
|
|
2
|
-
import type { SignedBTCR2Update, UnsignedBTCR2Update } from '@did-btcr2/cryptosuite';
|
|
3
|
-
import type { Btcr2DidDocument, DidVerificationMethod } from '../utils/did-document.js';
|
|
4
|
-
import type { BeaconService } from './beacon/interfaces.js';
|
|
5
|
-
import type { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
6
|
-
/**
|
|
7
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/operations/update.html | 7.3 Update}.
|
|
8
|
-
*
|
|
9
|
-
* An update to a did:btcr2 document is an invoked capability using the ZCAP-LD
|
|
10
|
-
* data format, signed by a verificationMethod that has the authority to make
|
|
11
|
-
* the update as specified in the previous DID document. Capability invocations
|
|
12
|
-
* for updates MUST be authorized using Data Integrity following the
|
|
13
|
-
* bip340-jcs-2025 cryptosuite with a proofPurpose of capabilityInvocation.
|
|
14
|
-
*
|
|
15
|
-
* @class Update
|
|
16
|
-
* @type {Update}
|
|
17
|
-
*/
|
|
18
|
-
export declare class Update {
|
|
19
|
-
/**
|
|
20
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
|
|
21
|
-
* This process constructs a BTCR2 Unsigned Update conformant to the spec template.
|
|
22
|
-
*
|
|
23
|
-
* @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
|
|
24
|
-
* @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
|
|
25
|
-
* @param {number} sourceVersionId The version ID of the source document.
|
|
26
|
-
* @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
|
|
27
|
-
* @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
|
|
28
|
-
*/
|
|
29
|
-
static construct(sourceDocument: Btcr2DidDocument, patches: PatchOperation[], sourceVersionId: number): UnsignedBTCR2Update;
|
|
30
|
-
/**
|
|
31
|
-
* Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
|
|
32
|
-
* This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
|
|
33
|
-
*
|
|
34
|
-
* @param {string} did The did-btcr2 identifier to derive the root capability from
|
|
35
|
-
* @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
|
|
36
|
-
* @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
|
|
37
|
-
* @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
|
|
38
|
-
* @throws {UpdateError} if the privateKeyBytes are invalid
|
|
39
|
-
*/
|
|
40
|
-
static sign(did: string, unsignedUpdate: UnsignedBTCR2Update, verificationMethod: DidVerificationMethod, secretKey: KeyBytes): SignedBTCR2Update;
|
|
41
|
-
/**
|
|
42
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
|
|
43
|
-
* BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
|
|
44
|
-
* @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
|
|
45
|
-
* @param {SignedBTCR2Update} update The signed update object to be announced.
|
|
46
|
-
* @param {KeyBytes} secretKey The private key used to sign the update for announcement.
|
|
47
|
-
* @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
|
|
48
|
-
* @throws {UpdateError} if the beaconService type is invalid
|
|
49
|
-
*/
|
|
50
|
-
static announce(beaconService: BeaconService, update: SignedBTCR2Update, secretKey: KeyBytes, bitcoin: BitcoinConnection): Promise<SignedBTCR2Update>;
|
|
51
|
-
}
|
|
52
|
-
//# sourceMappingURL=update.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"update.d.ts","sourceRoot":"","sources":["../../../src/core/update.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,EACR,cAAc,EAAC,MAAM,mBAAmB,CAAC;AAO3C,OAAO,KAAK,EAEV,iBAAiB,EACjB,mBAAmB,EACpB,MAAM,wBAAwB,CAAC;AAIhC,OAAO,KAAK,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAGxF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;;;;;;;;;;GAWG;AACH,qBAAa,MAAM;IACjB;;;;;;;;;OASG;IACH,MAAM,CAAC,SAAS,CACd,cAAc,EAAE,gBAAgB,EAChC,OAAO,EAAE,cAAc,EAAE,EACzB,eAAe,EAAE,MAAM,GACtB,mBAAmB;IAoCtB;;;;;;;;;OASG;IACH,MAAM,CAAC,IAAI,CACT,GAAG,EAAE,MAAM,EACX,cAAc,EAAE,mBAAmB,EACnC,kBAAkB,EAAE,qBAAqB,EACzC,SAAS,EAAE,QAAQ,GAClB,iBAAiB;IAgCpB;;;;;;;;OAQG;WACU,QAAQ,CACnB,aAAa,EAAE,aAAa,EAC5B,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,QAAQ,EACnB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,iBAAiB,CAAC;CAU9B"}
|
package/src/core/update.ts
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
KeyBytes,
|
|
3
|
-
PatchOperation} from '@did-btcr2/common';
|
|
4
|
-
import {
|
|
5
|
-
canonicalHash,
|
|
6
|
-
INVALID_DID_UPDATE,
|
|
7
|
-
JSONPatch,
|
|
8
|
-
UpdateError
|
|
9
|
-
} from '@did-btcr2/common';
|
|
10
|
-
import type {
|
|
11
|
-
DataIntegrityConfig,
|
|
12
|
-
SignedBTCR2Update,
|
|
13
|
-
UnsignedBTCR2Update
|
|
14
|
-
} from '@did-btcr2/cryptosuite';
|
|
15
|
-
import {
|
|
16
|
-
SchnorrMultikey
|
|
17
|
-
} from '@did-btcr2/cryptosuite';
|
|
18
|
-
import type { Btcr2DidDocument, DidVerificationMethod } from '../utils/did-document.js';
|
|
19
|
-
import { DidDocument } from '../utils/did-document.js';
|
|
20
|
-
import { BeaconFactory } from './beacon/factory.js';
|
|
21
|
-
import type { BeaconService } from './beacon/interfaces.js';
|
|
22
|
-
import type { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Implements {@link https://dcdpr.github.io/did-btcr2/operations/update.html | 7.3 Update}.
|
|
26
|
-
*
|
|
27
|
-
* An update to a did:btcr2 document is an invoked capability using the ZCAP-LD
|
|
28
|
-
* data format, signed by a verificationMethod that has the authority to make
|
|
29
|
-
* the update as specified in the previous DID document. Capability invocations
|
|
30
|
-
* for updates MUST be authorized using Data Integrity following the
|
|
31
|
-
* bip340-jcs-2025 cryptosuite with a proofPurpose of capabilityInvocation.
|
|
32
|
-
*
|
|
33
|
-
* @class Update
|
|
34
|
-
* @type {Update}
|
|
35
|
-
*/
|
|
36
|
-
export class Update {
|
|
37
|
-
/**
|
|
38
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-unsigned-update | 7.3.b Construct BTCR2 Unsigned Update}.
|
|
39
|
-
* This process constructs a BTCR2 Unsigned Update conformant to the spec template.
|
|
40
|
-
*
|
|
41
|
-
* @param {Btcr2DidDocument} sourceDocument The source DID document to be updated.
|
|
42
|
-
* @param {PatchOperation[]} patches The array of JSON Patch operations to apply to the sourceDocument.
|
|
43
|
-
* @param {number} sourceVersionId The version ID of the source document.
|
|
44
|
-
* @returns {UnsignedBTCR2Update} The constructed UnsignedBTCR2Update object.
|
|
45
|
-
* @throws {UpdateError} InvalidDid if sourceDocument.id does not match identifier.
|
|
46
|
-
*/
|
|
47
|
-
static construct(
|
|
48
|
-
sourceDocument: Btcr2DidDocument,
|
|
49
|
-
patches: PatchOperation[],
|
|
50
|
-
sourceVersionId: number,
|
|
51
|
-
): UnsignedBTCR2Update {
|
|
52
|
-
// Initialize an unsigned update conformant to btcr2 spec.
|
|
53
|
-
const unsignedUpdate: UnsignedBTCR2Update = {
|
|
54
|
-
'@context' : [
|
|
55
|
-
'https://w3id.org/security/v2',
|
|
56
|
-
'https://w3id.org/zcap/v1',
|
|
57
|
-
'https://w3id.org/json-ld-patch/v1',
|
|
58
|
-
'https://btcr2.dev/context/v1'
|
|
59
|
-
],
|
|
60
|
-
patch : patches,
|
|
61
|
-
targetHash : '',
|
|
62
|
-
targetVersionId : sourceVersionId + 1,
|
|
63
|
-
sourceHash : canonicalHash(sourceDocument),
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
// Apply all JSON patches to sourceDocument.
|
|
67
|
-
const targetDocument = JSONPatch.apply(sourceDocument, patches);
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
// Ensure the targetDocument is conformant to DID Core v1.1.
|
|
71
|
-
DidDocument.isValid(targetDocument);
|
|
72
|
-
} catch (error) {
|
|
73
|
-
// If validation fails, throw an UpdateError with INVALID_DID_UPDATE.
|
|
74
|
-
throw new UpdateError(
|
|
75
|
-
'Error validating targetDocument: ' + (error instanceof Error ? error.message : String(error)),
|
|
76
|
-
INVALID_DID_UPDATE, targetDocument
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
// Set the targetHash by canonicalizing the targetDocument and encoding it in base64url.
|
|
81
|
-
unsignedUpdate.targetHash = canonicalHash(targetDocument);
|
|
82
|
-
|
|
83
|
-
// Return unsignedUpdate.
|
|
84
|
-
return unsignedUpdate;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Implements subsection {@link http://dcdpr.github.io/did-btcr2/operations/update.html#construct-btcr2-signed-update | 7.3.c Construct BTCR2 Signed Update }.
|
|
89
|
-
* This process constructs a BTCR2 Signed Update from a BTCR2 Unsigned Update.
|
|
90
|
-
*
|
|
91
|
-
* @param {string} did The did-btcr2 identifier to derive the root capability from
|
|
92
|
-
* @param {UnsignedBTCR2Update} unsignedUpdate The updatePayload object to be signed
|
|
93
|
-
* @param {DidVerificationMethod} verificationMethod The verificationMethod object to be used for signing
|
|
94
|
-
* @returns {SignedBTCR2Update} Did update payload secured with a proof => SignedBTCR2Update
|
|
95
|
-
* @throws {UpdateError} if the privateKeyBytes are invalid
|
|
96
|
-
*/
|
|
97
|
-
static sign(
|
|
98
|
-
did: string,
|
|
99
|
-
unsignedUpdate: UnsignedBTCR2Update,
|
|
100
|
-
verificationMethod: DidVerificationMethod,
|
|
101
|
-
secretKey: KeyBytes,
|
|
102
|
-
): SignedBTCR2Update {
|
|
103
|
-
// Parse the controller from the verificationMethod
|
|
104
|
-
const controller = verificationMethod.controller;
|
|
105
|
-
// Parse the fragment from the vmId
|
|
106
|
-
const id = verificationMethod.id.slice(verificationMethod.id.indexOf('#'));
|
|
107
|
-
|
|
108
|
-
// Construct a Schnorr Multikey
|
|
109
|
-
const multikey = SchnorrMultikey.fromSecretKey(id, controller, secretKey);
|
|
110
|
-
|
|
111
|
-
// Define the Data Integrity proof config
|
|
112
|
-
const config: DataIntegrityConfig = {
|
|
113
|
-
'@context' : [
|
|
114
|
-
'https://w3id.org/security/v2',
|
|
115
|
-
'https://w3id.org/zcap/v1',
|
|
116
|
-
'https://w3id.org/json-ld-patch/v1',
|
|
117
|
-
'https://btcr2.dev/context/v1'
|
|
118
|
-
],
|
|
119
|
-
cryptosuite : 'bip340-jcs-2025',
|
|
120
|
-
type : 'DataIntegrityProof',
|
|
121
|
-
verificationMethod : verificationMethod.id,
|
|
122
|
-
proofPurpose : 'capabilityInvocation',
|
|
123
|
-
capability : `urn:zcap:root:${encodeURIComponent(did)}`,
|
|
124
|
-
capabilityAction : 'Write',
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
// Go from multikey => cryptosuite => diproof
|
|
128
|
-
const diproof = multikey.toCryptosuite().toDataIntegrityProof();
|
|
129
|
-
|
|
130
|
-
// Use the config to add a proof to the unsigned update
|
|
131
|
-
return diproof.addProof(unsignedUpdate, config);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
/**
|
|
135
|
-
* Implements subsection {@link https://dcdpr.github.io/did-btcr2/operations/update.html#announce-did-update | 7.3.d Announce DID Update}.
|
|
136
|
-
* BTCR2 Signed Updates are announced to the Bitcoin blockchain depending on the Beacon Type.
|
|
137
|
-
* @param {BeaconService} beaconService The BeaconService object representing the funded beacon to announce the update to.
|
|
138
|
-
* @param {SignedBTCR2Update} update The signed update object to be announced.
|
|
139
|
-
* @param {KeyBytes} secretKey The private key used to sign the update for announcement.
|
|
140
|
-
* @returns {SignedBTCR2Update} The SignedBTCR2Update object containing data to validate the Beacon Signal
|
|
141
|
-
* @throws {UpdateError} if the beaconService type is invalid
|
|
142
|
-
*/
|
|
143
|
-
static async announce(
|
|
144
|
-
beaconService: BeaconService,
|
|
145
|
-
update: SignedBTCR2Update,
|
|
146
|
-
secretKey: KeyBytes,
|
|
147
|
-
bitcoin: BitcoinConnection
|
|
148
|
-
): Promise<SignedBTCR2Update> {
|
|
149
|
-
// Establish a beacon object
|
|
150
|
-
const beacon = BeaconFactory.establish(beaconService);
|
|
151
|
-
|
|
152
|
-
// Broadcast the update
|
|
153
|
-
const result = await beacon.broadcastSignal(update, secretKey, bitcoin);
|
|
154
|
-
|
|
155
|
-
// Return the sidecarData
|
|
156
|
-
return result;
|
|
157
|
-
}
|
|
158
|
-
}
|