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 type { JsonRpcRequest } from '@metamask/utils';

/**
* 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,
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,
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 type { JsonRpcEngine } from '@metamask/json-rpc-engine';
import SafeEventEmitter from '@metamask/safe-event-emitter';
import type { JsonRpcRequest } from '@metamask/utils';

import type { LegacyEthereumProvider } from './legacy-ethereum-provider';

/**
* 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 LegacyEthereumProvider
{
#engine: JsonRpcEngine;

/**
Expand Down