UNPKG

chaingate

Version:

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

66 lines 5.02 kB
"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 Sonic_1 = require("../../entities/Currency/implementations/Sonic"); 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.client, this.client.ArbitrumApi, this.currencyProviders), this.derivationPaths), 'avalanche': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Avalanche_1.Avalanche(this.client, this.client.AvalancheApi, this.currencyProviders), this.derivationPaths), 'base': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Base_1.Base(this.client, this.client.BaseApi, this.currencyProviders), this.derivationPaths), 'bnbChain': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new BNBChain_1.BNBChain(this.client, this.client.BNBChainApi, this.currencyProviders), this.derivationPaths), 'ethereum': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Ethereum_1.Ethereum(this.client, this.client.EthereumApi, this.currencyProviders), this.derivationPaths), 'sonic': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Sonic_1.Sonic(this.client, this.client.FantomOperaApi, this.currencyProviders), this.derivationPaths), 'polygon': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Polygon_1.Polygon(this.client, this.client.PolygonApi, this.currencyProviders), this.derivationPaths), 'bitcoin': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Bitcoin_1.Bitcoin(this.client, this.client.BitcoinApi, this.currencyProviders), this.derivationPaths), 'bitcoinTestnet': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new BitcoinTestnet_1.BitcoinTestnet(this.client, this.client.BitcoinTestnetApi, this.currencyProviders), this.derivationPaths), 'dogecoin': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Dogecoin_1.Dogecoin(this.client, this.client.DogecoinApi, this.currencyProviders), this.derivationPaths), 'litecoin': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new Litecoin_1.Litecoin(this.client, this.client.LitecoinApi, this.currencyProviders), this.derivationPaths), 'bitcoinCash': (0, CurrencyWithDerivationPaths_1.CurrencyWithDerivationPaths)(new BitcoinCash_1.BitcoinCash(this.client, this.client.BitcoinCashApi, this.currencyProviders), this.derivationPaths) }; return currencyMap[currency]; } } exports.HDWallet = HDWallet; //# sourceMappingURL=HDWallet.js.map