@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,19 +0,0 @@
1
- export type * from './types/agent.js';
2
- export type * from './types/managed-key.js';
3
-
4
- export * from './app-data-store.js';
5
- export * from './did-manager.js';
6
- export * from './dwn-manager.js';
7
- export * from './identity-manager.js';
8
- export * from './json-rpc.js';
9
- export * from './key-manager.js';
10
- export * from './kms-local.js';
11
- export * from './rpc-client.js';
12
- export * from './store-managed-did.js';
13
- export * from './store-managed-key.js';
14
- export * from './store-managed-identity.js';
15
- export * from './outbox.js';
16
- export * from './sync-manager.js';
17
- export * from './utils.js';
18
-
19
- export * from './test-managed-agent.js';
@@ -1,107 +0,0 @@
1
- export type JsonRpcId = string | number | null;
2
- export type JsonRpcParams = any;
3
- export type JsonRpcVersion = '2.0';
4
-
5
- export interface JsonRpcRequest {
6
- jsonrpc: JsonRpcVersion;
7
- id?: JsonRpcId;
8
- method: string;
9
- params?: any;
10
- }
11
-
12
- export interface JsonRpcError {
13
- code: JsonRpcErrorCodes;
14
- message: string;
15
- data?: any;
16
- }
17
-
18
- export enum JsonRpcErrorCodes {
19
- // JSON-RPC 2.0 pre-defined errors
20
- InvalidRequest = -32600,
21
- MethodNotFound = -32601,
22
- InvalidParams = -32602,
23
- InternalError = -32603,
24
- ParseError = -32700,
25
- TransportError = -32300,
26
-
27
- // App defined errors
28
- BadRequest = -50400, // equivalent to HTTP Status 400
29
- Unauthorized = -50401, // equivalent to HTTP Status 401
30
- Forbidden = -50403, // equivalent to HTTP Status 403
31
- }
32
-
33
- export type JsonRpcResponse = JsonRpcSuccessResponse | JsonRpcErrorResponse;
34
-
35
- export interface JsonRpcSuccessResponse {
36
- jsonrpc: JsonRpcVersion;
37
- id: JsonRpcId;
38
- result: any;
39
- error?: never;
40
- }
41
-
42
- export interface JsonRpcErrorResponse {
43
- jsonrpc: JsonRpcVersion;
44
- id: JsonRpcId;
45
- result?: never;
46
- error: JsonRpcError;
47
- }
48
-
49
- export const createJsonRpcErrorResponse = (
50
- id: JsonRpcId,
51
- code: JsonRpcErrorCodes,
52
- message: string,
53
- data?: any,
54
- ): JsonRpcErrorResponse => {
55
- const error: JsonRpcError = { code, message };
56
- if (data != undefined) {
57
- error.data = data;
58
- }
59
- return {
60
- jsonrpc: '2.0',
61
- id,
62
- error,
63
- };
64
- };
65
-
66
- export const createJsonRpcNotification = (
67
- method: string,
68
- params?: JsonRpcParams,
69
- ): JsonRpcRequest => {
70
- return {
71
- jsonrpc: '2.0',
72
- method,
73
- params,
74
- };
75
- };
76
-
77
- export const createJsonRpcRequest = (
78
- id: JsonRpcId,
79
- method: string,
80
- params?: JsonRpcParams,
81
- ): JsonRpcRequest => {
82
- return {
83
- jsonrpc: '2.0',
84
- id,
85
- method,
86
- params,
87
- };
88
- };
89
-
90
- export const createJsonRpcSuccessResponse = (
91
- id: JsonRpcId,
92
- result?: any,
93
- ): JsonRpcSuccessResponse => {
94
- return {
95
- jsonrpc : '2.0',
96
- id,
97
- result : result ?? null,
98
- };
99
- };
100
-
101
- export function parseJson(text: string): object | null {
102
- try {
103
- return JSON.parse(text);
104
- } catch {
105
- return null;
106
- }
107
- }
@@ -1,302 +0,0 @@
1
- import type {
2
- ManagedKey,
3
- PortableKey,
4
- SignOptions,
5
- CryptoManager,
6
- VerifyOptions,
7
- DecryptOptions,
8
- EncryptOptions,
9
- ManagedKeyPair,
10
- GenerateKeyType,
11
- ManagedKeyStore,
12
- ImportKeyOptions,
13
- UpdateKeyOptions,
14
- DeriveBitsOptions,
15
- PortableKeyPair,
16
- GenerateKeyOptions,
17
- KeyManagementSystem,
18
- GenerateKeyOptionTypes,
19
- } from './types/managed-key.js';
20
-
21
- import { IDManagedAgent } from './types/agent.js';
22
- import { LocalKms } from './kms-local.js';
23
- import { isManagedKey, isManagedKeyPair } from './utils.js';
24
- import { KeyStoreMemory, PrivateKeyStoreMemory } from './store-managed-key.js';
25
-
26
- export type KmsMap = {
27
- [name: string]: KeyManagementSystem;
28
- }
29
-
30
- export type KeyManagerOptions = {
31
- agent?: IDManagedAgent;
32
- kms?: KmsMap;
33
- store?: ManagedKeyStore<string, ManagedKey | ManagedKeyPair>;
34
- }
35
-
36
- /**
37
- * KeyManager
38
- *
39
- * This class orchestrates implementations of {@link KeyManagementSystem},
40
- * using a ManagedKeyStore to remember the link between a key reference,
41
- * its metadata, and the respective key management system that provides the
42
- * actual cryptographic capabilities.
43
- *
44
- * The methods of this class are used automatically by other Agent
45
- * components to perform their required cryptographic operations using
46
- * the managed keys.
47
- *
48
- * @public
49
- */
50
- export class KeyManager implements CryptoManager {
51
- /**
52
- * Holds the instance of a `IDManagedAgent` that represents the current
53
- * execution context for the `KeyManager`. This agent is utilized
54
- * to interact with other agent components. It's vital
55
- * to ensure this instance is set to correctly contextualize
56
- * operations within the broader agent framework.
57
- */
58
- private _agent?: IDManagedAgent;
59
- // ManagedKey to use for signing DWN messages with DWN-backed store.
60
- private _defaultSigningKey?: ManagedKeyPair;
61
- // KMS name to KeyManagementSystem mapping.
62
- private _kms: Map<string, KeyManagementSystem>;
63
- // Store for managed key metadata.
64
- private _store: ManagedKeyStore<string, ManagedKey | ManagedKeyPair>;
65
-
66
- constructor(options?: KeyManagerOptions) {
67
- let { agent, kms, store } = options ?? { };
68
- this._agent = agent;
69
- this._store = store ?? new KeyStoreMemory();
70
-
71
- kms ??= this.useMemoryKms();
72
- this._kms = new Map(Object.entries(kms)) ;
73
- }
74
-
75
- /**
76
- * Retrieves the `IDManagedAgent` execution context.
77
- * If the `agent` instance proprety is undefined, it will throw an error.
78
- *
79
- * @returns The `IDManagedAgent` instance that represents the current execution
80
- * context.
81
- *
82
- * @throws Will throw an error if the `agent` instance property is undefined.
83
- */
84
- get agent(): IDManagedAgent {
85
- if (this._agent === undefined) {
86
- throw new Error('KeyManager: Unable to determine agent execution context.');
87
- }
88
-
89
- return this._agent;
90
- }
91
-
92
- set agent(agent: IDManagedAgent) {
93
- this._agent = agent;
94
- this._kms.forEach((kms) => {
95
- kms.agent = agent;
96
- });
97
- }
98
-
99
- async decrypt(options: DecryptOptions): Promise<Uint8Array> {
100
- let { keyRef, ...decryptOptions } = options;
101
-
102
- const key = await this.getKey({ keyRef });
103
-
104
- if (!isManagedKey(key)) {
105
- throw new Error(`Key not found: '${keyRef}'`);
106
- }
107
-
108
- const kmsName = key.kms;
109
- const kms = this.getKms(kmsName);
110
-
111
- const keyId = key.id;
112
- const plaintext = await kms.decrypt({ keyRef: keyId, ...decryptOptions });
113
-
114
- return plaintext;
115
- }
116
-
117
- async deriveBits(options: DeriveBitsOptions): Promise<Uint8Array> {
118
- const { baseKeyRef, ...deriveBitsOptions } = options;
119
-
120
- const ownKeyPair = await this.getKey({ keyRef: baseKeyRef });
121
-
122
- if (!isManagedKeyPair(ownKeyPair)) {
123
- throw new Error(`Key not found: '${baseKeyRef}'`);
124
- }
125
-
126
- const kmsName = ownKeyPair.privateKey.kms;
127
- const kms = this.getKms(kmsName);
128
-
129
- const ownKeyId = ownKeyPair.privateKey.id;
130
- const sharedSecret = kms.deriveBits({ baseKeyRef: ownKeyId, ...deriveBitsOptions });
131
-
132
- return sharedSecret;
133
- }
134
-
135
- async encrypt(options: EncryptOptions): Promise<Uint8Array> {
136
- let { keyRef, ...encryptOptions } = options;
137
-
138
- const key = await this.getKey({ keyRef });
139
-
140
- if (!isManagedKey(key)) {
141
- throw new Error(`Key not found: '${keyRef}'`);
142
- }
143
-
144
- const kmsName = key.kms;
145
- const kms = this.getKms(kmsName);
146
-
147
- const keyId = key.id;
148
- const ciphertext = await kms.encrypt({ keyRef: keyId, ...encryptOptions });
149
-
150
- return ciphertext;
151
- }
152
-
153
- async generateKey<T extends GenerateKeyOptionTypes>(options: GenerateKeyOptions<T> & { kms?: string }): Promise<GenerateKeyType<T>> {
154
- const { kms: kmsName, ...generateKeyOptions } = options;
155
-
156
- const kms = this.getKms(kmsName);
157
-
158
- const keyOrKeyPair = await kms.generateKey(generateKeyOptions);
159
-
160
- // Store the ManagedKey or ManagedKeyPair in KeyManager's key store.
161
- await this._store.importKey({ key: keyOrKeyPair, agent: this.agent });
162
-
163
- return keyOrKeyPair;
164
- }
165
-
166
- async getKey({ keyRef }: { keyRef: string }): Promise<ManagedKey | ManagedKeyPair | undefined> {
167
- let keyOrKeyPair: ManagedKey | ManagedKeyPair | undefined;
168
-
169
- // First, check to see if the requested key is the default signing key.
170
- const defaultSigningKeyId = this._defaultSigningKey?.publicKey.id;
171
- const defaultSigningKeyAlias = this._defaultSigningKey?.publicKey.alias;
172
- if (keyRef === defaultSigningKeyId || keyRef === defaultSigningKeyAlias) {
173
- return this._defaultSigningKey;
174
- }
175
-
176
- // Try to get key by ID.
177
- keyOrKeyPair = await this._store.getKey({ id: keyRef, agent: this.agent });
178
- if (keyOrKeyPair) return keyOrKeyPair;
179
-
180
- // Try to find key by alias.
181
- keyOrKeyPair = await this._store.findKey({ alias: keyRef, agent: this.agent });
182
- if (keyOrKeyPair) return keyOrKeyPair;
183
-
184
- return undefined;
185
- }
186
-
187
- async importKey(options: PortableKeyPair): Promise<ManagedKeyPair>;
188
- async importKey(options: PortableKey): Promise<ManagedKey>;
189
- async importKey(options: ImportKeyOptions): Promise<ManagedKey | ManagedKeyPair> {
190
- const kmsName = ('privateKey' in options) ? options.privateKey.kms : options.kms;
191
- const kms = this.getKms(kmsName);
192
-
193
- // Store the ManagedKey or ManagedKeyPair in the given KMS.
194
- const importedKeyOrKeyPair = await kms.importKey(options);
195
-
196
- // Store the ManagedKey or ManagedKeyPair in KeyManager's key store.
197
- await this._store.importKey({ key: importedKeyOrKeyPair, agent: this.agent });
198
-
199
- return importedKeyOrKeyPair;
200
- }
201
-
202
- listKms() {
203
- return Array.from(this._kms.keys());
204
- }
205
-
206
- async setDefaultSigningKey({ key }: { key: PortableKeyPair }) {
207
- const kmsName = key.privateKey.kms;
208
- const kms = this.getKms(kmsName);
209
-
210
- // Store the default signing key pair in an in-memory KMS.
211
- const importedDefaultSigningKey = await kms.importKey(key);
212
-
213
- // Set the in-memory key to be KeyManager's default signing key.
214
- this._defaultSigningKey = importedDefaultSigningKey;
215
- }
216
-
217
- async sign(options: SignOptions): Promise<Uint8Array> {
218
- const { keyRef, ...signOptions } = options;
219
-
220
- const keyPair = await this.getKey({ keyRef });
221
-
222
- if (!isManagedKeyPair(keyPair)) {
223
- throw new Error(`Key not found: '${keyRef}'`);
224
- }
225
-
226
- const kmsName = keyPair.privateKey.kms;
227
- const kms = this.getKms(kmsName);
228
-
229
- const keyId = keyPair.privateKey.id;
230
- const signature = await kms.sign({ keyRef: keyId, ...signOptions });
231
-
232
- return signature;
233
- }
234
-
235
- async updateKey(options: UpdateKeyOptions): Promise<boolean> {
236
- const { keyRef, alias, metadata } = options;
237
-
238
- const keyOrKeyPair = await this.getKey({ keyRef });
239
-
240
- if (!keyOrKeyPair) {
241
- throw new Error(`Key not found: '${keyRef}'`);
242
- }
243
-
244
- const { id: keyId, kms: kmsName } = (isManagedKeyPair(keyOrKeyPair))
245
- ? { ...keyOrKeyPair.publicKey }
246
- : { ...keyOrKeyPair };
247
-
248
- // Update the ManagedKey or ManagedKeyPair in the given KMS.
249
- const kms = this.getKms(kmsName);
250
- const kmsUpdated = await kms.updateKey(options);
251
-
252
- if (!kmsUpdated) return false;
253
-
254
- // Since the KMS was successfully updated, update the KeyManager store.
255
- return await this._store.updateKey({ id: keyId, alias, metadata, agent: this.agent });
256
- }
257
-
258
- async verify(options: VerifyOptions): Promise<boolean> {
259
- let { keyRef, ...verifyOptions } = options;
260
-
261
- const keyPair = await this.getKey({ keyRef });
262
-
263
- if (!isManagedKeyPair(keyPair)) {
264
- throw new Error(`Key not found: '${keyRef}'`);
265
- }
266
-
267
- const kmsName = keyPair.publicKey.kms;
268
- const kms = this.getKms(kmsName);
269
-
270
- const keyId = keyPair.publicKey.id;
271
- const isValid = await kms.verify({ keyRef: keyId, ...verifyOptions });
272
-
273
- return isValid;
274
- }
275
-
276
- private getKms(name: string | undefined): KeyManagementSystem {
277
- // For developer convenience, if a KMS name isn't specified and KeyManager only has
278
- // one KMS defined, use it. Otherwise, an exception will be thrown.
279
- name ??= (this._kms.size === 1) ? this._kms.keys().next().value : '';
280
-
281
- const kms = this._kms.get(name!);
282
-
283
- if (!kms) {
284
- throw Error(`Unknown key management system: '${name}'`);
285
- }
286
-
287
- return kms;
288
- }
289
-
290
- private useMemoryKms(): KmsMap {
291
- // Instantiate in-memory store for KMS key metadata and public keys.
292
- const keyStore = new KeyStoreMemory();
293
-
294
- // Instantiate in-memory store for KMS private keys.
295
- const privateKeyStore = new PrivateKeyStoreMemory();
296
-
297
- // Instantiate local KMS using in-memory key stores.
298
- const kms = new LocalKms({ kmsName: 'memory', keyStore, privateKeyStore });
299
-
300
- return { memory: kms };
301
- }
302
- }