Skip to content

Instantly share code, notes, and snippets.

@andywer
Created December 28, 2019 07:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andywer/925395687f42f6da04d111adf7d428ac to your computer and use it in GitHub Desktop.
Save andywer/925395687f42f6da04d111adf7d428ac to your computer and use it in GitHub Desktop.
threads.js super simple hashing example
const sha256 = require("js-sha256")
const { expose } = require("threads/worker")
expose({
hashPassword(password, salt) {
return sha256(password + salt)
}
})
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)
{
"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