@guarani/jose
Version:
Implementation of the RFCs of the JOSE Working Group.
89 lines (88 loc) • 3.32 kB
TypeScript
/// <reference types="node" />
import { Dict, Optional } from '@guarani/types';
import { KeyObject } from 'crypto';
import { SupportedJsonWebEncryptionKeyWrapAlgorithm } from '../jwe/algorithms/alg/types/supported-jsonwebencryption-keyencryption-algorithm';
import { SupportedJsonWebSignatureAlgorithm } from '../jws/algorithms/types/supported-jsonwebsignature-algorithm';
import { SupportedJsonWebKeyAlgorithm } from './algorithms/types/supported-jsonwebkey-algorithm';
import { JsonWebKeyParams } from './jsonwebkey.params';
import { KeyOperation } from './types/key-operation';
import { PublicKeyUse } from './types/public-key-use';
/**
* Implementation of {@link https://www.rfc-editor.org/rfc/rfc7517.html#section-4 RFC 7517 Section 4}.
*/
export declare abstract class JsonWebKey implements JsonWebKeyParams {
/**
* NodeJS Crypto Key.
*/
protected readonly cryptoKey: KeyObject;
/**
* Type of the JSON Web Key.
*/
readonly kty: SupportedJsonWebKeyAlgorithm;
/**
* Indicates whether a Public JSON Web Key is used for Plaintext Encryption or Signature Verification.
*/
readonly use?: Optional<PublicKeyUse>;
/**
* Operations for which the JSON Web Key are intended to be used.
*/
readonly key_ops?: Optional<KeyOperation[]>;
/**
* Defines the JSON Web Encryption Key Wrap Algorithm or JSON Web Signature Algorithm
* allowed to use this JSON Web Key.
*/
readonly alg?: Optional<SupportedJsonWebEncryptionKeyWrapAlgorithm | SupportedJsonWebSignatureAlgorithm>;
/**
* Defines the Identifier of the JSON Web Key.
*/
readonly kid?: Optional<string>;
/**
* Defines the URL of the X.509 certificate of the JSON Web Key.
*/
readonly x5u?: Optional<string>;
/**
* Defines a chain of X.509 certificates of the JSON Web Key.
*/
readonly x5c?: Optional<string[]>;
/**
* Defines the SHA-1 Thumbprint of the X.509 certificate of the JSON Web Key.
*/
readonly x5t?: Optional<string>;
/**
* Defines the SHA-256 Thumbprint of the X.509 certificate of the JSON Web Key.
*/
readonly 'x5t#S256'?: Optional<string>;
/**
* Instantiates a new JSON Web Key based on the provided Parameters.
*
* @param params Parameters of the JSON Web Key.
*/
constructor(params?: Optional<JsonWebKeyParams>);
/**
* Checks if the provided data conforms to the JSON Web Key Specification.
*
* @param data Data to be checked.
*/
static isJsonWebKey(data: unknown): data is JsonWebKeyParams;
/**
* Loads the provided JSON Web Key into a NodeJS Crypto Key.
*
* @param params Parameters of the JSON Web Key.
* @returns NodeJS Crypto Key.
*/
protected abstract loadCryptoKey(params: JsonWebKeyParams): KeyObject;
/**
* Exports the data of the JSON Web Key into a String.
*
* @param options Options for exporting the data of the JSON Web Key.
* @returns Resulting String.
*/
abstract export(options: Dict): string;
/**
* Exports the data of the JSON Web Key into a Buffer.
*
* @param options Options for exporing the data of the JSON Web Key.
* @returns Resulting Buffer.
*/
abstract export(options: Dict): Buffer;
}