UNPKG

2.27 kBTypeScriptView Raw
1import type { CookieInit, CookieList, CookieListItem, CookieStore, CookieStoreDeleteOptions, CookieStoreGetOptions } from 'cookie-store-interface';
2export * from 'cookie-store-interface';
3export interface SignedCookieStoreOptions {
4 /**
5 * One or more crypto keys that were previously used to sign cookies.
6 * `SignedCookieStore` will try to verify the signature using these, but they are not used for signing.
7 */
8 keyring?: readonly CryptoKey[];
9}
10export interface DeriveOptions {
11 secret: string | BufferSource | JsonWebKey;
12 salt?: BufferSource;
13 iterations?: number;
14 format?: KeyFormat;
15 hash?: HashAlgorithmIdentifier;
16 hmacHash?: HashAlgorithmIdentifier;
17 length?: number;
18}
19/**
20 * # Signed Cookie Store
21 * A partial implementation of the [Cookie Store API](https://wicg.github.io/cookie-store)
22 * that transparently signs and verifies cookies via the Web Cryptography API.
23 *
24 * This is likely only useful in server-side implementations,
25 * but written in a platform-agnostic way.
26 */
27export declare class SignedCookieStore implements CookieStore {
28 #private;
29 /**
30 * A helper function to derive a crypto key from a passphrase.
31 */
32 static deriveCryptoKey(opts: DeriveOptions): Promise<CryptoKey>;
33 constructor(store: CookieStore, key: CryptoKey, opts?: SignedCookieStoreOptions);
34 /**
35 * @throws if the signature doesn't match.
36 * @returns null when the signature cookie is missing.
37 */
38 get(name?: string): Promise<CookieListItem | null>;
39 get(options?: CookieStoreGetOptions): Promise<CookieListItem | null>;
40 /**
41 * @throws if any signature doesn't match.
42 * @returns A list of cookies, exclusive of all cookies without signatures
43 */
44 getAll(name?: string): Promise<CookieList>;
45 getAll(options?: CookieStoreGetOptions): Promise<CookieList>;
46 set(name: string, value: string): Promise<void>;
47 set(options: CookieInit): Promise<void>;
48 delete(name: string): Promise<void>;
49 delete(options: CookieStoreDeleteOptions): Promise<void>;
50 addEventListener(...args: Parameters<CookieStore['addEventListener']>): void;
51 dispatchEvent(event: Event): boolean;
52 removeEventListener(...args: Parameters<CookieStore['removeEventListener']>): void;
53}