/** * @pwngh/economy-lab * * Copyright (c) Preston Neal * * This source code is licensed under the MIT license found in the * LICENSE.md file in the root directory of this source tree. * * @license MIT */ import { toHex } from './bytes.js'; import type { Clock, Digest, Ids, Logger, Meter, Scheduler, Signer } from './ports.js'; /** * Production clock reading wall-clock time. Time is read only through a clock, * never `Date.now` directly elsewhere, so tests can swap in a fake. */ export declare function systemClock(): Clock; /** * Fake clock for tests. Frozen at `start` (epoch ms); only `advance(ms)` moves * it forward, returning the new time. Keeps test outcomes repeatable. * * @example * const clock = fixedClock(Date.UTC(2026, 6, 1)); * // ...subscribe against an economy wired with this clock... * clock.advance(31 * 24 * 60 * 60 * 1000); // a month passes; the renewal is due * await worker.sweep(); // the sweep reads the advanced time */ export declare function fixedClock(start?: number): Clock & { advance: (ms: number) => number; }; /** * Production id generator. Each id is `prefix_` (e.g. `txn_3f2a...`), * so ids are effectively unique without cross-machine coordination. */ export declare function randomIds(): Ids; /** * Predictable id generator for tests. Counts up from `seed` (`prefix_1`, * `prefix_2`, ...), so a test produces the same ids every run. The counter is * shared across prefixes: it increments on every call, whatever the prefix. * * @example * const ids = sequentialIds(); * ids.next('txn'); // 'txn_1' * ids.next('evt'); // 'evt_2' — one counter, not one per prefix */ export declare function sequentialIds(seed?: number): Ids; /** * Production hasher. Returns the shared SHA-256 {@link Digest} (`sha256Digest`): a synchronous * node:crypto hash where the runtime offers one, else Web Crypto. The same bytes hash to the same * value on every runtime, so a signed checkpoint re-derives wherever it is verified. */ export declare function systemDigest(): Digest; /** * Production signer. Signs bytes with Ed25519 so an auditor can confirm a checkpoint wasn't * rewritten using only the published public key. * * `sign` always uses the current key. `verify` accepts a signature from the current key or any * prior key passed in, so a checkpoint signed under the old key still verifies across a key * rotation. * * Both work on raw bytes. Hex encoding of keys and stored signatures happens at the storage * boundary, not here. * * @see {@link https://economy-lab-docs.pages.dev/economy/ports/signer/ Signer} for the signing and * key-rotation contract. */ export declare function systemSigner(options: { signingKey: string; priorKeys?: ReadonlyArray; }): Signer; /** * Hex-encoded raw 32-byte Ed25519 public key derived from `signingKey`. Publish it so an external * party can verify signed checkpoints without the signing secret. */ export declare function signingPublicKeyHex(signingKey: string): Promise; /** * Bundles the four capabilities (clock, id generator, hasher, signer) into one * object for a production host to wire in. * * `signingKey` and any `priorKeys` are hex-encoded secret key bytes the host * loads from its own config and passes in; this module never reads them from a * global or the environment. */ export declare function systemRuntime(options: { signingKey: string; priorKeys?: ReadonlyArray; }): { clock: Clock; ids: Ids; digest: Digest; signer: Signer; }; /** * Structured logger for production hosts. Each call writes one JSONL object, * shaped `{ts, level, service, event, ...fields}`, for log collectors to parse * line by line. By default every level writes to stderr (info, debug, and warn * via `console.warn`; error via `console.error`); supply `out` and `err` to * route the two separately. Implements the same `Logger` interface as the * no-op default, so a host can swap it in directly. * * Supply `now` (epoch ms) so a test can freeze the timestamp and check the exact * line; it defaults to wall-clock time. `service` names the emitting process and * appears on every line. */ export declare function jsonlLogger(options?: { service?: string; now?: () => number; out?: (line: string) => void; err?: (line: string) => void; }): Logger; /** A Logger that discards every line: the silent default for a host that wants no log output. */ export declare function silentLogger(): Logger; /** * The built-in fallback {@link Scheduler} for hosts that inject none: a plain interval timer. * The worker's `start` and the instance-economy manager's `start` both fall back to it. */ export declare function intervalScheduler(): Scheduler; /** A Meter that discards every count and observation: the default when a host collects no metrics. */ export declare function silentMeter(): Meter; export { toHex };