@did-btcr2/method 0.16.0 → 0.17.1

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 (43) hide show
  1. package/dist/browser.js +182 -202
  2. package/dist/browser.mjs +182 -202
  3. package/dist/cjs/core/beacon/aggregation/protocol/nostr.js +1 -1
  4. package/dist/cjs/core/beacon/aggregation/protocol/nostr.js.map +1 -1
  5. package/dist/cjs/core/crud/update.js +1 -1
  6. package/dist/cjs/core/crud/update.js.map +1 -1
  7. package/dist/cjs/did-btcr2.js +7 -19
  8. package/dist/cjs/did-btcr2.js.map +1 -1
  9. package/dist/cjs/index.js +0 -1
  10. package/dist/cjs/index.js.map +1 -1
  11. package/dist/cjs/utils/did-document.js +61 -13
  12. package/dist/cjs/utils/did-document.js.map +1 -1
  13. package/dist/esm/core/beacon/aggregation/protocol/nostr.js +1 -1
  14. package/dist/esm/core/beacon/aggregation/protocol/nostr.js.map +1 -1
  15. package/dist/esm/core/crud/update.js +1 -1
  16. package/dist/esm/core/crud/update.js.map +1 -1
  17. package/dist/esm/did-btcr2.js +7 -19
  18. package/dist/esm/did-btcr2.js.map +1 -1
  19. package/dist/esm/index.js +0 -1
  20. package/dist/esm/index.js.map +1 -1
  21. package/dist/esm/utils/did-document.js +61 -13
  22. package/dist/esm/utils/did-document.js.map +1 -1
  23. package/dist/types/core/crud/update.d.ts +10 -0
  24. package/dist/types/core/crud/update.d.ts.map +1 -1
  25. package/dist/types/did-btcr2.d.ts +16 -5
  26. package/dist/types/did-btcr2.d.ts.map +1 -1
  27. package/dist/types/index.d.ts +0 -1
  28. package/dist/types/index.d.ts.map +1 -1
  29. package/dist/types/utils/did-document.d.ts +25 -10
  30. package/dist/types/utils/did-document.d.ts.map +1 -1
  31. package/package.json +5 -5
  32. package/src/core/beacon/aggregation/protocol/nostr.ts +1 -1
  33. package/src/core/crud/update.ts +13 -1
  34. package/src/did-btcr2.ts +25 -25
  35. package/src/index.ts +0 -1
  36. package/src/utils/did-document.ts +72 -16
  37. package/dist/cjs/core/crud/create.js +0 -102
  38. package/dist/cjs/core/crud/create.js.map +0 -1
  39. package/dist/esm/core/crud/create.js +0 -102
  40. package/dist/esm/core/crud/create.js.map +0 -1
  41. package/dist/types/core/crud/create.d.ts +0 -92
  42. package/dist/types/core/crud/create.d.ts.map +0 -1
  43. package/src/core/crud/create.ts +0 -160
@@ -1,9 +1,16 @@
1
- import { PatchOperation } from '@did-btcr2/common';
1
+ import { DocumentBytes, KeyBytes, PatchOperation } from '@did-btcr2/common';
2
2
  import type { DidResolutionResult } from '@web5/dids';
3
3
  import { DidMethod } from '@web5/dids';
4
- import { CreateParams, CreateResponse } from './core/crud/create.js';
5
4
  import { DidResolutionOptions } from './interfaces/crud.js';
6
5
  import { DidDocument, DidVerificationMethod } from './utils/did-document.js';
6
+ import { SignalsMetadata } from './types/crud.js';
7
+ export type Btcr2Identifier = string;
8
+ export interface DidCreateOptions {
9
+ /** DID BTCR2 Version Number */
10
+ version?: number;
11
+ /** Bitcoin Network */
12
+ network?: string;
13
+ }
7
14
  /**
8
15
  * Implements {@link https://dcdpr.github.io/did-btcr2 | did:btcr2 DID Method Specification}.
9
16
  * did:btcr2 is a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce
@@ -13,7 +20,7 @@ import { DidDocument, DidVerificationMethod } from './utils/did-document.js';
13
20
  *
14
21
  * @class DidBtcr2
15
22
  * @type {DidBtcr2}
16
- *
23
+ * @implements {DidMethod}
17
24
  */
