@sap/xssec
Version:
XS Advanced Container Security API for node.js
26 lines (22 loc) • 811 B
JavaScript
const Jwk = require("./Jwk");
const MissingKidError = require('../error/validation/MissingKidError');
class Jwks {
constructor(keys = []) {
this.keys = Object.create(null);
for(const k of keys) {
this.keys[k.kid] = new Jwk(k);
}
}
/**
* Retrieves the JWK (JSON Web Key) associated with the specified key ID (kid).
* @param {string} kid - The key ID (kid) of the JWK to retrieve.
* @returns {Jwk} - The JWK associated with the specified key ID.
* @throws {MissingKidError} - If the JWKS does not contain a key for the specified key ID.
*/
get(kid) {
const jwk = this.keys[kid];
if(!jwk) throw new MissingKidError(kid, `JWKS does not contain a key for kid=${kid}`);
return jwk;
}
}
module.exports = Jwks;