-
Notifications
You must be signed in to change notification settings - Fork 10
/
types.ts
46 lines (37 loc) · 1.03 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import EventEmitter from 'events'
import type { JsonRpcPayload } from './payload'
// EIP-1193 interface types
export interface RequestArguments {
method: string
params?: readonly unknown[] | object
}
export type Payload = RequestArguments & {
chainId?: string
}
export type ProviderError = {
code: number
data?: unknown
}
export interface EthereumProvider {
request (payload: RequestArguments): Promise<unknown>
on: (event: string, cb: (data: unknown) => void) => void
removeListener: (event: string, handler: (data: unknown) => void) => void
}
// JSON RPC types
export type JsonRpcResponse = {
jsonrpc: '2.0'
id: number
result: unknown
}
// internal types
export type EventHandler = (eventPayload: unknown) => void
export type Callback<T> = (err: Error | null, result?: T) => void
export type PendingPromise = {
resolve: (result: unknown) => void
reject: (err: Error) => void
method: string
}
export interface Connection extends EventEmitter {
send: (payload: JsonRpcPayload) => Promise<void>
close: () => void
}