@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
36 lines (35 loc) • 1.65 kB
JavaScript
import { KeyManagementError } from "../error/KeyManagementError.mjs";
import { getJwkHumanDescription } from "./humanDescription.mjs";
//#region src/modules/kms/jwk/equals.ts
/**
* Checks if two JWK public keys have matching key types
* Supports EC, OKP, and RSA key types
*/
function asymmetricJwkKeyTypeMatches(first, second) {
if (first.kty !== second.kty) return false;
if (first.kty === "EC" && second.kty === "EC") return first.crv === second.crv;
if (first.kty === "OKP" && second.kty === "OKP") return first.crv === second.crv;
if (first.kty === "RSA" && second.kty === "RSA") return true;
return false;
}
/**
* Checks if two JWK public keys have matching key types
* Supports EC, OKP, and RSA key types
*/
function assertAsymmetricJwkKeyTypeMatches(first, second) {
if (!asymmetricJwkKeyTypeMatches(first, second)) throw new KeyManagementError(`Expected jwk types to match, but found ${getJwkHumanDescription(first)} and ${getJwkHumanDescription(second)}`);
}
/**
* Checks if two JWK public keys have matching key material
* Supports EC, OKP, and RSA key types
*/
function asymmetricPublicJwkMatches(first, second) {
if (!asymmetricJwkKeyTypeMatches(first, second)) return false;
if (first.kty === "EC" && second.kty === "EC") return first.x === second.x && first.y === second.y;
if (first.kty === "OKP" && second.kty === "OKP") return first.x === second.x;
if (first.kty === "RSA" && second.kty === "RSA") return first.n === second.n && first.e === second.e;
return false;
}
//#endregion
export { assertAsymmetricJwkKeyTypeMatches, asymmetricJwkKeyTypeMatches, asymmetricPublicJwkMatches };
//# sourceMappingURL=equals.mjs.map