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

Commit

Permalink
Merge pull request #72 from gre/fix/web3-subprovider-derivated-address
Browse files Browse the repository at this point in the history
Fix derivated Ethereum address to work in web3-subprovider
  • Loading branch information
gre authored Feb 9, 2018
2 parents a58f1ca + 7c97849 commit 4d4f378
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/web3-subprovider/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,23 @@ export default async function createLedgerSubprovider(

const pathComponents = obtainPathComponentsFromDerivationPath(path);

const addressToPathMap = {};

async function getAccounts() {
const addresses = {};
for (let i = accountsOffset; i < accountsOffset + accountsLength; i++) {
const path =
pathComponents.basePath + (pathComponents.index + i).toString();
const address = await eth.getAddress(path, askConfirm, false);
addresses[path] = address.address;
addressToPathMap[address.address] = path;
}
return addresses;
}

async function signPersonalMessage(msgData) {
const path = addressToPathMap[msgData.from];
if (!path) throw new Error("address unknown '" + msgData.from + "'");
const result = await eth.signPersonalMessage(
path,
stripHexPrefix(msgData.data)
Expand All @@ -122,6 +127,8 @@ export default async function createLedgerSubprovider(
}

async function signTransaction(txData) {
const path = addressToPathMap[txData.from];
if (!path) throw new Error("address unknown '" + txData.from + "'");
const tx = new EthereumTx(txData);

// Set the EIP155 bits
Expand Down

0 comments on commit 4d4f378

Please sign in to comment.