flocore/lib/transaction/input/scriptHash.js
Esteban Ordano af43228daf Add PublicKeyHashInput and ScriptHashInput.
Remove `_outpoints`, `_utxos` from Transaction, as that info
can be efficiently retrieved from the inputs
2014-12-15 18:19:39 -03:00

32 lines
993 B
JavaScript

'use strict';
var inherits = require('inherits');
var Input = require('./input');
var Hash = require('../../crypto/hash');
var Signature = require('../../crypto/signature');
var Sighash = require('../sighash');
var BufferUtil = require('../../util/buffer');
function ScriptHashInput() {
}
inherits(ScriptHashInput, Input);
ScriptHashInput.prototype.getSignatures = function(transaction, privateKey, index, sigtype, hashData) {
hashData = hashData || Hash.sha256ripemd160(privateKey.publicKey.toBuffer());
sigtype = sigtype || Signature.SIGHASH_ALL;
if (BufferUtil.equals(hashData, this.output.script.address.hashData)) {
return [{
address: this.output.script.address,
publicKey: privateKey.publicKey,
prevTxId: this.txId,
outputIndex: this.outputIndex,
inputIndex: index,
signature: Sighash.sign(transaction, privateKey, sigtype, index, this.output.script),
sigtype: sigtype
}];
}
return [];
};
module.exports = ScriptHashInput;