Skip to content

Commit

Permalink
Show bip44 path for eth accounts
Browse files Browse the repository at this point in the history
  • Loading branch information
agneslovelace committed Mar 3, 2020
1 parent 30ff408 commit 27e4ba9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import com.mycelium.wapi.wallet.bch.bip44.Bip44BCHAccount
import com.mycelium.wapi.wallet.bch.single.SingleAddressBCHAccount
import com.mycelium.wapi.wallet.btc.WalletBtcAccount
import com.mycelium.wapi.wallet.btc.single.SingleAddressAccount
import com.mycelium.wapi.wallet.eth.EthAccount
import com.mycelium.wapi.wallet.eth.EthereumModule
import com.squareup.otto.Subscribe

class AddressFragmentModel(
Expand Down Expand Up @@ -69,6 +71,9 @@ class AddressFragmentModel(
type.value = address.type
accountAddressType.value = context.getString(address.type.asStringRes())
}
} else if (account is EthAccount) {
val module = mbwManager.getWalletManager(false).getModuleById(EthereumModule.ID) as EthereumModule
bip32Path.value = module.getBip44Path(account.accountIndex)
}
accountAddress.value = account.receiveAddress
}
Expand All @@ -90,7 +95,7 @@ class AddressFragmentModel(
updateLabel()
onAddressChange()
mbwManager.getWalletManager(false).run {
if(hasAccount(event.account)) {
if (hasAccount(event.account)) {
startSynchronization(
SyncMode.FULL_SYNC_CURRENT_ACCOUNT_FORCED, listOf(getAccount(event.account) ?: return@run))
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.mrd.bitlib.model.NetworkParameters
import com.mrd.bitlib.model.hdpath.HdKeyPath
import com.mrd.bitlib.util.HexUtils
import com.mycelium.generated.wallet.database.WalletDB
import com.mycelium.net.HttpEndpoint
import com.mycelium.wapi.wallet.*
import com.mycelium.wapi.wallet.coins.Balance
import com.mycelium.wapi.wallet.eth.coins.EthMain
Expand Down Expand Up @@ -34,6 +33,7 @@ class EthereumModule(

var settings: EthereumSettings = EthereumSettings()
val password = ""
fun getBip44Path(accountIndex: Int): HdKeyPath = HdKeyPath.valueOf("m/44'/60'/$accountIndex'/0/0")
private val coinType = if (networkParameters.isProdnet) EthMain else EthTest

private val accounts = mutableMapOf<UUID, EthAccount>()
Expand Down Expand Up @@ -117,14 +117,14 @@ class EthereumModule(
private fun deriveKey(): Credentials {
val seed = MasterSeedManager.getMasterSeed(secureStore, AesKeyCipher.defaultKeyCipher())
val rootNode = HdKeyNode.fromSeed(seed.bip32Seed, null)
val path = "m/44'/60'/${getCurrentBip44Index() + 1}'/0/0"
val path = getBip44Path(getCurrentBip44Index() + 1)

val privKey = HexUtils.toHex(rootNode.createChildNode(HdKeyPath.valueOf(path)).privateKey.privateKeyBytes)
val privKey = HexUtils.toHex(rootNode.createChildNode(path).privateKey.privateKeyBytes)
val credentials = Credentials.create(privKey)

secureStore.encryptAndStoreValue(credentials.ecKeyPair.toUUID().toString().toByteArray(),
Keys.serialize(credentials.ecKeyPair), AesKeyCipher.defaultKeyCipher())
return Credentials.create(privKey)
return credentials
}

override fun deleteAccount(walletAccount: WalletAccount<*>, keyCipher: KeyCipher): Boolean {
Expand Down Expand Up @@ -180,8 +180,4 @@ class EthereumModule(

fun WalletManager.getEthAccounts() = getAccounts().filter { it is EthAccount && it.isVisible }
// TODO remove
fun WalletManager.getActiveMasterseedEthAccounts(): List<WalletAccount<*>> = getAccounts().filter { it is EthAccount && it.isDerivedFromInternalMasterseed }

interface ServerEthListChangedListener {
fun serverListChanged(newEndpoints: Array<HttpEndpoint>)
}
fun WalletManager.getActiveMasterseedEthAccounts(): List<WalletAccount<*>> = getAccounts().filter { it is EthAccount && it.isDerivedFromInternalMasterseed }
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,8 @@ class Web3jWrapper(endpoints: List<HttpEndpoint>) : ServerEthListChangedListener
class ParityAllTransactionsResponse : Response<ArrayList<Transaction>>() {
val transactions: ArrayList<Transaction>
get() = result
}

interface ServerEthListChangedListener {
fun serverListChanged(newEndpoints: Array<HttpEndpoint>)
}

0 comments on commit 27e4ba9

Please sign in to comment.