diff --git a/BIP32.js b/BIP32.js index 3e1705f..f333b41 100644 --- a/BIP32.js +++ b/BIP32.js @@ -290,8 +290,7 @@ BIP32.prototype.derive_child = function(i) { var il = new BigInteger(hash.slice(0, 64), 16); var ir = Crypto.util.hexToBytes(hash.slice(64, 128)); */ - var hmac = crypto.createHmac('sha512', this.chain_code); - var hash = hmac.update(data).digest(); + var hash = coinUtil.sha512hmac(data, this.chain_code); var il = bignum.fromBuffer(hash.slice(0, 32), {size: 32}); var ir = hash.slice(32, 64); @@ -317,8 +316,7 @@ BIP32.prototype.derive_child = function(i) { var ir = Crypto.util.hexToBytes(hash.slice(64, 128)); */ var data = Buffer.concat([this.eckey.public, ib]); - var hmac = crypto.createHmac('sha512', this.chain_code); - var hash = hmac.update(data).digest(); + var hash = coinUtil.sha512hmac(data, this.chain_code); var il = bignum.fromBuffer(hash.slice(0, 32), {size: 32}); var ir = hash.slice(32, 64); diff --git a/browser/build.js b/browser/build.js index 736ae3d..24efa9b 100644 --- a/browser/build.js +++ b/browser/build.js @@ -24,6 +24,7 @@ var pack = function (params) { var modules = [ 'Address', + 'BIP32', 'Block', 'Bloom', 'Buffers.monkey', diff --git a/package.json b/package.json index eb5a3c5..61d4857 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "postinstall": "node browser/build.js -a" }, "dependencies": { + "jssha": "=1.5.0", "soop": "=0.1.5", "base58-native": "=0.1.3", "bindings": "=1.1.1", diff --git a/test/index.html b/test/index.html index bbd0d61..510190e 100644 --- a/test/index.html +++ b/test/index.html @@ -17,6 +17,7 @@ + diff --git a/util/util.js b/util/util.js index 921cda5..dc7972b 100644 --- a/util/util.js +++ b/util/util.js @@ -3,6 +3,7 @@ var bignum = require('bignum'); var Binary = require('binary'); var Put = require('bufferput'); var buffertools = require('buffertools'); +var jssha = require('jssha'); var browser; var inBrowser = !process.versions; if (inBrowser) { @@ -13,7 +14,20 @@ if (inBrowser) { var sha256 = exports.sha256 = function(data) { return new Buffer(crypto.createHash('sha256').update(data).digest('binary'), 'binary'); }; -var ripe160 = exports.ripe160 = function(data) { + +var sha512hmac = exports.sha512hmac = function (data, key) { + if (inBrowser) { + var j = new jssha(data.toString('hex'), 'HEX'); + var hash = j.getHMAC(key.toString('hex'), "HEX", "SHA-512", "HEX"); + hash = new Buffer(hash, 'hex'); + return hash; + }; + var hmac = crypto.createHmac('sha512', key); + var hash = hmac.update(data).digest(); + return hash; +}; + +var ripe160 = exports.ripe160 = function (data) { if (!Buffer.isBuffer(data)) { throw new Error('arg should be a buffer'); }