@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
|
@@ -1,243 +0,0 @@
|
|
|
1
|
-
//@ts-nocheck
|
|
2
|
-
import { Convert } from '../common/index.js';
|
|
3
|
-
|
|
4
|
-
import type { IDManagedAgent } from './types/agent.js';
|
|
5
|
-
import type { ManagedIdentity } from './identity-manager.js';
|
|
6
|
-
import type { RecordsWriteMessage } from '@dwn-protocol/id';
|
|
7
|
-
|
|
8
|
-
export interface ManagedIdentityStore {
|
|
9
|
-
deleteIdentity(options: { did: string, agent?: IDManagedAgent, context?: string }): Promise<boolean>
|
|
10
|
-
getIdentity(options: { did: string, agent?: IDManagedAgent, context?: string }): Promise<ManagedIdentity | undefined>
|
|
11
|
-
importIdentity(options: { identity: ManagedIdentity, agent?: IDManagedAgent, context?: string }): Promise<void>
|
|
12
|
-
listIdentities(options?: { agent?: IDManagedAgent, context?: string }): Promise<ManagedIdentity[]>
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
*
|
|
17
|
-
*/
|
|
18
|
-
export class IdentityStoreDwn implements ManagedIdentityStore {
|
|
19
|
-
private _identityRecordProperties = {
|
|
20
|
-
dataFormat : 'application/json',
|
|
21
|
-
schema : 'https://abaxx.tech/schemas/dwn/managed-identity'
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
async deleteIdentity(options: {
|
|
25
|
-
agent: IDManagedAgent,
|
|
26
|
-
context?: string,
|
|
27
|
-
did: string
|
|
28
|
-
}): Promise<boolean> {
|
|
29
|
-
const { agent, context, did } = options;
|
|
30
|
-
|
|
31
|
-
// Determine which DID to use to author DWN messages.
|
|
32
|
-
const authorDid = await this.getAuthor({ agent, context, did });
|
|
33
|
-
|
|
34
|
-
// Query the DWN for all stored Identity objects.
|
|
35
|
-
const { reply: queryReply} = await agent.dwnManager.processRequest({
|
|
36
|
-
author : authorDid,
|
|
37
|
-
target : authorDid,
|
|
38
|
-
messageType : 'RecordsQuery',
|
|
39
|
-
messageOptions : {
|
|
40
|
-
filter: { ...this._identityRecordProperties }
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
// Loop through all of the entries and try to find a match.
|
|
45
|
-
let matchingRecordId: string | undefined;
|
|
46
|
-
for (const record of queryReply.entries ?? []) {
|
|
47
|
-
if (record.encodedData) {
|
|
48
|
-
const storedIdentity = Convert.base64Url(record.encodedData).toObject() as ManagedIdentity;
|
|
49
|
-
if (storedIdentity && storedIdentity.did === did) {
|
|
50
|
-
matchingRecordId = (record as RecordsWriteMessage).recordId ;
|
|
51
|
-
break;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// Return undefined if the specified Identity was not found in the store.
|
|
57
|
-
if (!matchingRecordId) return false;
|
|
58
|
-
|
|
59
|
-
// If a record for the specified Identity was found, attempt to delete it.
|
|
60
|
-
const { reply: { status } } = await agent.dwnManager.processRequest({
|
|
61
|
-
author : authorDid,
|
|
62
|
-
target : authorDid,
|
|
63
|
-
messageType : 'RecordsDelete',
|
|
64
|
-
messageOptions : {
|
|
65
|
-
recordId: matchingRecordId
|
|
66
|
-
}
|
|
67
|
-
});
|
|
68
|
-
|
|
69
|
-
// If the Identity was successfully deleted, return true;
|
|
70
|
-
if (status.code === 202) return true;
|
|
71
|
-
|
|
72
|
-
// If the Identity could not be deleted, return false;
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async getIdentity(options: {
|
|
77
|
-
agent: IDManagedAgent,
|
|
78
|
-
context?: string,
|
|
79
|
-
did: string
|
|
80
|
-
}): Promise<ManagedIdentity | undefined> {
|
|
81
|
-
const { agent, context, did } = options;
|
|
82
|
-
|
|
83
|
-
// Determine which DID to use to author DWN messages.
|
|
84
|
-
const authorDid = await this.getAuthor({ agent, context, did });
|
|
85
|
-
|
|
86
|
-
// Query the DWN for all stored Identity objects.
|
|
87
|
-
const { reply: queryReply} = await agent.dwnManager.processRequest({
|
|
88
|
-
author : authorDid,
|
|
89
|
-
target : authorDid,
|
|
90
|
-
messageType : 'RecordsQuery',
|
|
91
|
-
messageOptions : { filter: { ...this._identityRecordProperties } }
|
|
92
|
-
});
|
|
93
|
-
|
|
94
|
-
// Loop through all of the entries and return a match, if found.
|
|
95
|
-
for (const record of queryReply.entries ?? []) {
|
|
96
|
-
if (record.encodedData) {
|
|
97
|
-
const storedIdentity = Convert.base64Url(record.encodedData).toObject() as ManagedIdentity;
|
|
98
|
-
if (storedIdentity && storedIdentity.did === did) return storedIdentity;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// Return undefined if no matches were found.
|
|
103
|
-
return undefined;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
async importIdentity(options: {
|
|
107
|
-
agent: IDManagedAgent,
|
|
108
|
-
context?: string,
|
|
109
|
-
identity: ManagedIdentity
|
|
110
|
-
}) {
|
|
111
|
-
const { agent, context, identity } = options;
|
|
112
|
-
|
|
113
|
-
// Determine which DID to use to author DWN messages.
|
|
114
|
-
const authorDid = await this.getAuthor({ agent, context, did: identity.did });
|
|
115
|
-
|
|
116
|
-
// Check if the Identity being imported is already present in the store.
|
|
117
|
-
const duplicateFound = await this.getIdentity({ agent, context, did: identity.did });
|
|
118
|
-
if (duplicateFound) {
|
|
119
|
-
throw new Error(`IdentityStoreDwn: Identity with DID already exists: '${identity.did}'`);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// Encode the ManagedIdentity as bytes.
|
|
123
|
-
const identityU8A = Convert.object(identity).toUint8Array();
|
|
124
|
-
|
|
125
|
-
const { reply: { status } } = await agent.dwnManager.processRequest({
|
|
126
|
-
author : authorDid,
|
|
127
|
-
target : authorDid,
|
|
128
|
-
messageType : 'RecordsWrite',
|
|
129
|
-
messageOptions : { ...this._identityRecordProperties },
|
|
130
|
-
dataStream : new Blob([identityU8A])
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
// If the write fails, throw an error.
|
|
134
|
-
if (status.code !== 202) {
|
|
135
|
-
throw new Error('IdentityStoreDwn: Failed to write imported identity to store.');
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
async listIdentities(options: {
|
|
140
|
-
agent: IDManagedAgent,
|
|
141
|
-
context?: string
|
|
142
|
-
}): Promise<ManagedIdentity[]> {
|
|
143
|
-
const { agent, context } = options;
|
|
144
|
-
|
|
145
|
-
// Determine which DID to use to author DWN messages.
|
|
146
|
-
const authorDid = await this.getAuthor({ agent, context });
|
|
147
|
-
|
|
148
|
-
// Query the DWN for all stored Identity objects.
|
|
149
|
-
const { reply: queryReply} = await agent.dwnManager.processRequest({
|
|
150
|
-
author : authorDid,
|
|
151
|
-
target : authorDid,
|
|
152
|
-
messageType : 'RecordsQuery',
|
|
153
|
-
messageOptions : {
|
|
154
|
-
filter: { ...this._identityRecordProperties }
|
|
155
|
-
}
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
// Loop through all of the entries and accumulate the Identity objects.
|
|
159
|
-
let storedIdentities: ManagedIdentity[] = [];
|
|
160
|
-
for (const record of queryReply.entries ?? []) {
|
|
161
|
-
if (record.encodedData) {
|
|
162
|
-
const storedIdentity = Convert.base64Url(record.encodedData).toObject() as ManagedIdentity;
|
|
163
|
-
storedIdentities.push(storedIdentity);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return storedIdentities;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
private async getAuthor(options: {
|
|
171
|
-
context?: string,
|
|
172
|
-
did?: string,
|
|
173
|
-
agent: IDManagedAgent
|
|
174
|
-
}): Promise<string> {
|
|
175
|
-
const { context, did, agent } = options;
|
|
176
|
-
|
|
177
|
-
// If `context` is specified, DWN messages will be signed by this DID.
|
|
178
|
-
if (context) return context;
|
|
179
|
-
|
|
180
|
-
// If Agent has an agentDid, use it to sign DWN messages.
|
|
181
|
-
if (agent.agentDid) return agent.agentDid;
|
|
182
|
-
|
|
183
|
-
// If `context`, `agent.agentDid`, and `did` are undefined, throw error.
|
|
184
|
-
if (!did) {
|
|
185
|
-
throw new Error(`DidStoreDwn: Agent property 'agentDid' is undefined.`);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/** Lacking a context and agentDid DID, check whether KeyManager has
|
|
189
|
-
* a key pair for the given `did` value.*/
|
|
190
|
-
const signingKeyId = await agent.didManager.getDefaultSigningKey({ did });
|
|
191
|
-
const keyPair = (signingKeyId)
|
|
192
|
-
? await agent.keyManager.getKey({ keyRef: signingKeyId })
|
|
193
|
-
: undefined;
|
|
194
|
-
|
|
195
|
-
// If a key pair is found, use the `did` to sign messages.
|
|
196
|
-
if (keyPair) return did;
|
|
197
|
-
|
|
198
|
-
// If all else fails, throw an error.
|
|
199
|
-
throw new Error(`IdentityStoreDwn: Agent property 'agentDid' is undefined and no keys were found for: '${did}'`);
|
|
200
|
-
}
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
*
|
|
205
|
-
*/
|
|
206
|
-
export class IdentityStoreMemory implements ManagedIdentityStore {
|
|
207
|
-
/**
|
|
208
|
-
* A private field that contains the Map used as the in-memory key-value store.
|
|
209
|
-
*/
|
|
210
|
-
private store: Map<string, ManagedIdentity> = new Map();
|
|
211
|
-
|
|
212
|
-
async deleteIdentity({ did }: { did: string; }): Promise<boolean> {
|
|
213
|
-
if (this.store.has(did)) {
|
|
214
|
-
// Identity with given DID exists so proceed with delete.
|
|
215
|
-
this.store.delete(did);
|
|
216
|
-
return true;
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// Identity with given DID not present so delete operation not possible.
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
async getIdentity({ did }: { did: string; }): Promise<ManagedIdentity | undefined> {
|
|
224
|
-
return this.store.get(did);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
async importIdentity(options: { identity: ManagedIdentity }) {
|
|
228
|
-
const { identity } = options;
|
|
229
|
-
|
|
230
|
-
if (this.store.has(identity.did)) {
|
|
231
|
-
// Identity with given identifier already exists so import operation cannot proceed.
|
|
232
|
-
throw new Error(`IdentityStoreMemory: Identity with DID already exists: '${identity.did}'`);
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
// Make a deep copy of the Identity so that the object stored does not share the same references as the input.
|
|
236
|
-
const clonedIdentity = structuredClone(identity);
|
|
237
|
-
this.store.set(identity.did, clonedIdentity);
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
async listIdentities(): Promise<ManagedIdentity[]> {
|
|
241
|
-
return Array.from(this.store.values());
|
|
242
|
-
}
|
|
243
|
-
}
|