@did-btcr2/method 0.16.0 → 0.17.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.
Files changed (41) hide show
  1. package/dist/browser.js +101 -121
  2. package/dist/browser.mjs +101 -121
  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.map +1 -1
  6. package/dist/cjs/did-btcr2.js +7 -19
  7. package/dist/cjs/did-btcr2.js.map +1 -1
  8. package/dist/cjs/index.js +0 -1
  9. package/dist/cjs/index.js.map +1 -1
  10. package/dist/cjs/utils/did-document.js +61 -13
  11. package/dist/cjs/utils/did-document.js.map +1 -1
  12. package/dist/esm/core/beacon/aggregation/protocol/nostr.js +1 -1
  13. package/dist/esm/core/beacon/aggregation/protocol/nostr.js.map +1 -1
  14. package/dist/esm/core/crud/update.js.map +1 -1
  15. package/dist/esm/did-btcr2.js +7 -19
  16. package/dist/esm/did-btcr2.js.map +1 -1
  17. package/dist/esm/index.js +0 -1
  18. package/dist/esm/index.js.map +1 -1
  19. package/dist/esm/utils/did-document.js +61 -13
  20. package/dist/esm/utils/did-document.js.map +1 -1
  21. package/dist/types/core/crud/update.d.ts +10 -0
  22. package/dist/types/core/crud/update.d.ts.map +1 -1
  23. package/dist/types/did-btcr2.d.ts +14 -4
  24. package/dist/types/did-btcr2.d.ts.map +1 -1
  25. package/dist/types/index.d.ts +0 -1
  26. package/dist/types/index.d.ts.map +1 -1
  27. package/dist/types/utils/did-document.d.ts +25 -10
  28. package/dist/types/utils/did-document.d.ts.map +1 -1
  29. package/package.json +3 -3
  30. package/src/core/beacon/aggregation/protocol/nostr.ts +1 -1
  31. package/src/core/crud/update.ts +12 -0
  32. package/src/did-btcr2.ts +23 -24
  33. package/src/index.ts +0 -1
  34. package/src/utils/did-document.ts +72 -16
  35. package/dist/cjs/core/crud/create.js +0 -102
  36. package/dist/cjs/core/crud/create.js.map +0 -1
  37. package/dist/esm/core/crud/create.js +0 -102
  38. package/dist/esm/core/crud/create.js.map +0 -1
  39. package/dist/types/core/crud/create.d.ts +0 -92
  40. package/dist/types/core/crud/create.d.ts.map +0 -1
  41. package/src/core/crud/create.ts +0 -160
@@ -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
- }