@reown/appkit-common-react-native 2.0.0-alpha.2 → 2.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (237) hide show
  1. package/lib/commonjs/adapters/BlockchainAdapter.js +25 -12
  2. package/lib/commonjs/adapters/BlockchainAdapter.js.map +1 -1
  3. package/lib/commonjs/adapters/EvmAdapter.js +0 -11
  4. package/lib/commonjs/adapters/EvmAdapter.js.map +1 -1
  5. package/lib/commonjs/index.js +4 -4
  6. package/lib/commonjs/index.js.map +1 -1
  7. package/lib/commonjs/types/api/blockchain-api.js +15 -0
  8. package/lib/commonjs/types/api/blockchain-api.js.map +1 -0
  9. package/lib/commonjs/types/api/events.js +6 -0
  10. package/lib/commonjs/types/api/events.js.map +1 -0
  11. package/lib/commonjs/types/api/index.js +39 -0
  12. package/lib/commonjs/types/api/index.js.map +1 -0
  13. package/lib/commonjs/types/api/wallet-api.js +6 -0
  14. package/lib/commonjs/types/api/wallet-api.js.map +1 -0
  15. package/lib/commonjs/types/blockchain/adapter.js +6 -0
  16. package/lib/commonjs/types/blockchain/adapter.js.map +1 -0
  17. package/lib/commonjs/types/blockchain/balance.js +6 -0
  18. package/lib/commonjs/types/blockchain/balance.js.map +1 -0
  19. package/lib/commonjs/types/blockchain/index.js +50 -0
  20. package/lib/commonjs/types/blockchain/index.js.map +1 -0
  21. package/lib/commonjs/types/blockchain/network.js +6 -0
  22. package/lib/commonjs/types/blockchain/network.js.map +1 -0
  23. package/lib/commonjs/types/blockchain/transaction.js +2 -0
  24. package/lib/commonjs/types/blockchain/transaction.js.map +1 -0
  25. package/lib/commonjs/types/common.js +2 -0
  26. package/lib/commonjs/types/common.js.map +1 -0
  27. package/lib/commonjs/types/index.js +105 -0
  28. package/lib/commonjs/types/index.js.map +1 -0
  29. package/lib/commonjs/types/onramp/countries.js +2 -0
  30. package/lib/commonjs/types/onramp/countries.js.map +1 -0
  31. package/lib/commonjs/types/onramp/currencies.js +2 -0
  32. package/lib/commonjs/types/onramp/currencies.js.map +1 -0
  33. package/lib/commonjs/types/onramp/errors.js +22 -0
  34. package/lib/commonjs/types/onramp/errors.js.map +1 -0
  35. package/lib/commonjs/types/onramp/index.js +50 -0
  36. package/lib/commonjs/types/onramp/index.js.map +1 -0
  37. package/lib/commonjs/types/onramp/quotes.js +2 -0
  38. package/lib/commonjs/types/onramp/quotes.js.map +1 -0
  39. package/lib/commonjs/types/siwe/config.js +6 -0
  40. package/lib/commonjs/types/siwe/config.js.map +1 -0
  41. package/lib/commonjs/types/siwe/index.js +28 -0
  42. package/lib/commonjs/types/siwe/index.js.map +1 -0
  43. package/lib/commonjs/types/siwe/message.js +6 -0
  44. package/lib/commonjs/types/siwe/message.js.map +1 -0
  45. package/lib/commonjs/types/storage.js +2 -0
  46. package/lib/commonjs/types/storage.js.map +1 -0
  47. package/lib/commonjs/types/swap/index.js +17 -0
  48. package/lib/commonjs/types/swap/index.js.map +1 -0
  49. package/lib/commonjs/types/swap/tokens.js +6 -0
  50. package/lib/commonjs/types/swap/tokens.js.map +1 -0
  51. package/lib/commonjs/types/ui.js +6 -0
  52. package/lib/commonjs/types/ui.js.map +1 -0
  53. package/lib/commonjs/types/wallet/connection.js +6 -0
  54. package/lib/commonjs/types/wallet/connection.js.map +1 -0
  55. package/lib/commonjs/{utils/TypeUtil.js → types/wallet/connector.js} +1 -15
  56. package/lib/commonjs/types/wallet/connector.js.map +1 -0
  57. package/lib/commonjs/types/wallet/index.js +39 -0
  58. package/lib/commonjs/types/wallet/index.js.map +1 -0
  59. package/lib/commonjs/types/wallet/wallet-info.js +6 -0
  60. package/lib/commonjs/types/wallet/wallet-info.js.map +1 -0
  61. package/lib/commonjs/utils/ConstantsUtil.js +27 -7
  62. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  63. package/lib/commonjs/utils/NetworkUtil.js +3 -0
  64. package/lib/commonjs/utils/NetworkUtil.js.map +1 -1
  65. package/lib/module/adapters/BlockchainAdapter.js +25 -12
  66. package/lib/module/adapters/BlockchainAdapter.js.map +1 -1
  67. package/lib/module/adapters/EvmAdapter.js +0 -11
  68. package/lib/module/adapters/EvmAdapter.js.map +1 -1
  69. package/lib/module/index.js +1 -1
  70. package/lib/module/index.js.map +1 -1
  71. package/lib/module/types/api/blockchain-api.js +10 -0
  72. package/lib/module/types/api/blockchain-api.js.map +1 -0
  73. package/lib/module/types/api/events.js +4 -0
  74. package/lib/module/types/api/events.js.map +1 -0
  75. package/lib/module/types/api/index.js +7 -0
  76. package/lib/module/types/api/index.js.map +1 -0
  77. package/lib/module/types/api/wallet-api.js +4 -0
  78. package/lib/module/types/api/wallet-api.js.map +1 -0
  79. package/lib/module/types/blockchain/adapter.js +4 -0
  80. package/lib/module/types/blockchain/adapter.js.map +1 -0
  81. package/lib/module/types/blockchain/balance.js +4 -0
  82. package/lib/module/types/blockchain/balance.js.map +1 -0
  83. package/lib/module/types/blockchain/index.js +8 -0
  84. package/lib/module/types/blockchain/index.js.map +1 -0
  85. package/lib/module/types/blockchain/network.js +4 -0
  86. package/lib/module/types/blockchain/network.js.map +1 -0
  87. package/lib/module/types/blockchain/transaction.js +2 -0
  88. package/lib/module/types/blockchain/transaction.js.map +1 -0
  89. package/lib/module/types/common.js +2 -0
  90. package/lib/module/types/common.js.map +1 -0
  91. package/lib/module/types/index.js +31 -0
  92. package/lib/module/types/index.js.map +1 -0
  93. package/lib/module/types/onramp/countries.js +2 -0
  94. package/lib/module/types/onramp/countries.js.map +1 -0
  95. package/lib/module/types/onramp/currencies.js +2 -0
  96. package/lib/module/types/onramp/currencies.js.map +1 -0
  97. package/lib/module/types/onramp/errors.js +18 -0
  98. package/lib/module/types/onramp/errors.js.map +1 -0
  99. package/lib/module/types/onramp/index.js +8 -0
  100. package/lib/module/types/onramp/index.js.map +1 -0
  101. package/lib/module/types/onramp/quotes.js +2 -0
  102. package/lib/module/types/onramp/quotes.js.map +1 -0
  103. package/lib/module/types/siwe/config.js +4 -0
  104. package/lib/module/types/siwe/config.js.map +1 -0
  105. package/lib/module/types/siwe/index.js +6 -0
  106. package/lib/module/types/siwe/index.js.map +1 -0
  107. package/lib/module/types/siwe/message.js +4 -0
  108. package/lib/module/types/siwe/message.js.map +1 -0
  109. package/lib/module/types/storage.js +2 -0
  110. package/lib/module/types/storage.js.map +1 -0
  111. package/lib/module/types/swap/index.js +5 -0
  112. package/lib/module/types/swap/index.js.map +1 -0
  113. package/lib/module/types/swap/tokens.js +4 -0
  114. package/lib/module/types/swap/tokens.js.map +1 -0
  115. package/lib/module/types/ui.js +4 -0
  116. package/lib/module/types/ui.js.map +1 -0
  117. package/lib/module/types/wallet/connection.js +4 -0
  118. package/lib/module/types/wallet/connection.js.map +1 -0
  119. package/lib/module/{utils/TypeUtil.js → types/wallet/connector.js} +1 -16
  120. package/lib/module/types/wallet/connector.js.map +1 -0
  121. package/lib/module/types/wallet/index.js +7 -0
  122. package/lib/module/types/wallet/index.js.map +1 -0
  123. package/lib/module/types/wallet/wallet-info.js +4 -0
  124. package/lib/module/types/wallet/wallet-info.js.map +1 -0
  125. package/lib/module/utils/ConstantsUtil.js +27 -7
  126. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  127. package/lib/module/utils/NetworkUtil.js +3 -0
  128. package/lib/module/utils/NetworkUtil.js.map +1 -1
  129. package/lib/typescript/adapters/BlockchainAdapter.d.ts +5 -4
  130. package/lib/typescript/adapters/BlockchainAdapter.d.ts.map +1 -1
  131. package/lib/typescript/adapters/EvmAdapter.d.ts +1 -2
  132. package/lib/typescript/adapters/EvmAdapter.d.ts.map +1 -1
  133. package/lib/typescript/index.d.ts +1 -1
  134. package/lib/typescript/index.d.ts.map +1 -1
  135. package/lib/typescript/networks/bitcoin.d.ts +1 -1
  136. package/lib/typescript/networks/bitcoin.d.ts.map +1 -1
  137. package/lib/typescript/networks/solana.d.ts +1 -1
  138. package/lib/typescript/networks/solana.d.ts.map +1 -1
  139. package/lib/typescript/types/api/blockchain-api.d.ts +183 -0
  140. package/lib/typescript/types/api/blockchain-api.d.ts.map +1 -0
  141. package/lib/typescript/types/api/events.d.ts +304 -0
  142. package/lib/typescript/types/api/events.d.ts.map +1 -0
  143. package/lib/typescript/types/api/index.d.ts +4 -0
  144. package/lib/typescript/types/api/index.d.ts.map +1 -0
  145. package/lib/typescript/types/api/wallet-api.d.ts +50 -0
  146. package/lib/typescript/types/api/wallet-api.d.ts.map +1 -0
  147. package/lib/typescript/types/blockchain/adapter.d.ts +40 -0
  148. package/lib/typescript/types/blockchain/adapter.d.ts.map +1 -0
  149. package/lib/typescript/types/blockchain/balance.d.ts +28 -0
  150. package/lib/typescript/types/blockchain/balance.d.ts.map +1 -0
  151. package/lib/typescript/types/blockchain/index.d.ts +5 -0
  152. package/lib/typescript/types/blockchain/index.d.ts.map +1 -0
  153. package/lib/typescript/types/blockchain/network.d.ts +47 -0
  154. package/lib/typescript/types/blockchain/network.d.ts.map +1 -0
  155. package/lib/typescript/types/blockchain/transaction.d.ts +63 -0
  156. package/lib/typescript/types/blockchain/transaction.d.ts.map +1 -0
  157. package/lib/typescript/types/common.d.ts +24 -0
  158. package/lib/typescript/types/common.d.ts.map +1 -0
  159. package/lib/typescript/types/index.d.ts +10 -0
  160. package/lib/typescript/types/index.d.ts.map +1 -0
  161. package/lib/typescript/types/onramp/countries.d.ts +11 -0
  162. package/lib/typescript/types/onramp/countries.d.ts.map +1 -0
  163. package/lib/typescript/types/onramp/currencies.d.ts +30 -0
  164. package/lib/typescript/types/onramp/currencies.d.ts.map +1 -0
  165. package/lib/typescript/types/onramp/errors.d.ts +21 -0
  166. package/lib/typescript/types/onramp/errors.d.ts.map +1 -0
  167. package/lib/typescript/types/onramp/index.d.ts +5 -0
  168. package/lib/typescript/types/onramp/index.d.ts.map +1 -0
  169. package/lib/typescript/types/onramp/quotes.d.ts +45 -0
  170. package/lib/typescript/types/onramp/quotes.d.ts.map +1 -0
  171. package/lib/typescript/types/siwe/config.d.ts +31 -0
  172. package/lib/typescript/types/siwe/config.d.ts.map +1 -0
  173. package/lib/typescript/types/siwe/index.d.ts +3 -0
  174. package/lib/typescript/types/siwe/index.d.ts.map +1 -0
  175. package/lib/typescript/types/siwe/message.d.ts +57 -0
  176. package/lib/typescript/types/siwe/message.d.ts.map +1 -0
  177. package/lib/typescript/types/storage.d.ts +27 -0
  178. package/lib/typescript/types/storage.d.ts.map +1 -0
  179. package/lib/typescript/types/swap/index.d.ts +2 -0
  180. package/lib/typescript/types/swap/index.d.ts.map +1 -0
  181. package/lib/typescript/types/swap/tokens.d.ts +19 -0
  182. package/lib/typescript/types/swap/tokens.d.ts.map +1 -0
  183. package/lib/typescript/types/ui.d.ts +26 -0
  184. package/lib/typescript/types/ui.d.ts.map +1 -0
  185. package/lib/typescript/types/wallet/connection.d.ts +30 -0
  186. package/lib/typescript/types/wallet/connection.d.ts.map +1 -0
  187. package/lib/typescript/types/wallet/connector.d.ts +61 -0
  188. package/lib/typescript/types/wallet/connector.d.ts.map +1 -0
  189. package/lib/typescript/types/wallet/index.d.ts +4 -0
  190. package/lib/typescript/types/wallet/index.d.ts.map +1 -0
  191. package/lib/typescript/types/wallet/wallet-info.d.ts +36 -0
  192. package/lib/typescript/types/wallet/wallet-info.d.ts.map +1 -0
  193. package/lib/typescript/utils/ConstantsUtil.d.ts +25 -5
  194. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  195. package/lib/typescript/utils/NetworkUtil.d.ts +2 -0
  196. package/lib/typescript/utils/NetworkUtil.d.ts.map +1 -1
  197. package/package.json +1 -1
  198. package/src/adapters/BlockchainAdapter.ts +34 -15
  199. package/src/adapters/EvmAdapter.ts +1 -13
  200. package/src/adapters/__tests__/EvmAdapter.test.ts +2 -2
  201. package/src/index.ts +2 -1
  202. package/src/networks/bitcoin.ts +1 -1
  203. package/src/networks/solana.ts +1 -1
  204. package/src/types/api/blockchain-api.ts +213 -0
  205. package/src/types/api/events.ts +394 -0
  206. package/src/types/api/index.ts +4 -0
  207. package/src/types/api/wallet-api.ts +70 -0
  208. package/src/types/blockchain/adapter.ts +52 -0
  209. package/src/types/blockchain/balance.ts +31 -0
  210. package/src/types/blockchain/index.ts +5 -0
  211. package/src/types/blockchain/network.ts +39 -0
  212. package/src/types/blockchain/transaction.ts +71 -0
  213. package/src/types/common.ts +56 -0
  214. package/src/types/index.ts +28 -0
  215. package/src/types/onramp/countries.ts +11 -0
  216. package/src/types/onramp/currencies.ts +32 -0
  217. package/src/types/onramp/errors.ts +22 -0
  218. package/src/types/onramp/index.ts +5 -0
  219. package/src/types/onramp/quotes.ts +46 -0
  220. package/src/types/siwe/config.ts +44 -0
  221. package/src/types/siwe/index.ts +3 -0
  222. package/src/types/siwe/message.ts +62 -0
  223. package/src/types/storage.ts +30 -0
  224. package/src/types/swap/index.ts +2 -0
  225. package/src/types/swap/tokens.ts +21 -0
  226. package/src/types/ui.ts +26 -0
  227. package/src/types/wallet/connection.ts +33 -0
  228. package/src/types/wallet/connector.ts +85 -0
  229. package/src/types/wallet/index.ts +4 -0
  230. package/src/types/wallet/wallet-info.ts +41 -0
  231. package/src/utils/ConstantsUtil.ts +29 -9
  232. package/src/utils/NetworkUtil.ts +5 -0
  233. package/lib/commonjs/utils/TypeUtil.js.map +0 -1
  234. package/lib/module/utils/TypeUtil.js.map +0 -1
  235. package/lib/typescript/utils/TypeUtil.d.ts +0 -394
  236. package/lib/typescript/utils/TypeUtil.d.ts.map +0 -1
  237. package/src/utils/TypeUtil.ts +0 -493
