@metamask-previews/eth-json-rpc-provider 6.0.0-preview-565dfca2 → 6.0.0-preview-3fa1672

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.
@@ -1 +1 @@
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;QAC9D,QAAqD,EACrD,EAAE;YACF,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;gBACnC,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAC;YAC7D,CAAC;YACD,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAAI,4CAAoB,MAAxB,IAAI,EAAqB,cAAc,EAAE,QAAQ,CAAC,CAAC;QACrD,CAAC,CAAC;QAEO,mCAAU,KAAK,EACtB,cAA8B,EAC9B,OAAgC,EACC,EAAE;YACnC,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,cAAc,CAAC;YACvC,6EAA6E;YAC7E,mEAAmE;YACnE,MAAM,MAAM,GAAG,CAAC,MAAM,uBAAA,IAAI,gC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M;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
+ {"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,EAC/C,EAAE;YACR,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;QAC9D,QAAqD,EAC/C,EAAE;YACR,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE,CAAC;gBAC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qC,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 ): void => {\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 ): void => {\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":"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;AAC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B;IAE9B,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,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","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
+ {"version":3,"file":"internal-provider.mjs","sourceRoot":"","sources":["../src/internal-provider.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAE3D,OAAO,EAAE,eAAe,EAAE,qCAAqC;AAc/D,OAAO,EAAE,MAAM,EAAE,eAAe;AAmBhC;;;;;GAKG;AACH,MAAM,OAAO,gBAAgB;IAK3B;;;;;OAKG;IACH,YAAY,EAAE,MAAM,EAAoC;QAR/C,2CAAkD;QAkC3D;;;;;;;;;;WAUG;QACH,cAAS,GAAG,CACV,cAAsC;QACtC,mDAAmD;QACnD,8DAA8D;QAC9D,QAAqD,EAC/C,EAAE;YACR,MAAM,cAAc,GAClB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YACxD,uBAAA,IAA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e,CAAC,MAAM,CAAC;gBACrB,UAAU,EAAE,CAAC,cAAc,CAAgC,MAAM,CAAC,CAAC;aACpE,CAAC;YACJ,CAAC,CAAC,MAAM,MAAA,CAAC;IACf,CAAC;IAED;;;;;;;OAOG;IACH,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;;AAED;;;;;GAKG;AACH,MAAM,UAAU,qCAAqC,CACnD,cAA8B;IAE9B,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,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","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 ): void => {\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 ): void => {\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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/eth-json-rpc-provider",
3
- "version": "6.0.0-preview-565dfca2",
3
+ "version": "6.0.0-preview-3fa1672",
4
4
  "description": "Create an Ethereum provider using a JSON-RPC engine or middleware",
5
5
  "keywords": [
6
6
  "MetaMask",