@did-btcr2/method 0.22.0 → 0.23.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 +274 -1239
- package/dist/browser.mjs +274 -1239
- package/dist/cjs/core/beacon/aggregation/cohort/index.js +13 -2
- package/dist/cjs/core/beacon/aggregation/cohort/index.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js +7 -2
- package/dist/cjs/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js +5 -10
- package/dist/cjs/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js +4 -7
- package/dist/cjs/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/cjs/core/beacon/aggregation/session/index.js +15 -3
- package/dist/cjs/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/cjs/core/beacon/cas-beacon.js +1 -1
- package/dist/cjs/core/beacon/cas-beacon.js.map +1 -1
- package/dist/cjs/core/beacon/signal-discovery.js +6 -6
- package/dist/cjs/core/beacon/signal-discovery.js.map +1 -1
- package/dist/cjs/core/beacon/singleton.js +13 -12
- package/dist/cjs/core/beacon/singleton.js.map +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js +1 -1
- package/dist/cjs/core/beacon/smt-beacon.js.map +1 -1
- package/dist/cjs/core/identifier.js +11 -13
- package/dist/cjs/core/identifier.js.map +1 -1
- package/dist/cjs/core/resolve.js +14 -15
- package/dist/cjs/core/resolve.js.map +1 -1
- package/dist/cjs/core/update.js +2 -2
- package/dist/cjs/core/update.js.map +1 -1
- package/dist/cjs/did-btcr2.js +11 -14
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/utils/did-document.js +13 -2
- package/dist/cjs/utils/did-document.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/index.js +13 -2
- package/dist/esm/core/beacon/aggregation/cohort/index.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js +7 -2
- package/dist/esm/core/beacon/aggregation/cohort/messages/base.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js +5 -10
- package/dist/esm/core/beacon/aggregation/communication/adapter/did-comm.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js +4 -7
- package/dist/esm/core/beacon/aggregation/communication/adapter/nostr.js.map +1 -1
- package/dist/esm/core/beacon/aggregation/session/index.js +15 -3
- package/dist/esm/core/beacon/aggregation/session/index.js.map +1 -1
- package/dist/esm/core/beacon/cas-beacon.js +1 -1
- package/dist/esm/core/beacon/cas-beacon.js.map +1 -1
- package/dist/esm/core/beacon/signal-discovery.js +6 -6
- package/dist/esm/core/beacon/signal-discovery.js.map +1 -1
- package/dist/esm/core/beacon/singleton.js +13 -12
- package/dist/esm/core/beacon/singleton.js.map +1 -1
- package/dist/esm/core/beacon/smt-beacon.js +1 -1
- package/dist/esm/core/beacon/smt-beacon.js.map +1 -1
- package/dist/esm/core/identifier.js +11 -13
- package/dist/esm/core/identifier.js.map +1 -1
- package/dist/esm/core/resolve.js +14 -15
- package/dist/esm/core/resolve.js.map +1 -1
- package/dist/esm/core/update.js +2 -2
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +11 -14
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/utils/did-document.js +13 -2
- package/dist/esm/utils/did-document.js.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/cohort/index.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/cohort/messages/base.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/did-comm.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/communication/adapter/nostr.d.ts.map +1 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts +1 -1
- package/dist/types/core/beacon/aggregation/session/index.d.ts.map +1 -1
- package/dist/types/core/beacon/beacon.d.ts +3 -3
- package/dist/types/core/beacon/beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/cas-beacon.d.ts +3 -3
- package/dist/types/core/beacon/cas-beacon.d.ts.map +1 -1
- package/dist/types/core/beacon/signal-discovery.d.ts +5 -5
- package/dist/types/core/beacon/signal-discovery.d.ts.map +1 -1
- package/dist/types/core/beacon/singleton.d.ts +3 -3
- package/dist/types/core/beacon/singleton.d.ts.map +1 -1
- package/dist/types/core/beacon/smt-beacon.d.ts +3 -3
- package/dist/types/core/beacon/smt-beacon.d.ts.map +1 -1
- package/dist/types/core/identifier.d.ts +17 -21
- package/dist/types/core/identifier.d.ts.map +1 -1
- package/dist/types/core/interfaces.d.ts +2 -2
- package/dist/types/core/interfaces.d.ts.map +1 -1
- package/dist/types/core/resolve.d.ts +3 -3
- package/dist/types/core/resolve.d.ts.map +1 -1
- package/dist/types/core/update.d.ts +2 -2
- package/dist/types/core/update.d.ts.map +1 -1
- package/dist/types/did-btcr2.d.ts +4 -4
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +3 -1
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +5 -6
- package/src/core/beacon/aggregation/cohort/index.ts +13 -2
- package/src/core/beacon/aggregation/cohort/messages/base.ts +7 -2
- package/src/core/beacon/aggregation/communication/adapter/did-comm.ts +5 -12
- package/src/core/beacon/aggregation/communication/adapter/nostr.ts +5 -8
- package/src/core/beacon/aggregation/session/index.ts +15 -3
- package/src/core/beacon/beacon.ts +3 -3
- package/src/core/beacon/cas-beacon.ts +3 -3
- package/src/core/beacon/signal-discovery.ts +9 -9
- package/src/core/beacon/singleton.ts +15 -15
- package/src/core/beacon/smt-beacon.ts +3 -3
- package/src/core/identifier.ts +31 -28
- package/src/core/interfaces.ts +2 -2
- package/src/core/resolve.ts +17 -18
- package/src/core/update.ts +4 -4
- package/src/did-btcr2.ts +21 -19
- package/src/utils/did-document.ts +14 -2
package/src/did-btcr2.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BitcoinConnection } from '@did-btcr2/bitcoin';
|
|
2
2
|
import {
|
|
3
3
|
DocumentBytes,
|
|
4
4
|
HexString,
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
KeyBytes,
|
|
9
9
|
METHOD_NOT_SUPPORTED,
|
|
10
10
|
MethodError,
|
|
11
|
+
MISSING_RESOLUTION_OPTIONS,
|
|
11
12
|
MISSING_UPDATE_DATA,
|
|
12
13
|
PatchOperation,
|
|
13
14
|
ResolveError,
|
|
@@ -37,7 +38,7 @@ export type Btcr2Identifier = string;
|
|
|
37
38
|
|
|
38
39
|
export interface DidCreateOptions {
|
|
39
40
|
/** Type of identifier to create (key or external) */
|
|
40
|
-
idType:
|
|
41
|
+
idType: string;
|
|
41
42
|
/** DID BTCR2 Version Number */
|
|
42
43
|
version?: number;
|
|
43
44
|
/** Bitcoin Network */
|
|
@@ -83,10 +84,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
83
84
|
* const did = DidBtcr2.create(genesisBytes, { idType: 'KEY', network: 'regtest' });
|
|
84
85
|
* ```
|
|
85
86
|
*/
|
|
86
|
-
static create(
|
|
87
|
-
genesisBytes: KeyBytes | DocumentBytes,
|
|
88
|
-
options?: DidCreateOptions
|
|
89
|
-
): Btcr2Identifier {
|
|
87
|
+
static create(genesisBytes: KeyBytes | DocumentBytes, options?: DidCreateOptions): Btcr2Identifier {
|
|
90
88
|
// Deconstruct the idType, version and network from the options, setting defaults if not given
|
|
91
89
|
const { idType, version = 1, network = 'bitcoin' } = options || {};
|
|
92
90
|
|
|
@@ -98,7 +96,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
98
96
|
}
|
|
99
97
|
|
|
100
98
|
// Call identifier encoding algorithm
|
|
101
|
-
return Identifier.encode({ idType,
|
|
99
|
+
return Identifier.encode(genesisBytes, { idType, version, network });
|
|
102
100
|
}
|
|
103
101
|
|
|
104
102
|
/**
|
|
@@ -172,12 +170,11 @@ export class DidBtcr2 implements DidMethod {
|
|
|
172
170
|
|
|
173
171
|
// Check if bitcoin driver provided
|
|
174
172
|
if(!resolutionOptions?.drivers?.bitcoin) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
resolutionOptions.drivers.bitcoin.setActiveNetwork(didComponents.network);
|
|
173
|
+
throw new ResolveError(
|
|
174
|
+
'Bitcoin connection required for resolve. Pass a configured driver via '
|
|
175
|
+
+ 'resolutionOptions.drivers.bitcoin or use DidBtcr2Api which injects it automatically.',
|
|
176
|
+
MISSING_RESOLUTION_OPTIONS, resolutionOptions
|
|
177
|
+
);
|
|
181
178
|
}
|
|
182
179
|
|
|
183
180
|
// Get the bitcoin driver from the resolution options
|
|
@@ -217,9 +214,8 @@ export class DidBtcr2 implements DidMethod {
|
|
|
217
214
|
// Return didResolutionResult;
|
|
218
215
|
return didResolutionResult;
|
|
219
216
|
} catch (error: any) {
|
|
220
|
-
console.error(error);
|
|
221
217
|
// Rethrow any unexpected errors that are not a `ResolveError`.
|
|
222
|
-
if (!(error instanceof ResolveError)) throw new Error(error);
|
|
218
|
+
if (!(error instanceof ResolveError)) throw new Error(error.message ?? error, { cause: error });
|
|
223
219
|
|
|
224
220
|
// Return a DID Resolution Result with the appropriate error code.
|
|
225
221
|
return {
|
|
@@ -247,7 +243,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
247
243
|
* @param {string} params.verificationMethodId The verificationMethod ID to sign the update with.
|
|
248
244
|
* @param {string} params.beaconId The beacon ID associated with the update.
|
|
249
245
|
* @param {KeyBytes | HexString} [params.signingMaterial] Optional signing material (key bytes or hex string).
|
|
250
|
-
* @param {
|
|
246
|
+
* @param {BitcoinConnection} [params.bitcoin] Optional Bitcoin network connection for announcing the update. If not provided, a default connection will be initialized.
|
|
251
247
|
* @return {Promise<SignedBTCR2Update>} Promise resolving to the signed BTCR2 update.
|
|
252
248
|
* @throws {UpdateError} if no verificationMethod, verificationMethod type is not `Multikey` or the publicKeyMultibase
|
|
253
249
|
* header is not `zQ3s`
|
|
@@ -267,7 +263,7 @@ export class DidBtcr2 implements DidMethod {
|
|
|
267
263
|
verificationMethodId: string;
|
|
268
264
|
beaconId: string;
|
|
269
265
|
signingMaterial?: KeyBytes | HexString;
|
|
270
|
-
bitcoin?:
|
|
266
|
+
bitcoin?: BitcoinConnection;
|
|
271
267
|
}): Promise<SignedBTCR2Update> {
|
|
272
268
|
// TODO: provide KMS as alternative
|
|
273
269
|
// If no signingMaterial provided, throw an UpdateError with INVALID_DID_UPDATE.
|
|
@@ -337,8 +333,14 @@ export class DidBtcr2 implements DidMethod {
|
|
|
337
333
|
INVALID_DID_UPDATE, {sourceDocument, beaconId}
|
|
338
334
|
);
|
|
339
335
|
}
|
|
340
|
-
//
|
|
341
|
-
|
|
336
|
+
// Require an explicit bitcoin connection — no silent env-var fallback
|
|
337
|
+
if (!bitcoin) {
|
|
338
|
+
throw new UpdateError(
|
|
339
|
+
'Bitcoin connection required for update. Pass a configured `bitcoin` parameter '
|
|
340
|
+
+ 'or use DidBtcr2Api which injects it automatically.',
|
|
341
|
+
INVALID_DID_UPDATE, { beaconId }
|
|
342
|
+
);
|
|
343
|
+
}
|
|
342
344
|
|
|
343
345
|
// Announce the signed update to the blockchain using the specified beacon(s)
|
|
344
346
|
await Update.announce(beaconService, signed, secretKey, bitcoin);
|
|
@@ -99,6 +99,7 @@ export interface Btcr2DidDocument extends W3CDidDocument {
|
|
|
99
99
|
capabilityInvocation?: Array<string | DidVerificationMethod>;
|
|
100
100
|
capabilityDelegation?: Array<string | DidVerificationMethod>;
|
|
101
101
|
service: Array<BeaconService>;
|
|
102
|
+
deactivated?: boolean;
|
|
102
103
|
}
|
|
103
104
|
|
|
104
105
|
/**
|
|
@@ -114,6 +115,7 @@ export interface Btcr2DidDocument extends W3CDidDocument {
|
|
|
114
115
|
* @property {Array<string | DidVerificationMethod>} [capabilityInvocation] - The capability invocation methods of the DID Document.
|
|
115
116
|
* @property {Array<string | DidVerificationMethod>} [capabilityDelegation] - The capability delegation methods of the DID Document.
|
|
116
117
|
* @property {Array<BeaconService>} service - The services of the DID Document.
|
|
118
|
+
* @property {boolean} [deactivated] - Indicates if the DID Document is deactivated.
|
|
117
119
|
*/
|
|
118
120
|
export class DidDocument implements Btcr2DidDocument {
|
|
119
121
|
id: string;
|
|
@@ -199,8 +201,18 @@ export class DidDocument implements Btcr2DidDocument {
|
|
|
199
201
|
* Convert the DidDocument to a JSON object.
|
|
200
202
|
* @returns {DidDocument} The JSON representation of the DidDocument.
|
|
201
203
|
*/
|
|
202
|
-
public
|
|
203
|
-
return
|
|
204
|
+
public toJSON(): DidDocumentLike {
|
|
205
|
+
return {
|
|
206
|
+
id : this.id,
|
|
207
|
+
'@context' : this['@context'],
|
|
208
|
+
verificationMethod : this.verificationMethod,
|
|
209
|
+
authentication : this.authentication,
|
|
210
|
+
assertionMethod : this.assertionMethod,
|
|
211
|
+
capabilityInvocation : this.capabilityInvocation,
|
|
212
|
+
capabilityDelegation : this.capabilityDelegation,
|
|
213
|
+
service : this.service,
|
|
214
|
+
deactivated : this.deactivated
|
|
215
|
+
};
|
|
204
216
|
}
|
|
205
217
|
|
|
206
218
|
/**
|