Skip to content

fix: inline synchronous sha1, drop node crypto import (#643) - #645

Merged
BelfordZ merged 2 commits into
masterfrom
fix/643-inline-sha1
Oct 17, 2026
Merged

BelfordZ merged 2 commits into
masterfrom
fix/643-inline-sha1

Conversation

@belfordzjeeves

Copy link
Copy Markdown
Contributor

What

getDefaultTitleForSchema no longer imports Node's crypto, so the package runs in browser bundles (Vite etc. don't polyfill it, and Web Crypto has no createHash).

  • New src/sha1.ts: synchronous SHA-1 over the UTF-8 encoding of the input plus hand-written base64 over the 20 digest bytes. No new dependency, no btoa, no Buffer — works in browsers and Node alike.
  • src/index.ts: createHash("sha1").update(asString).digest("base64") replaced with sha1Base64(asString); the hashRegex friendly-hash logic is untouched.
  • New src/sha1.test.ts: known-answer vectors (empty, ASCII, 2/3/4-byte UTF-8, lone surrogates, 55/56-byte padding boundaries, long input) pinning the byte-compatibility contract.

Byte-compatibility verification

  • Differential check against live Node createHash("sha1"): 18/18 inputs byte-identical, including empty string, emoji, mixed multi-byte, lone high/low surrogates, padding-boundary lengths (55/56/57/64/119/120), and 100k-char inputs (throwaway script, not committed).
  • Existing suite passes unchanged, including the hardcoded title oracles (string_doaGddGA, oneOf_number_Ho1clIqD_self_string_doaGddGA_wGyf9nC9) — generated names are unchanged.
  • npm test (28/28, coverage thresholds met), npm run lint, and npm run build:code all green. No crypto references remain in src/ or build/.

Out of scope

The playground's shims/crypto.mjs alias can be deleted once a titleizer release with this change ships.

@BelfordZ
BelfordZ merged commit 21b40e5 into master Oct 17, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants