From 8f383be3257bec8cbac9ce32b2505b4c450e2243 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Sun, 16 Mar 2014 02:42:49 +0100 Subject: [PATCH 1/2] fix transaction hashing (was using Message.getHash incorrectly). --- src/transaction.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/transaction.js b/src/transaction.js index 527a945..b61b2fb 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -7,6 +7,7 @@ var ECKey = require('./eckey').ECKey; var ECDSA = require('./ecdsa'); var Address = require('./address'); var Message = require('./message'); +var SHA256 = require('./crypto-js/sha256'); var Transaction = function (doc) { if (!(this instanceof Transaction)) { return new Transaction(doc); } @@ -207,7 +208,8 @@ function (connectedScript, inIndex, hashType) buffer = buffer.concat(convert.numToBytes(parseInt(hashType),4)); - return Message.getHash(buffer) + buffer = convert.bytesToWordArray(buffer); + return convert.wordArrayToBytes(SHA256(SHA256(buffer))); }; /** @@ -217,8 +219,8 @@ function (connectedScript, inIndex, hashType) */ Transaction.prototype.getHash = function () { - var buffer = this.serialize(); - return Message.getHash(buffer).reverse() + var buffer = convert.bytesToWordArray(this.serialize()); + return convert.wordArrayToBytes(SHA256(SHA256(buffer))).reverse(); }; /** From 2e26a137d504857fb3708624da26ab002aff1737 Mon Sep 17 00:00:00 2001 From: Pablo Martin Date: Sun, 16 Mar 2014 03:02:04 +0100 Subject: [PATCH 2/2] require crypto-js/sha256 instead of ./crypto-js/sha256. --- src/transaction.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/transaction.js b/src/transaction.js index b61b2fb..cf7160d 100644 --- a/src/transaction.js +++ b/src/transaction.js @@ -7,7 +7,7 @@ var ECKey = require('./eckey').ECKey; var ECDSA = require('./ecdsa'); var Address = require('./address'); var Message = require('./message'); -var SHA256 = require('./crypto-js/sha256'); +var SHA256 = require('crypto-js/sha256'); var Transaction = function (doc) { if (!(this instanceof Transaction)) { return new Transaction(doc); }