bitcore-wallet-utils
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -26,12 +26,2 @@ 'use strict'; | ||
WalletUtils.PATHS = { | ||
BASE_ADDRESS_DERIVATION: { | ||
'BIP45': { | ||
livenet: "m/45'", | ||
testnet: "m/45'", | ||
}, | ||
'BIP44': { | ||
livenet: "m/44'/0'/0'", | ||
testnet: "m/44'/1'/0'", | ||
}, | ||
}, | ||
REQUEST_KEY: "m/1'/0", | ||
@@ -85,3 +75,3 @@ TXPROPOSAL_KEY: "m/1'/1", | ||
WalletUtils.deriveAddress = function(scriptType, publicKeyRing, path, m, network) { | ||
$.checkArgument(_.contains(_.keys(WalletUtils.SCRIPT_TYPES), scriptType)); | ||
$.checkArgument(_.contains(_.values(WalletUtils.SCRIPT_TYPES), scriptType)); | ||
@@ -264,4 +254,14 @@ var publicKeys = _.map(publicKeyRing, function(item) { | ||
WalletUtils.deriveXPrivFromMaster = function(masterXPriv, derivationStrategy, network) { | ||
var path = WalletUtils.PATHS.BASE_ADDRESS_DERIVATION[derivationStrategy][network]; | ||
WalletUtils.getBaseAddressDerivationPath = function(derivationStrategy, network, account) { | ||
$.checkArgument(_.contains(_.values(WalletUtils.DERIVATION_STRATEGIES), derivationStrategy)); | ||
if (derivationStrategy == WalletUtils.DERIVATION_STRATEGIES.BIP45) return "m/45'"; | ||
$.checkArgument(_.contains(['livenet', 'testnet'], network)); | ||
$.shouldBeNumber(account); | ||
return "m/44'/" + (network == 'livenet' ? "0'" : "1'") + "/" + account + "'"; | ||
}; | ||
WalletUtils.deriveXPrivFromMaster = function(masterXPriv, derivationStrategy, network, account) { | ||
var path = WalletUtils.getBaseAddressDerivationPath(derivationStrategy, network, account || 0); | ||
return new Bitcore.HDPrivateKey(masterXPriv, network).derive(path); | ||
@@ -268,0 +268,0 @@ }; |
@@ -5,3 +5,3 @@ { | ||
"author": "BitPay Inc", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"main": "index.js", | ||
@@ -8,0 +8,0 @@ "keywords": [ |
@@ -115,2 +115,33 @@ 'use strict'; | ||
describe('#getBaseAddressDerivationPath', function() { | ||
describe('BIP45', function() { | ||
it('should return path', function() { | ||
WalletUtils.getBaseAddressDerivationPath('BIP45').should.equal("m/45'"); | ||
}); | ||
}); | ||
describe('BIP44', function() { | ||
it('should return path for livenet, account 0', function() { | ||
WalletUtils.getBaseAddressDerivationPath('BIP44', 'livenet', 0).should.equal("m/44'/0'/0'"); | ||
}); | ||
it('should return path for testnet, account 2', function() { | ||
WalletUtils.getBaseAddressDerivationPath('BIP44', 'testnet', 2).should.equal("m/44'/1'/2'"); | ||
}); | ||
it('should fail on incorrect network', function() { | ||
(function() { | ||
WalletUtils.getBaseAddressDerivationPath('BIP44', 'fakenet'); | ||
}).should.throw; | ||
}); | ||
it('should fail on incorrect account', function() { | ||
(function() { | ||
WalletUtils.getBaseAddressDerivationPath('BIP44', 'livenet', 'dummy'); | ||
}).should.throw; | ||
}); | ||
}); | ||
it('should fail on incorrect derivationStrategy', function() { | ||
(function() { | ||
WalletUtils.getBaseAddressDerivationPath('BIP123'); | ||
}).should.throw; | ||
}); | ||
}); | ||
describe('#deriveXPrivFromMaster', function() { | ||
@@ -117,0 +148,0 @@ it('should derive BIP45 livenet', function() { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
40945
967