From f1b266e53b4b3d0b00684f77bb2f709380ee142c Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 2 Nov 2016 21:20:19 -0700 Subject: [PATCH] mtx: pass keyring into all signing methods. --- lib/primitives/mtx.js | 30 ++++++++++++++---------------- lib/workers/jobs.js | 6 +++--- 2 files changed, 17 insertions(+), 19 deletions(-) diff --git a/lib/primitives/mtx.js b/lib/primitives/mtx.js index caf87678..9c15ed0b 100644 --- a/lib/primitives/mtx.js +++ b/lib/primitives/mtx.js @@ -23,7 +23,6 @@ var Output = require('./output'); var Coin = require('./coin'); var KeyRing = require('./keyring'); var Address = require('./address'); -var ec = require('../crypto/ec'); var workers = require('../workers/workers'); /** @@ -396,27 +395,28 @@ MTX.prototype.scriptVector = function scriptVector(prev, vector, ring) { * Sign a transaction input on the worker pool * (if workers are enabled). * @param {Number} index - * @param {Buffer} key + * @param {KeyRing} ring * @param {SighashType?} type * @returns {Promise} */ -MTX.prototype.signInputAsync = function signInputAsync(index, key, type) { - return workers.pool.signInput(this, index, key, type); +MTX.prototype.signInputAsync = function signInputAsync(index, ring, type) { + return workers.pool.signInput(this, index, ring, type); }; /** * Sign an input. * @param {Number} index - Index of input being signed. - * @param {Buffer} key - Private key. + * @param {KeyRing} ring - Private key. * @param {SighashType} type * @returns {Boolean} Whether the input was able to be signed. */ -MTX.prototype.signInput = function signInput(index, key, type) { +MTX.prototype.signInput = function signInput(index, ring, type) { var input = this.inputs[index]; var version = 0; var redeem = false; + var key = ring.privateKey; var prev, vector, sig, result; assert(input, 'Input does not exist.'); @@ -462,13 +462,13 @@ MTX.prototype.signInput = function signInput(index, key, type) { if (redeem) { redeem = vector.pop(); - result = this.signVector(prev, vector, sig, key); + result = this.signVector(prev, vector, sig, ring); vector.push(redeem); vector.compile(); return result; } - return this.signVector(prev, vector, sig, key); + return this.signVector(prev, vector, sig, ring); }; /** @@ -477,12 +477,12 @@ MTX.prototype.signInput = function signInput(index, key, type) { * @param {Script} prev * @param {Witness|Script} vector * @param {Buffer} sig - * @param {Buffer} key + * @param {KeyRing} ring * @return {Boolean} */ -MTX.prototype.signVector = function signVector(prev, vector, sig, key) { - var pub = ec.publicKeyCreate(key, true); +MTX.prototype.signVector = function signVector(prev, vector, sig, ring) { + var pub = ring.publicKey; var i, m, n, keys, keyIndex, total; // P2PK @@ -870,7 +870,7 @@ MTX.prototype.template = function template(ring) { MTX.prototype.sign = function sign(ring, type) { var total = 0; - var i, key; + var i; if (Array.isArray(ring)) { for (i = 0; i < ring.length; i++) @@ -878,9 +878,7 @@ MTX.prototype.sign = function sign(ring, type) { return total; } - key = ring.privateKey; - - assert(key, 'No private key available.'); + assert(ring.privateKey, 'No private key available.'); for (i = 0; i < this.inputs.length; i++) { if (!ring.ownInput(this, i)) @@ -891,7 +889,7 @@ MTX.prototype.sign = function sign(ring, type) { continue; // Sign input - if (!this.signInput(i, key, type)) + if (!this.signInput(i, ring, type)) continue; total++; diff --git a/lib/workers/jobs.js b/lib/workers/jobs.js index 4f168361..2dfe2f2b 100644 --- a/lib/workers/jobs.js +++ b/lib/workers/jobs.js @@ -76,12 +76,12 @@ jobs.sign = function sign(tx, ring, type) { * @see MTX#signInput * @param {MTX} tx * @param {Number} index - * @param {Buffer} key + * @param {KeyRing} ring * @param {SighashType} type */ -jobs.signInput = function signInput(tx, index, key, type) { - var result = tx.signInput(tx, index, key, type); +jobs.signInput = function signInput(tx, index, ring, type) { + var result = tx.signInput(tx, index, ring, type); var input = tx.inputs[index]; if (!result)