]> git.codecow.com Git - nano25519.git/commitdiff
Fix output buffers in speed test page.
authorChris Duncan <chris@zoso.dev>
Sun, 6 Sep 2026 08:25:50 +0000 (01:25 -0700)
committerChris Duncan <chris@zoso.dev>
Sun, 6 Sep 2026 08:25:50 +0000 (01:25 -0700)
test/index.html

index 0981e687d17164c41c61614faf778073c5e7b396..2f6743d086ece4c61beebc37d565b9c0ce38499d 100644 (file)
@@ -129,6 +129,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        return [...bytes].map(b => b.toString(16).padStart(2, '0')).join('')
                }
 
+               const outPub = new Uint8Array(32)
+               const outSig = new Uint8Array(64)
+
                /**
                 * @param {Uint8Array} prv
                 * @param {string} api
@@ -137,7 +140,8 @@ SPDX-License-Identifier: GPL-3.0-or-later
                const derive = (prv, api) => {
                        switch (api) {
                                case 'nano25519': {
-                                       return nano25519.derive(prv)
+                                       nano25519.derive(prv, outPub)
+                                       return outPub
                                }
                                case 'NanocurrencyWeb': {
                                        const { publicKey } = NanocurrencyWeb.wallet.legacyAccounts(b2a(prv))[0]
@@ -165,9 +169,9 @@ SPDX-License-Identifier: GPL-3.0-or-later
                const sign = (msg, prv, pub, api) => {
                        const sk = new Uint8Array([...prv, ...pub])
                        switch (api) {
-                               case 'nano25519':
-                               case 'nano25519 with bulk block verification': {
-                                       return nano25519.sign(msg, prv, pub)
+                               case 'nano25519': {
+                                       nano25519.sign(msg, prv, pub, outSig)
+                                       return outSig
                                }
                                case 'NanocurrencyWeb': {
                                        const { privateKey } = NanocurrencyWeb.wallet.legacyAccounts(b2a(prv))[0]
@@ -266,13 +270,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
                        failures += +!test
 
                        result = nano25519.derive(NANO_ORG_VECTOR.privateKeyBytes)
-                       test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase()
+                       test = result.toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase()
                        check(`derive from bytes ${NANO_ORG_VECTOR.privateKey}`, test)
                        passes += +test
                        failures += +!test
 
                        result = nano25519.sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.privateKeyBytes, NANO_ORG_VECTOR.publicKeyBytes)
-                       test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase()
+                       test = result.toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase()
                        check(`sign message bytes ${NANO_ORG_VECTOR.blockHash}`, test)
                        passes += +test
                        failures += +!test
@@ -309,13 +313,13 @@ SPDX-License-Identifier: GPL-3.0-or-later
                                const signatureBytes = new Uint8Array(signature.match(/.{2}/g)?.slice(0, 64).map(b => parseInt(b, 16)) ?? [])
 
                                result = nano25519.derive(privateKeyBytes)
-                               test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === publicKey
+                               test = result.toLowerCase() === publicKey
                                check(`derive from ${privateKey}`, test)
                                passes += +test
                                failures += +!test
 
                                result = nano25519.sign(messageBytes, privateKeyBytes, publicKeyBytes)
-                               test = [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === signature.slice(0, 128)
+                               test = result.toLowerCase() === signature.slice(0, 128)
                                check(`sign message ${message}`, test)
                                passes += +test
                                failures += +!test