/** * SHA-256 over a UTF-8 string, in plain TypeScript. * * **Why the package carries an implementation instead of taking a port**, when * `run/receipts.ts` deliberately does the opposite. Two differences decide it. * * The first is *when* the digest is needed. A receipt's hash is taken inside an * already-async tool dispatch, so `crypto.subtle.digest` — which is async * everywhere, and is the only digest workerd has — fits without changing any * signature. A skill's `contentSha` is computed at **registration**, which is * the synchronous act of a module declaring what it contributes. Taking an * async digest there forces either an async `register()` (so a plugin's * registration becomes something a host must await and order) or a lazily * resolved hash on every read path that wants one. Both cost more than this * file. * * The second is *what the value means*. A receipt hash is persisted by the host * forever and compared against rows written by earlier versions, so the host * must own the algorithm choice — and its input is tool arguments, routinely * user data, which is why that doc argues preimage resistance. A `contentSha` * identifies build content within one deployment: it is derived from source the * deployment already ships, and nothing reads it that did not just compute it. * * A host with a native digest can still supply one — {@link Sha256Hex} is a * parameter everywhere this is used — but it must be synchronous and it must be * SHA-256, or the hashes two hosts compute for the same skill diverge. * * The implementation is the FIPS 180-4 reference algorithm with no shortcuts. * `__tests__/sha256.test.ts` pins it against the published vectors, plus a * multi-block and a multi-byte-UTF-8 case, because a hash that is subtly wrong * fails silently: every value still looks like a hash. */ /** A synchronous SHA-256 that returns lowercase hex. */ export type Sha256Hex = (text: string) => string; /** SHA-256 (lowercase hex) of a UTF-8 string. */ export declare const sha256Hex: Sha256Hex; /** Byte length of a string in UTF-8 — what a resource listing reports. */ export declare function utf8ByteLength(text: string): number;