UNPKG

@unvision/jose

Version:

Implementation of the RFCs of the JOSE Working Group.

54 lines (53 loc) 2.16 kB
/// <reference types="node" /> import { JsonWebKey } from '../jwk/jsonwebkey'; import { JsonWebKeyLoader } from '../types/jsonwebkey-loader'; import { JsonWebEncryptionHeader } from './jsonwebencryption.header'; import { JsonWebEncryptionHeaderParameters } from './jsonwebencryption.header.parameters'; /** * Implementation of a JSON Web Encryption. * * @see https://www.rfc-editor.org/rfc/rfc7516.html */ export declare class JsonWebEncryption { /** * JSON Web Encryption Header. */ readonly header: JsonWebEncryptionHeader; /** * JSON Web Encryption Plaintext. */ readonly plaintext: Buffer; /** * Instantiates a new JSON Web Encryption based on the provided JSON Web Encryption Header and Plaintext. * * @param header JSON Web Encryption Header. * @param plaintext Buffer to be used as the Plaintext. */ constructor(header: JsonWebEncryptionHeaderParameters, plaintext?: Buffer); /** * Decodes the provided JSON Web Encryption Token and returns its parsed Parameters. * * @example * * const [header, ek, iv, ciphertext, tag, aad] = JsonWebEncryption.decode('eyJhbGciOiJBMTI4...'); * * @param token JSON Web Encryption Token to be Decoded. * @returns Parsed Parameters of the JSON Web Encryption Token. */ static decode(token: string): [JsonWebEncryptionHeader, Buffer, Buffer, Buffer, Buffer, Buffer]; /** * Deserializes a JSON Web Encryption Compact Token. * * @param token JSON Web Encryption Compact Token to be Deserialized. * @param keyOrKeyLoader JSON Web Key used to Deserialize the JSON Web Encryption Compact Token. * @returns JSON Web Encryption containing the Deserialized JSON Web Encryption Header and Plaintext. */ static decrypt(token: string, keyOrKeyLoader: JsonWebKey | JsonWebKeyLoader): Promise<JsonWebEncryption>; /** * Serializes the JSON Web Encryption into a Compact Token. * * @param key JSON Web Key used to Serialize the JSON Web Encryption. * @returns JSON Web Encryption Compact Token. */ encrypt(key: JsonWebKey): Promise<string>; }