@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 • 5.05 kB
Source Map (JSON)
{"version":3,"file":"KmsCreateKeyOptions.mjs","names":[],"sources":["../../../../src/modules/kms/options/KmsCreateKeyOptions.ts"],"sourcesContent":["import { z } from 'zod'\nimport type { KnownJwaSignatureAlgorithm } from '../jwk'\nimport { zKnownJwaSignatureAlgorithm } from '../jwk/jwa'\nimport type { KmsJwkPublicFromCreateType } from '../jwk/knownJwk'\nimport { zKmsJwkPublicEc } from '../jwk/kty/ec/ecJwk'\nimport { zKmsJwkPublicOct } from '../jwk/kty/oct/octJwk'\nimport { zKmsJwkPublicOkp } from '../jwk/kty/okp/okpJwk'\nimport { zKmsJwkPublicRsa } from '../jwk/kty/rsa/rsaJwk'\nimport { zKmsKeyId } from './common'\n\nconst zKmsCreateKeyTypeEc = zKmsJwkPublicEc.pick({ kty: true, crv: true })\nexport type KmsCreateKeyTypeEc = z.output<typeof zKmsCreateKeyTypeEc>\n\n/**\n * Octer key pair, commonly used for Ed25519 and X25519 key types\n */\nconst zKmsCreateKeyTypeOkp = zKmsJwkPublicOkp.pick({ kty: true, crv: true })\nexport type KmsCreateKeyTypeOkp = z.output<typeof zKmsCreateKeyTypeOkp>\n\n/**\n * RSA key pair.\n */\nconst zKmsCreateKeyTypeRsa = zKmsJwkPublicRsa.pick({ kty: true }).extend({\n modulusLength: z.union([z.literal(2048), z.literal(3072), z.literal(4096)]),\n})\nexport type KmsCreateKeyTypeRsa = z.output<typeof zKmsCreateKeyTypeRsa>\n\n/**\n * Represents an octect sequence for symmetric keys\n */\nexport const zKmsCreateKeyTypeOct = z.discriminatedUnion('algorithm', [\n z.object({\n kty: zKmsJwkPublicOct.shape.kty,\n algorithm: z.literal('aes'),\n length: z.union([\n z.literal(128),\n z.literal(192),\n z.literal(256),\n z\n .number()\n .int()\n .refine((length) => length % 8 === 0, 'aes key length must be multiple of 8'),\n ]),\n }),\n z.object({\n kty: zKmsJwkPublicOct.shape.kty,\n algorithm: z.literal('hmac').describe('For usage with HS256, HS384 and HS512'),\n length: z.union([z.literal(256), z.literal(384), z.literal(512)]),\n }),\n z.object({\n kty: zKmsJwkPublicOct.shape.kty,\n\n /**\n * For usage with ChaCha20-Poly1305 and XChaCha20-Poly1305\n */\n algorithm: z.literal('C20P').describe('For usage with ChaCha20-Poly1305 and XChaCha20-Poly1305'),\n }),\n])\nexport type KmsCreateKeyTypeOct = z.output<typeof zKmsCreateKeyTypeOct>\n\nexport const zKmsCreateKeyTypeAsymmetric = z.union([zKmsCreateKeyTypeEc, zKmsCreateKeyTypeOkp, zKmsCreateKeyTypeRsa])\nexport type KmsCreateKeyTypeAsymmetric = z.output<typeof zKmsCreateKeyTypeAsymmetric>\n\n// TODO: see if we can use nested discriminated union with zod?\nexport const zKmsCreateKeyType = z.union([\n zKmsCreateKeyTypeEc,\n zKmsCreateKeyTypeOkp,\n zKmsCreateKeyTypeRsa,\n zKmsCreateKeyTypeOct,\n])\nexport type KmsCreateKeyType = z.output<typeof zKmsCreateKeyType>\n\nexport const zKmsCreateKeyOptions = z.object({\n keyId: z.optional(zKmsKeyId),\n type: zKmsCreateKeyType,\n})\n\nexport interface KmsCreateKeyOptions<Type extends KmsCreateKeyType = KmsCreateKeyType> {\n /**\n * The `kid` for the key.\n */\n keyId?: string\n\n /**\n * The type of key to generate\n */\n type: Type\n}\n\nexport const zKmsCreateKeyForSignatureAlgorithmOptions = z.object({\n keyId: z.optional(zKmsKeyId),\n algorithm: zKnownJwaSignatureAlgorithm,\n})\n\nexport interface KmsCreateKeyForSignatureAlgorithmOptions {\n /**\n * The `kid` for the key.\n */\n keyId?: string\n\n /**\n * The JWA signature algorithm to create the key for.\n */\n algorithm: KnownJwaSignatureAlgorithm\n}\n\nexport interface KmsCreateKeyReturn<Type extends KmsCreateKeyType = KmsCreateKeyType> {\n keyId: string\n\n /**\n * The public JWK representation of the created key. `kid` will always\n * be defined.\n *\n * In case of a symmetric (oct) key this won't include any key material, but\n * will include additional JWK claims such as `use`, `kty`, and `kid`\n */\n publicJwk: KmsJwkPublicFromCreateType<Type> & { kid: string }\n}\n"],"mappings":";;;;;;;;;;;AAUA,MAAM,sBAAsB,gBAAgB,KAAK;CAAE,KAAK;CAAM,KAAK;CAAM,CAAC;;;;AAM1E,MAAM,uBAAuB,iBAAiB,KAAK;CAAE,KAAK;CAAM,KAAK;CAAM,CAAC;;;;AAM5E,MAAM,uBAAuB,iBAAiB,KAAK,EAAE,KAAK,MAAM,CAAC,CAAC,OAAO,EACvE,eAAe,EAAE,MAAM;CAAC,EAAE,QAAQ,KAAK;CAAE,EAAE,QAAQ,KAAK;CAAE,EAAE,QAAQ,KAAK;CAAC,CAAC,EAC5E,CAAC;;;;AAMF,MAAa,uBAAuB,EAAE,mBAAmB,aAAa;CACpE,EAAE,OAAO;EACP,KAAK,iBAAiB,MAAM;EAC5B,WAAW,EAAE,QAAQ,MAAM;EAC3B,QAAQ,EAAE,MAAM;GACd,EAAE,QAAQ,IAAI;GACd,EAAE,QAAQ,IAAI;GACd,EAAE,QAAQ,IAAI;GACd,EACG,QAAQ,CACR,KAAK,CACL,QAAQ,WAAW,SAAS,MAAM,GAAG,uCAAuC;GAChF,CAAC;EACH,CAAC;CACF,EAAE,OAAO;EACP,KAAK,iBAAiB,MAAM;EAC5B,WAAW,EAAE,QAAQ,OAAO,CAAC,SAAS,wCAAwC;EAC9E,QAAQ,EAAE,MAAM;GAAC,EAAE,QAAQ,IAAI;GAAE,EAAE,QAAQ,IAAI;GAAE,EAAE,QAAQ,IAAI;GAAC,CAAC;EAClE,CAAC;CACF,EAAE,OAAO;EACP,KAAK,iBAAiB,MAAM;EAK5B,WAAW,EAAE,QAAQ,OAAO,CAAC,SAAS,0DAA0D;EACjG,CAAC;CACH,CAAC;AAGF,MAAa,8BAA8B,EAAE,MAAM;CAAC;CAAqB;CAAsB;CAAqB,CAAC;AAIrH,MAAa,oBAAoB,EAAE,MAAM;CACvC;CACA;CACA;CACA;CACD,CAAC;AAGF,MAAa,uBAAuB,EAAE,OAAO;CAC3C,OAAO,EAAE,SAAS,UAAU;CAC5B,MAAM;CACP,CAAC;AAcF,MAAa,4CAA4C,EAAE,OAAO;CAChE,OAAO,EAAE,SAAS,UAAU;CAC5B,WAAW;CACZ,CAAC"}