]> zoso.dev Git - libnemo.git/commitdiff
Fix hexification.
authorChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 22:55:09 +0000 (14:55 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 22:55:09 +0000 (14:55 -0800)
src/lib/nano-nacl.ts

index 62d2732385d572497a3fc2b4818fd79822de2704..9a38cf84d7e6cc2bfd421bff03b2fd487fb8e3cb 100644 (file)
@@ -24,7 +24,7 @@ const n = () => {
        addEventListener('message', message => {\r
                const data = JSON.parse(new TextDecoder().decode(message.data ?? message))\r
                for (const d of data) {\r
-                       d.publicKey = hexify(convert(d.privateKey).publicKey)\r
+                       d.publicKey = convert(d.privateKey)\r
                }\r
                const buf = new TextEncoder().encode(JSON.stringify(data)).buffer\r
                postMessage(buf, [buf])\r
@@ -759,10 +759,10 @@ const n = () => {
        function hexify (buf: Uint8Array): string {\r
                let str = ''\r
                for (let i = 0; i < buf.length; i++) {\r
-                       if (typeof next !== 'number')\r
-                               throw new TypeError(`expected number to convert to hex; received ${typeof next}`)\r
-                       if (next < 0 || next > 255)\r
-                               throw new RangeError(`expected byte value 0-255; received ${next}`)\r
+                       if (typeof buf[i] !== 'number')\r
+                               throw new TypeError(`expected number to convert to hex; received ${typeof buf[i]}`)\r
+                       if (buf[i] < 0 || buf[i] > 255)\r
+                               throw new RangeError(`expected byte value 0-255; received ${buf[i]}`)\r
                        str += buf[i].toString(16).padStart(2, '0')\r
                }\r
                return str\r