@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,442 +0,0 @@
1
- import type { IDCrypto } from '../../crypto/index.js';
2
- import type { RequireOnly } from '../../common/index.js';
3
-
4
- import { IDManagedAgent } from './agent.js';
5
-
6
- export interface CryptoManager {
7
- agent: IDManagedAgent;
8
-
9
- decrypt(options: DecryptOptions): Promise<Uint8Array>;
10
-
11
- deriveBits(options: DeriveBitsOptions): Promise<Uint8Array>;
12
-
13
- encrypt(options: EncryptOptions): Promise<Uint8Array>;
14
-
15
- /**
16
- * Generate a new ManagedKey within a CryptoManager implementation.
17
- */
18
- generateKey<T extends GenerateKeyOptionTypes>(options: GenerateKeyOptions<T>): Promise<GenerateKeyType<T>>;
19
-
20
- /**
21
- * Retrieves detailed information about a ManagedKey or ManagedKeyPair object.
22
- *
23
- * @param options - The options for retrieving the key.
24
- * @param options.keyRef - The reference identifier for the key. Can specify the id or alias property of the key.
25
- * @returns A promise that resolves to either a ManagedKey or ManagedKeyPair object.
26
- */
27
- getKey(options: { keyRef: string }): Promise<ManagedKey | ManagedKeyPair | undefined>;
28
-
29
- importKey(options: PortableKeyPair): Promise<ManagedKeyPair>;
30
- importKey(options: PortableKey): Promise<ManagedKey>;
31
- importKey(options: ImportKeyOptions): Promise<ManagedKey | ManagedKeyPair>;
32
-
33
- sign(options: SignOptions): Promise<Uint8Array>;
34
-
35
- updateKey(options: UpdateKeyOptions): Promise<boolean>;
36
-
37
- verify(options: VerifyOptions): Promise<boolean>;
38
- }
39
-
40
- /**
41
- * Input arguments for implementations of the CryptoManager interface
42
- * {@link CryptoManager.encrypt | encrypt} method.
43
- *
44
- * @public
45
- */
46
- export type DecryptOptions = {
47
- /**
48
- * An object defining the cipher algorithm to use and its parameters.
49
- */
50
- algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.AesCtrOptions | IDCrypto.AesGcmOptions;
51
-
52
- /**
53
- * A Uint8Array object containing the data to be decrypted
54
- * (also known as the ciphertext).
55
- */
56
- data: Uint8Array;
57
-
58
- /**
59
- * An identifier of the ManagedKey to be used for decryption.
60
- * You can use the id or alias property of the key.
61
- */
62
- keyRef: string;
63
- }
64
-
65
- /**
66
- * Input arguments for implementations of the CryptoManager interface
67
- * {@link CryptoManager.deriveBits | deriveBits} method.
68
- *
69
- * @public
70
- */
71
- export type DeriveBitsOptions = {
72
-
73
- /**
74
- * An object defining the derivation algorithm to use and its parameters.
75
- */
76
- // algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.EcdhDeriveKeyOptions;
77
- algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.EcdhDeriveKeyOptions | IDCrypto.Pbkdf2Options;
78
- /**
79
- * An identifier of the ManagedKey that will be the input to the
80
- * derivation algorithm.
81
- *
82
- * If the algorithm is ECDH, this identifier will refer to an ECDH key pair.
83
- * For PBKDF2, it might be a password.
84
- * For HDKF, it might be the shared secret output of an ECDH key agreement operation.
85
- */
86
- baseKeyRef: string;
87
-
88
- /**
89
- * A number representing the number of bits to derive. To be compatible with
90
- * all browsers, the number should be a multiple of 8.
91
- */
92
- length?: number;
93
- }
94
-
95
- /**
96
- * Input arguments for implementations of the CryptoManager interface
97
- * {@link CryptoManager.encrypt | encrypt} method.
98
- *
99
- * @public
100
- */
101
- export type EncryptOptions = {
102
- /**
103
- * An object defining the cipher algorithm to use and its parameters.
104
- */
105
- algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.AesCtrOptions | IDCrypto.AesGcmOptions;
106
-
107
- /**
108
- * An Uint8Array object containing the data to be encrypted
109
- * (also known as the plaintext).
110
- */
111
- data: Uint8Array;
112
-
113
- /**
114
- * An identifier of the ManagedKey to be used for encryption.
115
- * You can use the id or alias property of the key.
116
- */
117
- keyRef: string;
118
- }
119
-
120
- export type GenerateKeyOptions<T extends GenerateKeyOptionTypes> = {
121
- algorithm: T;
122
- alias?: string;
123
- extractable?: boolean;
124
- keyUsages: IDCrypto.KeyUsage[];
125
- metadata?: KeyMetadata;
126
- };
127
-
128
- export type GenerateKeyOptionTypes =
129
- | IDCrypto.AlgorithmIdentifier
130
- // | RsaHashedGenerateKeyOptions
131
- | IDCrypto.AesGenerateKeyOptions
132
- | IDCrypto.EcdsaGenerateKeyOptions
133
- | IDCrypto.EdDsaGenerateKeyOptions
134
- // | HmacGenerateKeyOptions
135
- // | Pbkdf2Params;
136
-
137
- export type GenerateKeyType<T> = T extends IDCrypto.EcGenerateKeyOptions ? ManagedKeyPair :
138
- T extends IDCrypto.AesGenerateKeyOptions /*| HmacGenerateKeyOptions | Pbkdf2Params*/ ? ManagedKey :
139
- T extends IDCrypto.AlgorithmIdentifier ? ManagedKey | ManagedKeyPair :
140
- never;
141
-
142
- export type PortableKey =
143
- RequireOnly<
144
- ManagedKey,
145
- 'algorithm' | 'extractable' | 'type' | 'usages',
146
- 'id' | 'material' | 'state'
147
- >
148
- & { material: Uint8Array; };
149
-
150
- export interface PortableKeyPair {
151
- privateKey: PortableKey;
152
- publicKey: PortableKey;
153
- }
154
-
155
- export type ImportKeyOptions =
156
- | PortableKey
157
- | PortableKeyPair
158
-
159
- /**
160
- * Base interface to be implemented by key management systems.
161
- */
162
- export type KeyManagementSystem = CryptoManager;
163
-
164
- /**
165
- * KeyMetadata
166
- *
167
- * Implementations of KeyManagementSystem can populate this object with KMS platform
168
- * specific data about each key.
169
- *
170
- * This property can also be used to add various tags to the keys under management.
171
- */
172
- export type KeyMetadata = {
173
- /**
174
- * Additional properties of any type.
175
- */
176
- [key: string]: any;
177
- }
178
-
179
- /**
180
- * KeyState
181
- *
182
- * The read-only `state` property of the `ManagedKey` interface indicates the
183
- * status of the ManagedKey.
184
- *
185
- * It can have the following string values:
186
- *
187
- * "Enabled": The key is ready for use.
188
- *
189
- * "Disabled": The key may not be used, but the key material is still available,
190
- * and the key can be placed back into the Enabled state.
191
- *
192
- * "PendingCreation": The key is still being created. It may not be used,
193
- * enabled, disabled, or destroyed yet. The KMS will
194
- * automatically change the state to enabled as soon
195
- * as the key is ready.
196
- *
197
- * "PendingDeletion": The key is scheduled for deletion. It can be placed back
198
- * into the Disabled state up until the time of deletion
199
- * using the CancelKeyDeletion() method. Once the key has
200
- * been deleted, any ciphertext encrypted with this key
201
- * is no longer recoverable. Minimum and maximum waiting
202
- * periods are defined by each KMS implementation.
203
- *
204
- * "PendingImport": The key is still being imported. It may not be used, enabled,
205
- * disabled, or deleted yet. The KMS will automatically change
206
- * the state to Enabled once the key is ready.
207
- *
208
- * "PendingUpdate": The key is still being updated. It may not be used, enabled,
209
- * disabled, or deleted until the update process completes.
210
- * The KMS will automatically change the state to Enabled
211
- * once the key is ready.
212
- */
213
- export type KeyState = 'Enabled' | 'Disabled' | 'PendingCreation' | 'PendingDeletion' | 'PendingImport' | 'PendingUpdate';
214
-
215
- /**
216
- * ManagedKey
217
- *
218
- * A ManagedKey represents a cryptographic key used by a cipher for
219
- * encryption or decryption or an algorithm for signing or verification.
220
- */
221
- export interface ManagedKey {
222
- /**
223
- * A unique identifier for the Key, autogenerated by a KMS.
224
- */
225
- id: string;
226
-
227
- /**
228
- * An object detailing the algorithm for which the key can be used along
229
- * with additional algorithm-specific parameters.
230
- */
231
- // algorithm: IDCrypto.GenerateKeyOptions;
232
- algorithm: IDCrypto.KeyAlgorithm | IDCrypto.GenerateKeyOptions;
233
- /**
234
- * An alternate identifier used to identify the key in a KMS.
235
- * This property can be used to associate a DID document key ID with a ManagedKey.
236
- */
237
- alias?: string;
238
-
239
- /**
240
- * A boolean value that is `true` if the key can be exported and `false` if not.
241
- */
242
- extractable: boolean;
243
-
244
- /**
245
- * Name of a registered key management system.
246
- */
247
- kms: string;
248
-
249
- /**
250
- * Key material as a raw binary data buffer.
251
- */
252
- material?: Uint8Array;
253
-
254
- /**
255
- * Optional. Additional Key metadata.
256
- */
257
- metadata?: KeyMetadata;
258
-
259
- /**
260
- * A registered string value specifying the algorithm and any algorithm
261
- * specific parameters.
262
- * Supported algorithms vary by KMS.
263
- */
264
- spec?: string;
265
-
266
- /**
267
- * The current status of the ManagedKey.
268
- */
269
- state: KeyState;
270
-
271
- /**
272
- * The type of key.
273
- */
274
- type: IDCrypto.KeyType;
275
-
276
- /**
277
- * Indicates which cryptographic operations are permissible to be used with this key.
278
- */
279
- usages: IDCrypto.KeyUsage[];
280
- }
281
-
282
- /**
283
- * Represents information about a managed key.
284
- * Private or secret key material is NOT present.
285
- *
286
- */
287
- export type ManagedKeyInfo = Omit<ManagedKey, 'material'>;
288
-
289
- export type ManagedKeyOptions = Omit<ManagedKey, 'toJwk'>
290
-
291
- /** ManagedKeyPair
292
- *
293
- * A ManagedKeyPair represents a key pair for an asymmetric cryptography algorithm,
294
- * also known as a public-key algorithm.
295
- *
296
- * A ManagedKeyPair object can be obtained using `generateKey()`, when the
297
- * selected algorithm is one of the asymmetric algorithms: ECDSA or ECDH.
298
- */
299
- export interface ManagedKeyPair {
300
- /**
301
- * A ManagedKey object representing the private key. For encryption and
302
- * decryption algorithms, this key is used to decrypt. For signing and
303
- * verification algorithms it is used to sign.
304
- */
305
- privateKey: ManagedKey;
306
-
307
- /**
308
- * A ManagedKey object representing the public key. For encryption and
309
- * decryption algorithms, this key is used to encrypt. For signing and
310
- * verification algorithms it is used to verify signatures.
311
- */
312
- publicKey: ManagedKey;
313
- }
314
-
315
- /**
316
- * ManagedKeyStore
317
- *
318
- * This interface should be implemented to provide platform specific
319
- * implementations that are usable by KeyManager and implementations
320
- * of KeyManagementSystem.
321
- *
322
- * Implementations of this class can be used to store:
323
- * ManagedKey and ManagedKeyPair
324
- * or:
325
- * ManagedPrivateKey
326
- * objects.
327
- *
328
- * @public
329
- */
330
- export interface ManagedKeyStore<K, V> {
331
- deleteKey(options: { id: K, agent?: IDManagedAgent, context?: string }): Promise<boolean>
332
- findKey(options: { id: K, agent?: IDManagedAgent, context?: string }): Promise<V | undefined>;
333
- findKey(options: { alias: K, agent?: IDManagedAgent, context?: string }): Promise<V | undefined>;
334
- getKey(options: { id: K, agent?: IDManagedAgent, context?: string }): Promise<V | undefined>
335
- importKey(options: { key: Omit<V, 'id'>, agent?: IDManagedAgent, context?: string }): Promise<K>
336
- listKeys(options?: { agent?: IDManagedAgent, context?: string }): Promise<V[]>
337
- updateKey(options: { id: K, agent?: IDManagedAgent, context?: string } & Partial<V>): Promise<boolean>
338
- }
339
-
340
- /**
341
- * Represents a private key.
342
- *
343
- * The `alias` is used to refer to the key material which is stored as the hex encoding of the raw byte array
344
- * (`privateKeyHex`).
345
- *
346
- * The `type` refers to the type of key that is represented.
347
- *
348
- * @public
349
- */
350
- export interface ManagedPrivateKey {
351
- /**
352
- * A unique identifier for the Key, autogenerated by a KMS.
353
- */
354
- id: string
355
-
356
- /**
357
- * Key material as raw binary data.
358
- */
359
- material: Uint8Array;
360
-
361
- /**
362
- * The type of key.
363
- */
364
- type: IDCrypto.PrivateKeyType;
365
- }
366
-
367
- /**
368
- * Input arguments for implementations of the CryptoManager interface {@link CryptoManager.sign | sign} method.
369
- *
370
- * @public
371
- */
372
- export type SignOptions = {
373
- /**
374
- * An object that specifies the signature algorithm to use and its parameters.
375
- */
376
- algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.EcdsaOptions | IDCrypto.EdDsaOptions;
377
-
378
- /**
379
- * An Uint8Array object containing the data to be signed.
380
- */
381
- data: Uint8Array;
382
-
383
- /**
384
- * An identifier of the ManagedKey to sign with.
385
- * You can use the id or alias property of the key.
386
- */
387
- keyRef: string;
388
- }
389
-
390
- /**
391
- * Input arguments for implementations of the CryptoManager interface
392
- * {@link CryptoManager.updateKey | updateKey} method.
393
- *
394
- * @public
395
- */
396
- export type UpdateKeyOptions = {
397
- /**
398
- * An alternate identifier used to identify the key in a KMS.
399
- * This property can be used to associate a DID document key ID with a ManagedKey.
400
- */
401
- alias?: string;
402
-
403
- /**
404
- * An identifier of the ManagedKey to be used for decryption.
405
- * You can use the id or alias property of the key.
406
- */
407
- keyRef: string;
408
-
409
- /**
410
- * Optional. Additional Key metadata.
411
- */
412
- metadata?: KeyMetadata;
413
- }
414
-
415
- /**
416
- * Input arguments for implementations of the CryptoManager interface
417
- * {@link CryptoManager.verify | verify} method.
418
- *
419
- * @public
420
- */
421
- export type VerifyOptions = {
422
- /**
423
- * An object that specifies the algorithm to use and its parameters.
424
- */
425
- algorithm: IDCrypto.AlgorithmIdentifier | IDCrypto.EcdsaOptions | IDCrypto.EdDsaOptions;
426
-
427
- /**
428
- * An Uint8Array object containing the data whose signature is to be verified.
429
- */
430
- data: Uint8Array;
431
-
432
- /**
433
- * An identifier of the ManagedKey to sign with.
434
- * You can use the id or alias property of the key.
435
- */
436
- keyRef: string;
437
-
438
- /**
439
- * A Uint8Array containing the signature to verify.
440
- */
441
- signature: Uint8Array;
442
- }
@@ -1,190 +0,0 @@
1
- import type { JsonWebKey, IDCrypto } from '../crypto/index.js';
2
-
3
- import { Jose } from '../crypto/index.js';
4
- import { RequireOnly } from '../common/index.js';
5
- import { Readable } from 'readable-stream';
6
- import { ReadableWebToNodeStream } from 'readable-web-to-node-stream';
7
-
8
- import { ManagedKey, ManagedKeyPair, PortableKey, PortableKeyPair } from './types/managed-key.js';
9
-
10
- export function blobToIsomorphicNodeReadable(blob: Blob): Readable {
11
- return webReadableToIsomorphicNodeReadable(blob.stream() as ReadableStream<any>);
12
- }
13
-
14
- export function cryptoToManagedKey(options: {
15
- cryptoKey: IDCrypto.CryptoKey,
16
- keyData: RequireOnly<ManagedKey, 'kms'>
17
- }): ManagedKey {
18
- const { cryptoKey, keyData } = options;
19
-
20
- const managedKey: ManagedKey = {
21
- id : keyData.id ?? '',
22
- algorithm : cryptoKey.algorithm,
23
- alias : keyData.alias,
24
- extractable : cryptoKey.extractable,
25
- kms : keyData.kms,
26
- material : (cryptoKey.type === 'public') ? cryptoKey.material : undefined,
27
- metadata : keyData.metadata,
28
- state : 'Enabled',
29
- type : cryptoKey.type,
30
- usages : cryptoKey.usages
31
- };
32
-
33
- return managedKey;
34
- }
35
-
36
- export function cryptoToManagedKeyPair(options: {
37
- cryptoKeyPair: IDCrypto.CryptoKeyPair,
38
- keyData: RequireOnly<ManagedKey, 'kms' | 'state'>
39
- }): ManagedKeyPair {
40
- const { cryptoKeyPair, keyData } = options;
41
-
42
- const privateKey = cryptoKeyPair.privateKey;
43
- const publicKey = cryptoKeyPair.publicKey;
44
-
45
- const managedKeyPair = {
46
- privateKey: {
47
- id : keyData.id ?? '',
48
- algorithm : privateKey.algorithm,
49
- alias : keyData.alias,
50
- extractable : privateKey.extractable,
51
- kms : keyData.kms,
52
- metadata : keyData.metadata,
53
- state : keyData.state,
54
- type : privateKey.type,
55
- usages : privateKey.usages
56
- },
57
-
58
- publicKey: {
59
- id : keyData.id ?? '',
60
- algorithm : publicKey.algorithm,
61
- alias : keyData.alias,
62
- extractable : publicKey.extractable,
63
- kms : keyData.kms,
64
- material : publicKey.material,
65
- metadata : keyData.metadata,
66
- state : keyData.state,
67
- type : publicKey.type,
68
- usages : publicKey.usages
69
- },
70
- };
71
-
72
- return managedKeyPair;
73
- }
74
-
75
- export function cryptoToPortableKey(options: {
76
- cryptoKey: IDCrypto.CryptoKey,
77
- keyData: RequireOnly<ManagedKey, 'kms'>
78
- }): PortableKey {
79
- const { cryptoKey, keyData } = options;
80
-
81
- const portableKey = {
82
- id : keyData.id ?? '',
83
- algorithm : cryptoKey.algorithm,
84
- alias : keyData.alias,
85
- extractable : cryptoKey.extractable,
86
- kms : keyData.kms,
87
- material : cryptoKey.material,
88
- metadata : keyData.metadata,
89
- type : cryptoKey.type,
90
- usages : cryptoKey.usages
91
- };
92
-
93
- return portableKey;
94
- }
95
-
96
- export function cryptoToPortableKeyPair(options: {
97
- cryptoKeyPair: IDCrypto.CryptoKeyPair,
98
- keyData: RequireOnly<ManagedKey, 'kms'>
99
- }): PortableKeyPair {
100
- const { cryptoKeyPair, keyData } = options;
101
-
102
- const privateKey = cryptoKeyPair.privateKey;
103
- const publicKey = cryptoKeyPair.publicKey;
104
-
105
- const portableKeyPair = {
106
- privateKey: {
107
- id : keyData.id ?? '',
108
- algorithm : privateKey.algorithm,
109
- alias : keyData.alias,
110
- extractable : privateKey.extractable,
111
- kms : keyData.kms,
112
- material : privateKey.material,
113
- metadata : keyData.metadata,
114
- type : privateKey.type,
115
- usages : privateKey.usages
116
- },
117
-
118
- publicKey: {
119
- id : keyData.id ?? '',
120
- algorithm : publicKey.algorithm,
121
- alias : keyData.alias,
122
- extractable : publicKey.extractable,
123
- kms : keyData.kms,
124
- material : publicKey.material,
125
- metadata : keyData.metadata,
126
- type : publicKey.type,
127
- usages : publicKey.usages
128
- },
129
- };
130
-
131
- return portableKeyPair;
132
- }
133
-
134
- /**
135
- * Type guard function to check if the given key is a ManagedKey.
136
- *
137
- * @param key The key to check.
138
- * @returns True if the key is a ManagedKeyPair, false otherwise.
139
- */
140
- export function isManagedKey(key: ManagedKey | ManagedKeyPair | undefined): key is ManagedKey {
141
- return key !== undefined && 'algorithm' in key && 'extractable' in key && 'type' in key && 'usages' in key;
142
- }
143
-
144
- /**
145
- * Type guard function to check if the given key is a ManagedKeyPair.
146
- *
147
- * @param key The key to check.
148
- * @returns True if the key is a ManagedKeyPair, false otherwise.
149
- */
150
- export function isManagedKeyPair(key: ManagedKey | ManagedKeyPair | undefined): key is ManagedKeyPair {
151
- return key !== undefined && 'privateKey' in key && 'publicKey' in key;
152
- }
153
-
154
- export async function managedKeyToJwk({ key }: {
155
- key: RequireOnly<ManagedKey, 'algorithm' | 'extractable' | 'material' | 'type' | 'usages'>
156
- }): Promise<JsonWebKey> {
157
- if (key.material === undefined) {
158
- throw new Error(`Could not convert to JWK: 'material' is undefined.`);
159
- }
160
-
161
- const cryptoKey: IDCrypto.CryptoKey = {
162
- algorithm : key.algorithm,
163
- extractable : key.extractable,
164
- material : key.material,
165
- type : key.type,
166
- usages : key.usages
167
- };
168
-
169
- const jwk = await Jose.cryptoKeyToJwk({ key: cryptoKey });
170
-
171
- return jwk;
172
- }
173
-
174
- export function managedToCryptoKey({ key }: {
175
- key: RequireOnly<ManagedKey, 'algorithm' | 'extractable' | 'material' | 'type' | 'usages'>
176
- }): IDCrypto.CryptoKey {
177
- const cryptoKey: IDCrypto.CryptoKey = {
178
- algorithm : key.algorithm,
179
- extractable : key.extractable,
180
- material : key.material,
181
- type : key.type,
182
- usages : key.usages
183
- };
184
-
185
- return cryptoKey;
186
- }
187
-
188
- export function webReadableToIsomorphicNodeReadable(webReadable: ReadableStream<any>) {
189
- return new ReadableWebToNodeStream(webReadable);
190
- }