@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,299 +0,0 @@
1
- import type { KeyValueStore } from '../common/index.js';
2
- import type { DidResolutionResult, DidResolverCache, PortableDid } from '../dids/index.js';
3
-
4
- import { Level } from 'level';
5
- import { Jose } from '../crypto/index.js';
6
- import { Dwn, MessageStoreLevel, DataStoreLevel, EventLogLevel } from '@dwn-protocol/id';
7
- import { LevelStore, MemoryStore } from '../common/index.js';
8
- import { DidIonMethod, DidKeyMethod, DidResolver, DidResolverCacheLevel } from '../dids/index.js';
9
-
10
- import type { IDManagedAgent } from './types/agent.js';
11
-
12
- import { LocalKms } from './kms-local.js';
13
- import { DidManager } from './did-manager.js';
14
- import { DwnManager } from './dwn-manager.js';
15
- import { KeyManager } from './key-manager.js';
16
- import { IDRpcClient } from './rpc-client.js';
17
- import { AppDataVault } from './app-data-store.js';
18
- import { SyncManagerLevel } from './sync-manager.js';
19
- import { cryptoToPortableKeyPair } from './utils.js';
20
- import { DidStoreDwn, DidStoreMemory } from './store-managed-did.js';
21
- import { IdentityManager, ManagedIdentity } from './identity-manager.js';
22
- import { IdentityStoreDwn, IdentityStoreMemory } from './store-managed-identity.js';
23
- import { KeyStoreDwn, KeyStoreMemory, PrivateKeyStoreDwn, PrivateKeyStoreMemory } from './store-managed-key.js';
24
-
25
- type CreateMethodOptions = {
26
- agentClass: new (options: any) => IDManagedAgent
27
- agentStores?: 'dwn' | 'memory';
28
- testDataLocation?: string;
29
- }
30
-
31
- type TestManagedAgentOptions = {
32
- agent: IDManagedAgent
33
-
34
- agentStores: 'dwn' | 'memory';
35
- appDataStore: KeyValueStore<string, any>;
36
- didResolverCache: DidResolverCache;
37
- dwn: Dwn;
38
- dwnDataStore: DataStoreLevel;
39
- dwnEventLog: EventLogLevel;
40
- dwnMessageStore: MessageStoreLevel;
41
- syncStore: Level;
42
- }
43
-
44
- export class TestManagedAgent {
45
- agent: IDManagedAgent;
46
-
47
- agentStores: 'dwn' | 'memory';
48
- appDataStore: KeyValueStore<string, any>;
49
- didResolverCache: DidResolverCache;
50
- dwn: Dwn;
51
- dwnDataStore: DataStoreLevel;
52
- dwnEventLog: EventLogLevel;
53
- dwnMessageStore: MessageStoreLevel;
54
- syncStore: Level;
55
-
56
- constructor(options: TestManagedAgentOptions) {
57
- this.agent = options.agent;
58
- this.agentStores = options.agentStores;
59
- this.appDataStore = options.appDataStore;
60
- this.didResolverCache = options.didResolverCache;
61
- this.dwn = options.dwn;
62
- this.dwnDataStore = options.dwnDataStore;
63
- this.dwnEventLog = options.dwnEventLog;
64
- this.dwnMessageStore = options.dwnMessageStore;
65
- this.syncStore = options.syncStore;
66
- }
67
-
68
- async clearStorage(): Promise<void> {
69
- this.agent.agentDid = undefined;
70
- await this.appDataStore.clear();
71
- await this.didResolverCache.clear();
72
- await this.dwnDataStore.clear();
73
- await this.dwnEventLog.clear();
74
- await this.dwnMessageStore.clear();
75
- await this.syncStore.clear();
76
-
77
- /** Easiest way to start with fresh in-memory stores is to
78
- * re-instantiate all of the managed agent components */
79
- if (this.agentStores === 'memory') {
80
- const { didManager, identityManager, keyManager } = TestManagedAgent.useMemoryStorage({ agent: this.agent });
81
- this.agent.didManager = didManager;
82
- this.agent.identityManager = identityManager;
83
- this.agent.keyManager = keyManager;
84
- }
85
- }
86
-
87
- async closeStorage(): Promise<void> {
88
- await this.appDataStore.close();
89
- await this.didResolverCache.close();
90
- await this.dwnDataStore.close();
91
- await this.dwnEventLog.close();
92
- await this.dwnMessageStore.close();
93
- await this.syncStore.close();
94
- }
95
-
96
- static async create(options: CreateMethodOptions): Promise<TestManagedAgent> {
97
- let { agentClass, agentStores, testDataLocation } = options;
98
-
99
- agentStores ??= 'memory';
100
- testDataLocation ??= '__TESTDATA__';
101
- const testDataPath = (path: string) => `${testDataLocation}/${path}`;
102
-
103
- const { appData, appDataStore, didManager, didResolverCache, identityManager, keyManager } = (agentStores === 'memory')
104
- ? TestManagedAgent.useMemoryStorage()
105
- : TestManagedAgent.useDiskStorage({ testDataLocation });
106
-
107
- // Instantiate DID resolver.
108
- const didMethodApis = [DidIonMethod, DidKeyMethod];
109
- const didResolver = new DidResolver({
110
- cache : didResolverCache,
111
- didResolvers : didMethodApis
112
- });
113
-
114
- // Instantiate custom stores to use with DWN instance.
115
- const dwnDataStore = new DataStoreLevel({ blockstoreLocation: testDataPath('DWN_DATASTORE') });
116
- const dwnEventLog = new EventLogLevel({ location: testDataPath('DWN_EVENTLOG') });
117
- const dwnMessageStore = new MessageStoreLevel({
118
- blockstoreLocation : testDataPath('DWN_MESSAGESTORE'),
119
- indexLocation : testDataPath('DWN_MESSAGEINDEX')
120
- });
121
-
122
- // Instantiate custom DWN instance.
123
- const dwn = await Dwn.create({
124
- eventLog : dwnEventLog,
125
- dataStore : dwnDataStore,
126
- // @ts-expect-error because the DidResolver implementation doesn't have the dump() method.
127
- didResolver : didResolver,
128
- messageStore : dwnMessageStore
129
- });
130
-
131
- // Instantiate a DwnManager using the custom DWN instance.
132
- const dwnManager = new DwnManager({ dwn });
133
-
134
- // Instantiate an RPC Client.
135
- const rpcClient = new IDRpcClient();
136
-
137
- // Instantiate a custom SyncManager and LevelDB-backed store.
138
- const syncStore = new Level(testDataPath('SYNC_STORE'));
139
- const syncManager = new SyncManagerLevel({ db: syncStore });
140
-
141
- const agent = new agentClass({
142
- agentDid: '',
143
- appData,
144
- didManager,
145
- didResolver,
146
- dwnManager,
147
- identityManager,
148
- keyManager,
149
- rpcClient,
150
- syncManager
151
- });
152
-
153
- return new TestManagedAgent({
154
- agent,
155
- agentStores,
156
- appDataStore,
157
- didResolverCache,
158
- dwn,
159
- dwnDataStore,
160
- dwnEventLog,
161
- dwnMessageStore,
162
- syncStore,
163
- });
164
- }
165
-
166
- async createAgentDid(): Promise<void> {
167
- // Create an a DID and key set for the Agent.
168
- const agentDid = await DidKeyMethod.create({ keyAlgorithm: 'Ed25519' });
169
- const privateCryptoKey = await Jose.jwkToCryptoKey({ key: agentDid.keySet.verificationMethodKeys![0].privateKeyJwk! });
170
- const publicCryptoKey = await Jose.jwkToCryptoKey({ key: agentDid.keySet.verificationMethodKeys![0].publicKeyJwk! });
171
- const agentSigningKey = { privateKey: privateCryptoKey, publicKey: publicCryptoKey };
172
-
173
- // Set the DID as the default signing key.
174
- const alias = await this.agent.didManager.getDefaultSigningKey({ did: agentDid.did });
175
- const defaultSigningKey = cryptoToPortableKeyPair({ cryptoKeyPair: agentSigningKey, keyData: { alias, kms: 'memory' } });
176
- await this.agent.keyManager.setDefaultSigningKey({ key: defaultSigningKey });
177
-
178
- // Set the DID as the Agent's DID.
179
- this.agent.agentDid = agentDid.did;
180
- }
181
-
182
- public async createIdentity(options: {
183
- keyAlgorithm?: 'Ed25519' | 'secp256k1';
184
- testDwnUrls: string[]
185
- }): Promise<{ did: PortableDid, identity: ManagedIdentity }> {
186
- // Default to generating Ed25519 keys.
187
- const { keyAlgorithm, testDwnUrls } = options;
188
-
189
- const didOptions = await DidIonMethod.generateDwnOptions({
190
- signingKeyAlgorithm : keyAlgorithm,
191
- serviceEndpointNodes : testDwnUrls
192
- });
193
-
194
- // Create a PortableDid.
195
- const did = await DidIonMethod.create({
196
- anchor: false,
197
- ...didOptions
198
- });
199
-
200
- // Create a ManagedIdentity.
201
- const identity: ManagedIdentity = {
202
- did : did.did,
203
- name : 'Test'
204
- };
205
-
206
- return { did, identity };
207
- }
208
-
209
- private static useDiskStorage(options: { agent?: IDManagedAgent, testDataLocation: string }) {
210
- const { agent, testDataLocation } = options;
211
- const testDataPath = (path: string) => `${testDataLocation}/${path}`;
212
-
213
- const appDataStore = new LevelStore(testDataPath('APPDATA'));
214
- const appData = new AppDataVault({
215
- keyDerivationWorkFactor : 1,
216
- store : appDataStore
217
- });
218
-
219
- const didManager = new DidManager({
220
- agent,
221
- didMethods : [DidIonMethod, DidKeyMethod],
222
- store : new DidStoreDwn()
223
- });
224
-
225
- const didResolverCache = new DidResolverCacheLevel({
226
- location: testDataPath('DID_RESOLVERCACHE')
227
- });
228
-
229
- const identityManager = new IdentityManager({
230
- agent,
231
- store: new IdentityStoreDwn()
232
- });
233
-
234
- const localKmsDwn = new LocalKms({
235
- agent,
236
- kmsName : 'local',
237
- keyStore : new KeyStoreDwn({ schema: 'https://abaxx.tech/schemas/dwn/kms-key' }),
238
- privateKeyStore : new PrivateKeyStoreDwn()
239
- });
240
- const localKmsMemory = new LocalKms({
241
- agent,
242
- kmsName: 'memory'
243
- });
244
- const keyManager = new KeyManager({
245
- agent,
246
- kms: {
247
- local : localKmsDwn,
248
- memory : localKmsMemory
249
- },
250
- store: new KeyStoreDwn({ schema: 'https://abaxx.tech/schemas/dwn/managed-key' })
251
- });
252
-
253
- return { appData, appDataStore, didManager, didResolverCache, identityManager, keyManager };
254
- }
255
-
256
- private static useMemoryStorage(options?: { agent: IDManagedAgent }) {
257
- const { agent } = options ?? {};
258
-
259
- const appDataStore = new MemoryStore<string, any>();
260
- const appData = new AppDataVault({
261
- keyDerivationWorkFactor : 1,
262
- store : appDataStore
263
- });
264
-
265
- const didManager = new DidManager({
266
- agent,
267
- didMethods : [DidIonMethod, DidKeyMethod],
268
- store : new DidStoreMemory()
269
- });
270
-
271
- const didResolverCache = new MemoryStore<string, DidResolutionResult | void>();
272
-
273
- const identityManager = new IdentityManager({
274
- agent,
275
- store: new IdentityStoreMemory()
276
- });
277
-
278
- const localKmsDwn = new LocalKms({
279
- agent,
280
- kmsName : 'local',
281
- keyStore : new KeyStoreMemory(),
282
- privateKeyStore : new PrivateKeyStoreMemory()
283
- });
284
- const localKmsMemory = new LocalKms({
285
- agent,
286
- kmsName: 'memory'
287
- });
288
- const keyManager = new KeyManager({
289
- agent,
290
- kms: {
291
- local : localKmsDwn,
292
- memory : localKmsMemory
293
- },
294
- store: new KeyStoreMemory()
295
- });
296
-
297
- return { appData, appDataStore, didManager, didResolverCache, identityManager, keyManager };
298
- }
299
- }
@@ -1,145 +0,0 @@
1
- import type { Readable } from 'readable-stream';
2
- import type { DidResolutionOptions, DidResolutionResult, PortableDid } from '../../dids/index.js';
3
- import type {
4
- EventsGetMessage,
5
- RecordsReadReply,
6
- UnionMessageReply,
7
- MessagesGetMessage,
8
- RecordsQueryMessage,
9
- RecordsWriteMessage,
10
- RecordsDeleteMessage,
11
- ProtocolsQueryMessage,
12
- ProtocolsConfigureMessage,
13
- } from '@dwn-protocol/id';
14
-
15
- import { DidResolver } from '../../dids/index.js';
16
-
17
- import type { Outbox } from '../outbox.js';
18
- import type { SyncManager } from '../sync-manager.js';
19
- import type { AppDataStore } from '../app-data-store.js';
20
- import type { DwnRpcResponse, IDRpc } from '../rpc-client.js';
21
-
22
- import { DidManager, DidMessage } from '../did-manager.js';
23
- import { DwnManager } from '../dwn-manager.js';
24
- import { KeyManager } from '../key-manager.js';
25
- import { IdentityManager } from '../identity-manager.js';
26
-
27
- /**
28
- * DID Types
29
- */
30
-
31
- export type DidMessageType = keyof typeof DidMessage;
32
-
33
- export type DidRequest = {
34
- messageType: DidMessageType;
35
- messageOptions: any;
36
- store?: boolean;
37
- }
38
-
39
- export type DidCreateMessage = {
40
- didMethod: string;
41
- didOptions?: any;
42
- }
43
-
44
- export type DidResolveMessage = {
45
- didUrl: string;
46
- resolutionOptions?: DidResolutionOptions;
47
- }
48
-
49
- export type DidResponse = {
50
- result?: DidResolutionResult | PortableDid
51
- };
52
-
53
- /**
54
- * DWN Types
55
- */
56
- export type DwnMessages = {
57
- 'EventsGet': EventsGetMessage;
58
- 'MessagesGet': MessagesGetMessage;
59
- 'RecordsWrite': RecordsWriteMessage;
60
- 'RecordsQuery': RecordsQueryMessage;
61
- 'RecordsDelete': RecordsDeleteMessage;
62
- 'ProtocolsQuery': ProtocolsQueryMessage;
63
- 'ProtocolsConfigure': ProtocolsConfigureMessage;
64
- };
65
-
66
- export type DwnMessageType = keyof DwnMessages;
67
-
68
- export type DwnRequest = {
69
- author: string;
70
- target: any;
71
- messageType: string;
72
- }
73
-
74
- /**
75
- * ProcessDwnRequest
76
- *
77
- * @beta
78
- */
79
- export type ProcessDwnRequest = DwnRequest & {
80
- dataStream?: Blob | ReadableStream | Readable;
81
- messageOptions: unknown;
82
- store?: boolean;
83
- };
84
-
85
- export type SendDwnRequest = DwnRequest & (ProcessDwnRequest | { messageCid: string })
86
-
87
- /**
88
- * DwnResponse
89
- *
90
- * @beta
91
- */
92
- export type DwnResponse = {
93
- message?: unknown;
94
- messageCid?: string;
95
- reply: UnionMessageReply & RecordsReadReply;
96
- };
97
-
98
- /**
99
- * SendDwnResponse
100
- *
101
- * @beta
102
- */
103
- export type SendDwnResponse = DwnRpcResponse;
104
-
105
- export interface SerializableDwnMessage {
106
- toJSON(): string;
107
- }
108
-
109
- /**
110
- * Verifiable Credential Types
111
- */
112
-
113
- export type ProcessVcRequest = { /** empty */ }
114
- export type SendVcRequest = { /** empty */ }
115
- export type VcResponse = { /** empty */ }
116
-
117
- /**
118
- * Agent Types
119
- */
120
- export interface IDAgent {
121
- agentDid: string | undefined;
122
-
123
- processDidRequest(request: DidRequest): Promise<DidResponse>
124
- sendDidRequest(request: DidRequest): Promise<DidResponse>;
125
- processDwnRequest(request: ProcessDwnRequest): Promise<DwnResponse>
126
- sendDwnRequest(request: SendDwnRequest): Promise<DwnResponse>;
127
- processVcRequest(request: ProcessVcRequest): Promise<VcResponse>
128
- sendVcRequest(request: SendVcRequest): Promise<VcResponse>;
129
- }
130
-
131
- export interface IDManagedAgent extends IDAgent {
132
- appData: AppDataStore;
133
- didManager: DidManager;
134
- didResolver: DidResolver;
135
- dwnManager: DwnManager;
136
- identityManager: IdentityManager;
137
- keyManager: KeyManager;
138
- outbox?: Outbox;
139
- rpcClient: IDRpc;
140
- syncManager: SyncManager;
141
-
142
- firstLaunch(): Promise<boolean>;
143
- initialize(options: { passphrase: string }): Promise<void>;
144
- start(options: { passphrase: string }): Promise<void>;
145
- }