chaingate
Version:
A complete TypeScript library for connecting to and making transactions on different blockchains
66 lines • 4.93 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HDWallet = void 0;
const CurrencyWithDerivationPaths_1 = require("./CurrencyWithDerivationPaths");
const Wallet_1 = require("../../Wallet");
const Arbitrum_1 = require("../../entities/Currency/implementations/Arbitrum");
const Avalanche_1 = require("../../entities/Currency/implementations/Avalanche");
const Base_1 = require("../../entities/Currency/implementations/Base");
const BNBChain_1 = require("../../entities/Currency/implementations/BNBChain");
const Ethereum_1 = require("../../entities/Currency/implementations/Ethereum/Ethereum");
const FantomOpera_1 = require("../../entities/Currency/implementations/FantomOpera");
const Polygon_1 = require("../../entities/Currency/implementations/Polygon");
const Bitcoin_1 = require("../../entities/Currency/implementations/Bitcoin/Bitcoin");
const BitcoinTestnet_1 = require("../../entities/Currency/implementations/BitcoinTestnet/BitcoinTestnet");
const Dogecoin_1 = require("../../entities/Currency/implementations/Dogecoin/Dogecoin");
const Litecoin_1 = require("../../entities/Currency/implementations/Litecoin/Litecoin");
const BitcoinCash_1 = require("../../entities/Currency/implementations/BitcoinCash/BitcoinCash");
class HDWallet extends Wallet_1.Wallet {
derivationPaths;
derivationResults;
constructor(apiClient, currencyProviders) {
super(apiClient, currencyProviders);
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.currencyInfo.defaultDerivationPath);
for (const derivationPath of currency.currencyInfo.commonDerivationPaths)
await this.deriveFromPathUsingCache(derivationPath);
}
}
setDerivationPath(currencyInfo, derivationPath) {
return this.derivationPaths.set(currencyInfo.id, derivationPath);
}
getDerivationPath(currencyInfo) {
return this.derivationPaths.get(currencyInfo.id) ?? currencyInfo.defaultDerivationPath;
}
currency(currency) {
const currencyMap = {
'arbitrum': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Arbitrum_1.Arbitrum(this.apiClient.ArbitrumApi, this.currencyProviders), this.derivationPaths),
'avalanche': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Avalanche_1.Avalanche(this.apiClient.AvalancheApi, this.currencyProviders), this.derivationPaths),
'base': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Base_1.Base(this.apiClient.BaseApi, this.currencyProviders), this.derivationPaths),
'bnbChain': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new BNBChain_1.BNBChain(this.apiClient.BNBChainApi, this.currencyProviders), this.derivationPaths),
'ethereum': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Ethereum_1.Ethereum(this.apiClient.EthereumApi, this.currencyProviders), this.derivationPaths),
'fantomOpera': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new FantomOpera_1.FantomOpera(this.apiClient.FantomOperaApi, this.currencyProviders), this.derivationPaths),
'polygon': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Polygon_1.Polygon(this.apiClient.PolygonApi, this.currencyProviders), this.derivationPaths),
'bitcoin': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Bitcoin_1.Bitcoin(this.apiClient.BitcoinApi, this.currencyProviders), this.derivationPaths),
'bitcoinTestnet': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new BitcoinTestnet_1.BitcoinTestnet(this.apiClient.BitcoinTestnetApi, this.currencyProviders), this.derivationPaths),
'dogecoin': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Dogecoin_1.Dogecoin(this.apiClient.DogecoinApi, this.currencyProviders), this.derivationPaths),
'litecoin': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Litecoin_1.Litecoin(this.apiClient.LitecoinApi, this.currencyProviders), this.derivationPaths),
'bitcoinCash': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new BitcoinCash_1.BitcoinCash(this.apiClient.BitcoinCashApi, this.currencyProviders), this.derivationPaths)
};
return currencyMap[currency];
}
}
exports.HDWallet = HDWallet;
//# sourceMappingURL=HDWallet.js.map