@did-btcr2/method 0.20.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/README.md +223 -1
- package/dist/browser.js +2566 -3507
- package/dist/browser.mjs +2566 -3507
- 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 +18 -20
- 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 +52 -49
- package/dist/cjs/core/resolve.js.map +1 -1
- package/dist/cjs/core/update.js +3 -4
- package/dist/cjs/core/update.js.map +1 -1
- package/dist/cjs/did-btcr2.js +36 -35
- package/dist/cjs/did-btcr2.js.map +1 -1
- package/dist/cjs/utils/did-document-builder.js +0 -6
- package/dist/cjs/utils/did-document-builder.js.map +1 -1
- package/dist/cjs/utils/did-document.js +44 -26
- 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 +18 -20
- 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 +52 -49
- package/dist/esm/core/resolve.js.map +1 -1
- package/dist/esm/core/update.js +3 -4
- package/dist/esm/core/update.js.map +1 -1
- package/dist/esm/did-btcr2.js +36 -35
- package/dist/esm/did-btcr2.js.map +1 -1
- package/dist/esm/utils/did-document-builder.js +0 -6
- package/dist/esm/utils/did-document-builder.js.map +1 -1
- package/dist/esm/utils/did-document.js +44 -26
- 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 +4 -4
- 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 +10 -7
- 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 +12 -8
- package/dist/types/did-btcr2.d.ts.map +1 -1
- package/dist/types/utils/did-document-builder.d.ts +0 -1
- package/dist/types/utils/did-document-builder.d.ts.map +1 -1
- package/dist/types/utils/did-document.d.ts +14 -9
- package/dist/types/utils/did-document.d.ts.map +1 -1
- package/package.json +8 -8
- 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 +21 -23
- 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 +73 -62
- package/src/core/update.ts +5 -5
- package/src/did-btcr2.ts +47 -43
- package/src/utils/did-document-builder.ts +0 -7
- package/src/utils/did-document.ts +54 -31
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { getNetwork } from '@did-btcr2/bitcoin';
|
|
2
2
|
import {
|
|
3
3
|
BTCR2_DID_DOCUMENT_CONTEXT,
|
|
4
|
+
Canonicalization,
|
|
4
5
|
DidDocumentError,
|
|
6
|
+
HashBytes,
|
|
5
7
|
IdentifierTypes,
|
|
6
8
|
INVALID_DID_DOCUMENT,
|
|
7
9
|
JSONObject,
|
|
@@ -10,11 +12,11 @@ import {
|
|
|
10
12
|
} from '@did-btcr2/common';
|
|
11
13
|
import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
|
|
12
14
|
import { DidDocument as W3CDidDocument, DidVerificationMethod as W3CDidVerificationMethod } from '@web5/dids';
|
|
15
|
+
import { payments } from 'bitcoinjs-lib';
|
|
13
16
|
import { BeaconService } from '../core/beacon/interfaces.js';
|
|
14
17
|
import { BeaconUtils } from '../core/beacon/utils.js';
|
|
15
18
|
import { Identifier } from '../core/identifier.js';
|
|
16
19
|
import { Appendix } from './appendix.js';
|
|
17
|
-
import { payments } from 'bitcoinjs-lib';
|
|
18
20
|
|
|
19
21
|
export const ID_PLACEHOLDER_VALUE = 'did:btcr2:_';
|
|
20
22
|
export const BECH32M_CHARS = '';
|
|
@@ -36,8 +38,9 @@ export type VerificationRelationships = {
|
|
|
36
38
|
capabilityDelegation?: Array<string | DidVerificationMethod>;
|
|
37
39
|
}
|
|
38
40
|
|
|
39
|
-
/** Loose type for unvalidated DID document-like input objects. */
|
|
41
|
+
/** Loose type for unvalidated DID / Genesis document-like input objects. */
|
|
40
42
|
export type DidDocumentLike = Partial<Btcr2DidDocument>;
|
|
43
|
+
export type GenesisDocumentLike = Partial<Btcr2DidDocument>;
|
|
41
44
|
|
|
42
45
|
export interface Btcr2VerificationMethod extends W3CDidVerificationMethod {
|
|
43
46
|
id: string;
|
|
@@ -79,7 +82,6 @@ export class DidVerificationMethod implements Btcr2VerificationMethod {
|
|
|
79
82
|
* @type {Btcr2DidDocument}
|
|
80
83
|
* @extends {W3CDidDocument}
|
|
81
84
|
* @property {string} id - The identifier of the DID Document.
|
|
82
|
-
* @property {Array<string>} [controller] - The controller of the DID Document.
|
|
83
85
|
* @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
|
|
84
86
|
* @property {Array<DidVerificationMethod>} verificationMethod - The verification methods of the DID Document.
|
|
85
87
|
* @property {Array<string | DidVerificationMethod>} [authentication] - The authentication methods of the DID Document.
|
|
@@ -90,7 +92,6 @@ export class DidVerificationMethod implements Btcr2VerificationMethod {
|
|
|
90
92
|
*/
|
|
91
93
|
export interface Btcr2DidDocument extends W3CDidDocument {
|
|
92
94
|
id: string;
|
|
93
|
-
controller?: Array<string>;
|
|
94
95
|
'@context'?: Array<string | JSONObject>;
|
|
95
96
|
verificationMethod: Array<DidVerificationMethod>;
|
|
96
97
|
authentication?: Array<string | DidVerificationMethod>;
|
|
@@ -98,6 +99,7 @@ export interface Btcr2DidDocument extends W3CDidDocument {
|
|
|
98
99
|
capabilityInvocation?: Array<string | DidVerificationMethod>;
|
|
99
100
|
capabilityDelegation?: Array<string | DidVerificationMethod>;
|
|
100
101
|
service: Array<BeaconService>;
|
|
102
|
+
deactivated?: boolean;
|
|
101
103
|
}
|
|
102
104
|
|
|
103
105
|
/**
|
|
@@ -106,7 +108,6 @@ export interface Btcr2DidDocument extends W3CDidDocument {
|
|
|
106
108
|
* @type {DidDocument}
|
|
107
109
|
* @implements {Btcr2DidDocument}
|
|
108
110
|
* @property {string} id - The identifier of the DID Document.
|
|
109
|
-
* @property {Array<string>} [controller] - The controller of the DID Document.
|
|
110
111
|
* @property {Array<string | JSONObject>} ['@context'] - The context of the DID Document.
|
|
111
112
|
* @property {Array<DidVerificationMethod>} verificationMethod - The verification methods of the DID Document.
|
|
112
113
|
* @property {Array<string | DidVerificationMethod>} [authentication] - The authentication methods of the DID Document.
|
|
@@ -114,11 +115,14 @@ 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;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
+
'@context'?: Array<string | JSONObject> = [
|
|
123
|
+
'https://www.w3.org/TR/did-1.1',
|
|
124
|
+
'https://btcr2.dev/context/v1'
|
|
125
|
+
];
|
|
122
126
|
verificationMethod: Array<DidVerificationMethod>;
|
|
123
127
|
authentication?: Array<string | DidVerificationMethod>;
|
|
124
128
|
assertionMethod?: Array<string | DidVerificationMethod>;
|
|
@@ -127,9 +131,14 @@ export class DidDocument implements Btcr2DidDocument {
|
|
|
127
131
|
service: Array<BeaconService>;
|
|
128
132
|
deactivated?: boolean;
|
|
129
133
|
|
|
130
|
-
constructor(document:
|
|
134
|
+
constructor(document: DidDocumentLike) {
|
|
135
|
+
// Ensure document has an id
|
|
136
|
+
if(!document.id) {
|
|
137
|
+
throw new DidDocumentError('DID Document must have an id', INVALID_DID_DOCUMENT, document);
|
|
138
|
+
}
|
|
139
|
+
|
|
131
140
|
// Set the ID and ID type
|
|
132
|
-
const idType = document.id.includes('
|
|
141
|
+
const idType = document.id.includes('k1')
|
|
133
142
|
? IdentifierTypes.KEY
|
|
134
143
|
: IdentifierTypes.EXTERNAL;
|
|
135
144
|
|
|
@@ -137,16 +146,13 @@ export class DidDocument implements Btcr2DidDocument {
|
|
|
137
146
|
const isGenesis = document.id === ID_PLACEHOLDER_VALUE;
|
|
138
147
|
|
|
139
148
|
// Deconstruct the document parts for validation
|
|
140
|
-
const { id,
|
|
149
|
+
const { id, verificationMethod: vm, service } = document;
|
|
141
150
|
|
|
142
151
|
// If not genesis, validate core properties
|
|
143
152
|
if (!isGenesis) {
|
|
144
153
|
if (!DidDocument.isValidId(id)) {
|
|
145
154
|
throw new DidDocumentError(`Invalid id: ${id}`, INVALID_DID_DOCUMENT, document);
|
|
146
155
|
}
|
|
147
|
-
if(!DidDocument.isValidController(controller ?? [id])) {
|
|
148
|
-
throw new DidDocumentError(`Invalid controller: ${controller}`, INVALID_DID_DOCUMENT, document);
|
|
149
|
-
}
|
|
150
156
|
if (!DidDocument.isValidVerificationMethods(vm)) {
|
|
151
157
|
throw new DidDocumentError('Invalid verificationMethod: ' + vm, INVALID_DID_DOCUMENT, document);
|
|
152
158
|
}
|
|
@@ -157,10 +163,12 @@ export class DidDocument implements Btcr2DidDocument {
|
|
|
157
163
|
|
|
158
164
|
// Set core properties
|
|
159
165
|
this.id = document.id;
|
|
160
|
-
this.verificationMethod = document.verificationMethod;
|
|
161
|
-
this.service = document.service;
|
|
162
|
-
this['@context'] = document['@context'] ||
|
|
163
|
-
|
|
166
|
+
this.verificationMethod = document.verificationMethod || [];
|
|
167
|
+
this.service = document.service || [];
|
|
168
|
+
this['@context'] = document['@context'] || [
|
|
169
|
+
'https://www.w3.org/TR/did-1.1',
|
|
170
|
+
'https://btcr2.dev/context/v1'
|
|
171
|
+
];
|
|
164
172
|
|
|
165
173
|
// Relationships logic based on idType
|
|
166
174
|
if (idType === IdentifierTypes.KEY) {
|
|
@@ -180,11 +188,12 @@ export class DidDocument implements Btcr2DidDocument {
|
|
|
180
188
|
|
|
181
189
|
// Sanitize the DID Document
|
|
182
190
|
DidDocument.sanitize(this);
|
|
191
|
+
|
|
183
192
|
// If the DID Document is not an intermediateDocument, validate it
|
|
184
|
-
if (
|
|
185
|
-
DidDocument.validate(this);
|
|
186
|
-
} else {
|
|
193
|
+
if (isGenesis) {
|
|
187
194
|
this.validateGenesis();
|
|
195
|
+
} else {
|
|
196
|
+
DidDocument.validate(this);
|
|
188
197
|
}
|
|
189
198
|
}
|
|
190
199
|
|
|
@@ -192,8 +201,18 @@ export class DidDocument implements Btcr2DidDocument {
|
|
|
192
201
|
* Convert the DidDocument to a JSON object.
|
|
193
202
|
* @returns {DidDocument} The JSON representation of the DidDocument.
|
|
194
203
|
*/
|
|
195
|
-
public
|
|
196
|
-
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
|
+
};
|
|
197
216
|
}
|
|
198
217
|
|
|
199
218
|
/**
|
|
@@ -386,10 +405,6 @@ export class DidDocument implements Btcr2DidDocument {
|
|
|
386
405
|
if(this.id !== ID_PLACEHOLDER_VALUE) {
|
|
387
406
|
throw new DidDocumentError('Invalid GenesisDocument ID', INVALID_DID_DOCUMENT, this);
|
|
388
407
|
}
|
|
389
|
-
// Validate the controller
|
|
390
|
-
if(!this.controller?.every(c => c === ID_PLACEHOLDER_VALUE)) {
|
|
391
|
-
throw new DidDocumentError('Invalid GenesisDocument controller', INVALID_DID_DOCUMENT, this);
|
|
392
|
-
}
|
|
393
408
|
// Validate the verificationMethod
|
|
394
409
|
if(!this.verificationMethod.every(vm => vm.id.includes(ID_PLACEHOLDER_VALUE) && vm.controller === ID_PLACEHOLDER_VALUE)) {
|
|
395
410
|
throw new DidDocumentError('Invalid GenesisDocument verificationMethod', INVALID_DID_DOCUMENT, this);
|
|
@@ -433,8 +448,8 @@ export class Document {
|
|
|
433
448
|
* @extends {DidDocument}
|
|
434
449
|
*/
|
|
435
450
|
export class GenesisDocument extends DidDocument {
|
|
436
|
-
constructor(document:
|
|
437
|
-
super(document
|
|
451
|
+
constructor(document: DidDocumentLike) {
|
|
452
|
+
super(document);
|
|
438
453
|
}
|
|
439
454
|
|
|
440
455
|
/**
|
|
@@ -471,8 +486,7 @@ export class GenesisDocument extends DidDocument {
|
|
|
471
486
|
relationships: VerificationRelationships,
|
|
472
487
|
service: Array<BeaconService>
|
|
473
488
|
): GenesisDocument {
|
|
474
|
-
|
|
475
|
-
return new GenesisDocument({ id, ...relationships, verificationMethod, service, });
|
|
489
|
+
return new GenesisDocument({ id: ID_PLACEHOLDER_VALUE, ...relationships, verificationMethod, service, });
|
|
476
490
|
}
|
|
477
491
|
|
|
478
492
|
/**
|
|
@@ -485,7 +499,7 @@ export class GenesisDocument extends DidDocument {
|
|
|
485
499
|
const id = ID_PLACEHOLDER_VALUE;
|
|
486
500
|
const address = payments.p2pkh({ pubkey: pk.compressed, network: getNetwork(network) })?.address;
|
|
487
501
|
const services = [{
|
|
488
|
-
id : `${id}#
|
|
502
|
+
id : `${id}#service-0`,
|
|
489
503
|
serviceEndpoint : `bitcoin:${address}`,
|
|
490
504
|
type : 'SingletonBeacon',
|
|
491
505
|
}];
|
|
@@ -516,4 +530,13 @@ export class GenesisDocument extends DidDocument {
|
|
|
516
530
|
public static fromJSON(object: object | DidDocument): GenesisDocument {
|
|
517
531
|
return new GenesisDocument(object as Btcr2DidDocument);
|
|
518
532
|
}
|
|
533
|
+
|
|
534
|
+
/**
|
|
535
|
+
* Convert a GenesisDocument to genesis bytes.
|
|
536
|
+
* @param {GenesisDocument} genesisDocument The GenesisDocument to convert.
|
|
537
|
+
* @returns {Bytes} The genesis bytes.
|
|
538
|
+
*/
|
|
539
|
+
static toGenesisBytes(genesisDocument: GenesisDocumentLike): HashBytes {
|
|
540
|
+
return Canonicalization.andHash(genesisDocument);
|
|
541
|
+
}
|
|
519
542
|
}
|