Skip to content
This repository has been archived by the owner on Jan 12, 2022. It is now read-only.

Commit

Permalink
fix: integration issues
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Werner committed Nov 18, 2021
1 parent afb46ef commit a43369a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/types/Account/Account.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand All @@ -152,7 +152,6 @@ class Account extends EventEmitter {
},
};
}

this.keyChainStore = wallet
.keyChainStore
.makeChildKeyChainStore(keyChainStorePath, keyChainStoreOpts);
Expand Down
8 changes: 4 additions & 4 deletions src/types/Account/methods/generateAddress.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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) {
Expand Down
11 changes: 6 additions & 5 deletions src/types/Account/methods/getAddress.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
const { WALLET_TYPES } = require('../../../CONSTANTS');

const getTypePathFromWalletType = (walletType, addressType = 'external', index, BIP44PATH) => {
const getTypePathFromWalletType = (walletType, addressType = 'external', accountIndex, addressIndex) => {
let type;
let path;

const addressTypeIndex = (addressType === 'external') ? 0 : 1;
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:
Expand All @@ -30,8 +30,9 @@ const getTypePathFromWalletType = (walletType, addressType = 'external', index,
* @param {AddressType} [_type="external"] - Type of the address (external, internal, misc)
* @return <AddressInfo>
*/
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];
Expand Down

0 comments on commit a43369a

Please sign in to comment.