@dwn-protocol/id-sdk 0.2.5 → 0.2.6

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 (99) hide show
  1. package/package.json +2 -3
  2. package/src/agent/app-data-store.ts +0 -365
  3. package/src/agent/did-manager.ts +0 -393
  4. package/src/agent/dwn-manager.ts +0 -548
  5. package/src/agent/identity-manager.ts +0 -165
  6. package/src/agent/index.ts +0 -19
  7. package/src/agent/json-rpc.ts +0 -107
  8. package/src/agent/key-manager.ts +0 -302
  9. package/src/agent/kms-local.ts +0 -412
  10. package/src/agent/outbox.ts +0 -128
  11. package/src/agent/rpc-client.ts +0 -223
  12. package/src/agent/store-managed-did.ts +0 -295
  13. package/src/agent/store-managed-identity.ts +0 -243
  14. package/src/agent/store-managed-key.ts +0 -754
  15. package/src/agent/sync-manager.ts +0 -631
  16. package/src/agent/test-managed-agent.ts +0 -299
  17. package/src/agent/types/agent.ts +0 -145
  18. package/src/agent/types/managed-key.ts +0 -442
  19. package/src/agent/utils.ts +0 -190
  20. package/src/common/convert.ts +0 -424
  21. package/src/common/index.ts +0 -9
  22. package/src/common/multicodec.ts +0 -176
  23. package/src/common/object.ts +0 -43
  24. package/src/common/stores.ts +0 -125
  25. package/src/common/stream-node.ts +0 -381
  26. package/src/common/stream.ts +0 -406
  27. package/src/common/type-utils.ts +0 -117
  28. package/src/common/types.ts +0 -48
  29. package/src/credentials/credential-bbs.ts +0 -419
  30. package/src/credentials/credential.ts +0 -324
  31. package/src/credentials/index.ts +0 -5
  32. package/src/credentials/presentation.ts +0 -182
  33. package/src/credentials/status-list.ts +0 -365
  34. package/src/credentials/utils.ts +0 -58
  35. package/src/credentials/validators.ts +0 -52
  36. package/src/crypto/algorithms-api/aes/base.ts +0 -49
  37. package/src/crypto/algorithms-api/aes/ctr.ts +0 -51
  38. package/src/crypto/algorithms-api/aes/index.ts +0 -2
  39. package/src/crypto/algorithms-api/crypto-algorithm.ts +0 -127
  40. package/src/crypto/algorithms-api/crypto-key.ts +0 -56
  41. package/src/crypto/algorithms-api/ec/base.ts +0 -39
  42. package/src/crypto/algorithms-api/ec/ecdh.ts +0 -53
  43. package/src/crypto/algorithms-api/ec/ecdsa.ts +0 -37
  44. package/src/crypto/algorithms-api/ec/eddsa.ts +0 -30
  45. package/src/crypto/algorithms-api/ec/index.ts +0 -4
  46. package/src/crypto/algorithms-api/errors.ts +0 -29
  47. package/src/crypto/algorithms-api/index.ts +0 -6
  48. package/src/crypto/algorithms-api/pbkdf/index.ts +0 -1
  49. package/src/crypto/algorithms-api/pbkdf/pbkdf2.ts +0 -91
  50. package/src/crypto/crypto-algorithms/aes-ctr.ts +0 -70
  51. package/src/crypto/crypto-algorithms/bbs.ts +0 -110
  52. package/src/crypto/crypto-algorithms/ecdh.ts +0 -115
  53. package/src/crypto/crypto-algorithms/ecdsa.ts +0 -111
  54. package/src/crypto/crypto-algorithms/eddsa.ts +0 -110
  55. package/src/crypto/crypto-algorithms/index.ts +0 -6
  56. package/src/crypto/crypto-algorithms/pbkdf2.ts +0 -54
  57. package/src/crypto/crypto-primitives/aes-ctr.ts +0 -131
  58. package/src/crypto/crypto-primitives/aes-gcm.ts +0 -138
  59. package/src/crypto/crypto-primitives/bbs.ts +0 -183
  60. package/src/crypto/crypto-primitives/concat-kdf.ts +0 -207
  61. package/src/crypto/crypto-primitives/ed25519.ts +0 -201
  62. package/src/crypto/crypto-primitives/index.ts +0 -10
  63. package/src/crypto/crypto-primitives/pbkdf2.ts +0 -78
  64. package/src/crypto/crypto-primitives/secp256k1.ts +0 -322
  65. package/src/crypto/crypto-primitives/x25519.ts +0 -101
  66. package/src/crypto/crypto-primitives/xchacha20-poly1305.ts +0 -46
  67. package/src/crypto/crypto-primitives/xchacha20.ts +0 -34
  68. package/src/crypto/index.ts +0 -8
  69. package/src/crypto/jose.ts +0 -948
  70. package/src/crypto/types/crypto-key.ts +0 -4
  71. package/src/crypto/types/iddwn-crypto.ts +0 -119
  72. package/src/crypto/utils.ts +0 -200
  73. package/src/did-api.ts +0 -72
  74. package/src/dids/dht.ts +0 -412
  75. package/src/dids/did-dht.ts +0 -436
  76. package/src/dids/did-ion.ts +0 -613
  77. package/src/dids/did-key.ts +0 -791
  78. package/src/dids/did-resolver.ts +0 -107
  79. package/src/dids/index.ts +0 -9
  80. package/src/dids/resolver-cache-level.ts +0 -82
  81. package/src/dids/resolver-cache-noop.ts +0 -25
  82. package/src/dids/types.ts +0 -278
  83. package/src/dids/utils.ts +0 -129
  84. package/src/dwn-api.ts +0 -584
  85. package/src/iddwn.ts +0 -241
  86. package/src/identity-agent/index.ts +0 -270
  87. package/src/index.ts +0 -26
  88. package/src/interfaces/metadata.ts +0 -163
  89. package/src/interfaces/queue.ts +0 -108
  90. package/src/interfaces/services.ts +0 -122
  91. package/src/interfaces/transactions.ts +0 -220
  92. package/src/protocol.ts +0 -68
  93. package/src/proxy-agent/index.ts +0 -255
  94. package/src/record.ts +0 -521
  95. package/src/service-options.ts +0 -62
  96. package/src/typings/decentralized-identity__ion-pow-sdk.d.ts +0 -7
  97. package/src/user-agent/index.ts +0 -295
  98. package/src/utils.ts +0 -29
  99. package/src/vc-api.ts +0 -505
