Minor updates #1

Closed
tornadocontrib wants to merge 67 commits from tornadocontrib/tornado-core:main into main
11 changed files with 217 additions and 123 deletions
Showing only changes of commit df54da689c - Show all commits

50
dist/index.js vendored
View File

@ -398,7 +398,6 @@ class BatchEventsService {
}
const defaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0";
const fetch = crossFetch;
function getHttpAgent({
fetchUrl,
proxyUrl,
@ -429,6 +428,7 @@ async function fetchData(url, options = {}) {
const MAX_RETRY = options.maxRetry ?? 3;
const RETRY_ON = options.retryOn ?? 500;
const userAgent = options.userAgent ?? defaultUserAgent;
const fetch = globalThis.useGlobalFetch ? globalThis.fetch : crossFetch;
let retry = 0;
let errorObject;
if (!options.method) {
@ -452,6 +452,14 @@ async function fetchData(url, options = {}) {
timeout = setTimeout(() => {
controller.abort();
}, options.timeout);
if (options.cancelSignal) {
if (options.cancelSignal.cancelled) {
throw new Error("request cancelled before sending");
}
options.cancelSignal.addListener(() => {
controller.abort();
});
}
}
if (!options.agent && isNode && (options.proxy || options.torPort)) {
options.agent = getHttpAgent({
@ -516,20 +524,13 @@ async function fetchData(url, options = {}) {
throw errorObject;
}
const fetchGetUrlFunc = (options = {}) => async (req, _signal) => {
let signal;
if (_signal) {
const controller = new AbortController();
signal = controller.signal;
_signal.addListener(() => {
controller.abort();
});
}
const init = {
...options,
method: req.method || "POST",
headers: req.headers,
body: req.body || void 0,
signal,
timeout: options.timeout || req.timeout,
cancelSignal: _signal,
returnResponse: true
};
const resp = await fetchData(req.url, init);
@ -740,15 +741,15 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/mainnet"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com"
},
mevblockerRPC: {
name: "MevblockerRPC",
name: "MEV Blocker",
url: "https://rpc.mevblocker.io"
},
keydonix: {
name: "keydonix",
name: "Horswap ( Keydonix )",
url: "https://ethereum.keydonix.com/v1/mainnet"
},
SecureRpc: {
@ -756,7 +757,7 @@ const defaultConfig = {
url: "https://api.securerpc.com/v1"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/ethereum-mainnet"
},
oneRpc: {
@ -891,7 +892,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/bsc"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/bsc"
},
bnbchain: {
@ -899,7 +900,7 @@ const defaultConfig = {
url: "https://bsc-dataseed.bnbchain.org"
},
ninicoin: {
name: "ninicoin",
name: "BNB Chain 2",
url: "https://bsc-dataseed1.ninicoin.io"
},
nodereal: {
@ -907,7 +908,7 @@ const defaultConfig = {
url: "https://binance.nodereal.io"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/bsc-mainnet"
},
oneRpc: {
@ -962,7 +963,7 @@ const defaultConfig = {
url: "https://1rpc.io/matic"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/polygon-mainnet"
}
},
@ -1014,7 +1015,7 @@ const defaultConfig = {
url: "https://1rpc.io/op"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/optimism-mainnet"
}
},
@ -1061,11 +1062,11 @@ const defaultConfig = {
subgraphs: {},
rpcUrls: {
Arbitrum: {
name: "Arbitrum RPC",
name: "Arbitrum",
url: "https://arb1.arbitrum.io/rpc"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/arbitrum-one"
},
oneRpc: {
@ -1120,7 +1121,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/gnosis"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/gnosis"
},
gnosis: {
@ -1179,7 +1180,7 @@ const defaultConfig = {
url: "https://1rpc.io/avax/c"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/avalanche-mainnet"
}
},
@ -1235,7 +1236,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/sepolia"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/sepolia"
},
sepolia: {
@ -10402,7 +10403,6 @@ exports.enabledChains = enabledChains;
exports.encodedLabelToLabelhash = encodedLabelToLabelhash;
exports.encryptedNotesSchema = encryptedNotesSchema;
exports.factories = index;
exports.fetch = fetch;
exports.fetchData = fetchData;
exports.fetchGetUrlFunc = fetchGetUrlFunc;
exports.fetchIp = fetchIp;

51
dist/index.mjs vendored
View File

@ -377,7 +377,6 @@ class BatchEventsService {
}
const defaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0";
const fetch = crossFetch;
function getHttpAgent({
fetchUrl,
proxyUrl,
@ -408,6 +407,7 @@ async function fetchData(url, options = {}) {
const MAX_RETRY = options.maxRetry ?? 3;
const RETRY_ON = options.retryOn ?? 500;
const userAgent = options.userAgent ?? defaultUserAgent;
const fetch = globalThis.useGlobalFetch ? globalThis.fetch : crossFetch;
let retry = 0;
let errorObject;
if (!options.method) {
@ -431,6 +431,14 @@ async function fetchData(url, options = {}) {
timeout = setTimeout(() => {
controller.abort();
}, options.timeout);
if (options.cancelSignal) {
if (options.cancelSignal.cancelled) {
throw new Error("request cancelled before sending");
}
options.cancelSignal.addListener(() => {
controller.abort();
});
}
}
if (!options.agent && isNode && (options.proxy || options.torPort)) {
options.agent = getHttpAgent({
@ -495,20 +503,13 @@ async function fetchData(url, options = {}) {
throw errorObject;
}
const fetchGetUrlFunc = (options = {}) => async (req, _signal) => {
let signal;
if (_signal) {
const controller = new AbortController();
signal = controller.signal;
_signal.addListener(() => {
controller.abort();
});
}
const init = {
...options,
method: req.method || "POST",
headers: req.headers,
body: req.body || void 0,
signal,
timeout: options.timeout || req.timeout,
cancelSignal: _signal,
returnResponse: true
};
const resp = await fetchData(req.url, init);
@ -719,15 +720,15 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/mainnet"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com"
},
mevblockerRPC: {
name: "MevblockerRPC",
name: "MEV Blocker",
url: "https://rpc.mevblocker.io"
},
keydonix: {
name: "keydonix",
name: "Horswap ( Keydonix )",
url: "https://ethereum.keydonix.com/v1/mainnet"
},
SecureRpc: {
@ -735,7 +736,7 @@ const defaultConfig = {
url: "https://api.securerpc.com/v1"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/ethereum-mainnet"
},
oneRpc: {
@ -870,7 +871,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/bsc"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/bsc"
},
bnbchain: {
@ -878,7 +879,7 @@ const defaultConfig = {
url: "https://bsc-dataseed.bnbchain.org"
},
ninicoin: {
name: "ninicoin",
name: "BNB Chain 2",
url: "https://bsc-dataseed1.ninicoin.io"
},
nodereal: {
@ -886,7 +887,7 @@ const defaultConfig = {
url: "https://binance.nodereal.io"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/bsc-mainnet"
},
oneRpc: {
@ -941,7 +942,7 @@ const defaultConfig = {
url: "https://1rpc.io/matic"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/polygon-mainnet"
}
},
@ -993,7 +994,7 @@ const defaultConfig = {
url: "https://1rpc.io/op"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/optimism-mainnet"
}
},
@ -1040,11 +1041,11 @@ const defaultConfig = {
subgraphs: {},
rpcUrls: {
Arbitrum: {
name: "Arbitrum RPC",
name: "Arbitrum",
url: "https://arb1.arbitrum.io/rpc"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/arbitrum-one"
},
oneRpc: {
@ -1099,7 +1100,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/gnosis"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/gnosis"
},
gnosis: {
@ -1158,7 +1159,7 @@ const defaultConfig = {
url: "https://1rpc.io/avax/c"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/avalanche-mainnet"
}
},
@ -1214,7 +1215,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/sepolia"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/sepolia"
},
sepolia: {
@ -10299,4 +10300,4 @@ async function calculateSnarkProof(input, circuit, provingKey) {
return { proof, args };
}
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseRegistryService, BaseRevenueService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DBEchoService, DBEncryptedNotesService, DBGovernanceService, DBRegistryService, DBRevenueService, DBTornadoService, DEPOSIT, Deposit, ENSNameWrapper__factory, ENSRegistry__factory, ENSResolver__factory, ENSUtils, ENS__factory, ERC20__factory, EnsContracts, INDEX_DB_ERROR, IndexedDB, Invoice, MAX_FEE, MAX_TOVARISH_EVENTS, MIN_FEE, MIN_STAKE_BALANCE, MerkleTreeService, Mimc, Multicall__factory, NetId, NoteAccount, OffchainOracle__factory, OvmGasPriceOracle__factory, Pedersen, RelayerClient, ReverseRecords__factory, TokenPriceOracle, TornadoBrowserProvider, TornadoFeeOracle, TornadoRpcSigner, TornadoVoidSigner, TornadoWallet, TovarishClient, WITHDRAWAL, addNetwork, addressSchemaType, ajv, base64ToBytes, bigIntReplacer, bnSchemaType, bnToBytes, buffPedersenHash, bufferToBytes, bytes32BNSchemaType, bytes32SchemaType, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, deployHasher, depositsEventsSchema, digest, downloadZip, echoEventsSchema, enabledChains, encodedLabelToLabelhash, encryptedNotesSchema, index as factories, fetch, fetchData, fetchGetUrlFunc, fetchIp, gasZipID, gasZipInbounds, gasZipInput, gasZipMinMax, getActiveTokenInstances, getActiveTokens, getConfig, getEventsSchemaValidator, getHttpAgent, getIndexedDB, getInstanceByAddress, getNetworkConfig, getPermit2CommitmentsSignature, getPermit2Signature, getPermitCommitmentsSignature, getPermitSignature, getProvider, getProviderWithNetId, getRelayerEnsSubdomains, getStatusSchema, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, governanceEventsSchema, hasherBytecode, hexToBytes, initGroth16, isHex, isNode, jobRequestSchema, jobsSchema, labelhash, leBuff2Int, leInt2Buff, loadDBEvents, loadRemoteEvents, makeLabelNodeAndParent, mimc, multicall, numberFormatter, packEncryptedMessage, parseInvoice, parseNote, pedersen, permit2Address, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, rBigInt, rHex, relayerRegistryEventsSchema, saveDBEvents, sleep, stakeBurnedEventsSchema, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync };
export { BaseEchoService, BaseEncryptedNotesService, BaseEventsService, BaseGovernanceService, BaseRegistryService, BaseRevenueService, BaseTornadoService, BatchBlockService, BatchEventsService, BatchTransactionService, DBEchoService, DBEncryptedNotesService, DBGovernanceService, DBRegistryService, DBRevenueService, DBTornadoService, DEPOSIT, Deposit, ENSNameWrapper__factory, ENSRegistry__factory, ENSResolver__factory, ENSUtils, ENS__factory, ERC20__factory, EnsContracts, INDEX_DB_ERROR, IndexedDB, Invoice, MAX_FEE, MAX_TOVARISH_EVENTS, MIN_FEE, MIN_STAKE_BALANCE, MerkleTreeService, Mimc, Multicall__factory, NetId, NoteAccount, OffchainOracle__factory, OvmGasPriceOracle__factory, Pedersen, RelayerClient, ReverseRecords__factory, TokenPriceOracle, TornadoBrowserProvider, TornadoFeeOracle, TornadoRpcSigner, TornadoVoidSigner, TornadoWallet, TovarishClient, WITHDRAWAL, addNetwork, addressSchemaType, ajv, base64ToBytes, bigIntReplacer, bnSchemaType, bnToBytes, buffPedersenHash, bufferToBytes, bytes32BNSchemaType, bytes32SchemaType, bytesToBN, bytesToBase64, bytesToHex, calculateScore, calculateSnarkProof, chunk, concatBytes, convertETHToTokenAmount, createDeposit, crypto, customConfig, defaultConfig, defaultUserAgent, deployHasher, depositsEventsSchema, digest, downloadZip, echoEventsSchema, enabledChains, encodedLabelToLabelhash, encryptedNotesSchema, index as factories, fetchData, fetchGetUrlFunc, fetchIp, gasZipID, gasZipInbounds, gasZipInput, gasZipMinMax, getActiveTokenInstances, getActiveTokens, getConfig, getEventsSchemaValidator, getHttpAgent, getIndexedDB, getInstanceByAddress, getNetworkConfig, getPermit2CommitmentsSignature, getPermit2Signature, getPermitCommitmentsSignature, getPermitSignature, getProvider, getProviderWithNetId, getRelayerEnsSubdomains, getStatusSchema, getSupportedInstances, getTokenBalances, getTovarishNetworks, getWeightRandom, governanceEventsSchema, hasherBytecode, hexToBytes, initGroth16, isHex, isNode, jobRequestSchema, jobsSchema, labelhash, leBuff2Int, leInt2Buff, loadDBEvents, loadRemoteEvents, makeLabelNodeAndParent, mimc, multicall, numberFormatter, packEncryptedMessage, parseInvoice, parseNote, pedersen, permit2Address, pickWeightedRandomRelayer, populateTransaction, proofSchemaType, proposalState, rBigInt, rHex, relayerRegistryEventsSchema, saveDBEvents, sleep, stakeBurnedEventsSchema, substring, toFixedHex, toFixedLength, unpackEncryptedMessage, unzipAsync, validateUrl, withdrawalsEventsSchema, zipAsync };

4
dist/providers.d.ts vendored
View File

@ -1,6 +1,6 @@
import type { EventEmitter } from 'stream';
import type { RequestOptions } from 'http';
import { JsonRpcApiProvider, JsonRpcProvider, Wallet, FetchGetUrlFunc, Provider, SigningKey, TransactionRequest, JsonRpcSigner, BrowserProvider, Networkish, Eip1193Provider, VoidSigner } from 'ethers';
import { JsonRpcApiProvider, JsonRpcProvider, Wallet, FetchGetUrlFunc, Provider, SigningKey, TransactionRequest, JsonRpcSigner, BrowserProvider, Networkish, Eip1193Provider, VoidSigner, FetchCancelSignal } from 'ethers';
import type { RequestInfo, RequestInit, Response, HeadersInit } from 'node-fetch';
import type { Config, NetIdType } from './networkConfig';
declare global {
@ -9,7 +9,6 @@ declare global {
}
}
export declare const defaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0";
export declare const fetch: nodeFetch;
export type nodeFetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
export type fetchDataOptions = RequestInit & {
headers?: HeadersInit | any;
@ -21,6 +20,7 @@ export type fetchDataOptions = RequestInit & {
torPort?: number;
debug?: Function;
returnResponse?: boolean;
cancelSignal?: FetchCancelSignal;
};
export type NodeAgent = RequestOptions['agent'] | ((parsedUrl: URL) => RequestOptions['agent']);
export declare function getHttpAgent({ fetchUrl, proxyUrl, torPort, retry, }: {

53
dist/tornado.umd.js vendored
View File

@ -91367,15 +91367,15 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/mainnet"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com"
},
mevblockerRPC: {
name: "MevblockerRPC",
name: "MEV Blocker",
url: "https://rpc.mevblocker.io"
},
keydonix: {
name: "keydonix",
name: "Horswap ( Keydonix )",
url: "https://ethereum.keydonix.com/v1/mainnet"
},
SecureRpc: {
@ -91383,7 +91383,7 @@ const defaultConfig = {
url: "https://api.securerpc.com/v1"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/ethereum-mainnet"
},
oneRpc: {
@ -91518,7 +91518,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/bsc"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/bsc"
},
bnbchain: {
@ -91526,7 +91526,7 @@ const defaultConfig = {
url: "https://bsc-dataseed.bnbchain.org"
},
ninicoin: {
name: "ninicoin",
name: "BNB Chain 2",
url: "https://bsc-dataseed1.ninicoin.io"
},
nodereal: {
@ -91534,7 +91534,7 @@ const defaultConfig = {
url: "https://binance.nodereal.io"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/bsc-mainnet"
},
oneRpc: {
@ -91589,7 +91589,7 @@ const defaultConfig = {
url: "https://1rpc.io/matic"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/polygon-mainnet"
}
},
@ -91641,7 +91641,7 @@ const defaultConfig = {
url: "https://1rpc.io/op"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/optimism-mainnet"
}
},
@ -91688,11 +91688,11 @@ const defaultConfig = {
subgraphs: {},
rpcUrls: {
Arbitrum: {
name: "Arbitrum RPC",
name: "Arbitrum",
url: "https://arb1.arbitrum.io/rpc"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/arbitrum-one"
},
oneRpc: {
@ -91747,7 +91747,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/gnosis"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/gnosis"
},
gnosis: {
@ -91806,7 +91806,7 @@ const defaultConfig = {
url: "https://1rpc.io/avax/c"
},
stackup: {
name: "Stackup RPC",
name: "Stackup",
url: "https://public.stackup.sh/api/v1/node/avalanche-mainnet"
}
},
@ -91862,7 +91862,7 @@ const defaultConfig = {
url: "https://tornadowithdraw.com/sepolia"
},
tornadoRpc: {
name: "Tornado RPC",
name: "torn-city.eth",
url: "https://tornadocash-rpc.com/sepolia"
},
sepolia: {
@ -92461,7 +92461,6 @@ __webpack_require__.d(__webpack_exports__, {
Gd: () => (/* binding */ TornadoVoidSigner),
nA: () => (/* binding */ TornadoWallet),
mJ: () => (/* binding */ defaultUserAgent),
hd: () => (/* binding */ providers_fetch),
Fd: () => (/* binding */ fetchData),
uY: () => (/* binding */ fetchGetUrlFunc),
WU: () => (/* binding */ getHttpAgent),
@ -99405,7 +99404,6 @@ var src_utils = __webpack_require__(67418);
const defaultUserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0";
const providers_fetch = (browser_ponyfill_default());
function getHttpAgent({
fetchUrl,
proxyUrl,
@ -99436,6 +99434,7 @@ async function fetchData(url, options = {}) {
const MAX_RETRY = options.maxRetry ?? 3;
const RETRY_ON = options.retryOn ?? 500;
const userAgent = options.userAgent ?? defaultUserAgent;
const fetch = globalThis.useGlobalFetch ? globalThis.fetch : (browser_ponyfill_default());
let retry = 0;
let errorObject;
if (!options.method) {
@ -99459,6 +99458,14 @@ async function fetchData(url, options = {}) {
timeout = setTimeout(() => {
controller.abort();
}, options.timeout);
if (options.cancelSignal) {
if (options.cancelSignal.cancelled) {
throw new Error("request cancelled before sending");
}
options.cancelSignal.addListener(() => {
controller.abort();
});
}
}
if (!options.agent && src_utils/* isNode */.Ll && (options.proxy || options.torPort)) {
options.agent = getHttpAgent({
@ -99477,7 +99484,7 @@ async function fetchData(url, options = {}) {
});
}
try {
const resp = await providers_fetch(url, {
const resp = await fetch(url, {
method: options.method,
headers: options.headers,
body: options.body,
@ -99523,20 +99530,13 @@ async function fetchData(url, options = {}) {
throw errorObject;
}
const fetchGetUrlFunc = (options = {}) => async (req, _signal) => {
let signal;
if (_signal) {
const controller = new AbortController();
signal = controller.signal;
_signal.addListener(() => {
controller.abort();
});
}
const init = {
...options,
method: req.method || "POST",
headers: req.headers,
body: req.body || void 0,
signal,
timeout: options.timeout || req.timeout,
cancelSignal: _signal,
returnResponse: true
};
const resp = await fetchData(req.url, init);
@ -209683,7 +209683,6 @@ __webpack_require__.r(__webpack_exports__);
/* harmony export */ encodedLabelToLabelhash: () => (/* reexport safe */ _ens__WEBPACK_IMPORTED_MODULE_6__.qX),
/* harmony export */ encryptedNotesSchema: () => (/* reexport safe */ _schemas__WEBPACK_IMPORTED_MODULE_1__.XW),
/* harmony export */ factories: () => (/* reexport safe */ _typechain__WEBPACK_IMPORTED_MODULE_2__.XB),
/* harmony export */ fetch: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_19__.hd),
/* harmony export */ fetchData: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_19__.Fd),
/* harmony export */ fetchGetUrlFunc: () => (/* reexport safe */ _providers__WEBPACK_IMPORTED_MODULE_19__.uY),
/* harmony export */ fetchIp: () => (/* reexport safe */ _ip__WEBPACK_IMPORTED_MODULE_11__.W),

File diff suppressed because one or more lines are too long

View File

@ -74,6 +74,7 @@
"eslint-import-resolver-typescript": "^3.6.3",
"eslint-plugin-import": "^2.31.0",
"eslint-plugin-prettier": "^5.2.1",
"fetch-mock": "^12.0.2",
"hardhat": "^2.22.10",
"hardhat-gas-reporter": "^2.2.1",
"mocha": "^10.7.3",

View File

@ -131,15 +131,15 @@ export const defaultConfig: networkConfig = {
url: 'https://tornadowithdraw.com/mainnet',
},
tornadoRpc: {
name: 'Tornado RPC',
name: 'torn-city.eth',
url: 'https://tornadocash-rpc.com',
},
mevblockerRPC: {
name: 'MevblockerRPC',
name: 'MEV Blocker',
url: 'https://rpc.mevblocker.io',
},
keydonix: {
name: 'keydonix',
name: 'Horswap ( Keydonix )',
url: 'https://ethereum.keydonix.com/v1/mainnet',
},
SecureRpc: {
@ -147,7 +147,7 @@ export const defaultConfig: networkConfig = {
url: 'https://api.securerpc.com/v1',
},
stackup: {
name: 'Stackup RPC',
name: 'Stackup',
url: 'https://public.stackup.sh/api/v1/node/ethereum-mainnet',
},
oneRpc: {
@ -282,7 +282,7 @@ export const defaultConfig: networkConfig = {
url: 'https://tornadowithdraw.com/bsc',
},
tornadoRpc: {
name: 'Tornado RPC',
name: 'torn-city.eth',
url: 'https://tornadocash-rpc.com/bsc',
},
bnbchain: {
@ -290,7 +290,7 @@ export const defaultConfig: networkConfig = {
url: 'https://bsc-dataseed.bnbchain.org',
},
ninicoin: {
name: 'ninicoin',
name: 'BNB Chain 2',
url: 'https://bsc-dataseed1.ninicoin.io',
},
nodereal: {
@ -298,7 +298,7 @@ export const defaultConfig: networkConfig = {
url: 'https://binance.nodereal.io',
},
stackup: {
name: 'Stackup RPC',
name: 'Stackup',
url: 'https://public.stackup.sh/api/v1/node/bsc-mainnet',
},
oneRpc: {
@ -353,7 +353,7 @@ export const defaultConfig: networkConfig = {
url: 'https://1rpc.io/matic',
},
stackup: {
name: 'Stackup RPC',
name: 'Stackup',
url: 'https://public.stackup.sh/api/v1/node/polygon-mainnet',
},
},
@ -405,7 +405,7 @@ export const defaultConfig: networkConfig = {
url: 'https://1rpc.io/op',
},
stackup: {
name: 'Stackup RPC',
name: 'Stackup',
url: 'https://public.stackup.sh/api/v1/node/optimism-mainnet',
},
},
@ -452,11 +452,11 @@ export const defaultConfig: networkConfig = {
subgraphs: {},
rpcUrls: {
Arbitrum: {
name: 'Arbitrum RPC',
name: 'Arbitrum',
url: 'https://arb1.arbitrum.io/rpc',
},
stackup: {
name: 'Stackup RPC',
name: 'Stackup',
url: 'https://public.stackup.sh/api/v1/node/arbitrum-one',
},
oneRpc: {
@ -511,7 +511,7 @@ export const defaultConfig: networkConfig = {
url: 'https://tornadowithdraw.com/gnosis',
},
tornadoRpc: {
name: 'Tornado RPC',
name: 'torn-city.eth',
url: 'https://tornadocash-rpc.com/gnosis',
},
gnosis: {
@ -570,7 +570,7 @@ export const defaultConfig: networkConfig = {
url: 'https://1rpc.io/avax/c',
},
stackup: {
name: 'Stackup RPC',
name: 'Stackup',
url: 'https://public.stackup.sh/api/v1/node/avalanche-mainnet',
},
},
@ -626,7 +626,7 @@ export const defaultConfig: networkConfig = {
url: 'https://tornadowithdraw.com/sepolia',
},
tornadoRpc: {
name: 'Tornado RPC',
name: 'torn-city.eth',
url: 'https://tornadocash-rpc.com/sepolia',
},
sepolia: {

View File

@ -19,6 +19,7 @@ import {
Network,
EnsPlugin,
GasCostPlugin,
FetchCancelSignal,
} from 'ethers';
import type { RequestInfo, RequestInit, Response, HeadersInit } from 'node-fetch';
// Temporary workaround until @types/node-fetch is compatible with @types/node
@ -35,8 +36,6 @@ declare global {
// Update this for every Tor Browser release
export const defaultUserAgent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:128.0) Gecko/20100101 Firefox/128.0';
export const fetch = crossFetch as unknown as nodeFetch;
export type nodeFetch = (url: RequestInfo, init?: RequestInit) => Promise<Response>;
export type fetchDataOptions = RequestInit & {
@ -51,6 +50,7 @@ export type fetchDataOptions = RequestInit & {
// eslint-disable-next-line @typescript-eslint/no-unsafe-function-type
debug?: Function;
returnResponse?: boolean;
cancelSignal?: FetchCancelSignal;
};
export type NodeAgent = RequestOptions['agent'] | ((parsedUrl: URL) => RequestOptions['agent']);
@ -99,6 +99,10 @@ export async function fetchData(url: string, options: fetchDataOptions = {}) {
const RETRY_ON = options.retryOn ?? 500;
const userAgent = options.userAgent ?? defaultUserAgent;
const fetch = ((globalThis as unknown as { useGlobalFetch?: boolean }).useGlobalFetch
? globalThis.fetch
: crossFetch) as unknown as nodeFetch;
let retry = 0;
let errorObject;
@ -121,7 +125,6 @@ export async function fetchData(url: string, options: fetchDataOptions = {}) {
while (retry < MAX_RETRY + 1) {
let timeout;
// Define promise timeout when the options.timeout is available
if (!options.signal && options.timeout) {
const controller = new AbortController();
@ -132,6 +135,18 @@ export async function fetchData(url: string, options: fetchDataOptions = {}) {
timeout = setTimeout(() => {
controller.abort();
}, options.timeout);
// Support Ethers.js style FetchCancelSignal class
if (options.cancelSignal) {
// assert(_signal == null || !_signal.cancelled, "request cancelled before sending", "CANCELLED");
if (options.cancelSignal.cancelled) {
throw new Error('request cancelled before sending');
}
options.cancelSignal.addListener(() => {
controller.abort();
});
}
}
if (!options.agent && isNode && (options.proxy || options.torPort)) {
@ -217,23 +232,13 @@ export async function fetchData(url: string, options: fetchDataOptions = {}) {
export const fetchGetUrlFunc =
(options: fetchDataOptions = {}): FetchGetUrlFunc =>
async (req, _signal) => {
let signal;
if (_signal) {
const controller = new AbortController();
// Temporary workaround until @types/node-fetch is compatible with @types/node
signal = controller.signal as FetchAbortSignal;
_signal.addListener(() => {
controller.abort();
});
}
const init = {
...options,
method: req.method || 'POST',
headers: req.headers,
body: req.body || undefined,
signal,
timeout: options.timeout || req.timeout,
cancelSignal: _signal,
returnResponse: true,
};

View File

@ -1,14 +0,0 @@
import { describe } from 'mocha';
import { ethers } from 'hardhat';
describe('Tornado Core', function () {
it('Get Provider', async function () {
const [owner] = await ethers.getSigners();
console.log(owner);
const { provider } = owner;
console.log(await provider.getBlock('latest'));
});
});

64
test/provider.ts Normal file
View File

@ -0,0 +1,64 @@
import fetchMock from 'fetch-mock';
import { FetchRequest } from 'ethers';
import { expect } from 'chai';
import { getProvider } from '../src';
(globalThis as unknown as { useGlobalFetch?: boolean }).useGlobalFetch = true;
const ETHERS_DEFAULT_TIMEOUT = new FetchRequest('').timeout;
describe('provider', function () {
it('getProvider', async function () {
// https://ethereum.github.io/execution-apis/api-documentation/
fetchMock.mockGlobal();
fetchMock.postOnce(
'http://localhost:8545/',
{
jsonrpc: '2.0',
result: '0x1',
id: 0,
},
{
delay: 1000,
},
);
const provider = await getProvider('http://localhost:8545', {
netId: 1,
});
expect((await provider.getNetwork()).chainId).to.be.equal(1n);
expect(provider._getConnection().timeout).to.be.equal(ETHERS_DEFAULT_TIMEOUT);
fetchMock.unmockGlobal();
});
it('timeout', async function () {
// https://ethereum.github.io/execution-apis/api-documentation/
fetchMock.mockGlobal();
fetchMock.postOnce(
'http://localhost:8545/',
{
jsonrpc: '2.0',
result: '0x1',
id: 0,
},
{
delay: 1000,
},
);
try {
await getProvider('http://localhost:8545', {
netId: 1,
timeout: 100,
});
// eslint-disable-next-line @typescript-eslint/no-explicit-any
} catch (err: any) {
expect(err.message.includes('The operation was aborted')).to.be.true;
}
});
});

View File

@ -1546,6 +1546,11 @@
resolved "https://registry.yarnpkg.com/@types/estree/-/estree-1.0.6.tgz#628effeeae2064a1b4e79f78e81d87b7e5fc7b50"
integrity sha512-AYnb1nQyY49te+VRAVgmzfcgjYS91mY5P0TKUDCLEM+gNnA+3T6rWITXRLYCpahpqSQbN5cE+gHpnPyXjHWxcw==
"@types/glob-to-regexp@^0.4.4":
version "0.4.4"
resolved "https://registry.yarnpkg.com/@types/glob-to-regexp/-/glob-to-regexp-0.4.4.tgz#409e71290253203185b1ea8a3d6ea406a4bdc902"
integrity sha512-nDKoaKJYbnn1MZxUY0cA1bPmmgZbg0cTq7Rh13d0KWYNOiKbqoR+2d89SnRPszGh7ROzSwZ/GOjZ4jPbmmZ6Eg==
"@types/glob@^7.1.1":
version "7.2.0"
resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.2.0.tgz#bc1b5bf3aa92f25bd5dd39f35c57361bdce5b2eb"
@ -3066,6 +3071,11 @@ depd@2.0.0:
resolved "https://registry.yarnpkg.com/depd/-/depd-2.0.0.tgz#b696163cc757560d09cf22cc8fad1571b79e76df"
integrity sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==
dequal@^2.0.3:
version "2.0.3"
resolved "https://registry.yarnpkg.com/dequal/-/dequal-2.0.3.tgz#2644214f1997d39ed0ee0ece72335490a7ac67be"
integrity sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==
des.js@^1.0.0:
version "1.1.0"
resolved "https://registry.yarnpkg.com/des.js/-/des.js-1.1.0.tgz#1d37f5766f3bbff4ee9638e871a8768c173b81da"
@ -3899,6 +3909,17 @@ fdir@^6.2.0:
resolved "https://registry.yarnpkg.com/fdir/-/fdir-6.4.0.tgz#8e80ab4b18a2ac24beebf9d20d71e1bc2627dbae"
integrity sha512-3oB133prH1o4j/L5lLW7uOCF1PlD+/It2L0eL/iAqWMB91RBbqTewABqxhj0ibBd90EEmWZq7ntIWzVaWcXTGQ==
fetch-mock@^12.0.2:
version "12.0.2"
resolved "https://registry.yarnpkg.com/fetch-mock/-/fetch-mock-12.0.2.tgz#380363c7a79e8d9f87d9d0267717eef56a3bbe64"
integrity sha512-9KVq/Scz06A+ThORLA/J/EACiPzLdSn6DeLV61hni57kd3DXhQVCtkpj4LgwES+8osEVEfcqA6LwdSX2FYVK7w==
dependencies:
"@types/glob-to-regexp" "^0.4.4"
dequal "^2.0.3"
glob-to-regexp "^0.4.1"
is-subset-of "^3.1.10"
regexparam "^3.0.0"
ffjavascript@0.2.48:
version "0.2.48"
resolved "https://registry.yarnpkg.com/ffjavascript/-/ffjavascript-0.2.48.tgz#0ca408471d7b18bfc096a9631aa3ef3549c8c82b"
@ -4926,6 +4947,13 @@ is-string@^1.0.5, is-string@^1.0.7:
dependencies:
has-tostringtag "^1.0.0"
is-subset-of@^3.1.10:
version "3.1.10"
resolved "https://registry.yarnpkg.com/is-subset-of/-/is-subset-of-3.1.10.tgz#d3f4331b9ca288318fae92ad5d953241b6f7b00b"
integrity sha512-avvaYgVmYWyaZ1NDFiv4y9JGkrE2je3op1Po4VYKKJKR8H2qVPsg1GZuuXl5elCTxTlwAIsrAjWAs4BVrISFRw==
dependencies:
typedescriptor "3.0.2"
is-symbol@^1.0.2, is-symbol@^1.0.3:
version "1.0.4"
resolved "https://registry.yarnpkg.com/is-symbol/-/is-symbol-1.0.4.tgz#a6dac93b635b063ca6872236de88910a57af139c"
@ -6304,6 +6332,11 @@ regexp.prototype.flags@^1.5.2:
es-errors "^1.3.0"
set-function-name "^2.0.1"
regexparam@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/regexparam/-/regexparam-3.0.0.tgz#1673e09d41cb7fd41eaafd4040a6aa90daa0a21a"
integrity sha512-RSYAtP31mvYLkAHrOlh25pCNQ5hWnT106VukGaaFfuJrZFkGRX5GhUAdPqpSDXxOhA2c4akmRuplv1mRqnBn6Q==
regexpp@^2.0.1:
version "2.0.1"
resolved "https://registry.yarnpkg.com/regexpp/-/regexpp-2.0.1.tgz#8d19d31cf632482b589049f8281f93dbcba4d07f"
@ -7361,6 +7394,11 @@ typedarray-to-buffer@^3.1.5:
dependencies:
is-typedarray "^1.0.0"
typedescriptor@3.0.2:
version "3.0.2"
resolved "https://registry.yarnpkg.com/typedescriptor/-/typedescriptor-3.0.2.tgz#9ad1715bc2be1cf063d5acbc4cd4bfc96d644225"
integrity sha512-hyVbaCUd18UiXk656g/imaBLMogpdijIEpnhWYrSda9rhvO4gOU16n2nh7xG5lv/rjumnZzGOdz0CEGTmFe0fQ==
typescript@^5.6.3:
version "5.6.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-5.6.3.tgz#5f3449e31c9d94febb17de03cc081dd56d81db5b"