Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@xchainjs/xchain-util

Package Overview
Dependencies
Maintainers
10
Versions
42
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@xchainjs/xchain-util - npm Package Compare versions

Comparing version 0.11.0 to 0.11.1

lib/ninerealms.d.ts

1

lib/index.d.ts

@@ -7,1 +7,2 @@ export * from './async';

export * from './types';
export * from './ninerealms';

@@ -630,3 +630,42 @@ import BigNumber from 'bignumber.js';

export { AVAXChain, AssetAVAX, AssetAtom, AssetBCH, AssetBNB, AssetBTC, AssetCurrencySymbol, AssetDOGE, AssetETH, AssetLTC, AssetRune67C, AssetRuneB1A, AssetRuneERC20, AssetRuneERC20Testnet, AssetRuneNative, AvalancheChain, BCHChain, BNBChain, BTCChain, Chain, CosmosChain, DOGEChain, Denomination, ETHChain, LTCChain, RUNE_TICKER, THORChain, assetAmount, assetFromString, assetFromStringEx, assetToBase, assetToString, baseAmount, baseToAsset, bn, bnOrZero, chainToString, currencySymbolByAsset, delay, eqAsset, eqChain, fixedBN, formatAssetAmount, formatAssetAmountCurrency, formatBN, formatBNCurrency, formatBaseAmount, formatBaseAsAssetAmount, getContractAddressFromAsset, isAssetAmount, isAssetRuneNative, isBaseAmount, isBchChain, isBigNumberValue, isBnbChain, isBtcChain, isChain, isDogeChain, isEnabledChain, isEthChain, isLtcChain, isSynthAsset, isThorChain, isValidAsset, isValidBN, strip0x, trimZeros, validBNOrZero };
const XCHAINJS_IDENTIFIER = 'xchainjs-client';
const NINE_REALMS_CLIENT_HEADER = 'x-client-id';
/**
* Middleware to add custom header to requests (9R endpoints only)
*
* @param request RequestArgs (rxjs/ajax) | AxiosRequestConfig (axios)
* @returns RequestArgs (rxjs/ajax) | AxiosRequestConfig (axios)
*/
const add9Rheader = (request) => {
var _a, _b;
try {
// URL throws an `TypeError` if `url` is not available and 'unknown-url' is set
// [TypeError: Invalid URL] input: 'unknown-url', code: 'ERR_INVALID_URL' }
const url = new URL((_a = request === null || request === void 0 ? void 0 : request.url) !== null && _a !== void 0 ? _a : 'unknown-url');
const headerAlreadyExists = request.headers && 'x-client-id' in request.headers;
if (url.host.includes('ninerealms') && !headerAlreadyExists) {
const headers = (_b = request === null || request === void 0 ? void 0 : request.headers) !== null && _b !== void 0 ? _b : {};
// Add custom header to request before returning it
const newRequest = Object.assign(Object.assign({}, request), { headers: Object.assign(Object.assign({}, headers), { [`${NINE_REALMS_CLIENT_HEADER}`]: `${XCHAINJS_IDENTIFIER}` }) });
// console.log(` Request ${newRequest.url} ${JSON.stringify(newRequest.headers)}`)
return newRequest;
}
}
catch (error) {
console.error(`Failed to add custom ${NINE_REALMS_CLIENT_HEADER} header`, error);
}
// If it errors, just return same request and keep it untouched (no change)
// console.log(` Request ${request.url} ${JSON.stringify(request.headers)}`)
return request;
};
/**
* Adds custom header to axios requests (9R endpoints only)
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const register9Rheader = (axios) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
axios.interceptors.request.use(add9Rheader, (error) => Promise.reject(error));
};
export { AVAXChain, AssetAVAX, AssetAtom, AssetBCH, AssetBNB, AssetBTC, AssetCurrencySymbol, AssetDOGE, AssetETH, AssetLTC, AssetRune67C, AssetRuneB1A, AssetRuneERC20, AssetRuneERC20Testnet, AssetRuneNative, AvalancheChain, BCHChain, BNBChain, BTCChain, Chain, CosmosChain, DOGEChain, Denomination, ETHChain, LTCChain, NINE_REALMS_CLIENT_HEADER, RUNE_TICKER, THORChain, XCHAINJS_IDENTIFIER, add9Rheader, assetAmount, assetFromString, assetFromStringEx, assetToBase, assetToString, baseAmount, baseToAsset, bn, bnOrZero, chainToString, currencySymbolByAsset, delay, eqAsset, eqChain, fixedBN, formatAssetAmount, formatAssetAmountCurrency, formatBN, formatBNCurrency, formatBaseAmount, formatBaseAsAssetAmount, getContractAddressFromAsset, isAssetAmount, isAssetRuneNative, isBaseAmount, isBchChain, isBigNumberValue, isBnbChain, isBtcChain, isChain, isDogeChain, isEnabledChain, isEthChain, isLtcChain, isSynthAsset, isThorChain, isValidAsset, isValidBN, register9Rheader, strip0x, trimZeros, validBNOrZero };
//# sourceMappingURL=index.esm.js.map

@@ -632,2 +632,41 @@ 'use strict';

const XCHAINJS_IDENTIFIER = 'xchainjs-client';
const NINE_REALMS_CLIENT_HEADER = 'x-client-id';
/**
* Middleware to add custom header to requests (9R endpoints only)
*
* @param request RequestArgs (rxjs/ajax) | AxiosRequestConfig (axios)
* @returns RequestArgs (rxjs/ajax) | AxiosRequestConfig (axios)
*/
const add9Rheader = (request) => {
var _a, _b;
try {
// URL throws an `TypeError` if `url` is not available and 'unknown-url' is set
// [TypeError: Invalid URL] input: 'unknown-url', code: 'ERR_INVALID_URL' }
const url = new URL((_a = request === null || request === void 0 ? void 0 : request.url) !== null && _a !== void 0 ? _a : 'unknown-url');
const headerAlreadyExists = request.headers && 'x-client-id' in request.headers;
if (url.host.includes('ninerealms') && !headerAlreadyExists) {
const headers = (_b = request === null || request === void 0 ? void 0 : request.headers) !== null && _b !== void 0 ? _b : {};
// Add custom header to request before returning it
const newRequest = Object.assign(Object.assign({}, request), { headers: Object.assign(Object.assign({}, headers), { [`${NINE_REALMS_CLIENT_HEADER}`]: `${XCHAINJS_IDENTIFIER}` }) });
// console.log(` Request ${newRequest.url} ${JSON.stringify(newRequest.headers)}`)
return newRequest;
}
}
catch (error) {
console.error(`Failed to add custom ${NINE_REALMS_CLIENT_HEADER} header`, error);
}
// If it errors, just return same request and keep it untouched (no change)
// console.log(` Request ${request.url} ${JSON.stringify(request.headers)}`)
return request;
};
/**
* Adds custom header to axios requests (9R endpoints only)
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const register9Rheader = (axios) => {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
axios.interceptors.request.use(add9Rheader, (error) => Promise.reject(error));
};
exports.AVAXChain = AVAXChain;

@@ -655,4 +694,7 @@ exports.AssetAVAX = AssetAVAX;

exports.LTCChain = LTCChain;
exports.NINE_REALMS_CLIENT_HEADER = NINE_REALMS_CLIENT_HEADER;
exports.RUNE_TICKER = RUNE_TICKER;
exports.THORChain = THORChain;
exports.XCHAINJS_IDENTIFIER = XCHAINJS_IDENTIFIER;
exports.add9Rheader = add9Rheader;
exports.assetAmount = assetAmount;

@@ -696,2 +738,3 @@ exports.assetFromString = assetFromString;

exports.isValidBN = isValidBN;
exports.register9Rheader = register9Rheader;
exports.strip0x = strip0x;

@@ -698,0 +741,0 @@ exports.trimZeros = trimZeros;

2

package.json
{
"name": "@xchainjs/xchain-util",
"version": "0.11.0",
"version": "0.11.1",
"description": "Helper utilities for XChain clients",

@@ -5,0 +5,0 @@ "keywords": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc