@credo-ts/core
Version:
<p align="center"> <br /> <img alt="Credo Logo" src="https://github.com/openwallet-foundation/credo-ts/blob/c7886cb8377ceb8ee4efe8d264211e561a75072d/images/credo-logo.png" height="250px" /> </p> <h1 align="center"><b>Credo - Core</b></h1
1 lines • 4.67 kB
Source Map (JSON)
{"version":3,"file":"KmsKeyAgreementEncryptOptions.mjs","names":["z"],"sources":["../../../../src/modules/kms/options/KmsKeyAgreementEncryptOptions.ts"],"sourcesContent":["import { z } from 'zod'\nimport { zAnyUint8Array } from '../../../utils/zod'\nimport { isJwaHpkeAlgorithm, zKnownJwaHpkeAlgorithm } from '../jwk/jwa'\nimport { zKmsJwkPublicEc } from '../jwk/kty/ec/ecJwk'\nimport { zKmsJwkPublicOkp } from '../jwk/kty/okp/okpJwk'\nimport { zKmsKeyId } from './common'\n\nexport const zKmsJwkPublicEcdh = z.union([\n zKmsJwkPublicOkp.extend({ crv: zKmsJwkPublicOkp.shape.crv.extract(['X25519']) }),\n zKmsJwkPublicEc.extend({ crv: zKmsJwkPublicEc.shape.crv.extract(['P-256', 'P-384', 'P-521', 'secp256k1']) }),\n])\n\nexport type KmsJwkPublicEcdh = z.infer<typeof zKmsJwkPublicEcdh>\n\nexport const zKmsKeyAgreementEcdhEs = 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.literal('ECDH-ES'),\n\n externalPublicJwk: zKmsJwkPublicEcdh,\n\n apu: z.optional(zAnyUint8Array),\n apv: z.optional(zAnyUint8Array),\n})\nexport type KmsKeyAgreementEcdhEs = z.output<typeof zKmsKeyAgreementEcdhEs>\n\nconst zKmsKeyAgreementEncryptEcdhEsKw = 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 apu: z.optional(zAnyUint8Array),\n apv: z.optional(zAnyUint8Array),\n})\nexport type KmsKeyAgreementEncryptEcdhEsKw = z.output<typeof zKmsKeyAgreementEncryptEcdhEsKw>\n\nconst zKmsKeyAgreementEncryptEcdhHsalsa20 = z.object({\n /**\n * The key id to use for encrypting the content encryption key.\n * If no key id is provided, anonymous encryption is used.\n */\n keyId: zKmsKeyId.optional(),\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 externalPublicJwk: zKmsJwkPublicOkp.extend({ crv: zKmsJwkPublicOkp.shape.crv.extract(['X25519']) }),\n})\nexport type KmsKeyAgreementEncryptEcdhHsalsa20 = z.output<typeof zKmsKeyAgreementEncryptEcdhHsalsa20>\n\nexport const zKmsKeyAgreementEncryptHpke = z.object({\n /**\n * HPKE (RFC 9180) in single-shot base mode. The suite fixes the AEAD, so `encryption` must not be\n * provided on the top-level encrypt options.\n */\n algorithm: zKnownJwaHpkeAlgorithm,\n\n /**\n * The public key of the recipient (`pkR`). HPKE generates its own ephemeral sender key, so no\n * `keyId` is used for sealing.\n */\n externalPublicJwk: zKmsJwkPublicEcdh,\n\n /**\n * Application supplied information, bound into the HPKE key schedule.\n */\n info: z.optional(zAnyUint8Array),\n})\nexport type KmsKeyAgreementEncryptHpke = z.output<typeof zKmsKeyAgreementEncryptHpke>\n\nexport const zKmsKeyAgreementEncryptOptions = z\n .discriminatedUnion('algorithm', [\n zKmsKeyAgreementEcdhEs,\n zKmsKeyAgreementEncryptEcdhEsKw,\n zKmsKeyAgreementEncryptEcdhHsalsa20,\n zKmsKeyAgreementEncryptHpke,\n ])\n .describe('Options for key agreement based on an asymmetric key.')\nexport type KmsKeyAgreementEncryptOptions = z.output<typeof zKmsKeyAgreementEncryptOptions>\n\nexport function isKmsKeyAgreementEncryptHpke(\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