@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
40 lines (36 loc) • 1.25 kB
JavaScript
import { TypedArrayEncoder } from "../../../utils/TypedArrayEncoder.mjs";
import { Hasher } from "../../../crypto/hashes/Hasher.mjs";
import "../../../utils/index.mjs";
import { zParseWithErrorHandling } from "../../../utils/zod.mjs";
import { zKmsJwkPublic } from "./knownJwk.mjs";
//#region src/modules/kms/jwk/jwkThumbprint.ts
const zJwkThumbprintComponents = zKmsJwkPublic.transform((data) => {
if (data.kty === "EC") return {
crv: data.crv,
kty: data.kty,
x: data.x,
y: data.y
};
if (data.kty === "OKP") return {
crv: data.crv,
kty: data.kty,
x: data.x
};
if (data.kty === "RSA") return {
e: data.e,
kty: data.kty,
n: data.n
};
if (data.kty === "oct") return {
k: data.k,
kty: data.kty
};
throw new Error("Unsupported kty");
});
function calculateJwkThumbprint(options) {
const jwkThumbprintComponents = zParseWithErrorHandling(zJwkThumbprintComponents, options.jwk, `Provided jwk does not match a supported jwk structure. Either the 'kty' is not supported, or required values are missing.`);
return Hasher.hash(TypedArrayEncoder.fromUtf8String(JSON.stringify(jwkThumbprintComponents)), options.hashAlgorithm);
}
//#endregion
export { calculateJwkThumbprint };
//# sourceMappingURL=jwkThumbprint.mjs.map