From 1018ca39a22ce9a4fdb270aeb925cc3ebce43b10 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 29 Nov 2024 23:00:42 -0800 Subject: [PATCH] Change some names and fix NanoNaCl worker with a forced name for the Blake2b class that was getting changed by esbuild. --- src/lib/wallet.ts | 4 ++-- src/lib/workers.ts | 4 ++-- src/lib/workers/ckdBip44.ts | 4 ++-- src/lib/workers/nano-nacl.ts | 19 ++++++------------- 4 files changed, 12 insertions(+), 19 deletions(-) diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index d8c4693..e417737 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -10,7 +10,7 @@ import { Entropy } from './entropy.js' import { Pool } from './pool.js' import { Rpc } from './rpc.js' import { Safe } from './safe.js' -import { ckdBip44, nanoNacl } from './workers.js' +import { ckdBip44, NanoNaCl } from './workers.js' import type { Ledger } from './ledger.js' type KeyPair = { @@ -60,7 +60,7 @@ abstract class Wallet { ? new Entropy(id) : new Entropy(16) this.#mnemonic = mnemonic ?? null - this.#pool = new Pool(`(${nanoNacl})(${Blake2b})`) + this.#pool = new Pool(`const Blake2b = ${Blake2b}\n${NanoNaCl}`) this.#safe = new Safe() this.#seed = seed ?? null } diff --git a/src/lib/workers.ts b/src/lib/workers.ts index 02bc056..c8e5202 100644 --- a/src/lib/workers.ts +++ b/src/lib/workers.ts @@ -1,4 +1,4 @@ import ckdBip44 from './workers/ckdBip44.js' -import nanoNacl from './workers/nano-nacl.js' +import NanoNaCl from './workers/nano-nacl.js' // import './workers/passkey.js' -export { ckdBip44, nanoNacl } +export { ckdBip44, NanoNaCl } diff --git a/src/lib/workers/ckdBip44.ts b/src/lib/workers/ckdBip44.ts index 1e8c0a9..0aa91d4 100644 --- a/src/lib/workers/ckdBip44.ts +++ b/src/lib/workers/ckdBip44.ts @@ -6,7 +6,7 @@ type ExtendedKey = { chainCode: DataView } -async function fn () { +const Bip44Ckd = () => { const BIP44_COIN_NANO = 165 const BIP44_PURPOSE = 44 const HARDENED_OFFSET = 0x80000000 @@ -95,4 +95,4 @@ async function fn () { } } -export default `(${fn.toString()})()` +export default Bip44Ckd.toString().substring(Bip44Ckd.toString().indexOf('{') + 1, Bip44Ckd.toString().lastIndexOf('}')) diff --git a/src/lib/workers/nano-nacl.ts b/src/lib/workers/nano-nacl.ts index 0cab73d..d63cef4 100644 --- a/src/lib/workers/nano-nacl.ts +++ b/src/lib/workers/nano-nacl.ts @@ -15,9 +15,7 @@ // 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 -import type { Blake2b } from '../blake2b.js' - -async function NanoNaCl (Blake2b: Blake2b) { +const NanoNaCl = () => { /** * Listens for messages from a calling function. */ @@ -27,8 +25,7 @@ async function NanoNaCl (Blake2b: Blake2b) { postMessage({ publicKey, privateKey, index }) }) - - var gf = function (init?: any) { + var gf = function (init?: number[]) { var i, r = new Float64Array(16) if (init) for (i = 0; i < init.length; i++) r[i] = init[i] return r @@ -858,13 +855,9 @@ async function NanoNaCl (Blake2b: Blake2b) { const seedLength = crypto_sign_SEEDBYTES const signatureLength = crypto_sign_BYTES + return { sign, open, detached, verify, keyPair } } -export const nacl = { - sign: NanoNaCl.sign, - open: NanoNaCl.open, - detached: NanoNaCl.detached, - verify: NanoNaCl.verify, - keyPair: NanoNaCl.keyPair -} -export default NanoNaCl.toString() +export const nacl = NanoNaCl() + +export default NanoNaCl.toString().substring(NanoNaCl.toString().indexOf('{') + 1, NanoNaCl.toString().lastIndexOf('return')) -- 2.34.1