@nmshd/consumption 7.4.1 → 7.5.0-openid4vc.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/buildInformation.js +5 -5
  2. package/dist/consumption/ConsumptionConfig.d.ts +1 -0
  3. package/dist/consumption/ConsumptionConfig.d.ts.map +1 -1
  4. package/dist/consumption/ConsumptionController.d.ts +3 -1
  5. package/dist/consumption/ConsumptionController.d.ts.map +1 -1
  6. package/dist/consumption/ConsumptionController.js +7 -1
  7. package/dist/consumption/ConsumptionController.js.map +1 -1
  8. package/dist/consumption/ConsumptionControllerName.d.ts +2 -1
  9. package/dist/consumption/ConsumptionControllerName.d.ts.map +1 -1
  10. package/dist/consumption/ConsumptionControllerName.js +1 -0
  11. package/dist/consumption/ConsumptionControllerName.js.map +1 -1
  12. package/dist/consumption/ConsumptionIds.d.ts +1 -0
  13. package/dist/consumption/ConsumptionIds.d.ts.map +1 -1
  14. package/dist/consumption/ConsumptionIds.js +1 -0
  15. package/dist/consumption/ConsumptionIds.js.map +1 -1
  16. package/dist/modules/index.d.ts +1 -0
  17. package/dist/modules/index.d.ts.map +1 -1
  18. package/dist/modules/index.js +1 -0
  19. package/dist/modules/index.js.map +1 -1
  20. package/dist/modules/openid4vc/OpenId4VcController.d.ts +36 -0
  21. package/dist/modules/openid4vc/OpenId4VcController.d.ts.map +1 -0
  22. package/dist/modules/openid4vc/OpenId4VcController.js +100 -0
  23. package/dist/modules/openid4vc/OpenId4VcController.js.map +1 -0
  24. package/dist/modules/openid4vc/index.d.ts +8 -0
  25. package/dist/modules/openid4vc/index.d.ts.map +1 -0
  26. package/dist/modules/openid4vc/index.js +24 -0
  27. package/dist/modules/openid4vc/index.js.map +1 -0
  28. package/dist/modules/openid4vc/local/BaseAgent.d.ts +17 -0
  29. package/dist/modules/openid4vc/local/BaseAgent.d.ts.map +1 -0
  30. package/dist/modules/openid4vc/local/BaseAgent.js +72 -0
  31. package/dist/modules/openid4vc/local/BaseAgent.js.map +1 -0
  32. package/dist/modules/openid4vc/local/EnmeshedHolderFileSystem.d.ts +14 -0
  33. package/dist/modules/openid4vc/local/EnmeshedHolderFileSystem.d.ts.map +1 -0
  34. package/dist/modules/openid4vc/local/EnmeshedHolderFileSystem.js +29 -0
  35. package/dist/modules/openid4vc/local/EnmeshedHolderFileSystem.js.map +1 -0
  36. package/dist/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.d.ts +33 -0
  37. package/dist/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.d.ts.map +1 -0
  38. package/dist/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.js +345 -0
  39. package/dist/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.js.map +1 -0
  40. package/dist/modules/openid4vc/local/EnmeshedStorageService.d.ts +25 -0
  41. package/dist/modules/openid4vc/local/EnmeshedStorageService.d.ts.map +1 -0
  42. package/dist/modules/openid4vc/local/EnmeshedStorageService.js +139 -0
  43. package/dist/modules/openid4vc/local/EnmeshedStorageService.js.map +1 -0
  44. package/dist/modules/openid4vc/local/Holder.d.ts +43 -0
  45. package/dist/modules/openid4vc/local/Holder.d.ts.map +1 -0
  46. package/dist/modules/openid4vc/local/Holder.js +184 -0
  47. package/dist/modules/openid4vc/local/Holder.js.map +1 -0
  48. package/dist/modules/openid4vc/local/KeyStorage.d.ts +12 -0
  49. package/dist/modules/openid4vc/local/KeyStorage.d.ts.map +1 -0
  50. package/dist/modules/openid4vc/local/KeyStorage.js +67 -0
  51. package/dist/modules/openid4vc/local/KeyStorage.js.map +1 -0
  52. package/dist/modules/openid4vc/local/OpenId4VciCredentialResponseJSON.d.ts +7 -0
  53. package/dist/modules/openid4vc/local/OpenId4VciCredentialResponseJSON.d.ts.map +1 -0
  54. package/dist/modules/openid4vc/local/OpenId4VciCredentialResponseJSON.js +3 -0
  55. package/dist/modules/openid4vc/local/OpenId4VciCredentialResponseJSON.js.map +1 -0
  56. package/dist/modules/openid4vc/local/RequestedCredentialCache.d.ts +9 -0
  57. package/dist/modules/openid4vc/local/RequestedCredentialCache.d.ts.map +1 -0
  58. package/dist/modules/openid4vc/local/RequestedCredentialCache.js +57 -0
  59. package/dist/modules/openid4vc/local/RequestedCredentialCache.js.map +1 -0
  60. package/dist/modules/requests/events/ShareCredentialOfferRequestItemProcessedByRecipientEvent.d.ts +12 -0
  61. package/dist/modules/requests/events/ShareCredentialOfferRequestItemProcessedByRecipientEvent.d.ts.map +1 -0
  62. package/dist/modules/requests/events/ShareCredentialOfferRequestItemProcessedByRecipientEvent.js +12 -0
  63. package/dist/modules/requests/events/ShareCredentialOfferRequestItemProcessedByRecipientEvent.js.map +1 -0
  64. package/dist/modules/requests/events/index.d.ts +1 -0
  65. package/dist/modules/requests/events/index.d.ts.map +1 -1
  66. package/dist/modules/requests/events/index.js +1 -0
  67. package/dist/modules/requests/events/index.js.map +1 -1
  68. package/dist/modules/requests/index.d.ts +3 -0
  69. package/dist/modules/requests/index.d.ts.map +1 -1
  70. package/dist/modules/requests/index.js +3 -0
  71. package/dist/modules/requests/index.js.map +1 -1
  72. package/dist/modules/requests/itemProcessors/shareAuthorizationRequest/AcceptShareAuthorizationRequestRequestItemParameters.d.ts +11 -0
  73. package/dist/modules/requests/itemProcessors/shareAuthorizationRequest/AcceptShareAuthorizationRequestRequestItemParameters.d.ts.map +1 -0
  74. package/dist/modules/requests/itemProcessors/shareAuthorizationRequest/AcceptShareAuthorizationRequestRequestItemParameters.js +29 -0
  75. package/dist/modules/requests/itemProcessors/shareAuthorizationRequest/AcceptShareAuthorizationRequestRequestItemParameters.js.map +1 -0
  76. package/dist/modules/requests/itemProcessors/shareAuthorizationRequest/ShareAuthorizationRequestRequestItemProcessor.d.ts +12 -0
  77. package/dist/modules/requests/itemProcessors/shareAuthorizationRequest/ShareAuthorizationRequestRequestItemProcessor.d.ts.map +1 -0
  78. package/dist/modules/requests/itemProcessors/shareAuthorizationRequest/ShareAuthorizationRequestRequestItemProcessor.js +55 -0
  79. package/dist/modules/requests/itemProcessors/shareAuthorizationRequest/ShareAuthorizationRequestRequestItemProcessor.js.map +1 -0
  80. package/dist/modules/requests/itemProcessors/shareCredentialOffer/ShareCredentialOfferRequestItemProcessor.d.ts +14 -0
  81. package/dist/modules/requests/itemProcessors/shareCredentialOffer/ShareCredentialOfferRequestItemProcessor.d.ts.map +1 -0
  82. package/dist/modules/requests/itemProcessors/shareCredentialOffer/ShareCredentialOfferRequestItemProcessor.js +45 -0
  83. package/dist/modules/requests/itemProcessors/shareCredentialOffer/ShareCredentialOfferRequestItemProcessor.js.map +1 -0
  84. package/dist/modules/requests/outgoing/OutgoingRequestsController.d.ts.map +1 -1
  85. package/dist/modules/requests/outgoing/OutgoingRequestsController.js +3 -1
  86. package/dist/modules/requests/outgoing/OutgoingRequestsController.js.map +1 -1
  87. package/package.json +30 -8
