kestrel.markets
Version:
A typed, token-efficient language + runtime for agentic trading: agents author bounded plans, the runtime fires them at the tick. CLI + typed library + MCP server.
33 lines • 2.34 kB
TypeScript
/**
* # crypto/sha256 — the one portable, synchronous sha256 the runtime hashes with (kestrel-alw.17)
*
* Content-addressing is woven through the whole grade path as **pure, synchronous** functions:
* {@link ../grade/receipt.ts createReceipt}, {@link ../blotter/project.ts project}, the {@link ../ledger
* ledger}'s `deriveRunId`, and the sim driver's bus hash all take a sha256 of a canonical string and must
* return it inline — no `await`. Bun's `Bun.CryptoHasher` gives exactly that (a synchronous `.digest`), but
* it is a **Bun-only** global: it does not exist in a Cloudflare Worker isolate, which is where the grade
* path must also run (ADR-0006, EPIC kestrel-markets-alw). WebCrypto (`crypto.subtle.digest`) IS present in
* a Worker but is **async**, and threading `await` through every content-address would break the
* pure-function doctrine the determinism check relies on (RUNTIME §0).
*
* The resolution of that sync-vs-async tension is this module: ONE synchronous `sha256(text)` that is
* portable across environments. It uses Bun's native hasher when the `Bun` global is present (the fast path
* under `bun test` / the CLI) and a self-contained pure-JS SHA-256 otherwise (the Worker isolate). Both code
* paths produce **byte-identical** output — a determinism guarantee locked down by a parity test that runs
* BOTH implementations over the same inputs ({@link sha256Pure} is exported so the Worker path is directly
* testable even under Bun). No wall clock, no RNG.
*/
/**
* Pure-JS SHA-256 over the UTF-8 bytes of `text` → a 64-char lowercase hex digest (FIPS 180-4). This is the
* Worker-portable path (no `Bun` global, no async `crypto.subtle`). Exported so the parity test can exercise
* it directly even under Bun, proving it matches the native hasher byte-for-byte.
*/
export declare function sha256Pure(text: string): string;
/**
* The portable, synchronous sha256 of a UTF-8 string → 64-char lowercase hex. Uses Bun's native
* `CryptoHasher` when the `Bun` global is present (fast path under `bun test` / the CLI) and the pure-JS
* {@link sha256Pure} otherwise (a Cloudflare Worker isolate). Both paths are byte-identical (parity test).
* Deterministic — no wall clock, no RNG.
*/
export declare function sha256(text: string): string;
//# sourceMappingURL=sha256.d.ts.map