@credo-ts/askar 0.7.2-pr-2704-20260925144545 → 0.7.2

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.
@@ -1 +1 @@
1
- {"version":3,"file":"AskarKeyManagementService.d.mts","names":[],"sources":["../../src/kms/AskarKeyManagementService.ts"],"mappings":";;qBA+Ba,qCAAqC,IAAI;kBAC7B;WACP;iBAED;UAQP;EAID,qBAAqB,eAAe,cAAc,WAAW,IAAI;EA2EjE,YAAY,eAAe,cAAc,SAAS,IAAI,wBAAwB,IAAI;EAI5E,aAAa,cAAc,cAAc,gBAAgB,QAAQ,IAAI;EAOrE,UAAU,YAAY,IAAI,eACrC,cAAc,cACd,SAAS,IAAI,oBAAoB,OAChC,QAAQ,IAAI,mBAAmB;EAsDrB,UAAU,cAAc,cAAc,SAAS,IAAI,sBAAsB;EAczE,UAAU,aAAa,IAAI,kBACtC,cAAc,cACd,SAAS,IAAI,oBAAoB,QAChC,QAAQ,IAAI,mBAAmB;EAqErB,KAAK,cAAc,cAAc,SAAS,IAAI,iBAAiB,QAAQ,IAAI;EAsC3E,OAAO,cAAc,cAAc,SAAS,IAAI,mBAAmB,QAAQ,IAAI;EAqE/E,QAAQ,cAAc,cAAc,SAAS,IAAI,oBAAoB,QAAQ,IAAI;EAyMjF,QAAQ,cAAc,cAAc,SAAS,IAAI,oBAAoB,QAAQ,IAAI;UAyNtF;UAYA;UASA;UAYA;UAeA;UAoBA;UAkBM;UAuBA;UASN"}
1
+ {"version":3,"file":"AskarKeyManagementService.d.mts","names":[],"sources":["../../src/kms/AskarKeyManagementService.ts"],"mappings":";;qBA0Ba,qCAAqC,IAAI;kBAC7B;WACP;iBAED;UAQP;EAID,qBAAqB,eAAe,cAAc,WAAW,IAAI;EA2EjE,YAAY,eAAe,cAAc,SAAS,IAAI,wBAAwB,IAAI;EAI5E,aAAa,cAAc,cAAc,gBAAgB,QAAQ,IAAI;EAOrE,UAAU,YAAY,IAAI,eACrC,cAAc,cACd,SAAS,IAAI,oBAAoB,OAChC,QAAQ,IAAI,mBAAmB;EAsDrB,UAAU,cAAc,cAAc,SAAS,IAAI,sBAAsB;EAczE,UAAU,aAAa,IAAI,kBACtC,cAAc,cACd,SAAS,IAAI,oBAAoB,QAChC,QAAQ,IAAI,mBAAmB;EAqErB,KAAK,cAAc,cAAc,SAAS,IAAI,iBAAiB,QAAQ,IAAI;EAsC3E,OAAO,cAAc,cAAc,SAAS,IAAI,mBAAmB,QAAQ,IAAI;EAqE/E,QAAQ,cAAc,cAAc,SAAS,IAAI,oBAAoB,QAAQ,IAAI;EA+KjF,QAAQ,cAAc,cAAc,SAAS,IAAI,oBAAoB,QAAQ,IAAI;UA2LtF;UAYA;UASA;UAYA;UAeA;UAoBA;UAkBM;UAuBA;UASN"}
@@ -4,8 +4,8 @@ import { jwkCrvToAskarAlg, jwkEncToAskarAlg } from "../utils/askarKeyTypes.mjs";
4
4
  import "../utils/index.mjs";
5
5
  import { AskarStoreManager } from "../AskarStoreManager.mjs";
6
6
  import { aeadDecrypt } from "./crypto/decrypt.mjs";
7
+ import { askarSupportedKeyAgreementAlgorithms, deriveDecryptionKey, deriveEncryptionKey } from "./crypto/deriveKey.mjs";
7
8
  import { aeadEncrypt } from "./crypto/encrypt.mjs";
8
- import { askarSupportedKeyAgreementAlgorithms, deriveDecryptionKey, deriveEncryptionKey, encryptEcdh1Pu } from "./crypto/deriveKey.mjs";
9
9
  import { askarSupportedHpkeAlgorithms, hpkeOpen, hpkeSeal } from "./crypto/hpke.mjs";
10
10
  import { randomBytes } from "./crypto/randomBytes.mjs";
11
11
  import { JsonEncoder, Kms, TypedArrayEncoder, utils } from "@credo-ts/core";
@@ -243,7 +243,7 @@ var AskarKeyManagementService = class AskarKeyManagementService {
243
243
  Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId);
244
244
  Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm);
245
245
  Kms.assertKeyAllowsDerive(privateJwk);
246
- if (key.keyAgreement.algorithm !== "ECDH-HSALSA20" && key.keyAgreement.algorithm !== "ECDH-1PU+A256KW") Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk);
246
+ if (key.keyAgreement.algorithm !== "ECDH-HSALSA20") Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk);
247
247
  }
248
248
  const recipientKey = this.keyFromJwk(agentContext, key.keyAgreement.externalPublicJwk);
249
249
  keysToFree.push(recipientKey);
@@ -269,26 +269,6 @@ var AskarKeyManagementService = class AskarKeyManagementService {
269
269
  };
270
270
  }
271
271
  if (!privateKey) throw new Kms.KeyManagementError("sender key is required for ECDH-ES key derivation.");
272
- if (key.keyAgreement.algorithm === "ECDH-1PU+A256KW" && privateKey.algorithm === KeyAlgorithm.Ed25519) {
273
- privateKey = privateKey.convertkey({ algorithm: KeyAlgorithm.X25519 });
274
- keysToFree.push(privateKey);
275
- }
276
- if (key.keyAgreement.algorithm === "ECDH-1PU+A256KW") {
277
- let ephemeralKey;
278
- if ("ephemeralKeyId" in key.keyAgreement && key.keyAgreement.ephemeralKeyId) {
279
- ephemeralKey = (await this.getKeyAsserted(agentContext, key.keyAgreement.ephemeralKeyId)).key;
280
- keysToFree.push(ephemeralKey);
281
- }
282
- return encryptEcdh1Pu({
283
- askar: this.getAskar(agentContext),
284
- keyAgreement: key.keyAgreement,
285
- encryption,
286
- senderKey: privateKey,
287
- recipientKey,
288
- data,
289
- ephemeralKey
290
- });
291
- }
292
272
  const { contentEncryptionKey, encryptedContentEncryptionKey } = deriveEncryptionKey({
293
273
  askar: this.getAskar(agentContext),
294
274
  encryption,
@@ -359,11 +339,10 @@ var AskarKeyManagementService = class AskarKeyManagementService {
359
339
  decryptionKey = this.keyFromSecretBytesAndEncryptionAlgorithm(TypedArrayEncoder.fromBase64Url(key.privateJwk.k), decryption.algorithm);
360
340
  keysToFree.push(decryptionKey);
361
341
  } else if (key.keyAgreement) {
362
- const externalPublicJwk = key.keyAgreement.algorithm === "ECDH-1PU+A256KW" || !("externalPublicJwk" in key.keyAgreement) ? void 0 : key.keyAgreement.externalPublicJwk;
363
342
  Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, askarSupportedKeyAgreementAlgorithms, this.backend);
364
- if (externalPublicJwk) {
365
- Kms.assertAllowedKeyDerivationAlgForKey(externalPublicJwk, key.keyAgreement.algorithm);
366
- Kms.assertKeyAllowsDerive(externalPublicJwk);
343
+ if (key.keyAgreement.externalPublicJwk) {
344
+ Kms.assertAllowedKeyDerivationAlgForKey(key.keyAgreement.externalPublicJwk, key.keyAgreement.algorithm);
345
+ Kms.assertKeyAllowsDerive(key.keyAgreement.externalPublicJwk);
367
346
  }
368
347
  let privateKey = (await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)).key;
369
348
  keysToFree.push(privateKey);
@@ -371,19 +350,9 @@ var AskarKeyManagementService = class AskarKeyManagementService {
371
350
  Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId);
372
351
  Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm);
373
352
  Kms.assertKeyAllowsDerive(privateJwk);
374
- const isEd25519Private = privateJwk.kty === "OKP" && privateJwk.crv === "Ed25519";
375
- if (externalPublicJwk && key.keyAgreement.algorithm !== "ECDH-HSALSA20" && !(key.keyAgreement.algorithm.startsWith("ECDH-ES") && isEd25519Private)) Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, externalPublicJwk);
376
- let senderKey;
377
- let ephemeralKey;
378
- if (key.keyAgreement.algorithm === "ECDH-1PU+A256KW") {
379
- const agreement = key.keyAgreement;
380
- ephemeralKey = this.keyFromJwk(agentContext, agreement.ephemeralPublicJwk);
381
- senderKey = this.keyFromJwk(agentContext, agreement.senderPublicJwk);
382
- keysToFree.push(ephemeralKey, senderKey);
383
- } else {
384
- senderKey = externalPublicJwk ? this.keyFromJwk(agentContext, externalPublicJwk) : void 0;
385
- if (senderKey) keysToFree.push(senderKey);
386
- }
353
+ if (key.keyAgreement.externalPublicJwk && key.keyAgreement.algorithm !== "ECDH-HSALSA20") Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk);
354
+ const senderKey = key.keyAgreement.externalPublicJwk ? this.keyFromJwk(agentContext, key.keyAgreement.externalPublicJwk) : void 0;
355
+ if (senderKey) keysToFree.push(senderKey);
387
356
  if (key.keyAgreement.algorithm === "ECDH-HSALSA20" || decryption.algorithm === "XSALSA20-POLY1305") {
388
357
  if (decryption.algorithm !== "XSALSA20-POLY1305" || key.keyAgreement.algorithm !== "ECDH-HSALSA20") throw new Kms.KeyManagementAlgorithmNotSupportedError(`key agreement algorithm '${key.keyAgreement.algorithm}' with encryption algorithm '${decryption.algorithm}'`, this.backend);
389
358
  if (privateKey.algorithm === KeyAlgorithm.Ed25519) {
@@ -403,17 +372,12 @@ var AskarKeyManagementService = class AskarKeyManagementService {
403
372
  })) };
404
373
  }
405
374
  if (!senderKey) throw new Kms.KeyManagementError("sender key is required for ECDH-ES key derivation.");
406
- if ((key.keyAgreement.algorithm === "ECDH-1PU+A256KW" || key.keyAgreement.algorithm === "ECDH-ES+A256KW" || key.keyAgreement.algorithm === "ECDH-ES+A128KW" || key.keyAgreement.algorithm === "ECDH-ES") && privateKey.algorithm === KeyAlgorithm.Ed25519) {
407
- privateKey = privateKey.convertkey({ algorithm: KeyAlgorithm.X25519 });
408
- keysToFree.push(privateKey);
409
- }
410
375
  const { contentEncryptionKey } = deriveDecryptionKey({
411
376
  askar: this.getAskar(agentContext),
412
377
  decryption,
413
378
  keyAgreement: key.keyAgreement,
414
379
  recipientKey: privateKey,
415
- senderKey,
416
- ephemeralKey
380
+ senderKey
417
381
  });
418
382
  decryptionKey = contentEncryptionKey;
419
383
  keysToFree.push(contentEncryptionKey);
@@ -1 +1 @@
1
- {"version":3,"file":"AskarKeyManagementService.mjs","names":[],"sources":["../../src/kms/AskarKeyManagementService.ts"],"sourcesContent":["import { type AgentContext, JsonEncoder, Kms, TypedArrayEncoder, utils } from '@credo-ts/core'\nimport type { JwkProps, KeyEntryObject, Session } from '@openwallet-foundation/askar-shared'\nimport {\n CryptoBox,\n Jwk,\n Key,\n KeyAlgorithm,\n KeyEntryList,\n SignatureAlgorithm,\n} from '@openwallet-foundation/askar-shared'\nimport { AskarModuleConfig } from '../AskarModuleConfig'\nimport { AskarStoreManager } from '../AskarStoreManager'\nimport { AskarErrorCode, isAskarError, jwkCrvToAskarAlg, jwkEncToAskarAlg } from '../utils'\nimport { aeadDecrypt } from './crypto/decrypt'\nimport {\n askarSupportedKeyAgreementAlgorithms,\n deriveDecryptionKey,\n deriveEncryptionKey,\n encryptEcdh1Pu,\n} from './crypto/deriveKey'\nimport { type AskarSupportedEncryptionOptions, aeadEncrypt } from './crypto/encrypt'\nimport { askarSupportedHpkeAlgorithms, hpkeOpen, hpkeSeal } from './crypto/hpke'\nimport { randomBytes } from './crypto/randomBytes'\n\nconst askarSymmetricKeyAlgorithms: KeyAlgorithm[] = Object.values(jwkEncToAskarAlg)\n\nconst askarSupportedEncryptionAlgorithms = [\n ...(Object.keys(jwkEncToAskarAlg) as Array<keyof typeof jwkEncToAskarAlg>),\n 'XSALSA20-POLY1305',\n] satisfies Array<Kms.KnownJwaContentEncryptionAlgorithm | Kms.KnownJwaKeyEncryptionAlgorithm>\n\nexport class AskarKeyManagementService implements Kms.KeyManagementService {\n public static readonly backend = 'askar'\n public readonly backend = AskarKeyManagementService.backend\n\n private static algToSigType: Partial<Record<Kms.KnownJwaSignatureAlgorithm, SignatureAlgorithm>> = {\n EdDSA: SignatureAlgorithm.EdDSA,\n Ed25519: SignatureAlgorithm.EdDSA,\n ES256K: SignatureAlgorithm.ES256K,\n ES256: SignatureAlgorithm.ES256,\n ES384: SignatureAlgorithm.ES384,\n }\n\n private withSession<Return>(agentContext: AgentContext, callback: (session: Session) => Return) {\n return agentContext.dependencyManager.resolve(AskarStoreManager).withSession(agentContext, callback)\n }\n\n public isOperationSupported(_agentContext: AgentContext, operation: Kms.KmsOperation): boolean {\n if (operation.operation === 'deleteKey') return true\n if (operation.operation === 'randomBytes') return true\n\n if (operation.operation === 'importKey') {\n if (operation.privateJwk.kty === 'EC' || operation.privateJwk.kty === 'OKP') {\n return jwkCrvToAskarAlg[operation.privateJwk.crv] !== undefined\n }\n\n // RSA/oct not supported\n return false\n }\n\n if (operation.operation === 'createKey') {\n if (operation.type.kty === 'EC' || operation.type.kty === 'OKP') {\n return jwkCrvToAskarAlg[operation.type.crv] !== undefined\n }\n\n if (operation.type.kty === 'oct') {\n if (operation.type.algorithm === 'C20P') return true\n\n // TODO: sync with the createKey code\n if (operation.type.algorithm === 'aes') {\n return [128, 256].includes(operation.type.length)\n }\n }\n\n return false\n }\n\n if (operation.operation === 'sign' || operation.operation === 'verify') {\n return AskarKeyManagementService.algToSigType[operation.algorithm] !== undefined\n }\n\n if (operation.operation === 'encrypt' || operation.operation === 'decrypt') {\n const encryption = operation.operation === 'encrypt' ? operation.encryption : operation.decryption\n\n // Askar can only perform key agreement with curves it supports. We also can't create the\n // ephemeral key for e.g. ECDH-ES if the curve is not supported.\n if (\n operation.keyAgreement &&\n 'externalPublicJwk' in operation.keyAgreement &&\n operation.keyAgreement.externalPublicJwk &&\n jwkCrvToAskarAlg[operation.keyAgreement.externalPublicJwk.crv] === undefined\n ) {\n return false\n }\n\n // HPKE is an integrated encryption mode: the suite fixes the AEAD, so the HPKE key agreement\n // algorithm is all there is to check.\n if (encryption.algorithm === 'HPKE') {\n if (!operation.keyAgreement || !Kms.isJwaHpkeAlgorithm(operation.keyAgreement.algorithm)) return false\n\n return askarSupportedHpkeAlgorithms.includes(\n operation.keyAgreement.algorithm as (typeof askarSupportedHpkeAlgorithms)[number]\n )\n }\n\n if (\n !askarSupportedEncryptionAlgorithms.includes(\n encryption.algorithm as (typeof askarSupportedEncryptionAlgorithms)[number]\n )\n ) {\n return false\n }\n if (!operation.keyAgreement) return true\n\n return askarSupportedKeyAgreementAlgorithms.includes(\n operation.keyAgreement.algorithm as (typeof askarSupportedKeyAgreementAlgorithms)[number]\n )\n }\n\n return false\n }\n\n public randomBytes(_agentContext: AgentContext, options: Kms.KmsRandomBytesOptions): Kms.KmsRandomBytesReturn {\n return randomBytes(options.length)\n }\n\n public async getPublicKey(agentContext: AgentContext, keyId: string): Promise<Kms.KmsJwkPublic | null> {\n const key = await this.fetchAskarKey(agentContext, keyId)\n if (!key) return null\n\n return this.publicJwkFromKey(agentContext, key.key, { kid: keyId })\n }\n\n public async importKey<Jwk extends Kms.KmsJwkPrivate>(\n agentContext: AgentContext,\n options: Kms.KmsImportKeyOptions<Jwk>\n ): Promise<Kms.KmsImportKeyReturn<Jwk>> {\n const { kid } = options.privateJwk\n\n const privateJwk = {\n ...options.privateJwk,\n kid: kid ?? utils.uuid(),\n }\n\n let key: Key | undefined\n try {\n if (privateJwk.kty === 'oct') {\n // TODO: we need to look at how to import symmetric keys, as we need the alg\n // Should we do the same as we do for createKey?\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `importing keys with kty '${privateJwk.kty}'`,\n this.backend\n )\n }\n if (privateJwk.kty === 'EC' || privateJwk.kty === 'OKP') {\n // Throws error if not supported\n this.assertAskarAlgForJwkCrv(privateJwk.kty, privateJwk.crv)\n\n key = Key.fromJwk({ jwk: Jwk.fromJson(privateJwk) })\n }\n\n const _key = key\n if (!_key) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty '${privateJwk.kty}'`, this.backend)\n }\n\n await this.withSession(agentContext, (session) => session.insertKey({ name: privateJwk.kid, key: _key }))\n const publicJwk = Kms.publicJwkFromPrivateJwk(privateJwk)\n\n return {\n keyId: privateJwk.kid,\n publicJwk: {\n ...publicJwk,\n kid: privateJwk.kid,\n },\n } as Kms.KmsImportKeyReturn<Jwk>\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n // Handle case where key already exists\n if (isAskarError(error, AskarErrorCode.Duplicate)) {\n throw new Kms.KeyManagementKeyExistsError(privateJwk.kid, this.backend)\n }\n\n throw new Kms.KeyManagementError('Error importing key', { cause: error })\n } finally {\n key?.handle.free()\n }\n }\n\n public async deleteKey(agentContext: AgentContext, options: Kms.KmsDeleteKeyOptions): Promise<boolean> {\n try {\n await this.withSession(agentContext, (session) => session.removeKey({ name: options.keyId }))\n return true\n } catch (error) {\n // Handle case where key does not exist\n if (isAskarError(error, AskarErrorCode.NotFound)) {\n return false\n }\n\n throw new Kms.KeyManagementError(`Error deleting key with id '${options.keyId}'`, { cause: error })\n }\n }\n\n public async createKey<Type extends Kms.KmsCreateKeyType>(\n agentContext: AgentContext,\n options: Kms.KmsCreateKeyOptions<Type>\n ): Promise<Kms.KmsCreateKeyReturn<Type>> {\n const { type, keyId } = options\n\n // FIXME: we should maybe keep the default keyId as publicKeyBase58 for a while for now, so it doesn't break\n // Or we need a way to query a key based on the public key?\n const kid = keyId ?? utils.uuid()\n let askarKey: Key | undefined\n try {\n if (type.kty === 'EC' || type.kty === 'OKP') {\n const keyAlg = this.assertAskarAlgForJwkCrv(type.kty, type.crv)\n askarKey = Key.generate(keyAlg)\n } else if (type.kty === 'oct') {\n // NOTE: askar is more specific in the intended use of the key at time of generation.\n // We either need to allow for this on a higher level (should be possible using `alg`)\n // but as the keys are the same it's ok to just always pick one and if used for another\n // purpose we can see them as the same.\n if (type.algorithm === 'aes') {\n const lengthToKeyAlg: Record<number, KeyAlgorithm | undefined> = {\n 128: KeyAlgorithm.AesA128Gcm,\n 256: KeyAlgorithm.AesA256Gcm,\n 512: KeyAlgorithm.AesA256CbcHs512,\n }\n\n const keyAlg = lengthToKeyAlg[type.length]\n if (!keyAlg) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `length '${type.length}' for kty '${type.kty}' with algorithm '${type.algorithm}'. Supported length values are ${Object.keys(lengthToKeyAlg).join(', ')}`,\n this.backend\n )\n }\n\n askarKey = Key.generate(keyAlg)\n } else if (type.algorithm === 'C20P') {\n // Both X and non-X variant can be used with the same key\n askarKey = Key.generate(KeyAlgorithm.Chacha20C20P)\n } else {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `algorithm '${type.algorithm}' for kty '${type.kty}'`,\n this.backend\n )\n }\n }\n\n const _key = askarKey\n if (!_key) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty '${type.kty}'`, this.backend)\n }\n\n const publicJwk = this.publicJwkFromKey(agentContext, _key, { kid }) as Kms.KmsCreateKeyReturn<Type>['publicJwk']\n await this.withSession(agentContext, (session) => session.insertKey({ name: kid, key: _key }))\n\n return {\n publicJwk,\n keyId: kid,\n } as Kms.KmsCreateKeyReturn<Type>\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n // Handle case where key already exists\n if (isAskarError(error, AskarErrorCode.Duplicate)) {\n throw new Kms.KeyManagementKeyExistsError(kid, this.backend)\n }\n\n throw new Kms.KeyManagementError('Error creating key', { cause: error })\n } finally {\n askarKey?.handle.free()\n }\n }\n\n public async sign(agentContext: AgentContext, options: Kms.KmsSignOptions): Promise<Kms.KmsSignReturn> {\n const { keyId, algorithm, data } = options\n\n // 1. Retrieve the key\n const key = await this.getKeyAsserted(agentContext, keyId)\n try {\n const sigType = this.assertedSigTypeForAlg(algorithm)\n // Askar has a bug with loading symmetric keys, but we shouldn't get here as I don't think askar\n // support signing with symmetric keys, and we don't support it (it will be caught by assertedSigTypeForAlg)\n if (!key.key) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`algorithm ${algorithm}`, this.backend)\n }\n\n // TODO: we should extend this with metadata properties (e.g. use, key_ops)\n const publicJwk = this.publicJwkFromKey(agentContext, key.key, { kid: keyId })\n const privateJwk = this.privateJwkFromKey(agentContext, key.key, { kid: keyId })\n\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(privateJwk, algorithm)\n Kms.assertKeyAllowsSign(publicJwk)\n\n // 3. Perform the signing operation\n const signature = key.key.signMessage({\n message: new Uint8Array(data),\n sigType,\n })\n\n return {\n signature: new Uint8Array(signature),\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error signing with key', { cause: error })\n } finally {\n key.key?.handle.free()\n }\n }\n\n public async verify(agentContext: AgentContext, options: Kms.KmsVerifyOptions): Promise<Kms.KmsVerifyReturn> {\n const { algorithm, data, signature, key: keyInput } = options\n\n // Get askar sig type (and handles unsupported alg)\n const sigType = this.assertedSigTypeForAlg(algorithm)\n\n // Retrieve the key\n let askarKey: Key | undefined\n\n try {\n if (keyInput.keyId) {\n askarKey = (await this.getKeyAsserted(agentContext, keyInput.keyId)).key\n } else if (keyInput.publicJwk?.kty === 'EC' || keyInput.publicJwk?.kty === 'OKP') {\n // Throws error if not supported\n this.assertAskarAlgForJwkCrv(keyInput.publicJwk.kty, keyInput.publicJwk.crv)\n\n askarKey = Key.fromJwk({ jwk: Jwk.fromJson(keyInput.publicJwk as JwkProps) })\n } else {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty ${keyInput.publicJwk?.kty}`, this.backend)\n }\n\n // Askar has a bug with loading symmetric keys, but we shouldn't get here as I don't think askar\n // support signing with symmetric keys, and we don't support it (it will be caught by assertedSigTypeForAlg)\n if (!askarKey) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`algorithm ${algorithm}`, this.backend)\n }\n\n const keyId = keyInput.keyId ?? keyInput.publicJwk?.kid\n const publicJwk = this.publicJwkFromKey(agentContext, askarKey, { kid: keyId })\n\n // For symmetric verificdation we need the private key\n if (publicJwk.kty === 'oct') {\n const privateJwk = this.privateJwkFromKey(agentContext, askarKey, { kid: keyId })\n\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(privateJwk, algorithm)\n Kms.assertKeyAllowsVerify(publicJwk)\n } else {\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(publicJwk, algorithm)\n Kms.assertKeyAllowsVerify(publicJwk)\n }\n\n // 4. Perform the verify operation\n const verified = askarKey.verifySignature({\n message: new Uint8Array(data),\n signature: new Uint8Array(signature),\n sigType,\n })\n if (verified) {\n return {\n verified: true,\n publicJwk: keyInput.keyId\n ? this.publicJwkFromKey(agentContext, askarKey, { kid: keyId })\n : (keyInput.publicJwk as Kms.KmsJwkPublic),\n }\n }\n\n return {\n verified: false,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error verifying with key', { cause: error })\n } finally {\n if (askarKey) askarKey.handle.free()\n }\n }\n\n public async encrypt(agentContext: AgentContext, options: Kms.KmsEncryptOptions): Promise<Kms.KmsEncryptReturn> {\n const { data, encryption, key } = options\n\n if (encryption.algorithm === 'HPKE') {\n if (!key.keyAgreement || !Kms.isKmsKeyAgreementEncryptHpke(key.keyAgreement)) {\n throw new Kms.KeyManagementError(\n `Encryption algorithm 'HPKE' can only be used with an integrated-encryption HPKE key agreement algorithm`\n )\n }\n\n const { keyAgreement } = key\n Kms.assertAllowedKeyDerivationAlgForKey(keyAgreement.externalPublicJwk, keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(keyAgreement.externalPublicJwk)\n\n try {\n return await hpkeSeal({\n algorithm: keyAgreement.algorithm,\n recipientPublicJwk: keyAgreement.externalPublicJwk,\n data,\n info: keyAgreement.info,\n aad: encryption.aad,\n })\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error encrypting with key', { cause: error })\n }\n }\n\n Kms.assertSupportedEncryptionAlgorithm(encryption, askarSupportedEncryptionAlgorithms, this.backend)\n\n const keysToFree: Key[] = []\n try {\n let encryptionKey: Key | undefined\n let encryptedKey: Kms.KmsEncryptedKey | undefined\n\n // TODO: we should check if the key allows this operation\n if (key.keyId) {\n encryptionKey = (await this.getKeyAsserted(agentContext, key.keyId)).key\n\n keysToFree.push(encryptionKey)\n } else if (key.privateJwk) {\n if (encryption.algorithm === 'XSALSA20-POLY1305') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption algorithm '${encryption.algorithm}' is only supported in combination with key agreement algorithm '${Kms.KnownJwaKeyAgreementAlgorithms.ECDH_HSALSA20}'`,\n this.backend\n )\n }\n encryptionKey = this.keyFromSecretBytesAndEncryptionAlgorithm(\n TypedArrayEncoder.fromBase64Url(key.privateJwk.k),\n encryption.algorithm\n )\n keysToFree.push(encryptionKey)\n } else if (key.keyAgreement) {\n Kms.assertAllowedKeyDerivationAlgForKey(key.keyAgreement.externalPublicJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(key.keyAgreement.externalPublicJwk)\n Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, askarSupportedKeyAgreementAlgorithms, this.backend)\n\n let privateKey = key.keyAgreement.keyId\n ? (await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)).key\n : undefined\n if (privateKey) keysToFree.push(privateKey)\n\n const privateJwk = privateKey ? this.privateJwkFromKey(agentContext, privateKey) : undefined\n if (privateJwk) {\n Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(privateJwk)\n\n // Special case: DIDComm v1/v2 often use X25519 for the recipient but Ed25519 for our key (we convert to X25519)\n if (key.keyAgreement.algorithm !== 'ECDH-HSALSA20' && key.keyAgreement.algorithm !== 'ECDH-1PU+A256KW') {\n Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk)\n }\n }\n\n const recipientKey = this.keyFromJwk(agentContext, key.keyAgreement.externalPublicJwk)\n keysToFree.push(recipientKey)\n\n // Special case to support DIDComm v1\n if (key.keyAgreement.algorithm === 'ECDH-HSALSA20' || encryption.algorithm === 'XSALSA20-POLY1305') {\n if (encryption.algorithm !== 'XSALSA20-POLY1305' || key.keyAgreement.algorithm !== 'ECDH-HSALSA20') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `key agreement algorithm '${key.keyAgreement.algorithm}' with encryption algorithm '${encryption.algorithm}'`,\n this.backend\n )\n }\n\n // anonymous encryption\n if (!privateKey) {\n return {\n encrypted: new Uint8Array(\n CryptoBox.seal({\n recipientKey,\n message: new Uint8Array(data),\n })\n ),\n }\n }\n\n // Special case. For DIDComm v1 we basically use the Ed25519 key also\n // for X25519 operations.\n if (privateKey.algorithm === KeyAlgorithm.Ed25519) {\n privateKey = privateKey.convertkey({ algorithm: KeyAlgorithm.X25519 })\n keysToFree.push(privateKey)\n }\n\n const nonce = new Uint8Array(CryptoBox.randomNonce())\n const encrypted = new Uint8Array(\n CryptoBox.cryptoBox({\n recipientKey,\n senderKey: privateKey,\n message: new Uint8Array(data),\n nonce,\n })\n )\n\n return {\n encrypted,\n iv: nonce,\n }\n }\n\n // This should not happen, but for TS\n if (!privateKey) {\n throw new Kms.KeyManagementError('sender key is required for ECDH-ES key derivation.')\n }\n\n // ECDH-1PU+A256KW (e.g. DIDComm v2) requires X25519; convert Ed25519 like DIDComm v1\n if (key.keyAgreement.algorithm === 'ECDH-1PU+A256KW' && privateKey.algorithm === KeyAlgorithm.Ed25519) {\n privateKey = privateKey.convertkey({ algorithm: KeyAlgorithm.X25519 })\n keysToFree.push(privateKey)\n }\n\n // ECDH-1PU+A256KW binds the JWE Authentication Tag into the KDF per draft-madden, so\n // content encryption has to happen before key derivation. encryptEcdh1Pu does the full\n // atomic flow (CEK gen, content encrypt, KEK derive with tag, CEK wrap) and short-circuits\n // the rest of this method.\n if (key.keyAgreement.algorithm === 'ECDH-1PU+A256KW') {\n let ephemeralKey: Key | undefined\n if ('ephemeralKeyId' in key.keyAgreement && key.keyAgreement.ephemeralKeyId) {\n ephemeralKey = (await this.getKeyAsserted(agentContext, key.keyAgreement.ephemeralKeyId)).key\n keysToFree.push(ephemeralKey)\n }\n return encryptEcdh1Pu({\n askar: this.getAskar(agentContext),\n keyAgreement: key.keyAgreement,\n encryption: encryption as AskarSupportedEncryptionOptions,\n senderKey: privateKey,\n recipientKey,\n data,\n ephemeralKey,\n })\n }\n\n const { contentEncryptionKey, encryptedContentEncryptionKey } = deriveEncryptionKey({\n askar: this.getAskar(agentContext),\n encryption,\n keyAgreement: key.keyAgreement,\n recipientKey,\n senderKey: privateKey,\n })\n\n encryptionKey = contentEncryptionKey\n keysToFree.push(contentEncryptionKey)\n encryptedKey = encryptedContentEncryptionKey\n } else {\n throw new Kms.KeyManagementError('Unexpected key parameter for encrypt')\n }\n\n if (encryption.algorithm === 'XSALSA20-POLY1305') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption algorithm '${encryption.algorithm}' can only be used with key agreement algorithm ECDH-HSALSA20`,\n this.backend\n )\n }\n\n const privateJwk = this.privateJwkFromKey(agentContext, encryptionKey)\n Kms.assertKeyAllowsDerive(privateJwk)\n Kms.assertAllowedEncryptionAlgForKey(privateJwk, encryption.algorithm)\n Kms.assertKeyAllowsEncrypt(privateJwk)\n\n const encrypted = aeadEncrypt({\n key: encryptionKey,\n data,\n encryption,\n })\n\n return {\n ...encrypted,\n encryptedKey,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error encrypting with key', { cause: error })\n } finally {\n // Clear all keys\n for (const key of keysToFree) {\n key.handle.free()\n }\n }\n }\n\n public async decrypt(agentContext: AgentContext, options: Kms.KmsDecryptOptions): Promise<Kms.KmsDecryptReturn> {\n const { encrypted, decryption, key } = options\n\n if (decryption.algorithm === 'HPKE') {\n if (!key.keyAgreement || !Kms.isKmsKeyAgreementDecryptHpke(key.keyAgreement)) {\n throw new Kms.KeyManagementError(\n `Decryption algorithm 'HPKE' can only be used with an integrated-encryption HPKE key agreement algorithm`\n )\n }\n\n const { keyAgreement } = key\n const recipientKey = (await this.getKeyAsserted(agentContext, keyAgreement.keyId)).key\n\n try {\n const recipientPublicJwk = this.publicJwkFromKey(agentContext, recipientKey)\n Kms.assertJwkAsymmetric(recipientPublicJwk, keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(recipientPublicJwk, keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(recipientPublicJwk)\n\n return {\n data: await hpkeOpen({\n algorithm: keyAgreement.algorithm,\n recipientKey,\n recipientPublicJwk,\n encapsulatedKey: keyAgreement.encapsulatedKey,\n encrypted,\n info: keyAgreement.info,\n aad: decryption.aad,\n }),\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error decrypting with key', { cause: error })\n } finally {\n recipientKey.handle.free()\n }\n }\n\n Kms.assertSupportedEncryptionAlgorithm(decryption, askarSupportedEncryptionAlgorithms, this.backend)\n\n const keysToFree: Key[] = []\n\n try {\n let decryptionKey: Key | undefined\n\n if (key.keyId) {\n decryptionKey = (await this.getKeyAsserted(agentContext, key.keyId)).key\n keysToFree.push(decryptionKey)\n } else if (key.privateJwk) {\n if (decryption.algorithm === 'XSALSA20-POLY1305') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `decryption algorithm '${decryption.algorithm}' is only supported in combination with key agreement algorithm '${Kms.KnownJwaKeyAgreementAlgorithms.ECDH_HSALSA20}'`,\n this.backend\n )\n }\n decryptionKey = this.keyFromSecretBytesAndEncryptionAlgorithm(\n TypedArrayEncoder.fromBase64Url(key.privateJwk.k),\n decryption.algorithm\n )\n keysToFree.push(decryptionKey)\n } else if (key.keyAgreement) {\n // ECDH-1PU+A256KW has ephemeralPublicJwk/senderPublicJwk instead of externalPublicJwk.\n const externalPublicJwk =\n key.keyAgreement.algorithm === 'ECDH-1PU+A256KW' || !('externalPublicJwk' in key.keyAgreement)\n ? undefined\n : key.keyAgreement.externalPublicJwk\n Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, askarSupportedKeyAgreementAlgorithms, this.backend)\n if (externalPublicJwk) {\n Kms.assertAllowedKeyDerivationAlgForKey(externalPublicJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(externalPublicJwk)\n }\n\n let privateKey = (await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)).key\n keysToFree.push(privateKey)\n\n const privateJwk = this.privateJwkFromKey(agentContext, privateKey)\n\n Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(privateJwk)\n\n // Special case: Ed25519 may be converted to X25519 for ECDH-HSALSA20 (DIDComm v1) and ECDH-ES (DIDComm v2 anoncrypt)\n const isEd25519Private = privateJwk.kty === 'OKP' && privateJwk.crv === 'Ed25519'\n if (\n externalPublicJwk &&\n key.keyAgreement.algorithm !== 'ECDH-HSALSA20' &&\n !(key.keyAgreement.algorithm.startsWith('ECDH-ES') && isEd25519Private)\n ) {\n Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, externalPublicJwk)\n }\n\n let senderKey: Key | undefined\n let ephemeralKey: Key | undefined\n if (key.keyAgreement.algorithm === 'ECDH-1PU+A256KW') {\n const agreement = key.keyAgreement\n ephemeralKey = this.keyFromJwk(agentContext, agreement.ephemeralPublicJwk)\n senderKey = this.keyFromJwk(agentContext, agreement.senderPublicJwk)\n keysToFree.push(ephemeralKey, senderKey)\n } else {\n senderKey = externalPublicJwk ? this.keyFromJwk(agentContext, externalPublicJwk) : undefined\n if (senderKey) keysToFree.push(senderKey)\n }\n\n // Special case to support DIDComm v1\n if (key.keyAgreement.algorithm === 'ECDH-HSALSA20' || decryption.algorithm === 'XSALSA20-POLY1305') {\n if (decryption.algorithm !== 'XSALSA20-POLY1305' || key.keyAgreement.algorithm !== 'ECDH-HSALSA20') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `key agreement algorithm '${key.keyAgreement.algorithm}' with encryption algorithm '${decryption.algorithm}'`,\n this.backend\n )\n }\n\n // Special case. For DIDComm v1 we basically use the Ed25519 key also\n // for X25519 operations.\n if (privateKey.algorithm === KeyAlgorithm.Ed25519) {\n privateKey = privateKey.convertkey({ algorithm: KeyAlgorithm.X25519 })\n keysToFree.push(privateKey)\n }\n\n if (!senderKey) {\n // anonymous encryption\n return {\n data: new Uint8Array(\n CryptoBox.sealOpen({\n recipientKey: privateKey,\n ciphertext: new Uint8Array(encrypted),\n })\n ),\n }\n }\n\n if (!decryption.iv) {\n throw new Kms.KeyManagementError(\n `Missing required 'iv' for key agreement algorithm ${key.keyAgreement.algorithm} and encryption algorithm ${decryption.algorithm} with sender key defined.`\n )\n }\n\n const decrypted = new Uint8Array(\n CryptoBox.open({\n recipientKey: privateKey,\n senderKey: senderKey,\n message: new Uint8Array(encrypted),\n nonce: new Uint8Array(decryption.iv),\n })\n )\n\n return {\n data: decrypted,\n }\n }\n\n // This should not happen, but for TS\n if (!senderKey) {\n throw new Kms.KeyManagementError('sender key is required for ECDH-ES key derivation.')\n }\n\n // ECDH-1PU+A256KW and ECDH-ES require X25519; convert Ed25519 like DIDComm v1\n // Note: ECDH-ES+A192KW is not in askarSupportedKeyAgreementAlgorithms so it's already\n // rejected by assertSupportedKeyAgreementAlgorithm above.\n if (\n (key.keyAgreement.algorithm === 'ECDH-1PU+A256KW' ||\n key.keyAgreement.algorithm === 'ECDH-ES+A256KW' ||\n key.keyAgreement.algorithm === 'ECDH-ES+A128KW' ||\n key.keyAgreement.algorithm === 'ECDH-ES') &&\n privateKey.algorithm === KeyAlgorithm.Ed25519\n ) {\n privateKey = privateKey.convertkey({ algorithm: KeyAlgorithm.X25519 })\n keysToFree.push(privateKey)\n }\n\n const { contentEncryptionKey } = deriveDecryptionKey({\n askar: this.getAskar(agentContext),\n decryption,\n keyAgreement: key.keyAgreement,\n recipientKey: privateKey,\n senderKey,\n ephemeralKey,\n })\n\n decryptionKey = contentEncryptionKey\n keysToFree.push(contentEncryptionKey)\n } else {\n throw new Kms.KeyManagementError('Unexpected key parameter for decrypt')\n }\n\n if (decryption.algorithm === 'XSALSA20-POLY1305') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption algorithm '${decryption.algorithm}' can only be used with key agreement algorithm ECDH-HSALSA20`,\n this.backend\n )\n }\n\n const privateJwk = this.privateJwkFromKey(agentContext, decryptionKey)\n Kms.assertKeyAllowsDerive(privateJwk)\n Kms.assertAllowedEncryptionAlgForKey(privateJwk, decryption.algorithm)\n Kms.assertKeyAllowsEncrypt(privateJwk)\n\n const decrypted = aeadDecrypt({\n key: decryptionKey,\n encrypted,\n decryption,\n })\n\n return {\n data: decrypted,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error decrypting with key', { cause: error })\n } finally {\n // Clear all keys\n for (const key of keysToFree) {\n key.handle.free()\n }\n }\n }\n\n private assertedSigTypeForAlg(algorithm: Kms.KnownJwaSignatureAlgorithm): SignatureAlgorithm {\n const sigType = AskarKeyManagementService.algToSigType[algorithm]\n if (!sigType) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `signing and verification with algorithm '${algorithm}'`,\n this.backend\n )\n }\n\n return sigType\n }\n\n private assertAskarAlgForJwkCrv(kty: string, crv: Kms.KmsJwkPublicEc['crv'] | Kms.KmsJwkPublicOkp['crv']) {\n const keyAlg = jwkCrvToAskarAlg[crv]\n if (!keyAlg) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`crv '${crv}' for kty '${kty}'`, this.backend)\n }\n\n return keyAlg\n }\n\n private keyFromJwk(agentContext: AgentContext, jwk: Kms.KmsJwkPrivate | Kms.KmsJwkPublic) {\n const key = new Key(\n this.getAskar(agentContext).keyFromJwk({\n // TODO: the JWK class in JS Askar wrapper is too limiting\n // so we use this method directly. should update it\n jwk: new Uint8Array(JsonEncoder.toUint8Array(jwk)) as unknown as Jwk,\n })\n )\n\n return key\n }\n\n private keyFromSecretBytesAndEncryptionAlgorithm(\n secretBytes: Uint8Array,\n algorithm: AskarSupportedEncryptionOptions['algorithm']\n ) {\n const askarEncryptionAlgorithm = jwkEncToAskarAlg[algorithm]\n if (!askarEncryptionAlgorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`JWA encryption algorithm '${algorithm}'`, 'askar')\n }\n\n return Key.fromSecretBytes({\n algorithm: askarEncryptionAlgorithm,\n secretKey: new Uint8Array(secretBytes),\n })\n }\n\n private publicJwkFromKey(agentContext: AgentContext, key: Key, partialJwkPublic?: Partial<Kms.KmsJwkPublic>) {\n // Askar has no public jwk representation for symmetric keys, and there's nothing\n // public about them besides the key type\n if (askarSymmetricKeyAlgorithms.includes(key.algorithm)) {\n return Kms.publicJwkFromPrivateJwk({ ...partialJwkPublic, kty: 'oct' } as Kms.KmsJwkPublic)\n }\n\n // TODO: the JWK class in JS Askar wrapper is too limiting\n // so we use this method directly. should update it\n // We extract alg, as Askar doesn't always use the same algs\n const { alg, ...jwkPublic } = JSON.parse(\n this.getAskar(agentContext).keyGetJwkPublic({\n localKeyHandle: key.handle,\n algorithm: key.algorithm,\n })\n )\n\n return Kms.publicJwkFromPrivateJwk({ ...partialJwkPublic, ...jwkPublic } as Kms.KmsJwkPublic)\n }\n\n private privateJwkFromKey(agentContext: AgentContext, key: Key, partialJwkPrivate?: Partial<Kms.KmsJwkPrivate>) {\n // TODO: once we support additional params we should add these here\n\n // TODO: the JWK class in JS Askar wrapper is too limiting\n // so we use this method directly. should update it\n // We extract alg, as Askar doesn't always use the same algs\n const { alg, ...jwkSecret } = JsonEncoder.fromUint8Array(\n this.getAskar(agentContext).keyGetJwkSecret({\n localKeyHandle: key.handle,\n })\n )\n\n return {\n ...partialJwkPrivate,\n ...jwkSecret,\n } as Kms.KmsJwkPrivate\n }\n\n private async fetchAskarKey(agentContext: AgentContext, keyId: string): Promise<KeyEntryObject | null> {\n return await this.withSession(agentContext, async (session) => {\n if (!session.handle) throw Error('Cannot fetch a key with a closed session')\n\n // Fetch the key from the session\n const handle = await this.getAskar(agentContext).sessionFetchKey({\n forUpdate: false,\n name: keyId,\n sessionHandle: session.handle,\n })\n if (!handle) return null\n\n // Get the key entry\n const keyEntryList = new KeyEntryList({ handle })\n const keyEntry = keyEntryList.getEntryByIndex(0)\n\n const keyEntryObject = keyEntry.toJson()\n keyEntryList.handle.free()\n\n return keyEntryObject\n })\n }\n\n private async getKeyAsserted(agentContext: AgentContext, keyId: string) {\n const storageKey = await this.fetchAskarKey(agentContext, keyId)\n if (!storageKey) {\n throw new Kms.KeyManagementKeyNotFoundError(keyId, [this.backend])\n }\n\n return storageKey\n }\n\n private getAskar(agentContext: AgentContext) {\n return agentContext.resolve(AskarModuleConfig).askar\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,MAAM,8BAA8C,OAAO,OAAO,gBAAgB;AAElF,MAAM,qCAAqC,CACzC,GAAI,OAAO,KAAK,gBAAgB,GAChC,mBACF;AAEA,IAAa,4BAAb,MAAa,0BAA8D;;EAEzE,KAAgB,UAAU,0BAA0B;;CAUpD,YAA4B,cAA4B,UAAwC;EAC9F,OAAO,aAAa,kBAAkB,QAAQ,iBAAiB,CAAC,CAAC,YAAY,cAAc,QAAQ;CACrG;CAEA,qBAA4B,eAA6B,WAAsC;EAC7F,IAAI,UAAU,cAAc,aAAa,OAAO;EAChD,IAAI,UAAU,cAAc,eAAe,OAAO;EAElD,IAAI,UAAU,cAAc,aAAa;GACvC,IAAI,UAAU,WAAW,QAAQ,QAAQ,UAAU,WAAW,QAAQ,OACpE,OAAO,iBAAiB,UAAU,WAAW,SAAS,KAAA;GAIxD,OAAO;EACT;EAEA,IAAI,UAAU,cAAc,aAAa;GACvC,IAAI,UAAU,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,OACxD,OAAO,iBAAiB,UAAU,KAAK,SAAS,KAAA;GAGlD,IAAI,UAAU,KAAK,QAAQ,OAAO;IAChC,IAAI,UAAU,KAAK,cAAc,QAAQ,OAAO;IAGhD,IAAI,UAAU,KAAK,cAAc,OAC/B,OAAO,CAAC,KAAK,GAAG,CAAC,CAAC,SAAS,UAAU,KAAK,MAAM;GAEpD;GAEA,OAAO;EACT;EAEA,IAAI,UAAU,cAAc,UAAU,UAAU,cAAc,UAC5D,OAAO,0BAA0B,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M,eAAe,IAAI,aAAa,EAAE,OAAO,CAAC;GAGhD,MAAM,iBAFW,aAAa,gBAAgB,CAEhB,CAAC,CAAC,OAAO;GACvC,aAAa,OAAO,KAAK;GAEzB,OAAO;EACT,CAAC;CACH;CAEA,MAAc,eAAe,cAA4B,OAAe;EACtE,MAAM,aAAa,MAAM,KAAK,cAAc,cAAc,KAAK;EAC/D,IAAI,CAAC,YACH,MAAM,IAAI,IAAI,8BAA8B,OAAO,CAAC,KAAK,OAAO,CAAC;EAGnE,OAAO;CACT;CAEA,SAAiB,cAA4B;EAC3C,OAAO,aAAa,QAAQ,iBAAiB,CAAC,CAAC;CACjD;AACF;AA13BE,0BAAuB,UAAU;AAGjC,0BAAe,eAAoF;CACjG,OAAO,mBAAmB;CAC1B,SAAS,mBAAmB;CAC5B,QAAQ,mBAAmB;CAC3B,OAAO,mBAAmB;CAC1B,OAAO,mBAAmB;AAC5B"}
1
+ {"version":3,"file":"AskarKeyManagementService.mjs","names":[],"sources":["../../src/kms/AskarKeyManagementService.ts"],"sourcesContent":["import { type AgentContext, JsonEncoder, Kms, TypedArrayEncoder, utils } from '@credo-ts/core'\nimport type { JwkProps, KeyEntryObject, Session } from '@openwallet-foundation/askar-shared'\nimport {\n CryptoBox,\n Jwk,\n Key,\n KeyAlgorithm,\n KeyEntryList,\n SignatureAlgorithm,\n} from '@openwallet-foundation/askar-shared'\nimport { AskarModuleConfig } from '../AskarModuleConfig'\nimport { AskarStoreManager } from '../AskarStoreManager'\nimport { AskarErrorCode, isAskarError, jwkCrvToAskarAlg, jwkEncToAskarAlg } from '../utils'\nimport { aeadDecrypt } from './crypto/decrypt'\nimport { askarSupportedKeyAgreementAlgorithms, deriveDecryptionKey, deriveEncryptionKey } from './crypto/deriveKey'\nimport { type AskarSupportedEncryptionOptions, aeadEncrypt } from './crypto/encrypt'\nimport { askarSupportedHpkeAlgorithms, hpkeOpen, hpkeSeal } from './crypto/hpke'\nimport { randomBytes } from './crypto/randomBytes'\n\nconst askarSymmetricKeyAlgorithms: KeyAlgorithm[] = Object.values(jwkEncToAskarAlg)\n\nconst askarSupportedEncryptionAlgorithms = [\n ...(Object.keys(jwkEncToAskarAlg) as Array<keyof typeof jwkEncToAskarAlg>),\n 'XSALSA20-POLY1305',\n] satisfies Array<Kms.KnownJwaContentEncryptionAlgorithm | Kms.KnownJwaKeyEncryptionAlgorithm>\n\nexport class AskarKeyManagementService implements Kms.KeyManagementService {\n public static readonly backend = 'askar'\n public readonly backend = AskarKeyManagementService.backend\n\n private static algToSigType: Partial<Record<Kms.KnownJwaSignatureAlgorithm, SignatureAlgorithm>> = {\n EdDSA: SignatureAlgorithm.EdDSA,\n Ed25519: SignatureAlgorithm.EdDSA,\n ES256K: SignatureAlgorithm.ES256K,\n ES256: SignatureAlgorithm.ES256,\n ES384: SignatureAlgorithm.ES384,\n }\n\n private withSession<Return>(agentContext: AgentContext, callback: (session: Session) => Return) {\n return agentContext.dependencyManager.resolve(AskarStoreManager).withSession(agentContext, callback)\n }\n\n public isOperationSupported(_agentContext: AgentContext, operation: Kms.KmsOperation): boolean {\n if (operation.operation === 'deleteKey') return true\n if (operation.operation === 'randomBytes') return true\n\n if (operation.operation === 'importKey') {\n if (operation.privateJwk.kty === 'EC' || operation.privateJwk.kty === 'OKP') {\n return jwkCrvToAskarAlg[operation.privateJwk.crv] !== undefined\n }\n\n // RSA/oct not supported\n return false\n }\n\n if (operation.operation === 'createKey') {\n if (operation.type.kty === 'EC' || operation.type.kty === 'OKP') {\n return jwkCrvToAskarAlg[operation.type.crv] !== undefined\n }\n\n if (operation.type.kty === 'oct') {\n if (operation.type.algorithm === 'C20P') return true\n\n // TODO: sync with the createKey code\n if (operation.type.algorithm === 'aes') {\n return [128, 256].includes(operation.type.length)\n }\n }\n\n return false\n }\n\n if (operation.operation === 'sign' || operation.operation === 'verify') {\n return AskarKeyManagementService.algToSigType[operation.algorithm] !== undefined\n }\n\n if (operation.operation === 'encrypt' || operation.operation === 'decrypt') {\n const encryption = operation.operation === 'encrypt' ? operation.encryption : operation.decryption\n\n // Askar can only perform key agreement with curves it supports. We also can't create the\n // ephemeral key for e.g. ECDH-ES if the curve is not supported.\n if (\n operation.keyAgreement &&\n 'externalPublicJwk' in operation.keyAgreement &&\n operation.keyAgreement.externalPublicJwk &&\n jwkCrvToAskarAlg[operation.keyAgreement.externalPublicJwk.crv] === undefined\n ) {\n return false\n }\n\n // HPKE is an integrated encryption mode: the suite fixes the AEAD, so the HPKE key agreement\n // algorithm is all there is to check.\n if (encryption.algorithm === 'HPKE') {\n if (!operation.keyAgreement || !Kms.isJwaHpkeAlgorithm(operation.keyAgreement.algorithm)) return false\n\n return askarSupportedHpkeAlgorithms.includes(\n operation.keyAgreement.algorithm as (typeof askarSupportedHpkeAlgorithms)[number]\n )\n }\n\n if (\n !askarSupportedEncryptionAlgorithms.includes(\n encryption.algorithm as (typeof askarSupportedEncryptionAlgorithms)[number]\n )\n ) {\n return false\n }\n if (!operation.keyAgreement) return true\n\n return askarSupportedKeyAgreementAlgorithms.includes(\n operation.keyAgreement.algorithm as (typeof askarSupportedKeyAgreementAlgorithms)[number]\n )\n }\n\n return false\n }\n\n public randomBytes(_agentContext: AgentContext, options: Kms.KmsRandomBytesOptions): Kms.KmsRandomBytesReturn {\n return randomBytes(options.length)\n }\n\n public async getPublicKey(agentContext: AgentContext, keyId: string): Promise<Kms.KmsJwkPublic | null> {\n const key = await this.fetchAskarKey(agentContext, keyId)\n if (!key) return null\n\n return this.publicJwkFromKey(agentContext, key.key, { kid: keyId })\n }\n\n public async importKey<Jwk extends Kms.KmsJwkPrivate>(\n agentContext: AgentContext,\n options: Kms.KmsImportKeyOptions<Jwk>\n ): Promise<Kms.KmsImportKeyReturn<Jwk>> {\n const { kid } = options.privateJwk\n\n const privateJwk = {\n ...options.privateJwk,\n kid: kid ?? utils.uuid(),\n }\n\n let key: Key | undefined\n try {\n if (privateJwk.kty === 'oct') {\n // TODO: we need to look at how to import symmetric keys, as we need the alg\n // Should we do the same as we do for createKey?\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `importing keys with kty '${privateJwk.kty}'`,\n this.backend\n )\n }\n if (privateJwk.kty === 'EC' || privateJwk.kty === 'OKP') {\n // Throws error if not supported\n this.assertAskarAlgForJwkCrv(privateJwk.kty, privateJwk.crv)\n\n key = Key.fromJwk({ jwk: Jwk.fromJson(privateJwk) })\n }\n\n const _key = key\n if (!_key) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty '${privateJwk.kty}'`, this.backend)\n }\n\n await this.withSession(agentContext, (session) => session.insertKey({ name: privateJwk.kid, key: _key }))\n const publicJwk = Kms.publicJwkFromPrivateJwk(privateJwk)\n\n return {\n keyId: privateJwk.kid,\n publicJwk: {\n ...publicJwk,\n kid: privateJwk.kid,\n },\n } as Kms.KmsImportKeyReturn<Jwk>\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n // Handle case where key already exists\n if (isAskarError(error, AskarErrorCode.Duplicate)) {\n throw new Kms.KeyManagementKeyExistsError(privateJwk.kid, this.backend)\n }\n\n throw new Kms.KeyManagementError('Error importing key', { cause: error })\n } finally {\n key?.handle.free()\n }\n }\n\n public async deleteKey(agentContext: AgentContext, options: Kms.KmsDeleteKeyOptions): Promise<boolean> {\n try {\n await this.withSession(agentContext, (session) => session.removeKey({ name: options.keyId }))\n return true\n } catch (error) {\n // Handle case where key does not exist\n if (isAskarError(error, AskarErrorCode.NotFound)) {\n return false\n }\n\n throw new Kms.KeyManagementError(`Error deleting key with id '${options.keyId}'`, { cause: error })\n }\n }\n\n public async createKey<Type extends Kms.KmsCreateKeyType>(\n agentContext: AgentContext,\n options: Kms.KmsCreateKeyOptions<Type>\n ): Promise<Kms.KmsCreateKeyReturn<Type>> {\n const { type, keyId } = options\n\n // FIXME: we should maybe keep the default keyId as publicKeyBase58 for a while for now, so it doesn't break\n // Or we need a way to query a key based on the public key?\n const kid = keyId ?? utils.uuid()\n let askarKey: Key | undefined\n try {\n if (type.kty === 'EC' || type.kty === 'OKP') {\n const keyAlg = this.assertAskarAlgForJwkCrv(type.kty, type.crv)\n askarKey = Key.generate(keyAlg)\n } else if (type.kty === 'oct') {\n // NOTE: askar is more specific in the intended use of the key at time of generation.\n // We either need to allow for this on a higher level (should be possible using `alg`)\n // but as the keys are the same it's ok to just always pick one and if used for another\n // purpose we can see them as the same.\n if (type.algorithm === 'aes') {\n const lengthToKeyAlg: Record<number, KeyAlgorithm | undefined> = {\n 128: KeyAlgorithm.AesA128Gcm,\n 256: KeyAlgorithm.AesA256Gcm,\n 512: KeyAlgorithm.AesA256CbcHs512,\n }\n\n const keyAlg = lengthToKeyAlg[type.length]\n if (!keyAlg) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `length '${type.length}' for kty '${type.kty}' with algorithm '${type.algorithm}'. Supported length values are ${Object.keys(lengthToKeyAlg).join(', ')}`,\n this.backend\n )\n }\n\n askarKey = Key.generate(keyAlg)\n } else if (type.algorithm === 'C20P') {\n // Both X and non-X variant can be used with the same key\n askarKey = Key.generate(KeyAlgorithm.Chacha20C20P)\n } else {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `algorithm '${type.algorithm}' for kty '${type.kty}'`,\n this.backend\n )\n }\n }\n\n const _key = askarKey\n if (!_key) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty '${type.kty}'`, this.backend)\n }\n\n const publicJwk = this.publicJwkFromKey(agentContext, _key, { kid }) as Kms.KmsCreateKeyReturn<Type>['publicJwk']\n await this.withSession(agentContext, (session) => session.insertKey({ name: kid, key: _key }))\n\n return {\n publicJwk,\n keyId: kid,\n } as Kms.KmsCreateKeyReturn<Type>\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n\n // Handle case where key already exists\n if (isAskarError(error, AskarErrorCode.Duplicate)) {\n throw new Kms.KeyManagementKeyExistsError(kid, this.backend)\n }\n\n throw new Kms.KeyManagementError('Error creating key', { cause: error })\n } finally {\n askarKey?.handle.free()\n }\n }\n\n public async sign(agentContext: AgentContext, options: Kms.KmsSignOptions): Promise<Kms.KmsSignReturn> {\n const { keyId, algorithm, data } = options\n\n // 1. Retrieve the key\n const key = await this.getKeyAsserted(agentContext, keyId)\n try {\n const sigType = this.assertedSigTypeForAlg(algorithm)\n // Askar has a bug with loading symmetric keys, but we shouldn't get here as I don't think askar\n // support signing with symmetric keys, and we don't support it (it will be caught by assertedSigTypeForAlg)\n if (!key.key) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`algorithm ${algorithm}`, this.backend)\n }\n\n // TODO: we should extend this with metadata properties (e.g. use, key_ops)\n const publicJwk = this.publicJwkFromKey(agentContext, key.key, { kid: keyId })\n const privateJwk = this.privateJwkFromKey(agentContext, key.key, { kid: keyId })\n\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(privateJwk, algorithm)\n Kms.assertKeyAllowsSign(publicJwk)\n\n // 3. Perform the signing operation\n const signature = key.key.signMessage({\n message: new Uint8Array(data),\n sigType,\n })\n\n return {\n signature: new Uint8Array(signature),\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error signing with key', { cause: error })\n } finally {\n key.key?.handle.free()\n }\n }\n\n public async verify(agentContext: AgentContext, options: Kms.KmsVerifyOptions): Promise<Kms.KmsVerifyReturn> {\n const { algorithm, data, signature, key: keyInput } = options\n\n // Get askar sig type (and handles unsupported alg)\n const sigType = this.assertedSigTypeForAlg(algorithm)\n\n // Retrieve the key\n let askarKey: Key | undefined\n\n try {\n if (keyInput.keyId) {\n askarKey = (await this.getKeyAsserted(agentContext, keyInput.keyId)).key\n } else if (keyInput.publicJwk?.kty === 'EC' || keyInput.publicJwk?.kty === 'OKP') {\n // Throws error if not supported\n this.assertAskarAlgForJwkCrv(keyInput.publicJwk.kty, keyInput.publicJwk.crv)\n\n askarKey = Key.fromJwk({ jwk: Jwk.fromJson(keyInput.publicJwk as JwkProps) })\n } else {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`kty ${keyInput.publicJwk?.kty}`, this.backend)\n }\n\n // Askar has a bug with loading symmetric keys, but we shouldn't get here as I don't think askar\n // support signing with symmetric keys, and we don't support it (it will be caught by assertedSigTypeForAlg)\n if (!askarKey) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`algorithm ${algorithm}`, this.backend)\n }\n\n const keyId = keyInput.keyId ?? keyInput.publicJwk?.kid\n const publicJwk = this.publicJwkFromKey(agentContext, askarKey, { kid: keyId })\n\n // For symmetric verificdation we need the private key\n if (publicJwk.kty === 'oct') {\n const privateJwk = this.privateJwkFromKey(agentContext, askarKey, { kid: keyId })\n\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(privateJwk, algorithm)\n Kms.assertKeyAllowsVerify(publicJwk)\n } else {\n // 2. Validate alg and use for key\n Kms.assertAllowedSigningAlgForKey(publicJwk, algorithm)\n Kms.assertKeyAllowsVerify(publicJwk)\n }\n\n // 4. Perform the verify operation\n const verified = askarKey.verifySignature({\n message: new Uint8Array(data),\n signature: new Uint8Array(signature),\n sigType,\n })\n if (verified) {\n return {\n verified: true,\n publicJwk: keyInput.keyId\n ? this.publicJwkFromKey(agentContext, askarKey, { kid: keyId })\n : (keyInput.publicJwk as Kms.KmsJwkPublic),\n }\n }\n\n return {\n verified: false,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error verifying with key', { cause: error })\n } finally {\n if (askarKey) askarKey.handle.free()\n }\n }\n\n public async encrypt(agentContext: AgentContext, options: Kms.KmsEncryptOptions): Promise<Kms.KmsEncryptReturn> {\n const { data, encryption, key } = options\n\n if (encryption.algorithm === 'HPKE') {\n if (!key.keyAgreement || !Kms.isKmsKeyAgreementEncryptHpke(key.keyAgreement)) {\n throw new Kms.KeyManagementError(\n `Encryption algorithm 'HPKE' can only be used with an integrated-encryption HPKE key agreement algorithm`\n )\n }\n\n const { keyAgreement } = key\n Kms.assertAllowedKeyDerivationAlgForKey(keyAgreement.externalPublicJwk, keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(keyAgreement.externalPublicJwk)\n\n try {\n return await hpkeSeal({\n algorithm: keyAgreement.algorithm,\n recipientPublicJwk: keyAgreement.externalPublicJwk,\n data,\n info: keyAgreement.info,\n aad: encryption.aad,\n })\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error encrypting with key', { cause: error })\n }\n }\n\n Kms.assertSupportedEncryptionAlgorithm(encryption, askarSupportedEncryptionAlgorithms, this.backend)\n\n const keysToFree: Key[] = []\n try {\n let encryptionKey: Key | undefined\n let encryptedKey: Kms.KmsEncryptedKey | undefined\n\n // TODO: we should check if the key allows this operation\n if (key.keyId) {\n encryptionKey = (await this.getKeyAsserted(agentContext, key.keyId)).key\n\n keysToFree.push(encryptionKey)\n } else if (key.privateJwk) {\n if (encryption.algorithm === 'XSALSA20-POLY1305') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption algorithm '${encryption.algorithm}' is only supported in combination with key agreement algorithm '${Kms.KnownJwaKeyAgreementAlgorithms.ECDH_HSALSA20}'`,\n this.backend\n )\n }\n encryptionKey = this.keyFromSecretBytesAndEncryptionAlgorithm(\n TypedArrayEncoder.fromBase64Url(key.privateJwk.k),\n encryption.algorithm\n )\n keysToFree.push(encryptionKey)\n } else if (key.keyAgreement) {\n Kms.assertAllowedKeyDerivationAlgForKey(key.keyAgreement.externalPublicJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(key.keyAgreement.externalPublicJwk)\n Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, askarSupportedKeyAgreementAlgorithms, this.backend)\n\n let privateKey = key.keyAgreement.keyId\n ? (await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)).key\n : undefined\n if (privateKey) keysToFree.push(privateKey)\n\n const privateJwk = privateKey ? this.privateJwkFromKey(agentContext, privateKey) : undefined\n if (privateJwk) {\n Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(privateJwk)\n\n // Special case, for DIDComm v1 we often use an X25519 for the external key\n // but we use an Ed25519 for our key\n if (key.keyAgreement.algorithm !== 'ECDH-HSALSA20') {\n Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk)\n }\n }\n\n const recipientKey = this.keyFromJwk(agentContext, key.keyAgreement.externalPublicJwk)\n keysToFree.push(recipientKey)\n\n // Special case to support DIDComm v1\n if (key.keyAgreement.algorithm === 'ECDH-HSALSA20' || encryption.algorithm === 'XSALSA20-POLY1305') {\n if (encryption.algorithm !== 'XSALSA20-POLY1305' || key.keyAgreement.algorithm !== 'ECDH-HSALSA20') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `key agreement algorithm '${key.keyAgreement.algorithm}' with encryption algorithm '${encryption.algorithm}'`,\n this.backend\n )\n }\n\n // anonymous encryption\n if (!privateKey) {\n return {\n encrypted: new Uint8Array(\n CryptoBox.seal({\n recipientKey,\n message: new Uint8Array(data),\n })\n ),\n }\n }\n\n // Special case. For DIDComm v1 we basically use the Ed25519 key also\n // for X25519 operations.\n if (privateKey.algorithm === KeyAlgorithm.Ed25519) {\n privateKey = privateKey.convertkey({ algorithm: KeyAlgorithm.X25519 })\n keysToFree.push(privateKey)\n }\n\n const nonce = new Uint8Array(CryptoBox.randomNonce())\n const encrypted = new Uint8Array(\n CryptoBox.cryptoBox({\n recipientKey,\n senderKey: privateKey,\n message: new Uint8Array(data),\n nonce,\n })\n )\n\n return {\n encrypted,\n iv: nonce,\n }\n }\n\n // This should not happen, but for TS\n if (!privateKey) {\n throw new Kms.KeyManagementError('sender key is required for ECDH-ES key derivation.')\n }\n\n const { contentEncryptionKey, encryptedContentEncryptionKey } = deriveEncryptionKey({\n askar: this.getAskar(agentContext),\n encryption,\n keyAgreement: key.keyAgreement,\n recipientKey,\n senderKey: privateKey,\n })\n\n encryptionKey = contentEncryptionKey\n keysToFree.push(contentEncryptionKey)\n encryptedKey = encryptedContentEncryptionKey\n } else {\n throw new Kms.KeyManagementError('Unexpected key parameter for encrypt')\n }\n\n if (encryption.algorithm === 'XSALSA20-POLY1305') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption algorithm '${encryption.algorithm}' can only be used with key agreement algorithm ECDH-HSALSA20`,\n this.backend\n )\n }\n\n const privateJwk = this.privateJwkFromKey(agentContext, encryptionKey)\n Kms.assertKeyAllowsDerive(privateJwk)\n Kms.assertAllowedEncryptionAlgForKey(privateJwk, encryption.algorithm)\n Kms.assertKeyAllowsEncrypt(privateJwk)\n\n const encrypted = aeadEncrypt({\n key: encryptionKey,\n data,\n encryption,\n })\n\n return {\n ...encrypted,\n encryptedKey,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error encrypting with key', { cause: error })\n } finally {\n // Clear all keys\n for (const key of keysToFree) {\n key.handle.free()\n }\n }\n }\n\n public async decrypt(agentContext: AgentContext, options: Kms.KmsDecryptOptions): Promise<Kms.KmsDecryptReturn> {\n const { encrypted, decryption, key } = options\n\n if (decryption.algorithm === 'HPKE') {\n if (!key.keyAgreement || !Kms.isKmsKeyAgreementDecryptHpke(key.keyAgreement)) {\n throw new Kms.KeyManagementError(\n `Decryption algorithm 'HPKE' can only be used with an integrated-encryption HPKE key agreement algorithm`\n )\n }\n\n const { keyAgreement } = key\n const recipientKey = (await this.getKeyAsserted(agentContext, keyAgreement.keyId)).key\n\n try {\n const recipientPublicJwk = this.publicJwkFromKey(agentContext, recipientKey)\n Kms.assertJwkAsymmetric(recipientPublicJwk, keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(recipientPublicJwk, keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(recipientPublicJwk)\n\n return {\n data: await hpkeOpen({\n algorithm: keyAgreement.algorithm,\n recipientKey,\n recipientPublicJwk,\n encapsulatedKey: keyAgreement.encapsulatedKey,\n encrypted,\n info: keyAgreement.info,\n aad: decryption.aad,\n }),\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error decrypting with key', { cause: error })\n } finally {\n recipientKey.handle.free()\n }\n }\n\n Kms.assertSupportedEncryptionAlgorithm(decryption, askarSupportedEncryptionAlgorithms, this.backend)\n\n const keysToFree: Key[] = []\n\n try {\n let decryptionKey: Key | undefined\n\n if (key.keyId) {\n decryptionKey = (await this.getKeyAsserted(agentContext, key.keyId)).key\n keysToFree.push(decryptionKey)\n } else if (key.privateJwk) {\n if (decryption.algorithm === 'XSALSA20-POLY1305') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `decryption algorithm '${decryption.algorithm}' is only supported in combination with key agreement algorithm '${Kms.KnownJwaKeyAgreementAlgorithms.ECDH_HSALSA20}'`,\n this.backend\n )\n }\n decryptionKey = this.keyFromSecretBytesAndEncryptionAlgorithm(\n TypedArrayEncoder.fromBase64Url(key.privateJwk.k),\n decryption.algorithm\n )\n keysToFree.push(decryptionKey)\n } else if (key.keyAgreement) {\n // Narrows away the integrated-encryption HPKE algorithms, which are handled above\n Kms.assertSupportedKeyAgreementAlgorithm(key.keyAgreement, askarSupportedKeyAgreementAlgorithms, this.backend)\n\n if (key.keyAgreement.externalPublicJwk) {\n Kms.assertAllowedKeyDerivationAlgForKey(key.keyAgreement.externalPublicJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(key.keyAgreement.externalPublicJwk)\n }\n\n let privateKey = (await this.getKeyAsserted(agentContext, key.keyAgreement.keyId)).key\n keysToFree.push(privateKey)\n\n const privateJwk = this.privateJwkFromKey(agentContext, privateKey)\n\n Kms.assertJwkAsymmetric(privateJwk, key.keyAgreement.keyId)\n Kms.assertAllowedKeyDerivationAlgForKey(privateJwk, key.keyAgreement.algorithm)\n Kms.assertKeyAllowsDerive(privateJwk)\n\n // Special case for ECDH-HSALSA as we can have mismatch between keys because of DIDComm v1\n if (key.keyAgreement.externalPublicJwk && key.keyAgreement.algorithm !== 'ECDH-HSALSA20') {\n Kms.assertAsymmetricJwkKeyTypeMatches(privateJwk, key.keyAgreement.externalPublicJwk)\n }\n\n const senderKey = key.keyAgreement.externalPublicJwk\n ? this.keyFromJwk(agentContext, key.keyAgreement.externalPublicJwk)\n : undefined\n if (senderKey) keysToFree.push(senderKey)\n\n // Special case to support DIDComm v1\n if (key.keyAgreement.algorithm === 'ECDH-HSALSA20' || decryption.algorithm === 'XSALSA20-POLY1305') {\n if (decryption.algorithm !== 'XSALSA20-POLY1305' || key.keyAgreement.algorithm !== 'ECDH-HSALSA20') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `key agreement algorithm '${key.keyAgreement.algorithm}' with encryption algorithm '${decryption.algorithm}'`,\n this.backend\n )\n }\n\n // Special case. For DIDComm v1 we basically use the Ed25519 key also\n // for X25519 operations.\n if (privateKey.algorithm === KeyAlgorithm.Ed25519) {\n privateKey = privateKey.convertkey({ algorithm: KeyAlgorithm.X25519 })\n keysToFree.push(privateKey)\n }\n\n if (!senderKey) {\n // anonymous encryption\n return {\n data: new Uint8Array(\n CryptoBox.sealOpen({\n recipientKey: privateKey,\n ciphertext: new Uint8Array(encrypted),\n })\n ),\n }\n }\n\n if (!decryption.iv) {\n throw new Kms.KeyManagementError(\n `Missing required 'iv' for key agreement algorithm ${key.keyAgreement.algorithm} and encryption algorithm ${decryption.algorithm} with sender key defined.`\n )\n }\n\n const decrypted = new Uint8Array(\n CryptoBox.open({\n recipientKey: privateKey,\n senderKey: senderKey,\n message: new Uint8Array(encrypted),\n nonce: new Uint8Array(decryption.iv),\n })\n )\n\n return {\n data: decrypted,\n }\n }\n\n // This should not happen, but for TS\n if (!senderKey) {\n throw new Kms.KeyManagementError('sender key is required for ECDH-ES key derivation.')\n }\n\n const { contentEncryptionKey } = deriveDecryptionKey({\n askar: this.getAskar(agentContext),\n decryption,\n keyAgreement: key.keyAgreement,\n recipientKey: privateKey,\n senderKey,\n })\n\n decryptionKey = contentEncryptionKey\n keysToFree.push(contentEncryptionKey)\n } else {\n throw new Kms.KeyManagementError('Unexpected key parameter for decrypt')\n }\n\n if (decryption.algorithm === 'XSALSA20-POLY1305') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption algorithm '${decryption.algorithm}' can only be used with key agreement algorithm ECDH-HSALSA20`,\n this.backend\n )\n }\n\n const privateJwk = this.privateJwkFromKey(agentContext, decryptionKey)\n Kms.assertKeyAllowsDerive(privateJwk)\n Kms.assertAllowedEncryptionAlgForKey(privateJwk, decryption.algorithm)\n Kms.assertKeyAllowsEncrypt(privateJwk)\n\n const decrypted = aeadDecrypt({\n key: decryptionKey,\n encrypted,\n decryption,\n })\n\n return {\n data: decrypted,\n }\n } catch (error) {\n if (error instanceof Kms.KeyManagementError) throw error\n throw new Kms.KeyManagementError('Error decrypting with key', { cause: error })\n } finally {\n // Clear all keys\n for (const key of keysToFree) {\n key.handle.free()\n }\n }\n }\n\n private assertedSigTypeForAlg(algorithm: Kms.KnownJwaSignatureAlgorithm): SignatureAlgorithm {\n const sigType = AskarKeyManagementService.algToSigType[algorithm]\n if (!sigType) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `signing and verification with algorithm '${algorithm}'`,\n this.backend\n )\n }\n\n return sigType\n }\n\n private assertAskarAlgForJwkCrv(kty: string, crv: Kms.KmsJwkPublicEc['crv'] | Kms.KmsJwkPublicOkp['crv']) {\n const keyAlg = jwkCrvToAskarAlg[crv]\n if (!keyAlg) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`crv '${crv}' for kty '${kty}'`, this.backend)\n }\n\n return keyAlg\n }\n\n private keyFromJwk(agentContext: AgentContext, jwk: Kms.KmsJwkPrivate | Kms.KmsJwkPublic) {\n const key = new Key(\n this.getAskar(agentContext).keyFromJwk({\n // TODO: the JWK class in JS Askar wrapper is too limiting\n // so we use this method directly. should update it\n jwk: new Uint8Array(JsonEncoder.toUint8Array(jwk)) as unknown as Jwk,\n })\n )\n\n return key\n }\n\n private keyFromSecretBytesAndEncryptionAlgorithm(\n secretBytes: Uint8Array,\n algorithm: AskarSupportedEncryptionOptions['algorithm']\n ) {\n const askarEncryptionAlgorithm = jwkEncToAskarAlg[algorithm]\n if (!askarEncryptionAlgorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(`JWA encryption algorithm '${algorithm}'`, 'askar')\n }\n\n return Key.fromSecretBytes({\n algorithm: askarEncryptionAlgorithm,\n secretKey: new Uint8Array(secretBytes),\n })\n }\n\n private publicJwkFromKey(agentContext: AgentContext, key: Key, partialJwkPublic?: Partial<Kms.KmsJwkPublic>) {\n // Askar has no public jwk representation for symmetric keys, and there's nothing\n // public about them besides the key type\n if (askarSymmetricKeyAlgorithms.includes(key.algorithm)) {\n return Kms.publicJwkFromPrivateJwk({ ...partialJwkPublic, kty: 'oct' } as Kms.KmsJwkPublic)\n }\n\n // TODO: the JWK class in JS Askar wrapper is too limiting\n // so we use this method directly. should update it\n // We extract alg, as Askar doesn't always use the same algs\n const { alg, ...jwkPublic } = JSON.parse(\n this.getAskar(agentContext).keyGetJwkPublic({\n localKeyHandle: key.handle,\n algorithm: key.algorithm,\n })\n )\n\n return Kms.publicJwkFromPrivateJwk({ ...partialJwkPublic, ...jwkPublic } as Kms.KmsJwkPublic)\n }\n\n private privateJwkFromKey(agentContext: AgentContext, key: Key, partialJwkPrivate?: Partial<Kms.KmsJwkPrivate>) {\n // TODO: once we support additional params we should add these here\n\n // TODO: the JWK class in JS Askar wrapper is too limiting\n // so we use this method directly. should update it\n // We extract alg, as Askar doesn't always use the same algs\n const { alg, ...jwkSecret } = JsonEncoder.fromUint8Array(\n this.getAskar(agentContext).keyGetJwkSecret({\n localKeyHandle: key.handle,\n })\n )\n\n return {\n ...partialJwkPrivate,\n ...jwkSecret,\n } as Kms.KmsJwkPrivate\n }\n\n private async fetchAskarKey(agentContext: AgentContext, keyId: string): Promise<KeyEntryObject | null> {\n return await this.withSession(agentContext, async (session) => {\n if (!session.handle) throw Error('Cannot fetch a key with a closed session')\n\n // Fetch the key from the session\n const handle = await this.getAskar(agentContext).sessionFetchKey({\n forUpdate: false,\n name: keyId,\n sessionHandle: session.handle,\n })\n if (!handle) return null\n\n // Get the key entry\n const keyEntryList = new KeyEntryList({ handle })\n const keyEntry = keyEntryList.getEntryByIndex(0)\n\n const keyEntryObject = keyEntry.toJson()\n keyEntryList.handle.free()\n\n return keyEntryObject\n })\n }\n\n private async getKeyAsserted(agentContext: AgentContext, keyId: string) {\n const storageKey = await this.fetchAskarKey(agentContext, keyId)\n if (!storageKey) {\n throw new Kms.KeyManagementKeyNotFoundError(keyId, [this.backend])\n }\n\n return storageKey\n }\n\n private getAskar(agentContext: AgentContext) {\n return agentContext.resolve(AskarModuleConfig).askar\n }\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,MAAM,8BAA8C,OAAO,OAAO,gBAAgB;AAElF,MAAM,qCAAqC,CACzC,GAAI,OAAO,KAAK,gBAAgB,GAChC,mBACF;AAEA,IAAa,4BAAb,MAAa,0BAA8D;;EAEzE,KAAgB,UAAU,0BAA0B;;CAUpD,YAA4B,cAA4B,UAAwC;EAC9F,OAAO,aAAa,kBAAkB,QAAQ,iBAAiB,CAAC,CAAC,YAAY,cAAc,QAAQ;CACrG;CAEA,qBAA4B,eAA6B,WAAsC;EAC7F,IAAI,UAAU,cAAc,aAAa,OAAO;EAChD,IAAI,UAAU,cAAc,eAAe,OAAO;EAElD,IAAI,UAAU,cAAc,aAAa;GACvC,IAAI,UAAU,WAAW,QAAQ,QAAQ,UAAU,WAAW,QAAQ,OACpE,OAAO,iBAAiB,UAAU,WAAW,SAAS,KAAA;GAIxD,OAAO;EACT;EAEA,IAAI,UAAU,cAAc,aAAa;GACvC,IAAI,UAAU,KAAK,QAAQ,QAAQ,UAAU,KAAK,QAAQ,OACxD,OAAO,iBAAiB,UAAU,KAAK,SAAS,KAAA;GAGlD,IAAI,UAAU,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AAc,YAAY,eACxC,KAAK,SAAS,YAAY,CAAC,CAAC,gBAAgB,EAC1C,gBAAgB,IAAI,OACtB,CAAC,CACH;EAEA,OAAO;GACL,GAAG;GACH,GAAG;EACL;CACF;CAEA,MAAc,cAAc,cAA4B,OAA+C;EACrG,OAAO,MAAM,KAAK,YAAY,cAAc,OAAO,YAAY;GAC7D,IAAI,CAAC,QAAQ,QAAQ,MAAM,MAAM,0CAA0C;GAG3E,MAAM,SAAS,MAAM,KAAK,SAAS,YAAY,CAAC,CAAC,gBAAgB;IAC/D,WAAW;IACX,MAAM;IACN,eAAe,QAAQ;GACzB,CAAC;GACD,IAAI,CAAC,QAAQ,OAAO;GAGpB,MAAM,eAAe,IAAI,aAAa,EAAE,OAAO,CAAC;GAGhD,MAAM,iBAFW,aAAa,gBAAgB,CAEhB,CAAC,CAAC,OAAO;GACvC,aAAa,OAAO,KAAK;GAEzB,OAAO;EACT,CAAC;CACH;CAEA,MAAc,eAAe,cAA4B,OAAe;EACtE,MAAM,aAAa,MAAM,KAAK,cAAc,cAAc,KAAK;EAC/D,IAAI,CAAC,YACH,MAAM,IAAI,IAAI,8BAA8B,OAAO,CAAC,KAAK,OAAO,CAAC;EAGnE,OAAO;CACT;CAEA,SAAiB,cAA4B;EAC3C,OAAO,aAAa,QAAQ,iBAAiB,CAAC,CAAC;CACjD;AACF;AAl0BE,0BAAuB,UAAU;AAGjC,0BAAe,eAAoF;CACjG,OAAO,mBAAmB;CAC1B,SAAS,mBAAmB;CAC5B,QAAQ,mBAAmB;CAC3B,OAAO,mBAAmB;CAC1B,OAAO,mBAAmB;AAC5B"}
@@ -1,83 +1,19 @@
1
1
  import { jwkEncToAskarAlg } from "../../utils/askarKeyTypes.mjs";
2
2
  import "../../utils/index.mjs";
3
- import { aeadEncrypt } from "./encrypt.mjs";
4
3
  import { Kms, TypedArrayEncoder } from "@credo-ts/core";
5
- import { Key, KeyAlgorithm } from "@openwallet-foundation/askar-shared";
4
+ import { Key } from "@openwallet-foundation/askar-shared";
6
5
  //#region src/kms/crypto/deriveKey.ts
7
6
  const askarSupportedKeyAgreementAlgorithms = [
8
7
  "ECDH-ES",
9
8
  "ECDH-ES+A128KW",
10
9
  "ECDH-ES+A256KW",
11
- "ECDH-1PU+A256KW",
12
10
  "ECDH-HSALSA20"
13
11
  ];
14
- /**
15
- * Full ECDH-1PU+A256KW encrypt flow per draft-madden-jose-ecdh-1pu-04 §2.3:
16
- * encrypt content with a fresh CEK first, then derive the KEK with the resulting JWE
17
- * Authentication Tag bound into SuppPubInfo, then wrap the CEK with that KEK. The KEK
18
- * cannot be derived before content encryption because it depends on the tag.
19
- */
20
- function encryptEcdh1Pu(options) {
21
- const { askar, keyAgreement, encryption, senderKey, recipientKey, data, ephemeralKey: providedEphemeralKey } = options;
22
- const supportedAlgorithms = [
23
- KeyAlgorithm.X25519,
24
- KeyAlgorithm.EcSecp256r1,
25
- KeyAlgorithm.EcSecp384r1
26
- ];
27
- if (!supportedAlgorithms.includes(senderKey.algorithm) || !supportedAlgorithms.includes(recipientKey.algorithm)) throw new Kms.KeyManagementAlgorithmNotSupportedError("ECDH-1PU+A256KW requires X25519, P-256, or P-384 sender and recipient keys", "askar");
28
- if (senderKey.algorithm !== recipientKey.algorithm) throw new Kms.KeyManagementAlgorithmNotSupportedError("ECDH-1PU+A256KW sender and recipient keys must be on the same curve", "askar");
29
- if (providedEphemeralKey && providedEphemeralKey.algorithm !== recipientKey.algorithm) throw new Kms.KeyManagementAlgorithmNotSupportedError("ECDH-1PU+A256KW ephemeral key must match the recipient curve", "askar");
30
- const askarEncryptionAlgorithm = jwkEncToAskarAlg[encryption.algorithm];
31
- if (!askarEncryptionAlgorithm) throw new Kms.KeyManagementAlgorithmNotSupportedError(`encryption with algorithm '${encryption.algorithm}'`, "askar");
32
- const ephemeralKey = providedEphemeralKey ?? Key.generate(recipientKey.algorithm);
33
- const ownsEphemeralKey = !providedEphemeralKey;
34
- const apu = keyAgreement.apu ? new Uint8Array(keyAgreement.apu) : new Uint8Array([]);
35
- const apv = keyAgreement.apv ? new Uint8Array(keyAgreement.apv) : new Uint8Array([]);
36
- const algId = TypedArrayEncoder.fromUtf8String("ECDH-1PU+A256KW");
37
- const contentEncryptionKey = Key.generate(askarEncryptionAlgorithm);
38
- let derivedKey;
39
- try {
40
- const aeadResult = aeadEncrypt({
41
- key: contentEncryptionKey,
42
- data,
43
- encryption
44
- });
45
- derivedKey = new Key(askar.keyDeriveEcdh1pu({
46
- algorithm: KeyAlgorithm.AesA256Kw,
47
- ephemeralKey,
48
- senderKey,
49
- recipientKey,
50
- algId,
51
- apu,
52
- apv,
53
- ccTag: aeadResult.tag,
54
- receive: false
55
- }));
56
- const wrappedKey = derivedKey.wrapKey({ other: contentEncryptionKey });
57
- const ephemeralPublicKey = ephemeralKey.jwkPublic;
58
- return {
59
- encrypted: aeadResult.encrypted,
60
- iv: aeadResult.iv,
61
- tag: aeadResult.tag,
62
- encryptedKey: {
63
- encrypted: new Uint8Array(wrappedKey.ciphertext),
64
- iv: wrappedKey.nonce ? new Uint8Array(wrappedKey.nonce) : void 0,
65
- tag: wrappedKey.tag ? new Uint8Array(wrappedKey.tag) : void 0,
66
- ephemeralPublicKey
67
- }
68
- };
69
- } finally {
70
- if (ownsEphemeralKey) ephemeralKey.handle.free();
71
- derivedKey?.handle.free();
72
- contentEncryptionKey.handle.free();
73
- }
74
- }
75
12
  function deriveEncryptionKey(options) {
76
13
  const { askar, keyAgreement, encryption, senderKey, recipientKey } = options;
77
14
  const askarEncryptionAlgorithm = jwkEncToAskarAlg[encryption.algorithm];
78
15
  if (!askarEncryptionAlgorithm) throw new Kms.KeyManagementAlgorithmNotSupportedError(`encryption with algorithm '${encryption.algorithm}'`, "askar");
79
16
  if (keyAgreement.algorithm === "ECDH-HSALSA20") throw new Kms.KeyManagementAlgorithmNotSupportedError(`derive key for algorithm '${keyAgreement.algorithm}' with encryption algorithm '${encryption.algorithm}'`, "askar");
80
- if (keyAgreement.algorithm === "ECDH-1PU+A256KW") throw new Kms.KeyManagementError("Use encryptEcdh1Pu for ECDH-1PU+A256KW; deriveEncryptionKey only handles ECDH-ES");
81
17
  const askarKeyWrappingAlgorithm = keyAgreement.algorithm !== "ECDH-ES" ? jwkEncToAskarAlg[keyAgreement.algorithm.replace("ECDH-ES+", "")] : void 0;
82
18
  const derivedKey = new Key(askar.keyDeriveEcdhEs({
83
19
  algId: TypedArrayEncoder.fromUtf8String(keyAgreement.algorithm === "ECDH-ES" ? encryption.algorithm : keyAgreement.algorithm),
@@ -113,21 +49,10 @@ function deriveEncryptionKey(options) {
113
49
  }
114
50
  }
115
51
  function deriveDecryptionKey(options) {
116
- const { askar, keyAgreement, decryption, senderKey, recipientKey, ephemeralKey } = options;
52
+ const { askar, keyAgreement, decryption, senderKey, recipientKey } = options;
117
53
  const askarEncryptionAlgorithm = jwkEncToAskarAlg[decryption.algorithm];
118
54
  if (!askarEncryptionAlgorithm) throw new Kms.KeyManagementAlgorithmNotSupportedError(`decryption with algorithm '${decryption.algorithm}'`, "askar");
119
55
  if (keyAgreement.algorithm === "ECDH-HSALSA20") throw new Kms.KeyManagementAlgorithmNotSupportedError(`derive key for algorithm '${keyAgreement.algorithm}' with encryption algorithm '${decryption.algorithm}'`, "askar");
120
- if (keyAgreement.algorithm === "ECDH-1PU+A256KW") {
121
- if (!ephemeralKey) throw new Kms.KeyManagementError("ECDH-1PU+A256KW decrypt requires ephemeralKey (ephemeral public key from JWE)");
122
- return deriveDecryptionKeyEcdh1Pu({
123
- askar,
124
- keyAgreement,
125
- decryption,
126
- ephemeralKey,
127
- senderKey,
128
- recipientKey
129
- });
130
- }
131
56
  const askarKeyWrappingAlgorithm = keyAgreement.algorithm !== "ECDH-ES" ? jwkEncToAskarAlg[keyAgreement.algorithm.replace("ECDH-ES+", "")] : void 0;
132
57
  const derivedKey = new Key(askar.keyDeriveEcdhEs({
133
58
  algId: TypedArrayEncoder.fromUtf8String(keyAgreement.algorithm === "ECDH-ES" ? decryption.algorithm : keyAgreement.algorithm),
@@ -155,44 +80,7 @@ function deriveDecryptionKey(options) {
155
80
  if (contentEncryptionKey) derivedKey.handle.free();
156
81
  }
157
82
  }
158
- function deriveDecryptionKeyEcdh1Pu(options) {
159
- const { askar, keyAgreement, decryption, ephemeralKey, senderKey, recipientKey } = options;
160
- if (![
161
- KeyAlgorithm.X25519,
162
- KeyAlgorithm.EcSecp256r1,
163
- KeyAlgorithm.EcSecp384r1
164
- ].includes(recipientKey.algorithm)) throw new Kms.KeyManagementAlgorithmNotSupportedError("ECDH-1PU+A256KW requires X25519, P-256, or P-384 recipient key", "askar");
165
- if (ephemeralKey.algorithm !== recipientKey.algorithm || senderKey.algorithm !== recipientKey.algorithm) throw new Kms.KeyManagementAlgorithmNotSupportedError("ECDH-1PU+A256KW sender, ephemeral, and recipient keys must be on the same curve", "askar");
166
- const askarEncryptionAlgorithm = jwkEncToAskarAlg[decryption.algorithm];
167
- if (!askarEncryptionAlgorithm) throw new Kms.KeyManagementAlgorithmNotSupportedError(`decryption with algorithm '${decryption.algorithm}'`, "askar");
168
- const apu = keyAgreement.apu ? new Uint8Array(keyAgreement.apu) : new Uint8Array([]);
169
- const apv = keyAgreement.apv ? new Uint8Array(keyAgreement.apv) : new Uint8Array([]);
170
- const algId = TypedArrayEncoder.fromUtf8String("ECDH-1PU+A256KW");
171
- const decryptionTag = "tag" in decryption ? decryption.tag : void 0;
172
- const ccTag = decryptionTag ? new Uint8Array(decryptionTag) : void 0;
173
- const derivedKey = new Key(askar.keyDeriveEcdh1pu({
174
- algorithm: KeyAlgorithm.AesA256Kw,
175
- ephemeralKey,
176
- senderKey,
177
- recipientKey,
178
- algId,
179
- apu,
180
- apv,
181
- ccTag,
182
- receive: true
183
- }));
184
- try {
185
- return { contentEncryptionKey: derivedKey.unwrapKey({
186
- ciphertext: new Uint8Array(keyAgreement.encryptedKey.encrypted),
187
- algorithm: askarEncryptionAlgorithm,
188
- nonce: keyAgreement.encryptedKey.iv ? new Uint8Array(keyAgreement.encryptedKey.iv) : void 0,
189
- tag: keyAgreement.encryptedKey.tag ? new Uint8Array(keyAgreement.encryptedKey.tag) : void 0
190
- }) };
191
- } finally {
192
- derivedKey.handle.free();
193
- }
194
- }
195
83
  //#endregion
196
- export { askarSupportedKeyAgreementAlgorithms, deriveDecryptionKey, deriveEncryptionKey, encryptEcdh1Pu };
84
+ export { askarSupportedKeyAgreementAlgorithms, deriveDecryptionKey, deriveEncryptionKey };
197
85
 
198
86
  //# sourceMappingURL=deriveKey.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"deriveKey.mjs","names":[],"sources":["../../../src/kms/crypto/deriveKey.ts"],"sourcesContent":["import { Kms, TypedArrayEncoder } from '@credo-ts/core'\nimport type { Askar } from '@openwallet-foundation/askar-shared'\nimport { Key, KeyAlgorithm } from '@openwallet-foundation/askar-shared'\nimport { jwkEncToAskarAlg } from '../../utils'\nimport { type AskarSupportedEncryptionOptions, aeadEncrypt } from './encrypt'\n\nexport const askarSupportedKeyAgreementAlgorithms = [\n 'ECDH-ES',\n 'ECDH-ES+A128KW',\n 'ECDH-ES+A256KW',\n 'ECDH-1PU+A256KW',\n 'ECDH-HSALSA20',\n] satisfies Kms.KnownJwaKeyAgreementAlgorithm[]\n\ntype AskarSupportedKeyAgreementEncryptOptions = Kms.KmsKeyAgreementEncryptOptions & {\n algorithm: (typeof askarSupportedKeyAgreementAlgorithms)[number]\n}\n\ntype AskarSupportedKeyAgreementDecryptOptions = Kms.KmsKeyAgreementDecryptOptions & {\n algorithm: (typeof askarSupportedKeyAgreementAlgorithms)[number]\n}\n\n/**\n * Full ECDH-1PU+A256KW encrypt flow per draft-madden-jose-ecdh-1pu-04 §2.3:\n * encrypt content with a fresh CEK first, then derive the KEK with the resulting JWE\n * Authentication Tag bound into SuppPubInfo, then wrap the CEK with that KEK. The KEK\n * cannot be derived before content encryption because it depends on the tag.\n */\nexport function encryptEcdh1Pu(options: {\n askar: Askar\n keyAgreement: AskarSupportedKeyAgreementEncryptOptions & { algorithm: 'ECDH-1PU+A256KW' }\n encryption: AskarSupportedEncryptionOptions\n senderKey: Key\n recipientKey: Key\n data: Uint8Array\n ephemeralKey?: Key\n}) {\n const { askar, keyAgreement, encryption, senderKey, recipientKey, data, ephemeralKey: providedEphemeralKey } = options\n\n const supportedAlgorithms: KeyAlgorithm[] = [KeyAlgorithm.X25519, KeyAlgorithm.EcSecp256r1, KeyAlgorithm.EcSecp384r1]\n if (!supportedAlgorithms.includes(senderKey.algorithm) || !supportedAlgorithms.includes(recipientKey.algorithm)) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n 'ECDH-1PU+A256KW requires X25519, P-256, or P-384 sender and recipient keys',\n 'askar'\n )\n }\n if (senderKey.algorithm !== recipientKey.algorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n 'ECDH-1PU+A256KW sender and recipient keys must be on the same curve',\n 'askar'\n )\n }\n if (providedEphemeralKey && providedEphemeralKey.algorithm !== recipientKey.algorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n 'ECDH-1PU+A256KW ephemeral key must match the recipient curve',\n 'askar'\n )\n }\n const askarEncryptionAlgorithm = jwkEncToAskarAlg[encryption.algorithm as keyof typeof jwkEncToAskarAlg]\n if (!askarEncryptionAlgorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption with algorithm '${encryption.algorithm}'`,\n 'askar'\n )\n }\n\n const ephemeralKey = providedEphemeralKey ?? Key.generate(recipientKey.algorithm)\n const ownsEphemeralKey = !providedEphemeralKey\n const apu = keyAgreement.apu ? new Uint8Array(keyAgreement.apu) : new Uint8Array([])\n const apv = keyAgreement.apv ? new Uint8Array(keyAgreement.apv) : new Uint8Array([])\n const algId = TypedArrayEncoder.fromUtf8String('ECDH-1PU+A256KW')\n\n const contentEncryptionKey = Key.generate(askarEncryptionAlgorithm)\n let derivedKey: Key | undefined\n try {\n const aeadResult = aeadEncrypt({ key: contentEncryptionKey, data, encryption })\n\n derivedKey = new Key(\n askar.keyDeriveEcdh1pu({\n algorithm: KeyAlgorithm.AesA256Kw,\n ephemeralKey,\n senderKey,\n recipientKey,\n algId,\n apu,\n apv,\n ccTag: aeadResult.tag,\n receive: false,\n })\n )\n const wrappedKey = derivedKey.wrapKey({ other: contentEncryptionKey })\n const ephemeralPublicKey = ephemeralKey.jwkPublic as Kms.KmsJwkPublicEcdh\n\n return {\n encrypted: aeadResult.encrypted,\n iv: aeadResult.iv,\n tag: aeadResult.tag,\n encryptedKey: {\n encrypted: new Uint8Array(wrappedKey.ciphertext),\n iv: wrappedKey.nonce ? new Uint8Array(wrappedKey.nonce) : undefined,\n tag: wrappedKey.tag ? new Uint8Array(wrappedKey.tag) : undefined,\n ephemeralPublicKey,\n } satisfies Kms.KmsEncryptedKey,\n }\n } finally {\n if (ownsEphemeralKey) ephemeralKey.handle.free()\n derivedKey?.handle.free()\n contentEncryptionKey.handle.free()\n }\n}\n\nexport function deriveEncryptionKey(options: {\n askar: Askar\n keyAgreement: AskarSupportedKeyAgreementEncryptOptions\n senderKey: Key\n recipientKey: Key\n encryption: Kms.KmsEncryptDataContentEncryption\n}) {\n const { askar, keyAgreement, encryption, senderKey, recipientKey } = options\n\n const askarEncryptionAlgorithm = jwkEncToAskarAlg[encryption.algorithm as keyof typeof jwkEncToAskarAlg]\n if (!askarEncryptionAlgorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption with algorithm '${encryption.algorithm}'`,\n 'askar'\n )\n }\n\n // This should be handled on a higher level as we only support combined key agreemnt + encryption\n if (keyAgreement.algorithm === 'ECDH-HSALSA20') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `derive key for algorithm '${keyAgreement.algorithm}' with encryption algorithm '${encryption.algorithm}'`,\n 'askar'\n )\n }\n\n // ECDH-1PU+A256KW requires the JWE Authentication Tag in the KDF, so it goes through encryptEcdh1Pu\n // which performs content encryption + key wrapping atomically. Callers that reach this dispatcher\n // with 1PU are programming errors.\n if (keyAgreement.algorithm === 'ECDH-1PU+A256KW') {\n throw new Kms.KeyManagementError('Use encryptEcdh1Pu for ECDH-1PU+A256KW; deriveEncryptionKey only handles ECDH-ES')\n }\n\n const askarKeyWrappingAlgorithm =\n keyAgreement.algorithm !== 'ECDH-ES'\n ? jwkEncToAskarAlg[keyAgreement.algorithm.replace('ECDH-ES+', '') as keyof typeof jwkEncToAskarAlg]\n : undefined\n\n const derivedKey = new Key(\n askar.keyDeriveEcdhEs({\n algId: TypedArrayEncoder.fromUtf8String(\n keyAgreement.algorithm === 'ECDH-ES' ? encryption.algorithm : keyAgreement.algorithm\n ),\n receive: false,\n apv: keyAgreement.apv ? new Uint8Array(keyAgreement.apv) : new Uint8Array([]),\n apu: keyAgreement.apu ? new Uint8Array(keyAgreement.apu) : new Uint8Array([]),\n algorithm: askarKeyWrappingAlgorithm ?? askarEncryptionAlgorithm,\n ephemeralKey: senderKey,\n recipientKey: recipientKey,\n })\n )\n let contentEncryptionKey: Key | undefined\n let encryptedContentEncryptionKey: Kms.KmsEncryptedKey | undefined\n try {\n // Key wrapping\n if (keyAgreement.algorithm !== 'ECDH-ES') {\n contentEncryptionKey = Key.generate(askarEncryptionAlgorithm)\n\n const wrappedKey = derivedKey.wrapKey({\n other: contentEncryptionKey,\n })\n encryptedContentEncryptionKey = {\n encrypted: new Uint8Array(wrappedKey.ciphertext),\n iv: new Uint8Array(wrappedKey.nonce),\n tag: new Uint8Array(wrappedKey.tag),\n }\n }\n\n return {\n contentEncryptionKey: contentEncryptionKey ?? derivedKey,\n encryptedContentEncryptionKey,\n }\n } catch (error) {\n if (contentEncryptionKey) {\n contentEncryptionKey.handle.free()\n }\n // We only free the derived key if there is no content encryption key\n // as in this case the derived key is already freed in the finally clause\n else {\n derivedKey.handle.free()\n }\n\n throw error\n } finally {\n // If there is a content encryption key, it means we can free the\n // derived key\n if (contentEncryptionKey) {\n derivedKey.handle.free()\n }\n }\n}\n\nexport function deriveDecryptionKey(options: {\n askar: Askar\n keyAgreement: AskarSupportedKeyAgreementDecryptOptions\n senderKey: Key\n recipientKey: Key\n decryption: Kms.KmsDecryptDataDecryption\n /** For ECDH-1PU+A256KW: ephemeral public key from the JWE header */\n ephemeralKey?: Key\n}) {\n const { askar, keyAgreement, decryption, senderKey, recipientKey, ephemeralKey } = options\n\n const askarEncryptionAlgorithm = jwkEncToAskarAlg[decryption.algorithm as keyof typeof jwkEncToAskarAlg]\n if (!askarEncryptionAlgorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `decryption with algorithm '${decryption.algorithm}'`,\n 'askar'\n )\n }\n\n if (keyAgreement.algorithm === 'ECDH-HSALSA20') {\n // This should be handled on a higher level as we only support combined key agreemnt + encryption\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `derive key for algorithm '${keyAgreement.algorithm}' with encryption algorithm '${decryption.algorithm}'`,\n 'askar'\n )\n }\n\n // ECDH-1PU+A256KW: ephemeralKey and senderKey (sender public) are required\n if (keyAgreement.algorithm === 'ECDH-1PU+A256KW') {\n if (!ephemeralKey) {\n throw new Kms.KeyManagementError('ECDH-1PU+A256KW decrypt requires ephemeralKey (ephemeral public key from JWE)')\n }\n return deriveDecryptionKeyEcdh1Pu({\n askar,\n keyAgreement: keyAgreement as AskarSupportedKeyAgreementDecryptOptions & { algorithm: 'ECDH-1PU+A256KW' },\n decryption,\n ephemeralKey,\n senderKey,\n recipientKey,\n })\n }\n\n const askarKeyWrappingAlgorithm =\n keyAgreement.algorithm !== 'ECDH-ES'\n ? jwkEncToAskarAlg[keyAgreement.algorithm.replace('ECDH-ES+', '') as keyof typeof jwkEncToAskarAlg]\n : undefined\n\n const derivedKey = new Key(\n askar.keyDeriveEcdhEs({\n algId: TypedArrayEncoder.fromUtf8String(\n keyAgreement.algorithm === 'ECDH-ES' ? decryption.algorithm : keyAgreement.algorithm\n ),\n receive: true,\n apv: keyAgreement.apv ? new Uint8Array(keyAgreement.apv) : new Uint8Array(),\n apu: keyAgreement.apu ? new Uint8Array(keyAgreement.apu) : new Uint8Array(),\n algorithm: askarKeyWrappingAlgorithm ?? askarEncryptionAlgorithm,\n ephemeralKey: senderKey,\n recipientKey: recipientKey,\n })\n )\n\n let contentEncryptionKey: Key | undefined\n try {\n // Key unwrapping\n if (keyAgreement.algorithm !== 'ECDH-ES') {\n contentEncryptionKey = derivedKey.unwrapKey({\n ciphertext: new Uint8Array(keyAgreement.encryptedKey.encrypted),\n algorithm: askarEncryptionAlgorithm,\n nonce: keyAgreement.encryptedKey.iv ? new Uint8Array(keyAgreement.encryptedKey.iv) : undefined,\n tag: keyAgreement.encryptedKey.tag ? new Uint8Array(keyAgreement.encryptedKey.tag) : undefined,\n })\n }\n\n return {\n contentEncryptionKey: contentEncryptionKey ?? derivedKey,\n }\n } catch (error) {\n if (contentEncryptionKey) {\n contentEncryptionKey.handle.free()\n } else {\n derivedKey.handle.free()\n }\n throw error\n } finally {\n if (contentEncryptionKey) {\n derivedKey.handle.free()\n }\n }\n}\n\nfunction deriveDecryptionKeyEcdh1Pu(options: {\n askar: Askar\n keyAgreement: AskarSupportedKeyAgreementDecryptOptions & { algorithm: 'ECDH-1PU+A256KW' }\n decryption: Kms.KmsDecryptDataDecryption\n ephemeralKey: Key\n senderKey: Key\n recipientKey: Key\n}) {\n const { askar, keyAgreement, decryption, ephemeralKey, senderKey, recipientKey } = options\n\n const supportedAlgorithms: KeyAlgorithm[] = [KeyAlgorithm.X25519, KeyAlgorithm.EcSecp256r1, KeyAlgorithm.EcSecp384r1]\n if (!supportedAlgorithms.includes(recipientKey.algorithm)) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n 'ECDH-1PU+A256KW requires X25519, P-256, or P-384 recipient key',\n 'askar'\n )\n }\n if (ephemeralKey.algorithm !== recipientKey.algorithm || senderKey.algorithm !== recipientKey.algorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n 'ECDH-1PU+A256KW sender, ephemeral, and recipient keys must be on the same curve',\n 'askar'\n )\n }\n\n const askarEncryptionAlgorithm = jwkEncToAskarAlg[decryption.algorithm as keyof typeof jwkEncToAskarAlg]\n if (!askarEncryptionAlgorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `decryption with algorithm '${decryption.algorithm}'`,\n 'askar'\n )\n }\n\n const apu = keyAgreement.apu ? new Uint8Array(keyAgreement.apu) : new Uint8Array([])\n const apv = keyAgreement.apv ? new Uint8Array(keyAgreement.apv) : new Uint8Array([])\n const algId = TypedArrayEncoder.fromUtf8String('ECDH-1PU+A256KW')\n // draft-madden-jose-ecdh-1pu-04 binds the JWE Authentication Tag into the KDF SuppPubInfo\n // for the Key Wrapping variants of ECDH-1PU.\n const decryptionTag = 'tag' in decryption ? decryption.tag : undefined\n const ccTag = decryptionTag ? new Uint8Array(decryptionTag) : undefined\n\n const derivedKey = new Key(\n askar.keyDeriveEcdh1pu({\n algorithm: KeyAlgorithm.AesA256Kw,\n ephemeralKey,\n senderKey,\n recipientKey,\n algId,\n apu,\n apv,\n ccTag,\n receive: true,\n })\n )\n\n try {\n const contentEncryptionKey = derivedKey.unwrapKey({\n ciphertext: new Uint8Array(keyAgreement.encryptedKey.encrypted),\n algorithm: askarEncryptionAlgorithm,\n nonce: keyAgreement.encryptedKey.iv ? new Uint8Array(keyAgreement.encryptedKey.iv) : undefined,\n tag: keyAgreement.encryptedKey.tag ? new Uint8Array(keyAgreement.encryptedKey.tag) : undefined,\n })\n return {\n contentEncryptionKey,\n }\n } finally {\n derivedKey.handle.free()\n }\n}\n"],"mappings":";;;;;;AAMA,MAAa,uCAAuC;CAClD;CACA;CACA;CACA;CACA;AACF;;;;;;;AAgBA,SAAgB,eAAe,SAQ5B;CACD,MAAM,EAAE,OAAO,cAAc,YAAY,WAAW,cAAc,MAAM,cAAc,yBAAyB;CAE/G,MAAM,sBAAsC;EAAC,aAAa;EAAQ,aAAa;EAAa,aAAa;CAAW;CACpH,IAAI,CAAC,oBAAoB,SAAS,UAAU,SAAS,KAAK,CAAC,oBAAoB,SAAS,aAAa,SAAS,GA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GACX,OAAO,aAAa,aAAa,KAAK,IAAI,WAAW,aAAa,aAAa,EAAE,IAAI,KAAA;GACrF,KAAK,aAAa,aAAa,MAAM,IAAI,WAAW,aAAa,aAAa,GAAG,IAAI,KAAA;EACvF,CAEqB,EACrB;CACF,UAAU;EACR,WAAW,OAAO,KAAK;CACzB;AACF"}
1
+ {"version":3,"file":"deriveKey.mjs","names":[],"sources":["../../../src/kms/crypto/deriveKey.ts"],"sourcesContent":["import { Kms, TypedArrayEncoder } from '@credo-ts/core'\nimport type { Askar } from '@openwallet-foundation/askar-shared'\nimport { Key } from '@openwallet-foundation/askar-shared'\nimport { jwkEncToAskarAlg } from '../../utils'\n\nexport const askarSupportedKeyAgreementAlgorithms = [\n 'ECDH-ES',\n 'ECDH-ES+A128KW',\n 'ECDH-ES+A256KW',\n 'ECDH-HSALSA20',\n] satisfies Kms.KnownJwaKeyAgreementAlgorithm[]\n\ntype AskarSupportedKeyAgreementEncryptOptions = Kms.KmsKeyAgreementEncryptOptions & {\n algorithm: (typeof askarSupportedKeyAgreementAlgorithms)[number]\n}\n\ntype AskarSupportedKeyAgreementDecryptOptions = Kms.KmsKeyAgreementDecryptOptions & {\n algorithm: (typeof askarSupportedKeyAgreementAlgorithms)[number]\n}\n\nexport function deriveEncryptionKey(options: {\n askar: Askar\n keyAgreement: AskarSupportedKeyAgreementEncryptOptions\n senderKey: Key\n recipientKey: Key\n encryption: Kms.KmsEncryptDataContentEncryption\n}) {\n const { askar, keyAgreement, encryption, senderKey, recipientKey } = options\n\n const askarEncryptionAlgorithm = jwkEncToAskarAlg[encryption.algorithm as keyof typeof jwkEncToAskarAlg]\n if (!askarEncryptionAlgorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `encryption with algorithm '${encryption.algorithm}'`,\n 'askar'\n )\n }\n\n // This should be handled on a higher level as we only support combined key agreemnt + encryption\n if (keyAgreement.algorithm === 'ECDH-HSALSA20') {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `derive key for algorithm '${keyAgreement.algorithm}' with encryption algorithm '${encryption.algorithm}'`,\n 'askar'\n )\n }\n\n const askarKeyWrappingAlgorithm =\n keyAgreement.algorithm !== 'ECDH-ES'\n ? jwkEncToAskarAlg[keyAgreement.algorithm.replace('ECDH-ES+', '') as keyof typeof jwkEncToAskarAlg]\n : undefined\n\n const derivedKey = new Key(\n askar.keyDeriveEcdhEs({\n algId: TypedArrayEncoder.fromUtf8String(\n keyAgreement.algorithm === 'ECDH-ES' ? encryption.algorithm : keyAgreement.algorithm\n ),\n receive: false,\n apv: keyAgreement.apv ? new Uint8Array(keyAgreement.apv) : new Uint8Array([]),\n apu: keyAgreement.apu ? new Uint8Array(keyAgreement.apu) : new Uint8Array([]),\n algorithm: askarKeyWrappingAlgorithm ?? askarEncryptionAlgorithm,\n ephemeralKey: senderKey,\n recipientKey: recipientKey,\n })\n )\n let contentEncryptionKey: Key | undefined\n let encryptedContentEncryptionKey: Kms.KmsEncryptedKey | undefined\n try {\n // Key wrapping\n if (keyAgreement.algorithm !== 'ECDH-ES') {\n contentEncryptionKey = Key.generate(askarEncryptionAlgorithm)\n\n const wrappedKey = derivedKey.wrapKey({\n other: contentEncryptionKey,\n })\n encryptedContentEncryptionKey = {\n encrypted: new Uint8Array(wrappedKey.ciphertext),\n iv: new Uint8Array(wrappedKey.nonce),\n tag: new Uint8Array(wrappedKey.tag),\n }\n }\n\n return {\n contentEncryptionKey: contentEncryptionKey ?? derivedKey,\n encryptedContentEncryptionKey,\n }\n } catch (error) {\n if (contentEncryptionKey) {\n contentEncryptionKey.handle.free()\n }\n // We only free the derived key if there is no content encryption key\n // as in this case the derived key is already freed in the finally clause\n else {\n derivedKey.handle.free()\n }\n\n throw error\n } finally {\n // If there is a content encryption key, it means we can free the\n // derived key\n if (contentEncryptionKey) {\n derivedKey.handle.free()\n }\n }\n}\n\nexport function deriveDecryptionKey(options: {\n askar: Askar\n keyAgreement: AskarSupportedKeyAgreementDecryptOptions\n senderKey: Key\n recipientKey: Key\n decryption: Kms.KmsDecryptDataContentDecryption\n}) {\n const { askar, keyAgreement, decryption, senderKey, recipientKey } = options\n\n const askarEncryptionAlgorithm = jwkEncToAskarAlg[decryption.algorithm as keyof typeof jwkEncToAskarAlg]\n if (!askarEncryptionAlgorithm) {\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `decryption with algorithm '${decryption.algorithm}'`,\n 'askar'\n )\n }\n\n if (keyAgreement.algorithm === 'ECDH-HSALSA20') {\n // This should be handled on a higher level as we only support combined key agreemnt + encryption\n throw new Kms.KeyManagementAlgorithmNotSupportedError(\n `derive key for algorithm '${keyAgreement.algorithm}' with encryption algorithm '${decryption.algorithm}'`,\n 'askar'\n )\n }\n\n const askarKeyWrappingAlgorithm =\n keyAgreement.algorithm !== 'ECDH-ES'\n ? jwkEncToAskarAlg[keyAgreement.algorithm.replace('ECDH-ES+', '') as keyof typeof jwkEncToAskarAlg]\n : undefined\n\n const derivedKey = new Key(\n askar.keyDeriveEcdhEs({\n algId: TypedArrayEncoder.fromUtf8String(\n keyAgreement.algorithm === 'ECDH-ES' ? decryption.algorithm : keyAgreement.algorithm\n ),\n receive: true,\n apv: keyAgreement.apv ? new Uint8Array(keyAgreement.apv) : new Uint8Array(),\n apu: keyAgreement.apu ? new Uint8Array(keyAgreement.apu) : new Uint8Array(),\n algorithm: askarKeyWrappingAlgorithm ?? askarEncryptionAlgorithm,\n ephemeralKey: senderKey,\n recipientKey: recipientKey,\n })\n )\n\n let contentEncryptionKey: Key | undefined\n try {\n // Key unwrapping\n if (keyAgreement.algorithm !== 'ECDH-ES') {\n contentEncryptionKey = derivedKey.unwrapKey({\n ciphertext: new Uint8Array(keyAgreement.encryptedKey.encrypted),\n algorithm: askarEncryptionAlgorithm,\n nonce: keyAgreement.encryptedKey.iv ? new Uint8Array(keyAgreement.encryptedKey.iv) : undefined,\n tag: keyAgreement.encryptedKey.tag ? new Uint8Array(keyAgreement.encryptedKey.tag) : undefined,\n })\n }\n\n return {\n contentEncryptionKey: contentEncryptionKey ?? derivedKey,\n }\n } catch (error) {\n if (contentEncryptionKey) {\n contentEncryptionKey.handle.free()\n } else {\n derivedKey.handle.free()\n }\n throw error\n } finally {\n if (contentEncryptionKey) {\n derivedKey.handle.free()\n }\n }\n}\n"],"mappings":";;;;;AAKA,MAAa,uCAAuC;CAClD;CACA;CACA;CACA;AACF;AAUA,SAAgB,oBAAoB,SAMjC;CACD,MAAM,EAAE,OAAO,cAAc,YAAY,WAAW,iBAAiB;CAErE,MAAM,2BAA2B,iBAAiB,WAAW;CAC7D,IAAI,CAAC,0BACH,MAAM,IAAI,IAAI,wCACZ,8BAA8B,WAAW,UAAU,IACnD,OACF;CAIF,IAAI,aAAa,cAAc,iBAC7B,MAAM,IAAI,IAAI,wCACZ,6BAA6B,aAAa,UAAU,+BAA+B,WAAW,UAAU,IACxG,OACF;CAGF,MAAM,4BACJ,aAAa,cAAc,YACvB,iBAAiB,aAAa,UAAU,QAAQ,YAAY,EAAE,KAC9D,KAAA;CAEN,MAAM,aAAa,IAAI,IACrB,MAAM,gBAAgB;EACpB,OAAO,kBAAkB,eACvB,aAAa,cAAc,YAAY,WAAW,YAAY,aAAa,SAC7E;EACA,SAAS;EACT,KAAK,aAAa,MAAM,IAAI,WAAW,aAAa,GAAG,IAAI,IAAI,WAAW,CAAC,CAAC;EAC5E,KAAK,aAAa,MAAM,IAAI,WAAW,aAAa,GAAG,IAAI,IAAI,WAAW,CAAC,CAAC;EAC5E,WAAW,6BAA6B;EACxC,cAAc;EACA;CAChB,CAAC,CACH;CACA,IAAI;CACJ,IAAI;CACJ,IAAI;EAEF,IAAI,aAAa,cAAc,WAAW;GACxC,uBAAuB,IAAI,SAAS,wBAAwB;GAE5D,MAAM,aAAa,WAAW,QAAQ,EACpC,OAAO,qBACT,CAAC;GACD,gCAAgC;IAC9B,WAAW,IAAI,WAAW,WAAW,UAAU;IAC/C,IAAI,IAAI,WAAW,WAAW,KAAK;IACnC,KAAK,IAAI,WAAW,WAAW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AAsB,wBAAwB,WAChD;CACF,SAAS,OAAO;EACd,IAAI,sBACF,qBAAqB,OAAO,KAAK;OAEjC,WAAW,OAAO,KAAK;EAEzB,MAAM;CACR,UAAU;EACR,IAAI,sBACF,WAAW,OAAO,KAAK;CAE3B;AACF"}
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  ".": "./build/index.mjs",
5
5
  "./package.json": "./package.json"
6
6
  },
7
- "version": "0.7.2-pr-2704-20260925144545",
7
+ "version": "0.7.2",
8
8
  "files": [
9
9
  "build"
10
10
  ],
@@ -25,7 +25,7 @@
25
25
  "hpke": "^1.1.4",
26
26
  "rxjs": "^7.8.2",
27
27
  "tsyringe": "^4.10.0",
28
- "@credo-ts/core": "0.7.2-pr-2704-20260925144545"
28
+ "@credo-ts/core": "0.7.2"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@openwallet-foundation/askar-nodejs": "0.6.0",
@@ -34,7 +34,7 @@
34
34
  "@types/ref-struct-di": "^1.1.12",
35
35
  "reflect-metadata": "0.2.2",
36
36
  "typescript": "~5.9.3",
37
- "@credo-ts/tenants": "0.7.2-pr-2704-20260925144545"
37
+ "@credo-ts/tenants": "0.7.2"
38
38
  },
39
39
  "peerDependencies": {
40
40
  "@openwallet-foundation/askar-shared": "^0.4.3 || ^0.5.0 || ^0.6.0"