chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
40 lines • 1.66 kB
JavaScript
import { CurrencyWithDerivationPaths } from './CurrencyWithDerivationPaths';
import { Wallet } from '../../Wallet';
export class HDWallet extends Wallet {
derivationPaths;
derivationResults;
constructor(client, transports, markets) {
super(client, transports, markets);
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 CurrencyWithDerivationPaths(currency, this.derivationPaths);
}
}
//# sourceMappingURL=HDWallet.js.map