/** What the secrets module answers GET /secrets/fields/keys with. */ export interface FieldKeySet { keys: Array<{ id: string; key: string; activates_at: string; }>; lookup: string; } /** A field that is not an encrypted one, or does not open here. */ export declare class FieldError extends Error { /** `not_loaded`, `not_encrypted` (a plain value where an encrypted one belongs), `unknown_key` or `unopenable` */ readonly code: 'not_loaded' | 'not_encrypted' | 'unknown_key' | 'unopenable'; constructor(code: FieldError['code'], message: string); } export declare const FIELD_PREFIX = "pbe1."; export declare const LOOKUP_PREFIX = "pbl1."; /** How often the keys are fetched again: well inside a rotation's five minutes. */ export declare const REFRESH_MS = 60000; /** Whether address names a field: table.column, or schema.table.column. */ export declare function validAddress(address: string): boolean; export interface FieldsOptions { /** Reads the project's keys (the secrets module's GetFieldKeys). */ fetch: (signal?: AbortSignal) => Promise; /** The clock a key's coming into force is read by (tests). */ now?: () => number; } /** * The project's encrypted fields. `await load()` once at startup; after it, * encrypt, decrypt and lookup are synchronous — what a column transform runs * inside a query. */ export declare class Fields { private crypto; private keys; private lookupKey; private timer; private readonly opts; private readonly now; constructor(opts: FieldsOptions); /** Whether the keys are loaded. */ get loaded(): boolean; /** * Reads the keys, and keeps reading them every minute until close(). A * failed refresh keeps the keys held: the next one tries again. */ load(signal?: AbortSignal): Promise; /** Stops the refresh. */ close(): void; private take; private ready; /** The id of the key new values are sealed with now: the newest in force. */ currentKey(): string; /** Encrypts value as the field at address. */ encrypt(address: string, value: string): string; /** Opens the field at address. A plain value, another column's, a tampered one or one sealed with a key not held is refused (FieldError). */ decrypt(address: string, value: string): string; /** Whether value is an encrypted field (sealed with any key), without opening it. */ isEncrypted(value: string): boolean; /** What the field at address holding value is found by. */ lookup(address: string, value: string): string; }