Skip to content

Commit

Permalink
Merge pull request #678 from wAISw/MINT-1595-Fix-addresses-on-login-w…
Browse files Browse the repository at this point in the history
…ith-mnemonic-and-wallet-file

MINT-1595 Fix addresses on login with mnemonic and wallet file
  • Loading branch information
wAISw committed Jun 19, 2018
2 parents 0bb2442 + cd3a93a commit 8ebcaf3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 24 deletions.
2 changes: 1 addition & 1 deletion packages/login/network/BitcoinEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class BitcoinEngine {
createNewChildAddress (deriveNumber = 0, coinType) {
const wallet = bitcoin.HDNode
.fromSeedBuffer(this._wallet.keyPair.d.toBuffer(), this._network)
.derivePath(`m/44'/${coinType}'/0'/0/${deriveNumber}`)
.derivePath(`m/44'/${coinType}'/0'/0/0/${deriveNumber}`)

this._walletsMap[wallet.getAddress()] = wallet

Expand Down
6 changes: 3 additions & 3 deletions packages/login/network/EthereumEngine.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default class EthereumEngine {
constructor (wallet, network, url, engine, deriveNumber) {
this._wallet = wallet
this._network = network
const web3 = engine && new Web3(engine)
const web3 = engine && new Web3(engine)
try {
this._address = engine && web3.eth.accounts[0]
} catch (e) {
Expand All @@ -21,14 +21,14 @@ export default class EthereumEngine {
this._engine = engine || Web3Utils.createEngine(wallet, url, deriveNumber)
}

getNetwork() {
getNetwork () {
return this._network
}

getAddress () {
return this._address || this._wallet.getAddressString()
}

getProvider () {
return this._engine
}
Expand Down
8 changes: 4 additions & 4 deletions packages/login/network/mnemonicProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const COIN_TYPE_LTC_TESTNET = 8
export const COIN_TYPE_BTG_MAINNET = 17
export const COIN_TYPE_BTG_TESTNET = 16
// get the first account using the standard hd path
export const WALLET_HD_PATH = `m/44'/${COIN_TYPE_ETH}'/0'/0`
export const WALLET_HD_PATH = `m/44'/${COIN_TYPE_ETH}'/0'/0/0`

class MnemonicProvider {
getMnemonicProvider (mnemonic, { url, network } = {}) {
Expand Down Expand Up @@ -90,7 +90,7 @@ class MnemonicProvider {
: COIN_TYPE_BTC_MAINNET
return bitcoin.HDNode
.fromSeedBuffer(bip39.mnemonicToSeed(mnemonic), network)
.derivePath(`m/44'/${coinType}'/0'/0`)
.derivePath(`m/44'/${coinType}'/0'/0/0`)
}

createLitecoinWallet (mnemonic, network) {
Expand All @@ -99,7 +99,7 @@ class MnemonicProvider {
: COIN_TYPE_LTC_MAINNET
return bitcoin.HDNode
.fromSeedBuffer(bip39.mnemonicToSeed(mnemonic), network)
.derivePath(`m/44'/${coinType}'/0'/0`)
.derivePath(`m/44'/${coinType}'/0'/0/0`)
}

createBitcoinGoldWallet (mnemonic, network) {
Expand All @@ -108,7 +108,7 @@ class MnemonicProvider {
: COIN_TYPE_BTG_MAINNET
return bitcoin.HDNode
.fromSeedBuffer(bip39.mnemonicToSeed(mnemonic), network)
.derivePath(`m/44'/${coinType}'/0'/0`)
.derivePath(`m/44'/${coinType}'/0'/0/0`)
}

validateMnemonic (mnemonic) {
Expand Down
6 changes: 3 additions & 3 deletions packages/login/network/privateKeyProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class PrivateKeyProvider {
: COIN_TYPE_BTC_MAINNET
return bitcoin.HDNode
.fromSeedBuffer(Buffer.from(privateKey, 'hex'), network)
.derivePath(`m/44'/${coinType}'/0'/0`)
.derivePath(`m/44'/${coinType}'/0'/0/0`)
}

createLitecoinWallet (privateKey, network) {
Expand All @@ -97,7 +97,7 @@ class PrivateKeyProvider {
: COIN_TYPE_LTC_MAINNET
return bitcoin.HDNode
.fromSeedBuffer(Buffer.from(privateKey, 'hex'), network)
.derivePath(`m/44'/${coinType}'/0'/0`)
.derivePath(`m/44'/${coinType}'/0'/0/0`)
}

createBitcoinGoldWallet (privateKey, network) {
Expand All @@ -109,7 +109,7 @@ class PrivateKeyProvider {
: COIN_TYPE_BTG_MAINNET
return bitcoin.HDNode
.fromSeedBuffer(Buffer.from(privateKey, 'hex'), network)
.derivePath(`m/44'/${coinType}'/0'/0`)
.derivePath(`m/44'/${coinType}'/0'/0/0`)
}

createEthereumWallet (privateKey) {
Expand Down
16 changes: 3 additions & 13 deletions src/redux/mainWallet/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,6 @@ export const initMainWallet = () => async (dispatch, getState) => {
}),
})
})

const { isMnemonic, isWalletFile } = getState().get(DUCK_NETWORK)
if (isMnemonic || isWalletFile) {
dispatch(createPackChildWallets())
}
}

export const mainTransfer = (wallet: DerivedWalletModel, token: TokenModel, amount: Amount, recipient: string, feeMultiplier: Number = 1, additionalOptions = {}) => async (dispatch, getState) => {
Expand Down Expand Up @@ -428,11 +423,6 @@ export const getTokensBalancesAndWatch = (address, blockchain, customTokens: Arr

await dao.watch(address)
}
export const createPackChildWallets = () => async (dispatch) => {
dispatch(createNewChildAddress({ blockchain: BLOCKCHAIN_ETHEREUM, deriveNumber: 0 }))
dispatch(createNewChildAddress({ blockchain: BLOCKCHAIN_BITCOIN, deriveNumber: 0 }))
dispatch(createNewChildAddress({ blockchain: BLOCKCHAIN_LITECOIN, deriveNumber: 0 }))
}

export const createNewChildAddress = ({ blockchain, tokens, name, deriveNumber }) => async (dispatch, getState) => {
const account = getState().get(DUCK_SESSION).account
Expand Down Expand Up @@ -462,7 +452,7 @@ export const createNewChildAddress = ({ blockchain, tokens, name, deriveNumber }

switch (blockchain) {
case BLOCKCHAIN_ETHEREUM:
if (!newDeriveNumber) {
if (newDeriveNumber !== undefined) {
newDeriveNumber = lastDeriveNumbers.hasOwnProperty(blockchain) ? lastDeriveNumbers[blockchain] + 1 : 0
}
newWallet = ethereumProvider.createNewChildAddress(newDeriveNumber)
Expand All @@ -471,15 +461,15 @@ export const createNewChildAddress = ({ blockchain, tokens, name, deriveNumber }
ethereumProvider.addNewEthWallet(newDeriveNumber)
break
case BLOCKCHAIN_BITCOIN:
if (!newDeriveNumber) {
if (newDeriveNumber !== undefined) {
newDeriveNumber = lastDeriveNumbers.hasOwnProperty(blockchain) ? lastDeriveNumbers[blockchain] + 1 : 0
}
newWallet = btcProvider.createNewChildAddress(newDeriveNumber)
address = newWallet.getAddress()
btcProvider.subscribeNewWallet(address)
break
case BLOCKCHAIN_LITECOIN:
if (!newDeriveNumber) {
if (newDeriveNumber !== undefined) {
newDeriveNumber = lastDeriveNumbers.hasOwnProperty(blockchain) ? lastDeriveNumbers[blockchain] + 1 : 0
}
newWallet = ltcProvider.createNewChildAddress(newDeriveNumber)
Expand Down

0 comments on commit 8ebcaf3

Please sign in to comment.