UNPKG

@borderless/web-jwt

Version:

Small JWT library using the Web Crypto API

46 lines (45 loc) 1.01 kB
/** * JWT header object. */ export type JwtHeader = { typ?: "JWT"; alg?: string; kid?: string; }; /** * JWT payload object. */ export type JwtPayload = object; /** * JWT none algorithm support. */ export declare const NONE_KEY: unique symbol; /** * Support `none` JWT key. */ export type Key = CryptoKey | typeof NONE_KEY; /** * Raw JWT used for signing. */ export type RawJwt = { header: JwtHeader; payload: JwtPayload; data: Uint8Array; signature: Uint8Array; }; /** * Decode results for invalid JWTs. */ export declare const NOOP_JWT: RawJwt; /** * Decode the JWT using base64url and JSON. */ export declare function decodeJwt(token: string): RawJwt; /** * Verify the JWT contents by deriving the signature from the content. */ export declare function verifyJwt(raw: RawJwt, key: Key): Promise<boolean>; /** * Stringify a JWT payload and sign using crypto key. */ export declare function encodeJwt(header: JwtHeader, payload: JwtPayload, key: Key): Promise<string>;