]> git.codecow.com Git - nano25519.git/commitdiff
Move async message data checks prior to execution.
authorChris Duncan <chris@codecow.com>
Fri, 26 Jun 2026 21:50:13 +0000 (14:50 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 26 Jun 2026 21:50:13 +0000 (14:50 -0700)
src/lib/nano25519.ts

index b9c97908d8ecaf9f7a00fb8d750f8b9b1cb01404..286821b49de397d486648901c8ef8642af4b837f 100644 (file)
@@ -198,27 +198,24 @@ const nano25519_worker_init = ({ derive, sign, verify }: typeof nano25519) => {
         */
        function handleMessage (message: unknown): void {
                NODE: if (host == null) return queueMicrotask(() => handleMessage(message))
+               if (message == null
+                       || typeof message !== 'object'
+                       || !('data' in message)
+                       || message.data == null
+                       || typeof message.data !== 'object'
+                       || !('url' in message.data)
+                       || typeof message.data.url !== 'string'
+                       || !('id' in message.data)
+                       || typeof message.data.id !== 'string'
+                       || !('action' in message.data)
+                       || typeof message.data.action !== 'string'
+               ) return
                let result: undefined | boolean | string | Uint8Array<ArrayBuffer>
                let url: undefined | string
                let id: undefined | string
                try {
-                       if (message == null
-                               || typeof message !== 'object'
-                               || !('data' in message)
-                               || message.data == null
-                               || typeof message.data !== 'object'
-                               || !('url' in message.data)
-                               || typeof message.data.url !== 'string'
-                               || !('id' in message.data)
-                               || typeof message.data.id !== 'string'
-                               || !('action' in message.data)
-                               || typeof message.data.action !== 'string'
-                       ) {
-                               throw new TypeError('Invalid nano25519Worker request')
-                       }
                        const data: Data = message.data as object & { url: string, id: string, action: string }
                        { ({ url, id } = data) }
-                       if (typeof url !== 'string' || typeof id !== 'string') return
                        if (url !== client) return
 
                        if (data.action === 'start') {