@extrimian/agent 0.12.0-1 → 0.12.0-11
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/dist/agent.d.ts +77 -77
- package/dist/agent.js +173 -173
- package/dist/agent.js.map +1 -1
- package/dist/data-share-behaviours/data-share-behavior.d.ts +4 -4
- package/dist/data-share-behaviours/data-share-behavior.js +2 -2
- package/dist/data-share-behaviours/identity-data-share-behavior.d.ts +16 -16
- package/dist/data-share-behaviours/identity-data-share-behavior.js +2 -2
- package/dist/data-share-behaviours/identity-plaintext-data-share-behavior.d.ts +5 -5
- package/dist/data-share-behaviours/identity-plaintext-data-share-behavior.js +15 -15
- package/dist/data-share-behaviours/vcs/vc-share-behavior.d.ts +12 -12
- package/dist/data-share-behaviours/vcs/vc-share-behavior.js +2 -2
- package/dist/data-share-behaviours/vcs/vc-share-didcomm-behavior.d.ts +20 -20
- package/dist/data-share-behaviours/vcs/vc-share-didcomm-behavior.js +29 -29
- package/dist/did/did-services.d.ts +14 -14
- package/dist/did/did-services.js +14 -14
- package/dist/exceptions/agent-plugin-not-found.d.ts +2 -2
- package/dist/exceptions/agent-plugin-not-found.js +6 -6
- package/dist/exceptions/vc-protocol-not-found.d.ts +3 -3
- package/dist/exceptions/vc-protocol-not-found.js +11 -11
- package/dist/index.d.ts +32 -32
- package/dist/index.js +60 -60
- package/dist/messaging/messaging.d.ts +41 -41
- package/dist/messaging/messaging.js +90 -88
- package/dist/messaging/messaging.js.map +1 -1
- package/dist/models/agent-identity.d.ts +86 -86
- package/dist/models/agent-identity.js +399 -399
- package/dist/models/agent-identity.js.map +1 -1
- package/dist/models/agent-kms.d.ts +42 -42
- package/dist/models/agent-kms.js +78 -78
- package/dist/models/agent-pbk.d.ts +11 -11
- package/dist/models/agent-pbk.js +11 -11
- package/dist/models/agent-registry.d.ts +95 -94
- package/dist/models/agent-registry.js +130 -129
- package/dist/models/agent-registry.js.map +1 -1
- package/dist/models/agent-resolver-cache.d.ts +21 -21
- package/dist/models/agent-resolver-cache.js +47 -47
- package/dist/models/agent-resolver.d.ts +19 -19
- package/dist/models/agent-resolver.js +33 -33
- package/dist/models/agent-secure-storage.d.ts +3 -3
- package/dist/models/agent-secure-storage.js +2 -2
- package/dist/models/agent-secure-storages/filesystem-agent-secure-storage.d.ts +14 -14
- package/dist/models/agent-secure-storages/filesystem-agent-secure-storage.js +48 -48
- package/dist/models/agent-storage.d.ts +9 -9
- package/dist/models/agent-storage.js +2 -2
- package/dist/models/did.d.ts +19 -19
- package/dist/models/did.js +63 -63
- package/dist/models/transports/ami-transport.d.ts +30 -30
- package/dist/models/transports/ami-transport.js +183 -183
- package/dist/models/transports/connectable-transport.d.ts +25 -25
- package/dist/models/transports/connectable-transport.js +25 -25
- package/dist/models/transports/dwn-transport.d.ts +32 -32
- package/dist/models/transports/dwn-transport.js +191 -191
- package/dist/models/transports/messaging-transport.d.ts +3 -3
- package/dist/models/transports/messaging-transport.js +2 -2
- package/dist/models/transports/transport.d.ts +30 -30
- package/dist/models/transports/transport.js +7 -7
- package/dist/models/transports/websocket-client-transport.d.ts +5 -5
- package/dist/models/transports/websocket-client-transport.js +33 -33
- package/dist/models/transports/websocket-server-transport.d.ts +7 -7
- package/dist/models/transports/websocket-server-transport.js +21 -21
- package/dist/models/transports/websocket-transport.d.ts +30 -30
- package/dist/models/transports/websocket-transport.js +84 -84
- package/dist/models/vc-storage.d.ts +8 -8
- package/dist/models/vc-storage.js +2 -2
- package/dist/plugins/iplugin.d.ts +17 -17
- package/dist/plugins/iplugin.js +2 -2
- package/dist/plugins/istatus-list-plugin.d.ts +14 -14
- package/dist/plugins/istatus-list-plugin.js +2 -2
- package/dist/plugins/ivc-interceptor-plugin.d.ts +9 -9
- package/dist/plugins/ivc-interceptor-plugin.js +2 -2
- package/dist/plugins/plugin-dispatcher.d.ts +6 -6
- package/dist/plugins/plugin-dispatcher.js +19 -19
- package/dist/transport/transport.d.ts +43 -43
- package/dist/transport/transport.js +109 -109
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.js +14 -14
- package/dist/utils/lite-event.d.ts +25 -25
- package/dist/utils/lite-event.js +36 -36
- package/dist/vc/models/credentia-flow.d.ts +4 -4
- package/dist/vc/models/credentia-flow.js +8 -8
- package/dist/vc/models/credential-request.d.ts +3 -3
- package/dist/vc/models/credential-request.js +2 -2
- package/dist/vc/models/vc-create-key-request.d.ts +4 -4
- package/dist/vc/models/vc-create-key-request.js +2 -2
- package/dist/vc/models/waci-message.d.ts +3 -3
- package/dist/vc/models/waci-message.js +7 -7
- package/dist/vc/protocols/openid-protocol.d.ts +161 -161
- package/dist/vc/protocols/openid-protocol.js +125 -125
- package/dist/vc/protocols/vc-protocol.d.ts +106 -106
- package/dist/vc/protocols/vc-protocol.js +36 -36
- package/dist/vc/protocols/waci-protocol.d.ts +183 -183
- package/dist/vc/protocols/waci-protocol.js +552 -552
- package/dist/vc/vc.d.ts +225 -225
- package/dist/vc/vc.js +328 -328
- package/package.json +19 -20
- package/readme.md +392 -392
- package/dist/vc/vc-setup/vc-setup.d.ts +0 -0
|
@@ -1,400 +1,400 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AgentIdentity = void 0;
|
|
4
|
-
const did_core_1 = require("@extrimian/did-core");
|
|
5
|
-
const kms_core_1 = require("@extrimian/kms-core");
|
|
6
|
-
const lite_event_1 = require("../utils/lite-event");
|
|
7
|
-
const agent_registry_1 = require("./agent-registry");
|
|
8
|
-
const did_1 = require("./did");
|
|
9
|
-
const modena_sdk_1 = require("@extrimian/modena-sdk");
|
|
10
|
-
const AGENT_DID_KEY = 'agent-did';
|
|
11
|
-
const OPERATIONAL_DID_KEY = 'operational-did';
|
|
12
|
-
class AgentIdentity {
|
|
13
|
-
get operationalDIDChanged() {
|
|
14
|
-
return this._onOperationalDIDChanged.expose();
|
|
15
|
-
}
|
|
16
|
-
get identityInitialized() {
|
|
17
|
-
return this._onIdentityInitialized.expose();
|
|
18
|
-
}
|
|
19
|
-
get didCreated() {
|
|
20
|
-
return this.onDidCreated.expose();
|
|
21
|
-
}
|
|
22
|
-
constructor(params) {
|
|
23
|
-
this._dids = new Array();
|
|
24
|
-
this._onOperationalDIDChanged = new lite_event_1.LiteEvent();
|
|
25
|
-
this._onIdentityInitialized = new lite_event_1.LiteEvent();
|
|
26
|
-
this.onDidCreated = new lite_event_1.LiteEvent();
|
|
27
|
-
this.agentStorage = params.agentStorage;
|
|
28
|
-
this.kms = params.kms;
|
|
29
|
-
this.resolver = params.resolver;
|
|
30
|
-
this.registry = params.registry;
|
|
31
|
-
}
|
|
32
|
-
get initialized() {
|
|
33
|
-
return this._initialized;
|
|
34
|
-
}
|
|
35
|
-
async initialize(params) {
|
|
36
|
-
var _a;
|
|
37
|
-
this.resolver = params.resolver;
|
|
38
|
-
this.registry = params.registry;
|
|
39
|
-
this._dids =
|
|
40
|
-
(await this.agentStorage.get(AGENT_DID_KEY)) || new Array();
|
|
41
|
-
if (params.operationalDID) {
|
|
42
|
-
if (this._dids.indexOf(params.operationalDID.value) == -1) {
|
|
43
|
-
throw new Error(`Operational DID ${params.operationalDID} not exists on agent. You must import the did with its private keys`);
|
|
44
|
-
}
|
|
45
|
-
await this.setOperationalDID(params.operationalDID);
|
|
46
|
-
}
|
|
47
|
-
else {
|
|
48
|
-
const did = (await this.agentStorage.get(OPERATIONAL_DID_KEY));
|
|
49
|
-
this._did = did != null ? did_1.DID.from(did) : null;
|
|
50
|
-
if (!this._did && this._dids && this._dids.length > 0) {
|
|
51
|
-
await this.setOperationalDID(did_1.DID.from(this._dids[0]));
|
|
52
|
-
}
|
|
53
|
-
else if (this._did) {
|
|
54
|
-
await this.setOperationalDID(this._did);
|
|
55
|
-
}
|
|
56
|
-
if ((_a = this._did) === null || _a === void 0 ? void 0 : _a.isLongDID()) {
|
|
57
|
-
const shortDID = this.getDIDs().map(x => did_1.DID.from(x)).find(x => this._did.isLongDIDFor(x));
|
|
58
|
-
if (shortDID) {
|
|
59
|
-
const result = await this.checkDIDPublished(shortDID, true);
|
|
60
|
-
if (!result) {
|
|
61
|
-
this.waitForDIDPublish(shortDID, true);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
this._initialized = true;
|
|
67
|
-
this._onIdentityInitialized.trigger();
|
|
68
|
-
}
|
|
69
|
-
async addDID(params) {
|
|
70
|
-
if (!this._did) {
|
|
71
|
-
this._did = params.did;
|
|
72
|
-
}
|
|
73
|
-
if (!this._dids[params.did.value]) {
|
|
74
|
-
this._dids.push(params.did.value);
|
|
75
|
-
await this.agentStorage.add(AGENT_DID_KEY, this._dids);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
async setOperationalDID(did) {
|
|
79
|
-
if (!did) {
|
|
80
|
-
throw new Error("Operational DID to set can't be null or undefined.");
|
|
81
|
-
}
|
|
82
|
-
if (this._dids.indexOf(did.value) == -1) {
|
|
83
|
-
throw new Error('Operational DID to set must be defined on dids of the identity. You must import the did with its private keys');
|
|
84
|
-
}
|
|
85
|
-
const auxDid = this._did;
|
|
86
|
-
this._did = did;
|
|
87
|
-
await this.agentStorage.add(OPERATIONAL_DID_KEY, this._did.value);
|
|
88
|
-
if (auxDid != did) {
|
|
89
|
-
this._onOperationalDIDChanged.trigger({ did });
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
getOperationalDID() {
|
|
93
|
-
return this._did;
|
|
94
|
-
}
|
|
95
|
-
getDIDs() {
|
|
96
|
-
return [...this._dids];
|
|
97
|
-
}
|
|
98
|
-
async createNewDID(params) {
|
|
99
|
-
var _a, _b, _c, _d;
|
|
100
|
-
params = params || {};
|
|
101
|
-
if (!params.keysToCreate || params.createDefaultKeys) {
|
|
102
|
-
if (!params.keysToCreate) {
|
|
103
|
-
params.keysToCreate = new Array();
|
|
104
|
-
}
|
|
105
|
-
if (!params.preventCredentialCreation) {
|
|
106
|
-
params.keysToCreate.push({ id: 'vc-bbsbls', vmKey: agent_registry_1.VMKey.VC });
|
|
107
|
-
}
|
|
108
|
-
params.keysToCreate.push({ id: 'didcomm', vmKey: agent_registry_1.VMKey.DIDComm });
|
|
109
|
-
params.keysToCreate.push({ id: 'rsa', vmKey: agent_registry_1.VMKey.RSA });
|
|
110
|
-
}
|
|
111
|
-
const updateKey = await this.kms.create(kms_core_1.Suite.ES256k);
|
|
112
|
-
const recoveryKey = await this.kms.create(kms_core_1.Suite.ES256k);
|
|
113
|
-
if (params.keysToImport) {
|
|
114
|
-
for (let ktu of params.keysToImport) {
|
|
115
|
-
await this.kms.import({
|
|
116
|
-
publicKeyHex: kms_core_1.BaseConverter.convert(ktu.publicKeyJWK, kms_core_1.Base.JWK, kms_core_1.Base.Hex, ktu.secrets.keyType),
|
|
117
|
-
secret: ktu.secrets,
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
const didCommKeys = [...await Promise.all(params.keysToCreate
|
|
122
|
-
.filter((x) => x.vmKey == agent_registry_1.VMKey.DIDComm)
|
|
123
|
-
.map(async (x) => ({
|
|
124
|
-
id: x.id,
|
|
125
|
-
pbk: await this.kms.create(kms_core_1.Suite.DIDCommV2),
|
|
126
|
-
}))), ...(_a = (params.keysToImport || [])) === null || _a === void 0 ? void 0 : _a.filter(x => x.vmKey == agent_registry_1.VMKey.DIDComm).map(x => ({
|
|
127
|
-
id: x.id,
|
|
128
|
-
pbk: { publicKeyJWK: x.publicKeyJWK }
|
|
129
|
-
}))];
|
|
130
|
-
const bbsbls2020Keys = [...await Promise.all(params.keysToCreate
|
|
131
|
-
.filter((x) => x.vmKey == agent_registry_1.VMKey.VC)
|
|
132
|
-
.map(async (x) => ({
|
|
133
|
-
id: x.id,
|
|
134
|
-
pbk: await this.kms.create(kms_core_1.Suite.Bbsbls2020),
|
|
135
|
-
}))),
|
|
136
|
-
...(_b = (params.keysToImport || [])) === null || _b === void 0 ? void 0 : _b.filter(x => x.vmKey == agent_registry_1.VMKey.VC).map(x => ({
|
|
137
|
-
id: x.id,
|
|
138
|
-
pbk: { publicKeyJWK: x.publicKeyJWK }
|
|
139
|
-
}))];
|
|
140
|
-
const rsaKeys = [...await Promise.all(params.keysToCreate
|
|
141
|
-
.filter((x) => x.vmKey == agent_registry_1.VMKey.RSA)
|
|
142
|
-
.map(async (x) => ({
|
|
143
|
-
id: x.id,
|
|
144
|
-
pbk: await this.kms.create(kms_core_1.Suite.RsaSignature2018),
|
|
145
|
-
}))),
|
|
146
|
-
...(_c = (params.keysToImport || [])) === null || _c === void 0 ? void 0 : _c.filter(x => x.vmKey == agent_registry_1.VMKey.RSA).map(x => ({
|
|
147
|
-
id: x.id,
|
|
148
|
-
pbk: { publicKeyJWK: x.publicKeyJWK }
|
|
149
|
-
}))];
|
|
150
|
-
const ecdskeys = [...await Promise.all(params.keysToCreate
|
|
151
|
-
.filter((x) => x.vmKey == agent_registry_1.VMKey.ES256k)
|
|
152
|
-
.map(async (x) => ({
|
|
153
|
-
id: x.id,
|
|
154
|
-
pbk: await this.kms.create(kms_core_1.Suite.ES256k),
|
|
155
|
-
}))),
|
|
156
|
-
...(_d = (params.keysToImport || [])) === null || _d === void 0 ? void 0 : _d.filter(x => x.vmKey == agent_registry_1.VMKey.ES256k).map(x => ({
|
|
157
|
-
id: x.id,
|
|
158
|
-
pbk: { publicKeyJWK: x.publicKeyJWK }
|
|
159
|
-
}))];
|
|
160
|
-
if (!params.services) {
|
|
161
|
-
params.services = new Array();
|
|
162
|
-
}
|
|
163
|
-
if (params.dwnUrl) {
|
|
164
|
-
params.services.push({
|
|
165
|
-
id: 'dwn-default',
|
|
166
|
-
type: 'DecentralizedWebNode',
|
|
167
|
-
serviceEndpoint: {
|
|
168
|
-
nodes: typeof params.dwnUrl === 'string' ? [params.dwnUrl] : params.dwnUrl,
|
|
169
|
-
},
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
|
-
const response = await this.registry.createDID({
|
|
173
|
-
didMethod: params.didMethod,
|
|
174
|
-
recoveryKeys: [recoveryKey.publicKeyJWK],
|
|
175
|
-
updateKeys: [updateKey.publicKeyJWK],
|
|
176
|
-
services: params.services,
|
|
177
|
-
alsoKnownAs: params.alsoKnownAs,
|
|
178
|
-
verificationMethods: didCommKeys
|
|
179
|
-
.map((x) => ({
|
|
180
|
-
id: x.id,
|
|
181
|
-
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
182
|
-
purpose: [new did_core_1.KeyAgreementPurpose()],
|
|
183
|
-
type: 'X25519KeyAgreementKey2019',
|
|
184
|
-
controller: this.getOperationalDID(),
|
|
185
|
-
}))
|
|
186
|
-
.concat(bbsbls2020Keys
|
|
187
|
-
.map((x) => ({
|
|
188
|
-
id: x.id,
|
|
189
|
-
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
190
|
-
purpose: [new did_core_1.AssertionMethodPurpose()],
|
|
191
|
-
type: 'Bls12381G1Key2020',
|
|
192
|
-
controller: this.getOperationalDID(),
|
|
193
|
-
}))
|
|
194
|
-
.concat(rsaKeys.map((x) => ({
|
|
195
|
-
id: x.id,
|
|
196
|
-
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
197
|
-
purpose: [new did_core_1.AuthenticationPurpose()],
|
|
198
|
-
type: '
|
|
199
|
-
controller: this.getOperationalDID(),
|
|
200
|
-
})))
|
|
201
|
-
.concat(ecdskeys.map((x) => ({
|
|
202
|
-
id: x.id,
|
|
203
|
-
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
204
|
-
purpose: [new did_core_1.AuthenticationPurpose()],
|
|
205
|
-
type: 'EcdsaSecp256k1VerificationKey2019',
|
|
206
|
-
controller: this.getOperationalDID(),
|
|
207
|
-
}))))
|
|
208
|
-
});
|
|
209
|
-
if ('longDid' in response) {
|
|
210
|
-
const sidetreeResponse = response;
|
|
211
|
-
this.addDID({ did: did_1.DID.from(sidetreeResponse.longDid) });
|
|
212
|
-
const h = (args) => {
|
|
213
|
-
if (args.did.value == response.did) {
|
|
214
|
-
this.onDidCreated.off(h);
|
|
215
|
-
if (this.getOperationalDID().isEqual(did_1.DID.from(sidetreeResponse.longDid))) {
|
|
216
|
-
this.setOperationalDID(args.did);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
await this.setOperationalDID(did_1.DID.from(sidetreeResponse.longDid));
|
|
221
|
-
this.onDidCreated.on(h);
|
|
222
|
-
}
|
|
223
|
-
this.addDID({ did: did_1.DID.from(response.did) });
|
|
224
|
-
this.waitForDIDPublish(did_1.DID.from(response.did));
|
|
225
|
-
return did_1.DID.from(response.did);
|
|
226
|
-
}
|
|
227
|
-
async checkDIDPublished(shortDid, setAsOperationalAfterDIDPublish = false) {
|
|
228
|
-
const didDocument = await this.resolver.resolve(shortDid);
|
|
229
|
-
if (didDocument) {
|
|
230
|
-
if (setAsOperationalAfterDIDPublish) {
|
|
231
|
-
this.setOperationalDID(shortDid);
|
|
232
|
-
}
|
|
233
|
-
this.onDidCreated.trigger({ did: shortDid });
|
|
234
|
-
return true;
|
|
235
|
-
}
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
async waitForDIDPublish(shortDid, setAsOperationalAfterDIDPublish = false) {
|
|
239
|
-
let interval = null;
|
|
240
|
-
const pollFunc = () => new Promise(async (resolve, reject) => {
|
|
241
|
-
if (await this.checkDIDPublished(shortDid, setAsOperationalAfterDIDPublish)) {
|
|
242
|
-
if (interval) {
|
|
243
|
-
clearInterval(interval);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
resolve();
|
|
247
|
-
});
|
|
248
|
-
const result = await this.checkDIDPublished(shortDid, setAsOperationalAfterDIDPublish);
|
|
249
|
-
if (result)
|
|
250
|
-
return;
|
|
251
|
-
interval = setInterval(async () => {
|
|
252
|
-
await pollFunc();
|
|
253
|
-
}, 5000);
|
|
254
|
-
}
|
|
255
|
-
async updateDID(params) {
|
|
256
|
-
params.did = params.did || this.getOperationalDID();
|
|
257
|
-
const didDoc = await this.resolver.resolveWithMetdata(params.did);
|
|
258
|
-
const keys = (await this.kms.getPublicKeysBySuiteType(kms_core_1.Suite.ES256k)).map(jwk => ({
|
|
259
|
-
jwk,
|
|
260
|
-
updateCommitmentHash: modena_sdk_1.UpdateCommitmentUtils.getUpdateCommitmentHash(jwk),
|
|
261
|
-
}));
|
|
262
|
-
const updateKey = keys.find(x => didDoc.didDocumentMetadata.method.updateCommitment.some(y => y == x.updateCommitmentHash));
|
|
263
|
-
const newUpdateKey = await this.kms.create(kms_core_1.Suite.ES256k);
|
|
264
|
-
params.verificationMethodsToAdd = params.verificationMethodsToAdd || [];
|
|
265
|
-
const didCommKeys = await Promise.all(params.verificationMethodsToAdd
|
|
266
|
-
.filter((x) => x.vmKey == agent_registry_1.VMKey.DIDComm)
|
|
267
|
-
.map(async (x) => ({
|
|
268
|
-
id: x.id,
|
|
269
|
-
pbk: await this.kms.create(kms_core_1.Suite.DIDCommV2),
|
|
270
|
-
})));
|
|
271
|
-
const bbsbls2020Keys = await Promise.all(params.verificationMethodsToAdd
|
|
272
|
-
.filter((x) => x.vmKey == agent_registry_1.VMKey.VC)
|
|
273
|
-
.map(async (x) => ({
|
|
274
|
-
id: x.id,
|
|
275
|
-
pbk: await this.kms.create(kms_core_1.Suite.Bbsbls2020),
|
|
276
|
-
})));
|
|
277
|
-
const rsaKeys = await Promise.all(params.verificationMethodsToAdd
|
|
278
|
-
.filter((x) => x.vmKey == agent_registry_1.VMKey.RSA)
|
|
279
|
-
.map(async (x) => ({
|
|
280
|
-
id: x.id,
|
|
281
|
-
pbk: await this.kms.create(kms_core_1.Suite.RsaSignature2018),
|
|
282
|
-
})));
|
|
283
|
-
const es256kKeys = await Promise.all(params.verificationMethodsToAdd
|
|
284
|
-
.filter((x) => x.vmKey == agent_registry_1.VMKey.ES256k)
|
|
285
|
-
.map(async (x) => ({
|
|
286
|
-
id: x.id,
|
|
287
|
-
pbk: await this.kms.create(kms_core_1.Suite.ES256k),
|
|
288
|
-
})));
|
|
289
|
-
let time = Date.now();
|
|
290
|
-
if (params.dwnUrl) {
|
|
291
|
-
for (let dwn of params.dwnUrl) {
|
|
292
|
-
dwn.id = dwn.id || `dwn-service-${time++}`;
|
|
293
|
-
params.servicesToAdd = params.servicesToAdd || new Array;
|
|
294
|
-
params.servicesToAdd.push({
|
|
295
|
-
id: dwn.id,
|
|
296
|
-
type: 'DecentralizedWebNode',
|
|
297
|
-
serviceEndpoint: {
|
|
298
|
-
nodes: typeof params.dwnUrl === 'string' ? [params.dwnUrl] : params.dwnUrl,
|
|
299
|
-
},
|
|
300
|
-
});
|
|
301
|
-
}
|
|
302
|
-
}
|
|
303
|
-
await this.registry.updateDIDDocument({
|
|
304
|
-
did: params.did,
|
|
305
|
-
updatePublicKey: updateKey.jwk,
|
|
306
|
-
kms: this.kms,
|
|
307
|
-
documentMetadata: didDoc.didDocumentMetadata,
|
|
308
|
-
newUpdateKeys: [...(params.controllersToAdd || []), newUpdateKey.publicKeyJWK],
|
|
309
|
-
servicesToAdd: params.servicesToAdd,
|
|
310
|
-
idsOfServiceToRemove: params.idsOfServiceToRemove,
|
|
311
|
-
idsOfVerificationMethodsToRemove: params.idsOfVerificationMethodsToRemove,
|
|
312
|
-
updateKeysToRemove: params.updateKeysToRemove,
|
|
313
|
-
alsoKnownAsToAdd: params.alsoKnownAsToAdd,
|
|
314
|
-
alsoKnownAsToRemove: params.alsoKnownAsToRemove,
|
|
315
|
-
verificationMethodsToAdd: didCommKeys
|
|
316
|
-
.map((x) => ({
|
|
317
|
-
id: x.id,
|
|
318
|
-
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
319
|
-
purpose: [new did_core_1.KeyAgreementPurpose()],
|
|
320
|
-
type: 'X25519KeyAgreementKey2019',
|
|
321
|
-
controller: this.getOperationalDID(),
|
|
322
|
-
}))
|
|
323
|
-
.concat(bbsbls2020Keys
|
|
324
|
-
.map((x) => ({
|
|
325
|
-
id: x.id,
|
|
326
|
-
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
327
|
-
purpose: [new did_core_1.AssertionMethodPurpose()],
|
|
328
|
-
type: 'Bls12381G1Key2020',
|
|
329
|
-
controller: this.getOperationalDID(),
|
|
330
|
-
}))
|
|
331
|
-
.concat(rsaKeys.map((x) => ({
|
|
332
|
-
id: x.id,
|
|
333
|
-
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
334
|
-
purpose: [new did_core_1.AuthenticationPurpose()],
|
|
335
|
-
type: '
|
|
336
|
-
controller: this.getOperationalDID(),
|
|
337
|
-
})))
|
|
338
|
-
.concat(es256kKeys.map((x) => ({
|
|
339
|
-
id: x.id,
|
|
340
|
-
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
341
|
-
purpose: [new did_core_1.AuthenticationPurpose()],
|
|
342
|
-
type: 'EcdsaSecp256k1VerificationKey2019',
|
|
343
|
-
controller: this.getOperationalDID(),
|
|
344
|
-
})))),
|
|
345
|
-
// verificationMethodsToAdd: didCommKeys
|
|
346
|
-
// .map((x) => ({
|
|
347
|
-
// id: x.id,
|
|
348
|
-
// publicKeyJwk: x.pbk.publicKeyJWK,
|
|
349
|
-
// purpose: [new KeyAgreementPurpose()],
|
|
350
|
-
// type: 'X25519KeyAgreementKey2019',
|
|
351
|
-
// controller: this.getOperationalDID(),
|
|
352
|
-
// }))
|
|
353
|
-
// .concat(
|
|
354
|
-
// bbsbls2020Keys
|
|
355
|
-
// .map((x) => ({
|
|
356
|
-
// id: x.id,
|
|
357
|
-
// publicKeyJwk: x.pbk.publicKeyJWK,
|
|
358
|
-
// purpose: [new AssertionMethodPurpose()],
|
|
359
|
-
// type: 'Bls12381G1Key2020',
|
|
360
|
-
// controller: this.getOperationalDID(),
|
|
361
|
-
// }))
|
|
362
|
-
// .concat(
|
|
363
|
-
// rsaKeys.map((x) => ({
|
|
364
|
-
// id: x.id,
|
|
365
|
-
// publicKeyJwk: x.pbk.publicKeyJWK,
|
|
366
|
-
// purpose: [new AuthenticationPurpose()],
|
|
367
|
-
// type: '
|
|
368
|
-
// controller: this.getOperationalDID(),
|
|
369
|
-
// }))
|
|
370
|
-
// )
|
|
371
|
-
// ),
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
async exportKeys(params) {
|
|
375
|
-
const keys = await this.kms.getAllPublicKeys();
|
|
376
|
-
const exportResult = await params.exportBehavior.export({
|
|
377
|
-
dids: this._dids,
|
|
378
|
-
operationalDID: this.getOperationalDID().value,
|
|
379
|
-
keys: await Promise.all(keys.map(async (x) => ({
|
|
380
|
-
publicKeyHex: kms_core_1.BaseConverter.convert(x, kms_core_1.Base.JWK, kms_core_1.Base.Hex, x.kty),
|
|
381
|
-
secret: await this.kms.export(x),
|
|
382
|
-
}))),
|
|
383
|
-
});
|
|
384
|
-
return exportResult;
|
|
385
|
-
}
|
|
386
|
-
async importKeys(params) {
|
|
387
|
-
const importResult = await params.exportBehavior.import(params.exportResult);
|
|
388
|
-
if (importResult.dids.length == 0)
|
|
389
|
-
throw new Error('agent importKeys requires at least one did in exportResult');
|
|
390
|
-
await Promise.all(importResult.keys.map(async (key) => this.kms.import({
|
|
391
|
-
publicKeyHex: key.publicKeyHex,
|
|
392
|
-
secret: key.secret,
|
|
393
|
-
})));
|
|
394
|
-
this._dids = importResult.dids;
|
|
395
|
-
await this.agentStorage.add(AGENT_DID_KEY, this._dids);
|
|
396
|
-
await this.setOperationalDID(did_1.DID.from(importResult.operationalDID || this._dids[0]));
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
exports.AgentIdentity = AgentIdentity;
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AgentIdentity = void 0;
|
|
4
|
+
const did_core_1 = require("@extrimian/did-core");
|
|
5
|
+
const kms_core_1 = require("@extrimian/kms-core");
|
|
6
|
+
const lite_event_1 = require("../utils/lite-event");
|
|
7
|
+
const agent_registry_1 = require("./agent-registry");
|
|
8
|
+
const did_1 = require("./did");
|
|
9
|
+
const modena_sdk_1 = require("@extrimian/modena-sdk");
|
|
10
|
+
const AGENT_DID_KEY = 'agent-did';
|
|
11
|
+
const OPERATIONAL_DID_KEY = 'operational-did';
|
|
12
|
+
class AgentIdentity {
|
|
13
|
+
get operationalDIDChanged() {
|
|
14
|
+
return this._onOperationalDIDChanged.expose();
|
|
15
|
+
}
|
|
16
|
+
get identityInitialized() {
|
|
17
|
+
return this._onIdentityInitialized.expose();
|
|
18
|
+
}
|
|
19
|
+
get didCreated() {
|
|
20
|
+
return this.onDidCreated.expose();
|
|
21
|
+
}
|
|
22
|
+
constructor(params) {
|
|
23
|
+
this._dids = new Array();
|
|
24
|
+
this._onOperationalDIDChanged = new lite_event_1.LiteEvent();
|
|
25
|
+
this._onIdentityInitialized = new lite_event_1.LiteEvent();
|
|
26
|
+
this.onDidCreated = new lite_event_1.LiteEvent();
|
|
27
|
+
this.agentStorage = params.agentStorage;
|
|
28
|
+
this.kms = params.kms;
|
|
29
|
+
this.resolver = params.resolver;
|
|
30
|
+
this.registry = params.registry;
|
|
31
|
+
}
|
|
32
|
+
get initialized() {
|
|
33
|
+
return this._initialized;
|
|
34
|
+
}
|
|
35
|
+
async initialize(params) {
|
|
36
|
+
var _a;
|
|
37
|
+
this.resolver = params.resolver;
|
|
38
|
+
this.registry = params.registry;
|
|
39
|
+
this._dids =
|
|
40
|
+
(await this.agentStorage.get(AGENT_DID_KEY)) || new Array();
|
|
41
|
+
if (params.operationalDID) {
|
|
42
|
+
if (this._dids.indexOf(params.operationalDID.value) == -1) {
|
|
43
|
+
throw new Error(`Operational DID ${params.operationalDID} not exists on agent. You must import the did with its private keys`);
|
|
44
|
+
}
|
|
45
|
+
await this.setOperationalDID(params.operationalDID);
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
const did = (await this.agentStorage.get(OPERATIONAL_DID_KEY));
|
|
49
|
+
this._did = did != null ? did_1.DID.from(did) : null;
|
|
50
|
+
if (!this._did && this._dids && this._dids.length > 0) {
|
|
51
|
+
await this.setOperationalDID(did_1.DID.from(this._dids[0]));
|
|
52
|
+
}
|
|
53
|
+
else if (this._did) {
|
|
54
|
+
await this.setOperationalDID(this._did);
|
|
55
|
+
}
|
|
56
|
+
if ((_a = this._did) === null || _a === void 0 ? void 0 : _a.isLongDID()) {
|
|
57
|
+
const shortDID = this.getDIDs().map(x => did_1.DID.from(x)).find(x => this._did.isLongDIDFor(x));
|
|
58
|
+
if (shortDID) {
|
|
59
|
+
const result = await this.checkDIDPublished(shortDID, true);
|
|
60
|
+
if (!result) {
|
|
61
|
+
this.waitForDIDPublish(shortDID, true);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
this._initialized = true;
|
|
67
|
+
this._onIdentityInitialized.trigger();
|
|
68
|
+
}
|
|
69
|
+
async addDID(params) {
|
|
70
|
+
if (!this._did) {
|
|
71
|
+
this._did = params.did;
|
|
72
|
+
}
|
|
73
|
+
if (!this._dids[params.did.value]) {
|
|
74
|
+
this._dids.push(params.did.value);
|
|
75
|
+
await this.agentStorage.add(AGENT_DID_KEY, this._dids);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
async setOperationalDID(did) {
|
|
79
|
+
if (!did) {
|
|
80
|
+
throw new Error("Operational DID to set can't be null or undefined.");
|
|
81
|
+
}
|
|
82
|
+
if (this._dids.indexOf(did.value) == -1) {
|
|
83
|
+
throw new Error('Operational DID to set must be defined on dids of the identity. You must import the did with its private keys');
|
|
84
|
+
}
|
|
85
|
+
const auxDid = this._did;
|
|
86
|
+
this._did = did;
|
|
87
|
+
await this.agentStorage.add(OPERATIONAL_DID_KEY, this._did.value);
|
|
88
|
+
if (auxDid != did) {
|
|
89
|
+
this._onOperationalDIDChanged.trigger({ did });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
getOperationalDID() {
|
|
93
|
+
return this._did;
|
|
94
|
+
}
|
|
95
|
+
getDIDs() {
|
|
96
|
+
return [...this._dids];
|
|
97
|
+
}
|
|
98
|
+
async createNewDID(params) {
|
|
99
|
+
var _a, _b, _c, _d;
|
|
100
|
+
params = params || {};
|
|
101
|
+
if (!params.keysToCreate || params.createDefaultKeys) {
|
|
102
|
+
if (!params.keysToCreate) {
|
|
103
|
+
params.keysToCreate = new Array();
|
|
104
|
+
}
|
|
105
|
+
if (!params.preventCredentialCreation) {
|
|
106
|
+
params.keysToCreate.push({ id: 'vc-bbsbls', vmKey: agent_registry_1.VMKey.VC });
|
|
107
|
+
}
|
|
108
|
+
params.keysToCreate.push({ id: 'didcomm', vmKey: agent_registry_1.VMKey.DIDComm });
|
|
109
|
+
params.keysToCreate.push({ id: 'rsa', vmKey: agent_registry_1.VMKey.RSA });
|
|
110
|
+
}
|
|
111
|
+
const updateKey = await this.kms.create(kms_core_1.Suite.ES256k);
|
|
112
|
+
const recoveryKey = await this.kms.create(kms_core_1.Suite.ES256k);
|
|
113
|
+
if (params.keysToImport) {
|
|
114
|
+
for (let ktu of params.keysToImport) {
|
|
115
|
+
await this.kms.import({
|
|
116
|
+
publicKeyHex: kms_core_1.BaseConverter.convert(ktu.publicKeyJWK, kms_core_1.Base.JWK, kms_core_1.Base.Hex, ktu.secrets.keyType),
|
|
117
|
+
secret: ktu.secrets,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
const didCommKeys = [...await Promise.all(params.keysToCreate
|
|
122
|
+
.filter((x) => x.vmKey == agent_registry_1.VMKey.DIDComm)
|
|
123
|
+
.map(async (x) => ({
|
|
124
|
+
id: x.id,
|
|
125
|
+
pbk: await this.kms.create(kms_core_1.Suite.DIDCommV2),
|
|
126
|
+
}))), ...(_a = (params.keysToImport || [])) === null || _a === void 0 ? void 0 : _a.filter(x => x.vmKey == agent_registry_1.VMKey.DIDComm).map(x => ({
|
|
127
|
+
id: x.id,
|
|
128
|
+
pbk: { publicKeyJWK: x.publicKeyJWK }
|
|
129
|
+
}))];
|
|
130
|
+
const bbsbls2020Keys = [...await Promise.all(params.keysToCreate
|
|
131
|
+
.filter((x) => x.vmKey == agent_registry_1.VMKey.VC)
|
|
132
|
+
.map(async (x) => ({
|
|
133
|
+
id: x.id,
|
|
134
|
+
pbk: await this.kms.create(kms_core_1.Suite.Bbsbls2020),
|
|
135
|
+
}))),
|
|
136
|
+
...(_b = (params.keysToImport || [])) === null || _b === void 0 ? void 0 : _b.filter(x => x.vmKey == agent_registry_1.VMKey.VC).map(x => ({
|
|
137
|
+
id: x.id,
|
|
138
|
+
pbk: { publicKeyJWK: x.publicKeyJWK }
|
|
139
|
+
}))];
|
|
140
|
+
const rsaKeys = [...await Promise.all(params.keysToCreate
|
|
141
|
+
.filter((x) => x.vmKey == agent_registry_1.VMKey.RSA)
|
|
142
|
+
.map(async (x) => ({
|
|
143
|
+
id: x.id,
|
|
144
|
+
pbk: await this.kms.create(kms_core_1.Suite.RsaSignature2018),
|
|
145
|
+
}))),
|
|
146
|
+
...(_c = (params.keysToImport || [])) === null || _c === void 0 ? void 0 : _c.filter(x => x.vmKey == agent_registry_1.VMKey.RSA).map(x => ({
|
|
147
|
+
id: x.id,
|
|
148
|
+
pbk: { publicKeyJWK: x.publicKeyJWK }
|
|
149
|
+
}))];
|
|
150
|
+
const ecdskeys = [...await Promise.all(params.keysToCreate
|
|
151
|
+
.filter((x) => x.vmKey == agent_registry_1.VMKey.ES256k)
|
|
152
|
+
.map(async (x) => ({
|
|
153
|
+
id: x.id,
|
|
154
|
+
pbk: await this.kms.create(kms_core_1.Suite.ES256k),
|
|
155
|
+
}))),
|
|
156
|
+
...(_d = (params.keysToImport || [])) === null || _d === void 0 ? void 0 : _d.filter(x => x.vmKey == agent_registry_1.VMKey.ES256k).map(x => ({
|
|
157
|
+
id: x.id,
|
|
158
|
+
pbk: { publicKeyJWK: x.publicKeyJWK }
|
|
159
|
+
}))];
|
|
160
|
+
if (!params.services) {
|
|
161
|
+
params.services = new Array();
|
|
162
|
+
}
|
|
163
|
+
if (params.dwnUrl) {
|
|
164
|
+
params.services.push({
|
|
165
|
+
id: 'dwn-default',
|
|
166
|
+
type: 'DecentralizedWebNode',
|
|
167
|
+
serviceEndpoint: {
|
|
168
|
+
nodes: typeof params.dwnUrl === 'string' ? [params.dwnUrl] : params.dwnUrl,
|
|
169
|
+
},
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
const response = await this.registry.createDID({
|
|
173
|
+
didMethod: params.didMethod,
|
|
174
|
+
recoveryKeys: [recoveryKey.publicKeyJWK],
|
|
175
|
+
updateKeys: [updateKey.publicKeyJWK],
|
|
176
|
+
services: params.services,
|
|
177
|
+
alsoKnownAs: params.alsoKnownAs,
|
|
178
|
+
verificationMethods: didCommKeys
|
|
179
|
+
.map((x) => ({
|
|
180
|
+
id: x.id,
|
|
181
|
+
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
182
|
+
purpose: [new did_core_1.KeyAgreementPurpose()],
|
|
183
|
+
type: 'X25519KeyAgreementKey2019',
|
|
184
|
+
controller: this.getOperationalDID(),
|
|
185
|
+
}))
|
|
186
|
+
.concat(bbsbls2020Keys
|
|
187
|
+
.map((x) => ({
|
|
188
|
+
id: x.id,
|
|
189
|
+
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
190
|
+
purpose: [new did_core_1.AssertionMethodPurpose()],
|
|
191
|
+
type: 'Bls12381G1Key2020',
|
|
192
|
+
controller: this.getOperationalDID(),
|
|
193
|
+
}))
|
|
194
|
+
.concat(rsaKeys.map((x) => ({
|
|
195
|
+
id: x.id,
|
|
196
|
+
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
197
|
+
purpose: [new did_core_1.AuthenticationPurpose()],
|
|
198
|
+
type: 'RsaVerificationKey2018',
|
|
199
|
+
controller: this.getOperationalDID(),
|
|
200
|
+
})))
|
|
201
|
+
.concat(ecdskeys.map((x) => ({
|
|
202
|
+
id: x.id,
|
|
203
|
+
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
204
|
+
purpose: [new did_core_1.AuthenticationPurpose()],
|
|
205
|
+
type: 'EcdsaSecp256k1VerificationKey2019',
|
|
206
|
+
controller: this.getOperationalDID(),
|
|
207
|
+
}))))
|
|
208
|
+
});
|
|
209
|
+
if ('longDid' in response) {
|
|
210
|
+
const sidetreeResponse = response;
|
|
211
|
+
this.addDID({ did: did_1.DID.from(sidetreeResponse.longDid) });
|
|
212
|
+
const h = (args) => {
|
|
213
|
+
if (args.did.value == response.did) {
|
|
214
|
+
this.onDidCreated.off(h);
|
|
215
|
+
if (this.getOperationalDID().isEqual(did_1.DID.from(sidetreeResponse.longDid))) {
|
|
216
|
+
this.setOperationalDID(args.did);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
await this.setOperationalDID(did_1.DID.from(sidetreeResponse.longDid));
|
|
221
|
+
this.onDidCreated.on(h);
|
|
222
|
+
}
|
|
223
|
+
this.addDID({ did: did_1.DID.from(response.did) });
|
|
224
|
+
this.waitForDIDPublish(did_1.DID.from(response.did));
|
|
225
|
+
return did_1.DID.from(response.did);
|
|
226
|
+
}
|
|
227
|
+
async checkDIDPublished(shortDid, setAsOperationalAfterDIDPublish = false) {
|
|
228
|
+
const didDocument = await this.resolver.resolve(shortDid);
|
|
229
|
+
if (didDocument) {
|
|
230
|
+
if (setAsOperationalAfterDIDPublish) {
|
|
231
|
+
this.setOperationalDID(shortDid);
|
|
232
|
+
}
|
|
233
|
+
this.onDidCreated.trigger({ did: shortDid });
|
|
234
|
+
return true;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
}
|
|
238
|
+
async waitForDIDPublish(shortDid, setAsOperationalAfterDIDPublish = false) {
|
|
239
|
+
let interval = null;
|
|
240
|
+
const pollFunc = () => new Promise(async (resolve, reject) => {
|
|
241
|
+
if (await this.checkDIDPublished(shortDid, setAsOperationalAfterDIDPublish)) {
|
|
242
|
+
if (interval) {
|
|
243
|
+
clearInterval(interval);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
resolve();
|
|
247
|
+
});
|
|
248
|
+
const result = await this.checkDIDPublished(shortDid, setAsOperationalAfterDIDPublish);
|
|
249
|
+
if (result)
|
|
250
|
+
return;
|
|
251
|
+
interval = setInterval(async () => {
|
|
252
|
+
await pollFunc();
|
|
253
|
+
}, 5000);
|
|
254
|
+
}
|
|
255
|
+
async updateDID(params) {
|
|
256
|
+
params.did = params.did || this.getOperationalDID();
|
|
257
|
+
const didDoc = await this.resolver.resolveWithMetdata(params.did);
|
|
258
|
+
const keys = (await this.kms.getPublicKeysBySuiteType(kms_core_1.Suite.ES256k)).map(jwk => ({
|
|
259
|
+
jwk,
|
|
260
|
+
updateCommitmentHash: modena_sdk_1.UpdateCommitmentUtils.getUpdateCommitmentHash(jwk),
|
|
261
|
+
}));
|
|
262
|
+
const updateKey = keys.find(x => didDoc.didDocumentMetadata.method.updateCommitment.some(y => y == x.updateCommitmentHash));
|
|
263
|
+
const newUpdateKey = await this.kms.create(kms_core_1.Suite.ES256k);
|
|
264
|
+
params.verificationMethodsToAdd = params.verificationMethodsToAdd || [];
|
|
265
|
+
const didCommKeys = await Promise.all(params.verificationMethodsToAdd
|
|
266
|
+
.filter((x) => x.vmKey == agent_registry_1.VMKey.DIDComm)
|
|
267
|
+
.map(async (x) => ({
|
|
268
|
+
id: x.id,
|
|
269
|
+
pbk: await this.kms.create(kms_core_1.Suite.DIDCommV2),
|
|
270
|
+
})));
|
|
271
|
+
const bbsbls2020Keys = await Promise.all(params.verificationMethodsToAdd
|
|
272
|
+
.filter((x) => x.vmKey == agent_registry_1.VMKey.VC)
|
|
273
|
+
.map(async (x) => ({
|
|
274
|
+
id: x.id,
|
|
275
|
+
pbk: await this.kms.create(kms_core_1.Suite.Bbsbls2020),
|
|
276
|
+
})));
|
|
277
|
+
const rsaKeys = await Promise.all(params.verificationMethodsToAdd
|
|
278
|
+
.filter((x) => x.vmKey == agent_registry_1.VMKey.RSA)
|
|
279
|
+
.map(async (x) => ({
|
|
280
|
+
id: x.id,
|
|
281
|
+
pbk: await this.kms.create(kms_core_1.Suite.RsaSignature2018),
|
|
282
|
+
})));
|
|
283
|
+
const es256kKeys = await Promise.all(params.verificationMethodsToAdd
|
|
284
|
+
.filter((x) => x.vmKey == agent_registry_1.VMKey.ES256k)
|
|
285
|
+
.map(async (x) => ({
|
|
286
|
+
id: x.id,
|
|
287
|
+
pbk: await this.kms.create(kms_core_1.Suite.ES256k),
|
|
288
|
+
})));
|
|
289
|
+
let time = Date.now();
|
|
290
|
+
if (params.dwnUrl) {
|
|
291
|
+
for (let dwn of params.dwnUrl) {
|
|
292
|
+
dwn.id = dwn.id || `dwn-service-${time++}`;
|
|
293
|
+
params.servicesToAdd = params.servicesToAdd || new Array;
|
|
294
|
+
params.servicesToAdd.push({
|
|
295
|
+
id: dwn.id,
|
|
296
|
+
type: 'DecentralizedWebNode',
|
|
297
|
+
serviceEndpoint: {
|
|
298
|
+
nodes: typeof params.dwnUrl === 'string' ? [params.dwnUrl] : params.dwnUrl,
|
|
299
|
+
},
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
await this.registry.updateDIDDocument({
|
|
304
|
+
did: params.did,
|
|
305
|
+
updatePublicKey: updateKey.jwk,
|
|
306
|
+
kms: this.kms,
|
|
307
|
+
documentMetadata: didDoc.didDocumentMetadata,
|
|
308
|
+
newUpdateKeys: [...(params.controllersToAdd || []), newUpdateKey.publicKeyJWK],
|
|
309
|
+
servicesToAdd: params.servicesToAdd,
|
|
310
|
+
idsOfServiceToRemove: params.idsOfServiceToRemove,
|
|
311
|
+
idsOfVerificationMethodsToRemove: params.idsOfVerificationMethodsToRemove,
|
|
312
|
+
updateKeysToRemove: params.updateKeysToRemove,
|
|
313
|
+
alsoKnownAsToAdd: params.alsoKnownAsToAdd,
|
|
314
|
+
alsoKnownAsToRemove: params.alsoKnownAsToRemove,
|
|
315
|
+
verificationMethodsToAdd: didCommKeys
|
|
316
|
+
.map((x) => ({
|
|
317
|
+
id: x.id,
|
|
318
|
+
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
319
|
+
purpose: [new did_core_1.KeyAgreementPurpose()],
|
|
320
|
+
type: 'X25519KeyAgreementKey2019',
|
|
321
|
+
controller: this.getOperationalDID(),
|
|
322
|
+
}))
|
|
323
|
+
.concat(bbsbls2020Keys
|
|
324
|
+
.map((x) => ({
|
|
325
|
+
id: x.id,
|
|
326
|
+
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
327
|
+
purpose: [new did_core_1.AssertionMethodPurpose()],
|
|
328
|
+
type: 'Bls12381G1Key2020',
|
|
329
|
+
controller: this.getOperationalDID(),
|
|
330
|
+
}))
|
|
331
|
+
.concat(rsaKeys.map((x) => ({
|
|
332
|
+
id: x.id,
|
|
333
|
+
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
334
|
+
purpose: [new did_core_1.AuthenticationPurpose()],
|
|
335
|
+
type: 'RsaVerificationKey2018',
|
|
336
|
+
controller: this.getOperationalDID(),
|
|
337
|
+
})))
|
|
338
|
+
.concat(es256kKeys.map((x) => ({
|
|
339
|
+
id: x.id,
|
|
340
|
+
publicKeyJwk: x.pbk.publicKeyJWK,
|
|
341
|
+
purpose: [new did_core_1.AuthenticationPurpose()],
|
|
342
|
+
type: 'EcdsaSecp256k1VerificationKey2019',
|
|
343
|
+
controller: this.getOperationalDID(),
|
|
344
|
+
})))),
|
|
345
|
+
// verificationMethodsToAdd: didCommKeys
|
|
346
|
+
// .map((x) => ({
|
|
347
|
+
// id: x.id,
|
|
348
|
+
// publicKeyJwk: x.pbk.publicKeyJWK,
|
|
349
|
+
// purpose: [new KeyAgreementPurpose()],
|
|
350
|
+
// type: 'X25519KeyAgreementKey2019',
|
|
351
|
+
// controller: this.getOperationalDID(),
|
|
352
|
+
// }))
|
|
353
|
+
// .concat(
|
|
354
|
+
// bbsbls2020Keys
|
|
355
|
+
// .map((x) => ({
|
|
356
|
+
// id: x.id,
|
|
357
|
+
// publicKeyJwk: x.pbk.publicKeyJWK,
|
|
358
|
+
// purpose: [new AssertionMethodPurpose()],
|
|
359
|
+
// type: 'Bls12381G1Key2020',
|
|
360
|
+
// controller: this.getOperationalDID(),
|
|
361
|
+
// }))
|
|
362
|
+
// .concat(
|
|
363
|
+
// rsaKeys.map((x) => ({
|
|
364
|
+
// id: x.id,
|
|
365
|
+
// publicKeyJwk: x.pbk.publicKeyJWK,
|
|
366
|
+
// purpose: [new AuthenticationPurpose()],
|
|
367
|
+
// type: 'RsaVerificationKey2018',
|
|
368
|
+
// controller: this.getOperationalDID(),
|
|
369
|
+
// }))
|
|
370
|
+
// )
|
|
371
|
+
// ),
|
|
372
|
+
});
|
|
373
|
+
}
|
|
374
|
+
async exportKeys(params) {
|
|
375
|
+
const keys = await this.kms.getAllPublicKeys();
|
|
376
|
+
const exportResult = await params.exportBehavior.export({
|
|
377
|
+
dids: this._dids,
|
|
378
|
+
operationalDID: this.getOperationalDID().value,
|
|
379
|
+
keys: await Promise.all(keys.map(async (x) => ({
|
|
380
|
+
publicKeyHex: kms_core_1.BaseConverter.convert(x, kms_core_1.Base.JWK, kms_core_1.Base.Hex, x.kty),
|
|
381
|
+
secret: await this.kms.export(x),
|
|
382
|
+
}))),
|
|
383
|
+
});
|
|
384
|
+
return exportResult;
|
|
385
|
+
}
|
|
386
|
+
async importKeys(params) {
|
|
387
|
+
const importResult = await params.exportBehavior.import(params.exportResult);
|
|
388
|
+
if (importResult.dids.length == 0)
|
|
389
|
+
throw new Error('agent importKeys requires at least one did in exportResult');
|
|
390
|
+
await Promise.all(importResult.keys.map(async (key) => this.kms.import({
|
|
391
|
+
publicKeyHex: key.publicKeyHex,
|
|
392
|
+
secret: key.secret,
|
|
393
|
+
})));
|
|
394
|
+
this._dids = importResult.dids;
|
|
395
|
+
await this.agentStorage.add(AGENT_DID_KEY, this._dids);
|
|
396
|
+
await this.setOperationalDID(did_1.DID.from(importResult.operationalDID || this._dids[0]));
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
exports.AgentIdentity = AgentIdentity;
|
|
400
400
|
//# sourceMappingURL=agent-identity.js.map
|