@nmshd/consumption 7.0.0-openid4vc.2 → 7.0.0-openid4vc.3
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/buildInformation.js +5 -5
- package/dist/modules/openid4vc/OpenId4VcController.d.ts +5 -0
- package/dist/modules/openid4vc/OpenId4VcController.d.ts.map +1 -1
- package/dist/modules/openid4vc/OpenId4VcController.js +61 -27
- package/dist/modules/openid4vc/OpenId4VcController.js.map +1 -1
- package/dist/modules/openid4vc/index.d.ts +3 -3
- package/dist/modules/openid4vc/index.d.ts.map +1 -1
- package/dist/modules/openid4vc/index.js +3 -3
- package/dist/modules/openid4vc/index.js.map +1 -1
- package/dist/modules/openid4vc/local/BaseAgent.d.ts +8 -8
- package/dist/modules/openid4vc/local/BaseAgent.d.ts.map +1 -1
- package/dist/modules/openid4vc/local/BaseAgent.js +13 -17
- package/dist/modules/openid4vc/local/BaseAgent.js.map +1 -1
- package/dist/modules/openid4vc/local/{FakeFileSystem.d.ts → EnmeshedHolderFileSystem.d.ts} +3 -2
- package/dist/modules/openid4vc/local/EnmeshedHolderFileSystem.d.ts.map +1 -0
- package/dist/modules/openid4vc/local/EnmeshedHolderFileSystem.js +94 -0
- package/dist/modules/openid4vc/local/EnmeshedHolderFileSystem.js.map +1 -0
- package/dist/modules/openid4vc/local/{FakeKeyManagmentService.d.ts → EnmeshedHolderKeyManagmentService.d.ts} +13 -2
- package/dist/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.d.ts.map +1 -0
- package/dist/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.js +364 -0
- package/dist/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.js.map +1 -0
- package/dist/modules/openid4vc/local/{FakeStorageService.d.ts → EnmeshedStorageService.d.ts} +10 -3
- package/dist/modules/openid4vc/local/EnmeshedStorageService.d.ts.map +1 -0
- package/dist/modules/openid4vc/local/EnmeshedStorageService.js +218 -0
- package/dist/modules/openid4vc/local/EnmeshedStorageService.js.map +1 -0
- package/dist/modules/openid4vc/local/Holder.d.ts +6 -4
- package/dist/modules/openid4vc/local/Holder.d.ts.map +1 -1
- package/dist/modules/openid4vc/local/Holder.js +82 -30
- package/dist/modules/openid4vc/local/Holder.js.map +1 -1
- package/dist/modules/openid4vc/local/LocalAgentDependencies.d.ts.map +1 -1
- package/dist/modules/openid4vc/local/LocalAgentDependencies.js +2 -4
- package/dist/modules/openid4vc/local/LocalAgentDependencies.js.map +1 -1
- package/package.json +10 -7
- package/dist/modules/openid4vc/local/FakeFileSystem.d.ts.map +0 -1
- package/dist/modules/openid4vc/local/FakeFileSystem.js +0 -67
- package/dist/modules/openid4vc/local/FakeFileSystem.js.map +0 -1
- package/dist/modules/openid4vc/local/FakeKeyManagmentService.d.ts.map +0 -1
- package/dist/modules/openid4vc/local/FakeKeyManagmentService.js +0 -121
- package/dist/modules/openid4vc/local/FakeKeyManagmentService.js.map +0 -1
- package/dist/modules/openid4vc/local/FakeStorageService.d.ts.map +0 -1
- package/dist/modules/openid4vc/local/FakeStorageService.js +0 -72
- package/dist/modules/openid4vc/local/FakeStorageService.js.map +0 -1
|
@@ -0,0 +1,364 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.EnmshedHolderKeyManagmentService = void 0;
|
|
7
|
+
const elliptic_1 = require("elliptic");
|
|
8
|
+
const libsodium_wrappers_1 = __importDefault(require("libsodium-wrappers"));
|
|
9
|
+
const sjcl_1 = __importDefault(require("sjcl"));
|
|
10
|
+
class EnmshedHolderKeyManagmentService {
|
|
11
|
+
static { this.backend = "fakeKeyManagementService"; }
|
|
12
|
+
constructor() {
|
|
13
|
+
this.backend = EnmshedHolderKeyManagmentService.backend;
|
|
14
|
+
this.b64url = (bytes) => libsodium_wrappers_1.default.to_base64(bytes, libsodium_wrappers_1.default.base64_variants.URLSAFE_NO_PADDING);
|
|
15
|
+
this.b64urlDecode = (b64url) => libsodium_wrappers_1.default.from_base64(b64url, libsodium_wrappers_1.default.base64_variants.URLSAFE_NO_PADDING);
|
|
16
|
+
// please note: we cannot use buffer here - because it is not available in the browser
|
|
17
|
+
// and yes it could be pollyfilled but that extends the bundle size for no good reason
|
|
18
|
+
this.buf2hex = (bytes) => {
|
|
19
|
+
return Array.from(bytes)
|
|
20
|
+
.map((b) => b.toString(16).padStart(2, "0"))
|
|
21
|
+
.join("");
|
|
22
|
+
};
|
|
23
|
+
this.hex2buf = (hex) => {
|
|
24
|
+
const bytes = new Uint8Array(hex.length / 2);
|
|
25
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
26
|
+
bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
|
|
27
|
+
}
|
|
28
|
+
return bytes;
|
|
29
|
+
};
|
|
30
|
+
if (globalThis.fakeKeyStorage) {
|
|
31
|
+
this.keystore = globalThis.fakeKeyStorage;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
this.keystore = new Map();
|
|
35
|
+
}
|
|
36
|
+
this.updateGlobalInstance(this.keystore);
|
|
37
|
+
}
|
|
38
|
+
updateGlobalInstance(storrage) {
|
|
39
|
+
// console.log(`FKM: updating global instance ${JSON.stringify(Array.from(storrage.entries()))}`);
|
|
40
|
+
globalThis.fakeKeyStorage = storrage;
|
|
41
|
+
// console.log(`FKM: global instance state ${JSON.stringify(Array.from((globalThis as any).fakeKeyStorage.entries()))}`);
|
|
42
|
+
}
|
|
43
|
+
isOperationSupported(agentContext, operation) {
|
|
44
|
+
agentContext.config.logger.debug(`EKM: Checking if operation is supported: ${JSON.stringify(operation)}`);
|
|
45
|
+
if (operation.operation === "createKey") {
|
|
46
|
+
if (operation.type.kty === "OKP") {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
if (operation.type.kty === "EC" && operation.type.crv === "P-256") {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
return false;
|
|
53
|
+
}
|
|
54
|
+
if (operation.operation === "verify" && operation.algorithm === "ES256") {
|
|
55
|
+
return true;
|
|
56
|
+
}
|
|
57
|
+
if (operation.operation === "sign" && (operation.algorithm === "EdDSA" || operation.algorithm === "ES256")) {
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
if (operation.operation === "randomBytes") {
|
|
61
|
+
return true;
|
|
62
|
+
}
|
|
63
|
+
if (operation.operation === "deleteKey") {
|
|
64
|
+
return true;
|
|
65
|
+
}
|
|
66
|
+
if (operation.operation === "encrypt") {
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
getPublicKey(agentContext, keyId) {
|
|
72
|
+
const keyPair = this.keystore.get(keyId);
|
|
73
|
+
if (!keyPair) {
|
|
74
|
+
agentContext.config.logger.error(`EKM: Key with id ${keyId} not found`);
|
|
75
|
+
throw new Error(`Key with id ${keyId} not found`);
|
|
76
|
+
}
|
|
77
|
+
return Promise.resolve(JSON.parse(keyPair).publicKey);
|
|
78
|
+
}
|
|
79
|
+
async createKey(agentContext, options) {
|
|
80
|
+
options.keyId ??= "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
|
|
81
|
+
// Use libsodium's randombytes_uniform for secure random number generation
|
|
82
|
+
const r = libsodium_wrappers_1.default.randombytes_uniform(16);
|
|
83
|
+
const v = c === "x" ? r : (r & 0x3) | 0x8;
|
|
84
|
+
return v.toString(16);
|
|
85
|
+
});
|
|
86
|
+
agentContext.config.logger.debug(`EKM: Creating key with id ${options.keyId} and type ${JSON.stringify(options.type)}`);
|
|
87
|
+
if (options.type.kty === "EC" && options.type.crv === "P-256") {
|
|
88
|
+
// Use P-256 (aka secp256r1)
|
|
89
|
+
const ec = new elliptic_1.ec("p256");
|
|
90
|
+
const key = ec.genKeyPair();
|
|
91
|
+
// Public JWK
|
|
92
|
+
const publicJwk = {
|
|
93
|
+
kty: "EC", // Elliptic Curve
|
|
94
|
+
crv: "P-256",
|
|
95
|
+
x: this.b64url(new Uint8Array(key.getPublic().getX().toArray())),
|
|
96
|
+
y: this.b64url(new Uint8Array(key.getPublic().getY().toArray()))
|
|
97
|
+
};
|
|
98
|
+
// Private JWK
|
|
99
|
+
const privateJwk = {
|
|
100
|
+
...publicJwk,
|
|
101
|
+
d: this.b64url(new Uint8Array(key.getPrivate().toArray()))
|
|
102
|
+
};
|
|
103
|
+
const jwkKeyPair = {
|
|
104
|
+
publicKey: publicJwk,
|
|
105
|
+
privateKey: privateJwk,
|
|
106
|
+
keyType: "EC"
|
|
107
|
+
};
|
|
108
|
+
agentContext.config.logger.debug(`EKM: Created EC key pair with id ${options.keyId}`);
|
|
109
|
+
// store the key pair in the keystore
|
|
110
|
+
this.keystore.set(options.keyId, JSON.stringify(jwkKeyPair));
|
|
111
|
+
this.updateGlobalInstance(this.keystore);
|
|
112
|
+
return await Promise.resolve({
|
|
113
|
+
keyId: options.keyId,
|
|
114
|
+
publicJwk: publicJwk
|
|
115
|
+
});
|
|
116
|
+
}
|
|
117
|
+
await libsodium_wrappers_1.default.ready;
|
|
118
|
+
const sodium = libsodium_wrappers_1.default;
|
|
119
|
+
const { keyType, publicKey, privateKey } = sodium.crypto_sign_keypair();
|
|
120
|
+
agentContext.config.logger.debug(`EKM: Created OKP key pair with id ${options.keyId} and keyType ${keyType}`);
|
|
121
|
+
const seed = privateKey.slice(0, sodium.crypto_sign_SEEDBYTES);
|
|
122
|
+
// Public JWK
|
|
123
|
+
const publicJwk = {
|
|
124
|
+
kty: "OKP", // Octet Key Pair
|
|
125
|
+
crv: "Ed25519",
|
|
126
|
+
x: this.b64url(publicKey)
|
|
127
|
+
};
|
|
128
|
+
// Private JWK
|
|
129
|
+
const privateJwk = {
|
|
130
|
+
...publicJwk,
|
|
131
|
+
d: this.b64url(seed)
|
|
132
|
+
};
|
|
133
|
+
const jwkKeyPair = {
|
|
134
|
+
publicKey: publicJwk,
|
|
135
|
+
privateKey: privateJwk,
|
|
136
|
+
keyType: "OKP"
|
|
137
|
+
};
|
|
138
|
+
// store the key pair in the keystore
|
|
139
|
+
this.keystore.set(options.keyId, JSON.stringify(jwkKeyPair));
|
|
140
|
+
this.updateGlobalInstance(this.keystore);
|
|
141
|
+
return await Promise.resolve({
|
|
142
|
+
keyId: options.keyId,
|
|
143
|
+
publicJwk: publicJwk
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
importKey(agentContext, options) {
|
|
147
|
+
agentContext.config.logger.debug(`EKM: Importing key with ${JSON.stringify(options)}`);
|
|
148
|
+
throw new Error("Method not implemented.");
|
|
149
|
+
}
|
|
150
|
+
deleteKey(agentContext, options) {
|
|
151
|
+
if (this.keystore.has(options.keyId)) {
|
|
152
|
+
agentContext.config.logger.debug(`EKM: Deleting key with id ${options.keyId}`);
|
|
153
|
+
this.keystore.delete(options.keyId);
|
|
154
|
+
this.updateGlobalInstance(this.keystore);
|
|
155
|
+
return Promise.resolve(true);
|
|
156
|
+
}
|
|
157
|
+
throw new Error(`key with id ${options.keyId} not found. and cannot be deleted`);
|
|
158
|
+
}
|
|
159
|
+
async sign(agentContext, options) {
|
|
160
|
+
agentContext.config.logger.debug(`EKM: Signing data with key id ${options.keyId} using algorithm ${options.algorithm}`);
|
|
161
|
+
const stringifiedKeyPair = this.keystore.get(options.keyId);
|
|
162
|
+
if (!stringifiedKeyPair) {
|
|
163
|
+
throw new Error(`Key with id ${options.keyId} not found`);
|
|
164
|
+
}
|
|
165
|
+
const { privateKey, publicKey } = JSON.parse(stringifiedKeyPair);
|
|
166
|
+
if (options.algorithm === "ES256") {
|
|
167
|
+
// Use P-256 (aka secp256r1)
|
|
168
|
+
const ec = new elliptic_1.ec("p256");
|
|
169
|
+
if (!privateKey.d) {
|
|
170
|
+
throw new Error("Private JWK does not contain 'd' parameter");
|
|
171
|
+
}
|
|
172
|
+
const priv = this.buf2hex(this.b64urlDecode(privateKey.d));
|
|
173
|
+
const key = ec.keyFromPrivate(priv, "hex");
|
|
174
|
+
// we need to hash the data using SHA-256
|
|
175
|
+
const dataHash = ec.hash().update(options.data).digest();
|
|
176
|
+
const signature = key.sign(dataHash);
|
|
177
|
+
const r = new Uint8Array(signature.r.toArray());
|
|
178
|
+
const s = new Uint8Array(signature.s.toArray());
|
|
179
|
+
const signatureBytes = new Uint8Array(r.length + s.length);
|
|
180
|
+
signatureBytes.set(r);
|
|
181
|
+
signatureBytes.set(s, r.length);
|
|
182
|
+
return await Promise.resolve({
|
|
183
|
+
signature: signatureBytes
|
|
184
|
+
});
|
|
185
|
+
}
|
|
186
|
+
await libsodium_wrappers_1.default.ready;
|
|
187
|
+
const sodium = libsodium_wrappers_1.default;
|
|
188
|
+
const decode = (bytes) => sodium.from_base64(bytes, sodium.base64_variants.URLSAFE_NO_PADDING);
|
|
189
|
+
// get the priavte key bytes
|
|
190
|
+
if (privateKey.d === undefined) {
|
|
191
|
+
throw new Error("Private key does not contain 'd' parameter");
|
|
192
|
+
}
|
|
193
|
+
const privateKeyBytes = decode(privateKey.d);
|
|
194
|
+
// get the public key bytes
|
|
195
|
+
if (publicKey.x === undefined) {
|
|
196
|
+
throw new Error("Public key does not contain 'x' parameter");
|
|
197
|
+
}
|
|
198
|
+
const publicKeyBytes = decode(publicKey.x);
|
|
199
|
+
// combine the key bytes to a full private key
|
|
200
|
+
const fullPrivateKeyBytes = new Uint8Array(privateKeyBytes.length + publicKeyBytes.length);
|
|
201
|
+
fullPrivateKeyBytes.set(privateKeyBytes);
|
|
202
|
+
fullPrivateKeyBytes.set(publicKeyBytes, privateKeyBytes.length);
|
|
203
|
+
// and use it to sign the data
|
|
204
|
+
const signature = sodium.crypto_sign_detached(options.data, fullPrivateKeyBytes);
|
|
205
|
+
return {
|
|
206
|
+
signature: signature
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
verify(agentContext, options) {
|
|
210
|
+
agentContext.config.logger.debug(`EKM: Verifying signature with key id ${options.key.keyId} using algorithm ${options.algorithm}`);
|
|
211
|
+
// Use P-256 (aka secp256r1)
|
|
212
|
+
const ec = new elliptic_1.ec("p256");
|
|
213
|
+
if (!options.key.publicJwk) {
|
|
214
|
+
throw new Error("Public JWK is undefined");
|
|
215
|
+
}
|
|
216
|
+
if (options.key.publicJwk.kty !== "EC") {
|
|
217
|
+
throw new Error("Public JWK does not contain 'x' or 'y' parameter");
|
|
218
|
+
}
|
|
219
|
+
const x = options.key.publicJwk.x;
|
|
220
|
+
const y = options.key.publicJwk.y;
|
|
221
|
+
const pub = { x: this.buf2hex(this.b64urlDecode(x)), y: this.buf2hex(this.b64urlDecode(y)) };
|
|
222
|
+
const key = ec.keyFromPublic(pub, "hex");
|
|
223
|
+
const signatureBytes = options.signature;
|
|
224
|
+
const r = signatureBytes.subarray(0, 32);
|
|
225
|
+
const s = signatureBytes.subarray(32, 64);
|
|
226
|
+
const signature = { r: this.buf2hex(r), s: this.buf2hex(s) };
|
|
227
|
+
// we need to hash the data using SHA-256
|
|
228
|
+
const dataHash = ec.hash().update(options.data).digest();
|
|
229
|
+
try {
|
|
230
|
+
const verified = key.verify(dataHash, signature);
|
|
231
|
+
return Promise.resolve({ verified: verified });
|
|
232
|
+
}
|
|
233
|
+
catch (e) {
|
|
234
|
+
agentContext.config.logger.error(`EKM: Error during signature verification: ${e}`);
|
|
235
|
+
throw e;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
ecdhEs(localKeyId, remotePublicJWK) {
|
|
239
|
+
const keyPairString = this.keystore.get(localKeyId);
|
|
240
|
+
if (!keyPairString) {
|
|
241
|
+
throw new Error(`Key with id ${localKeyId} not found`);
|
|
242
|
+
}
|
|
243
|
+
const localKeyPair = JSON.parse(keyPairString);
|
|
244
|
+
if (localKeyPair.keyType !== "EC") {
|
|
245
|
+
throw new Error("Key type is not EC");
|
|
246
|
+
}
|
|
247
|
+
const ec = new elliptic_1.ec("p256");
|
|
248
|
+
if (localKeyPair.privateKey.d === undefined) {
|
|
249
|
+
throw new Error("Local private key does not contain 'd' parameter");
|
|
250
|
+
}
|
|
251
|
+
const localPriv = ec.keyFromPrivate(this.buf2hex(this.b64urlDecode(localKeyPair.privateKey.d)), "hex");
|
|
252
|
+
// the remote jwk is base64url encoded - we again decode and transform to hex to receive a fitting public key
|
|
253
|
+
const remoteBasePoint = ec.keyFromPublic({
|
|
254
|
+
x: this.buf2hex(this.b64urlDecode(remotePublicJWK.x)),
|
|
255
|
+
y: this.buf2hex(this.b64urlDecode(remotePublicJWK.y))
|
|
256
|
+
}, "hex");
|
|
257
|
+
const sharedSecret = localPriv.derive(remoteBasePoint.getPublic());
|
|
258
|
+
const sharedBytes = new Uint8Array(sharedSecret.toArray("be"));
|
|
259
|
+
return sharedBytes;
|
|
260
|
+
}
|
|
261
|
+
// UTF-8 encode helper
|
|
262
|
+
utf8(str) {
|
|
263
|
+
return new TextEncoder().encode(str);
|
|
264
|
+
}
|
|
265
|
+
// Concat Uint8Arrays
|
|
266
|
+
concat(...arrays) {
|
|
267
|
+
const total = arrays.reduce((sum, a) => sum + a.length, 0);
|
|
268
|
+
const out = new Uint8Array(total);
|
|
269
|
+
let offset = 0;
|
|
270
|
+
for (const a of arrays) {
|
|
271
|
+
out.set(a, offset);
|
|
272
|
+
offset += a.length;
|
|
273
|
+
}
|
|
274
|
+
return out;
|
|
275
|
+
}
|
|
276
|
+
// Encode a 32-bit big-endian length prefix
|
|
277
|
+
lenPrefix(data) {
|
|
278
|
+
const buf = new Uint8Array(4 + data.length);
|
|
279
|
+
const view = new DataView(buf.buffer);
|
|
280
|
+
view.setUint32(0, data.length, false); // big-endian
|
|
281
|
+
buf.set(data, 4);
|
|
282
|
+
return buf;
|
|
283
|
+
}
|
|
284
|
+
concatKdf(sharedSecret, keyLength, algorithmDescriptor, keyAgreement) {
|
|
285
|
+
if (keyAgreement.apu === undefined) {
|
|
286
|
+
throw new Error("Key agreement apu is undefined");
|
|
287
|
+
}
|
|
288
|
+
if (keyAgreement.apv === undefined) {
|
|
289
|
+
throw new Error("Key agreement apv is undefined");
|
|
290
|
+
}
|
|
291
|
+
const algId = this.lenPrefix(this.utf8(algorithmDescriptor));
|
|
292
|
+
const partyU = this.lenPrefix(keyAgreement.apu);
|
|
293
|
+
const partyV = this.lenPrefix(keyAgreement.apv);
|
|
294
|
+
const suppPubInfo = new Uint8Array(4);
|
|
295
|
+
new DataView(suppPubInfo.buffer).setUint32(0, keyLength, false);
|
|
296
|
+
const suppPrivInfo = new Uint8Array(0);
|
|
297
|
+
const otherInfo = this.concat(algId, partyU, partyV, suppPubInfo, suppPrivInfo);
|
|
298
|
+
const counter = new Uint8Array([0, 0, 0, 1]);
|
|
299
|
+
const input = this.concat(counter, sharedSecret, otherInfo);
|
|
300
|
+
// Hash with SHA-256 (SJCL)
|
|
301
|
+
const inputHex = this.buf2hex(input);
|
|
302
|
+
const inputBits = sjcl_1.default.codec.hex.toBits(inputHex);
|
|
303
|
+
const hashBits = sjcl_1.default.hash.sha256.hash(inputBits);
|
|
304
|
+
const hashHex = sjcl_1.default.codec.hex.fromBits(hashBits);
|
|
305
|
+
const hashBuf = this.hex2buf(hashHex);
|
|
306
|
+
// Truncate to desired key length
|
|
307
|
+
return hashBuf.subarray(0, keyLength / 8);
|
|
308
|
+
}
|
|
309
|
+
encrypt(agentContext, options) {
|
|
310
|
+
try {
|
|
311
|
+
// encryption via A-256-GCM
|
|
312
|
+
// we will call the services side bob and the incoming side alice
|
|
313
|
+
if (options.key.keyAgreement === undefined) {
|
|
314
|
+
throw new Error("Key agreement is undefined");
|
|
315
|
+
}
|
|
316
|
+
if (options.key.keyAgreement.keyId === undefined) {
|
|
317
|
+
throw new Error("Key agreement keyId is undefined");
|
|
318
|
+
}
|
|
319
|
+
// 1. derive the shared secret via ECDH-ES
|
|
320
|
+
const sharedSecret = this.ecdhEs(options.key.keyAgreement.keyId, options.key.keyAgreement.externalPublicJwk);
|
|
321
|
+
agentContext.config.logger.debug(`EKM: Derived shared secret for encryption using ECDH-ES`);
|
|
322
|
+
// 2. Concat KDF to form the final key
|
|
323
|
+
const derivedKey = this.concatKdf(sharedSecret, 256, "A256GCM", options.key.keyAgreement);
|
|
324
|
+
// 3. Encrypt the data via AES-256-GCM using libsodium
|
|
325
|
+
// create nonce
|
|
326
|
+
const iv = crypto.getRandomValues(new Uint8Array(12));
|
|
327
|
+
// transform to bit arrays for sjcl
|
|
328
|
+
const keyBits = sjcl_1.default.codec.hex.toBits(this.buf2hex(derivedKey));
|
|
329
|
+
const dataBits = sjcl_1.default.codec.hex.toBits(this.buf2hex(options.data));
|
|
330
|
+
const ivBits = sjcl_1.default.codec.hex.toBits(this.buf2hex(iv));
|
|
331
|
+
// do not forget to add the additional authenticated data
|
|
332
|
+
const aadBits = "aad" in options.encryption && options.encryption.aad ? sjcl_1.default.codec.hex.toBits(this.buf2hex(options.encryption.aad)) : [];
|
|
333
|
+
// setup aes
|
|
334
|
+
const aes = new sjcl_1.default.cipher.aes(keyBits);
|
|
335
|
+
// encrypt
|
|
336
|
+
const cyphertextBits = sjcl_1.default.mode.gcm.encrypt(aes, dataBits, ivBits, aadBits, 128);
|
|
337
|
+
// transform back to byte array
|
|
338
|
+
const cyphertextBuf = this.hex2buf(sjcl_1.default.codec.hex.fromBits(cyphertextBits));
|
|
339
|
+
// In SJCL, GCM output = ciphertext || tag
|
|
340
|
+
const cyphertext = cyphertextBuf.subarray(0, cyphertextBuf.length - 16);
|
|
341
|
+
const tag = cyphertextBuf.subarray(cyphertextBuf.length - 16);
|
|
342
|
+
const returnValue = {
|
|
343
|
+
encrypted: cyphertext,
|
|
344
|
+
iv: iv,
|
|
345
|
+
tag: tag
|
|
346
|
+
};
|
|
347
|
+
return Promise.resolve(returnValue);
|
|
348
|
+
}
|
|
349
|
+
catch (e) {
|
|
350
|
+
agentContext.config.logger.error(`EKM: Error during encryption: ${e}`);
|
|
351
|
+
throw e;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
decrypt(agentContext, options) {
|
|
355
|
+
agentContext.config.logger.debug(`EKM: Decrypting data with key id ${options.key.keyId} using options ${options}`);
|
|
356
|
+
throw new Error("Method not implemented.");
|
|
357
|
+
}
|
|
358
|
+
randomBytes(agentContext, options) {
|
|
359
|
+
agentContext.config.logger.debug(`EKM: Generating ${options.length} random bytes`);
|
|
360
|
+
return libsodium_wrappers_1.default.randombytes_buf(options.length); // Uint8Array
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
exports.EnmshedHolderKeyManagmentService = EnmshedHolderKeyManagmentService;
|
|
364
|
+
//# sourceMappingURL=EnmeshedHolderKeyManagmentService.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnmeshedHolderKeyManagmentService.js","sourceRoot":"","sources":["../../../../src/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.ts"],"names":[],"mappings":";;;;;;AAuBA,uCAAoC;AACpC,4EAAyC;AACzC,gDAAwB;AAQxB,MAAa,gCAAgC;aAClB,YAAO,GAAG,0BAA0B,AAA7B,CAA8B;IAuB5D;QArBgB,YAAO,GAAG,gCAAgC,CAAC,OAAO,CAAC;QAGlD,WAAM,GAAG,CAAC,KAAiB,EAAE,EAAE,CAAC,4BAAO,CAAC,SAAS,CAAC,KAAK,EAAE,4BAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;QACrG,iBAAY,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,4BAAO,CAAC,WAAW,CAAC,MAAM,EAAE,4BAAO,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;QAE5H,sFAAsF;QACtF,sFAAsF;QACrE,YAAO,GAAG,CAAC,KAAiB,EAAE,EAAE;YAC7C,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;iBACnB,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,QAAQ,CA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AC,mBAAmB,OAAO,CAAC,MAAM,eAAe,CAAC,CAAC;QACnF,OAAO,4BAAO,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa;IACjE,CAAC;;AAxZL,4EAyZC"}
|
package/dist/modules/openid4vc/local/{FakeStorageService.d.ts → EnmeshedStorageService.d.ts}
RENAMED
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { AgentContext, BaseRecord, BaseRecordConstructor, Query, QueryOptions, StorageService } from "@credo-ts/core";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
import { AccountController } from "@nmshd/transport";
|
|
3
|
+
import { AttributesController } from "../../attributes/AttributesController";
|
|
4
|
+
export declare class EnmeshedStorageService<T extends BaseRecord> implements StorageService<T> {
|
|
5
|
+
accountController: AccountController;
|
|
6
|
+
attributeController: AttributesController;
|
|
7
|
+
storrage: Map<string, T>;
|
|
8
|
+
constructor(accountController: AccountController, attributeController: AttributesController);
|
|
4
9
|
save(agentContext: AgentContext, record: T): Promise<void>;
|
|
10
|
+
saveWithDisplay(agentContext: AgentContext, value: string, type: string, displayInformation: string, title: string): Promise<any>;
|
|
5
11
|
update(agentContext: AgentContext, record: T): Promise<void>;
|
|
6
12
|
delete(agentContext: AgentContext, record: T): Promise<void>;
|
|
7
13
|
deleteById(agentContext: AgentContext, recordClass: BaseRecordConstructor<T>, id: string): Promise<void>;
|
|
8
14
|
getById(agentContext: AgentContext, recordClass: BaseRecordConstructor<T>, id: string): Promise<T>;
|
|
9
15
|
getAll(agentContext: AgentContext, recordClass: BaseRecordConstructor<T>): Promise<T[]>;
|
|
16
|
+
getAllAsAttributes(agentContext: AgentContext, recordClass: BaseRecordConstructor<T>): Promise<any[]>;
|
|
10
17
|
findByQuery(agentContext: AgentContext, recordClass: BaseRecordConstructor<T>, query: Query<T>, queryOptions?: QueryOptions): Promise<T[]>;
|
|
11
18
|
}
|
|
12
|
-
//# sourceMappingURL=
|
|
19
|
+
//# sourceMappingURL=EnmeshedStorageService.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnmeshedStorageService.d.ts","sourceRoot":"","sources":["../../../../src/modules/openid4vc/local/EnmeshedStorageService.ts"],"names":[],"mappings":"AAAA,OAAO,EACH,YAAY,EACZ,UAAU,EACV,qBAAqB,EAMrB,KAAK,EACL,YAAY,EAEZ,cAAc,EAIjB,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAE7E,qBACa,sBAAsB,CAAC,CAAC,SAAS,UAAU,CAAE,YAAW,cAAc,CAAC,CAAC,CAAC;IAIvE,iBAAiB,EAAE,iBAAiB;IACpC,mBAAmB,EAAE,oBAAoB;IAJ7C,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAwB;gBAG5C,iBAAiB,EAAE,iBAAiB,EACpC,mBAAmB,EAAE,oBAAoB;IAGvC,IAAI,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAmC1D,eAAe,CAAC,YAAY,EAAE,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,kBAAkB,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;IAmBjI,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAuB5D,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAS5D,UAAU,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IASxG,OAAO,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,CAAC,CAAC;IAiBlG,MAAM,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IA0CvF,kBAAkB,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC;IAMrG,WAAW,CAAC,YAAY,EAAE,YAAY,EAAE,WAAW,EAAE,qBAAqB,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,YAAY,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;CAkC1J"}
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.EnmeshedStorageService = void 0;
|
|
13
|
+
const core_1 = require("@credo-ts/core");
|
|
14
|
+
const content_1 = require("@nmshd/content");
|
|
15
|
+
const core_types_1 = require("@nmshd/core-types");
|
|
16
|
+
const transport_1 = require("@nmshd/transport");
|
|
17
|
+
const AttributesController_1 = require("../../attributes/AttributesController");
|
|
18
|
+
let EnmeshedStorageService = class EnmeshedStorageService {
|
|
19
|
+
constructor(accountController, attributeController) {
|
|
20
|
+
this.accountController = accountController;
|
|
21
|
+
this.attributeController = attributeController;
|
|
22
|
+
this.storrage = new Map();
|
|
23
|
+
}
|
|
24
|
+
async save(agentContext, record) {
|
|
25
|
+
if (record.id === "STORAGE_VERSION_RECORD_ID") {
|
|
26
|
+
this.storrage.set(record.id, record);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (record.type === "DidRecord") {
|
|
30
|
+
this.storrage.set(record.id, record);
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
let value = record.encoded;
|
|
34
|
+
if (typeof value !== "string") {
|
|
35
|
+
agentContext.config.logger.warn(`Record is not a string, serializing to JSON`);
|
|
36
|
+
value = JSON.stringify(value);
|
|
37
|
+
}
|
|
38
|
+
const owner = this.accountController.identity.address;
|
|
39
|
+
agentContext.config.logger.debug(`Saving record with id ${record.id} and value ${value}`);
|
|
40
|
+
const identityAttribute = content_1.IdentityAttribute.from({
|
|
41
|
+
value: {
|
|
42
|
+
"@type": "VerifiableCredential",
|
|
43
|
+
title: record.credential?.payload?.vct ?? "Credential",
|
|
44
|
+
value: value,
|
|
45
|
+
type: record.type
|
|
46
|
+
},
|
|
47
|
+
owner: owner
|
|
48
|
+
});
|
|
49
|
+
const result = await this.attributeController.createRepositoryAttribute({
|
|
50
|
+
content: identityAttribute
|
|
51
|
+
});
|
|
52
|
+
agentContext.config.logger.debug(`Saved record: ${JSON.stringify(result)}`);
|
|
53
|
+
return await Promise.resolve();
|
|
54
|
+
}
|
|
55
|
+
async saveWithDisplay(agentContext, value, type, displayInformation, title) {
|
|
56
|
+
const owner = this.accountController.identity.address;
|
|
57
|
+
const identityAttribute = content_1.IdentityAttribute.from({
|
|
58
|
+
value: {
|
|
59
|
+
"@type": "VerifiableCredential",
|
|
60
|
+
value: value,
|
|
61
|
+
type: type,
|
|
62
|
+
displayInformation: displayInformation,
|
|
63
|
+
title: title
|
|
64
|
+
},
|
|
65
|
+
owner: owner
|
|
66
|
+
});
|
|
67
|
+
const result = await this.attributeController.createRepositoryAttribute({
|
|
68
|
+
content: identityAttribute
|
|
69
|
+
});
|
|
70
|
+
agentContext.config.logger.debug(`Saved record: ${JSON.stringify(result)}`);
|
|
71
|
+
return await Promise.resolve(result);
|
|
72
|
+
}
|
|
73
|
+
async update(agentContext, record) {
|
|
74
|
+
agentContext.config.logger.debug(`Updating record with id ${record.id}`);
|
|
75
|
+
const value = core_1.JsonTransformer.serialize(record);
|
|
76
|
+
const owner = this.accountController.identity.address;
|
|
77
|
+
const oldAttribute = await this.attributeController.getLocalAttribute(core_types_1.CoreId.from(record.id));
|
|
78
|
+
if (!oldAttribute)
|
|
79
|
+
throw new Error(`Attribute with id ${record.id} not found`);
|
|
80
|
+
const identityAttribute = content_1.IdentityAttribute.from({
|
|
81
|
+
value: {
|
|
82
|
+
"@type": "VerifiableCredential",
|
|
83
|
+
value: value,
|
|
84
|
+
title: "Employee ID Card",
|
|
85
|
+
displayInformation: oldAttribute.content.value.displayInformation
|
|
86
|
+
},
|
|
87
|
+
owner: owner
|
|
88
|
+
});
|
|
89
|
+
await this.attributeController.createRepositoryAttribute({
|
|
90
|
+
content: identityAttribute,
|
|
91
|
+
id: core_types_1.CoreId.from(record.id)
|
|
92
|
+
});
|
|
93
|
+
return await Promise.resolve();
|
|
94
|
+
}
|
|
95
|
+
async delete(agentContext, record) {
|
|
96
|
+
agentContext.config.logger.debug(`Deleting record with id ${record.id}`);
|
|
97
|
+
const attribute = await this.attributeController.getLocalAttribute(core_types_1.CoreId.from(record.id));
|
|
98
|
+
if (attribute === undefined) {
|
|
99
|
+
throw new Error(`Attribute with id ${record.id} not found`);
|
|
100
|
+
}
|
|
101
|
+
await this.attributeController.deleteAttribute(attribute);
|
|
102
|
+
}
|
|
103
|
+
async deleteById(agentContext, recordClass, id) {
|
|
104
|
+
agentContext.config.logger.debug(`Deleting record with id ${id} - with record class ${recordClass.name}`);
|
|
105
|
+
const attribute = await this.attributeController.getLocalAttribute(core_types_1.CoreId.from(id));
|
|
106
|
+
if (attribute === undefined) {
|
|
107
|
+
throw new Error(`Attribute with id ${id} not found`);
|
|
108
|
+
}
|
|
109
|
+
await this.attributeController.deleteAttribute(attribute);
|
|
110
|
+
}
|
|
111
|
+
async getById(agentContext, recordClass, id) {
|
|
112
|
+
if (this.storrage.has(id)) {
|
|
113
|
+
const record = this.storrage.get(id);
|
|
114
|
+
if (!record)
|
|
115
|
+
throw new Error(`Record with id ${id} not found`);
|
|
116
|
+
return record;
|
|
117
|
+
}
|
|
118
|
+
agentContext.config.logger.debug(`Getting record with id ${id}`);
|
|
119
|
+
const attribute = await this.attributeController.getLocalAttribute(core_types_1.CoreId.from(id));
|
|
120
|
+
// parse the value field of attribute as JSON into T
|
|
121
|
+
if (attribute === undefined) {
|
|
122
|
+
throw new Error(`Attribute with id ${id} not found`);
|
|
123
|
+
}
|
|
124
|
+
const record = core_1.JsonTransformer.deserialize(attribute.content.value.value, recordClass);
|
|
125
|
+
return record;
|
|
126
|
+
}
|
|
127
|
+
async getAll(agentContext, recordClass) {
|
|
128
|
+
const records = [];
|
|
129
|
+
const attributes = await this.attributeController.getLocalAttributes({ "content.value.@type": "VerifiableCredential", shareInfo: { $exists: false } });
|
|
130
|
+
for (const attribute of attributes) {
|
|
131
|
+
// TODO: Correct casting
|
|
132
|
+
const type = attribute.content.value.type;
|
|
133
|
+
let record;
|
|
134
|
+
if (type === core_1.ClaimFormat.SdJwtDc.toString() && recordClass.name === core_1.SdJwtVcRecord.name) {
|
|
135
|
+
record = new core_1.SdJwtVcRecord({ id: attribute.content.id, compactSdJwtVc: attribute.content.value.value });
|
|
136
|
+
}
|
|
137
|
+
else if (type === core_1.ClaimFormat.MsoMdoc.toString() && recordClass.name === core_1.MdocRecord.name) {
|
|
138
|
+
record = new core_1.MdocRecord({ id: attribute.content.id, mdoc: core_1.Mdoc.fromBase64Url(attribute.content.value.value) });
|
|
139
|
+
}
|
|
140
|
+
else if (type === core_1.ClaimFormat.SdJwtW3cVc.toString() && recordClass.name === core_1.W3cCredentialRecord.name) {
|
|
141
|
+
const credential = core_1.W3cJwtVerifiableCredential.fromSerializedJwt(attribute.content.value.value);
|
|
142
|
+
record = new core_1.W3cCredentialRecord({
|
|
143
|
+
id: attribute.content.id,
|
|
144
|
+
credential: credential,
|
|
145
|
+
tags: {}
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
agentContext.config.logger.info(`Skipping attribute with id ${attribute.id} and type ${type} as it does not match record class ${recordClass.name}`);
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (attribute.content.value.key !== undefined) {
|
|
153
|
+
// TODO: Remove as this is only a workaround for demo purposes
|
|
154
|
+
agentContext.config.logger.info("Found keys to possibly import");
|
|
155
|
+
const parsed = JSON.parse(attribute.content.value.key);
|
|
156
|
+
for (const [k, v] of parsed) {
|
|
157
|
+
const currentKeys = globalThis.fakeKeyStorage;
|
|
158
|
+
if (!currentKeys.has(k)) {
|
|
159
|
+
globalThis.fakeKeyStorage.set(k, v);
|
|
160
|
+
agentContext.config.logger.info(`Added key ${k} to fake keystore`);
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
agentContext.config.logger.info(`Key ${k} already in fake keystore`);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
records.push(record);
|
|
168
|
+
}
|
|
169
|
+
return records;
|
|
170
|
+
}
|
|
171
|
+
// should only be used for exporting data out of the credo environment
|
|
172
|
+
async getAllAsAttributes(agentContext, recordClass) {
|
|
173
|
+
agentContext.config.logger.debug(`Getting all records of type ${recordClass.name}`);
|
|
174
|
+
const attributes = await this.attributeController.getLocalAttributes({ "content.value.@type": "VerifiableCredential", shareInfo: { $exists: false } });
|
|
175
|
+
return attributes;
|
|
176
|
+
}
|
|
177
|
+
async findByQuery(agentContext, recordClass, query, queryOptions) {
|
|
178
|
+
agentContext.config.logger.debug(`Finding records by query ${JSON.stringify(query)} and options ${JSON.stringify(queryOptions)}`);
|
|
179
|
+
const records = [];
|
|
180
|
+
for (const record of await this.getAll(agentContext, recordClass)) {
|
|
181
|
+
let match = true;
|
|
182
|
+
for (const [key, value] of Object.entries(query)) {
|
|
183
|
+
if (record[key] !== value) {
|
|
184
|
+
match = false;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
if (match) {
|
|
189
|
+
records.push(record);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
if (records.length === 0) {
|
|
193
|
+
// try to recover over local storrage - temporary fix
|
|
194
|
+
for (const record of this.storrage.values()) {
|
|
195
|
+
let match = true;
|
|
196
|
+
// there may be keys labeled with an $or - solve them accordingly
|
|
197
|
+
// TODO: $or and other operators not yet supported
|
|
198
|
+
for (const [key, value] of Object.entries(query)) {
|
|
199
|
+
if (record[key] !== value) {
|
|
200
|
+
match = false;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (match) {
|
|
205
|
+
records.push(record);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
return records;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
exports.EnmeshedStorageService = EnmeshedStorageService;
|
|
213
|
+
exports.EnmeshedStorageService = EnmeshedStorageService = __decorate([
|
|
214
|
+
(0, core_1.injectable)(),
|
|
215
|
+
__metadata("design:paramtypes", [transport_1.AccountController,
|
|
216
|
+
AttributesController_1.AttributesController])
|
|
217
|
+
], EnmeshedStorageService);
|
|
218
|
+
//# sourceMappingURL=EnmeshedStorageService.js.map
|