@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
JavaScript
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 = {
[]: KnownJwaSignatureAlgorithms.Ed25519,
[]: KnownJwaSignatureAlgorithms.ES256,
[]: KnownJwaSignatureAlgorithms.ES384,
[]: KnownJwaSignatureAlgorithms.ES512,
[]: KnownJwaSignatureAlgorithms.ES256K,
[]: KnownJwaSignatureAlgorithms.RS256,
[]: KnownJwaSignatureAlgorithms.RS384,
[]: KnownJwaSignatureAlgorithms.RS512,
[]: KnownJwaSignatureAlgorithms.PS256,
[]: KnownJwaSignatureAlgorithms.PS384,
[]: KnownJwaSignatureAlgorithms.PS512,
[]: KnownJwaSignatureAlgorithms.HS256,
[]: KnownJwaSignatureAlgorithms.HS384,
[]: 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