Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/base58.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@

// https://en.bitcoin.it/wiki/Base58Check_encoding

var BigInteger = require('./jsbn/jsbn');
var Crypto = require('crypto-js');
var SHA256 = Crypto.SHA256;
var WordArray = Crypto.lib.WordArray;
var convert = require('./convert');
var SHA256 = Crypto.SHA256;

var alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
var base = BigInteger.valueOf(58);
Expand Down Expand Up @@ -38,7 +36,7 @@ module.exports.encode = function (input) {
}

return chars.reverse().join('');
},
}

// decode a base58 string into a byte array
// input should be a base58 encoded string
Expand Down Expand Up @@ -90,10 +88,13 @@ module.exports.checkDecode = function(input) {
var bytes = module.exports.decode(input),
front = bytes.slice(0,bytes.length-4),
back = bytes.slice(bytes.length-4);

var checksum = getChecksum(front)

if (""+checksum != ""+back) {
throw new Error("Checksum failed");
}

var o = front.slice(1);
o.version = front[0];
return o;
Expand All @@ -105,4 +106,3 @@ function getChecksum(bytes) {
}

module.exports.getChecksum = getChecksum

4 changes: 2 additions & 2 deletions src/convert.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ exports.base64ToBytes = function(base64) {
// Remove non-base-64 characters
base64 = base64.replace(/[^A-Z0-9+\/]/ig, '');

var bytes = []
, imod4 = 0
var bytes = [];
var imod4 = 0;

for (var i = 0; i < base64.length; imod4 = ++i % 4) {
if (!imod4) continue
Expand Down
2 changes: 1 addition & 1 deletion src/ecdsa.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ var ECDSA = {
var alpha = x.multiply(x).multiply(x).add(a.multiply(x)).add(b).mod(p);
var beta = alpha.modPow(P_OVER_FOUR, p);

var xorOdd = beta.isEven() ? (i % 2) : ((i+1) % 2);
// var xorOdd = beta.isEven() ? (i % 2) : ((i+1) % 2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for commenting this out?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was unused.
I figured it might be a bit controversial given its proximity to the ECDSA code, therefore I didn't remove the line entirely.

// If beta is even, but y isn't or vice versa, then convert it,
// otherwise we're done and y == beta.
var y = (beta.isEven() ? !isYEven : isYEven) ? beta : p.subtract(beta);
Expand Down
10 changes: 5 additions & 5 deletions src/eckey.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ ECKey.prototype.getPub = function(compressed) {
* @deprecated Reserved keyword, factory pattern. Use toHex, toBytes, etc.
*/
ECKey.prototype['export'] = function(format) {
format || (format = 'hex')
var format = format || 'hex'
return this['to' + format.substr(0, 1).toUpperCase() + format.substr(1)]()
}

Expand All @@ -77,7 +77,7 @@ ECKey.version_bytes = {
}

ECKey.prototype.toWif = function(version) {
var version = version || Network.mainnet.addressVersion;
version = version || Network.mainnet.addressVersion;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was var commented out here?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, nevermind, I see it.


return base58.checkEncode(this.toBytes(), ECKey.version_bytes[version])
}
Expand Down Expand Up @@ -147,7 +147,7 @@ ECPubKey.prototype.multiply = function(key) {
}

ECPubKey.prototype['export'] = function(format) {
format || (format = 'hex')
var format = format || 'hex';
return this['to' + format.substr(0, 1).toUpperCase() + format.substr(1)]()
}

Expand All @@ -165,15 +165,15 @@ ECPubKey.prototype.toBin = function() {
}

ECPubKey.prototype.toWif = function(version) {
var version = version || Network.mainnet.addressVersion;
version = version || Network.mainnet.addressVersion;

return base58.checkEncode(this.toBytes(), version)
}

ECPubKey.prototype.toString = ECPubKey.prototype.toHex

ECPubKey.prototype.getAddress = function(version) {
var version = version || Network.mainnet.addressVersion;
version = version || Network.mainnet.addressVersion;

return new Address(util.sha256ripe160(this.toBytes()), version);
}
Expand Down
4 changes: 2 additions & 2 deletions src/opcode.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Opcode = {
var Opcode = {
map: {
// push value
OP_0 : 0,
Expand Down Expand Up @@ -144,4 +144,4 @@ for(var i in Opcode.map) {
Opcode.reverseMap[Opcode.map[i]] = i
}

module.exports = Opcode
module.exports = Opcode;
Loading