]> git.codecow.com Git - nano25519.git/commitdiff
Remove extraneous error logging,
authorChris Duncan <chris@zoso.dev>
Wed, 12 Aug 2026 09:21:29 +0000 (02:21 -0700)
committerChris Duncan <chris@zoso.dev>
Wed, 12 Aug 2026 09:21:29 +0000 (02:21 -0700)
src/lib/nano25519.ts

index 3c9907509ce8185ed7a0d0f38a513be20fc4a8b1..308728319f3e4c70471d7fa8964a4b01c7a050c6 100644 (file)
@@ -151,15 +151,18 @@ const nano25519_init = (bytes: number[]): { derive: typeof derive, sign: typeof
                if (typeof name !== 'string') {
                        throw new TypeError(`Invalid name ${name}`)
                }
-               if (typeof byteLengthMin !== 'number' || typeof byteLengthMax !== 'number') {
-                       throw new TypeError(`Invalid byte length for ${name}`)
+               if (typeof byteLengthMin !== 'number') {
+                       throw new TypeError(`Invalid minimum byte length for ${name}`)
+               }
+               if (typeof byteLengthMax !== 'number') {
+                       throw new TypeError(`Invalid maximum byte length for ${name}`)
                }
                if (typeof value === 'string') {
                        if (/[^0-9a-f]/i.test(value)) {
-                               throw new TypeError(`Invalid hexadecimal characters in ${name} ${value}`)
+                               throw new TypeError(`Invalid hexadecimal characters in ${name}`)
                        }
                        if (value.length & 1 || value.length < (byteLengthMin << 1) || value.length > (byteLengthMax << 1)) {
-                               throw new TypeError(`Invalid hexadecimal length ${value.length} for ${name} ${value}`)
+                               throw new TypeError(`Invalid hexadecimal length ${value.length} for ${name}`)
                        }
                        value = new Uint8Array(value.match(/[0-9a-f]{2}/gi)?.map(b => parseInt(b, 16)) || [])
                }
@@ -308,7 +311,7 @@ function init (): void {
                isWorkerReady = true
        } catch (err: any) {
                isWorkerReady = false
-               throw new Error('nano25519 initialization failed.', { cause: err })
+               throw new Error('nano25519 initialization failed')
        }
 }
 
@@ -372,13 +375,13 @@ async function dispatch (data: { [key: string]: string | ArrayBuffer | Uint8Arra
                        if (data.url !== url) return
                        if (data.id !== id) return
                        const { result } = data
-                       console.log(`received result from worker: `, result)
+                       console.log('received result from worker')
                        if (typeof result !== 'boolean' && typeof result !== 'string' && !isBytes(result)) {
                                return reject('Invalid return type')
                        }
                        resolve(result)
                }
-               console.log(`sending data to worker: `, data)
+               console.log('sending data to worker')
                data.url = url
                data.id = id
                BROWSER: {
@@ -435,25 +438,22 @@ export async function run (data: Record<string, string | Uint8Array<ArrayBuffer>
        try {
                await start()
        } catch (err: any) {
-               console.error(err?.stack ?? err)
                throw new Error('Error initializing worker')
        }
        try {
                const result = await dispatch(data)
                if (typeof result === 'string' && !/^([0-9a-f]{64}|[0-9a-f]{128})$/i.test(result)) {
-                       throw new Error(result)
+                       throw new Error('Invalid result')
                }
                return result
        } catch (err: any) {
-               console.error(err)
-               console.error(data)
                try {
                        await stop()
                } catch (e: any) {
-                       console.error('failed to stop worker', err?.message ?? err ?? 'unknown reason')
+                       console.error('failed to stop worker')
                        reset()
                } finally {
-                       throw new Error(err?.message ?? err ?? 'unknown error')
+                       throw new Error('Error dispatching async request')
                }
        }
 }