@xevolab/jades
Version:
JAdES Digital Signatures compatible with the ETSI TS 119 182-1 Standard
91 lines (90 loc) • 2.65 kB
TypeScript
import ProtectedHeaders from "./ProtectedHeaders";
import UnprotectedHeaders from "./UnprotectedHeaders";
import type { SignAlg } from "../types";
import { KeyObject } from "crypto";
export default class Token {
/**
* Protected headers of the token
* @var {object}
*/
private protectedHeader;
/**
* Unprotected headers of the token
* @var {object}
*/
private header;
/**
* The claim of the token (aka payload)
* @var {string}
*/
private claim;
/**
* The signature of the token
* @var {Buffer}
*/
private signature;
constructor(_claim: string | object);
/**
* Set the protected headers of the token.
*
* @param {ProtectedHeaders} headers The protected headers of the token.
*
* @returns {void}
*/
setProtectedHeaders(headers: ProtectedHeaders): void;
/**
* Set the unprotected headers of the token.
*
* @param {UnprotectedHeaders} headers The unprotected headers of the token.
*
* @returns {void}
*/
setUnprotectedHeaders(headers: UnprotectedHeaders): void;
/**
* Method to use a detached signature for this token.
* This will require you to pass a `sigD` header value (validation not yet implemented), and will
* also remove the claim from the token in accordance with the detached signature requirements.
*
* @param {Object} sigD The detached signature object
*
* @returns {void}
*/
setDetachedSignature(sigD: Object): void;
/**
* Method to get the hased value to be signed.
*
* @param {SignAlg} alg The algorithm to use to sign the token.
*
* @returns {Buffer} The hashed value to be signed.
*/
getHash(alg: SignAlg): Buffer;
/**
* Set the signature of the token.
*
* @param {Buffer} signature The signature of the token.
*
* @returns
*/
setSignature(alg: SignAlg, signature: Buffer): void;
/**
* Sign the token using the specified algorithm and key.
*
* @param {SignAlg} alg Algorithm to use to sign the token
* @param {KeyObject} key Key to use to sign the token
*
* @return {string} Base64url encoded signature
*/
sign(alg: SignAlg, key: KeyObject): string;
/**
* Export the token to a string using in compact serialization.
*
* @return {string} The token in compact serialization.
*/
toString(): string;
/**
* Export the token to an object.
*
* @return {object} The token in object form.
*/
toObject(): object;
}