'use strict'; var errors = require('@solana/errors'); var rpcSpecTypes = require('@solana/rpc-spec-types'); var rpcSpec = require('@solana/rpc-spec'); // src/http-transport.ts var DISALLOWED_HEADERS = { accept: true, "content-length": true, "content-type": true }; var FORBIDDEN_HEADERS = /* @__PURE__ */ Object.assign( { "accept-charset": true, "access-control-request-headers": true, "access-control-request-method": true, connection: true, "content-length": true, cookie: true, date: true, dnt: true, expect: true, host: true, "keep-alive": true, "permissions-policy": true, // Prefix matching is implemented in code, below. // 'proxy-': true, // 'sec-': true, referer: true, te: true, trailer: true, "transfer-encoding": true, upgrade: true, via: true }, void 0 , void 0 ); function assertIsAllowedHttpRequestHeaders(headers) { const badHeaders = Object.keys(headers).filter((headerName) => { const lowercaseHeaderName = headerName.toLowerCase(); return DISALLOWED_HEADERS[headerName.toLowerCase()] === true || FORBIDDEN_HEADERS[headerName.toLowerCase()] === true || lowercaseHeaderName.startsWith("proxy-") || lowercaseHeaderName.startsWith("sec-"); }); if (badHeaders.length > 0) { throw new errors.SolanaError(errors.SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN, { headers: badHeaders }); } } function normalizeHeaders(headers) { const out = {}; for (const headerName in headers) { out[headerName.toLowerCase()] = headers[headerName]; } return out; } // src/http-transport.ts function createHttpTransport(config) { if (process.env.NODE_ENV !== "production" && false) ; const { fromJson, headers, toJson, url } = config; if (process.env.NODE_ENV !== "production" && headers) { assertIsAllowedHttpRequestHeaders(headers); } let dispatcherConfig; if ("dispatcher_NODE_ONLY" in config) { dispatcherConfig = { dispatcher: config.dispatcher_NODE_ONLY }; } const customHeaders = headers && normalizeHeaders(headers); return async function makeHttpRequest({ payload, signal }) { const body = toJson ? toJson(payload) : JSON.stringify(payload); const requestInfo = { ...dispatcherConfig, body, headers: { ...customHeaders, // Keep these headers lowercase so they will override any user-supplied headers above. accept: "application/json", "content-length": body.length.toString(), "content-type": "application/json; charset=utf-8" }, method: "POST", signal }; const response = await fetch(url, requestInfo); if (!response.ok) { throw new errors.SolanaError(errors.SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, { headers: response.headers, message: response.statusText, statusCode: response.status }); } if (fromJson) { return fromJson(await response.text(), payload); } return await response.json(); }; } var SOLANA_RPC_METHODS = [ "getAccountInfo", "getBalance", "getBlock", "getBlockCommitment", "getBlockHeight", "getBlockProduction", "getBlocks", "getBlocksWithLimit", "getBlockTime", "getClusterNodes", "getEpochInfo", "getEpochSchedule", "getFeeForMessage", "getFirstAvailableBlock", "getGenesisHash", "getHealth", "getHighestSnapshotSlot", "getIdentity", "getInflationGovernor", "getInflationRate", "getInflationReward", "getLargestAccounts", "getLatestBlockhash", "getLeaderSchedule", "getMaxRetransmitSlot", "getMaxShredInsertSlot", "getMinimumBalanceForRentExemption", "getMultipleAccounts", "getProgramAccounts", "getRecentPerformanceSamples", "getRecentPrioritizationFees", "getSignaturesForAddress", "getSignatureStatuses", "getSlot", "getSlotLeader", "getSlotLeaders", "getStakeMinimumDelegation", "getSupply", "getTokenAccountBalance", "getTokenAccountsByDelegate", "getTokenAccountsByOwner", "getTokenLargestAccounts", "getTokenSupply", "getTransaction", "getTransactionCount", "getVersion", "getVoteAccounts", "index", "isBlockhashValid", "minimumLedgerSlot", "requestAirdrop", "sendTransaction", "simulateTransaction" ]; function isSolanaRequest(payload) { return rpcSpec.isJsonRpcPayload(payload) && SOLANA_RPC_METHODS.includes(payload.method); } // src/http-transport-for-solana-rpc.ts function createHttpTransportForSolanaRpc(config) { return createHttpTransport({ ...config, fromJson: (rawResponse, payload) => isSolanaRequest(payload) ? rpcSpecTypes.parseJsonWithBigInts(rawResponse) : JSON.parse(rawResponse), toJson: (payload) => isSolanaRequest(payload) ? rpcSpecTypes.stringifyJsonWithBigInts(payload) : JSON.stringify(payload) }); } exports.createHttpTransport = createHttpTransport; exports.createHttpTransportForSolanaRpc = createHttpTransportForSolanaRpc; //# sourceMappingURL=index.node.cjs.map //# sourceMappingURL=index.node.cjs.map