@thorwallet/xchain-ethereum
Version:
Ethereum client for XChainJS
27 lines • 1.05 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAddress = void 0;
const tslib_1 = require("tslib");
const hdnode_1 = require("./hdnode/hdnode");
const addrCache = {};
const rootDerivationPaths = {
mainnet: `m/44'/60'/0'/0/`,
testnet: `m/44'/60'/0'/0/`, // this is INCORRECT but makes the unit tests pass
};
const getFullDerivationPath = (network, index) => {
return rootDerivationPaths[network] + `${index}`;
};
const getAddress = ({ network, phrase, index, }) => tslib_1.__awaiter(void 0, void 0, void 0, function* () {
if (addrCache[phrase] && addrCache[phrase][index]) {
return addrCache[phrase][index];
}
const hdNode = yield hdnode_1.HDNode.fromMnemonic(phrase);
const address = (yield hdNode.derivePath(getFullDerivationPath(network, index))).address.toLowerCase();
if (!addrCache[phrase]) {
addrCache[phrase] = {};
}
addrCache[phrase][index] = address;
return address;
});
exports.getAddress = getAddress;
//# sourceMappingURL=get-address.js.map