]> git.codecow.com Git - nano25519.git/commitdiff
Add tests for output buffers larger than necessary but still offset by 0.
authorChris Duncan <chris@codecow.com>
Fri, 14 Aug 2026 23:21:06 +0000 (16:21 -0700)
committerChris Duncan <chris@codecow.com>
Fri, 14 Aug 2026 23:21:06 +0000 (16:21 -0700)
test.mjs

index 93c4ac453abe7ae557936921cbdc654cba30a62b..b4b515819436463ef47bf9f8e2638bb7db6b2a05 100644 (file)
--- a/test.mjs
+++ b/test.mjs
@@ -359,6 +359,28 @@ check(`sign message bytes ${NANO_ORG_VECTOR.blockHash} and allocate result to ou
 passes += +test
 failures += +!test
 
+outbuf = new Uint8Array(new ArrayBuffer(96), 0, 32)
+result = derive(NANO_ORG_VECTOR.privateKeyBytes, outbuf)
+test = overlaps(result, outbuf)
+test &&= [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase()
+test &&= [...outbuf].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase()
+test &&= [...new Uint8Array(result.buffer)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() !== NANO_ORG_VECTOR.publicKey.toLowerCase()
+test &&= [...new Uint8Array(outbuf.buffer)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() !== NANO_ORG_VECTOR.publicKey.toLowerCase()
+check(`derive from private key bytes ${NANO_ORG_VECTOR.privateKey} and allocate result to output buffer`, test)
+passes += +test
+failures += +!test
+
+outbuf = new Uint8Array(new ArrayBuffer(96), 0, 64)
+result = sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.secretKeyBytes, outbuf)
+test = overlaps(result, outbuf)
+test &&= [...result].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase()
+test &&= [...outbuf].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase()
+test &&= [...new Uint8Array(result.buffer)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() !== NANO_ORG_VECTOR.publicKey.toLowerCase()
+test &&= [...new Uint8Array(outbuf.buffer)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() !== NANO_ORG_VECTOR.publicKey.toLowerCase()
+check(`sign message bytes ${NANO_ORG_VECTOR.blockHash} and allocate result to output buffer`, test)
+passes += +test
+failures += +!test
+
 // Check sync imports with byte inputs and offset output buffer
 length = 33 + crypto.getRandomValues(new Uint8Array(1))[0]
 outbuf = new Uint8Array(new ArrayBuffer(length), length - 32, 32)