From 432f74488a237ea3a4a4285e9b6499f1a6e4c10f Mon Sep 17 00:00:00 2001 From: Matias Alejo Garcia Date: Wed, 14 May 2014 20:55:34 -0300 Subject: [PATCH] change name to bitcore.HierarchicalKey --- js/models/core/PrivateKey.js | 10 ++++----- js/models/core/PublicKeyRing.js | 38 ++++++++++++++++----------------- 2 files changed, 24 insertions(+), 24 deletions(-) diff --git a/js/models/core/PrivateKey.js b/js/models/core/PrivateKey.js index f7212e1e3..8f0643b59 100644 --- a/js/models/core/PrivateKey.js +++ b/js/models/core/PrivateKey.js @@ -3,7 +3,7 @@ var imports = require('soop').imports(); var bitcore = require('bitcore'); -var BIP32 = bitcore.BIP32; +var HK = bitcore.HierarchicalKey; var WalletKey = bitcore.WalletKey; var networks = bitcore.networks; var util = bitcore.util; @@ -14,7 +14,7 @@ function PrivateKey(opts) { this.network = opts.networkName === 'testnet' ? networks.testnet : networks.livenet; var init = opts.extendedPrivateKeyString || this.network.name; - this.bip = opts.BIP32 || new BIP32(init); + this.bip = opts.HK || new HK(init); this.privateKeyCache = opts.privateKeyCache || {}; }; @@ -47,7 +47,7 @@ PrivateKey.prototype.getExtendedPrivateKeyString = function() { return this.bip.extendedPrivateKeyString(); }; -PrivateKey.prototype._getBIP32 = function(path) { +PrivateKey.prototype._getHK = function(path) { if (typeof path === 'undefined') { return this.bip; } @@ -58,8 +58,8 @@ PrivateKey.prototype.get = function(index,isChange) { var path = PublicKeyRing.Branch(index, isChange); var pk = this.privateKeyCache[path]; if (!pk) { - var derivedBIP32 = this._getBIP32(path); - pk = this.privateKeyCache[path] = derivedBIP32.eckey.private.toString('hex'); + var derivedHK = this._getHK(path); + pk = this.privateKeyCache[path] = derivedHK.eckey.private.toString('hex'); } else { //console.log('cache hit!'); } diff --git a/js/models/core/PublicKeyRing.js b/js/models/core/PublicKeyRing.js index d9073c792..c76d0914d 100644 --- a/js/models/core/PublicKeyRing.js +++ b/js/models/core/PublicKeyRing.js @@ -4,7 +4,7 @@ var imports = require('soop').imports(); var bitcore = require('bitcore'); -var BIP32 = bitcore.BIP32; +var HK = bitcore.HierarchicalKey; var Address = bitcore.Address; var Script = bitcore.Script; var coinUtil = bitcore.util; @@ -26,7 +26,7 @@ function PublicKeyRing(opts) { this.requiredCopayers = opts.requiredCopayers || 3; this.totalCopayers = opts.totalCopayers || 5; - this.copayersBIP32 = opts.copayersBIP32 || []; + this.copayersHK = opts.copayersHK || []; this.changeAddressIndex= opts.changeAddressIndex || 0; this.addressIndex= opts.addressIndex || 0; @@ -74,7 +74,7 @@ PublicKeyRing.prototype.toObj = function() { changeAddressIndex: this.changeAddressIndex, addressIndex: this.addressIndex, - copayersExtPubKeys: this.copayersBIP32.map( function (b) { + copayersExtPubKeys: this.copayersHK.map( function (b) { return b.extendedPublicKeyString(); }), nicknameFor: this.nicknameFor, @@ -87,7 +87,7 @@ PublicKeyRing.prototype.getCopayerId = function(i) { }; PublicKeyRing.prototype.registeredCopayers = function () { - return this.copayersBIP32.length; + return this.copayersHK.length; }; PublicKeyRing.prototype.isComplete = function () { @@ -109,14 +109,14 @@ PublicKeyRing.prototype._checkKeys = function() { }; PublicKeyRing.prototype._newExtendedPublicKey = function () { - return new BIP32(this.network.name) + return new HK(this.network.name) .extendedPublicKeyString(); }; PublicKeyRing.prototype._updateBip = function (index) { var path = PublicKeyRing.ID_BRANCH; - var bip32 = this.copayersBIP32[index].derive(path); - this.copayerIds[index]= bip32.eckey.public.toString('hex'); + var hk = this.copayersHK[index].derive(path); + this.copayerIds[index]= hk.eckey.public.toString('hex'); }; PublicKeyRing.prototype._setNicknameForIndex = function (index, nickname) { @@ -139,14 +139,14 @@ PublicKeyRing.prototype.addCopayer = function (newEpk, nickname) { newEpk = this._newExtendedPublicKey(); } - this.copayersBIP32.forEach(function(b){ + this.copayersHK.forEach(function(b){ if (b.extendedPublicKeyString() === newEpk) throw new Error('already have that key'); }); - var i=this.copayersBIP32.length; - var bip = new BIP32(newEpk); - this.copayersBIP32.push(bip); + var i=this.copayersHK.length; + var bip = new HK(newEpk); + this.copayersHK.push(bip); this._updateBip(i); if (nickname) { this._setNicknameForIndex(i,nickname); @@ -161,10 +161,10 @@ PublicKeyRing.prototype.getPubKeys = function (index, isChange) { var pubKeys = this.publicKeysCache[path]; if (!pubKeys) { pubKeys = []; - var l = this.copayersBIP32.length; + var l = this.copayersHK.length; for(var i=0; i