/// import { ASN1 } from './asn1'; import { AB2hex, cleanZeros, CRYPTO_NOT_FOUND, generateErrorMessage, hex2AB, ILLEGAL_ARGUMENT, num2hex, PAKO_NOT_FOUND, UNSUPPORTED_ALGORITHM, UNSUPPORTED_ZIP_TYPE } from './util'; export declare const webCrypto: false | Crypto; export declare const webCryptoSubtle: false | SubtleCrypto; /** * Class for creating a JwtSplit object with three parts of JWT Token as strings * * @class JwtSplit */ export declare class JwtSplit { /** * Header (first) part of JWT Token * * @name header * @type {string} */ header: string; /** * Payload (second) part of JWT Token * * @name payload * @type {string} */ payload: string; /** * Signature (third) part of JWT Token * * @name signature * @type {string} */ signature: string; constructor(str: string, callee?: string); fromString(str: string, callee?: string): void; toString(): string; } /** JwtPart interface basically object type definition used as a placeholder */ export interface JwtPart { [key: string]: any; } /** * Class for creating a JwtDecode object with three parts of JWT Token, header and payload decoded and parsed, signature in initial form * * @class JwtDecode */ export declare class JwtDecode { /** * Header (first) part of JWT Token * * @name header * @type {JwtPart} */ header: JwtPart; /** * Payload (second) part of JWT Token * * @name payload * @type {JwtPart} */ payload: JwtPart; /** * Signature (third) part of JWT Token * * @name signature * @type {string} */ signature: string; constructor(str: string, callee?: string); isGzip(): boolean; fromString(str: any, callee?: string): void; toString(): string; } /** * Try running function and replace it's response as Promise.resolve/reject * * @param {function} fn - fn to call in for response * * @returns {Promise} resulting Promise */ export declare function tryPromise(fn: any): Promise; /** * Converts string to JSON object * * @param {string} str - data string to convert * * @returns {object} resulting object */ export declare function s2J(str: string): any; /** * Converts JSON object to string * * @param {object} obj - JSON object to convert * * @returns {string} resulting string */ export declare function J2s(obj: any): string; /** * Converts string to base64 string * * @param {string} str - data string to convert * * @returns {string} decoded data string */ export declare function b2s(str: string): string; /** * Converts base64 string to base64url string * * @param {string} str - data string to convert * * @returns {string} base64url string */ export declare function b2bu(str: string): string; /** * * Converts base64url string to base64 string * * @param {string} str - data string to convert * * @returns {string} base64 string */ export declare function bu2b(str: string): string; /** * Converts base64url string to string * * @param {string} str - base64url string to convert * * @returns {string} decoded data string */ export declare function bu2s(str: string): string; /** * Check if header has zip property (and it is equal to 'GZIP', ignorecase) * * @param {string} header - object to check * * @returns {boolean} does it have gzip in zip property */ export declare function isGzip(header: JwtPart): boolean; /** * Decode jwtToken header and payload * * @param {string} str - data string to decode * * @returns {JwtDecode} object with decoded header and body, and signature untouched */ export declare function jwtDecode(str: string, callee?: string): JwtDecode; export declare const decodeJwt: typeof jwtDecode; export declare const decode: typeof jwtDecode; /** * Split jwtToken into object {header, payload, signature} * * @param {string} str - data string to split * * @returns {JwtSplit} jwt split object of three strings */ export declare function jwtSplit(str: string, callee?: string): JwtSplit; export declare const splitJwt: typeof jwtSplit; export declare const split: typeof jwtSplit; /** * Converts base64 string to string * * @param {string} str - data string to convert * * @returns {string} base64 string */ export declare function s2b(str: string): string; /** * Converts string to base64url string * * @param {string} str - data string to convert * * @returns {string} base64url string */ export declare function s2bu(str: string): string; /** * Zip and encode data string to base64url string * * @param {string} str - data string to encode * @param {string} type - type of zip type: "zlib", "gzip". default: "zlib" * * @returns {string} base64url string */ export declare function s2zbu(str: string, type?: string): string; /** * Converts from zip data string to string * * @param {string} str - data string to convert * * @returns {string} decoded data string */ export declare function unzip(str: string): string; /** * Decode from base64url and unzip data string * * @param {string} str - data string to decode * * @returns {string} decoded data string */ export declare function zbu2s(str: string): string; /** * Converts string to zip data string * * @param {string} str - data string to convert * @param {string} type - type of zip type: "zlib", "gzip". default: "zlib" * * @returns {string} zip data string */ export declare function zip(str: string, type?: string): string; /** * Converts string to ArrayBuffer * * @param {string} str - data string to convert * * @returns {ArrayBuffer} charCode ArrayBuffer */ export declare function s2AB(str: string): ArrayBuffer; /** * Converts string to Uint8Array * * @param {string} str - data string to convert * * @returns {Uint8Array} charCode Uint8Array */ export declare function s2U8A(str: string): ArrayBuffer; /** * Converts ArrayBuffer to string * * @param {ArrayBuffer | Uint8Array} buff - charCode ArrayBuffer to convert * * @returns {string} data string */ export declare function AB2s(buff: ArrayBuffer | Uint8Array): string; /** * Async function inspired by createHmac in crypto (used WebCrypto Api supported by most browsers) * */ export declare function createHmac(name: string, secret: string): Promise; /** * Algorithm HMAC sign generator * */ export declare function algHSsign(bits: number): (thing: string, secret: string) => Promise; /** * Algorithm HMAC verify generator * */ export declare function algHSverify(bits: number): (thing: string, signature: string, secret: string) => Promise; export interface PEM { body: ArrayBuffer | Uint8Array; type: 'private' | 'public'; } export declare function s2pem(secret: string): PEM; export declare class Asn1Tag { tagClass: number; tagConstructed: boolean; tagNumber: number; constructor(stream: any); } export declare function pem2asn1(buff: ArrayBuffer | Uint8Array): any; export declare function asn12jwk(asn1: any, type?: string, extra?: any): any; export declare function pem2jwk(secret: string, type?: 'public' | 'private', extra?: any): Promise; export declare function createSign(name: string): Promise; export declare function algRSsign(bits: number): (thing: string, privateKey: string) => Promise; export declare function createVerify(name: string): Promise; export declare function algRSverify(bits: number): (thing: string, signature: string, publicKey: string) => Promise; /** * Universal algorithm verifier * */ export declare function algVerify(algorithm: string, thing: string, signature: string, secret: string): Promise; /** * Universal algorithm signer * */ export declare function algSign(algorithm: string, thing: string, secret: string): Promise; export declare function jwtVerify(jwtStr: string, secret: string): Promise; export declare const verifyJwt: typeof jwtVerify; export declare const verify: typeof jwtVerify; export declare function jwtSign(jwtStr: string, secret: string): Promise; export declare const signJwt: typeof jwtSign; export declare const sign: typeof jwtSign; export declare function jwtResign(jwtStr: string, secret: string, alg?: string): Promise; export declare const resignJwt: typeof jwtResign; export declare const resign: typeof jwtResign; /** * Used for testing only * * @hidden */ export declare function cryptoType(): Promise; export declare function notLatin1String(str: any): boolean; export declare function textEncode(input: string): ArrayBuffer; export declare function textDecode(input: string | Buffer): string; export declare function getTextEncoder(): TextEncoder | false; export declare function getTextDecoder(...args: any[]): TextDecoder | false; export { ASN1, AB2hex, cleanZeros, CRYPTO_NOT_FOUND, generateErrorMessage, hex2AB, ILLEGAL_ARGUMENT, num2hex, PAKO_NOT_FOUND, UNSUPPORTED_ALGORITHM, UNSUPPORTED_ZIP_TYPE, };