{"version":3,"file":"provider-from-middleware.cjs","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":";;;AAAA,+DAA2D;AAE3D,qDAA+D;AAQ/D,+DAAuD;AAEvD;;;;;;GAMG;AACH,SAAgB,sBAAsB,CAGpC,UAAmD;IACnD,OAAO,wBAAwB;IAC7B,sGAAsG;IACtG,mGAAmG;IACnG,sGAAsG;IACtG,oEAAoE;IACpE,IAAA,gCAAc,EAAC,UAAU,CAAsC,CAChE,CAAC;AACJ,CAAC;AAXD,wDAWC;AAED;;;;;GAKG;AACH,SAAgB,wBAAwB,CAOtC,UAAsB;IACtB,OAAO,IAAI,oCAAgB,CAAC;QAC1B,MAAM,EAAE,oBAAe,CAAC,MAAM,CAAC;YAC7B,4FAA4F;YAC5F,oGAAoG;YACpG,0DAA0D;YAC1D,UAAU,EAAE,CAAC,UAA+C,CAAC;SAC9D,CAAC;KACH,CAAC,CAAC;AACL,CAAC;AAhBD,4DAgBC","sourcesContent":["import { asV2Middleware } from '@metamask/json-rpc-engine';\nimport type { JsonRpcMiddleware as LegacyJsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { JsonRpcEngineV2 } from '@metamask/json-rpc-engine/v2';\nimport type {\n  ContextConstraint,\n  JsonRpcMiddleware,\n  ResultConstraint,\n} from '@metamask/json-rpc-engine/v2';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nimport { InternalProvider } from './internal-provider';\n\n/**\n * Construct an Ethereum provider from the given middleware.\n *\n * @param middleware - The middleware to construct a provider from.\n * @returns An Ethereum provider.\n * @deprecated Use `JsonRpcEngineV2` middleware and {@link providerFromMiddlewareV2} instead.\n */\nexport function providerFromMiddleware<\n  Params extends JsonRpcParams,\n  Result extends Json,\n>(middleware: LegacyJsonRpcMiddleware<Params, Result>): InternalProvider {\n  return providerFromMiddlewareV2(\n    // This function is generic on the Params and Result types to match the legacy JsonRpcMiddleware type.\n    // However, since the V2 JsonRpcMiddleware type is not generic on the Params, we need to elide this\n    // parameter by upcasting the request type to JsonRpcRequest, or we get an error due to contravariance\n    // since JsonRpcRequest<Params> is not assignable to JsonRpcRequest.\n    asV2Middleware(middleware) as JsonRpcMiddleware<JsonRpcRequest>,\n  );\n}\n\n/**\n * Construct an Ethereum provider from the given middleware.\n *\n * @param middleware - The middleware to construct a provider from.\n * @returns An Ethereum provider.\n */\nexport function providerFromMiddlewareV2<\n  Request extends JsonRpcRequest,\n  Middleware extends JsonRpcMiddleware<\n    Request,\n    ResultConstraint<Request>,\n    ContextConstraint\n  >,\n>(middleware: Middleware): InternalProvider {\n  return new InternalProvider({\n    engine: JsonRpcEngineV2.create({\n      // This function is generic in order to accept middleware functions with narrower types than\n      // the plain JsonRpcMiddleware<JsonRpcRequest> type. However, since InternalProvider is non-generic,\n      // we need to upcast the middleware to avoid a type error.\n      middleware: [middleware as JsonRpcMiddleware<JsonRpcRequest>],\n    }),\n  });\n}\n"]}