Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash due to Buffer required in dependency #264

Closed
DavidEdwards opened this issue Nov 6, 2018 · 0 comments
Closed

Crash due to Buffer required in dependency #264

DavidEdwards opened this issue Nov 6, 2018 · 0 comments

Comments

@DavidEdwards
Copy link
Contributor

The problem

The driver is passing a Uint8Array from nacl into base-x. This is an unexpected datatype and is causing a crash.

/home/david/repo/bigchaindb-test/node_modules/base-x/index.js:29
    if (!Buffer.isBuffer(source)) throw new TypeError('Expected Buffer')

Where it is

The issue begins here in the driver code.

nacl is creating a Uint8Array here.

That is creating the Exception in base-x here.

Reproduce

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);

How to fix

If you wrap the Uint8Array in a Buffer, it will work without crashing.

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
DavidEdwards added a commit to DavidEdwards/js-bigchaindb-driver that referenced this issue Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant