Skip to content

Commit f88a1f6

Browse files
Weston SiegenthalerWeston Siegenthaler
Weston Siegenthaler
authored and
Weston Siegenthaler
committed
using shortcut to calculate double sha256 hashes
1 parent 7ecf838 commit f88a1f6

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

src/address.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Bitcoin.Address.prototype.toString = function () {
2121
// Version
2222
hash.unshift(this.version);
2323

24-
var checksum = Crypto.SHA256(Crypto.SHA256(hash, {asBytes: true}), {asBytes: true});
24+
var checksum = Bitcoin.Util.dsha256(hash);
2525

2626
var bytes = hash.concat(checksum.slice(0,4));
2727

@@ -40,7 +40,7 @@ Bitcoin.Address.decodeString = function (string) {
4040

4141
var hash = bytes.slice(0, 21);
4242

43-
var checksum = Crypto.SHA256(Crypto.SHA256(hash, {asBytes: true}), {asBytes: true});
43+
var checksum = Bitcoin.Util.dsha256(hash);
4444

4545
if (checksum[0] != bytes[21] ||
4646
checksum[1] != bytes[22] ||

src/bitcoin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@
100100
buffer.concat(Crypto.util.wordsToBytes([parseInt(hashType)]));
101101
102102
console.log(buffer);
103-
104-
return Crypto.SHA256(Crypto.SHA256(buffer, {asBytes: true}), {asBytes: true});
103+
104+
return Bitcoin.Util.dsha256(buffer);
105105
};
106106
107107
function verifyTransactionSignature(tx) {

src/eckey.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ Bitcoin.ECKey = (function () {
136136
var bytes = this.getPrivateKeyByteArray();
137137
bytes.unshift(ECKey.privateKeyPrefix); // prepend 0x80 byte
138138
if (this.compressed) bytes.push(0x01); // append 0x01 byte for compressed format
139-
var checksum = Crypto.SHA256(Crypto.SHA256(bytes, { asBytes: true }), { asBytes: true });
139+
var checksum = Bitcoin.Util.dsha256(bytes);
140140
bytes = bytes.concat(checksum.slice(0, 4));
141141
var privWif = Bitcoin.Base58.encode(bytes);
142142
return privWif;
@@ -194,7 +194,7 @@ Bitcoin.ECKey = (function () {
194194

195195
var hash = bytes.slice(0, 33);
196196

197-
var checksum = Crypto.SHA256(Crypto.SHA256(hash, {asBytes: true}), {asBytes: true});
197+
var checksum = Bitcoin.Util.dsha256(hash);
198198

199199
if (checksum[0] != bytes[33] ||
200200
checksum[1] != bytes[34] ||
@@ -218,7 +218,7 @@ Bitcoin.ECKey = (function () {
218218
ECKey.decodeCompressedWalletImportFormat = function (privStr) {
219219
var bytes = Bitcoin.Base58.decode(privStr);
220220
var hash = bytes.slice(0, 34);
221-
var checksum = Crypto.SHA256(Crypto.SHA256(hash, { asBytes: true }), { asBytes: true });
221+
var checksum = Bitcoin.Util.dsha256(hash);
222222
if (checksum[0] != bytes[34] ||
223223
checksum[1] != bytes[35] ||
224224
checksum[2] != bytes[36] ||

src/message.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Bitcoin.Message = (function () {
2121

2222
Message.getHash = function (message) {
2323
var buffer = Message.makeMagicMessage(message);
24-
return Crypto.SHA256(Crypto.SHA256(buffer, {asBytes: true}), {asBytes: true});
24+
return Bitcoin.Util.dsha256(buffer);
2525
};
2626

2727
Message.signMessage = function (key, message, compressed) {

0 commit comments

Comments
 (0)