@metamask-previews/eth-json-rpc-provider 6.0.0-preview-7cfbb337 → 6.0.0-preview-6c66772
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/internal-provider.cjs.map +1 -1
- package/dist/internal-provider.d.cts +4 -3
- package/dist/internal-provider.d.cts.map +1 -1
- package/dist/internal-provider.d.mts +4 -3
- package/dist/internal-provider.d.mts.map +1 -1
- package/dist/internal-provider.mjs.map +1 -1
- package/dist/provider-from-middleware.cjs.map +1 -1
- package/dist/provider-from-middleware.d.cts +1 -2
- package/dist/provider-from-middleware.d.cts.map +1 -1
- package/dist/provider-from-middleware.d.mts +1 -2
- package/dist/provider-from-middleware.d.mts.map +1 -1
- package/dist/provider-from-middleware.mjs.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-provider.cjs","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+
|
|
1
|
+
{"version":3,"file":"internal-provider.cjs","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,+DAA2D;AAE3D,qDAA+D;AAc/D,mCAAgC;AAmBhC;;;;;GAKG;AACH,MAAa,gBAAgB;IAK3B;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAAoC;QAR/C,2CAAkD;QAkC3D;;;;;;;;;;WAUG;QACH,cAAS,GAAG,CACV,cAAsC;QACtC,mDAAmD;QACnD,8DAA8D;QAC9D,QAAqD,EACrD,EAAE;YACF,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAAI,4CAAoB,MAAxB,IAAI,EAAqB,cAAc,EAAE,QAAQ,CAAC,CAAC;QACrD,CAAC,CAAC;QAEF;;;;;;;;;;WAUG;QACH,SAAI,GAAG,CACL,cAAsC;QACtC,gCAAgC;QAChC,8DAA8D;QAC9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KAAK,CAAC,OAAO,CACX,cAAsC,EACtC,OAAgC;QAEhC,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;QACxD,OAAO,CAAC,MAAM,uBAAA,IAAI,gCAAQ,MAAZ,IAAI,EAAiB,cAAc,EAAE,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC;IACtE,CAAC;CAiFF;AApHD,4CAoHC;;AAED;;;;;GAKG;AACH,SAAgB,qCAAqC,CACnD,cAA8B;IAE9B,MAAM,EAAE,EAAE,GAAG,IAAA,eAAM,GAAE,EAAE,OAAO,GAAG,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,cAAc,CAAC;IAE1E,OAAO,MAAM;QACX,CAAC,CAAC;YACE,EAAE;YACF,OAAO;YACP,MAAM;YACN,MAAM;SACP;QACH,CAAC,CAAC;YACE,EAAE;YACF,OAAO;YACP,MAAM;SACP,CAAC;AACR,CAAC;AAjBD,sFAiBC","sourcesContent":["import { asV2Middleware } from '@metamask/json-rpc-engine';\nimport type { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport { JsonRpcEngineV2 } from '@metamask/json-rpc-engine/v2';\nimport type {\n HandleOptions,\n ContextConstraint,\n MiddlewareContext,\n} from '@metamask/json-rpc-engine/v2';\nimport type {\n Json,\n JsonRpcId,\n JsonRpcParams,\n JsonRpcSuccess,\n JsonRpcRequest,\n JsonRpcVersion2,\n} from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\n/**\n * A JSON-RPC request conforming to the EIP-1193 specification.\n */\ntype Eip1193Request<Params extends JsonRpcParams = JsonRpcParams> = {\n id?: JsonRpcId;\n jsonrpc?: JsonRpcVersion2;\n method: string;\n params?: Params;\n};\n\ntype Options<\n Request extends JsonRpcRequest = JsonRpcRequest,\n Context extends ContextConstraint = MiddlewareContext,\n> = {\n engine: JsonRpcEngine | JsonRpcEngineV2<Request, Context>;\n};\n\n/**\n * An Ethereum provider.\n *\n * This provider loosely follows conventions that pre-date EIP-1193.\n * It is not compliant with any Ethereum provider standard.\n */\nexport class InternalProvider<\n Context extends ContextConstraint = MiddlewareContext,\n> {\n readonly #engine: JsonRpcEngineV2<JsonRpcRequest, Context>;\n\n /**\n * Construct a InternalProvider from a JSON-RPC server or legacy engine.\n *\n * @param options - Options.\n * @param options.engine - The JSON-RPC engine used to process requests.\n */\n constructor({ engine }: Options<JsonRpcRequest, Context>) {\n this.#engine =\n 'push' in engine\n ? JsonRpcEngineV2.create({\n middleware: [asV2Middleware<JsonRpcParams, JsonRpcRequest>(engine)],\n })\n : engine;\n }\n\n /**\n * Send a provider request asynchronously.\n *\n * @param eip1193Request - The request to send.\n * @param options - The options for the request operation.\n * @param options.context - The context to include with the request.\n * @returns The JSON-RPC response.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n eip1193Request: Eip1193Request<Params>,\n options?: HandleOptions<Context>,\n ): Promise<Result> {\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n return (await this.#handle<Result>(jsonRpcRequest, options)).result;\n }\n\n /**\n * Send a provider request asynchronously.\n *\n * This method serves the same purpose as `request`. It only exists for\n * legacy reasons.\n *\n * @param eip1193Request - The request to send.\n * @param callback - A function that is called upon the success or failure of the request.\n * @deprecated Use {@link request} instead. This method is retained solely for backwards\n * compatibility with certain libraries.\n */\n sendAsync = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // Non-polluting `any` that acts like a constraint.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback: (error: unknown, providerRes?: any) => void,\n ) => {\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n this.#handleWithCallback(jsonRpcRequest, callback);\n };\n\n /**\n * Send a provider request asynchronously.\n *\n * This method serves the same purpose as `request`. It only exists for\n * legacy reasons.\n *\n * @param eip1193Request - The request to send.\n * @param callback - A function that is called upon the success or failure of the request.\n * @deprecated Use {@link request} instead. This method is retained solely for backwards\n * compatibility with certain libraries.\n */\n send = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback: (error: unknown, providerRes?: any) => void,\n ) => {\n if (typeof callback !== 'function') {\n throw new Error('Must provide callback to \"send\" method.');\n }\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n this.#handleWithCallback(jsonRpcRequest, callback);\n };\n\n readonly #handle = async <Result extends Json>(\n jsonRpcRequest: JsonRpcRequest,\n options?: HandleOptions<Context>,\n ): Promise<JsonRpcSuccess<Result>> => {\n const { id, jsonrpc } = jsonRpcRequest;\n // The `result` typecast is unsafe, but we need it to preserve the provider's\n // public interface, which allows you to unsafely typecast results.\n const result = (await this.#engine.handle(\n jsonRpcRequest,\n options,\n )) as unknown as Result;\n\n return {\n id,\n jsonrpc,\n result,\n };\n };\n\n readonly #handleWithCallback = (\n jsonRpcRequest: JsonRpcRequest,\n callback: (error: unknown, providerRes?: unknown) => void,\n ): void => {\n /* eslint-disable promise/no-callback-in-promise */\n this.#handle(jsonRpcRequest)\n // A resolution will always be a successful response\n .then((response) => callback(null, response))\n .catch((error) => {\n callback(error);\n });\n /* eslint-enable promise/no-callback-in-promise */\n };\n}\n\n/**\n * Convert an EIP-1193 request to a JSON-RPC request.\n *\n * @param eip1193Request - The EIP-1193 request to convert.\n * @returns The JSON-RPC request.\n */\nexport function convertEip1193RequestToJsonRpcRequest(\n eip1193Request: Eip1193Request,\n): JsonRpcRequest {\n const { id = nanoid(), jsonrpc = '2.0', method, params } = eip1193Request;\n\n return params\n ? {\n id,\n jsonrpc,\n method,\n params,\n }\n : {\n id,\n jsonrpc,\n method,\n };\n}\n"]}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import { JsonRpcEngineV2 } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import type { HandleOptions, ContextConstraint, MiddlewareContext } from "@metamask/json-rpc-engine/v2";
|
|
4
|
+
import type { Json, JsonRpcId, JsonRpcParams, JsonRpcRequest, JsonRpcVersion2 } from "@metamask/utils";
|
|
4
5
|
/**
|
|
5
6
|
* A JSON-RPC request conforming to the EIP-1193 specification.
|
|
6
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-provider.d.cts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal-provider.d.cts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,kCAAkC;AAC/D,OAAO,EAAE,eAAe,EAAE,qCAAqC;AAC/D,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EAClB,qCAAqC;AACtC,OAAO,KAAK,EACV,IAAI,EACJ,SAAS,EACT,aAAa,EAEb,cAAc,EACd,eAAe,EAChB,wBAAwB;AAGzB;;GAEG;AACH,KAAK,cAAc,CAAC,MAAM,SAAS,aAAa,GAAG,aAAa,IAAI;IAClE,EAAE,CAAC,EAAE,SAAS,CAAC;IACf,OAAO,CAAC,EAAE,eAAe,CAAC;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,KAAK,OAAO,CACV,OAAO,SAAS,cAAc,GAAG,cAAc,EAC/C,OAAO,SAAS,iBAAiB,GAAG,iBAAiB,IACnD;IACF,MAAM,EAAE,aAAa,GAAG,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;CAC3D,CAAC;AAEF;;;;;GAKG;AACH,qBAAa,gBAAgB,CAC3B,OAAO,SAAS,iBAAiB,GAAG,iBAAiB;;IAIrD;;;;;OAKG;gBACS,EAAE,MAAM,EAAE,EAAE,OAAO,CAAC,cAAc,EAAE,OAAO,CAAC;IASxD;;;;;;;OAOG;IACG,OAAO,CAAC,MAAM,SAAS,aAAa,EAAE,MAAM,SAAS,IAAI,EAC7D,cAAc,EAAE,cAAc,CAAC,MAAM,CAAC,EACtC,OAAO,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAC/B,OAAO,CAAC,MAAM,CAAC;IAMlB;;;;;;;;;;OAUG;IACH,SAAS,2FAIW,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAKrD;IAEF;;;;;;;;;;OAUG;IACH,IAAI,2FAIgB,OAAO,gBAAgB,GAAG,KAAK,IAAI,UAQrD;CAkCH;AAED;;;;;GAKG;AACH,wBAAgB,qCAAqC,CACnD,cAAc,EAAE,cAAc,GAC7B,cAAc,CAehB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import
|
|
1
|
+
import type { JsonRpcEngine } from "@metamask/json-rpc-engine";
|
|
2
|
+
import { JsonRpcEngineV2 } from "@metamask/json-rpc-engine/v2";
|
|
3
|
+
import type { HandleOptions, ContextConstraint, MiddlewareContext } from "@metamask/json-rpc-engine/v2";
|
|
4
|
+
import type { Json, JsonRpcId, JsonRpcParams, JsonRpcRequest, JsonRpcVersion2 } from "@metamask/utils";
|
|
4
5
|
/**
|
|
5
6
|
* A JSON-RPC request conforming to the EIP-1193 specification.
|
|
6
7
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"internal-provider.d.mts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"internal-provider.d.mts","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,kCAAkC;AAC/D,OAAO,EAAE,eAAe,EAAE,qCAAqC;AAC/D,OAAO,KAAK,EACV,aAAa,EACb,iBAAiB,EACjB,iBAAiB,EAClB,qCAAqC;AACtC,OAAO,KAAK,EACV,IAAI,EACJ,SAAS,EACT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pc-engine';\nimport type { JsonRpcEngine } from '@metamask/json-rpc-engine';\nimport { JsonRpcEngineV2 } from '@metamask/json-rpc-engine/v2';\nimport type {\n HandleOptions,\n ContextConstraint,\n MiddlewareContext,\n} from '@metamask/json-rpc-engine/v2';\nimport type {\n Json,\n JsonRpcId,\n JsonRpcParams,\n JsonRpcSuccess,\n JsonRpcRequest,\n JsonRpcVersion2,\n} from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\n/**\n * A JSON-RPC request conforming to the EIP-1193 specification.\n */\ntype Eip1193Request<Params extends JsonRpcParams = JsonRpcParams> = {\n id?: JsonRpcId;\n jsonrpc?: JsonRpcVersion2;\n method: string;\n params?: Params;\n};\n\ntype Options<\n Request extends JsonRpcRequest = JsonRpcRequest,\n Context extends ContextConstraint = MiddlewareContext,\n> = {\n engine: JsonRpcEngine | JsonRpcEngineV2<Request, Context>;\n};\n\n/**\n * An Ethereum provider.\n *\n * This provider loosely follows conventions that pre-date EIP-1193.\n * It is not compliant with any Ethereum provider standard.\n */\nexport class InternalProvider<\n Context extends ContextConstraint = MiddlewareContext,\n> {\n readonly #engine: JsonRpcEngineV2<JsonRpcRequest, Context>;\n\n /**\n * Construct a InternalProvider from a JSON-RPC server or legacy engine.\n *\n * @param options - Options.\n * @param options.engine - The JSON-RPC engine used to process requests.\n */\n constructor({ engine }: Options<JsonRpcRequest, Context>) {\n this.#engine =\n 'push' in engine\n ? JsonRpcEngineV2.create({\n middleware: [asV2Middleware<JsonRpcParams, JsonRpcRequest>(engine)],\n })\n : engine;\n }\n\n /**\n * Send a provider request asynchronously.\n *\n * @param eip1193Request - The request to send.\n * @param options - The options for the request operation.\n * @param options.context - The context to include with the request.\n * @returns The JSON-RPC response.\n */\n async request<Params extends JsonRpcParams, Result extends Json>(\n eip1193Request: Eip1193Request<Params>,\n options?: HandleOptions<Context>,\n ): Promise<Result> {\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n return (await this.#handle<Result>(jsonRpcRequest, options)).result;\n }\n\n /**\n * Send a provider request asynchronously.\n *\n * This method serves the same purpose as `request`. It only exists for\n * legacy reasons.\n *\n * @param eip1193Request - The request to send.\n * @param callback - A function that is called upon the success or failure of the request.\n * @deprecated Use {@link request} instead. This method is retained solely for backwards\n * compatibility with certain libraries.\n */\n sendAsync = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // Non-polluting `any` that acts like a constraint.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback: (error: unknown, providerRes?: any) => void,\n ) => {\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n this.#handleWithCallback(jsonRpcRequest, callback);\n };\n\n /**\n * Send a provider request asynchronously.\n *\n * This method serves the same purpose as `request`. It only exists for\n * legacy reasons.\n *\n * @param eip1193Request - The request to send.\n * @param callback - A function that is called upon the success or failure of the request.\n * @deprecated Use {@link request} instead. This method is retained solely for backwards\n * compatibility with certain libraries.\n */\n send = <Params extends JsonRpcParams>(\n eip1193Request: Eip1193Request<Params>,\n // TODO: Replace `any` with type\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n callback: (error: unknown, providerRes?: any) => void,\n ) => {\n if (typeof callback !== 'function') {\n throw new Error('Must provide callback to \"send\" method.');\n }\n const jsonRpcRequest =\n convertEip1193RequestToJsonRpcRequest(eip1193Request);\n this.#handleWithCallback(jsonRpcRequest, callback);\n };\n\n readonly #handle = async <Result extends Json>(\n jsonRpcRequest: JsonRpcRequest,\n options?: HandleOptions<Context>,\n ): Promise<JsonRpcSuccess<Result>> => {\n const { id, jsonrpc } = jsonRpcRequest;\n // The `result` typecast is unsafe, but we need it to preserve the provider's\n // public interface, which allows you to unsafely typecast results.\n const result = (await this.#engine.handle(\n jsonRpcRequest,\n options,\n )) as unknown as Result;\n\n return {\n id,\n jsonrpc,\n result,\n };\n };\n\n readonly #handleWithCallback = (\n jsonRpcRequest: JsonRpcRequest,\n callback: (error: unknown, providerRes?: unknown) => void,\n ): void => {\n /* eslint-disable promise/no-callback-in-promise */\n this.#handle(jsonRpcRequest)\n // A resolution will always be a successful response\n .then((response) => callback(null, response))\n .catch((error) => {\n callback(error);\n });\n /* eslint-enable promise/no-callback-in-promise */\n };\n}\n\n/**\n * Convert an EIP-1193 request to a JSON-RPC request.\n *\n * @param eip1193Request - The EIP-1193 request to convert.\n * @returns The JSON-RPC request.\n */\nexport function convertEip1193RequestToJsonRpcRequest(\n eip1193Request: Eip1193Request,\n): JsonRpcRequest {\n const { id = nanoid(), jsonrpc = '2.0', method, params } = eip1193Request;\n\n return params\n ? {\n id,\n jsonrpc,\n method,\n params,\n }\n : {\n id,\n jsonrpc,\n method,\n };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-from-middleware.cjs","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":";;;AAAA,+DAA2D;
|
|
1
|
+
{"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"]}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { JsonRpcMiddleware as LegacyJsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type { JsonRpcMiddleware, ResultConstraint } from "@metamask/json-rpc-engine/v2";
|
|
3
|
-
import { type ContextConstraint } from "@metamask/json-rpc-engine/v2";
|
|
2
|
+
import type { ContextConstraint, JsonRpcMiddleware, ResultConstraint } from "@metamask/json-rpc-engine/v2";
|
|
4
3
|
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
5
4
|
import { InternalProvider } from "./internal-provider.cjs";
|
|
6
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-from-middleware.d.cts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.d.cts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,kCAAkC;AAE9F,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,EACnB,UAAU,EAAE,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,CAQvE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,SAAS,cAAc,EAC9B,UAAU,SAAS,iBAAiB,CAClC,OAAO,EACP,gBAAgB,CAAC,OAAO,CAAC,EACzB,iBAAiB,CAClB,EACD,UAAU,EAAE,UAAU,GAAG,gBAAgB,CAS1C"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { JsonRpcMiddleware as LegacyJsonRpcMiddleware } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type { JsonRpcMiddleware, ResultConstraint } from "@metamask/json-rpc-engine/v2";
|
|
3
|
-
import { type ContextConstraint } from "@metamask/json-rpc-engine/v2";
|
|
2
|
+
import type { ContextConstraint, JsonRpcMiddleware, ResultConstraint } from "@metamask/json-rpc-engine/v2";
|
|
4
3
|
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
5
4
|
import { InternalProvider } from "./internal-provider.mjs";
|
|
6
5
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-from-middleware.d.mts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.d.mts","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,IAAI,uBAAuB,EAAE,kCAAkC;AAE9F,OAAO,KAAK,EACV,iBAAiB,EACjB,iBAAiB,EACjB,gBAAgB,EACjB,qCAAqC;AACtC,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc,EAAE,wBAAwB;AAE3E,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CACpC,MAAM,SAAS,aAAa,EAC5B,MAAM,SAAS,IAAI,EACnB,UAAU,EAAE,uBAAuB,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,gBAAgB,CAQvE;AAED;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,SAAS,cAAc,EAC9B,UAAU,SAAS,iBAAiB,CAClC,OAAO,EACP,gBAAgB,CAAC,OAAO,CAAC,EACzB,iBAAiB,CAClB,EACD,UAAU,EAAE,UAAU,GAAG,gBAAgB,CAS1C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-from-middleware.mjs","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;
|
|
1
|
+
{"version":3,"file":"provider-from-middleware.mjs","sourceRoot":"","sources":["../src/provider-from-middleware.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EAAE,eAAe,EAAE,qCAAqC;AAQ/D,OAAO,EAAE,gBAAgB,EAAE,gCAA4B;AAEvD;;;;;;GAMG;AACH,MAAM,UAAU,sBAAsB,CAGpC,UAAmD;IACnD,OAAO,wBAAwB;IAC7B,sGAAsG;IACtG,mGAAmG;IACnG,sGAAsG;IACtG,oEAAoE;IACpE,cAAc,CAAC,UAAU,CAAsC,CAChE,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,wBAAwB,CAOtC,UAAsB;IACtB,OAAO,IAAI,gBAAgB,CAAC;QAC1B,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC;YAC7B,4FAA4F;YAC5F,oGAAoG;YACpG,0DAA0D;YAC1D,UAAU,EAAE,CAAC,UAA+C,CAAC;SAC9D,CAAC;KACH,CAAC,CAAC;AACL,CAAC","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"]}
|
package/package.json
CHANGED