Skip to content
This repository has been archived by the owner on Nov 9, 2023. It is now read-only.

Introduce LegacyEthereumProvider interface #14

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './legacy-ethereum-provider';
export * from './provider-from-engine';
export * from './provider-from-middleware';
export type { SafeEventEmitterProvider } from './safe-event-emitter-provider';
36 changes: 36 additions & 0 deletions src/legacy-ethereum-provider.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { JsonRpcRequest } from '@metamask/json-rpc-engine';

Check failure on line 1 in src/legacy-ethereum-provider.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Build (16.x)

Module '"@metamask/json-rpc-engine"' has no exported member 'JsonRpcRequest'.

Check failure on line 1 in src/legacy-ethereum-provider.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Build (18.x)

Module '"@metamask/json-rpc-engine"' has no exported member 'JsonRpcRequest'.
mcmire marked this conversation as resolved.
Show resolved Hide resolved

/**
* The interface for a legacy Ethereum provider.
*
* This provider follows conventions that pre-date
* [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193). It is not compliant with
* any Ethereum provider standard.
*/
export type LegacyEthereumProvider = {
/**
* Send a provider request asynchronously.
*
* @param req - The request to send.
* @param callback - A function that is called upon the success or failure of the request.
*/
sendAsync(
req: JsonRpcRequest<unknown>,
callback: (error: unknown, providerRes?: any) => void,
): void;

/**
* Send a provider request asynchronously.
*
* This method serves the same purpose as `sendAsync`. It only exists for
* legacy reasons.
*
* @deprecated Use `sendAsync` instead.
* @param req - The request to send.
* @param callback - A function that is called upon the success or failure of the request.
*/
send(
req: JsonRpcRequest<unknown>,
callback: (error: unknown, providerRes?: any) => void,
): void;
};
16 changes: 12 additions & 4 deletions src/safe-event-emitter-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
import SafeEventEmitter from '@metamask/safe-event-emitter';
import type { JsonRpcRequest } from '@metamask/utils';

import { JsonRpcProvider } from './json-rpc-provider';

Check failure on line 5 in src/safe-event-emitter-provider.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Build (16.x)

Cannot find module './json-rpc-provider' or its corresponding type declarations.

Check failure on line 5 in src/safe-event-emitter-provider.ts

View workflow job for this annotation

GitHub Actions / Build, lint, and test / Build (18.x)

Cannot find module './json-rpc-provider' or its corresponding type declarations.

/**
* An Ethereum provider.
* SafeEventEmitterProvider implements the JSON-RPC provider interface by using
* a [JSON-RPC engine](https://github.com/MetaMask/json-rpc-engine) to make
* requests.
*
* This provider loosely follows conventions that pre-date EIP-1193.
* It is not compliant with any Ethereum provider standard.
* This provider follows conventions that pre-date
* [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193). It is not compliant with
* any Ethereum provider standard.
*/
export class SafeEventEmitterProvider extends SafeEventEmitter {
export class SafeEventEmitterProvider
extends SafeEventEmitter
implements JsonRpcProvider
{
#engine: JsonRpcEngine;

/**
Expand Down
Loading