GitHub - montyanderson/ts-sha256: sha-256 computed entirely by the typescript type checker. zero runtime. · GitHub
/" data-turbo-transient="true" />
Skip to content
Search or jump to...
Search code, repositories, users, issues, pull requests...
-->
Search
Clear
Search syntax tips
Provide feedback
--><br>We read every piece of feedback, and take your input very seriously.
Include my email address so I can be contacted
Cancel
Submit feedback
Saved searches
Use saved searches to filter your results more quickly
-->
Name
Query
To see all available qualifiers, see our documentation.
Cancel
Create saved search
Sign in
/;ref_cta:Sign up;ref_loc:header logged out"}"<br>Sign up
Appearance settings
Resetting focus
You signed in with another tab or window. Reload to refresh your session.<br>You signed out in another tab or window. Reload to refresh your session.<br>You switched accounts on another tab or window. Reload to refresh your session.
Dismiss alert
{{ message }}
montyanderson
ts-sha256
Public
Notifications<br>You must be signed in to change notification settings
Fork
Star
main
BranchesTags
Go to file
CodeOpen more actions menu
Folders and files<br>NameNameLast commit message<br>Last commit date<br>Latest commit
History<br>2 Commits<br>2 Commits
demo
demo
.gitignore
.gitignore
README.md
README.md
package.json
package.json
sha256.ts
sha256.ts
tsconfig.json
tsconfig.json
View all files
Repository files navigation
ts-sha256
sha-256 computed entirely by the typescript type checker. zero runtime.
// ^? "da408360ba4fd661aaaacb205dd680fc71280558627f45f99dd2b5f578cbb506"">import type { SHA256 } from "./sha256";
type Hash = SHA256"Input string">;<br>// ^? "da408360ba4fd661aaaacb205dd680fc71280558627f45f99dd2b5f578cbb506"
the type-level program faithfully implements fips 180-4: bits live in 32-tuples of 0 | 1, a ripple-carry adder does mod-2³² addition, the message schedule and 64-round compression run as tail-recursive conditional types. running tsc --noEmit is the hash.
install
pnpm install
use it
drop sha256.ts into your project and import SHA256. that's the whole api.
; // "e3b0c442..."<br>type B = SHA256; // "ba7816bf..."">import type { SHA256 } from "./sha256";
type A = SHA256"">; // "e3b0c442..."<br>type B = SHA256"abc">; // "ba7816bf..."
input is a printable-ascii string literal. output is a 64-char lowercase hex string literal. unsupported characters resolve to never.
run the tests
the test vectors are compile-time Assert> declarations. if tsc exits clean, they passed.
NODE_OPTIONS="--max-old-space-size=12288" pnpm exec tsc --noEmit
the big heap reservation is required — the checker allocates a lot of intermediate tuple types.
limits
printable ascii + a few control chars. non-ascii → never.
single 512-bit block (≤ 55 bytes) is what i actually tested. longer inputs are implemented but will probably exhaust the type checker.
expect ~20s per hash on a modern laptop.
About
sha-256 computed entirely by the typescript type checker. zero runtime.
Topics
cryptography
typescript
sha256
type-level-programming
Resources
Readme
Uh oh!
There was an error while loading. Please reload this page.
Activity
Stars
stars
Watchers
watching
Forks
forks
Report repository
Releases
No releases published
Packages
Uh oh!
There was an error while loading. Please reload this page.
Contributors
Uh oh!
There was an error while loading. Please reload this page.
Languages
TypeScript<br>100.0%
You can’t perform that action at this time.