Created
December 28, 2019 07:44
-
-
Save andywer/925395687f42f6da04d111adf7d428ac to your computer and use it in GitHub Desktop.
threads.js super simple hashing example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const sha256 = require("js-sha256") | |
const { expose } = require("threads/worker") | |
expose({ | |
hashPassword(password, salt) { | |
return sha256(password + salt) | |
} | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { spawn, Thread, Worker } = require("threads") | |
async function main() { | |
const auth = await spawn(new Worker("./auth")) | |
const hashed = await auth.hashPassword("Super secret password", "1234") | |
console.log("Hashed password:", hashed) | |
await Thread.terminate(auth) | |
} | |
main().catch(console.error) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "threads.js-hashing-sample", | |
"version": "0.0.0", | |
"license": "MIT", | |
"private": true, | |
"dependencies": { | |
"js-sha256": "^0.9.0", | |
"threads": "^1.0.0-beta.9" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment