UNPKG

chaingate

Version:

A complete TypeScript library for connecting to and making transactions on different blockchains

44 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.HDWallet = void 0; const CurrencyWithDerivationPaths_1 = require("./CurrencyWithDerivationPaths"); const Wallet_1 = require("../../Wallet"); class HDWallet extends Wallet_1.Wallet { derivationPaths; derivationResults; constructor(context, transports) { super(context, transports); this.derivationPaths = new Map(); this.derivationResults = new Map(); } async deriveFromPathUsingCache(derivationPath) { let result = this.derivationResults.get(derivationPath); if (!result) { result = await this.deriveFromPath(derivationPath); this.derivationResults.set(derivationPath, result); } return result; } async generateAllCurrencyDefaultDerivations() { for (const currency of this.allCurrencies) { await this.deriveFromPathUsingCache(currency.utils.currencyInfo.defaultDerivationPath); for (const derivationPath of currency.utils.currencyInfo.commonDerivationPaths) await this.deriveFromPathUsingCache(derivationPath); } } setDerivationPath(id, derivationPath) { const currency = this.currency(id); return this.derivationPaths.set(currency.utils.currencyInfo.id, derivationPath); } getDerivationPath(id) { const currency = this.currency(id); return (this.derivationPaths.get(currency.utils.currencyInfo.id) ?? currency.utils.currencyInfo.defaultDerivationPath); } currency(id) { const currency = super.currency(id); return (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(currency, this.derivationPaths); } } exports.HDWallet = HDWallet; //# sourceMappingURL=HDWallet.js.map