From d2bf2c8b4ef3bdc9d562048c3d9e01057dbe360c Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Thu, 28 Nov 2024 02:21:21 -0800 Subject: [PATCH] Begin refactoring NaCl implementation to a web worker format. --- src/lib/workers/nano-nacl.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/lib/workers/nano-nacl.ts b/src/lib/workers/nano-nacl.ts index 41b850e..8e2b9b4 100644 --- a/src/lib/workers/nano-nacl.ts +++ b/src/lib/workers/nano-nacl.ts @@ -17,6 +17,16 @@ import { Blake2b } from '../blake2b.js' // See for details: https://docs.nano.org/integration-guides/the-basics/ // Original source commit: https://github.com/dchest/tweetnacl-js/blob/71df1d6a1d78236ca3e9f6c788786e21f5a651a6/nacl-fast.js +async function fn () { + /** + * Listens for messages from a calling function. + */ + addEventListener('message', (message) => { + const { privateKey, index } = message.data ?? message + keyPair.fromSeed(seed).then(publicKey => postMessage({ publicKey, privateKey, index })) + }) + + var gf = function(init?: any) { var i, r = new Float64Array(16); if (init) for (i = 0; i < init.length; i++) r[i] = init[i]; @@ -880,5 +890,7 @@ const setPRNG = function(fn) { } } })(); +} -export const nacl = { sign, open, detached, verify, keyPair, publicKeyLength, secretKeyLength, seedLength, signatureLength } \ No newline at end of file +export const nacl = { sign, open, detached, verify, keyPair, publicKeyLength, secretKeyLength, seedLength, signatureLength } +export default `(${fn.toString()})()` -- 2.34.1