bigchaindb / js-bigchaindb-driver

Official BigchainDB JavaScript driver for Node.js and the browser
https://docs.bigchaindb.com/projects/js-driver/en/latest/usage.html
Apache License 2.0
216 stars 92 forks source link

Ed25519Keypair(seed) is passing Uint8Array to encode() instead of Buffer #274

Closed bjmacd closed 5 years ago

bjmacd commented 5 years ago

base-x encode function is expecting Buffer but is being passed Uint8Array which raises error;

/home/bjmacd/node_modules/base-x/index.js:30 if (!Buffer.isBuffer(source)) throw new TypeError('Expected Buffer') ^

TypeError: Expected Buffer at Object.encode (/home/bjmacd/node_modules/base-x/index.js:30:41) at new Ed25519Keypair (/home/bjmacd/node_modules/bigchaindb-driver/dist/node/Ed25519Keypair.js:28:33) at Object. (/home/bjmacd/myKeys/app.js:5:12) at Module._compile (internal/modules/cjs/loader.js:723:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:734:10) at Module.load (internal/modules/cjs/loader.js:620:32) at tryModuleLoad (internal/modules/cjs/loader.js:560:12) at Function.Module._load (internal/modules/cjs/loader.js:552:3) at Function.Module.runMain (internal/modules/cjs/loader.js:776:12) at executeUserCode (internal/bootstrap/node.js:342:17)

Updated function to pass as Buffer;

function Ed25519Keypair(seed) { var keyPair = seed ? _tweetnacl2.default.sign.keyPair.fromSeed(seed) : _tweetnacl2.default.sign.keyPair(); this.publicKey = _bs2.default.encode(Buffer(keyPair.publicKey)); // tweetnacl's generated secret key is the secret key + public key (resulting in a 64-byte buffer) this.privateKey = _bs2.default.encode(Buffer(keyPair.secretKey.slice(0, 32)));

bjmacd commented 5 years ago

Duplicate