{"version":3,"file":"KmsKeyAgreementDecryptOptions.mjs","names":["z"],"sources":["../../../../src/modules/kms/options/KmsKeyAgreementDecryptOptions.ts"],"sourcesContent":["import { z } from 'zod'\nimport { zAnyUint8Array } from '../../../utils/zod'\nimport { isJwaHpkeAlgorithm, zKnownJwaHpkeAlgorithm } from '../jwk/jwa'\nimport { zKmsJwkPublicOkp } from '../jwk/kty/okp/okpJwk'\nimport { zKmsKeyId } from './common'\nimport { zKmsEncryptedKey } from './KmsEncryptOptions'\nimport { zKmsJwkPublicEcdh, zKmsKeyAgreementEcdhEs } from './KmsKeyAgreementEncryptOptions'\n\nconst zKmsKeyAgreementDecryptEcdhEsKw = z.object({\n  /**\n   * The key id pointing to the ephemeral public key.\n   *\n   * The key type MUST match with the externalPublicJwk\n   */\n  keyId: zKmsKeyId,\n\n  algorithm: z.enum(['ECDH-ES+A128KW', 'ECDH-ES+A192KW', 'ECDH-ES+A256KW']),\n\n  externalPublicJwk: zKmsJwkPublicEcdh,\n\n  /**\n   * The encrypted content encryption key (cek)\n   */\n  encryptedKey: zKmsEncryptedKey,\n\n  apu: z.optional(zAnyUint8Array),\n  apv: z.optional(zAnyUint8Array),\n})\nexport type KmsKeyAgreementDecryptEcdhEsKw = z.output<typeof zKmsKeyAgreementDecryptEcdhEsKw>\n\nconst zKmsKeyAgreementDecryptEcdhHsalsa20 = z.object({\n  /**\n   * The key id to use for decrypting the content encryption key.\n   */\n  keyId: zKmsKeyId,\n\n  /**\n   * Perform key agreement based on the HSALSA20 as used in Libsodium's\n   * Cryptobox. This is not based on an official JWA algorithm, but is\n   * used primarily for DIDComm v1 messaging.\n   */\n  algorithm: z.literal('ECDH-HSALSA20'),\n\n  /**\n   * Can be undefined for anonymous encryption\n   */\n  externalPublicJwk: zKmsJwkPublicOkp.extend({ crv: zKmsJwkPublicOkp.shape.crv.extract(['X25519']) }).optional(),\n})\nexport type KmsKeyAgreementDecryptEcdhHsalsa20 = z.output<typeof zKmsKeyAgreementDecryptEcdhHsalsa20>\n\nexport const zKmsKeyAgreementDecryptHpke = z.object({\n  /**\n   * The key id pointing to the recipient private key (`skR`).\n   */\n  keyId: zKmsKeyId,\n\n  algorithm: zKnownJwaHpkeAlgorithm,\n\n  /**\n   * The raw serialized encapsulated key (`enc`) generated by the sender. For the DHKEM(P-256)\n   * suites this is the 65-byte uncompressed SEC1 point.\n   */\n  encapsulatedKey: zAnyUint8Array,\n\n  /**\n   * Application supplied information, bound into the HPKE key schedule.\n   */\n  info: z.optional(zAnyUint8Array),\n})\nexport type KmsKeyAgreementDecryptHpke = z.output<typeof zKmsKeyAgreementDecryptHpke>\n\nexport const zKmsKeyAgreementDecryptOptions = z\n  .discriminatedUnion('algorithm', [\n    zKmsKeyAgreementEcdhEs,\n    zKmsKeyAgreementDecryptEcdhEsKw,\n    zKmsKeyAgreementDecryptEcdhHsalsa20,\n    zKmsKeyAgreementDecryptHpke,\n  ])\n  .describe('Options for key agreement based on an asymmetric key.')\nexport type KmsKeyAgreementDecryptOptions = z.output<typeof zKmsKeyAgreementDecryptOptions>\n\nexport function isKmsKeyAgreementDecryptHpke(\n  keyAgreement: KmsKeyAgreementDecryptOptions\n): keyAgreement is KmsKeyAgreementDecryptHpke {\n  return isJwaHpkeAlgorithm(keyAgreement.algorithm)\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,kCAAkCA,IAAE,OAAO;;;;;;CAM/C,OAAO;CAEP,WAAWA,IAAE,KAAK;EAAC;EAAkB;EAAkB;CAAgB,CAAC;CAExE,mBAAmB;;;;CAKnB,cAAc;CAEd,KAAKA,IAAE,SAAS,cAAc;CAC9B,KAAKA,IAAE,SAAS,cAAc;AAChC,CAAC;AAGD,MAAM,sCAAsCA,IAAE,OAAO;;;;CAInD,OAAO;;;;;;CAOP,WAAWA,IAAE,QAAQ,eAAe;;;;CAKpC,mBAAmB,iBAAiB,OAAO,EAAE,KAAK,iBAAiB,MAAM,IAAI,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS;AAC/G,CAAC;AAGD,MAAa,8BAA8BA,IAAE,OAAO;;;;CAIlD,OAAO;CAEP,WAAW;;;;;CAMX,iBAAiB;;;;CAKjB,MAAMA,IAAE,SAAS,cAAc;AACjC,CAAC;AAGD,MAAa,iCAAiCA,IAC3C,mBAAmB,aAAa;CAC/B;CACA;CACA;CACA;AACF,CAAC,CAAC,CACD,SAAS,uDAAuD;AAGnE,SAAgB,6BACd,cAC4C;CAC5C,OAAO,mBAAmB,aAAa,SAAS;AAClD"}