console.log(`${test ? '\x1b[32mPASS' : '\x1b[31mFAIL'}\x1b[0m: ${name}`)
}
-/**
- *
- * @param {Uint8Array<ArrayBuffer>} a
- * @param {Uint8Array<ArrayBuffer>} b
- */
-function overlaps (a, b) {
- return a.buffer === b.buffer
- && a.byteOffset === b.byteOffset
- && a.byteLength === b.byteLength
- && a.byteLength !== 0
-}
-
-let outbuf, length, result, test, passes = 0, failures = 0
+const bigBuf = new Uint8Array(96).fill(255)
+let inbuf, outbuf, result, test, passes = 0, failures = 0
// Check string input validation
try {
failures += +!test
// Check sync imports with byte inputs and preallocated output buffer
+inbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 32)
+inbuf.set(NANO_ORG_VECTOR.privateKeyBytes)
outbuf = new Uint8Array(32)
-derive(NANO_ORG_VECTOR.privateKeyBytes, outbuf)
+derive(inbuf, outbuf)
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
+inbuf = new Uint8Array(bigBuf.buffer.slice(), 0, 64)
+inbuf.set(NANO_ORG_VECTOR.secretKeyBytes)
outbuf = new Uint8Array(64)
-sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.secretKeyBytes, outbuf)
+sign(NANO_ORG_VECTOR.blockHashBytes, inbuf, outbuf)
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
-outbuf = new Uint8Array(new ArrayBuffer(96), 0, 32)
-derive(NANO_ORG_VECTOR.privateKeyBytes, outbuf)
+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 &&= [...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)
-sign(NANO_ORG_VECTOR.blockHashBytes, NANO_ORG_VECTOR.secretKeyBytes, outbuf)
+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 &&= [...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)
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)
+outbuf = new Uint8Array(new ArrayBuffer(96), 1, 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()
passes += +test
failures += +!test
-length = 65 + crypto.getRandomValues(new Uint8Array(1))[0]
-outbuf = new Uint8Array(new ArrayBuffer(length), length - 64, 64)
+outbuf = new Uint8Array(new ArrayBuffer(96), 1, 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.publicKey.toLowerCase()