@@ -1,393 +0,0 @@
1
- import type { PublicKeyJwk, IDCrypto } from '../crypto/index.js';
2
- import type {
3
- DidKeySet,
4
- DidDocument,
5
- DidMetadata,
6
- PortableDid,
7
- DidMethodApi,
8
- DidIonCreateOptions,
9
- DidKeyCreateOptions,
10
- DidDhtCreateOptions,
11
- } from '../dids/index.js';
12
-
13
- import { Jose} from '../crypto/index.js';
14
- import { utils } from '../dids/index.js';
15
-
16
- import type { ManagedDidStore } from './store-managed-did.js';
17
- import type { DidRequest, DidResponse, IDManagedAgent } from './types/agent.js';
18
-
19
- import { DidStoreMemory } from './store-managed-did.js';
20
-
21
- export type CreateDidMethodOptions = {
22
- dht: DidDhtCreateOptions;
23
- ion: DidIonCreateOptions;
24
- key: DidKeyCreateOptions;
25
- };
26
-
27
- export type CreateDidOptions<M extends keyof CreateDidMethodOptions> = CreateDidMethodOptions[M] & {
28
- method: M;
29
- alias?: string;
30
- context?: string;
31
- kms?: string;
32
- metadata?: DidMetadata;
33
- }
34
-
35
- export enum DidMessage {
36
- Create = 'Create',
37
- Resolve = 'Resolve',
38
- }
39
-
40
- export type ImportDidOptions = {
41
- alias?: string;
42
- context?: string;
43
- did: PortableDid;
44
- kms?: string;
45
- }
46
-
47
- export interface ManagedDid extends PortableDid {
48
- /**
49
- * An alternate identifier used to identify the DID.
50
- * This property can be used to associate a DID with an external identifier.
51
- */
52
- alias?: string;
53
-
54
- /**
55
- * DID Method name.
56
- */
57
- method: string;
58
- }
59
-
60
- export type DidManagerOptions = {
61
- agent?: IDManagedAgent;
62
- didMethods: DidMethodApi[];
63
- store?: ManagedDidStore;
64
- }
65
-
66
- export type DidIonGenerateKeySetOptions = { /* empty */ }
67
- export type DidKeyGenerateKeySetOptions = { /* empty */ }
68
-
69
- export type GenerateKeySetOptions = {
70
- ion: DidIonGenerateKeySetOptions;
71
- key: DidKeyGenerateKeySetOptions;
72
- };
73
-
74
- export class DidManager {
75
- /**
76
- * Holds the instance of a `IDManagedAgent` that represents the current
77
- * execution context for the `KeyManager`. This agent is utilized
78
- * to interact with other agent components. It's vital
79
- * to ensure this instance is set to correctly contextualize
80
- * operations within the broader agent framework.
81
- */
82
- private _agent?: IDManagedAgent;
83
- private _didMethods: Map<string, DidMethodApi> = new Map();
84
- private _store: ManagedDidStore;
85
-
86
- constructor(options: DidManagerOptions) {
87
- const { agent, didMethods, store } = options;
88
- this._agent = agent;
89
- this._store = store ?? new DidStoreMemory();
90
-
91
- if (!didMethods) {
92
- throw new TypeError(`DidManager: Required parameter missing: 'didMethods'`);
93
- }
94
-
95
- for (const didMethod of didMethods) {
96
- this._didMethods.set(didMethod.methodName, didMethod);
97
- }
98
- }
99
-
100
- /**
101
- * Retrieves the `IDManagedAgent` execution context.
102
- * If the `agent` instance proprety is undefined, it will throw an error.
103
- *
104
- * @returns The `IDManagedAgent` instance that represents the current execution
105
- * context.
106
- *
107
- * @throws Will throw an error if the `agent` instance property is undefined.
108
- */
109
- get agent(): IDManagedAgent {
110
- if (this._agent === undefined) {
111
- throw new Error('DidManager: Unable to determine agent execution context.');
112
- }
113
-
114
- return this._agent;
115
- }
116
-
117
- set agent(agent: IDManagedAgent) {
118
- this._agent = agent;
119
- }
120
-
121
- async create<M extends keyof CreateDidMethodOptions>(options: CreateDidOptions<M>): Promise<ManagedDid> {
122
- let { alias, keySet, kms, metadata, method, context, ...methodOptions } = options;
123
-
124
- // Get the DID method implementation.
125
- const didMethod = this.getMethod(method);
126
-
127
- // If keySet not given, generate a DID method specific key set.
128
- if (keySet?.verificationMethodKeys === undefined) {
129
- keySet = await didMethod.generateKeySet();
130
- }
131
-
132
- /** Import key set to KeyManager, or if already in KeyManager, retrieve the
133
- * public key. */
134
- keySet = await this.importOrGetKeySet({ keySet, kms });
135
-
136
- // Create a DID.
137
- const did = await didMethod.create({ ...methodOptions, keySet });
138
-
139
- // Set the KeyManager alias for each key to the DID Document primary ID.
140
- await this.updateKeySet({
141
- canonicalId : did.canonicalId,
142
- didDocument : did.document,
143
- keySet
144
- });
145
-
146
- // Merged given metadata and format as a ManagedDid.
147
- const mergedMetadata = { ...metadata, ...did.metadata };
148
- const managedDid = { alias, method, ...did, metadata: mergedMetadata };
149
-
150
- /** If context is undefined, then the DID will be stored under the
151
- * tenant of the created DID. Otherwise, the DID record will
152
- * be stored under the tenant of the specified context. */
153
- context ??= managedDid.did;
154
-
155
- // Store the ManagedDid in the store.
156
- await this._store.importDid({ did: managedDid, agent: this.agent, context });
157
-
158
- return managedDid;
159
- }
160
-
161
- async getDefaultSigningKey(options: {
162
- did: string
163
- }): Promise<string | undefined> {
164
- const { did } = options;
165
-
166
- // Resolve the DID to a DID Document.
167
- const { didDocument } = await this.agent.didResolver.resolve(did);
168
-
169
- // Get the DID method implementation.
170
- const parsedDid = utils.parseDid({ didUrl: did });
171
-
172
- if (!(didDocument && parsedDid)) {
173
- throw new Error(`DidManager: Unable to resolve: ${did}`);
174
- }
175
-
176
- const didMethod = this.getMethod(parsedDid.method);
177
-
178
- // Retrieve the DID method specific default signing key.
179
- const verificationMethodId = await didMethod.getDefaultSigningKey({ didDocument });
180
-
181
- return verificationMethodId;
182
- }
183
-
184
- async get(options: {
185
- didRef: string,
186
- context?: string
187
- }): Promise<ManagedDid | undefined> {
188
- let did: ManagedDid | undefined;
189
- const { context, didRef } = options;
190
-
191
- // Try to get DID by ID.
192
- did = await this._store.getDid({ did: didRef, agent: this.agent, context });
193
- if (did) return did;
194
-
195
- // Try to find DID by alias.
196
- did = await this._store.findDid({ alias: didRef, agent: this.agent, context });
197
- if (did) return did;
198
-
199
- return undefined;
200
- }
201
-
202
- async import(options: ImportDidOptions): Promise<ManagedDid> {
203
- let { alias, context, did, kms } = options;
204
-
205
- if (did.keySet === undefined) {
206
- throw new Error(`Portable DID is missing required property: 'keySet'`);
207
- }
208
-
209
- // Verify the DID method is supported.
210
- const parsedDid = utils.parseDid({ didUrl: did.did });
211
- if (!parsedDid) {
212
- throw new Error(`DidManager: Unable to resolve: ${did}`);
213
- }
214
- const { method } = parsedDid;
215
- this.getMethod(method);
216
-
217
- /** Import key set to KeyManager, or if already in KeyManager, retrieve the
218
- * public key. */
219
- const keySet = await this.importOrGetKeySet({ keySet: did.keySet, kms });
220
-
221
- // Set the KeyManager alias for each key to the DID Document primary ID.
222
- await this.updateKeySet({
223
- canonicalId : did.canonicalId,
224
- didDocument : did.document,
225
- keySet
226
- });
227
-
228
- // Format the PortableDid and given input as a ManagedDid.
229
- const managedDid = { alias, method, ...did, keySet };
230
-
231
- /** If context is undefined, then the DID will be stored under the
232
- * tenant of the imported DID. Otherwise, the DID record will
233
- * be stored under the tenant of the specified context. */
234
- context ??= managedDid.did;
235
-
236
- // Store the ManagedDid in the store.
237
- await this._store.importDid({ did: managedDid, agent: this.agent, context });
238
-
239
- return managedDid;
240
- }
241
-
242
- /**
243
- * Retrieves a `DidMethodApi` instance associated with a specific method
244
- * name. This method uses the method name to access the `didMethods` map
245
- * and returns the corresponding `DidMethodApi` instance. If a method
246
- * name is provided that does not exist within the `didMethods` map, it
247
- * will throw an error.
248
- *
249
- * @param methodName - A string representing the name of the method for
250
- * which the corresponding `DidMethodApi` instance is to be retrieved.
251
- *
252
- * @returns The `DidMethodApi` instance that corresponds to the provided
253
- * method name. If no `DidMethodApi` instance corresponds to the provided
254
- * method name, an error is thrown.
255
- *
256
- * @throws Will throw an error if the provided method name does not
257
- * correspond to any `DidMethodApi` instance within the `didMethods` map.
258
- */
259
- private getMethod(methodName: string): DidMethodApi {
260
- const didMethod = this._didMethods.get(methodName);
261
-
262
- if (didMethod === undefined) {
263
- throw new Error(`The DID method '${methodName}' is not supported`);
264
- }
265
-
266
- return didMethod;
267
- }
268
-
269
- private async importOrGetKeySet(options: {
270
- keySet: DidKeySet,
271
- kms: string | undefined
272
- }): Promise<DidKeySet> {
273
- const { kms } = options;
274
-
275
- // Get the agent instance.
276
- const agent = this.agent;
277
-
278
- // Make a deep copy of the key set to prevent side effects.
279
- const keySet = structuredClone(options.keySet);
280
-
281
- for (let key of keySet.verificationMethodKeys!) {
282
- /**
283
- * The key has no `keyManagerId` value, indicating it is not present in
284
- * the KeyManager store. Import each key into KeyManager.
285
- */
286
- if (key.keyManagerId === undefined) {
287
- if ('publicKeyJwk' in key && 'privateKeyJwk' in key
288
- && key.publicKeyJwk && key.privateKeyJwk) {
289
- // Import key pair to KeyManager.
290
- const publicKey = await Jose.jwkToCryptoKey({ key: key.publicKeyJwk });
291
- const privateKey = await Jose.jwkToCryptoKey({ key: key.privateKeyJwk! });
292
- const importedKeyPair = await agent.keyManager.importKey({
293
- privateKey : { kms: kms, ...privateKey, material: privateKey.material },
294
- publicKey : { kms: kms, ...publicKey, material: publicKey.material }
295
- });
296
- // Store the UUID assigned by KeyManager.
297
- key.keyManagerId = importedKeyPair.privateKey.id;
298
- // Delete the private key.
299
- delete key.privateKeyJwk;
300
-
301
- } else if ('publicKeyJwk' in key && key.publicKeyJwk) {
302
- // Import only public key.
303
- const publicKey = await Jose.jwkToCryptoKey({ key: key.publicKeyJwk });
304
- const importedPublicKey = await agent.keyManager.importKey({
305
- kms: kms, ...publicKey, material: publicKey.material
306
- });
307
- // Store the UUID assigned by KeyManager.
308
- key.keyManagerId = importedPublicKey.id;
309
-
310
- } else {
311
- throw new Error(`Required parameter(s) missing: 'publicKeyJwk', and optionally, 'privateKeyJwk`);
312
- }
313
-
314
- /**
315
- * The key does have a `keyManagerId` value so retrieve the public key
316
- * from the KeyManager store.
317
- */
318
- } else {
319
- const keyOrKeyPair = await agent.keyManager.getKey({ keyRef: key.keyManagerId });
320
- if (!keyOrKeyPair) throw new Error(`Key with ID '${key.keyManagerId} not found.`);
321
- const publicKey = 'publicKey' in keyOrKeyPair ? keyOrKeyPair.publicKey : keyOrKeyPair;
322
- // Convert public key from CryptoKey to JWK format.
323
- key.publicKeyJwk = await Jose.cryptoKeyToJwk({ key: publicKey as IDCrypto.CryptoKey }) as PublicKeyJwk;
324
- }
325
- }
326
-
327
- return keySet;
328
- }
329
-
330
- public async processRequest(request: DidRequest): Promise<DidResponse> {
331
- const { messageOptions, messageType, store: _ } = request;
332
-
333
- switch (messageType) {
334
- case DidMessage.Create: {
335
- const result = await this.create(messageOptions);
336
- return { result };
337
- break;
338
- }
339
- default: {
340
- throw new Error(`DidManager: Unsupported request type: ${messageType}`);
341
- }
342
- }
343
- }
344
-
345
- /**
346
- * Set the KeyManager alias for each key to the DID primary ID.
347
- *
348
- * If defined, use the `canonicalId` as the primary ID for the
349
- * DID subject. Otherwise, use the `id` property from the topmost
350
- * map of the DID document.
351
- *
352
- * @see {@link https://www.w3.org/TR/did-core/#did-subject | DID Subject}
353
- * @see {@link https://www.w3.org/TR/did-core/#dfn-canonicalid | DID Document Metadata}
354
- */
355
- private async updateKeySet(options: {
356
- canonicalId?: string,
357
- didDocument: DidDocument,
358
- keySet: DidKeySet
359
- }) {
360
- const { canonicalId, didDocument, keySet, } = options;
361
-
362
- // Get the agent instance.
363
- const agent = this.agent;
364
-
365
- // DID primary ID is the canonicalId, if present, or the DID document `id`.
366
- const didPrimaryId = canonicalId ?? didDocument.id;
367
-
368
- for (let keyPair of keySet.verificationMethodKeys!) {
369
- /** Compute the multibase ID for the JWK in case the DID method uses
370
- * publicKeyMultibase format. */
371
- const publicKeyMultibase = await Jose.jwkToMultibaseId({ key: keyPair.publicKeyJwk! });
372
-
373
- // Find the verification method ID of the key in the DID document.
374
- const methodId = utils.getVerificationMethodIds({
375
- didDocument,
376
- publicKeyJwk: keyPair.publicKeyJwk,
377
- publicKeyMultibase
378
- });
379
-
380
- if (!(methodId && methodId.includes('#'))) {
381
- throw new Error('DidManager: Unable to update key set due to malformed verification method ID');
382
- }
383
-
384
- /** Construct the key alias given the DID's primary ID and the key's
385
- * verification method ID. */
386
- const [, fragment] = methodId.split('#');
387
- const keyAlias = `${didPrimaryId}#${fragment}`;
388
-
389
- // Set the KeyManager alias to the method ID.
390
- await agent.keyManager.updateKey({ keyRef: keyPair.keyManagerId!, alias: keyAlias });
391
- }
392
- }
393
- }