11import type SafeEventEmitter from '@metamask/safe-event-emitter' ;
22
3- import type { Hex } from './hex' ;
4- import type { JsonRpcParams , Json } from './json' ;
3+ import type { JsonRpcParams , JsonRpcRequest , Json } from './json' ;
54import type { PartialOrAbsent } from './misc' ;
65
76/**
@@ -28,30 +27,37 @@ export type EIP1993Provider = SafeEventEmitter & {
2827} ;
2928
3029/**
31- * An extension of the EIP-1193 specification for an Ethereum JavaScript Provider .
30+ * The interface for a legacy Ethereum provider .
3231 *
33- * For details, see:
34- * - [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193)
35- * - [BaseProvider]{@link https://github.com/MetaMask/providers/blob/main/src/BaseProvider.ts} in package [@metamask/providers](https://www.npmjs.com/package/@metamask/providers)
36- * - https://docs.metamask.io/wallet/reference/provider-api/
32+ * This provider follows conventions that pre-date
33+ * [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193). It is not compliant with
34+ * any Ethereum provider standard.
3735 */
38- export type EthJsonRpcProvider = EIP1993Provider & {
39- /**
40- * The chain ID of the currently connected Ethereum chain, represented as 0x-prefixed hexstring.
41- * See [chainId.network]{@link https://chainid.network} for more information.
42- */
43- chainId : Hex | null ;
44-
36+ export type LegacyEthereumProvider = {
4537 /**
46- * The user's currently selected Ethereum address as a 0x-prefixed hexstring.
47- * If read-access is denied, null is returned.
48- */
49- selectedAddress : Hex | null ;
50-
51- /**
52- * Returns true if the provider has a connection to the network and is able to process requests for the active chain.
38+ * Send a provider request asynchronously.
5339 *
54- * @returns Whether the provider can process RPC requests.
40+ * @param req - The request to send.
41+ * @param callback - A function that is called upon the success or failure of the request.
5542 */
56- isConnected ( ) : boolean ;
43+ sendAsync < Result extends Json = Json > (
44+ req : Partial < JsonRpcRequest > ,
45+ callback : SendAsyncCallback < Result > ,
46+ ) : void ;
5747} ;
48+
49+ type SendAsyncCallback < Result extends Json > = (
50+ ...args :
51+ | [ error : EverythingButNull , result : undefined ]
52+ | [ error : null , result : Result ]
53+ ) => void ;
54+
55+ // What it says on the tin. We omit `null`, as that value is used for a
56+ // successful response to indicate a lack of an error.
57+ type EverythingButNull =
58+ | string
59+ | number
60+ | boolean
61+ | object
62+ | symbol
63+ | undefined ;
0 commit comments