UNPKG

paseto-ts

Version:

PASETO v4 (encrypt, decrypt, sign & verify) in TypeScript

80 lines (79 loc) 3.56 kB
import { Assertion, Footer, Payload } from "./types.js"; /** * Parses a key and ensures it is a valid key for the given type * @param {string} purpose Purpose of the key. Must be one of `local`, `secret` or `public`. * @param {string | Uint8Array} key Key to parse. **Must contain the magic string (or bytes) for the given purpose.** * @returns {Uint8Array} Parsed key * @see https://github.com/paseto-standard/paseto-spec/blob/master/docs/02-Implementation-Guide/03-Algorithm-Lucidity.md */ export declare function parseKeyData(purpose: 'local' | 'secret' | 'public', key: string | Uint8Array, { version }?: { version?: 'v4'; }): Uint8Array; /** * Splits a PASETO v4.public token into its parts * @param {string | Uint8Array} token Token to split * @returns {object} Object containing the token parts */ export declare function parsePublicToken(token: string | Uint8Array): { payload: Uint8Array<ArrayBufferLike>; message: Uint8Array<ArrayBufferLike>; signature: Uint8Array<ArrayBufferLike>; footer: Uint8Array<ArrayBufferLike>; }; /** * Splits a PASETO v4.secret token into its parts * @param {string | Uint8Array} token Token to split * @returns {object} Object containing the token parts */ export declare function parseLocalToken(token: string | Uint8Array): { payload: Uint8Array<ArrayBufferLike>; nonce: Uint8Array<ArrayBuffer>; tag: Uint8Array<ArrayBuffer>; ciphertext: Uint8Array<ArrayBuffer>; footer: Uint8Array<ArrayBufferLike>; }; /** * Parse and validate the payload of a message * @param {string | object | Uint8Array} obj Payload to validate * @see https://github.com/paseto-standard/paseto-spec/blob/master/docs/02-Implementation-Guide/01-Payload-Processing.md#payload-processing */ export declare function parsePayload(payload: string | Payload | Uint8Array, { addIat, // Add an iat claim if one is not provided addExp, // Add an exp claim if one is not provided: maxDepth, // Maximum depth of the JSON object maxKeys, // Maximum number of keys in the JSON object validate, }?: { addIat?: boolean; addExp?: boolean; maxDepth?: number; maxKeys?: number; validate?: boolean; }): Payload; /** * Assert that the footer is a Uint8Array. Parses a string footer into a Uint8Array. * If the footer is JSON, the `kid` and `wpk` claims will be validated. * @param {Footer | string | Uint8Array} footer The footer to assert. * @returns {Uint8Array} footer as a Uint8Array. * @see https://github.com/paseto-standard/paseto-spec/blob/master/docs/02-Implementation-Guide/04-Claims.md#optional-footer-claims */ export declare function parseFooter(footer: Footer | string | Uint8Array, { maxDepth, maxKeys, validate }?: { maxDepth?: number; maxKeys?: number; validate?: boolean; }): Uint8Array; /** * Assert that the assertion is a Uint8Array. Parses a string assertion into a Uint8Array. * @param {Assertion | string | Uint8Array} assertion The assertion to assert. * @returns {Uint8Array} assertion as a Uint8Array. */ export declare function parseAssertion(assertion: Assertion | string | Uint8Array): Uint8Array; /** * Derives an encryption key, counter nonce, and auth key from a key and nonce. * @param {Uint8Array} key Local key. * @param {Uint8Array} nonce Local nonce. * @returns {object} Encryption and auth keys. */ export declare function deriveEncryptionAndAuthKeys(key: Uint8Array, nonce: Uint8Array): { encryptionKey: Uint8Array<ArrayBuffer>; counterNonce: Uint8Array<ArrayBuffer>; authKey: Uint8Array<ArrayBufferLike>; };