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 • 4.67 kB
{"version":3,"file":"jwa.mjs","names":["z"],"sources":["../../../../src/modules/kms/jwk/jwa.ts"],"sourcesContent":["import { z } from 'zod'\n\nfunction recordToUnion<T>(record: Record<string, T>) {\n return Object.values(record) as [\n (typeof record)[keyof typeof record],\n (typeof record)[keyof typeof record],\n ...(typeof record)[keyof typeof record][],\n ]\n}\n\nexport const KnownJwaSignatureAlgorithms = {\n HS256: 'HS256',\n HS384: 'HS384',\n HS512: 'HS512',\n RS256: 'RS256',\n RS384: 'RS384',\n RS512: 'RS512',\n ES256: 'ES256',\n ES384: 'ES384',\n ES512: 'ES512',\n PS256: 'PS256',\n PS384: 'PS384',\n PS512: 'PS512',\n EdDSA: 'EdDSA',\n Ed25519: 'Ed25519',\n ES256K: 'ES256K',\n} as const\n\nexport const zKnownJwaSignatureAlgorithm = z.enum(recordToUnion(KnownJwaSignatureAlgorithms))\nexport type KnownJwaSignatureAlgorithm = z.output<typeof zKnownJwaSignatureAlgorithm>\n\nexport function isKnownJwaSignatureAlgorithm(alg: string): alg is KnownJwaSignatureAlgorithm {\n return Object.values(KnownJwaSignatureAlgorithms).includes(alg as keyof typeof KnownJwaSignatureAlgorithms)\n}\n\n// Content encryption algorithms (\"enc\" parameter)\nexport const KnownJwaContentEncryptionAlgorithms = {\n // AES-GCM Content Encryption\n A128GCM: 'A128GCM',\n A192GCM: 'A192GCM',\n A256GCM: 'A256GCM',\n\n // AES-CBC Content Encryption\n A128CBC: 'A128CBC',\n A256CBC: 'A256CBC',\n\n // (X)ChaCha20-Poly1305\n C20P: 'C20P',\n XC20P: 'XC20P',\n\n /**\n * As is used in DIDComm v1\n */\n 'XSALSA20-POLY1305': 'XSALSA20-POLY1305',\n\n A128CBC_HS256: 'A128CBC-HS256',\n A192CBC_HS384: 'A192CBC-HS384',\n A256CBC_HS512: 'A256CBC-HS512',\n} as const\nexport const zKnownJwaContentEncryptionAlgorithm = z.enum(recordToUnion(KnownJwaContentEncryptionAlgorithms))\nexport type KnownJwaContentEncryptionAlgorithm = z.output<typeof zKnownJwaContentEncryptionAlgorithm>\n\nexport const KnownJwaKeyEncryptionAlgorithms = {\n // AES Key Wrapping\n A128KW: 'A128KW',\n A192KW: 'A192KW',\n A256KW: 'A256KW',\n} as const\nconst zKnownJwaKeyEncryptionAlgorithm = z.enum(recordToUnion(KnownJwaKeyEncryptionAlgorithms))\nexport type KnownJwaKeyEncryptionAlgorithm = z.output<typeof zKnownJwaKeyEncryptionAlgorithm>\n\n// Key derivation / wrapping algorithms (\"alg\" parameter)\nexport const KnownJwaKeyAgreementAlgorithms = {\n // ECDH-ES with P-256/P-384/P-521\n ECDH_ES: 'ECDH-ES',\n ECDH_ES_A128KW: 'ECDH-ES+A128KW',\n ECDH_ES_A192KW: 'ECDH-ES+A192KW',\n ECDH_ES_A256KW: 'ECDH-ES+A256KW',\n\n ECDH_HSALSA20: 'ECDH-HSALSA20',\n\n // HPKE (RFC 9180) in integrated encryption mode, named after\n // draft-ietf-jose-hpke-encrypt. The suite fixes the AEAD, so no separate content encryption\n // algorithm is used:\n // - HPKE-0: DHKEM(P-256, HKDF-SHA256) / HKDF-SHA256 / AES-128-GCM\n // - HPKE-3: DHKEM(X25519, HKDF-SHA256) / HKDF-SHA256 / AES-128-GCM\n // - HPKE-7: DHKEM(P-256, HKDF-SHA256) / HKDF-SHA256 / AES-256-GCM\n HPKE_0: 'HPKE-0',\n HPKE_3: 'HPKE-3',\n HPKE_7: 'HPKE-7',\n} as const\nconst zKnownJwaKeyAgreementAlgorithm = z.enum(recordToUnion(KnownJwaKeyAgreementAlgorithms))\nexport type KnownJwaKeyAgreementAlgorithm = z.output<typeof zKnownJwaKeyAgreementAlgorithm>\n\nexport const KnownJwaHpkeAlgorithms = [\n KnownJwaKeyAgreementAlgorithms.HPKE_0,\n KnownJwaKeyAgreementAlgorithms.HPKE_3,\n KnownJwaKeyAgreementAlgorithms.HPKE_7,\n] as const\nexport const zKnownJwaHpkeAlgorithm = z.enum(KnownJwaHpkeAlgorithms)\nexport type KnownJwaHpkeAlgorithm = z.output<typeof zKnownJwaHpkeAlgorithm>\n\nexport function isJwaHpkeAlgorithm(algorithm: string): algorithm is KnownJwaHpkeAlgorithm {\n return (KnownJwaHpkeAlgorithms as readonly string[]).includes(algorithm)\n}\n"],"mappings":";;AAEA,SAAS,cAAiB,QAA2B;CACnD,OAAO,OAAO,OAAO,MAAM;AAK7B;AAEA,MAAa,8BAA8B;CACzC,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,OAAO;CACP,SAAS;CACT,QAAQ;AACV;AAEA,MAAa,8BAA8BA,IAAE,KAAK,cAAc,2BAA2B,CAAC;AAG5F,SAAgB,6BAA6B,KAAgD;CAC3F,OAAO,OAAO,OAAO,2BAA2B,CAAC,CAAC,SAAS,GAA+C;AAC5G;AAGA,MAAa,sCAAsC;CAEjD,SAAS;CACT,SAAS;CACT,SAAS;CAGT,SAAS;CACT,SAAS;CAGT,MAAM;CACN,OAAO;;;;CAKP,qBAAqB;CAErB,eAAe;CACf,eAAe;CACf,eAAe;AACjB;AACmDA,IAAE,KAAK,cAAc,mCAAmC,CAAC;AAG5G,MAAa,kCAAkC;CAE7C,QAAQ;CACR,QAAQ;CACR,QAAQ;AACV;AACwCA,IAAE,KAAK,cAAc,+BAA+B,CAAC;AAI7F,MAAa,iCAAiC;CAE5C,SAAS;CACT,gBAAgB;CAChB,gBAAgB;CAChB,gBAAgB;CAEhB,eAAe;CAQf,QAAQ;CACR,QAAQ;CACR,QAAQ;AACV;AACuCA,IAAE,KAAK,cAAc,8BAA8B,CAAC;AAG3F,MAAa,yBAAyB;CACpC,+BAA+B;CAC/B,+BAA+B;CAC/B,+BAA+B;AACjC;AACA,MAAa,yBAAyBA,IAAE,KAAK,sBAAsB;AAGnE,SAAgB,mBAAmB,WAAuD;CACxF,OAAQ,uBAA6C,SAAS,SAAS;AACzE"}