UNPKG

@worker-tools/encrypted-cookie-store

Version:

A partial implementation of the Cookie Store API that transparently encrypts and decrypts cookies via AES-GCM.

44 lines (43 loc) 2.01 kB
import type { CookieInit, CookieList, CookieListItem, CookieStore, CookieStoreDeleteOptions, CookieStoreGetOptions } from 'cookie-store-interface'; export * from 'cookie-store-interface'; export interface EncryptedCookieStoreOptions { /** * One or more crypto keys that were previously used to encrypt cookies. * `EncryptedCookieStore` will try to decrypt cookies using these, but they are not used for encrypting new cookies. */ keyring?: readonly CryptoKey[]; } export interface DeriveOptions { secret: string | BufferSource | JsonWebKey; salt?: BufferSource; iterations?: number; format?: KeyFormat; hash?: HashAlgorithmIdentifier; hmacHash?: HashAlgorithmIdentifier; length?: number; } /** * # Encrypted Cookie Store * A partial implementation of the [Cookie Store API](https://wicg.github.io/cookie-store) * that transparently encrypts and decrypts cookies via AES-GCM. * * This is likely only useful in server-side implementations, * but written in a platform-agnostic way. */ export declare class EncryptedCookieStore implements CookieStore { #private; /** A helper function to derive a crypto key from a passphrase */ static deriveCryptoKey(opts: DeriveOptions): Promise<CryptoKey>; constructor(store: CookieStore, key: CryptoKey, opts?: EncryptedCookieStoreOptions); get(name?: string): Promise<CookieListItem | null>; get(options?: CookieStoreGetOptions): Promise<CookieListItem | null>; getAll(name?: string): Promise<CookieList>; getAll(options?: CookieStoreGetOptions): Promise<CookieList>; set(name: string, value: string): Promise<void>; set(options: CookieInit): Promise<void>; delete(name: string): Promise<void>; delete(options: CookieStoreDeleteOptions): Promise<void>; addEventListener(...args: Parameters<CookieStore['addEventListener']>): void; dispatchEvent(event: Event): boolean; removeEventListener(...args: Parameters<CookieStore['removeEventListener']>): void; }