@@ -1,493 +0,0 @@
1
- import { EventEmitter } from 'events';
2
- import type { BlockchainAdapter } from '../adapters/BlockchainAdapter';
3
-
4
- export type CaipAddress = `${string}:${string}:${string}`;
5
-
6
- export type CaipNetworkId = `${string}:${string}`;
7
-
8
- export type ChainNamespace = 'eip155' | 'solana' | 'polkadot' | 'bip122';
9
-
10
- export type AdapterType = 'solana' | 'wagmi' | 'ethers' | 'universal' | 'bip122';
11
-
12
- export type Network = {
13
- // Core viem/chain properties
14
- id: number | string;
15
- name: string;
16
- nativeCurrency: { name: string; symbol: string; decimals: number };
17
- rpcUrls: {
18
- default: { http: readonly string[] };
19
- [key: string]: { http: readonly string[] } | undefined;
20
- };
21
- blockExplorers?: {
22
- default: { name: string; url: string };
23
- [key: string]: { name: string; url: string } | undefined;
24
- };
25
-
26
- // AppKit specific / CAIP properties (Optional in type, but needed in practice)
27
- chainNamespace?: ChainNamespace; // e.g., 'eip155'
28
- caipNetworkId?: CaipNetworkId; // e.g., 'eip155:1'
29
- testnet?: boolean;
30
- deprecatedCaipNetworkId?: CaipNetworkId; // for Solana deprecated id
31
- };
32
-
33
- export type AppKitNetwork = Network & {
34
- chainNamespace: ChainNamespace; // e.g., 'eip155'
35
- caipNetworkId: CaipNetworkId; // e.g., 'eip155:1'
36
- testnet?: boolean;
37
- deprecatedCaipNetworkId?: CaipNetworkId; // for Solana deprecated id
38
- };
39
-
40
- export interface AppKitOpenOptions {
41
- view: 'Account' | 'Connect' | 'Networks' | 'Swap' | 'OnRamp';
42
- }
43
-
44
- export type AppKitConnectOptions = Pick<
45
- ConnectOptions,
46
- 'namespaces' | 'defaultChain' | 'universalLink'
47
- >;
48
-
49
- export interface CaipNetwork {
50
- id: CaipNetworkId;
51
- name?: string;
52
- imageId?: string;
53
- imageUrl?: string;
54
- }
55
-
56
- export interface Balance {
57
- name?: string;
58
- amount: string;
59
- symbol: string;
60
- quantity?: {
61
- decimals: string;
62
- numeric: string;
63
- };
64
- chainId?: string;
65
- address?: CaipAddress; // contract address
66
- value?: number; //total value of the amount in currency
67
- price?: number; //price of the token in currency
68
- iconUrl?: string;
69
- }
70
-
71
- export type TransactionStatus = 'confirmed' | 'failed' | 'pending';
72
- export type TransactionDirection = 'in' | 'out' | 'self';
73
- export type TransactionImage = {
74
- type: 'FUNGIBLE' | 'NFT' | undefined;
75
- url: string | undefined;
76
- };
77
-
78
- export interface Transaction {
79
- id: string;
80
- metadata: TransactionMetadata;
81
- transfers: TransactionTransfer[];
82
- }
83
-
84
- export interface TransactionMetadata {
85
- application: {
86
- iconUrl: string | null;
87
- name: string | null;
88
- };
89
- operationType: string;
90
- hash: string;
91
- minedAt: string;
92
- sentFrom: string;
93
- sentTo: string;
94
- status: TransactionStatus;
95
- nonce: number;
96
- chain?: string;
97
- }
98
-
99
- export interface TransactionTransfer {
100
- fungible_info?: {
101
- name?: string;
102
- symbol?: string;
103
- icon?: {
104
- url: string;
105
- };
106
- };
107
- nft_info?: TransactionNftInfo;
108
- direction: TransactionDirection;
109
- quantity: TransactionQuantity;
110
- value?: number;
111
- price?: number;
112
- }
113
-
114
- export interface TransactionNftInfo {
115
- name?: string;
116
- content?: TransactionContent;
117
- flags: TransactionNftInfoFlags;
118
- }
119
-
120
- export interface TransactionNftInfoFlags {
121
- is_spam: boolean;
122
- }
123
-
124
- export interface TransactionContent {
125
- preview?: TransactionPreview;
126
- detail?: TransactionDetail;
127
- }
128
-
129
- export interface TransactionPreview {
130
- url: string;
131
- content_type?: null;
132
- }
133
-
134
- export interface TransactionDetail {
135
- url: string;
136
- content_type?: null;
137
- }
138
-
139
- export interface TransactionQuantity {
140
- numeric: string;
141
- }
142
-
143
- export type SocialProvider =
144
- | 'google'
145
- | 'facebook'
146
- | 'github'
147
- | 'apple'
148
- | 'x'
149
- | 'discord'
150
- | 'email'
151
- | 'farcaster';
152
-
153
- export type ThemeMode = 'dark' | 'light';
154
-
155
- export interface ThemeVariables {
156
- accent?: string;
157
- }
158
-
159
- export interface Token {
160
- address: string;
161
- image?: string;
162
- }
163
-
164
- export type Tokens = Record<CaipNetworkId, Token>;
165
-
166
- export type Metadata = {
167
- name: string;
168
- description: string;
169
- url: string;
170
- icons: string[];
171
- redirect?: {
172
- native?: string;
173
- universal?: string;
174
- linkMode?: boolean;
175
- };
176
- };
177
-
178
- export interface Identity {
179
- name: string;
180
- avatar?: string;
181
- }
182
-
183
- export interface Connection {
184
- accounts: CaipAddress[];
185
- balances: Map<CaipAddress, Balance[]>;
186
- adapter: BlockchainAdapter;
187
- caipNetwork: CaipNetworkId;
188
- wallet?: WalletInfo;
189
- properties?: ConnectionProperties;
190
- type?: AccountType;
191
- identities?: Map<CaipAddress, Identity>;
192
- }
193
-
194
- export type BlockchainAdapterConfig = {
195
- projectId: string;
196
- supportedNamespace: ChainNamespace;
197
- adapterType: AdapterType;
198
- };
199
-
200
- //********** Adapter Event Payloads **********//
201
- export type AccountsChangedEvent = {
202
- accounts: string[];
203
- };
204
-
205
- export type ChainChangedEvent = {
206
- chainId: string;
207
- };
208
-
209
- export type DisconnectEvent = {};
210
-
211
- export type BalanceChangedEvent = {
212
- address: CaipAddress;
213
- balance: Balance;
214
- };
215
-
216
- //********** Adapter Event Map **********//
217
- export interface AdapterEvents {
218
- accountsChanged: (event: AccountsChangedEvent) => void;
219
- chainChanged: (event: ChainChangedEvent) => void;
220
- disconnect: (event: DisconnectEvent) => void;
221
- balanceChanged: (event: BalanceChangedEvent) => void;
222
- }
223
-
224
- export interface GetBalanceParams {
225
- network: AppKitNetwork;
226
- address?: CaipAddress;
227
- tokens?: Tokens;
228
- }
229
-
230
- export type GetBalanceResponse = Balance;
231
-
232
- //********** Connector Types **********//
233
- interface BaseNamespace {
234
- chains?: CaipNetworkId[];
235
- accounts: CaipAddress[];
236
- methods: string[];
237
- events: string[];
238
- }
239
-
240
- type Namespace = BaseNamespace;
241
-
242
- export type Namespaces = Record<string, Namespace>;
243
-
244
- export type ProposalNamespaces = Record<
245
- string,
246
- Omit<Namespace, 'accounts'> &
247
- Required<Pick<Namespace, 'chains'>> & { rpcMap: Record<string, string> }
248
- >;
249
-
250
- export type ConnectOptions = {
251
- namespaces?: ProposalNamespaces;
252
- defaultChain?: CaipNetworkId;
253
- universalLink?: string;
254
- siweConfig?: AppKitSIWEClient;
255
- };
256
-
257
- export type ConnectorInitOptions = {
258
- storage: Storage;
259
- metadata: Metadata;
260
- };
261
-
262
- export abstract class WalletConnector extends EventEmitter {
263
- public type: ConnectorType;
264
- protected provider?: Provider;
265
- protected namespaces?: Namespaces;
266
- protected wallet?: WalletInfo;
267
- protected storage?: Storage;
268
- protected metadata?: Metadata;
269
- protected properties?: ConnectionProperties;
270
-
271
- constructor({ type }: { type: ConnectorType }) {
272
- super();
273
- this.type = type;
274
- }
275
-
276
- public async init(ops: ConnectorInitOptions) {
277
- this.storage = ops.storage;
278
- this.metadata = ops.metadata;
279
- }
280
-
281
- public setProvider(provider: Provider) {
282
- this.provider = provider;
283
- }
284
-
285
- public async disconnect() {
286
- await this.provider?.disconnect();
287
- this.namespaces = undefined;
288
- this.wallet = undefined;
289
- this.properties = undefined;
290
- }
291
-
292
- abstract connect(opts: ConnectOptions): Promise<Namespaces | undefined>;
293
- abstract getProvider(): Provider;
294
- abstract getNamespaces(): Namespaces;
295
- abstract getChainId(namespace: ChainNamespace): CaipNetworkId | undefined;
296
- abstract getWalletInfo(): WalletInfo | undefined;
297
- abstract getProperties(): ConnectionProperties | undefined;
298
- abstract switchNetwork(network: AppKitNetwork): Promise<void>;
299
- abstract restoreSession(): Promise<boolean>;
300
- }
301
-
302
- export type ConnectorType = 'walletconnect' | 'coinbase' | 'auth' | 'phantom';
303
-
304
- //********** Provider Types **********//
305
-
306
- export interface Provider {
307
- connect<T>(params?: any): Promise<T>;
308
- disconnect(): Promise<void>;
309
- request<T = unknown>(
310
- args: RequestArguments,
311
- chain?: string | undefined,
312
- expiry?: number | undefined
313
- ): Promise<T>;
314
- on(event: string, listener: (args?: any) => void): any;
315
- off(event: string, listener: (args?: any) => void): any;
316
- }
317
-
318
- export interface RequestArguments {
319
- method: string;
320
- params?: unknown[] | Record<string, unknown> | object | undefined;
321
- }
322
-
323
- //********** Others **********//
324
-
325
- export interface ConnectionResponse {
326
- accounts: string[];
327
- chainId: string;
328
- [key: string]: any;
329
- }
330
-
331
- export interface WalletInfo {
332
- name?: string;
333
- icon?: string;
334
- description?: string;
335
- url?: string;
336
- icons?: string[];
337
- redirect?: {
338
- native?: string;
339
- universal?: string;
340
- linkMode?: boolean;
341
- };
342
- [key: string]: unknown;
343
- }
344
-
345
- export interface ConnectionProperties {
346
- email?: string;
347
- username?: string;
348
- smartAccounts?: CaipAddress[];
349
- provider?: SocialProvider;
350
- sessionTopic?: string;
351
- }
352
-
353
- export interface LinkingRecord {
354
- redirect: string;
355
- href: string;
356
- }
357
-
358
- export interface WalletDeepLink {
359
- href: string;
360
- name: string;
361
- }
362
-
363
- export type AccountType = 'eoa' | 'smartAccount';
364
-
365
- export interface Storage {
366
- /**
367
- * Returns all keys in storage.
368
- */
369
- getKeys(): Promise<string[]>;
370
-
371
- /**
372
- * Returns all key-value entries in storage.
373
- */
374
- getEntries<T = any>(): Promise<[string, T][]>;
375
-
376
- /**
377
- * Get an item from storage for a given key.
378
- * @param key The key to retrieve.
379
- */
380
- getItem<T = any>(key: string): Promise<T | undefined>;
381
-
382
- /**
383
- * Set an item in storage for a given key.
384
- * @param key The key to set.
385
- * @param value The value to set.
386
- */
387
- setItem<T = any>(key: string, value: T): Promise<void>;
388
-
389
- /**
390
- * Remove an item from storage for a given key.
391
- * @param key The key to remove.
392
- */
393
- removeItem(key: string): Promise<void>;
394
- }
395
-
396
- //********** SIWE Types **********//
397
- export interface SIWESession {
398
- address: string;
399
- chainId: number;
400
- }
401
-
402
- interface CacaoHeader {
403
- t: 'caip122';
404
- }
405
-
406
- export interface SIWECreateMessageArgs {
407
- domain: string;
408
- nonce: string;
409
- uri: string;
410
- address: CaipAddress;
411
- version: '1';
412
- type?: CacaoHeader['t'];
413
- nbf?: string;
414
- exp?: string;
415
- statement?: string;
416
- requestId?: string;
417
- resources?: string[];
418
- expiry?: number;
419
- iat?: string;
420
- }
421
- export type SIWEMessageArgs = {
422
- chains: CaipNetworkId[];
423
- methods?: string[];
424
- } & Omit<SIWECreateMessageArgs, 'address' | 'nonce' | 'version'>;
425
- // Signed Cacao (CAIP-74)
426
- interface CacaoPayload {
427
- domain: string;
428
- aud: string;
429
- nonce: string;
430
- iss: string;
431
- version?: string;
432
- iat?: string;
433
- nbf?: string;
434
- exp?: string;
435
- statement?: string;
436
- requestId?: string;
437
- resources?: string[];
438
- type?: string;
439
- }
440
-
441
- interface Cacao {
442
- h: CacaoHeader;
443
- p: CacaoPayload;
444
- s: {
445
- t: 'eip191' | 'eip1271';
446
- s: string;
447
- m?: string;
448
- };
449
- }
450
-
451
- export interface SIWEVerifyMessageArgs {
452
- message: string;
453
- signature: string;
454
- cacao?: Cacao;
455
- }
456
-
457
- export interface SIWEClientMethods {
458
- getNonce: (address?: string) => Promise<string>;
459
- createMessage: (args: SIWECreateMessageArgs) => string;
460
- verifyMessage: (args: SIWEVerifyMessageArgs) => Promise<boolean>;
461
- getSession: () => Promise<SIWESession | null>;
462
- signOut: () => Promise<boolean>;
463
- getMessageParams?: () => Promise<SIWEMessageArgs>;
464
- onSignIn?: (session?: SIWESession) => void;
465
- onSignOut?: () => void;
466
- }
467
-
468
- export interface SIWEConfig extends SIWEClientMethods {
469
- // Defaults to true
470
- enabled?: boolean;
471
- // In milliseconds, defaults to 5 minutes
472
- nonceRefetchIntervalMs?: number;
473
- // In milliseconds, defaults to 5 minutes
474
- sessionRefetchIntervalMs?: number;
475
- // Defaults to true
476
- signOutOnDisconnect?: boolean;
477
- // Defaults to true
478
- signOutOnAccountChange?: boolean;
479
- // Defaults to true
480
- signOutOnNetworkChange?: boolean;
481
- }
482
-
483
- export interface AppKitSIWEClient extends SIWEClientMethods {
484
- signIn: () => Promise<SIWESession | undefined>;
485
- options: {
486
- enabled: boolean;
487
- nonceRefetchIntervalMs: number;
488
- sessionRefetchIntervalMs: number;
489
- signOutOnDisconnect: boolean;
490
- signOutOnAccountChange: boolean;
491
- signOutOnNetworkChange: boolean;
492
- };
493
- }