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

54 lines (50 loc) • 2.31 kB
import { KeyManagementError } from "../error/KeyManagementError.mjs"; import { KnownJwaSignatureAlgorithms } from "../jwk/jwa.mjs"; import { z } from "zod"; //#region src/modules/kms/cose/algorithm.ts const KnownCoseSignatureAlgorithms = { Ed25519: -19, Ed448: -53, EdDSA: -19, ESP256: -9, ESP384: -51, ESP512: -52, ES256K: -47, RS256: -257, RS384: -258, RS512: -259, PS256: -37, PS384: -38, PS512: -39, HS256: 5, HS384: 6, HS512: 7 }; const zKnownCoseSignatureAlgorithm = z.enum(KnownCoseSignatureAlgorithms); function isKnownCoseSignatureAlgorithm(coseAlg) { return Object.values(KnownCoseSignatureAlgorithms).includes(coseAlg); } const coseToJwaSignatureAlgorithmMap = { [KnownCoseSignatureAlgorithms.Ed25519]: KnownJwaSignatureAlgorithms.Ed25519, [KnownCoseSignatureAlgorithms.ESP256]: KnownJwaSignatureAlgorithms.ES256, [KnownCoseSignatureAlgorithms.ESP384]: KnownJwaSignatureAlgorithms.ES384, [KnownCoseSignatureAlgorithms.ESP512]: KnownJwaSignatureAlgorithms.ES512, [KnownCoseSignatureAlgorithms.ES256K]: KnownJwaSignatureAlgorithms.ES256K, [KnownCoseSignatureAlgorithms.RS256]: KnownJwaSignatureAlgorithms.RS256, [KnownCoseSignatureAlgorithms.RS384]: KnownJwaSignatureAlgorithms.RS384, [KnownCoseSignatureAlgorithms.RS512]: KnownJwaSignatureAlgorithms.RS512, [KnownCoseSignatureAlgorithms.PS256]: KnownJwaSignatureAlgorithms.PS256, [KnownCoseSignatureAlgorithms.PS384]: KnownJwaSignatureAlgorithms.PS384, [KnownCoseSignatureAlgorithms.PS512]: KnownJwaSignatureAlgorithms.PS512, [KnownCoseSignatureAlgorithms.HS256]: KnownJwaSignatureAlgorithms.HS256, [KnownCoseSignatureAlgorithms.HS384]: KnownJwaSignatureAlgorithms.HS384, [KnownCoseSignatureAlgorithms.HS512]: KnownJwaSignatureAlgorithms.HS512 }; function knownJwaFromCoseSignatureAlgorithm(coseAlg) { const jwaAlg = coseToJwaSignatureAlgorithmMap[coseAlg]; if (!jwaAlg) throw new KeyManagementError(`Cannot map coseAlg ${coseAlg} (${Object.entries(KnownCoseSignatureAlgorithms).find(([key, possibleCoseAlg]) => coseAlg === possibleCoseAlg)?.[0]}) to JWA signature algorithm, no JWA signature algorithm known for COSE algorithm.`); return jwaAlg; } //#endregion export { KnownCoseSignatureAlgorithms, isKnownCoseSignatureAlgorithm, knownJwaFromCoseSignatureAlgorithm }; //# sourceMappingURL=algorithm.mjs.map