@unvision/jose
Version:
Implementation of the RFCs of the JOSE Working Group.
43 lines • 1.57 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.OctKeyAlgorithm = void 0;
const crypto_1 = require("crypto");
const invalid_jsonwebkey_exception_1 = require("../../exceptions/invalid-jsonwebkey.exception");
/**
* Implementation of the **Octet Sequence** JSON Web Key Algorithm.
*
* @see https://www.rfc-editor.org/rfc/rfc7518.html#section-6.4
*/
class OctKeyAlgorithm {
constructor() {
/**
* Private Parameters of the JSON Web Key Octet Sequence Algorithm.
*/
this.privateParameters = ['k'];
}
/**
* Validates the provided JSON Web Key Parameters.
*
* @param parameters Parameters of the JSON Web Key.
*/
validateParameters(parameters) {
if (typeof parameters.k !== 'string') {
throw new invalid_jsonwebkey_exception_1.InvalidJsonWebKeyException('Invalid key parameter "k".');
}
if (Buffer.byteLength(parameters.k, 'base64url') === 0) {
throw new invalid_jsonwebkey_exception_1.InvalidJsonWebKeyException('The Secret cannot be empty.');
}
}
/**
* Loads the provided JSON Web Key into a NodeJS Crypto Key.
*
* @param parameters Parameters of the JSON Web Key.
* @returns NodeJS Crypto Key.
*/
loadCryptoKey(parameters) {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
return (0, crypto_1.createSecretKey)(parameters.k, 'base64url');
}
}
exports.OctKeyAlgorithm = OctKeyAlgorithm;
//# sourceMappingURL=octkey.algorithm.js.map