From 8a86f954f93bd59937f4fd7cfe3c02a1f1f1467a Mon Sep 17 00:00:00 2001 From: vrde Date: Sun, 14 May 2017 14:41:04 +0200 Subject: [PATCH] Change Ed25519 constructor --- src/Ed25519Keypair.js | 16 +++------------- src/transaction/makeOutput.js | 2 +- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Ed25519Keypair.js b/src/Ed25519Keypair.js index 7f1f961..eadfd80 100644 --- a/src/Ed25519Keypair.js +++ b/src/Ed25519Keypair.js @@ -6,22 +6,12 @@ import sha3 from 'js-sha3'; * @public * @class Keypair Ed25519 keypair in base58 (as BigchainDB expects base58 keys) * @type {Object} - * @param {number} [secret] A seed that will be used as a key derivation function + * @param {Buffer} [seed] A seed that will be used as a key derivation function * @property {string} publicKey * @property {string} privateKey */ -export default function Ed25519Keypair(secret) { - let keyPair; - if (secret) { - // Quick and dirty: use key derivation function instead - const secretHash = sha3.sha3_256 - .create() - .update(secret) - .array(); - keyPair = nacl.sign.keyPair.fromSeed(new Uint8Array(secretHash)) - } else { - keyPair = nacl.sign.keyPair(); - } +export default function Ed25519Keypair(seed) { + const keyPair = seed ? nacl.sign.keyPair.fromSeed(seed) : nacl.sign.keyPair(); this.publicKey = base58.encode(keyPair.publicKey); // tweetnacl's generated secret key is the secret key + public key (resulting in a 64-byte buffer) this.privateKey = base58.encode(keyPair.secretKey.slice(0, 32)); diff --git a/src/transaction/makeOutput.js b/src/transaction/makeOutput.js index 208bfcf..e95ffa2 100644 --- a/src/transaction/makeOutput.js +++ b/src/transaction/makeOutput.js @@ -8,7 +8,7 @@ */ export default function makeOutput(condition, amount = 1) { return { - amount: amount, + amount: amount.toString(), condition, 'public_keys': condition.details.hasOwnProperty('public_key') ? [condition.details.public_key] : [],