Closed DavidEdwards closed 6 years ago
The driver is passing a Uint8Array from nacl into base-x. This is an unexpected datatype and is causing a crash.
Uint8Array
nacl
base-x
/home/david/repo/bigchaindb-test/node_modules/base-x/index.js:29 if (!Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')
The issue begins here in the driver code.
nacl is creating a Uint8Array here.
That is creating the Exception in base-x here.
Dependencies
{ "dependencies": { "bigchaindb-driver": "^4.1.0" } }
const base58 = require('bs58') const nacl = require('tweetnacl') const keyPair = nacl.sign.keyPair() console.log("keyPair.publicKey", keyPair.publicKey); console.log("keyPair.secretKey", keyPair.secretKey); publicKey = base58.encode(keyPair.publicKey) console.log("publicKey", publicKey); privateKey = base58.encode(keyPair.secretKey.slice(0, 32)) console.log("privateKey", privateKey);
If you wrap the Uint8Array in a Buffer, it will work without crashing.
Buffer
const base58 = require('bs58') const nacl = require('tweetnacl') const keyPair = nacl.sign.keyPair() console.log("keyPair.publicKey", keyPair.publicKey); console.log("keyPair.secretKey", keyPair.secretKey); publicKey = base58.encode(new Buffer(keyPair.publicKey)) console.log("publicKey", publicKey); privateKey = base58.encode(new Buffer(keyPair.secretKey.slice(0, 32))) console.log("privateKey", privateKey);
Output
keyPair.publicKey Uint8Array [ 210, 154, ...snip... 87, 91 ] keyPair.secretKey Uint8Array [ 119, 13, ...snip... 87, 91 ] publicKey FB7R29t5wQL5SaxtjMckc1BuKLxGZy56XnC6kvzX5enN privateKey 91jXtHyiCemrZxu2XLtAT2iiMJuqo5EFAL1h3k
The problem
The driver is passing a
Uint8Array
fromnacl
intobase-x
. This is an unexpected datatype and is causing a crash.Where it is
The issue begins here in the driver code.
nacl
is creating aUint8Array
here.That is creating the Exception in
base-x
here.Reproduce
Dependencies
How to fix
If you wrap the
Uint8Array
in aBuffer
, it will work without crashing.Output