18
25
  export declare class DidBtcr2 implements DidMethod {
19
26
  /** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
@@ -36,7 +43,11 @@ export declare class DidBtcr2 implements DidMethod {
36
43
  * @returns {Promise<CreateResponse>} Promise resolving to a CreateResponse object.
37
44
  * @throws {DidBtcr2Error} if any of the checks fail
38
45
  */
39
- static create(params: CreateParams): Promise<CreateResponse>;
46
+ static create(params: {
47
+ idType: 'KEY' | 'EXTERNAL';
48
+ genesisBytes: KeyBytes | DocumentBytes;
49
+ options?: DidCreateOptions;
50
+ }): Promise<Btcr2Identifier>;
40
51
  /**
41
52
  * Entry point for section {@link https://dcdpr.github.io/did-btcr2/#read | 7.2 Read}.
42
53
  * See {@link Resolve} for implementation details.
@@ -97,7 +108,7 @@ export declare class DidBtcr2 implements DidMethod {
97
108
  patch: PatchOperation[];
98
109
  verificationMethodId: string;
99
110
  beaconIds: string[];
100
- }): Promise<any>;
111
+ }): Promise<SignalsMetadata>;
101
112
  /**
102
113
  * Given the W3C DID Document of a `did:btcr2` identifier, return the signing verification method that will be used
103
114
  * for signing messages and credentials. If given, the `methodId` parameter is used to select the
@@ -1 +1 @@
1
- {"version":3,"file":"did-btcr2.d.ts","sourceRoot":"","sources":["../../src/did-btcr2.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,cAAc,EAEf,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACtD,OAAO,EAIL,SAAS,EAEV,MAAM,YAAY,CAAC;AAGpB,OAAO,EAAU,YAAY,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAG7E,OAAO,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAE5D,OAAO,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAM7E;;;;;;;;;;GAUG;AACH,qBAAa,QAAS,YAAW,SAAS;IACxC,uFAAuF;IACvF,OAAc,UAAU,EAAE,MAAM,CAAW;IAE3C;;;;;;;;;;;;;;;;;OAiBG;WACiB,MAAM,CAAC,MAAM,EAAE,YAAY,GAAG,OAAO,CAAC,cAAc,CAAC;IA0BzE;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;WACiB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA2C5H;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;W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EAAE,KAAK,GAAG,UAAU,CAAC;QAC3B,YAAY,EAAE,QAAQ,GAAG,aAAa,CAAC;QACvC,OAAO,CAAC,EAAE,gBAAgB,CAAC;KAC5B,GAAG,OAAO,CAAC,eAAe,CAAC;IAa5B;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;WACiB,OAAO,CAAC,UAAU,EAAE,MAAM,EAAE,kBAAkB,GAAE,oBAAyB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IA2C5H;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;WACiB,MAAM,CAAC,MAAM,EAAE;QACjC,UAAU,EAAE,MAAM,CAAC;QACnB,cAAc,EAAE,WAAW,CAAC;QAC5B,eAAe,EAAE,MAAM,CAAC;QACxB,KAAK,EAAE,cAAc,EAAE,CAAC;QACxB,oBAAoB,EAAE,MAAM,CAAC;QAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;KACrB,GAAG,OAAO,CAAC,eAAe,CAAC;IAuD5B;;;;;;;;;;;OAWG;WACW,gBAAgB,CAAC,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE;QACxD,WAAW,EAAE,WAAW,CAAC;QACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,GAAG,qBAAqB;CA0B1B"}
@@ -2,7 +2,6 @@ export * from './core/beacon/cid-aggregate.js';
2
2
  export * from './core/beacon/factory.js';
3
3
  export * from './core/beacon/singleton.js';
4
4
  export * from './core/beacon/smt-aggregate.js';
5
- export * from './core/crud/create.js';
6
5
  export * from './core/crud/deactivate.js';
7
6
  export * from './core/crud/read.js';
8
7
  export * from './core/crud/update.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAE/C,cAAc,uBAAuB,CAAC;AACtC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAEhD,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AAExC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,gCAAgC,CAAC;AAE/C,cAAc,2BAA2B,CAAC;AAC1C,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,6BAA6B,CAAC;AAC5C,cAAc,iCAAiC,CAAC;AAEhD,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,yBAAyB,CAAC;AAExC,cAAc,iBAAiB,CAAC;AAEhC,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,iCAAiC,CAAC;AAChD,cAAc,yBAAyB,CAAC;AACxC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AAEtC,cAAc,gBAAgB,CAAC"}
@@ -1,5 +1,5 @@
1
- import { JSONObject } from '@did-btcr2/common';
2
- import { DidVerificationMethod as IIDidVerificationMethod, DidDocument as IIDidDocument } from '@web5/dids';
1
+ import { JSONObject, KeyBytes } from '@did-btcr2/common';
2
+ import { DidDocument as IIDidDocument, DidVerificationMethod as IIDidVerificationMethod } from '@web5/dids';
3
3
  import { BeaconService } from '../interfaces/ibeacon.js';
4
4
  export declare const BECH32M_CHARS = "";
5
5
  export declare const DID_REGEX: RegExp;
@@ -172,7 +172,7 @@ export declare class DidDocument implements IDidDocument {
172
172
  * Validate the IntermediateDidDocument.
173
173
  * @returns {boolean} True if the IntermediateDidDocument is valid.
174
174
  */
175
- validateIntermediate(): void;
175
+ validateIntermediate(): boolean;
176
176
  /**
177
177
  * Convert the DidDocument to an IntermediateDidDocument.
178
178
  * @returns {IntermediateDidDocument} The IntermediateDidDocument representation of the DidDocument.
@@ -187,7 +187,19 @@ export declare class DidDocument implements IDidDocument {
187
187
  * @extends {DidDocument}
188
188
  */
189
189
  export declare class IntermediateDidDocument extends DidDocument {
190
- constructor(document: IDidDocument);
190
+ constructor(document: JSONObject);
191
+ /**
192
+ * Convert the IntermediateDidDocument to a DidDocument by replacing the placeholder value with the provided DID.
193
+ * @param did The DID to replace the placeholder value in the document.
194
+ * @returns {DidDocument} A new DidDocument with the placeholder value replaced by the provided DID.
195
+ */
196
+ toDidDocument(did: string): DidDocument;
197
+ /**
198
+ * Create an IntermediateDidDocument from a DidDocument by replacing the DID with a placeholder value.
199
+ * @param {DidDocument} didDocument The DidDocument to convert.
200
+ * @returns {IntermediateDidDocument} The IntermediateDidDocument representation of the DidDocument.
201
+ */
202
+ static fromDidDocument(didDocument: DidDocument): IntermediateDidDocument;
191
203
  /**
192
204
  * Create a minimal IntermediateDidDocument with a placeholder ID.
193
205
  * @param {Array<DidVerificationMethod>} verificationMethod The public key in multibase format.
@@ -197,15 +209,18 @@ export declare class IntermediateDidDocument extends DidDocument {
197
209
  */
198
210
  static create(verificationMethod: Array<DidVerificationMethod>, relationships: VerificationRelationships, service: Array<BeaconService>): IntermediateDidDocument;
199
211
  /**
200
- * Convert the IntermediateDidDocument to a DidDocument by replacing the placeholder value with the provided DID.
201
- * @param did The DID to replace the placeholder value in the document.
202
- * @returns {DidDocument} A new DidDocument with the placeholder value replaced by the provided DID.
212
+ * Create a minimal IntermediateDidDocument from a public key.
213
+ * @param {KeyBytes} publicKey The public key in bytes format.
214
+ * @returns {IntermediateDidDocument} A new IntermediateDidDocument with the placeholder ID.
203
215
  */
204
- toDidDocument(did: string): DidDocument;
216
+ static fromPublicKey(publicKey: KeyBytes, network: string): IntermediateDidDocument;
205
217
  /**
206
- * Create a DidDocument from a JSON object.
218
+ * Taken an object, convert it to an IntermediateDocuemnt and then to a DidDocument.
207
219
  * @param {JSONObject} object The JSON object to convert.
208
220
  * @returns {DidDocument} The created DidDocument.
209
221
  */
210
- static from(object: JSONObject): DidDocument;
222
+ static fromJSON(object: JSONObject): IntermediateDidDocument;
223
+ }
224
+ export declare class Document {
225
+ static isValid(didDocument: DidDocument | IntermediateDidDocument): boolean;
211
226
  }
@@ -1 +1 @@
1
- {"version":3,"file":"did-document.d.ts","sourceRoot":"","sources":["../../../src/utils/did-document.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,UAAU,EAEX,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAc,qBAAqB,IAAI,uBAAuB,EAAE,WAAW,IAAI,aAAa,EAAE,MAAM,YAAY,CAAC;AACxH,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAKzD,eAAO,MAAM,aAAa,KAAK,CAAC;AAChC,eAAO,MAAM,SAAS,QAAuD,CAAC;AAE9E,MAAM,MAAM,YAAY,GAAG;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,kBAAkB,EAAE,KAAK,CAAC,qBAAqB,CAAC,CAAC;IACjD,cAAc,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,qBAAqB,CAAC,CAAC;IACvD,eAAe,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,qBAAqB,CAAC,CAAC;IACxD,oBAAoB,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,qBAAqB,CAAC,CAAC;IAC7D,oBAAoB,CAAC,EAAE,KAAK,CAAC,MAAM,GAAG,qBAAqB,CAAC,CAAC;IAC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;;;;OAMG;WACW,MAAM,CAClB,kBAAkB,EAAE,KAAK,CAAC,qBAAqB,CAAC,EAChD,aAAa,EAAE,yBAAyB,EACxC,OAAO,EAAE,KAAK,CAAC,aAAa,CAAC,GAC5B,uBAAuB;IAK1B;;;;OAIG;WACW,aAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,GAAG,uBAAuB;IA6B1F;;;;OAIG;WACW,QAAQ,CAAC,MAAM,EAAE,UAAU,GAAG,uBAAuB;CAGpE;AAED,qBAAa,QAAQ;WACL,OAAO,CAAC,WAAW,EAAE,WAAW,GAAG,uBAAuB,GAAG,OAAO;CAGnF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@did-btcr2/method",
3
- "version": "0.16.0",
3
+ "version": "0.17.1",
4
4
  "type": "module",
5
5
  "description": "Javascript/TypeScript reference implementation of did:btcr2 method, a censorship resistant DID Method using the Bitcoin blockchain as a Verifiable Data Registry to announce changes to the DID document. Core package of the did-btcr2-js monorepo.",
6
6
  "main": "./dist/cjs/index.js",
@@ -83,10 +83,10 @@
83
83
  "multiformats": "^13.3.1",
84
84
  "nostr-tools": "^2.15.0",
85
85
  "tiny-secp256k1": "^2.2.3",
86
- "@did-btcr2/bitcoin": "0.3.0",
87
- "@did-btcr2/common": "2.2.0",
88
- "@did-btcr2/cryptosuite": "3.2.0",
89
- "@did-btcr2/keypair": "0.6.0"
86
+ "@did-btcr2/bitcoin": "0.3.1",
87
+ "@did-btcr2/cryptosuite": "3.2.1",
88
+ "@did-btcr2/common": "2.2.1",
89
+ "@did-btcr2/keypair": "0.7.0"
90
90
  },
91
91
  "devDependencies": {
92
92
  "@eslint/js": "^9.22.0",
@@ -67,7 +67,7 @@ export class NostrAdapter implements ProtocolService {
67
67
  */
68
68
  public generateIdentity(): string {
69
69
  this.config.keys.secret = Secp256k1SecretKey.random();
70
- this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret);
70
+ this.config.keys.public = Secp256k1SecretKey.getPublicKey(this.config.keys.secret).compressed;
71
71
  this.config.did = Identifier.encode(
72
72
  {
73
73
  idType : this.config.components.idType || 'KEY',
@@ -21,6 +21,18 @@ import { DidDocument, DidVerificationMethod } from '../../utils/did-document.js'
21
21
  import { BeaconFactory } from '../beacon/factory.js';
22
22
  import { KeyManager } from '../key-manager/index.js';
23
23
 
24
+ export interface ConstructUpdateParams {
25
+ identifier: string;
26
+ sourceDocument: DidDocument;
27
+ sourceVersionId: number;
28
+ patch: PatchOperation[];
29
+ }
30
+
31
+ export interface UpdateParams extends ConstructUpdateParams {
32
+ verificationMethodId: string;
33
+ beaconIds: string[];
34
+ }
35
+
24
36
  export type InvokePayloadParams = {
25
37
  identifier: string;
26
38
  didUpdatePayload: DidUpdatePayload;
@@ -154,7 +166,7 @@ export class Update {
154
166
  ? await KeyManager.getKeyPair(fullId)
155
167
  // 1.2 If not, use the secretKeyMultibase from the verificationMethod
156
168
  : SchnorrMultikey
157
- .initialize({
169
+ .create({
158
170
  id,
159
171
  controller,
160
172
  keys : new SchnorrKeyPair({
package/src/did-btcr2.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import {
2
- MethodError,
3
- IdentifierTypes,
4
- INVALID_DID,
2
+ DocumentBytes,
5
3
  INVALID_DID_DOCUMENT,
4
+ KeyBytes,
6
5
  METHOD_NOT_SUPPORTED,
6
+ MethodError,
7
7
  PatchOperation,
8
8
  W3C_DID_RESOLUTION_V1
9
9
  } from '@did-btcr2/common';
@@ -17,13 +17,22 @@ import {
17
17
  } from '@web5/dids';
18
18
  import { initEccLib } from 'bitcoinjs-lib';
19
19
  import * as tinysecp from 'tiny-secp256k1';
20
- import { Create, CreateParams, CreateResponse } from './core/crud/create.js';
21
20
  import { Resolve } from './core/crud/read.js';
22
21
  import { Update } from './core/crud/update.js';
23
22
  import { DidResolutionOptions } from './interfaces/crud.js';
24
23
  import { Appendix } from './utils/appendix.js';
25
24
  import { DidDocument, DidVerificationMethod } from './utils/did-document.js';
26
25
  import { Identifier } from './utils/identifier.js';
26
+ import { SignalsMetadata } from './types/crud.js';
27
+
28
+ export type Btcr2Identifier = string;
29
+
30
+ export interface DidCreateOptions {
31
+ /** DID BTCR2 Version Number */
32
+ version?: number;
33
+ /** Bitcoin Network */
34
+ network?: string;
35
+ }
27
36
 
28
37
  /** Initialize tiny secp256k1 */
29
38
  initEccLib(tinysecp);
@@ -37,7 +46,7 @@ initEccLib(tinysecp);
37
46
  *
38
47
  * @class DidBtcr2
39
48
  * @type {DidBtcr2}
40
- *
49
+ * @implements {DidMethod}
41
50
  */
42
51
  export class DidBtcr2 implements DidMethod {
43
52
  /** @type {string} Name of the DID method, as defined in the DID BTCR2 specification */
@@ -61,30 +70,21 @@ export class DidBtcr2 implements DidMethod {
61
70
  * @returns {Promise<CreateResponse>} Promise resolving to a CreateResponse object.
62
71
  * @throws {DidBtcr2Error} if any of the checks fail
63
72
  */
64
- public static async create(params: CreateParams): Promise<CreateResponse> {
73
+ public static async create(params: {
74
+ idType: 'KEY' | 'EXTERNAL';
75
+ genesisBytes: KeyBytes | DocumentBytes;
76
+ options?: DidCreateOptions;
77
+ }): Promise<Btcr2Identifier> {
65
78
  // Deconstruct the idType and options from the params
66
79
  const { idType, options = {} } = params;
67
80
 
68
- // If idType is key, call Create.deterministic
69
- if(idType === IdentifierTypes.KEY) {
70
- // Deconstruct the pubKeyBytes from the params
71
- const { pubKeyBytes } = params;
81
+ // Deconstruct the version and network from the options, setting defaults if not given
82
+ const { version = 1, network = 'bitcoin' } = options;
72
83
 
73
- // Return call to Create.deterministic
74
- return Create.deterministic({ pubKeyBytes, options });
75
- }
76
-
77
- // If idType is external, call Create.external
78
- if(idType === IdentifierTypes.EXTERNAL) {
79
- // Deconstruct the intermediateDocument from the params
80
- const { intermediateDocument } = params;
81
-
82
- // Return call to Create.external
83
- return await Create.external({ intermediateDocument, options });
84
- }
84
+ // Set the genesisBytes from the params
85
+ const genesisBytes = params.genesisBytes;
85
86
 
86
- // Throw error if idType is not key or external
87
- throw new MethodError('Invalid idType: expected "KEY" or "EXTERNAL"', INVALID_DID, params);
87
+ return Identifier.encode({ idType, genesisBytes, version, network });
88
88
  }
89
89
 
90
90
  /**
@@ -189,7 +189,7 @@ export class DidBtcr2 implements DidMethod {
189
189
  patch: PatchOperation[];
190
190
  verificationMethodId: string;
191
191
  beaconIds: string[];
192
- }): Promise<any> {
192
+ }): Promise<SignalsMetadata> {
193
193
  // Deconstruct the params
194
194
  const {
195
195
  identifier,
package/src/index.ts CHANGED
@@ -3,7 +3,6 @@ export * from './core/beacon/factory.js';
3
3
  export * from './core/beacon/singleton.js';
4
4
  export * from './core/beacon/smt-aggregate.js';
5
5
 
6
- export * from './core/crud/create.js';
7
6
  export * from './core/crud/deactivate.js';
8
7
  export * from './core/crud/read.js';
9
8
  export * from './core/crud/update.js';
@@ -1,13 +1,16 @@
1
+ import { getNetwork } from '@did-btcr2/bitcoin';
1
2
  import {
2
3
  BTCR2_DID_DOCUMENT_CONTEXT,
3
- IdentifierTypes,
4
4
  DidDocumentError,
5
5
  ID_PLACEHOLDER_VALUE,
6
+ IdentifierTypes,
6
7
  INVALID_DID_DOCUMENT,
7
8
  JSONObject,
9
+ KeyBytes,
8
10
  Logger
9
11
  } from '@did-btcr2/common';
10
- import { DidService, DidVerificationMethod as IIDidVerificationMethod, DidDocument as IIDidDocument } from '@web5/dids';
12
+ import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
13
+ import { DidService, DidDocument as IIDidDocument, DidVerificationMethod as IIDidVerificationMethod } from '@web5/dids';
11
14
  import { BeaconService } from '../interfaces/ibeacon.js';
12
15
  import { Appendix } from './appendix.js';
13
16
  import { BeaconUtils } from './beacons.js';
@@ -120,6 +123,7 @@ export class DidDocument implements IDidDocument {
120
123
  service: Array<BeaconService>;
121
124
 
122
125
  constructor(document: IDidDocument) {
126
+ console.log('Constructing DidDocument with document:', document);
123
127
  // Set the ID and ID type
124
128
  const idType = document.id.includes('k1')
125
129
  ? IdentifierTypes.KEY
@@ -388,7 +392,7 @@ export class DidDocument implements IDidDocument {
388
392
  * Validate the IntermediateDidDocument.
389
393
  * @returns {boolean} True if the IntermediateDidDocument is valid.
390
394
  */
391
- public validateIntermediate(): void {
395
+ public validateIntermediate(): boolean {
392
396
  // Validate the id
393
397
  if(this.id !== ID_PLACEHOLDER_VALUE) {
394
398
  throw new DidDocumentError('Invalid IntermediateDidDocument ID', INVALID_DID_DOCUMENT, this);
@@ -409,6 +413,8 @@ export class DidDocument implements IDidDocument {
409
413
  // Return true if all validations pass
410
414
  throw new DidDocumentError('Invalid IntermediateDidDocument assertionMethod', INVALID_DID_DOCUMENT, this);
411
415
  }
416
+
417
+ return true;
412
418
  }
413
419
 
414
420
  /**
@@ -431,9 +437,30 @@ export class DidDocument implements IDidDocument {
431
437
  * @extends {DidDocument}
432
438
  */
433
439
  export class IntermediateDidDocument extends DidDocument {
434
- constructor(document: IDidDocument) {
435
- const intermediateDocument = JSON.cloneReplace(document, DID_REGEX, ID_PLACEHOLDER_VALUE) as IDidDocument;
436
- super(intermediateDocument);
440
+ constructor(document: JSONObject) {
441
+ super(document as IDidDocument);
442
+ }
443
+
444
+ /**
445
+ * Convert the IntermediateDidDocument to a DidDocument by replacing the placeholder value with the provided DID.
446
+ * @param did The DID to replace the placeholder value in the document.
447
+ * @returns {DidDocument} A new DidDocument with the placeholder value replaced by the provided DID.
448
+ */
449
+ public toDidDocument(did: string): DidDocument {
450
+ const stringThis = JSON.stringify(this).replaceAll(ID_PLACEHOLDER_VALUE, did);
451
+ const parseThis = JSON.parse(stringThis) as IDidDocument;
452
+ return new DidDocument(parseThis);
453
+ }
454
+
455
+
456
+ /**
457
+ * Create an IntermediateDidDocument from a DidDocument by replacing the DID with a placeholder value.
458
+ * @param {DidDocument} didDocument The DidDocument to convert.
459
+ * @returns {IntermediateDidDocument} The IntermediateDidDocument representation of the DidDocument.
460
+ */
461
+ public static fromDidDocument(didDocument: DidDocument): IntermediateDidDocument {
462
+ const intermediateDocument = JSON.cloneReplace(didDocument, DID_REGEX, ID_PLACEHOLDER_VALUE) as IDidDocument;
463
+ return new IntermediateDidDocument(intermediateDocument);
437
464
  }
438
465
 
439
466
  /**
@@ -453,22 +480,51 @@ export class IntermediateDidDocument extends DidDocument {
453
480
  }
454
481
 
455
482
  /**
456
- * Convert the IntermediateDidDocument to a DidDocument by replacing the placeholder value with the provided DID.
457
- * @param did The DID to replace the placeholder value in the document.
458
- * @returns {DidDocument} A new DidDocument with the placeholder value replaced by the provided DID.
483
+ * Create a minimal IntermediateDidDocument from a public key.
484
+ * @param {KeyBytes} publicKey The public key in bytes format.
485
+ * @returns {IntermediateDidDocument} A new IntermediateDidDocument with the placeholder ID.
459
486
  */
460
- public toDidDocument(did: string): DidDocument {
461
- const stringThis = JSON.stringify(this).replaceAll(ID_PLACEHOLDER_VALUE, did);
462
- const parseThis = JSON.parse(stringThis) as IDidDocument;
463
- return new DidDocument(parseThis);
487
+ public static fromPublicKey(publicKey: KeyBytes, network: string): IntermediateDidDocument {
488
+ const pk = new CompressedSecp256k1PublicKey(publicKey);
489
+ const id = ID_PLACEHOLDER_VALUE;
490
+ const service = BeaconUtils.generateBeaconService({
491
+ id : `${id}#key-0`,
492
+ publicKey : pk.compressed,
493
+ network : getNetwork(network),
494
+ addressType : 'p2pkh',
495
+ type : 'SingletonBeacon',
496
+ });
497
+
498
+ const relationships = {
499
+ authentication : [`${id}#key-0`],
500
+ assertionMethod : [`${id}#key-0`],
501
+ capabilityInvocation : [`${id}#key-0`],
502
+ capabilityDelegation : [`${id}#key-0`]
503
+ };
504
+ const verificationMethod = [
505
+ {
506
+ id : `${id}#key-0`,
507
+ type : 'Multikey',
508
+ controller : id,
509
+ publicKeyMultibase : pk.multibase.encoded,
510
+ }
511
+ ];
512
+
513
+ return IntermediateDidDocument.create(verificationMethod, relationships, [service]);
464
514
  }
465
515
 
466
516
  /**
467
- * Create a DidDocument from a JSON object.
517
+ * Taken an object, convert it to an IntermediateDocuemnt and then to a DidDocument.
468
518
  * @param {JSONObject} object The JSON object to convert.
469
519
  * @returns {DidDocument} The created DidDocument.
470
520
  */
471
- public static from(object: JSONObject): DidDocument {
472
- return new IntermediateDidDocument(object as IDidDocument).toDidDocument(object.id as string);
521
+ public static fromJSON(object: JSONObject): IntermediateDidDocument {
522
+ return new IntermediateDidDocument(object as IDidDocument);
523
+ }
524
+ }
525
+
526
+ export class Document {
527
+ public static isValid(didDocument: DidDocument | IntermediateDidDocument): boolean {
528
+ return new DidDocument(didDocument).validateIntermediate();
473
529
  }
474
530
  }
@@ -1,102 +0,0 @@
1
- import { IdentifierTypes } from '@did-btcr2/common';
2
- import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
3
- import { getNetwork } from '@did-btcr2/bitcoin';
4
- import { BeaconUtils } from '../../utils/beacons.js';
5
- import { DidDocument } from '../../utils/did-document.js';
6
- import { Identifier } from '../../utils/identifier.js';
7
- /**
8
- * Implements section {@link https://dcdpr.github.io/did-btcr2/#create | 4.1 Create}.
9
- *
10
- * A did:btcr2 identifier and associated DID document can either be created deterministically from a cryptographic seed,
11
- * or it can be created from an arbitrary genesis intermediate DID document representation. In both cases, DID creation
12
- * can be undertaken in an offline manner, i.e., the DID controller does not need to interact with the Bitcoin network
13
- * to create their DID.
14
- *
15
- * @class Create
16
- * @type {Create}
17
- */
18
- export class Create {
19
- /**
20
- * Implements {@link https://dcdpr.github.io/did-btcr2/#deterministic-key-based-creation | 4.1.1 Deterministic Key-Based Creation}.
21
- *
22
- * For deterministic key-based creation, the did:btcr2 identifier encodes a secp256k1 public key. The key is then used
23
- * to deterministically generate the initial DID document.
24
- *
25
- * @param {CreateKeyParams} params See {@link CreateKeyParams} for details.
26
- * @param {number} params.version did-btcr2 identifier version.
27
- * @param {string} params.network did-btcr2 bitcoin network.
28
- * @param {KeyBytes} params.pubKeyBytes public key bytes for id creation.
29
- * @returns {CreateResponse} A response object of type {@link CreateResponse}.
30
- * @throws {DidError} if the public key is missing or invalid.
31
- */
32
- static deterministic({ pubKeyBytes, options }) {
33
- // Deconstruct options and set the default values
34
- const { version = 1, network = 'bitcoin' } = options;
35
- // Set idType to "KEY"
36
- const idType = IdentifierTypes.KEY;
37
- // Call the the did:btcr2 Identifier Encoding algorithm
38
- const identifier = Identifier.encode({ version, network, idType, genesisBytes: pubKeyBytes });
39
- // Instantiate CompressedSecp256k1PublicKey object and get the multibase formatted publicKey
40
- const { compressed: publicKey, multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(pubKeyBytes);
41
- // Generate the service field for the DID Document
42
- const service = BeaconUtils.generateBeaconServices({
43
- identifier,
44
- publicKey,
45
- network: getNetwork(network),
46
- type: 'SingletonBeacon',
47
- });
48
- // Create initialDocument ensuring conformant to spec as DidDocument
49
- const initialDocument = new DidDocument({
50
- id: identifier,
51
- controller: [identifier],
52
- verificationMethod: [{
53
- id: `${identifier}#initialKey`,
54
- type: 'Multikey',
55
- controller: identifier,
56
- publicKeyMultibase: publicKeyMultibase.encoded,
57
- }],
58
- service,
59
- });
60
- // Return did & initialDocument
61
- return { did: identifier, initialDocument };
62
- }
63
- /**
64
- * Implements {@link https://dcdpr.github.io/did-btcr2/#external-initial-document-creation | 4.1.2 External Initial Document Creation}.
65
- *
66
- * Creates a did:btcr2 identifier from some initiating arbitrary DID document. This allows for more complex
67
- * initial DID documents, including the ability to include Service Endpoints and Beacons that support aggregation.
68
- * Inputs include `intermediateDocument`, optional version and network returning initialDidDocument. The
69
- * intermediateDocument should be a valid DID document except all places where the DID document requires the use of
70
- * the identifier (e.g. the id field). These fields should use placeholder value
71
- * `did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`. The intermediateDocument should include at
72
- * least one verificationMethod and service of the type SingletonBeacon.
73
- *
74
- * @param {CreateExternalParams} params See {@link CreateExternalParams} for details.
75
- * @param {number} params.version Identifier version.
76
- * @param {string} params.network Identifier network name.
77
- * @param {string} params.documentBytes Intermediate DID Document bytes.
78
- * @returns {CreateResponse} A Promise resolving to {@link CreateResponses}.
79
- * @throws {DidError} if the verificationMethod or service objects are missing required properties
80
- */
81
- static async external({ intermediateDocument, options }) {
82
- // 1. Set idType to "EXTERNAL"
83
- const idType = IdentifierTypes.EXTERNAL;
84
- // 2. Set version to 1
85
- // 3. Set network to the desired network.
86
- const { version = 1, network = 'bitcoin' } = options;
87
- // Validate intermediateDocument
88
- intermediateDocument.validateIntermediate();
89
- // 4. Set genesisBytes to the result of passing intermediateDocument into the JSON Canonicalization and Hash
90
- // algorithm.
91
- const genesisBytes = await JSON.canonicalization.canonicalhash(intermediateDocument);
92
- // 5. Pass idType, version, network, and genesisBytes to the did:btcr2 Identifier Encoding algorithm, retrieving id.
93
- // 6. Set did to id
94
- const did = Identifier.encode({ idType, genesisBytes, version, network });
95
- // 7. Set initialDocument to a copy of the intermediateDocument.
96
- // 8. Replace all did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx values in the initialDocument with the did.
97
- const initialDocument = intermediateDocument.toDidDocument(did);
98
- // Return DID & DID Document.
99
- return { did, initialDocument };
100
- }
101
- }
102
- //# sourceMappingURL=create.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"create.js","sourceRoot":"","sources":["../../../../src/core/crud/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAA4B,MAAM,mBAAmB,CAAC;AAC9E,OAAO,EAAE,4BAA4B,EAAE,MAAM,oBAAoB,CAAC;AAElE,OAAO,EAAE,UAAU,EAAE,MAAO,oBAAoB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,WAAW,EAA2B,MAAM,6BAA6B,CAAC;AACnF,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAwCvD;;;;;;;;;;GAUG;AACH,MAAM,OAAO,MAAM;IACjB;;;;;;;;;;;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