{"version":3,"sources":["../src/http-transport-headers.ts","../src/http-transport.ts","../src/is-solana-request.ts","../src/http-transport-for-solana-rpc.ts"],"names":["SolanaError","SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN","SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR","isJsonRpcPayload","parseJsonWithBigInts","stringifyJsonWithBigInts"],"mappings":";;;;;;;AAkDA,IAAM,kBAAA,GAA8C;AAAA,EAChD,MAAA,EAAQ,IAAA;AAAA,EACR,gBAAA,EAAkB,IAAA;AAAA,EAClB,cAAA,EAAgB;AACpB,CAAA;AAEA,IAAM,oCAA6D,MAAA,CAAO,MAAA;AAAA,EACtE;AAAA,IACI,gBAAA,EAAkB,IAAA;AAAA,IAClB,gCAAA,EAAkC,IAAA;AAAA,IAClC,+BAAA,EAAiC,IAAA;AAAA,IACjC,UAAA,EAAY,IAAA;AAAA,IACZ,gBAAA,EAAkB,IAAA;AAAA,IAClB,MAAA,EAAQ,IAAA;AAAA,IACR,IAAA,EAAM,IAAA;AAAA,IACN,GAAA,EAAK,IAAA;AAAA,IACL,MAAA,EAAQ,IAAA;AAAA,IACR,IAAA,EAAM,IAAA;AAAA,IACN,YAAA,EAAc,IAAA;AAAA,IACd,oBAAA,EAAsB,IAAA;AAAA;AAAA;AAAA;AAAA,IAItB,OAAA,EAAS,IAAA;AAAA,IACT,EAAA,EAAI,IAAA;AAAA,IACJ,OAAA,EAAS,IAAA;AAAA,IACT,mBAAA,EAAqB,IAAA;AAAA,IACrB,OAAA,EAAS,IAAA;AAAA,IACT,GAAA,EAAK;AAAA,GACT;AAAA,EACyB,EAAE,iBAAA,EAAmB,IAAA,EAAK;AAAA,EACrC,EAAE,MAAA,EAAQ,IAAA,EAAK;AACjC,CAAA;AAEO,SAAS,kCACZ,OAAA,EAC4C;AAC5C,EAAA,MAAM,aAAa,MAAA,CAAO,IAAA,CAAK,OAAO,CAAA,CAAE,OAAO,CAAA,UAAA,KAAc;AACzD,IAAA,MA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AAA,KACL,eAAA,CAAgB,OAAO,CAAA,GAAIC,qCAAA,CAAyB,OAAO,CAAA,GAAI,IAAA,CAAK,SAAA,CAAU,OAAO;AAAA,GAC5F,CAAA;AACL","file":"index.browser.cjs","sourcesContent":["import { SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN, SolanaError } from '@solana/errors';\n\nexport type AllowedHttpRequestHeaders = Readonly<\n {\n // Someone can still sneak a forbidden header past Typescript if they do something like\n // fOo-BaR, but at that point they deserve the runtime failure.\n [K in DisallowedHeaders | ForbiddenHeaders as\n | Capitalize> // `Foo-bar`\n | K // `Foo-Bar`\n | Lowercase // `foo-bar`\n | Uncapitalize // `foo-Bar`\n // `FOO-BAR`\n | Uppercase]?: never;\n } & { [headerName: string]: string }\n>;\n// These are headers that we simply don't allow the developer to override because they're\n// fundamental to the operation of the JSON-RPC transport.\ntype DisallowedHeaders = 'Accept' | 'Content-Length' | 'Content-Type' | 'Solana-Client';\ntype ForbiddenHeaders =\n | 'Accept-Charset'\n // Though technically forbidden in non-Node environments, we don't have a way to target\n // TypeScript types depending on which platform you are authoring for. `Accept-Encoding` is\n // therefore omitted from the forbidden headers type, but is still a runtime error in dev mode\n // when supplied in a non-Node context.\n // | 'Accept-Encoding'\n | 'Access-Control-Request-Headers'\n | 'Access-Control-Request-Method'\n | 'Connection'\n | 'Content-Length'\n | 'Cookie'\n | 'Date'\n | 'DNT'\n | 'Expect'\n | 'Host'\n | 'Keep-Alive'\n // Similar to `Accept-Encoding`, we don't have a way to target TypeScript types depending on\n // which platform you are authoring for. `Origin` is therefore omitted from the forbidden\n // headers type, but is still a runtime error in dev mode when supplied in a browser context.\n // | 'Origin'\n | 'Permissions-Policy'\n | 'Referer'\n | 'TE'\n | 'Trailer'\n | 'Transfer-Encoding'\n | 'Upgrade'\n | 'Via'\n | `Proxy-${string}`\n | `Sec-${string}`;\n\n// These are headers which are fundamental to the JSON-RPC transport, and must not be modified.\nconst DISALLOWED_HEADERS: Record = {\n accept: true,\n 'content-length': true,\n 'content-type': true,\n};\n// https://developer.mozilla.org/en-US/docs/Glossary/Forbidden_header_name\nconst FORBIDDEN_HEADERS: Record = /* @__PURE__ */ Object.assign(\n {\n 'accept-charset': true,\n 'access-control-request-headers': true,\n 'access-control-request-method': true,\n connection: true,\n 'content-length': true,\n cookie: true,\n date: true,\n dnt: true,\n expect: true,\n host: true,\n 'keep-alive': true,\n 'permissions-policy': true,\n // Prefix matching is implemented in code, below.\n // 'proxy-': true,\n // 'sec-': true,\n referer: true,\n te: true,\n trailer: true,\n 'transfer-encoding': true,\n upgrade: true,\n via: true,\n },\n __NODEJS__ ? undefined : { 'accept-encoding': true },\n __BROWSER__ ? { origin: true } : undefined,\n);\n\nexport function assertIsAllowedHttpRequestHeaders(\n headers: Record,\n): asserts headers is AllowedHttpRequestHeaders {\n const badHeaders = Object.keys(headers).filter(headerName => {\n const lowercaseHeaderName = headerName.toLowerCase();\n return (\n DISALLOWED_HEADERS[headerName.toLowerCase()] === true ||\n FORBIDDEN_HEADERS[headerName.toLowerCase()] === true ||\n lowercaseHeaderName.startsWith('proxy-') ||\n lowercaseHeaderName.startsWith('sec-')\n );\n });\n if (badHeaders.length > 0) {\n throw new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_HEADER_FORBIDDEN, {\n headers: badHeaders,\n });\n }\n}\n\n// Lowercasing header names makes it easier to override user-supplied headers, such as those defined\n// in the `DisallowedHeaders` type.\nexport function normalizeHeaders>(\n headers: T,\n): { [K in string & keyof T as Lowercase]: T[K] } {\n const out: Record = {};\n for (const headerName in headers) {\n out[headerName.toLowerCase()] = headers[headerName];\n }\n return out as { [K in string & keyof T as Lowercase]: T[K] };\n}\n","import { SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, SolanaError } from '@solana/errors';\nimport type { RpcTransport } from '@solana/rpc-spec';\nimport type { RpcResponse } from '@solana/rpc-spec-types';\nimport type Dispatcher from 'undici-types/dispatcher';\n\nimport { HttpTransportConfig as Config } from './http-transport-config';\nimport { assertIsAllowedHttpRequestHeaders, normalizeHeaders } from './http-transport-headers';\n\nlet didWarnDispatcherWasSuppliedInNonNodeEnvironment = false;\nfunction warnDispatcherWasSuppliedInNonNodeEnvironment() {\n if (didWarnDispatcherWasSuppliedInNonNodeEnvironment) {\n return;\n }\n didWarnDispatcherWasSuppliedInNonNodeEnvironment = true;\n console.warn(\n 'You have supplied a `Dispatcher` to `createHttpTransport()`. It has been ignored ' +\n 'because Undici dispatchers only work in Node environments. To eliminate this ' +\n 'warning, omit the `dispatcher_NODE_ONLY` property from your config when running in ' +\n 'a non-Node environment.',\n );\n}\n\n/**\n * Creates a function you can use to make `POST` requests with headers suitable for sending JSON\n * data to a server.\n *\n * @example\n * ```ts\n * import { createHttpTransport } from '@solana/rpc-transport-http';\n *\n * const transport = createHttpTransport({ url: 'https://api.mainnet-beta.solana.com' });\n * const response = await transport({\n * payload: { id: 1, jsonrpc: '2.0', method: 'getSlot' },\n * });\n * const data = await response.json();\n * ```\n */\nexport function createHttpTransport(config: Config): RpcTransport {\n if (process.env.NODE_ENV !== \"production\" && !__NODEJS__ && 'dispatcher_NODE_ONLY' in config) {\n warnDispatcherWasSuppliedInNonNodeEnvironment();\n }\n const { fromJson, headers, toJson, url } = config;\n if (process.env.NODE_ENV !== \"production\" && headers) {\n assertIsAllowedHttpRequestHeaders(headers);\n }\n let dispatcherConfig: { dispatcher: Dispatcher | undefined } | undefined;\n if (__NODEJS__ && 'dispatcher_NODE_ONLY' in config) {\n dispatcherConfig = { dispatcher: config.dispatcher_NODE_ONLY };\n }\n const customHeaders = headers && normalizeHeaders(headers);\n return async function makeHttpRequest({\n payload,\n signal,\n }: Parameters[0]): Promise> {\n const body = toJson ? toJson(payload) : JSON.stringify(payload);\n const requestInfo = {\n ...dispatcherConfig,\n body,\n headers: {\n ...customHeaders,\n // Keep these headers lowercase so they will override any user-supplied headers above.\n accept: 'application/json',\n 'content-length': body.length.toString(),\n 'content-type': 'application/json; charset=utf-8',\n },\n method: 'POST',\n signal,\n };\n const response = await fetch(url, requestInfo);\n if (!response.ok) {\n throw new SolanaError(SOLANA_ERROR__RPC__TRANSPORT_HTTP_ERROR, {\n headers: response.headers,\n message: response.statusText,\n statusCode: response.status,\n });\n }\n if (fromJson) {\n return fromJson(await response.text(), payload) as TResponse;\n }\n return await response.json();\n };\n}\n","import { isJsonRpcPayload } from '@solana/rpc-spec';\n\nconst SOLANA_RPC_METHODS = [\n 'getAccountInfo',\n 'getBalance',\n 'getBlock',\n 'getBlockCommitment',\n 'getBlockHeight',\n 'getBlockProduction',\n 'getBlocks',\n 'getBlocksWithLimit',\n 'getBlockTime',\n 'getClusterNodes',\n 'getEpochInfo',\n 'getEpochSchedule',\n 'getFeeForMessage',\n 'getFirstAvailableBlock',\n 'getGenesisHash',\n 'getHealth',\n 'getHighestSnapshotSlot',\n 'getIdentity',\n 'getInflationGovernor',\n 'getInflationRate',\n 'getInflationReward',\n 'getLargestAccounts',\n 'getLatestBlockhash',\n 'getLeaderSchedule',\n 'getMaxRetransmitSlot',\n 'getMaxShredInsertSlot',\n 'getMinimumBalanceForRentExemption',\n 'getMultipleAccounts',\n 'getProgramAccounts',\n 'getRecentPerformanceSamples',\n 'getRecentPrioritizationFees',\n 'getSignaturesForAddress',\n 'getSignatureStatuses',\n 'getSlot',\n 'getSlotLeader',\n 'getSlotLeaders',\n 'getStakeMinimumDelegation',\n 'getSupply',\n 'getTokenAccountBalance',\n 'getTokenAccountsByDelegate',\n 'getTokenAccountsByOwner',\n 'getTokenLargestAccounts',\n 'getTokenSupply',\n 'getTransaction',\n 'getTransactionCount',\n 'getVersion',\n 'getVoteAccounts',\n 'index',\n 'isBlockhashValid',\n 'minimumLedgerSlot',\n 'requestAirdrop',\n 'sendTransaction',\n 'simulateTransaction',\n] as const;\n\n/**\n * Helper function that checks if a given `RpcRequest` comes from the Solana RPC API.\n */\nexport function isSolanaRequest(payload: unknown): payload is Readonly<{\n jsonrpc: '2.0';\n method: (typeof SOLANA_RPC_METHODS)[number];\n params: unknown;\n}> {\n return isJsonRpcPayload(payload) && (SOLANA_RPC_METHODS as readonly string[]).includes(payload.method);\n}\n","import { RpcTransport } from '@solana/rpc-spec';\nimport { parseJsonWithBigInts, stringifyJsonWithBigInts } from '@solana/rpc-spec-types';\n\nimport { createHttpTransport } from './http-transport';\nimport { HttpTransportConfig } from './http-transport-config';\nimport { isSolanaRequest } from './is-solana-request';\n\ntype Config = Pick;\n\n/**\n * Creates a {@link RpcTransport} that uses JSON HTTP requests — much like the\n * {@link createHttpTransport} function - except that it also uses custom `toJson` and `fromJson`\n * functions in order to allow `bigint` values to be serialized and deserialized correctly over the\n * wire.\n *\n * Since this is something specific to the Solana RPC API, these custom JSON functions are only\n * triggered when the request is recognized as a Solana RPC request. Normal RPC APIs should aim to\n * wrap their `bigint` values — e.g. `u64` or `i64` — in special value objects that represent the\n * number as a string to avoid numerical values going above `Number.MAX_SAFE_INTEGER`.\n *\n * It has the same configuration options as {@link createHttpTransport}, but without the `fromJson`\n * and `toJson` options.\n */\nexport function createHttpTransportForSolanaRpc(config: Config): RpcTransport {\n return createHttpTransport({\n ...config,\n fromJson: (rawResponse: string, payload: unknown) =>\n isSolanaRequest(payload) ? parseJsonWithBigInts(rawResponse) : JSON.parse(rawResponse),\n toJson: (payload: unknown) =>\n isSolanaRequest(payload) ? stringifyJsonWithBigInts(payload) : JSON.stringify(payload),\n });\n}\n"]}