@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dwn-protocol/id-sdk",
3
- "version": "0.2.5",
3
+ "version": "0.2.6",
4
4
  "description": "SDK for accessing the features and capabilities",
5
5
  "type": "module",
6
6
  "main": "./dist/cjs/index.js",
@@ -30,8 +30,7 @@
30
30
  "license": "Apache-2.0",
31
31
  "contributors": [],
32
32
  "files": [
33
- "dist",
34
- "src"
33
+ "dist"
35
34
  ],
36
35
  "exports": {
37
36
  ".": {
@@ -1,365 +0,0 @@
1
- import type { DidKeySet } from '../dids/index.js';
2
- import type { KeyValueStore } from '../common/index.js';
3
- import type { JweHeaderParams, PublicKeyJwk, IDCrypto } from '../crypto/index.js';
4
-
5
- import { DidKeyMethod } from '../dids/index.js';
6
- import { hkdf } from '@noble/hashes/hkdf';
7
- import { sha256 } from '@noble/hashes/sha256';
8
- import { Convert, MemoryStore } from '../common/index.js';
9
- import { CryptoKey, Jose, Pbkdf2, utils as cryptoUtils, XChaCha20Poly1305 } from '../crypto/index.js';
10
-
11
- export type AppDataBackup = {
12
- /**
13
- * A timestamp to record when the backup was made.
14
- */
15
- dateCreated: string;
16
-
17
- /**
18
- * The size of the backup data.
19
- */
20
- size: number;
21
-
22
- /**
23
- * Encrypted vault contents.
24
- */
25
- data: string;
26
- }
27
-
28
- export type AppDataStatus = {
29
- /**
30
- * Boolean indicating whether the data was successful.
31
- */
32
- initialized: boolean;
33
-
34
- /**
35
- * The timestamp of the last backup.
36
- */
37
- lastBackup: string | undefined;
38
-
39
- /**
40
- * The timestamp of the last restore.
41
- */
42
- lastRestore: string | undefined;
43
- }
44
-
45
- export type AppData = {
46
- [key: string]: any;
47
- }
48
-
49
- export interface AppDataStore {
50
- /**
51
- * Returns a promise that resolves to a string, which is the App DID.
52
- */
53
- getDid(): Promise<string>
54
-
55
- /**
56
- * Returns a promise that resolves to a CryptoKey object, which
57
- * represents the public key associated with the App DID.
58
- */
59
- getPublicKey(): Promise<IDCrypto.CryptoKey>
60
-
61
- /**
62
- * Returns a promise that resolves to a CryptoKey object, which
63
- * represents the private key associated with the App DID.
64
- */
65
- getPrivateKey(): Promise<IDCrypto.CryptoKey>
66
-
67
- /**
68
- * Returns a promise that resolves to a AppDataStatus object, which
69
- * provides information about the current status of the AppData instance.
70
- */
71
- getStatus(): Promise<AppDataStatus>
72
-
73
- /**
74
- * Initializes the AppDataStore and returns a Promise that resolves
75
- * to a boolean indicating whether the operation was successful.
76
- */
77
- initialize(options: { passphrase: string, keyPair: IDCrypto.CryptoKeyPair }): Promise<void>;
78
-
79
- /**
80
- * Creates an encrypted backup of the current state of `AppData` and
81
- * returns a Promise that resolves to an `AppDataBackup` object.
82
- */
83
- backup(options: { passphrase: string }): Promise<AppDataBackup>;
84
-
85
- /**
86
- * Restores `AppData` to the state in the provided `AppDataBackup` object.
87
- * It requires a passphrase to decrypt the backup and returns a Promise that
88
- * resolves to a boolean indicating whether the restore was successful.
89
- */
90
- restore(options: { backup: AppDataBackup, passphrase: string }): Promise<boolean>;
91
-
92
- /**
93
- * Locks the `AppDataStore`, secured by a passphrase
94
- * that must be entered to unlock.
95
- */
96
- lock(): Promise<void>;
97
-
98
- /**
99
- * Attempts to unlock the `AppDataStore` with the provided
100
- * passphrase. It returns a Promise that resolves to a
101
- * boolean indicating whether the unlock was successful.
102
- */
103
- unlock(options: { passphrase: string }): Promise<boolean>;
104
-
105
- /**
106
- * Attempts to change the passphrase of the `AppDataStore`.
107
- * It requires the old passphrase for verification and returns
108
- * a Promise that resolves to a boolean indicating whether the
109
- * passphrase change was successful.
110
- */
111
- changePassphrase(options: { oldPassphrase: string, newPassphrase: string }): Promise<boolean>;
112
- }
113
-
114
- export type AppDataVaultOptions = {
115
- keyDerivationWorkFactor?: number;
116
- store?: KeyValueStore<string, any>;
117
- }
118
-
119
- export class AppDataVault implements AppDataStore {
120
- private _keyDerivationWorkFactor: number;
121
- private _store: KeyValueStore<string, any>;
122
- private _vaultUnlockKey = new Uint8Array();
123
-
124
- constructor(options?: AppDataVaultOptions) {
125
- this._keyDerivationWorkFactor = options?.keyDerivationWorkFactor ?? 650_000;
126
- this._store = options?.store ?? new MemoryStore();
127
- }
128
-
129
- async backup(_options: { passphrase: string }): Promise<AppDataBackup> {
130
- throw new Error ('Not implemented');
131
- }
132
-
133
- async changePassphrase(_options: { oldPassphrase: string, newPassphrase: string }): Promise<boolean> {
134
- throw new Error ('Not implemented');
135
- }
136
-
137
- private async generateVaultUnlockKey(options: {
138
- passphrase: string,
139
- salt: Uint8Array
140
- }): Promise<Uint8Array> {
141
- const { passphrase, salt } = options;
142
-
143
- /** The salt value derived in Step 3 and the passphrase entered by the
144
- * end-user are inputs to the PBKDF2 algorithm to derive a 32-byte secret
145
- * key that will be referred to as the Vault Unlock Key (VUK). */
146
- const vaultUnlockKey = await Pbkdf2.deriveKey({
147
- hash : 'SHA-512',
148
- iterations : this._keyDerivationWorkFactor,
149
- length : 256,
150
- password : Convert.string(passphrase).toUint8Array(),
151
- salt : salt
152
- });
153
-
154
- return vaultUnlockKey;
155
- }
156
-
157
- async getDid(): Promise<string> {
158
- // Get the Vault Key Set JWE from the data store.
159
- const vaultKeySet = await this._store.get('vaultKeySet');
160
-
161
- // Decode the Base64 URL encoded JWE protected header.
162
- let [protectedHeaderB64U] = vaultKeySet.split('.');
163
- const protectedHeader = Convert.base64Url(protectedHeaderB64U).toObject() as JweHeaderParams;
164
-
165
- // Extract the public key in JWK format.
166
- const publicKeyJwk = protectedHeader.wrappedKey as PublicKeyJwk;
167
-
168
- // Expand the public key to a did:key identifier.
169
- const keySet: DidKeySet = { verificationMethodKeys: [{ publicKeyJwk, relationships: ['authentication'] }]};
170
- const { did } = await DidKeyMethod.create({ keySet });
171
-
172
- return did;
173
- }
174
-
175
- async getPublicKey(): Promise<CryptoKey> {
176
- // Get the Vault Key Set JWE from the data store.
177
- const vaultKeySet = await this._store.get('vaultKeySet');
178
-
179
- // Decode the Base64 URL encoded JWE protected header.
180
- let [protectedHeaderB64U] = vaultKeySet.split('.');
181
- const protectedHeader = Convert.base64Url(protectedHeaderB64U).toObject() as JweHeaderParams;
182
-
183
- // Convert the public key in JWK format to crypto key.
184
- const publicKeyJwk = protectedHeader.wrappedKey as PublicKeyJwk;
185
- const cryptoKey = await Jose.jwkToCryptoKey({ key: publicKeyJwk });
186
-
187
- return cryptoKey;
188
- }
189
-
190
- async getPrivateKey(): Promise<IDCrypto.CryptoKey> {
191
- // Get the Vault Key Set JWE from the data store.
192
- const vaultKeySet = await this._store.get('vaultKeySet');
193
-
194
- // Decode the Base64 URL encoded JWE content.
195
- let [protectedHeaderB64U, encryptedKeyB64U, nonceB64U, _, tagB64U] = vaultKeySet.split('.');
196
- const protectedHeader = Convert.base64Url(protectedHeaderB64U).toObject() as JweHeaderParams;
197
- const encryptedKey = Convert.base64Url(encryptedKeyB64U).toUint8Array();
198
- const nonce = Convert.base64Url(nonceB64U).toUint8Array();
199
- const tag = Convert.base64Url(tagB64U).toUint8Array();
200
-
201
- // Decrypt the Identity Agent's private key material.
202
- const privateKeyMaterial = await XChaCha20Poly1305.decrypt({
203
- additionalData : Convert.object(protectedHeader).toUint8Array(),
204
- data : encryptedKey,
205
- key : this._vaultUnlockKey,
206
- nonce : nonce,
207
- tag : tag
208
- });
209
-
210
- // Get the public key.
211
- const publicKey = await this.getPublicKey();
212
-
213
- // Create a private crypto key based off the parameters of the public key.
214
- const privateKey = new CryptoKey(
215
- publicKey.algorithm,
216
- publicKey.extractable,
217
- privateKeyMaterial,
218
- 'private',
219
- ['sign']
220
- );
221
-
222
- return privateKey;
223
- }
224
-
225
- async getStatus(): Promise<AppDataStatus> {
226
- try {
227
- const appDataStatus = await this._store.get('appDataStatus');
228
- return JSON.parse(appDataStatus);
229
- } catch(error: any) {
230
- return {
231
- initialized : false,
232
- lastBackup : undefined,
233
- lastRestore : undefined
234
- };
235
- }
236
- }
237
-
238
- async initialize(options: {
239
- keyPair: IDCrypto.CryptoKeyPair,
240
- passphrase: string
241
- }): Promise<void> {
242
- const { keyPair, passphrase } = options;
243
-
244
- const appDataStatus = await this.getStatus();
245
-
246
- // Throw if the data vault was previously initialized.
247
- if (appDataStatus.initialized === true) {
248
- throw new Error(`Operation 'initialize' failed. Data vault already initialized.`);
249
- }
250
-
251
- /** A non-secret static info value is combined with the Identity Agent's
252
- * public key as input to a Hash-based Key Derivation Function (HKDF)
253
- * to derive a new 32-byte salt. */
254
- const publicKey = keyPair.publicKey.material;
255
- const saltInput = hkdf(
256
- sha256, // hash function
257
- publicKey, // input keying material
258
- undefined, // no salt because public key is already random
259
- 'vault_unlock_salt', // non-secret application specific information
260
- 32 // derived key length, in bytes
261
- );
262
-
263
- /**
264
- * Per RFC 7518, the salt value used with PBES2 should be of the format
265
- * (UTF8(Alg) || 0x00 || Salt Input), where Alg is the "alg" (algorithm)
266
- * Header Parameter value. This reduces the potential for a precomputed
267
- * dictionary attack (also known as a rainbow table attack).
268
- * @see {@link https://www.rfc-editor.org/rfc/rfc7518.html#section-4.8.1.1 | RFC 7518, Section 4.8.1.1}
269
- */
270
- const algorithm = Convert.string('PBES2-HS512+XC20PKW').toUint8Array();
271
- const salt = new Uint8Array([...algorithm, 0x00, ...saltInput]);
272
-
273
- /**
274
- * Generate a vault unlock key (VUK), which will be used as a
275
- * key encryption key (KEK) for wrapping the private key */
276
- // @ts-ignore
277
- this._vaultUnlockKey = await this.generateVaultUnlockKey({ passphrase, salt });
278
-
279
- /** Convert the public crypto key to JWK format to store within the JWE. */
280
- const wrappedKey = await Jose.cryptoKeyToJwk({ key: keyPair.publicKey });
281
-
282
- /** Construct the JWE header. */
283
- const protectedHeader: JweHeaderParams = {
284
- alg : 'PBES2-HS512+XC20PKW',
285
- crit : ['wrappedKey'],
286
- enc : 'XC20P',
287
- p2c : this._keyDerivationWorkFactor,
288
- p2s : Convert.uint8Array(salt).toBase64Url(),
289
- wrappedKey : wrappedKey
290
- };
291
-
292
- /** 6. Encrypt the Identity Agent's private key with the derived VUK
293
- * using XChaCha20-Poly1305 */
294
- const nonce = cryptoUtils.randomBytes(24);
295
- const privateKey = keyPair.privateKey.material;
296
- const {
297
- ciphertext: privateKeyCiphertext,
298
- tag: privateKeyTag } = await XChaCha20Poly1305.encrypt({
299
- additionalData : Convert.object(protectedHeader).toUint8Array(),
300
- data : privateKey,
301
- key : this._vaultUnlockKey,
302
- nonce : nonce
303
- });
304
-
305
- /** 7. Serialize the Identity Agent's vault key set to a compact JWE, which
306
- * includes the VUK salt and encrypted VUK (nonce, tag, and ciphertext). */
307
- const vaultKeySet =
308
- Convert.object(protectedHeader).toBase64Url() + '.' +
309
- Convert.uint8Array(privateKeyCiphertext).toBase64Url() + '.' +
310
- Convert.uint8Array(nonce).toBase64Url() + '.' +
311
- Convert.string('unused').toBase64Url() + '.' +
312
- Convert.uint8Array(privateKeyTag).toBase64Url();
313
-
314
- /** Store the vault key set in the AppDataStore. */
315
- await this._store.set('vaultKeySet', vaultKeySet);
316
-
317
- /** Set the vault to initialized. */
318
- appDataStatus.initialized = true;
319
- await this.setStatus(appDataStatus);
320
- }
321
-
322
- async lock(): Promise<void> {
323
- this._vaultUnlockKey.fill(0);
324
- this._vaultUnlockKey = new Uint8Array();
325
- }
326
-
327
- async restore(_options: { backup: AppDataBackup, passphrase: string }): Promise<boolean> {
328
- throw new Error ('Not implemented');
329
- }
330
-
331
- async setStatus(options: Partial<AppDataStatus>): Promise<boolean> {
332
- // Get the current status values from the store, if any.
333
- const appDataStatus = await this.getStatus();
334
-
335
- // Update the status properties with new values specified, if any.
336
- appDataStatus.initialized = options.initialized ?? appDataStatus.initialized;
337
- appDataStatus.lastBackup = options.lastBackup ?? appDataStatus.lastBackup;
338
- appDataStatus.lastRestore = options.lastRestore ?? appDataStatus.lastRestore;
339
-
340
- // Write the changes to the store.
341
- await this._store.set('appDataStatus', JSON.stringify(appDataStatus));
342
-
343
- return true;
344
- }
345
-
346
- async unlock(options: { passphrase: string }): Promise<boolean> {
347
- const { passphrase } = options;
348
-
349
- // Get the vault key set from the store.
350
- const vaultKeySet: string = await this._store.get('vaultKeySet');
351
-
352
- // Decode the protected header.
353
- let [protectedHeaderString] = vaultKeySet.split('.');
354
- const protectedHeader = Convert.base64Url(protectedHeaderString).toObject() as JweHeaderParams;
355
-
356
- // Derive the Vault Unlock Key (VUK).
357
- if (protectedHeader.p2s !== undefined) {
358
- const salt = Convert.base64Url(protectedHeader.p2s).toUint8Array();
359
- // @ts-ignore
360
- this._vaultUnlockKey = await this.generateVaultUnlockKey({ passphrase, salt });
361
- }
362
-
363
- return true;
364
- }
365
- }