mtx: pass keyring into all signing methods.

This commit is contained in:
Christopher Jeffrey 2016-11-02 21:20:19 -07:00
parent 2bd3ac4618
commit f1b266e53b
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
2 changed files with 17 additions and 19 deletions

View File

@ -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++;

View File

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