UNPKG

@ledgerhq/ledger-cal-service

Version:
47 lines 2.34 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.findCurrencyData = exports.NoCurrencyFound = void 0; const live_network_1 = __importDefault(require("@ledgerhq/live-network")); const common_1 = require("./common"); const live_env_1 = require("@ledgerhq/live-env"); // https://github.com/LedgerHQ/crypto-assets-service/blob/master/modules/api/src/main/scala/co/ledger/cal/api/assets/v1/model/asset/Currency.scala#L95 const OUTPUT_FILTER = "id,type,chain_id,coin_type,confirmations_needed,deposit_amount,family,has_tokens,name,network_magic,network,network_type,symbol,ticker,units,descriptor_exchange_app,blockchain_name,exchange_app_config_serialized,exchange_app_signature"; class NoCurrencyFound extends Error { constructor(message) { super(message); this.name = "NoCurrencyFound"; } } exports.NoCurrencyFound = NoCurrencyFound; async function findCurrencyData(id, { env = "prod", signatureKind = "prod", ref = (0, live_env_1.getEnv)("CAL_REF") || undefined, } = common_1.DEFAULT_OPTION) { // https://github.com/LedgerHQ/crypto-assets-service/blob/master/modules/service/src/main/scala/co/ledger/cal/service/api/ApiCALService.scala#L237 const { data: currencyData } = await (0, live_network_1.default)({ url: `${(0, common_1.getCALDomain)(env)}/v1/currencies`, params: { output: OUTPUT_FILTER, id, ref, }, }); if (!currencyData.length) { throw new NoCurrencyFound(`CAL currencies, missing configuration for ${id}`); } if (currencyData.length !== 1) { throw new NoCurrencyFound(`CAL currencies, multiple configurations found for ${id}`); } return { id: currencyData[0].id, chainId: currencyData[0]?.chain_id, coinType: currencyData[0].coin_type, config: currencyData[0].descriptor_exchange_app.data, signature: currencyData[0].descriptor_exchange_app.signatures[signatureKind], symbol: currencyData[0].symbol, ticker: currencyData[0].ticker, units: currencyData[0].units, }; } exports.findCurrencyData = findCurrencyData; //# sourceMappingURL=currencies.js.map