From 9cfeb1abcd3e910e4b709c18c1c181db0c341e28 Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 16:03:02 +0700
Subject: [PATCH 1/9] Trailing whitespace
---
src/bip32.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bip32.js b/src/bip32.js
index 0b83ac9..e29e255 100644
--- a/src/bip32.js
+++ b/src/bip32.js
@@ -80,7 +80,7 @@ BIP32key.prototype.ckd = function(i) {
blob = [0].concat(priv.slice(0,32),util.numToBytes(i,4).reverse())
}
else blob = pub.concat(util.numToBytes(i,4).reverse())
-
+
I = Crypto.HMAC(Crypto.SHA512,blob,this.chaincode,{ asBytes: true })
if (this.type == 'priv') {
From 4b598271354e76afee504af91fe867e327169b7d Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 16:05:53 +0700
Subject: [PATCH 2/9] Declare statics on BIP32key, not its prototype
---
src/bip32.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/bip32.js b/src/bip32.js
index e29e255..46f6e49 100644
--- a/src/bip32.js
+++ b/src/bip32.js
@@ -13,10 +13,10 @@ var BIP32key = function(opts) {
if (!opts) opts = {}
if (typeof opts == "string") {
try {
- opts = BIP32key.prototype.deserialize(opts);
+ opts = BIP32key.deserialize(opts);
}
catch(e) {
- opts = BIP32key.prototype.fromMasterKey(opts);
+ opts = BIP32key.fromMasterKey(opts);
}
}
this.vbytes = opts.vbytes;
@@ -32,7 +32,7 @@ var BIP32key = function(opts) {
var PRIVDERIV = BIP32key.PRIVDERIV = '\x04\x88\xAD\xE4'
var PUBDERIV = BIP32key.PUBDERIV = '\x04\x88\xB2\x1E'
-BIP32key.prototype.deserialize = function(str) {
+BIP32key.deserialize = function(str) {
var bytes = base58.decode(str)
var front = bytes.slice(0,bytes.length-4),
back = bytes.slice(bytes.length-4);
@@ -119,7 +119,7 @@ BIP32key.prototype.privtopub = BIP32key.prototype.getPub = function() {
})
}
-BIP32key.prototype.fromMasterKey = function(seed) {
+BIP32key.fromMasterKey = function(seed) {
var I = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA512,seed,"Bitcoin seed",{ asBytes: true })
return new BIP32key({
vbytes: conv.stringToBytes(PRIVDERIV),
From 49513684a24b609d173c14968c79851877b316cf Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 16:06:53 +0700
Subject: [PATCH 3/9] Remove unused imports from BIP32key
---
src/bip32.js | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/src/bip32.js b/src/bip32.js
index 46f6e49..912e367 100644
--- a/src/bip32.js
+++ b/src/bip32.js
@@ -1,13 +1,9 @@
-var Script = require('./script'),
- util = require('./util'),
+var util = require('./util'),
conv = require('./convert'),
ECKey = require('./eckey').ECKey,
ECPubKey = require('./eckey').ECPubKey,
base58 = require('./base58'),
- Crypto = require('./crypto-js/crypto'),
- ECPointFp = require('./jsbn/ec').ECPointFp,
- sec = require('./jsbn/sec'),
- ecparams = sec("secp256k1");
+ Crypto = require('./crypto-js/crypto');
var BIP32key = function(opts) {
if (!opts) opts = {}
From d39567c589ec38da92337118c0772378de56a190 Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 16:09:59 +0700
Subject: [PATCH 4/9] Clean up formatting of BIP32key (jshint)
---
src/bip32.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/bip32.js b/src/bip32.js
index 912e367..4c04952 100644
--- a/src/bip32.js
+++ b/src/bip32.js
@@ -7,7 +7,7 @@ var util = require('./util'),
var BIP32key = function(opts) {
if (!opts) opts = {}
- if (typeof opts == "string") {
+ if (typeof opts == 'string') {
try {
opts = BIP32key.deserialize(opts);
}
@@ -34,8 +34,8 @@ BIP32key.deserialize = function(str) {
back = bytes.slice(bytes.length-4);
var checksum = Crypto.SHA256(Crypto.SHA256(front,{asBytes: true}), {asBytes: true})
.slice(0,4);
- if (""+checksum != ""+back) {
- throw new Error("Checksum failed");
+ if ('' + checksum != '' + back) {
+ throw new Error('Checksum failed');
}
var type = conv.bytesToString(bytes.slice(0,4)) == PRIVDERIV ? 'priv' : 'pub';
return new BIP32key({
@@ -116,7 +116,7 @@ BIP32key.prototype.privtopub = BIP32key.prototype.getPub = function() {
}
BIP32key.fromMasterKey = function(seed) {
- var I = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA512,seed,"Bitcoin seed",{ asBytes: true })
+ var I = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA512,seed, 'Bitcoin seed' , { asBytes: true })
return new BIP32key({
vbytes: conv.stringToBytes(PRIVDERIV),
type: 'priv',
From 26ac76d42c0edc1f1350cb26beffd5528070388e Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 16:10:39 +0700
Subject: [PATCH 5/9] Fix bad references to Bitcoin.Crypto
---
src/bip32.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bip32.js b/src/bip32.js
index 4c04952..306550a 100644
--- a/src/bip32.js
+++ b/src/bip32.js
@@ -116,7 +116,7 @@ BIP32key.prototype.privtopub = BIP32key.prototype.getPub = function() {
}
BIP32key.fromMasterKey = function(seed) {
- var I = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA512,seed, 'Bitcoin seed' , { asBytes: true })
+ var I = Crypto.HMAC(Crypto.SHA512,seed, 'Bitcoin seed' , { asBytes: true })
return new BIP32key({
vbytes: conv.stringToBytes(PRIVDERIV),
type: 'priv',
From 3e6796a6606b371591b56b8462650f9ba71edd6d Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 16:16:24 +0700
Subject: [PATCH 6/9] Fix references to Bitcoin.BigInteger
---
src/jsbn/ec.js | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/src/jsbn/ec.js b/src/jsbn/ec.js
index 0bfc111..a7642e8 100644
--- a/src/jsbn/ec.js
+++ b/src/jsbn/ec.js
@@ -376,11 +376,11 @@ ECPointFp.decodeFrom = function (ecparams, enc) {
var xBa = enc.slice(1),
x = BigInteger.fromByteArrayUnsigned(xBa),
p = ecparams.getQ(),
- xCubedPlus7 = x.multiply(x).multiply(x).add(new Bitcoin.BigInteger('7')).mod(p),
- pPlus1Over4 = p.add(new Bitcoin.BigInteger('1'))
- .divide(new Bitcoin.BigInteger('4')),
+ xCubedPlus7 = x.multiply(x).multiply(x).add(new BigInteger('7')).mod(p),
+ pPlus1Over4 = p.add(new BigInteger('1'))
+ .divide(new BigInteger('4')),
y = xCubedPlus7.modPow(pPlus1Over4,p);
- if (y.mod(new Bitcoin.BigInteger('2')).toString() != ''+(type % 2)) {
+ if (y.mod(new BigInteger('2')).toString() != ''+(type % 2)) {
y = p.subtract(y)
}
}
From be7406d9a9fd523836019023e002a5ff273ed1b1 Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 16:47:14 +0700
Subject: [PATCH 7/9] Add bitcoinAddress convenience func to BIP32key
---
src/bip32.js | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/src/bip32.js b/src/bip32.js
index 306550a..2bc3079 100644
--- a/src/bip32.js
+++ b/src/bip32.js
@@ -1,4 +1,5 @@
var util = require('./util'),
+ Address = require('./address'),
conv = require('./convert'),
ECKey = require('./eckey').ECKey,
ECPubKey = require('./eckey').ECPubKey,
@@ -130,4 +131,8 @@ BIP32key.fromMasterKey = function(seed) {
BIP32key.prototype.getKey = function() { return this.key }
+BIP32key.prototype.bitcoinAddress = function() {
+ return new Address(util.sha256ripe160(this.getPub().key))
+}
+
module.exports = BIP32key;
From c3fbd63c8487a692e2e571cbfe2399f250edfe1a Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 16:47:35 +0700
Subject: [PATCH 8/9] Fix bad Bitcoin.Crypto reference in ecdsa.js
---
src/ecdsa.js | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/ecdsa.js b/src/ecdsa.js
index 53770df..1c1e3b8 100644
--- a/src/ecdsa.js
+++ b/src/ecdsa.js
@@ -3,6 +3,7 @@ var util = require('./util');
var SecureRandom = require('./jsbn/rng');
var BigInteger = require('./jsbn/jsbn');
var conv = require('./convert')
+var Crypto = require('./crypto-js/crypto.js')
var ECPointFp = require('./jsbn/ec').ECPointFp;
@@ -42,12 +43,12 @@ function deterministicGenerateK(hash,key) {
var k = [];
for (var i = 0;i < 32;i++) v.push(1);
for (var i = 0;i < 32;i++) k.push(0);
- k = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA256,v.concat([0]).concat(key).concat(hash),k,{ asBytes: true })
- v = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA256,v,k,{ asBytes: true })
- k = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA256,v.concat([1]).concat(key).concat(hash),k,{ asBytes: true })
- v = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA256,v,k,{ asBytes: true })
- v = Bitcoin.Crypto.HMAC(Bitcoin.Crypto.SHA256,v,k,{ asBytes: true })
- return Bitcoin.BigInteger.fromByteArrayUnsigned(v);
+ k = Crypto.HMAC(Crypto.SHA256,v.concat([0]).concat(key).concat(hash),k,{ asBytes: true })
+ v = Crypto.HMAC(Crypto.SHA256,v,k,{ asBytes: true })
+ k = Crypto.HMAC(Crypto.SHA256,v.concat([1]).concat(key).concat(hash),k,{ asBytes: true })
+ v = Crypto.HMAC(Crypto.SHA256,v,k,{ asBytes: true })
+ v = Crypto.HMAC(Crypto.SHA256,v,k,{ asBytes: true })
+ return BigInteger.fromByteArrayUnsigned(v);
}
var ECDSA = {
From 4ffabf05af3ab98c53293679c4ab331557a040c0 Mon Sep 17 00:00:00 2001
From: Andreas Brekken
Date: Fri, 10 Jan 2014 17:16:08 +0700
Subject: [PATCH 9/9] Fix bitcoinAddress to use getPub().key.export('bytes')
---
src/bip32.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/bip32.js b/src/bip32.js
index 2bc3079..fb4c80d 100644
--- a/src/bip32.js
+++ b/src/bip32.js
@@ -132,7 +132,7 @@ BIP32key.fromMasterKey = function(seed) {
BIP32key.prototype.getKey = function() { return this.key }
BIP32key.prototype.bitcoinAddress = function() {
- return new Address(util.sha256ripe160(this.getPub().key))
+ return new Address(util.sha256ripe160(this.getPub().key.export('bytes')))
}
module.exports = BIP32key;