Browse Source

tx_valid tests passing!

patch-2
Manuel Araoz 10 years ago
parent
commit
b3be9461cf
  1. 4
      lib/script_interpreter.js
  2. 5
      lib/transaction/sighash.js
  3. 1
      test/script_interpreter.js

4
lib/script_interpreter.js

@ -162,6 +162,7 @@ ScriptInterpreter.prototype.checkPubkeyEncoding = function(buf) {
* bitcoind commit: b5d1b1092998bc95313856d535c632ea5a8f9104
*/
ScriptInterpreter.prototype.evaluate = function() {
console.log(this.script.toString());
if (this.script.toBuffer().length > 10000) {
this.errstr = 'SCRIPT_ERR_SCRIPT_SIZE';
return false;
@ -883,7 +884,6 @@ ScriptInterpreter.prototype.step = function() {
subscript.findAndDelete(tmpScript);
if (!this.checkSignatureEncoding(bufSig) || !this.checkPubkeyEncoding(bufPubkey)) {
// serror is set
return false;
}
@ -973,7 +973,6 @@ ScriptInterpreter.prototype.step = function() {
var bufPubkey = this.stack[this.stack.length - ikey];
if (!this.checkSignatureEncoding(bufSig) || !this.checkPubkeyEncoding(bufPubkey)) {
// serror is set
return false;
}
@ -1141,7 +1140,6 @@ ScriptInterpreter.prototype.verify = function(scriptSig, scriptPubkey, tx, nin,
// evaluate redeemScript
if (!this.evaluate())
// serror is set
return false;
if (stackCopy.length === 0) {

5
lib/transaction/sighash.js

@ -11,6 +11,7 @@ var BN = require('../crypto/bn');
var Hash = require('../crypto/hash');
var ECDSA = require('../crypto/ecdsa');
var $ = require('../util/preconditions');
var _ = require('lodash');
var SIGHASH_SINGLE_BUG = '0000000000000000000000000000000000000000000000000000000000000001';
var BITS_64_ON = 'ffffffffffffffff';
@ -122,8 +123,8 @@ function sign(transaction, privateKey, sighashType, inputIndex, subscript) {
* @return {boolean}
*/
function verify(transaction, signature, publicKey, inputIndex, subscript) {
$.checkArgument(transaction);
$.checkArgument(signature && signature.nhashtype);
$.checkArgument(!_.isUndefined(transaction));
$.checkArgument(!_.isUndefined(signature) && !_.isUndefined(signature.nhashtype));
var hashbuf = sighash(transaction, signature.nhashtype, inputIndex, subscript);
return ECDSA.verify(hashbuf, signature, publicKey, 'little');
}

1
test/script_interpreter.js

@ -247,7 +247,6 @@ describe('ScriptInterpreter', function() {
var tx = Transaction(txhex);
tx.inputs.forEach(function(txin, j) {
console.log('input ' + j);
var scriptSig = txin.script;
var txidhex = txin.prevTxId.toString('hex');
var txoutnum = txin.outputIndex;

Loading…
Cancel
Save