@@ -0,0 +1,345 @@
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 core_1 = require("@credo-ts/core");
8
+ const elliptic_1 = require("elliptic");
9
+ const crypto_1 = require("@nmshd/crypto");
10
+ const sjcl_1 = __importDefault(require("sjcl"));
11
+ class EnmshedHolderKeyManagmentService {
12
+ static { this.backend = "enmeshed"; }
13
+ constructor(keyStorage) {
14
+ this.keyStorage = keyStorage;
15
+ this.backend = EnmshedHolderKeyManagmentService.backend;
16
+ this.b64url = (bytes) => crypto_1.SodiumWrapper.sodium.to_base64(bytes, crypto_1.SodiumWrapper.sodium.base64_variants.URLSAFE_NO_PADDING);
17
+ this.b64urlDecode = (b64url) => crypto_1.SodiumWrapper.sodium.from_base64(b64url, crypto_1.SodiumWrapper.sodium.base64_variants.URLSAFE_NO_PADDING);
18
+ // please note: we cannot use buffer here - because it is not available in the browser
19
+ // and yes it could be pollyfilled but that extends the bundle size for no good reason
20
+ this.buf2hex = (bytes) => {
21
+ return Array.from(bytes)
22
+ .map((b) => b.toString(16).padStart(2, "0"))
23
+ .join("");
24
+ };
25
+ this.hex2buf = (hex) => {
26
+ const bytes = new Uint8Array(hex.length / 2);
27
+ for (let i = 0; i < bytes.length; i++) {
28
+ bytes[i] = parseInt(hex.substring(i * 2, i * 2 + 2), 16);
29
+ }
30
+ return bytes;
31
+ };
32
+ }
33
+ isOperationSupported(agentContext, operation) {
34
+ agentContext.config.logger.debug(`EKM: Checking if operation is supported: ${JSON.stringify(operation)}`);
35
+ if (operation.operation === "createKey") {
36
+ if (operation.type.kty === "OKP") {
37
+ return true;
38
+ }
39
+ if (operation.type.kty === "EC" && operation.type.crv === "P-256") {
40
+ return true;
41
+ }
42
+ return false;
43
+ }
44
+ if (operation.operation === "verify" && operation.algorithm === "ES256") {
45
+ return true;
46
+ }
47
+ if (operation.operation === "sign" && (operation.algorithm === "EdDSA" || operation.algorithm === "ES256")) {
48
+ return true;
49
+ }
50
+ if (operation.operation === "randomBytes") {
51
+ return true;
52
+ }
53
+ if (operation.operation === "deleteKey") {
54
+ return true;
55
+ }
56
+ if (operation.operation === "encrypt" && ["A128GCM", "A256GCM"].includes(operation.encryption.algorithm)) {
57
+ return true;
58
+ }
59
+ return false;
60
+ }
61
+ async getPublicKey(agentContext, keyId) {
62
+ const keyPair = await this.keyStorage.getKey(keyId);
63
+ if (!keyPair) {
64
+ agentContext.config.logger.error(`EKM: Key with id ${keyId} not found`);
65
+ throw new Error(`Key with id ${keyId} not found`);
66
+ }
67
+ return JSON.parse(keyPair).publicKey;
68
+ }
69
+ async createKey(agentContext, options) {
70
+ options.keyId ??= "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function (c) {
71
+ // Use libsodium's randombytes_uniform for secure random number generation
72
+ const r = crypto_1.SodiumWrapper.sodium.randombytes_uniform(16);
73
+ const v = c === "x" ? r : (r & 0x3) | 0x8;
74
+ return v.toString(16);
75
+ });
76
+ agentContext.config.logger.debug(`EKM: Creating key with id ${options.keyId} and type ${JSON.stringify(options.type)}`);
77
+ if (options.type.kty === "EC" && options.type.crv === "P-256") {
78
+ // Use P-256 (aka secp256r1)
79
+ const ec = new elliptic_1.ec("p256");
80
+ const key = ec.genKeyPair();
81
+ // Public JWK
82
+ const publicJwk = {
83
+ kty: "EC", // Elliptic Curve
84
+ crv: "P-256",
85
+ x: this.b64url(new Uint8Array(key.getPublic().getX().toArray())),
86
+ y: this.b64url(new Uint8Array(key.getPublic().getY().toArray()))
87
+ };
88
+ // Private JWK
89
+ const privateJwk = {
90
+ ...publicJwk,
91
+ d: this.b64url(new Uint8Array(key.getPrivate().toArray()))
92
+ };
93
+ const jwkKeyPair = {
94
+ publicKey: publicJwk,
95
+ privateKey: privateJwk,
96
+ keyType: "EC"
97
+ };
98
+ agentContext.config.logger.debug(`EKM: Created EC key pair with id ${options.keyId}`);
99
+ // store the key pair in the keystore
100
+ await this.keyStorage.storeKey(options.keyId, JSON.stringify(jwkKeyPair));
101
+ // Credo doesn't trust the key id provided in the key binding jwk anymore, so there are two options: Storing the key id with the credential and making sure that key id is properly fetched - this turned out to be difficult - or the easy way out by storing this alternative key id computed from the public key.
102
+ const credoLegacyKeyId = core_1.Kms.PublicJwk.fromPublicJwk(publicJwk).legacyKeyId;
103
+ await this.keyStorage.storeKey(credoLegacyKeyId, JSON.stringify(jwkKeyPair));
104
+ return { keyId: options.keyId, publicJwk: publicJwk };
105
+ }
106
+ const { keyType, publicKey, privateKey } = crypto_1.SodiumWrapper.sodium.crypto_sign_keypair();
107
+ agentContext.config.logger.debug(`EKM: Created OKP key pair with id ${options.keyId} and keyType ${keyType}`);
108
+ const seed = privateKey.slice(0, crypto_1.SodiumWrapper.sodium.crypto_sign_SEEDBYTES);
109
+ // Public JWK
110
+ const publicJwk = {
111
+ kty: "OKP", // Octet Key Pair
112
+ crv: "Ed25519",
113
+ x: this.b64url(publicKey)
114
+ };
115
+ // Private JWK
116
+ const privateJwk = {
117
+ ...publicJwk,
118
+ d: this.b64url(seed)
119
+ };
120
+ const jwkKeyPair = {
121
+ publicKey: publicJwk,
122
+ privateKey: privateJwk,
123
+ keyType: "OKP"
124
+ };
125
+ await this.keyStorage.storeKey(options.keyId, JSON.stringify(jwkKeyPair));
126
+ return { keyId: options.keyId, publicJwk: publicJwk };
127
+ }
128
+ importKey(agentContext, options) {
129
+ agentContext.config.logger.debug(`EKM: Importing key with ${JSON.stringify(options)}`);
130
+ throw new Error("Method not implemented.");
131
+ }
132
+ async deleteKey(agentContext, options) {
133
+ const hasKey = await this.keyStorage.hasKey(options.keyId);
134
+ if (!hasKey)
135
+ throw new Error(`key with id ${options.keyId} not found. and cannot be deleted`);
136
+ agentContext.config.logger.debug(`EKM: Deleting key with id ${options.keyId}`);
137
+ await this.keyStorage.deleteKey(options.keyId);
138
+ return true;
139
+ }
140
+ async sign(agentContext, options) {
141
+ agentContext.config.logger.debug(`EKM: Signing data with key id ${options.keyId} using algorithm ${options.algorithm}`);
142
+ const stringifiedKeyPair = await this.keyStorage.getKey(options.keyId);
143
+ if (!stringifiedKeyPair) {
144
+ throw new Error(`Key with id ${options.keyId} not found`);
145
+ }
146
+ const { privateKey, publicKey } = JSON.parse(stringifiedKeyPair);
147
+ if (options.algorithm === "ES256") {
148
+ // Use P-256 (aka secp256r1)
149
+ const ec = new elliptic_1.ec("p256");
150
+ if (!privateKey.d) {
151
+ throw new Error("Private JWK does not contain 'd' parameter");
152
+ }
153
+ const priv = this.buf2hex(this.b64urlDecode(privateKey.d));
154
+ const key = ec.keyFromPrivate(priv, "hex");
155
+ // we need to hash the data using SHA-256
156
+ const dataHash = ec.hash().update(options.data).digest();
157
+ const signature = key.sign(dataHash);
158
+ const r = new Uint8Array(signature.r.toArray());
159
+ const s = new Uint8Array(signature.s.toArray());
160
+ const signatureBytes = new Uint8Array(r.length + s.length);
161
+ signatureBytes.set(r);
162
+ signatureBytes.set(s, r.length);
163
+ return await Promise.resolve({
164
+ signature: signatureBytes
165
+ });
166
+ }
167
+ const decode = (bytes) => crypto_1.SodiumWrapper.sodium.from_base64(bytes, crypto_1.SodiumWrapper.sodium.base64_variants.URLSAFE_NO_PADDING);
168
+ // get the private key bytes
169
+ if (privateKey.d === undefined) {
170
+ throw new Error("Private key does not contain 'd' parameter");
171
+ }
172
+ const privateKeyBytes = decode(privateKey.d);
173
+ // get the public key bytes
174
+ if (publicKey.x === undefined) {
175
+ throw new Error("Public key does not contain 'x' parameter");
176
+ }
177
+ const publicKeyBytes = decode(publicKey.x);
178
+ // combine the key bytes to a full private key
179
+ const fullPrivateKeyBytes = new Uint8Array(privateKeyBytes.length + publicKeyBytes.length);
180
+ fullPrivateKeyBytes.set(privateKeyBytes);
181
+ fullPrivateKeyBytes.set(publicKeyBytes, privateKeyBytes.length);
182
+ // and use it to sign the data
183
+ const signature = crypto_1.SodiumWrapper.sodium.crypto_sign_detached(options.data, fullPrivateKeyBytes);
184
+ return {
185
+ signature: signature // I hope this cast doesn't paper over something
186
+ };
187
+ }
188
+ verify(agentContext, options) {
189
+ agentContext.config.logger.debug(`EKM: Verifying signature with key id ${options.key.keyId} using algorithm ${options.algorithm}`);
190
+ // Use P-256 (aka secp256r1)
191
+ const ec = new elliptic_1.ec("p256");
192
+ if (!options.key.publicJwk) {
193
+ throw new Error("Public JWK is undefined");
194
+ }
195
+ if (options.key.publicJwk.kty !== "EC") {
196
+ throw new Error("Public JWK does not contain 'x' or 'y' parameter");
197
+ }
198
+ const x = options.key.publicJwk.x;
199
+ const y = options.key.publicJwk.y;
200
+ const pub = { x: this.buf2hex(this.b64urlDecode(x)), y: this.buf2hex(this.b64urlDecode(y)) };
201
+ const key = ec.keyFromPublic(pub, "hex");
202
+ const signatureBytes = options.signature;
203
+ const r = signatureBytes.subarray(0, 32);
204
+ const s = signatureBytes.subarray(32, 64);
205
+ const signature = { r: this.buf2hex(r), s: this.buf2hex(s) };
206
+ // we need to hash the data using SHA-256
207
+ const dataHash = ec.hash().update(options.data).digest();
208
+ try {
209
+ const verified = key.verify(dataHash, signature);
210
+ return Promise.resolve({ verified: verified });
211
+ }
212
+ catch (e) {
213
+ agentContext.config.logger.error(`EKM: Error during signature verification: ${e}`);
214
+ throw e;
215
+ }
216
+ }
217
+ async ecdhEs(localKeyId, remotePublicJWK) {
218
+ const keyPairString = await this.keyStorage.getKey(localKeyId);
219
+ if (!keyPairString) {
220
+ throw new Error(`Key with id ${localKeyId} not found`);
221
+ }
222
+ const localKeyPair = JSON.parse(keyPairString);
223
+ if (localKeyPair.keyType !== "EC") {
224
+ throw new Error("Key type is not EC");
225
+ }
226
+ const ec = new elliptic_1.ec("p256");
227
+ if (localKeyPair.privateKey.d === undefined) {
228
+ throw new Error("Local private key does not contain 'd' parameter");
229
+ }
230
+ const localPriv = ec.keyFromPrivate(this.buf2hex(this.b64urlDecode(localKeyPair.privateKey.d)), "hex");
231
+ // the remote jwk is base64url encoded - we again decode and transform to hex to receive a fitting public key
232
+ const remoteBasePoint = ec.keyFromPublic({
233
+ x: this.buf2hex(this.b64urlDecode(remotePublicJWK.x)),
234
+ y: this.buf2hex(this.b64urlDecode(remotePublicJWK.y))
235
+ }, "hex");
236
+ const sharedSecret = localPriv.derive(remoteBasePoint.getPublic());
237
+ const sharedBytes = new Uint8Array(sharedSecret.toArray("be"));
238
+ return sharedBytes;
239
+ }
240
+ // UTF-8 encode helper
241
+ utf8(str) {
242
+ return new TextEncoder().encode(str);
243
+ }
244
+ // Concat Uint8Arrays
245
+ concat(...arrays) {
246
+ const total = arrays.reduce((sum, a) => sum + a.length, 0);
247
+ const out = new Uint8Array(total);
248
+ let offset = 0;
249
+ for (const a of arrays) {
250
+ out.set(a, offset);
251
+ offset += a.length;
252
+ }
253
+ return out;
254
+ }
255
+ // Encode a 32-bit big-endian length prefix
256
+ lenPrefix(data) {
257
+ const buf = new Uint8Array(4 + data.length);
258
+ const view = new DataView(buf.buffer);
259
+ view.setUint32(0, data.length, false); // big-endian
260
+ buf.set(data, 4);
261
+ return buf;
262
+ }
263
+ concatKdf(sharedSecret, keyLength, algorithmDescriptor, keyAgreement) {
264
+ if (keyAgreement.apu === undefined) {
265
+ throw new Error("Key agreement apu is undefined");
266
+ }
267
+ if (keyAgreement.apv === undefined) {
268
+ throw new Error("Key agreement apv is undefined");
269
+ }
270
+ const algId = this.lenPrefix(this.utf8(algorithmDescriptor));
271
+ const partyU = this.lenPrefix(keyAgreement.apu);
272
+ const partyV = this.lenPrefix(keyAgreement.apv);
273
+ const suppPubInfo = new Uint8Array(4);
274
+ new DataView(suppPubInfo.buffer).setUint32(0, keyLength, false);
275
+ const suppPrivInfo = new Uint8Array(0);
276
+ const otherInfo = this.concat(algId, partyU, partyV, suppPubInfo, suppPrivInfo);
277
+ const counter = new Uint8Array([0, 0, 0, 1]);
278
+ const input = this.concat(counter, sharedSecret, otherInfo);
279
+ // Hash with SHA-256 (SJCL)
280
+ const inputHex = this.buf2hex(input);
281
+ const inputBits = sjcl_1.default.codec.hex.toBits(inputHex);
282
+ const hashBits = sjcl_1.default.hash.sha256.hash(inputBits);
283
+ const hashHex = sjcl_1.default.codec.hex.fromBits(hashBits);
284
+ const hashBuf = this.hex2buf(hashHex);
285
+ // Truncate to desired key length
286
+ return hashBuf.subarray(0, keyLength / 8);
287
+ }
288
+ async encrypt(agentContext, options) {
289
+ try {
290
+ // encryption via A-128-GCM/A-256-GCM
291
+ // we will call the services side bob and the incoming side alice
292
+ if (options.key.keyAgreement === undefined) {
293
+ throw new Error("Key agreement is undefined");
294
+ }
295
+ if (options.key.keyAgreement.keyId === undefined) {
296
+ throw new Error("Key agreement keyId is undefined");
297
+ }
298
+ const algorithm = options.encryption.algorithm;
299
+ const keyLength = options.encryption.algorithm === "A128GCM" ? 128 : 256;
300
+ // 1. derive the shared secret via ECDH-ES
301
+ const sharedSecret = await this.ecdhEs(options.key.keyAgreement.keyId, options.key.keyAgreement.externalPublicJwk);
302
+ agentContext.config.logger.debug(`EKM: Derived shared secret for encryption using ECDH-ES`);
303
+ // 2. Concat KDF to form the final key
304
+ const derivedKey = this.concatKdf(sharedSecret, keyLength, algorithm, options.key.keyAgreement);
305
+ // 3. Encrypt the data via AES-256-GCM using libsodium
306
+ // create nonce
307
+ const iv = crypto.getRandomValues(new Uint8Array(12));
308
+ // transform to bit arrays for sjcl
309
+ const keyBits = sjcl_1.default.codec.hex.toBits(this.buf2hex(derivedKey));
310
+ const dataBits = sjcl_1.default.codec.hex.toBits(this.buf2hex(options.data));
311
+ const ivBits = sjcl_1.default.codec.hex.toBits(this.buf2hex(iv));
312
+ // do not forget to add the additional authenticated data
313
+ const aadBits = "aad" in options.encryption && options.encryption.aad ? sjcl_1.default.codec.hex.toBits(this.buf2hex(options.encryption.aad)) : [];
314
+ // setup aes
315
+ const aes = new sjcl_1.default.cipher.aes(keyBits);
316
+ // encrypt
317
+ const cyphertextBits = sjcl_1.default.mode.gcm.encrypt(aes, dataBits, ivBits, aadBits, 128);
318
+ // transform back to byte array
319
+ const cyphertextBuf = this.hex2buf(sjcl_1.default.codec.hex.fromBits(cyphertextBits));
320
+ // In SJCL, GCM output = ciphertext || tag
321
+ const cyphertext = cyphertextBuf.subarray(0, cyphertextBuf.length - 16);
322
+ const tag = cyphertextBuf.subarray(cyphertextBuf.length - 16);
323
+ const returnValue = {
324
+ encrypted: cyphertext,
325
+ iv: iv,
326
+ tag: tag
327
+ };
328
+ return returnValue;
329
+ }
330
+ catch (e) {
331
+ agentContext.config.logger.error(`EKM: Error during encryption: ${e}`);
332
+ throw e;
333
+ }
334
+ }
335
+ decrypt(agentContext, options) {
336
+ agentContext.config.logger.debug(`EKM: Decrypting data with key id ${options.key.keyId} using options ${options}`);
337
+ throw new Error("Method not implemented.");
338
+ }
339
+ randomBytes(agentContext, options) {
340
+ agentContext.config.logger.debug(`EKM: Generating ${options.length} random bytes`);
341
+ return crypto_1.SodiumWrapper.sodium.randombytes_buf(options.length); // Uint8Array
342
+ }
343
+ }
344
+ exports.EnmshedHolderKeyManagmentService = EnmshedHolderKeyManagmentService;
345
+ //# sourceMappingURL=EnmeshedHolderKeyManagmentService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnmeshedHolderKeyManagmentService.js","sourceRoot":"","sources":["../../../../src/modules/openid4vc/local/EnmeshedHolderKeyManagmentService.ts"],"names":[],"mappings":";;;;;;AAAA,yCAAmD;AACnD,uCAAoC;AAEpC,0CAA8C;AAC9C,gDAAwB;AASxB,MAAa,gCAAgC;aAClB,YAAO,GAAG,UAAU,AAAb,CAAc;IAsB5C,YAAoC,UAAsB;QAAtB,eAAU,GAAV,UAAU,CAAY;QApB1C,YAAO,GAAG,gCAAgC,CAAC,OAAO,CAAC;QAElD,WAAM,GAAG,CAAC,KAAiB,EAAE,EAAE,CAAC,sBAAa,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,EAAG,sBAAa,CAAC,MAAc,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;QACxI,iBAAY,GAAG,CAAC,MAAc,EAAE,EAAE,CAAC,sBAAa,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,EAAG,sBAAa,CAAC,MAAc,CAAC,eAAe,CAAC,kBAAkB,CAAC,CAAC;QAE/J,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,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;iBAC3C,IAAI,CAAC,EAAE,CAAC,CAAC;QAClB,CAAC,CAAC;QACe,YAAO,GAAG,CAAC,GAAW,EAAE,EAAE;YACvC,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC7C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,K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C,QAAQ,CAAC,CAAC,EAAE,aAAa,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;YACxE,MAAM,GAAG,GAAG,aAAa,CAAC,QAAQ,CAAC,aAAa,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC;YAE9D,MAAM,WAAW,GAAG;gBAChB,SAAS,EAAE,UAAU;gBACrB,EAAE,EAAE,EAAE;gBACN,GAAG,EAAE,GAAG;aACX,CAAC;YAEF,OAAO,WAAW,CAAC;QACvB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACT,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,iCAAiC,CAAC,EAAE,CAAC,CAAC;YACvE,MAAM,CAAC,CAAC;QACZ,CAAC;IACL,CAAC;IAEM,OAAO,CAAC,YAA0B,EAAE,OAA8B;QACrE,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,oCAAoC,OAAO,CAAC,GAAG,CAAC,KAAK,kBAAkB,OAAO,EAAE,CAAC,CAAC;QACnH,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC/C,CAAC;IACM,WAAW,CAAC,YAA0B,EAAE,OAAkC;QAC7E,YAAY,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,mBAAmB,OAAO,CAAC,MAAM,eAAe,CAAC,CAAC;QACnF,OAAO,sBAAa,CAAC,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,aAAa;IAC9E,CAAC;;AArYL,4EAsYC"}
@@ -0,0 +1,25 @@
1
+ import { AgentContext, BaseRecord, BaseRecordConstructor, Query, QueryOptions, StorageService } from "@credo-ts/core";
2
+ import { AccountController } from "@nmshd/transport";
3
+ import { OwnIdentityAttribute } from "../../attributes";
4
+ import { AttributesController } from "../../attributes/AttributesController";
5
+ import { KeyStorage } from "./KeyStorage";
6
+ export declare class EnmeshedStorageService<T extends BaseRecord> implements StorageService<T> {
7
+ private readonly accountController;
8
+ private readonly attributeController;
9
+ private readonly keyStorage;
10
+ storage: Map<string, T>;
11
+ supportsCursorPagination: boolean;
12
+ constructor(accountController: AccountController, attributeController: AttributesController, keyStorage: KeyStorage);
13
+ save(_agentContext: AgentContext, record: T): Promise<void>;
14
+ saveWithDisplay(agentContext: AgentContext, value: string | Record<string, any>, type: string, displayInformation?: Record<string, any>[]): Promise<OwnIdentityAttribute>;
15
+ update(_agentContext: AgentContext, _record: T): Promise<void>;
16
+ delete(_agentContext: AgentContext, _record: T): Promise<void>;
17
+ deleteById(_agentContext: AgentContext, _recordClass: BaseRecordConstructor<T>, _id: string): Promise<void>;
18
+ getById(_agentContext: AgentContext, _recordClass: BaseRecordConstructor<T>, id: string): Promise<T>;
19
+ getAll(_agentContext: AgentContext, recordClass: BaseRecordConstructor<T>): Promise<T[]>;
20
+ private recordTypeToCredentialType;
21
+ findByQuery(agentContext: AgentContext, recordClass: BaseRecordConstructor<T>, query: Query<T>, queryOptions?: QueryOptions): Promise<T[]>;
22
+ private matchesQuery;
23
+ }
24
+ export declare function decodeRecord(type: string, encoded: string | Record<string, any>): BaseRecord<any, any>;
25
+ //# 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,EAIrB,KAAK,EACL,YAAY,EAEZ,cAAc,EAEjB,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAC7E,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAE1C,qBACa,sBAAsB,CAAC,CAAC,SAAS,UAAU,CAAE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0BAA0B;IAarB,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;IAoBvJ,OAAO,CAAC,YAAY;CAQvB;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,UAAU,CAAC,GAAG,EAAE,GAAG,CAAC,CAWtG"}
@@ -0,0 +1,139 @@
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
+ exports.decodeRecord = decodeRecord;
14
+ const core_1 = require("@credo-ts/core");
15
+ const content_1 = require("@nmshd/content");
16
+ const transport_1 = require("@nmshd/transport");
17
+ const AttributesController_1 = require("../../attributes/AttributesController");
18
+ const KeyStorage_1 = require("./KeyStorage");
19
+ let EnmeshedStorageService = class EnmeshedStorageService {
20
+ constructor(accountController, attributeController, keyStorage) {
21
+ this.accountController = accountController;
22
+ this.attributeController = attributeController;
23
+ this.keyStorage = keyStorage;
24
+ this.storage = new Map();
25
+ this.supportsCursorPagination = false;
26
+ }
27
+ save(_agentContext, record) {
28
+ if (record.id !== "STORAGE_VERSION_RECORD_ID" && record.type !== "DidRecord") {
29
+ throw new Error("Only storage of STORAGE_VERSION_RECORD_ID and DidRecord implemented because others previously not needed");
30
+ }
31
+ this.storage.set(record.id, record);
32
+ return Promise.resolve();
33
+ }
34
+ async saveWithDisplay(agentContext, value, type, displayInformation) {
35
+ const owner = this.accountController.identity.address;
36
+ const identityAttribute = content_1.IdentityAttribute.from({
37
+ value: {
38
+ "@type": "VerifiableCredential",
39
+ value: value,
40
+ type: type,
41
+ displayInformation: displayInformation
42
+ },
43
+ owner: owner
44
+ });
45
+ const result = await this.attributeController.createOwnIdentityAttribute({
46
+ content: identityAttribute
47
+ });
48
+ agentContext.config.logger.debug(`Saved record: ${JSON.stringify(result)}`);
49
+ return await Promise.resolve(result);
50
+ }
51
+ update(_agentContext, _record) {
52
+ throw new Error("Storage update not implemented because previously not needed");
53
+ }
54
+ delete(_agentContext, _record) {
55
+ throw new Error("Storage delete not implemented because previously not needed");
56
+ }
57
+ deleteById(_agentContext, _recordClass, _id) {
58
+ throw new Error("Storage delete not implemented because previously not needed");
59
+ }
60
+ getById(_agentContext, _recordClass, id) {
61
+ const record = this.storage.get(id);
62
+ if (!record)
63
+ throw new Error(`Record with id ${id} not found`);
64
+ return Promise.resolve(record);
65
+ }
66
+ async getAll(_agentContext, recordClass) {
67
+ // so far only encountered in the credential context
68
+ const recordType = recordClass.type;
69
+ const correspondingCredentialType = this.recordTypeToCredentialType(recordType);
70
+ const attributes = await this.attributeController.getLocalAttributes({
71
+ "@type": "OwnIdentityAttribute",
72
+ "content.value.@type": "VerifiableCredential",
73
+ "content.value.type": correspondingCredentialType
74
+ });
75
+ return attributes.map((attribute) => {
76
+ const attributeValue = attribute.content.value;
77
+ return decodeRecord(correspondingCredentialType, attributeValue.value);
78
+ });
79
+ }
80
+ recordTypeToCredentialType(recordType) {
81
+ switch (recordType) {
82
+ case core_1.SdJwtVcRecord.name:
83
+ return core_1.ClaimFormat.SdJwtDc;
84
+ case core_1.MdocRecord.name:
85
+ return core_1.ClaimFormat.MsoMdoc;
86
+ case core_1.W3cCredentialRecord.name:
87
+ return core_1.ClaimFormat.SdJwtW3cVc;
88
+ default:
89
+ throw new Error("Record type not supported.");
90
+ }
91
+ }
92
+ async findByQuery(agentContext, recordClass, query, queryOptions) {
93
+ // so far only encountered in the credential context
94
+ agentContext.config.logger.debug(`Finding records by query ${JSON.stringify(query)} and options ${JSON.stringify(queryOptions)}`);
95
+ const records = [];
96
+ for (const record of await this.getAll(agentContext, recordClass)) {
97
+ if (this.matchesQuery(record, query)) {
98
+ records.push(record);
99
+ }
100
+ }
101
+ if (records.length === 0) {
102
+ // try to recover over local storage - temporary fix
103
+ for (const record of this.storage.values()) {
104
+ if (this.matchesQuery(record, query)) {
105
+ records.push(record);
106
+ }
107
+ }
108
+ }
109
+ return records;
110
+ }
111
+ matchesQuery(record, query) {
112
+ return Object.entries(query).every(([key, value]) => {
113
+ if (key === "$or") {
114
+ return value.some((subquery) => this.matchesQuery(record, subquery));
115
+ }
116
+ return record.getTags()[key] === value;
117
+ });
118
+ }
119
+ };
120
+ exports.EnmeshedStorageService = EnmeshedStorageService;
121
+ exports.EnmeshedStorageService = EnmeshedStorageService = __decorate([
122
+ (0, core_1.injectable)(),
123
+ __metadata("design:paramtypes", [transport_1.AccountController,
124
+ AttributesController_1.AttributesController,
125
+ KeyStorage_1.KeyStorage])
126
+ ], EnmeshedStorageService);
127
+ function decodeRecord(type, encoded) {
128
+ switch (type) {
129
+ case core_1.ClaimFormat.SdJwtDc:
130
+ return new core_1.SdJwtVcRecord({ credentialInstances: [{ compactSdJwtVc: encoded }] });
131
+ case core_1.ClaimFormat.MsoMdoc:
132
+ return new core_1.MdocRecord({ credentialInstances: [{ issuerSignedBase64Url: encoded }] });
133
+ case core_1.ClaimFormat.SdJwtW3cVc:
134
+ return new core_1.W3cCredentialRecord({ credentialInstances: [{ credential: encoded }] });
135
+ default:
136
+ throw new Error("Credential type not supported.");
137
+ }
138
+ }
139
+ //# sourceMappingURL=EnmeshedStorageService.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"EnmeshedStorageService.js","sourceRoot":"","sources":["../../../../src/modules/openid4vc/local/EnmeshedStorageService.ts"],"names":[],"mappings":";;;;;;;;;;;;AA2IA,oCAWC;AAtJD,yCAYwB;AACxB,4CAAyE;AACzE,gDAAqD;AAErD,gFAA6E;AAC7E,6CAA0C;AAGnC,IAAM,sBAAsB,GAA5B,MAAM,sBAAsB;IAG/B,YACqB,iBAAoC,EACpC,mBAAyC,EACzC,UAAsB;QAFtB,sBAAiB,GAAjB,iBAAiB,CAAmB;QACpC,wBAAmB,GAAnB,mBAAmB,CAAsB;QACzC,eAAU,GAAV,UAAU,CAAY;QALpC,YAAO,GAAmB,IAAI,GAAG,EAAa,CAAC;QAC/C,6BAAwB,GAAG,KAAK,CAAC;IAKrC,CAAC;IAEG,IAAI,CAAC,aAA2B,EAAE,MAAS;QAC9C,IAAI,MAAM,CAAC,EAAE,KAAK,2BAA2B,IAAI,MAAM,CAAC,IAAI,KAAK,WAAW,EAAE,CAAC;YAC3E,MAAM,IAAI,KAAK,CAAC,0GAA0G,CAAC,CAAC;QAChI,CAAC;QAED,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QACpC,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC;IAEM,KAAK,CAAC,eAAe,CACxB,YAA0B,EAC1B,KAAmC,EACnC,IAAY,EACZ,kBAA0C;QAE1C,MAAM,KAAK,GAAG,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,OAAO,CAAC;QACtD,MAAM,iBAAiB,GAAG,2BAAiB,CAAC,IAAI,CAAC;YAC7C,KAAK,EAAE;gBACH,OAAO,EAAE,sBAAsB;gBAC/B,KAAK,EAAE,KAAK;gBACZ,IAAI,EAAE,IAAI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iB,EAAE,CAAC,EAAE,CAAC,CAAC;QACnG,KAAK,kBAAW,CAAC,UAAU;YACvB,OAAO,IAAI,0BAAmB,CAAC,EAAE,mBAAmB,EAAE,CAAC,EAAE,UAAU,EAAE,OAAiB,EAAE,CAAC,EAAE,CAAC,CAAC;QACjG;YACI,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IAC1D,CAAC;AACL,CAAC"}
@@ -0,0 +1,43 @@
1
+ import { X509Module } from "@credo-ts/core";
2
+ import { OpenId4VciCredentialResponse, OpenId4VcModule, type OpenId4VciResolvedCredentialOffer, type OpenId4VpResolvedAuthorizationRequest } from "@credo-ts/openid4vc";
3
+ import { TokenContentVerifiablePresentation, VerifiableCredential } from "@nmshd/content";
4
+ import { AccountController } from "@nmshd/transport";
5
+ import { AttributesController, OwnIdentityAttribute } from "../../attributes";
6
+ import { BaseAgent } from "./BaseAgent";
7
+ import { KeyStorage } from "./KeyStorage";
8
+ import { OpenId4VciCredentialResponseJSON } from "./OpenId4VciCredentialResponseJSON";
9
+ declare function getOpenIdHolderModules(): {
10
+ readonly openid4vc: OpenId4VcModule<null, null>;
11
+ readonly x509: X509Module;
12
+ };
13
+ export declare class Holder extends BaseAgent<ReturnType<typeof getOpenIdHolderModules>> {
14
+ client: {
15
+ clientId: string;
16
+ redirectUri: string;
17
+ };
18
+ constructor(keyStorage: KeyStorage, accountController: AccountController, attributeController: AttributesController, fetchInstance: typeof fetch);
19
+ resolveCredentialOffer(credentialOffer: string): Promise<OpenId4VciResolvedCredentialOffer>;
20
+ requestCredentials(resolvedCredentialOffer: OpenId4VciResolvedCredentialOffer, credentialConfigurationIds: string[], access: {
21
+ accessToken: string;
22
+ } | {
23
+ pinCode?: string;
24
+ }): Promise<OpenId4VciCredentialResponse[]>;
25
+ storeCredentials(credentialResponses: OpenId4VciCredentialResponseJSON[]): Promise<OwnIdentityAttribute[]>;
26
+ resolveAuthorizationRequest(request: string): Promise<OpenId4VpResolvedAuthorizationRequest>;
27
+ acceptAuthorizationRequest(resolvedAuthorizationRequest: OpenId4VpResolvedAuthorizationRequest, credential: OwnIdentityAttribute): Promise<{
28
+ readonly status: number;
29
+ readonly body: string | Record<string, unknown> | null;
30
+ } | {
31
+ readonly status: number;
32
+ readonly body: Record<string, unknown>;
33
+ } | undefined>;
34
+ createPresentationTokenContent(credential: VerifiableCredential, nonce: string): Promise<TokenContentVerifiablePresentation>;
35
+ verifyPresentationTokenContent(tokenContent: TokenContentVerifiablePresentation, expectedNonce: string): Promise<{
36
+ isValid: boolean;
37
+ error?: Error;
38
+ }>;
39
+ exit(): Promise<void>;
40
+ restart(): Promise<void>;
41
+ }
42
+ export {};
43
+ //# sourceMappingURL=Holder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Holder.d.ts","sourceRoot":"","sources":["../../../../src/modules/openid4vc/local/Holder.ts"],"names":[],"mappings":"AAAA,OAAO,EAYH,UAAU,EACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,4BAA4B,EAAE,eAAe,EAAE,KAAK,iCAAiC,EAAE,KAAK,qCAAqC,EAAE,MAAM,qBAAqB,CAAC;AACxK,OAAO,EAAE,kCAAkC,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAC1F,OAAO,EAAE,iBAAiB,EAAE,MAAM,kBAAkB,CAAC;AACrD,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAExC,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,gCAAgC,EAAE,MAAM,oCAAoC,CAAC;AAEtF,iBAAS,sBAAsB;;;EAW9B;AAED,qBAAa,MAAO,SAAQ,SAAS,CAAC,UAAU,CAAC,OAAO,sBAAsB,CAAC,CAAC;IACrE,MAAM;;;MAGX;gBAEiB,UAAU,EAAE,UAAU,EAAE,iBAAiB,EAAE,iBAAiB,E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