-
Notifications
You must be signed in to change notification settings - Fork 1
/
starknet.env.d.ts
131 lines (112 loc) · 3.68 KB
/
starknet.env.d.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
// https://github.com/argentlabs/argent-x/blob/e57225f5841f47782e444ae7c75b28cb8840c23b/packages/extension/src/inpage/inpage.model.ts
import type { AccountInterface, ProviderInterface } from 'starknet4'
import type { AccountInterface as AccountInterface3, ProviderInterface as ProviderInterface3 } from 'starknet3'
type AccountChangeEventHandler = (accounts: string[]) => void
type NetworkChangeEventHandler = (network?: string) => void
type WalletEventHandlers = AccountChangeEventHandler | NetworkChangeEventHandler
type WalletEvents =
| {
type: 'accountsChanged'
handler: AccountChangeEventHandler
}
| {
type: 'networkChanged'
handler: NetworkChangeEventHandler
}
// EIP-747:
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-747.md
interface WatchAssetParameters {
type: 'ERC20' // The asset's interface, e.g. 'ERC20'
options: {
address: string // The hexadecimal StarkNet address of the token contract
symbol?: string // A ticker symbol or shorthand, up to 5 alphanumerical characters
decimals?: number // The number of asset decimals
image?: string // A string url of the token logo
name?: string // The name of the token - not in spec
}
}
// EIP-3085
// https://github.com/ethereum/EIPs/blob/master/EIPS/eip-3085.md
interface AddStarknetChainParameters {
id: string
chainId: string // A 0x-prefixed hexadecimal string
chainName: string
baseUrl: string
rpcUrl?: string
blockExplorerUrl?: string
accountImplementation?: string
nativeCurrency?: {
name: string
symbol: string // 2-6 characters long
decimals: 18
} // Currently ignored.
iconUrls?: string[] // Currently ignored.
}
interface SwitchStarknetChainParameter {
chainId: string // A 0x-prefixed hexadecimal string
}
type RpcMessage =
| {
type: 'wallet_watchAsset'
params: WatchAssetParameters
result: boolean
}
| {
type: 'wallet_addStarknetChain'
params: AddStarknetChainParameters
result: boolean
}
| {
type: 'wallet_switchStarknetChain'
params: SwitchStarknetChainParameter
result: boolean
}
| {
type: string
params: unknown
result: never
}
type StarknetJsVersion = 'v3' | 'v4'
interface IStarketWindowObject {
id: string
name: string
version: string
icon: string
request: <T extends RpcMessage>(call: Omit<T, 'result'>) => Promise<T['result']>
enable: (options?: { starknetVersion?: StarknetJsVersion }) => Promise<string[]>
isPreauthorized: () => Promise<boolean>
on: (event: WalletEvents['type'], handleEvent: WalletEvents['handler']) => void
off: (event: WalletEvents['type'], handleEvent: WalletEvents['handler']) => void
starknetJsVersion?: StarknetJsVersion
account?: AccountInterface | AccountInterface3
provider?: ProviderInterface | ProviderInterface3
selectedAddress?: string
chainId?: string
}
interface ConnectedStarketWindowObjectV3 extends IStarketWindowObject {
isConnected: true
starknetJsVersion: 'v3'
account: AccountInterface3
provider: ProviderInterface3
selectedAddress: string
chainId: string
}
interface ConnectedStarketWindowObjectV4 extends IStarketWindowObject {
isConnected: true
starknetJsVersion: 'v4'
account: AccountInterface
provider: ProviderInterface
selectedAddress: string
chainId: string
}
type ConnectedStarketWindowObject = ConnectedStarketWindowObjectV3 | ConnectedStarketWindowObjectV4
interface DisconnectedStarketWindowObject extends IStarketWindowObject {
isConnected: false
}
type StarknetWindowObject = ConnectedStarketWindowObject | DisconnectedStarketWindowObject
declare global {
interface Window {
starknet?: StarknetWindowObject
starknet_braavos?: StarknetWindowObject
}
}