shelving
Version:
Toolkit for using data in JavaScript.
34 lines (33 loc) • 1.36 kB
TypeScript
import { type PossibleBytes } from "./bytes.js";
import type { Data } from "./data.js";
import type { AnyFunction } from "./function.js";
/**
* Encode a JWT and return the string token.
* - Currently only supports HMAC SHA-512 signing.
*
* @throws ValueError If the input parameters, e.g. `secret` or `issuer`, are invalid.
*/
export declare function encodeToken(claims: Data, secret: PossibleBytes): Promise<string>;
/** Parts that make up a JSON Web Token. */
export type TokenData = {
header: string;
payload: string;
signature: string;
headerData: Data;
payloadData: Data;
signatureBytes: Uint8Array;
};
/**
* Split a JSON Web Token into its header, payload, and signature, and decode and parse the JSON.
*/
export declare function splitToken(token: unknown): TokenData;
export declare function _splitToken(caller: AnyFunction, token: unknown): TokenData;
/**
* Decode a JWT, verify it, and return the full payload data.
* - Currently only supports HMAC SHA-512 signing.
*
* @throws ValueError If the input parameters, e.g. `secret` or `issuer`, are invalid.
* @throws RequestError If the token is invalid or malformed.
* @throws UnauthorizedError If the token signature is incorrect, token is expired or not issued yet.
*/
export declare function verifyToken(token: unknown, secret: PossibleBytes): Promise<Data>;