UNPKG

@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.09 kB
{"version":3,"file":"KmsCreateKeyOptions.mjs","names":["z"],"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;AAAK,CAAC;;;;AAMzE,MAAM,uBAAuB,iBAAiB,KAAK;CAAE,KAAK;CAAM,KAAK;AAAK,CAAC;;;;AAM3E,MAAM,uBAAuB,iBAAiB,KAAK,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,OAAO,EACvE,eAAeA,IAAE,MAAM;CAACA,IAAE,QAAQ,IAAI;CAAGA,IAAE,QAAQ,IAAI;CAAGA,IAAE,QAAQ,IAAI;AAAC,CAAC,EAC5E,CAAC;;;;AAMD,MAAa,uBAAuBA,IAAE,mBAAmB,aAAa;CACpEA,IAAE,OAAO;EACP,KAAK,iBAAiB,MAAM;EAC5B,WAAWA,IAAE,QAAQ,KAAK;EAC1B,QAAQA,IAAE,MAAM;GACdA,IAAE,QAAQ,GAAG;GACbA,IAAE,QAAQ,GAAG;GACbA,IAAE,QAAQ,GAAG;GACbA,IACG,OAAO,CAAC,CACR,IAAI,CAAC,CACL,QAAQ,WAAW,SAAS,MAAM,GAAG,sCAAsC;EAChF,CAAC;CACH,CAAC;CACDA,IAAE,OAAO;EACP,KAAK,iBAAiB,MAAM;EAC5B,WAAWA,IAAE,QAAQ,MAAM,CAAC,CAAC,SAAS,uCAAuC;EAC7E,QAAQA,IAAE,MAAM;GAACA,IAAE,QAAQ,GAAG;GAAGA,IAAE,QAAQ,GAAG;GAAGA,IAAE,QAAQ,GAAG;EAAC,CAAC;CAClE,CAAC;CACDA,IAAE,OAAO;EACP,KAAK,iBAAiB,MAAM;;;;EAK5B,WAAWA,IAAE,QAAQ,MAAM,CAAC,CAAC,SAAS,yDAAyD;CACjG,CAAC;AACH,CAAC;AAG0CA,IAAE,MAAM;CAAC;CAAqB;CAAsB;AAAoB,CAAC;AAIpH,MAAa,oBAAoBA,IAAE,MAAM;CACvC;CACA;CACA;CACA;AACF,CAAC;AAGD,MAAa,uBAAuBA,IAAE,OAAO;CAC3C,OAAOA,IAAE,SAAS,SAAS;CAC3B,MAAM;AACR,CAAC;AAcD,MAAa,4CAA4CA,IAAE,OAAO;CAChE,OAAOA,IAAE,SAAS,SAAS;CAC3B,WAAW;AACb,CAAC"}