@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,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;;;;;;;;;;;;OAYG;IACI,MAAM,CAAC,aAAa,CAAC,EAAE,WAAW,EAAE,OAAO,EAGjD;QACC,iDAAiD;QACjD,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;QAErD,sBAAsB;QACtB,MAAM,MAAM,GAAG,eAAe,CAAC,GAAG,CAAC;QAEnC,uDAAuD;QACvD,MAAM,UAAU,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,EAAE,CAAC,CAAC;QAE9F,4FAA4F;QAC5F,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,kBAAkB,EAAE,GAAG,IAAI,4BAA4B,CAAC,WAAW,CAAC,CAAC;QAE/G,kDAAkD;QAClD,MAAM,OAAO,GAAG,WAAW,CAAC,sBAAsB,CAAC;YACjD,UAAU;YACV,SAAS;YACT,OAAO,EAAG,UAAU,CAAC,OAAO,CAAC;YAC7B,IAAI,EAAM,iBAAiB;SAC5B,CAAC,CAAC;QAEH,oEAAoE;QACpE,MAAM,eAAe,GAAG,IAAI,WAAW,CAAC;YACtC,EAAE,EAAmB,UAAU;YAC/B,UAAU,EAAW,CAAC,UAAU,CAAC;YACjC,kBAAkB,EAAG,CAAC;oBACpB,EAAE,EAAmB,GAAG,UAAU,aAAa;oBAC/C,IAAI,EAAiB,UAAU;oBAC/B,UAAU,EAAW,UAAU;oBAC/B,kBAAkB,EAAG,kBAAkB,CAAC,OAAO;iBAChD,CAAC;YACF,OAAO;SACR,CAAC,CAAC;QAEH,+BAA+B;QAC/B,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,eAAe,EAAE,CAAC;IAC9C,CAAC;IAED;;;;;;;;;;;;;;;;;OAiBG;IACI,MAAM,CAAC,KAAK,CAAC,QAAQ,CAAC,EAAE,oBAAoB,EAAE,OAAO,EAG3D;QACC,8BAA8B;QAC9B,MAAM,MAAM,GAAG,eAAe,CAAC,QAAQ,CAAC;QAExC,sBAAsB;QACtB,yCAAyC;QACzC,MAAM,EAAE,OAAO,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,EAAE,GAAG,OAAO,CAAC;QAErD,gCAAgC;QAChC,oBAAoB,CAAC,oBAAoB,EAAE,CAAC;QAE5C,4GAA4G;QAC5G,gBAAgB;QAChB,MAAM,YAAY,GAAG,MAAM,IAAI,CAAC,gBAAgB,CAAC,aAAa,CAAC,oBAAoB,CAAC,CAAC;QAErF,oHAAoH;QACpH,mBAAmB;QACnB,MAAM,GAAG,GAAG,UAAU,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,OAAO,EAAE,CAAC,CAAC;QAE1E,gEAAgE;QAChE,oIAAoI;QACpI,MAAM,eAAe,GAAG,oBAAoB,CAAC,aAAa,CAAC,GAAG,CAAC,CAAC;QAEhE,6BAA6B;QAC7B,OAAO,EAAE,GAAG,EAAE,eAAe,EAAE,CAAC;IAClC,CAAC;CACF"}
@@ -1,92 +0,0 @@
1
- import { KeyBytes, PatchOperation } from '@did-btcr2/common';
2
- import { DidCreateOptions as IDidCreateOptions } from '@web5/dids';
3
- import { DidDocument, IntermediateDidDocument } from '../../utils/did-document.js';
4
- import { KeyManager } from '../key-manager/index.js';
5
- export type CreateParams = CreateKeyParams | CreateExternalParams;
6
- export interface CreateIdentifierParams {
7
- genesisBytes: Uint8Array;
8
- newtork?: string;
9
- version?: string;
10
- }
11
- export type CreateResponse = {
12
- did: string;
13
- initialDocument: DidDocument;
14
- };
15
- export interface ConstructUpdateParams {
16
- identifier: string;
17
- sourceDocument: DidDocument;
18
- sourceVersionId: number;
19
- patch: PatchOperation[];
20
- }
21
- export interface UpdateParams extends ConstructUpdateParams {
22
- verificationMethodId: string;
23
- beaconIds: string[];
24
- }
25
- export interface DidCreateOptions extends IDidCreateOptions<KeyManager> {
26
- /** DID BTCR2 Version Number */
27
- version?: number;
28
- /** Bitcoin Network */
29
- network?: string;
30
- }
31
- export type CreateKeyParams = {
32
- idType: 'KEY';
33
- pubKeyBytes: KeyBytes;
34
- options?: DidCreateOptions;
35
- };
36
- export type CreateExternalParams = {
37
- idType: 'EXTERNAL';
38
- intermediateDocument: IntermediateDidDocument;
39
- options?: DidCreateOptions;
40
- };
41
- /**
42
- * Implements section {@link https://dcdpr.github.io/did-btcr2/#create | 4.1 Create}.
43
- *
44
- * A did:btcr2 identifier and associated DID document can either be created deterministically from a cryptographic seed,
45
- * or it can be created from an arbitrary genesis intermediate DID document representation. In both cases, DID creation
46
- * can be undertaken in an offline manner, i.e., the DID controller does not need to interact with the Bitcoin network
47
- * to create their DID.
48
- *
49
- * @class Create
50
- * @type {Create}
51
- */
52
- export declare class Create {
53
- /**
54
- * Implements {@link https://dcdpr.github.io/did-btcr2/#deterministic-key-based-creation | 4.1.1 Deterministic Key-Based Creation}.
55
- *
56
- * For deterministic key-based creation, the did:btcr2 identifier encodes a secp256k1 public key. The key is then used
57
- * to deterministically generate the initial DID document.
58
- *
59
- * @param {CreateKeyParams} params See {@link CreateKeyParams} for details.
60
- * @param {number} params.version did-btcr2 identifier version.
61
- * @param {string} params.network did-btcr2 bitcoin network.
62
- * @param {KeyBytes} params.pubKeyBytes public key bytes for id creation.
63
- * @returns {CreateResponse} A response object of type {@link CreateResponse}.
64
- * @throws {DidError} if the public key is missing or invalid.
65
- */
66
- static deterministic({ pubKeyBytes, options }: {
67
- pubKeyBytes: KeyBytes;
68
- options: DidCreateOptions;
69
- }): CreateResponse;
70
- /**
71
- * Implements {@link https://dcdpr.github.io/did-btcr2/#external-initial-document-creation | 4.1.2 External Initial Document Creation}.
72
- *
73
- * Creates a did:btcr2 identifier from some initiating arbitrary DID document. This allows for more complex
74
- * initial DID documents, including the ability to include Service Endpoints and Beacons that support aggregation.
75
- * Inputs include `intermediateDocument`, optional version and network returning initialDidDocument. The
76
- * intermediateDocument should be a valid DID document except all places where the DID document requires the use of
77
- * the identifier (e.g. the id field). These fields should use placeholder value
78
- * `did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`. The intermediateDocument should include at
79
- * least one verificationMethod and service of the type SingletonBeacon.
80
- *
81
- * @param {CreateExternalParams} params See {@link CreateExternalParams} for details.
82
- * @param {number} params.version Identifier version.
83
- * @param {string} params.network Identifier network name.
84
- * @param {string} params.documentBytes Intermediate DID Document bytes.
85
- * @returns {CreateResponse} A Promise resolving to {@link CreateResponses}.
86
- * @throws {DidError} if the verificationMethod or service objects are missing required properties
87
- */
88
- static external({ intermediateDocument, options }: {
89
- intermediateDocument: IntermediateDidDocument;
90
- options: DidCreateOptions;
91
- }): Promise<CreateResponse>;
92
- }
@@ -1 +0,0 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../../src/core/crud/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,QAAQ,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAE9E,OAAO,EAAE,gBAAgB,IAAI,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,6BAA6B,CAAC;AAEnF,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAErD,MAAM,MAAM,YAAY,GAAG,eAAe,GAAG,oBAAoB,CAAC;AAClE,MAAM,WAAW,sBAAsB;IACrC,YAAY,EAAE,UAAU,CAAC;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,MAAM,cAAc,GAAG;IAC3B,GAAG,EAAE,MAAM,CAAC;IACZ,eAAe,EAAE,WAAW,CAAC;CAC9B,CAAC;AACF,MAAM,WAAW,qBAAqB;IAClC,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,EAAE,WAAW,CAAC;IAC5B,eAAe,EAAE,MAAM,CAAC;IACxB,KAAK,EAAE,cAAc,EAAE,CAAC;CAC3B;AACD,MAAM,WAAW,YAAa,SAAQ,qBAAqB;IACvD,oBAAoB,EAAE,MAAM,CAAC;IAC7B,SAAS,EAAE,MAAM,EAAE,CAAC;CACvB;AACD,MAAM,WAAW,gBAAiB,SAAQ,iBAAiB,CAAC,UAAU,CAAC;IACrE,+BAA+B;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,sBAAsB;IACtB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AACD,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,KAAK,CAAC;IACd,WAAW,EAAE,QAAQ,CAAC;IACtB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AACF,MAAM,MAAM,oBAAoB,GAAG;IACjC,MAAM,EAAE,UAAU,CAAC;IACnB,oBAAoB,EAAE,uBAAuB,CAAC;IAC9C,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC;AAEF;;;;;;;;;;GAUG;AACH,qBAAa,MAAM;IACjB;;;;;;;;;;;;OAYG;WACW,aAAa,CAAC,EAAE,WAAW,EAAE,OAAO,EAAE,EAAE;QACpD,WAAW,EAAE,QAAQ,CAAC;QACtB,OAAO,EAAE,gBAAgB,CAAC;KAC3B,GAAG,cAAc;IAsClB;;;;;;;;;;;;;;;;;OAiBG;WACiB,QAAQ,CAAC,EAAE,oBAAoB,EAAE,OAAO,EAAE,EAAE;QAC9D,oBAAoB,EAAE,uBAAuB,CAAC;QAC9C,OAAO,EAAE,gBAAgB,CAAC;KAC3B,GAAG,OAAO,CAAC,cAAc,CAAC;CA0B5B"}
@@ -1,160 +0,0 @@
1
- import { IdentifierTypes, KeyBytes, PatchOperation } from '@did-btcr2/common';
2
- import { CompressedSecp256k1PublicKey } from '@did-btcr2/keypair';
3
- import { DidCreateOptions as IDidCreateOptions } from '@web5/dids';
4
- import { getNetwork } from '@did-btcr2/bitcoin';
5
- import { BeaconUtils } from '../../utils/beacons.js';
6
- import { DidDocument, IntermediateDidDocument } from '../../utils/did-document.js';
7
- import { Identifier } from '../../utils/identifier.js';
8
- import { KeyManager } from '../key-manager/index.js';
9
-
10
- export type CreateParams = CreateKeyParams | CreateExternalParams;
11
- export interface CreateIdentifierParams {
12
- genesisBytes: Uint8Array;
13
- newtork?: string;
14
- version?: string;
15
- }
16
- export type CreateResponse = {
17
- did: string;
18
- initialDocument: DidDocument;
19
- };
20
- export interface ConstructUpdateParams {
21
- identifier: string;
22
- sourceDocument: DidDocument;
23
- sourceVersionId: number;
24
- patch: PatchOperation[];
25
- }
26
- export interface UpdateParams extends ConstructUpdateParams {
27
- verificationMethodId: string;
28
- beaconIds: string[];
29
- }
30
- export interface DidCreateOptions extends IDidCreateOptions<KeyManager> {
31
- /** DID BTCR2 Version Number */
32
- version?: number;
33
- /** Bitcoin Network */
34
- network?: string;
35
- }
36
- export type CreateKeyParams = {
37
- idType: 'KEY';
38
- pubKeyBytes: KeyBytes;
39
- options?: DidCreateOptions;
40
- };
41
- export type CreateExternalParams = {
42
- idType: 'EXTERNAL';
43
- intermediateDocument: IntermediateDidDocument;
44
- options?: DidCreateOptions;
45
- };
46
-
47
- /**
48
- * Implements section {@link https://dcdpr.github.io/did-btcr2/#create | 4.1 Create}.
49
- *
50
- * A did:btcr2 identifier and associated DID document can either be created deterministically from a cryptographic seed,
51
- * or it can be created from an arbitrary genesis intermediate DID document representation. In both cases, DID creation
52
- * can be undertaken in an offline manner, i.e., the DID controller does not need to interact with the Bitcoin network
53
- * to create their DID.
54
- *
55
- * @class Create
56
- * @type {Create}
57
- */
58
- export class Create {
59
- /**
60
- * Implements {@link https://dcdpr.github.io/did-btcr2/#deterministic-key-based-creation | 4.1.1 Deterministic Key-Based Creation}.
61
- *
62
- * For deterministic key-based creation, the did:btcr2 identifier encodes a secp256k1 public key. The key is then used
63
- * to deterministically generate the initial DID document.
64
- *
65
- * @param {CreateKeyParams} params See {@link CreateKeyParams} for details.
66
- * @param {number} params.version did-btcr2 identifier version.
67
- * @param {string} params.network did-btcr2 bitcoin network.
68
- * @param {KeyBytes} params.pubKeyBytes public key bytes for id creation.
69
- * @returns {CreateResponse} A response object of type {@link CreateResponse}.
70
- * @throws {DidError} if the public key is missing or invalid.
71
- */
72
- public static deterministic({ pubKeyBytes, options }: {
73
- pubKeyBytes: KeyBytes;
74
- options: DidCreateOptions;
75
- }): CreateResponse {
76
- // Deconstruct options and set the default values
77
- const { version = 1, network = 'bitcoin' } = options;
78
-
79
- // Set idType to "KEY"
80
- const idType = IdentifierTypes.KEY;
81
-
82
- // Call the the did:btcr2 Identifier Encoding algorithm
83
- const identifier = Identifier.encode({ version, network, idType, genesisBytes: pubKeyBytes });
84
-
85
- // Instantiate CompressedSecp256k1PublicKey object and get the multibase formatted publicKey
86
- const { compressed: publicKey, multibase: publicKeyMultibase } = new CompressedSecp256k1PublicKey(pubKeyBytes);
87
-
88
- // Generate the service field for the DID Document
89
- const service = BeaconUtils.generateBeaconServices({
90
- identifier,
91
- publicKey,
92
- network : getNetwork(network),
93
- type : 'SingletonBeacon',
94
- });
95
-
96
- // Create initialDocument ensuring conformant to spec as DidDocument
97
- const initialDocument = new DidDocument({
98
- id : identifier,
99
- controller : [identifier],
100
- verificationMethod : [{
101
- id : `${identifier}#initialKey`,
102
- type : 'Multikey',
103
- controller : identifier,
104
- publicKeyMultibase : publicKeyMultibase.encoded,
105
- }],
106
- service,
107
- });
108
-
109
- // Return did & initialDocument
110
- return { did: identifier, initialDocument };
111
- }
112
-
113
- /**
114
- * Implements {@link https://dcdpr.github.io/did-btcr2/#external-initial-document-creation | 4.1.2 External Initial Document Creation}.
115
- *
116
- * Creates a did:btcr2 identifier from some initiating arbitrary DID document. This allows for more complex
117
- * initial DID documents, including the ability to include Service Endpoints and Beacons that support aggregation.
118
- * Inputs include `intermediateDocument`, optional version and network returning initialDidDocument. The
119
- * intermediateDocument should be a valid DID document except all places where the DID document requires the use of
120
- * the identifier (e.g. the id field). These fields should use placeholder value
121
- * `did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`. The intermediateDocument should include at
122
- * least one verificationMethod and service of the type SingletonBeacon.
123
- *
124
- * @param {CreateExternalParams} params See {@link CreateExternalParams} for details.
125
- * @param {number} params.version Identifier version.
126
- * @param {string} params.network Identifier network name.
127
- * @param {string} params.documentBytes Intermediate DID Document bytes.
128
- * @returns {CreateResponse} A Promise resolving to {@link CreateResponses}.
129
- * @throws {DidError} if the verificationMethod or service objects are missing required properties
130
- */
131
- public static async external({ intermediateDocument, options }: {
132
- intermediateDocument: IntermediateDidDocument;
133
- options: DidCreateOptions;
134
- }): Promise<CreateResponse> {
135
- // 1. Set idType to "EXTERNAL"
136
- const idType = IdentifierTypes.EXTERNAL;
137
-
138
- // 2. Set version to 1
139
- // 3. Set network to the desired network.
140
- const { version = 1, network = 'bitcoin' } = options;
141
-
142
- // Validate intermediateDocument
143
- intermediateDocument.validateIntermediate();
144
-
145
- // 4. Set genesisBytes to the result of passing intermediateDocument into the JSON Canonicalization and Hash
146
- // algorithm.
147
- const genesisBytes = await JSON.canonicalization.canonicalhash(intermediateDocument);
148
-
149
- // 5. Pass idType, version, network, and genesisBytes to the did:btcr2 Identifier Encoding algorithm, retrieving id.
150
- // 6. Set did to id
151
- const did = Identifier.encode({ idType, genesisBytes, version, network });
152
-
153
- // 7. Set initialDocument to a copy of the intermediateDocument.
154
- // 8. Replace all did:btcr2:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx values in the initialDocument with the did.
155
- const initialDocument = intermediateDocument.toDidDocument(did);
156
-
157
- // Return DID & DID Document.
158
- return { did, initialDocument };
159
- }
160
- }