Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bitcore-wallet-utils

Package Overview
Dependencies
Maintainers
3
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitcore-wallet-utils - npm Package Compare versions

Comparing version 0.2.2 to 0.3.0

26

lib/walletutils.js

@@ -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() {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc