UNPKG

@veraid/kliento

Version:

Self-contained client authentication tokens

51 lines (50 loc) 2.2 kB
import { Chain, SignatureBundle } from '@relaycorp/veraid'; import { Token } from './Token.js'; import { TokenBundleOptions } from './TokenBundleOptions.js'; import { TokenBundleVerification } from './TokenBundleVerification.js'; import { TokenBundleVerificationOptions } from './TokenBundleVerificationOptions.js'; /** * Kliento token bundle. */ export declare class TokenBundle { protected constructor(signatureBundle: SignatureBundle); /** * Deserialise a token bundle. * @param serialisation - The serialisation of the token bundle. * @returns A new token bundle. */ static deserialise(serialisation: ArrayBuffer): TokenBundle; /** * Deserialise a token bundle from an authorization header. * @param header - The authorization header. * @returns The token bundle. * @throws An error if the authorization scheme is not "Kliento" or the token bundle is malformed. * * This value requires the scheme "Kliento" and the token bundle to be base64-encoded. */ static deserialiseFromAuthHeader(header: string): TokenBundle; /** * Sign a token. * @param token - The token to sign. * @param privateKey - The private key to sign the token with. * @param chain - The chain to sign the token with. * @param expiry - The expiry date of the token. * @param options - The options for the token bundle. * @returns A new token bundle. */ static sign(token: Token, privateKey: CryptoKey, chain: Chain, expiry: Date, options?: Partial<TokenBundleOptions>): Promise<TokenBundle>; /** * Serialise the token bundle. * @returns The serialised token bundle. */ serialise(): ArrayBuffer; /** * Verify the token bundle. * @param audience - The required audience of the token. * @param options - Verification options. * @param options.date - The date at which to verify the token bundle. * @param options.trustAnchors - The trust anchors with which to verify the token bundle. * @returns The token claims. */ verify(audience: string, { date, trustAnchors }?: Partial<TokenBundleVerificationOptions>): Promise<TokenBundleVerification>; }