diff --git a/src/types/Account/Account.js b/src/types/Account/Account.js index cc9ba923..69b263a4 100644 --- a/src/types/Account/Account.js +++ b/src/types/Account/Account.js @@ -139,10 +139,10 @@ class Account extends EventEmitter { let keyChainStorePath = this.index; const keyChainStoreOpts = {}; - if (this.walletType.includes([ + if ([ WALLET_TYPES.HDWALLET, WALLET_TYPES.HDPUBLIC, - WALLET_TYPES.PRIVATEKEY]) + WALLET_TYPES.PRIVATEKEY].includes(this.walletType) ) { keyChainStorePath = this.BIP44PATH; keyChainStoreOpts.lookAheadOpts = { @@ -152,7 +152,6 @@ class Account extends EventEmitter { }, }; } - this.keyChainStore = wallet .keyChainStore .makeChildKeyChainStore(keyChainStorePath, keyChainStoreOpts); diff --git a/src/types/Account/methods/generateAddress.js b/src/types/Account/methods/generateAddress.js index d4eba6a4..19f71f6b 100644 --- a/src/types/Account/methods/generateAddress.js +++ b/src/types/Account/methods/generateAddress.js @@ -45,11 +45,11 @@ function generateAddress(path, isWatchedAddress = true) { case WALLET_TYPES.HDPRIVATE: case WALLET_TYPES.HDWALLET: // eslint-disable-next-line prefer-destructuring - index = parseInt(path.toString().split('/')[5], 10); + index = parseInt(path.toString().split('/')[2], 10); keyData = this.keyChainStore .getMasterKeyChain() .getForPath(path, { isWatched: isWatchedAddress }); - address = keyData.address; + address = keyData.address.toString(); privateKey = keyData.key; break; case WALLET_TYPES.HDPUBLIC: @@ -59,12 +59,12 @@ function generateAddress(path, isWatchedAddress = true) { .getMasterKeyChain() .getForPath(path, { isWatched: isWatchedAddress }); privateKey = keyData.key; - address = keyData.address; + address = keyData.address.toString(); break; // TODO: DEPRECATE USAGE OF SINGLE_ADDRESS in favor or PRIVATEKEY case WALLET_TYPES.PRIVATEKEY: case WALLET_TYPES.SINGLE_ADDRESS: - privateKey = this.keyChainStore.getMasterKeyChain().rootKey; + privateKey = this.keyChainStore.getMasterKeyChain().rootKey.toString(); address = privateKey.publicKey.toAddress(network).toString(); if (isWatchedAddress) { diff --git a/src/types/Account/methods/getAddress.js b/src/types/Account/methods/getAddress.js index d4771dc7..ed89c24f 100644 --- a/src/types/Account/methods/getAddress.js +++ b/src/types/Account/methods/getAddress.js @@ -1,6 +1,6 @@ const { WALLET_TYPES } = require('../../../CONSTANTS'); -const getTypePathFromWalletType = (walletType, addressType = 'external', index, BIP44PATH) => { +const getTypePathFromWalletType = (walletType, addressType = 'external', accountIndex, addressIndex) => { let type; let path; @@ -8,11 +8,11 @@ const getTypePathFromWalletType = (walletType, addressType = 'external', index, switch (walletType) { case WALLET_TYPES.HDWALLET: type = addressType; - path = `${BIP44PATH}/${addressTypeIndex}/${index}`; + path = `m/${addressTypeIndex}/${addressIndex}`; break; case WALLET_TYPES.HDPUBLIC: type = 'external'; - path = `${BIP44PATH}/${addressTypeIndex}/${index}`; + path = `m/${addressTypeIndex}/${addressIndex}`; break; case WALLET_TYPES.PUBLICKEY: case WALLET_TYPES.ADDRESS: @@ -30,8 +30,9 @@ const getTypePathFromWalletType = (walletType, addressType = 'external', index, * @param {AddressType} [_type="external"] - Type of the address (external, internal, misc) * @return */ -function getAddress(index = 0, _type = 'external') { - const { type, path } = getTypePathFromWalletType(this.walletType, _type, index, this.BIP44PATH); +function getAddress(addressIndex = 0, _type = 'external') { + const accountIndex = this.index; + const { type, path } = getTypePathFromWalletType(this.walletType, _type, accountIndex, addressIndex); const { wallets } = this.storage.getStore(); const matchingTypeAddresses = wallets[this.walletId].addresses[type];