@reown/appkit-common-react-native 0.0.0-chore-canary-20250722145858 → 0.0.0-chore-bump-builder-20250728194329

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 (98) hide show
  1. package/lib/commonjs/adapters/BlockchainAdapter.js +81 -0
  2. package/lib/commonjs/adapters/BlockchainAdapter.js.map +1 -0
  3. package/lib/commonjs/adapters/EvmAdapter.js +204 -0
  4. package/lib/commonjs/adapters/EvmAdapter.js.map +1 -0
  5. package/lib/commonjs/adapters/SolanaBaseAdapter.js +10 -0
  6. package/lib/commonjs/adapters/SolanaBaseAdapter.js.map +1 -0
  7. package/lib/commonjs/index.js +62 -1
  8. package/lib/commonjs/index.js.map +1 -1
  9. package/lib/commonjs/networks/bitcoin.js +40 -0
  10. package/lib/commonjs/networks/bitcoin.js.map +1 -0
  11. package/lib/commonjs/networks/solana.js +78 -0
  12. package/lib/commonjs/networks/solana.js.map +1 -0
  13. package/lib/commonjs/package.json +1 -0
  14. package/lib/commonjs/utils/ConstantsUtil.js +31 -5
  15. package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
  16. package/lib/commonjs/utils/ErrorUtil.js +2 -2
  17. package/lib/commonjs/utils/NumberUtil.js +52 -11
  18. package/lib/commonjs/utils/NumberUtil.js.map +1 -1
  19. package/lib/commonjs/utils/PresetsUtil.js +34 -21
  20. package/lib/commonjs/utils/PresetsUtil.js.map +1 -1
  21. package/lib/commonjs/utils/StringUtil.js +7 -0
  22. package/lib/commonjs/utils/StringUtil.js.map +1 -1
  23. package/lib/commonjs/utils/TypeUtil.js +42 -0
  24. package/lib/commonjs/utils/TypeUtil.js.map +1 -1
  25. package/lib/module/adapters/BlockchainAdapter.js +76 -0
  26. package/lib/module/adapters/BlockchainAdapter.js.map +1 -0
  27. package/lib/module/adapters/EvmAdapter.js +200 -0
  28. package/lib/module/adapters/EvmAdapter.js.map +1 -0
  29. package/lib/module/adapters/SolanaBaseAdapter.js +5 -0
  30. package/lib/module/adapters/SolanaBaseAdapter.js.map +1 -0
  31. package/lib/module/contracts/erc20.js +2 -0
  32. package/lib/module/contracts/erc20.js.map +1 -1
  33. package/lib/module/contracts/usdt.js +2 -0
  34. package/lib/module/contracts/usdt.js.map +1 -1
  35. package/lib/module/index.js +7 -0
  36. package/lib/module/index.js.map +1 -1
  37. package/lib/module/networks/bitcoin.js +36 -0
  38. package/lib/module/networks/bitcoin.js.map +1 -0
  39. package/lib/module/networks/solana.js +74 -0
  40. package/lib/module/networks/solana.js.map +1 -0
  41. package/lib/module/utils/ConstantsUtil.js +33 -5
  42. package/lib/module/utils/ConstantsUtil.js.map +1 -1
  43. package/lib/module/utils/ContractUtil.js +2 -0
  44. package/lib/module/utils/ContractUtil.js.map +1 -1
  45. package/lib/module/utils/DateUtil.js +2 -0
  46. package/lib/module/utils/DateUtil.js.map +1 -1
  47. package/lib/module/utils/ErrorUtil.js +4 -2
  48. package/lib/module/utils/ErrorUtil.js.map +1 -1
  49. package/lib/module/utils/NamesUtil.js +2 -0
  50. package/lib/module/utils/NamesUtil.js.map +1 -1
  51. package/lib/module/utils/NetworkUtil.js +2 -0
  52. package/lib/module/utils/NetworkUtil.js.map +1 -1
  53. package/lib/module/utils/NumberUtil.js +54 -11
  54. package/lib/module/utils/NumberUtil.js.map +1 -1
  55. package/lib/module/utils/PresetsUtil.js +36 -21
  56. package/lib/module/utils/PresetsUtil.js.map +1 -1
  57. package/lib/module/utils/StringUtil.js +9 -0
  58. package/lib/module/utils/StringUtil.js.map +1 -1
  59. package/lib/module/utils/TypeUtil.js +38 -0
  60. package/lib/module/utils/TypeUtil.js.map +1 -1
  61. package/lib/typescript/adapters/BlockchainAdapter.d.ts +25 -0
  62. package/lib/typescript/adapters/BlockchainAdapter.d.ts.map +1 -0
  63. package/lib/typescript/adapters/EvmAdapter.d.ts +27 -0
  64. package/lib/typescript/adapters/EvmAdapter.d.ts.map +1 -0
  65. package/lib/typescript/adapters/SolanaBaseAdapter.d.ts +6 -0
  66. package/lib/typescript/adapters/SolanaBaseAdapter.d.ts.map +1 -0
  67. package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts +2 -0
  68. package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts.map +1 -0
  69. package/lib/typescript/index.d.ts +5 -0
  70. package/lib/typescript/index.d.ts.map +1 -1
  71. package/lib/typescript/networks/bitcoin.d.ts +4 -0
  72. package/lib/typescript/networks/bitcoin.d.ts.map +1 -0
  73. package/lib/typescript/networks/solana.d.ts +5 -0
  74. package/lib/typescript/networks/solana.d.ts.map +1 -0
  75. package/lib/typescript/utils/ConstantsUtil.d.ts +27 -3
  76. package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
  77. package/lib/typescript/utils/NumberUtil.d.ts +39 -11
  78. package/lib/typescript/utils/NumberUtil.d.ts.map +1 -1
  79. package/lib/typescript/utils/PresetsUtil.d.ts +1 -6
  80. package/lib/typescript/utils/PresetsUtil.d.ts.map +1 -1
  81. package/lib/typescript/utils/StringUtil.d.ts +1 -0
  82. package/lib/typescript/utils/StringUtil.d.ts.map +1 -1
  83. package/lib/typescript/utils/TypeUtil.d.ts +322 -12
  84. package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
  85. package/package.json +5 -1
  86. package/src/adapters/BlockchainAdapter.ts +107 -0
  87. package/src/adapters/EvmAdapter.ts +259 -0
  88. package/src/adapters/SolanaBaseAdapter.ts +6 -0
  89. package/src/adapters/__tests__/EvmAdapter.test.ts +126 -0
  90. package/src/index.ts +5 -0
  91. package/src/networks/bitcoin.ts +32 -0
  92. package/src/networks/solana.ts +44 -0
  93. package/src/utils/ConstantsUtil.ts +33 -6
  94. package/src/utils/ErrorUtil.ts +2 -2
  95. package/src/utils/NumberUtil.ts +54 -11
  96. package/src/utils/PresetsUtil.ts +34 -26
  97. package/src/utils/StringUtil.ts +7 -0
  98. package/src/utils/TypeUtil.ts +410 -14
@@ -1,6 +1,12 @@
1
1
  import * as BigNumber from 'bignumber.js';
2
2
 
3
3
  export const NumberUtil = {
4
+ /**
5
+ * Creates a BigNumber instance from a given value.
6
+ * If the value is a string, commas are removed before conversion.
7
+ * @param value - The input value (string, number, or BigNumber) to convert to a BigNumber.
8
+ * @returns A BigNumber instance.
9
+ */
4
10
  bigNumber(value: BigNumber.BigNumber.Value) {
5
11
  if (typeof value === 'string') {
6
12
  return new BigNumber.BigNumber(value.replace(/,/g, ''));
@@ -10,10 +16,11 @@ export const NumberUtil = {
10
16
  },
11
17
 
12
18
  /**
13
- * Multiply two numbers represented as strings with BigNumber to handle decimals correctly
14
- * @param a string
15
- * @param b string
16
- * @returns
19
+ * Multiplies two numbers using BigNumber for precision, especially with decimals.
20
+ * Handles undefined inputs by returning BigNumber(0).
21
+ * @param a - The first multiplicand (string, number, or BigNumber). Commas are removed if it's a string.
22
+ * @param b - The second multiplicand (string, number, or BigNumber). Commas are removed if it's a string.
23
+ * @returns The product as a BigNumber instance, or BigNumber(0) if either input is undefined.
17
24
  */
18
25
  multiply(a: BigNumber.BigNumber.Value | undefined, b: BigNumber.BigNumber.Value | undefined) {
19
26
  if (a === undefined || b === undefined) {
@@ -26,6 +33,13 @@ export const NumberUtil = {
26
33
  return aBigNumber.multipliedBy(bBigNumber);
27
34
  },
28
35
 
36
+ /**
37
+ * Rounds a number to a specified number of decimal places if its string representation meets a certain length threshold.
38
+ * @param number - The number to potentially round.
39
+ * @param threshold - The minimum string length of the number to trigger rounding.
40
+ * @param fixed - The number of decimal places to round to.
41
+ * @returns The rounded number (as a string if rounded, otherwise the original number) or the original number.
42
+ */
29
43
  roundNumber(number: number, threshold: number, fixed: number) {
30
44
  const roundedNumber =
31
45
  number.toString().length >= threshold ? Number(number).toFixed(fixed) : number;
@@ -33,6 +47,12 @@ export const NumberUtil = {
33
47
  return roundedNumber;
34
48
  },
35
49
 
50
+ /**
51
+ * Calculates the next multiple of ten greater than or equal to the given amount.
52
+ * Defaults to 10 if no amount is provided or if the calculated multiple is less than 10.
53
+ * @param amount - The number for which to find the next multiple of ten. Optional.
54
+ * @returns The next multiple of ten, at least 10.
55
+ */
36
56
  nextMultipleOfTen(amount?: number) {
37
57
  if (!amount) return 10;
38
58
 
@@ -40,10 +60,10 @@ export const NumberUtil = {
40
60
  },
41
61
 
42
62
  /**
43
- * Format the given number or string to human readable numbers with the given number of decimals
44
- * @param value - The value to format. It could be a number or string. If it's a string, it will be parsed to a float then formatted.
45
- * @param decimals - number of decimals after dot
46
- * @returns
63
+ * Formats a number or string to a human-readable string with a specified number of decimal places, using US locale formatting.
64
+ * @param value - The value to format (string, number, or undefined). If undefined, returns '0.00'.
65
+ * @param decimals - The number of decimal places to display. Defaults to 2.
66
+ * @returns A locale-formatted string representation of the number.
47
67
  */
48
68
  formatNumberToLocalString(value: string | number | undefined, decimals = 2) {
49
69
  if (value === undefined) {
@@ -62,10 +82,11 @@ export const NumberUtil = {
62
82
  minimumFractionDigits: decimals
63
83
  });
64
84
  },
85
+
65
86
  /**
66
- * Parse a formatted local string back to a number
67
- * @param value - The formatted string to parse
68
- * @returns
87
+ * Parses a locale-formatted numeric string (e.g., with commas) back into a number.
88
+ * @param value - The formatted string to parse. If undefined, returns 0.
89
+ * @returns The parsed number, or 0 if the input is undefined.
69
90
  */
70
91
  parseLocalStringToNumber(value: string | undefined) {
71
92
  if (value === undefined) {
@@ -74,5 +95,27 @@ export const NumberUtil = {
74
95
 
75
96
  // Remove any commas used as thousand separators and parse the float
76
97
  return parseFloat(value.replace(/,/gu, ''));
98
+ },
99
+
100
+ /**
101
+ * Converts a numeric value (BigInt, number, or string representation of a number) to a 0x-prefixed hexadecimal string.
102
+ * This is often required for Ethereum RPC parameters like value, gas, gasPrice.
103
+ * @param value - The value to convert. Can be BigInt, number, or a string (decimal or hex).
104
+ * @returns A 0x-prefixed hexadecimal string, or undefined if the input is undefined or null.
105
+ * @throws Error if the value cannot be converted to BigInt.
106
+ */
107
+ convertNumericToHexString: (value: any): string | undefined => {
108
+ if (value === undefined || value === null) {
109
+ return undefined;
110
+ }
111
+ try {
112
+ // This handles BigInt, number, or string representation of a number (decimal or hex)
113
+ const bigIntValue = BigInt(value);
114
+ // Ethereum RPC spec requires "0x0" for zero, and other values to be 0x-prefixed hex.
115
+
116
+ return '0x' + bigIntValue.toString(16);
117
+ } catch (error) {
118
+ throw new Error(`NumberUtil: Invalid parameter, cannot convert to hex: ${value}`);
119
+ }
77
120
  }
78
121
  };
@@ -1,17 +1,9 @@
1
- import type { ConnectorType } from './TypeUtil';
2
- import { ConstantsUtil } from './ConstantsUtil';
3
-
4
1
  export const PresetsUtil = {
5
- ConnectorExplorerIds: {
6
- [ConstantsUtil.COINBASE_CONNECTOR_ID]:
7
- 'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa'
8
- } as Record<string, string>,
9
-
10
- EIP155NetworkImageIds: {
2
+ NetworkImageIds: {
11
3
  // Ethereum
12
4
  1: 'ba0ba0cd-17c6-4806-ad93-f9d174f17900',
13
5
  // Arbitrum
14
- 42161: '600a9a04-c1b9-42ca-6785-9b4b6ff85200',
6
+ 42161: '3bff954d-5cb0-47a0-9a23-d20192e74600',
15
7
  // Avalanche
16
8
  43114: '30c46e53-e989-45fb-4549-be3bd4eb3b00',
17
9
  // Binance Smart Chain
@@ -22,6 +14,20 @@ export const PresetsUtil = {
22
14
  10: 'ab9c186a-c52f-464b-2906-ca59d760a400',
23
15
  // Polygon
24
16
  137: '41d04d42-da3b-4453-8506-668cc0727900',
17
+ // Mantle
18
+ 5000: 'e86fae9b-b770-4eea-e520-150e12c81100',
19
+ // Hedera Mainnet
20
+ 295: '6a97d510-cac8-4e58-c7ce-e8681b044c00',
21
+ // Sepolia
22
+ 11_155_111: 'e909ea0a-f92a-4512-c8fc-748044ea6800',
23
+ // Base Sepolia
24
+ 84532: 'a18a7ecd-e307-4360-4746-283182228e00',
25
+ // Unichain Sepolia
26
+ 1301: '4eeea7ef-0014-4649-5d1d-07271a80f600',
27
+ // Unichain Mainnet
28
+ 130: '2257980a-3463-48c6-cbac-a42d2a956e00',
29
+ // Monad Testnet
30
+ 10_143: '0a728e83-bacb-46db-7844-948f05434900',
25
31
  // Gnosis
26
32
  100: '02b53f6a-e3d4-479e-1cb4-21178987d100',
27
33
  // EVMos
@@ -45,26 +51,28 @@ export const PresetsUtil = {
45
51
  // Base
46
52
  8453: '7289c336-3981-4081-c5f4-efc26ac64a00',
47
53
  // Aurora
48
- 1313161554: '3ff73439-a619-4894-9262-4470c773a100'
49
- } as Record<string, string>,
54
+ 1313161554: '3ff73439-a619-4894-9262-4470c773a100',
55
+ // Ronin Mainnet
56
+ 2020: 'b8101fc0-9c19-4b6f-ec65-f6dfff106e00',
57
+ // Saigon Testnet (a.k.a. Ronin)
58
+ 2021: 'b8101fc0-9c19-4b6f-ec65-f6dfff106e00',
59
+ // Berachain Mainnet
60
+ 80094: 'e329c2c9-59b0-4a02-83e4-212ff3779900',
61
+ // Abstract Mainnet
62
+ 2741: 'fc2427d1-5af9-4a9c-8da5-6f94627cd900',
50
63
 
51
- ConnectorNamesMap: {
52
- [ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'WalletConnect',
53
- [ConstantsUtil.COINBASE_CONNECTOR_ID]: 'Coinbase Wallet',
54
- [ConstantsUtil.AUTH_CONNECTOR_ID]: 'AppKit Universal Wallet'
55
- } as Record<string, string>,
64
+ // Solana networks
65
+ /// Mainnet
66
+ '5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'a1b58899-f671-4276-6a5e-56ca5bd59700',
67
+ /// Testnet
68
+ '4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z': 'a1b58899-f671-4276-6a5e-56ca5bd59700',
56
69
 
57
- ConnectorImageIds: {
58
- [ConstantsUtil.COINBASE_CONNECTOR_ID]: '0c2840c3-5b04-4c44-9661-fbd4b49e1800',
59
- [ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'ef1a1fcf-7fe8-4d69-bd6d-fda1345b4400'
70
+ // Bitcoin
71
+ '000000000019d6689c085ae165831e93': '0b4838db-0161-4ffe-022d-532bf03dba00',
72
+ // Bitcoin Testnet
73
+ '000000000933ea01ad0ee984209779ba': '39354064-d79b-420b-065d-f980c4b78200'
60
74
  } as Record<string, string>,
61
75
 
62
- ConnectorTypesMap: {
63
- [ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'WALLET_CONNECT',
64
- [ConstantsUtil.COINBASE_CONNECTOR_ID]: 'COINBASE',
65
- [ConstantsUtil.AUTH_CONNECTOR_ID]: 'AUTH'
66
- } as Record<string, ConnectorType>,
67
-
68
76
  RpcChainIds: [
69
77
  // Ethereum
70
78
  1,
@@ -5,5 +5,12 @@ export const StringUtil = {
5
5
  }
6
6
 
7
7
  return value.charAt(0).toUpperCase() + value.slice(1).toLowerCase();
8
+ },
9
+ hexToString(hexValue: string) {
10
+ // Remove 0x prefix if present
11
+ const cleanHex = hexValue.startsWith('0x') ? hexValue.slice(2) : hexValue;
12
+ // Convert hex to decimal number, then to string
13
+
14
+ return parseInt(cleanHex, 16).toString();
8
15
  }
9
16
  };
@@ -1,19 +1,73 @@
1
- export interface Balance {
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;
2
15
  name: string;
3
- symbol: string;
4
- chainId: string;
5
- address?: string;
6
- value?: number;
7
- price: number;
8
- quantity: BalanceQuantity;
9
- iconUrl: string;
10
- }
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
+ };
11
25
 
12
- type BalanceQuantity = {
13
- decimals: string;
14
- numeric: string;
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
15
38
  };
16
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
+
17
71
  export type TransactionStatus = 'confirmed' | 'failed' | 'pending';
18
72
  export type TransactionDirection = 'in' | 'out' | 'self';
19
73
  export type TransactionImage = {
@@ -86,7 +140,15 @@ export interface TransactionQuantity {
86
140
  numeric: string;
87
141
  }
88
142
 
89
- export type SocialProvider = 'apple' | 'x' | 'discord' | 'farcaster';
143
+ export type SocialProvider =
144
+ | 'google'
145
+ | 'facebook'
146
+ | 'github'
147
+ | 'apple'
148
+ | 'x'
149
+ | 'discord'
150
+ | 'email'
151
+ | 'farcaster';
90
152
 
91
153
  export type ThemeMode = 'dark' | 'light';
92
154
 
@@ -94,4 +156,338 @@ export interface ThemeVariables {
94
156
  accent?: string;
95
157
  }
96
158
 
97
- export type ConnectorType = 'WALLET_CONNECT' | 'COINBASE' | 'AUTH' | 'EXTERNAL';
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
+ }