From 1f482e480cd208feb012545ec70ed26eede2c2cd Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 16 Aug 2026 03:32:44 -0700 Subject: [PATCH] Test offset buffers with exact matches against untouched ranges. --- test/node.mjs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/test/node.mjs b/test/node.mjs index 4858ed9..66f9bed 100644 --- a/test/node.mjs +++ b/test/node.mjs @@ -334,7 +334,7 @@ inbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 32) inbuf.set(NANO_ORG_VECTOR.privateKeyBytes) outbuf = new Uint8Array(32) derive(inbuf, outbuf) -test &&= [...outbuf].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() check(`derive from private key bytes ${NANO_ORG_VECTOR.privateKey} and allocate result to output buffer`, test) passes += +test failures += +!test @@ -343,7 +343,7 @@ inbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 64) inbuf.set(NANO_ORG_VECTOR.secretKeyBytes) outbuf = new Uint8Array(64) sign(NANO_ORG_VECTOR.blockHashBytes, inbuf, outbuf) -test &&= [...outbuf].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() check(`sign message bytes ${NANO_ORG_VECTOR.blockHash} and allocate result to output buffer`, test) passes += +test failures += +!test @@ -352,9 +352,9 @@ inbuf = new Uint8Array(bigBuf.buffer.slice(), 1, 32) inbuf.set(NANO_ORG_VECTOR.privateKeyBytes) outbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 32) derive(inbuf, outbuf) -test &&= [...outbuf].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(outbuf.buffer, 0, 32)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.publicKey.toLowerCase() -test &&= [...new Uint8Array(outbuf.buffer, 32, 32)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() !== NANO_ORG_VECTOR.publicKey.toLowerCase() +test &&= [...new Uint8Array(outbuf.buffer, 32, 32)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === 'ff'.repeat(32) check(`derive from private key bytes ${NANO_ORG_VECTOR.privateKey} and allocate result to output buffer`, test) passes += +test failures += +!test @@ -363,9 +363,9 @@ inbuf = new Uint8Array(bigBuf.buffer.slice(), 1, 64) inbuf.set(NANO_ORG_VECTOR.secretKeyBytes) outbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 64) sign(NANO_ORG_VECTOR.blockHashBytes, inbuf, outbuf) -test &&= [...outbuf].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(outbuf.buffer, 0, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() -test &&= [...new Uint8Array(outbuf.buffer, 64, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() !== NANO_ORG_VECTOR.signature.toLowerCase() +test &&= [...new Uint8Array(outbuf.buffer, 64, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === 'ff'.repeat(64) check(`sign message bytes ${NANO_ORG_VECTOR.blockHash} and allocate result to output buffer`, test) passes += +test failures += +!test @@ -373,9 +373,8 @@ failures += +!test // Check sync imports with byte inputs and offset output buffer outbuf = new Uint8Array(new ArrayBuffer(128), 32, 32) derive(NANO_ORG_VECTOR.privateKeyBytes, outbuf) -test &&= [...outbuf].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() -test &&= [...new Uint8Array(outbuf.buffer, 0, 32)].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(outbuf.buffer, 0, 32)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === '00'.repeat(32) test &&= [...new Uint8Array(outbuf.buffer, 32, 32)].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} to offset outbuf`, test) passes += +test @@ -383,9 +382,8 @@ failures += +!test outbuf = new Uint8Array(new ArrayBuffer(128), 64, 64) sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.secretKeyBytes, outbuf) -test &&= [...outbuf].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() -test &&= [...new Uint8Array(outbuf.buffer)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() !== NANO_ORG_VECTOR.signature.toLowerCase() -test &&= [...new Uint8Array(outbuf.buffer, 0, 64)].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(outbuf.buffer, 0, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === '00'.repeat(64) test &&= [...new Uint8Array(outbuf.buffer, 64, 64)].map(b => b.toString(16).padStart(2, '0')).join('').toLowerCase() === NANO_ORG_VECTOR.signature.toLowerCase() check(`sign message bytes ${NANO_ORG_VECTOR.blockHash} to offset outbuf`, test) passes += +test -- 2.52.0