@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.
- package/package.json +2 -3
- package/src/agent/app-data-store.ts +0 -365
- package/src/agent/did-manager.ts +0 -393
- package/src/agent/dwn-manager.ts +0 -548
- package/src/agent/identity-manager.ts +0 -165
- package/src/agent/index.ts +0 -19
- package/src/agent/json-rpc.ts +0 -107
- package/src/agent/key-manager.ts +0 -302
- package/src/agent/kms-local.ts +0 -412
- package/src/agent/outbox.ts +0 -128
- package/src/agent/rpc-client.ts +0 -223
- package/src/agent/store-managed-did.ts +0 -295
- package/src/agent/store-managed-identity.ts +0 -243
- package/src/agent/store-managed-key.ts +0 -754
- package/src/agent/sync-manager.ts +0 -631
- package/src/agent/test-managed-agent.ts +0 -299
- package/src/agent/types/agent.ts +0 -145
- package/src/agent/types/managed-key.ts +0 -442
- package/src/agent/utils.ts +0 -190
- package/src/common/convert.ts +0 -424
- package/src/common/index.ts +0 -9
- package/src/common/multicodec.ts +0 -176
- package/src/common/object.ts +0 -43
- package/src/common/stores.ts +0 -125
- package/src/common/stream-node.ts +0 -381
- package/src/common/stream.ts +0 -406
- package/src/common/type-utils.ts +0 -117
- package/src/common/types.ts +0 -48
- package/src/credentials/credential-bbs.ts +0 -419
- package/src/credentials/credential.ts +0 -324
- package/src/credentials/index.ts +0 -5
- package/src/credentials/presentation.ts +0 -182
- package/src/credentials/status-list.ts +0 -365
- package/src/credentials/utils.ts +0 -58
- package/src/credentials/validators.ts +0 -52
- package/src/crypto/algorithms-api/aes/base.ts +0 -49
- package/src/crypto/algorithms-api/aes/ctr.ts +0 -51
- package/src/crypto/algorithms-api/aes/index.ts +0 -2
- package/src/crypto/algorithms-api/crypto-algorithm.ts +0 -127
- package/src/crypto/algorithms-api/crypto-key.ts +0 -56
- package/src/crypto/algorithms-api/ec/base.ts +0 -39
- package/src/crypto/algorithms-api/ec/ecdh.ts +0 -53
- package/src/crypto/algorithms-api/ec/ecdsa.ts +0 -37
- package/src/crypto/algorithms-api/ec/eddsa.ts +0 -30
- package/src/crypto/algorithms-api/ec/index.ts +0 -4
- package/src/crypto/algorithms-api/errors.ts +0 -29
- package/src/crypto/algorithms-api/index.ts +0 -6
- package/src/crypto/algorithms-api/pbkdf/index.ts +0 -1
- package/src/crypto/algorithms-api/pbkdf/pbkdf2.ts +0 -91
- package/src/crypto/crypto-algorithms/aes-ctr.ts +0 -70
- package/src/crypto/crypto-algorithms/bbs.ts +0 -110
- package/src/crypto/crypto-algorithms/ecdh.ts +0 -115
- package/src/crypto/crypto-algorithms/ecdsa.ts +0 -111
- package/src/crypto/crypto-algorithms/eddsa.ts +0 -110
- package/src/crypto/crypto-algorithms/index.ts +0 -6
- package/src/crypto/crypto-algorithms/pbkdf2.ts +0 -54
- package/src/crypto/crypto-primitives/aes-ctr.ts +0 -131
- package/src/crypto/crypto-primitives/aes-gcm.ts +0 -138
- package/src/crypto/crypto-primitives/bbs.ts +0 -183
- package/src/crypto/crypto-primitives/concat-kdf.ts +0 -207
- package/src/crypto/crypto-primitives/ed25519.ts +0 -201
- package/src/crypto/crypto-primitives/index.ts +0 -10
- package/src/crypto/crypto-primitives/pbkdf2.ts +0 -78
- package/src/crypto/crypto-primitives/secp256k1.ts +0 -322
- package/src/crypto/crypto-primitives/x25519.ts +0 -101
- package/src/crypto/crypto-primitives/xchacha20-poly1305.ts +0 -46
- package/src/crypto/crypto-primitives/xchacha20.ts +0 -34
- package/src/crypto/index.ts +0 -8
- package/src/crypto/jose.ts +0 -948
- package/src/crypto/types/crypto-key.ts +0 -4
- package/src/crypto/types/iddwn-crypto.ts +0 -119
- package/src/crypto/utils.ts +0 -200
- package/src/did-api.ts +0 -72
- package/src/dids/dht.ts +0 -412
- package/src/dids/did-dht.ts +0 -436
- package/src/dids/did-ion.ts +0 -613
- package/src/dids/did-key.ts +0 -791
- package/src/dids/did-resolver.ts +0 -107
- package/src/dids/index.ts +0 -9
- package/src/dids/resolver-cache-level.ts +0 -82
- package/src/dids/resolver-cache-noop.ts +0 -25
- package/src/dids/types.ts +0 -278
- package/src/dids/utils.ts +0 -129
- package/src/dwn-api.ts +0 -584
- package/src/iddwn.ts +0 -241
- package/src/identity-agent/index.ts +0 -270
- package/src/index.ts +0 -26
- package/src/interfaces/metadata.ts +0 -163
- package/src/interfaces/queue.ts +0 -108
- package/src/interfaces/services.ts +0 -122
- package/src/interfaces/transactions.ts +0 -220
- package/src/protocol.ts +0 -68
- package/src/proxy-agent/index.ts +0 -255
- package/src/record.ts +0 -521
- package/src/service-options.ts +0 -62
- package/src/typings/decentralized-identity__ion-pow-sdk.d.ts +0 -7
- package/src/user-agent/index.ts +0 -295
- package/src/utils.ts +0 -29
- package/src/vc-api.ts +0 -505
package/src/user-agent/index.ts
DELETED
|
@@ -1,295 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
IDRpc,
|
|
3
|
-
DidRequest,
|
|
4
|
-
VcResponse,
|
|
5
|
-
DidResponse,
|
|
6
|
-
DwnResponse,
|
|
7
|
-
SyncManager,
|
|
8
|
-
AppDataStore,
|
|
9
|
-
SendVcRequest,
|
|
10
|
-
SendDwnRequest,
|
|
11
|
-
ProcessVcRequest,
|
|
12
|
-
IDManagedAgent,
|
|
13
|
-
ProcessDwnRequest,
|
|
14
|
-
} from '../agent/index.js';
|
|
15
|
-
|
|
16
|
-
// import { DateSort, DataStream } from '@dwn-protocol/id';
|
|
17
|
-
// import { DwnApi } from '../dwn-api.js';
|
|
18
|
-
import { LevelStore } from '../common/index.js';
|
|
19
|
-
import { EdDsaAlgorithm } from '../crypto/index.js';
|
|
20
|
-
import { DidIonMethod, DidKeyMethod, DidResolverCacheLevel, DidResolver, DidDhtMethod } from '../dids/index.js';
|
|
21
|
-
import { Level } from 'level';
|
|
22
|
-
import {
|
|
23
|
-
LocalKms,
|
|
24
|
-
DidManager,
|
|
25
|
-
DwnManager,
|
|
26
|
-
KeyManager,
|
|
27
|
-
DidStoreDwn,
|
|
28
|
-
KeyStoreDwn,
|
|
29
|
-
AppDataVault,
|
|
30
|
-
IDRpcClient,
|
|
31
|
-
IdentityManager,
|
|
32
|
-
IdentityStoreDwn,
|
|
33
|
-
Outbox,
|
|
34
|
-
SyncManagerLevel,
|
|
35
|
-
PrivateKeyStoreDwn,
|
|
36
|
-
cryptoToPortableKeyPair,
|
|
37
|
-
DidMessage,
|
|
38
|
-
} from '../agent/index.js';
|
|
39
|
-
|
|
40
|
-
export type IDUserAgentOptions = {
|
|
41
|
-
agentDid: string;
|
|
42
|
-
appData: AppDataStore;
|
|
43
|
-
didManager: DidManager;
|
|
44
|
-
didResolver: DidResolver;
|
|
45
|
-
dwnManager: DwnManager;
|
|
46
|
-
identityManager: IdentityManager;
|
|
47
|
-
keyManager: KeyManager;
|
|
48
|
-
outbox?: Outbox;
|
|
49
|
-
rpcClient: IDRpc;
|
|
50
|
-
syncManager: SyncManager;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let connected: boolean = false;
|
|
54
|
-
|
|
55
|
-
export class IDUserAgent implements IDManagedAgent {
|
|
56
|
-
agentDid: string;
|
|
57
|
-
appData: AppDataStore;
|
|
58
|
-
didManager: DidManager;
|
|
59
|
-
didResolver: DidResolver;
|
|
60
|
-
dwnManager: DwnManager;
|
|
61
|
-
identityManager: IdentityManager;
|
|
62
|
-
keyManager: KeyManager;
|
|
63
|
-
outbox?: Outbox;
|
|
64
|
-
rpcClient: IDRpc;
|
|
65
|
-
syncManager: SyncManager;
|
|
66
|
-
|
|
67
|
-
constructor(options: IDUserAgentOptions) {
|
|
68
|
-
this.agentDid = options.agentDid;
|
|
69
|
-
this.appData = options.appData;
|
|
70
|
-
this.keyManager = options.keyManager;
|
|
71
|
-
this.didManager = options.didManager;
|
|
72
|
-
this.didResolver = options.didResolver;
|
|
73
|
-
this.dwnManager = options.dwnManager;
|
|
74
|
-
this.identityManager = options.identityManager;
|
|
75
|
-
this.outbox = options.outbox;
|
|
76
|
-
this.rpcClient = options.rpcClient;
|
|
77
|
-
this.syncManager = options.syncManager;
|
|
78
|
-
|
|
79
|
-
// Set this agent to be the default agent.
|
|
80
|
-
this.didManager.agent = this;
|
|
81
|
-
this.dwnManager.agent = this;
|
|
82
|
-
this.identityManager.agent = this;
|
|
83
|
-
this.keyManager.agent = this;
|
|
84
|
-
this.syncManager.agent = this;
|
|
85
|
-
if (this.outbox) {
|
|
86
|
-
this.outbox.agent = this;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
static async create(options: Partial<IDUserAgentOptions> & { queueWhenOffline?: boolean } = {}): Promise<IDUserAgent> {
|
|
91
|
-
let {
|
|
92
|
-
agentDid, appData, didManager, didResolver, dwnManager,
|
|
93
|
-
identityManager, keyManager, rpcClient, syncManager, queueWhenOffline
|
|
94
|
-
} = options;
|
|
95
|
-
|
|
96
|
-
if (agentDid === undefined) {
|
|
97
|
-
// An Agent DID was not specified, so set to empty string.
|
|
98
|
-
agentDid = '';
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
if (appData === undefined) {
|
|
102
|
-
/** A custom AppDataStore implementation was not specified, so
|
|
103
|
-
* instantiate a LevelDB backed secure AppDataVault. */
|
|
104
|
-
appData = new AppDataVault({
|
|
105
|
-
store: new LevelStore('data/AGENT/APPDATA')
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (didManager === undefined) {
|
|
110
|
-
/** A custom DidManager implementation was not specified, so
|
|
111
|
-
* instantiate a default that uses a DWN-backed store. */
|
|
112
|
-
didManager = new DidManager({
|
|
113
|
-
didMethods : [DidIonMethod, DidKeyMethod, DidDhtMethod],
|
|
114
|
-
store : new DidStoreDwn()
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
if (didResolver === undefined) {
|
|
119
|
-
/** A custom DidManager implementation was not specified, so
|
|
120
|
-
* instantiate a default that uses a DWN-backed store and
|
|
121
|
-
* LevelDB-backed resolution cache. */
|
|
122
|
-
didResolver = new DidResolver({
|
|
123
|
-
cache : new DidResolverCacheLevel(),
|
|
124
|
-
didResolvers : [DidIonMethod, DidKeyMethod, DidDhtMethod]
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (dwnManager === undefined) {
|
|
129
|
-
/** A custom DwnManager implementation was not specified, so
|
|
130
|
-
* instantiate a default. */
|
|
131
|
-
dwnManager = await DwnManager.create({ didResolver });
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (identityManager === undefined) {
|
|
135
|
-
/** A custom IdentityManager implementation was not specified, so
|
|
136
|
-
* instantiate a default that uses a DWN-backed store. */
|
|
137
|
-
identityManager = new IdentityManager({
|
|
138
|
-
store: new IdentityStoreDwn()
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
if (keyManager === undefined) {
|
|
143
|
-
/** A custom KeyManager implementation was not specified, so
|
|
144
|
-
* instantiate a default with KMSs that use a DWN-backed store. */
|
|
145
|
-
const localKmsDwn = new LocalKms({
|
|
146
|
-
kmsName : 'local',
|
|
147
|
-
keyStore : new KeyStoreDwn({ schema: 'https://abaxx.tech/schemas/dwn/kms-key' }),
|
|
148
|
-
privateKeyStore : new PrivateKeyStoreDwn()
|
|
149
|
-
});
|
|
150
|
-
const localKmsMemory = new LocalKms({
|
|
151
|
-
kmsName: 'memory'
|
|
152
|
-
});
|
|
153
|
-
keyManager = new KeyManager({
|
|
154
|
-
kms: {
|
|
155
|
-
local : localKmsDwn,
|
|
156
|
-
memory : localKmsMemory
|
|
157
|
-
},
|
|
158
|
-
store: new KeyStoreDwn({ schema: 'https://abaxx.tech/schemas/dwn/managed-key' })
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
if (rpcClient === undefined) {
|
|
163
|
-
// A custom RPC Client implementation was not specified, so
|
|
164
|
-
// instantiate a default.
|
|
165
|
-
rpcClient = new IDRpcClient();
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
if (syncManager === undefined) {
|
|
169
|
-
// A custom SyncManager implementation was not specified, so
|
|
170
|
-
// instantiate a LevelDB-backed default. When queueWhenOffline is enabled,
|
|
171
|
-
// use a shared Level so Outbox and SyncManager share the same store root.
|
|
172
|
-
if (queueWhenOffline !== false) {
|
|
173
|
-
const agentDb = new Level('data/AGENT');
|
|
174
|
-
syncManager = new SyncManagerLevel({ db: agentDb });
|
|
175
|
-
options.outbox = new Outbox({ db: agentDb });
|
|
176
|
-
} else {
|
|
177
|
-
syncManager = new SyncManagerLevel();
|
|
178
|
-
}
|
|
179
|
-
} else if (queueWhenOffline !== false && options.outbox === undefined) {
|
|
180
|
-
options.outbox = new Outbox();
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
// Instantiate the Agent.
|
|
184
|
-
const agent = new IDUserAgent({
|
|
185
|
-
agentDid,
|
|
186
|
-
appData,
|
|
187
|
-
didManager,
|
|
188
|
-
didResolver,
|
|
189
|
-
dwnManager,
|
|
190
|
-
keyManager,
|
|
191
|
-
identityManager,
|
|
192
|
-
outbox: options.outbox,
|
|
193
|
-
rpcClient,
|
|
194
|
-
syncManager
|
|
195
|
-
});
|
|
196
|
-
// connected = false;
|
|
197
|
-
return agent;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
static isConnected(): boolean {
|
|
201
|
-
return connected;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
async firstLaunch(): Promise<boolean> {
|
|
205
|
-
// Check whether data vault is already initialized.
|
|
206
|
-
const { initialized } = await this.appData.getStatus();
|
|
207
|
-
return initialized === false;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
/** Executed once the first time the Agent is launched.
|
|
211
|
-
* The passphrase should be input by the end-user. */
|
|
212
|
-
async initialize(options: { passphrase: string }) {
|
|
213
|
-
const { passphrase } = options;
|
|
214
|
-
|
|
215
|
-
// Generate an Ed25519 key pair for the Agent.
|
|
216
|
-
const agentKeyPair = await new EdDsaAlgorithm().generateKey({
|
|
217
|
-
algorithm : { name: 'EdDSA', namedCurve: 'Ed25519' },
|
|
218
|
-
extractable : true,
|
|
219
|
-
keyUsages : ['sign', 'verify']
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
/** Initialize the AppDataStore with the Agent's
|
|
223
|
-
* private key and passphrase, which also unlocks the data vault. */
|
|
224
|
-
await this.appData.initialize({
|
|
225
|
-
passphrase : passphrase,
|
|
226
|
-
keyPair : agentKeyPair,
|
|
227
|
-
});
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
async processDidRequest(request: DidRequest): Promise<DidResponse> {
|
|
231
|
-
switch (request.messageType) {
|
|
232
|
-
case DidMessage.Resolve: {
|
|
233
|
-
const { didUrl, resolutionOptions } = request.messageOptions;
|
|
234
|
-
const result = await this.didResolver.resolve(didUrl, resolutionOptions);
|
|
235
|
-
return { result };
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
default: {
|
|
239
|
-
return this.didManager.processRequest(request);
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
async processDwnRequest(request: ProcessDwnRequest): Promise<DwnResponse> {
|
|
245
|
-
return this.dwnManager.processRequest(request);
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
async processVcRequest(_request: ProcessVcRequest): Promise<VcResponse> {
|
|
249
|
-
throw new Error('Not implemented');
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
async sendDidRequest(_request: DidRequest): Promise<DidResponse> {
|
|
253
|
-
throw new Error('Not implemented');
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
async sendDwnRequest(request: SendDwnRequest): Promise<DwnResponse> {
|
|
257
|
-
return this.dwnManager.sendRequest(request);
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
async sendVcRequest(_request: SendVcRequest): Promise<VcResponse> {
|
|
261
|
-
throw new Error('Not implemented');
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
async start(options: { passphrase: string }) {
|
|
265
|
-
const { passphrase } = options;
|
|
266
|
-
|
|
267
|
-
if (await this.firstLaunch()) {
|
|
268
|
-
// 1A. Agent's first launch so initialize.
|
|
269
|
-
await this.initialize({ passphrase });
|
|
270
|
-
} else {
|
|
271
|
-
// 1B. Agent was previously initialized.
|
|
272
|
-
// Unlock the data vault and cache the vault unlock key (VUK) in memory.
|
|
273
|
-
await this.appData.unlock({ passphrase });
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
// 2. Set the Agent's root did:key identifier.
|
|
277
|
-
this.agentDid = await this.appData.getDid();
|
|
278
|
-
|
|
279
|
-
// 3. Import the Agent's private key into the KeyManager.
|
|
280
|
-
const defaultSigningKey = cryptoToPortableKeyPair({
|
|
281
|
-
cryptoKeyPair: {
|
|
282
|
-
privateKey : await this.appData.getPrivateKey(),
|
|
283
|
-
publicKey : await this.appData.getPublicKey()
|
|
284
|
-
},
|
|
285
|
-
keyData: {
|
|
286
|
-
alias : await this.didManager.getDefaultSigningKey({ did: this.agentDid }),
|
|
287
|
-
kms : 'memory'
|
|
288
|
-
}
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
// Import the Agent's signing key pair to the in-memory KMS key stores.
|
|
292
|
-
await this.keyManager.setDefaultSigningKey({ key: defaultSigningKey });
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { Convert, universalTypeOf } from './common/index.js';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Set/detect the media type and return the data as bytes.
|
|
5
|
-
*
|
|
6
|
-
* @beta
|
|
7
|
-
*/
|
|
8
|
-
export const dataToBlob = (data: any, dataFormat?: string) => {
|
|
9
|
-
let dataBlob: Blob;
|
|
10
|
-
|
|
11
|
-
// Check for Object or String, and if neither, assume bytes.
|
|
12
|
-
const detectedType = universalTypeOf(data);
|
|
13
|
-
if (dataFormat === 'text/plain' || detectedType === 'String') {
|
|
14
|
-
dataBlob = new Blob([data], { type: 'text/plain' });
|
|
15
|
-
} else if (dataFormat === 'application/json' || detectedType === 'Object') {
|
|
16
|
-
const dataBytes: any = Convert.object(data).toUint8Array();
|
|
17
|
-
dataBlob = new Blob([dataBytes], { type: 'application/json' });
|
|
18
|
-
} else if (detectedType === 'Uint8Array' || detectedType === 'ArrayBuffer') {
|
|
19
|
-
dataBlob = new Blob([data], { type: 'application/octet-stream' });
|
|
20
|
-
} else if (detectedType === 'Blob') {
|
|
21
|
-
dataBlob = data;
|
|
22
|
-
} else {
|
|
23
|
-
throw new Error('data type not supported.');
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
dataFormat = dataFormat || dataBlob.type || 'application/octet-stream';
|
|
27
|
-
|
|
28
|
-
return { dataBlob, dataFormat };
|
|
29
|
-
};
|