@reown/appkit-common-react-native 0.0.0-feat-multi-social-20250714211631 → 0.0.0-feat-onramp-20250718185718
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.
- package/lib/commonjs/index.js +1 -62
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/utils/ConstantsUtil.js +1 -4
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/NumberUtil.js +11 -52
- package/lib/commonjs/utils/NumberUtil.js.map +1 -1
- package/lib/commonjs/utils/PresetsUtil.js +8 -34
- package/lib/commonjs/utils/PresetsUtil.js.map +1 -1
- package/lib/commonjs/utils/TypeUtil.js +0 -46
- package/lib/commonjs/utils/TypeUtil.js.map +1 -1
- package/lib/module/index.js +0 -5
- package/lib/module/index.js.map +1 -1
- package/lib/module/utils/ConstantsUtil.js +1 -4
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/NumberUtil.js +11 -52
- package/lib/module/utils/NumberUtil.js.map +1 -1
- package/lib/module/utils/PresetsUtil.js +8 -34
- package/lib/module/utils/PresetsUtil.js.map +1 -1
- package/lib/module/utils/TypeUtil.js +0 -40
- package/lib/module/utils/TypeUtil.js.map +1 -1
- package/lib/typescript/index.d.ts +0 -5
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/utils/ConstantsUtil.d.ts +0 -3
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/NumberUtil.d.ts +11 -39
- package/lib/typescript/utils/NumberUtil.d.ts.map +1 -1
- package/lib/typescript/utils/PresetsUtil.d.ts +3 -1
- package/lib/typescript/utils/PresetsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +11 -291
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/index.ts +0 -5
- package/src/utils/ConstantsUtil.ts +1 -4
- package/src/utils/NumberUtil.ts +11 -54
- package/src/utils/PresetsUtil.ts +10 -36
- package/src/utils/TypeUtil.ts +13 -375
- package/lib/commonjs/adapters/BlockchainAdapter.js +0 -79
- package/lib/commonjs/adapters/BlockchainAdapter.js.map +0 -1
- package/lib/commonjs/adapters/EvmAdapter.js +0 -267
- package/lib/commonjs/adapters/EvmAdapter.js.map +0 -1
- package/lib/commonjs/adapters/SolanaBaseAdapter.js +0 -12
- package/lib/commonjs/adapters/SolanaBaseAdapter.js.map +0 -1
- package/lib/commonjs/networks/bitcoin.js +0 -40
- package/lib/commonjs/networks/bitcoin.js.map +0 -1
- package/lib/commonjs/networks/solana.js +0 -78
- package/lib/commonjs/networks/solana.js.map +0 -1
- package/lib/module/adapters/BlockchainAdapter.js +0 -72
- package/lib/module/adapters/BlockchainAdapter.js.map +0 -1
- package/lib/module/adapters/EvmAdapter.js +0 -261
- package/lib/module/adapters/EvmAdapter.js.map +0 -1
- package/lib/module/adapters/SolanaBaseAdapter.js +0 -5
- package/lib/module/adapters/SolanaBaseAdapter.js.map +0 -1
- package/lib/module/networks/bitcoin.js +0 -34
- package/lib/module/networks/bitcoin.js.map +0 -1
- package/lib/module/networks/solana.js +0 -72
- package/lib/module/networks/solana.js.map +0 -1
- package/lib/typescript/adapters/BlockchainAdapter.d.ts +0 -27
- package/lib/typescript/adapters/BlockchainAdapter.d.ts.map +0 -1
- package/lib/typescript/adapters/EvmAdapter.d.ts +0 -55
- package/lib/typescript/adapters/EvmAdapter.d.ts.map +0 -1
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts +0 -4
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts.map +0 -1
- package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts +0 -2
- package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts.map +0 -1
- package/lib/typescript/networks/bitcoin.d.ts +0 -4
- package/lib/typescript/networks/bitcoin.d.ts.map +0 -1
- package/lib/typescript/networks/solana.d.ts +0 -5
- package/lib/typescript/networks/solana.d.ts.map +0 -1
- package/src/adapters/BlockchainAdapter.ts +0 -109
- package/src/adapters/EvmAdapter.ts +0 -298
- package/src/adapters/SolanaBaseAdapter.ts +0 -5
- package/src/adapters/__tests__/EvmAdapter.test.ts +0 -104
- package/src/networks/bitcoin.ts +0 -32
- package/src/networks/solana.ts +0 -44
package/src/utils/NumberUtil.ts
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
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
|
-
*/
|
|
10
4
|
bigNumber(value: BigNumber.BigNumber.Value) {
|
|
11
5
|
if (typeof value === 'string') {
|
|
12
6
|
return new BigNumber.BigNumber(value.replace(/,/g, ''));
|
|
@@ -16,11 +10,10 @@ export const NumberUtil = {
|
|
|
16
10
|
},
|
|
17
11
|
|
|
18
12
|
/**
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* @param
|
|
22
|
-
* @
|
|
23
|
-
* @returns The product as a BigNumber instance, or BigNumber(0) if either input is undefined.
|
|
13
|
+
* Multiply two numbers represented as strings with BigNumber to handle decimals correctly
|
|
14
|
+
* @param a string
|
|
15
|
+
* @param b string
|
|
16
|
+
* @returns
|
|
24
17
|
*/
|
|
25
18
|
multiply(a: BigNumber.BigNumber.Value | undefined, b: BigNumber.BigNumber.Value | undefined) {
|
|
26
19
|
if (a === undefined || b === undefined) {
|
|
@@ -33,13 +26,6 @@ export const NumberUtil = {
|
|
|
33
26
|
return aBigNumber.multipliedBy(bBigNumber);
|
|
34
27
|
},
|
|
35
28
|
|
|
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
|
-
*/
|
|
43
29
|
roundNumber(number: number, threshold: number, fixed: number) {
|
|
44
30
|
const roundedNumber =
|
|
45
31
|
number.toString().length >= threshold ? Number(number).toFixed(fixed) : number;
|
|
@@ -47,12 +33,6 @@ export const NumberUtil = {
|
|
|
47
33
|
return roundedNumber;
|
|
48
34
|
},
|
|
49
35
|
|
|
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
|
-
*/
|
|
56
36
|
nextMultipleOfTen(amount?: number) {
|
|
57
37
|
if (!amount) return 10;
|
|
58
38
|
|
|
@@ -60,10 +40,10 @@ export const NumberUtil = {
|
|
|
60
40
|
},
|
|
61
41
|
|
|
62
42
|
/**
|
|
63
|
-
*
|
|
64
|
-
* @param value - The value to format
|
|
65
|
-
* @param decimals -
|
|
66
|
-
* @returns
|
|
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
|
|
67
47
|
*/
|
|
68
48
|
formatNumberToLocalString(value: string | number | undefined, decimals = 2) {
|
|
69
49
|
if (value === undefined) {
|
|
@@ -82,11 +62,10 @@ export const NumberUtil = {
|
|
|
82
62
|
minimumFractionDigits: decimals
|
|
83
63
|
});
|
|
84
64
|
},
|
|
85
|
-
|
|
86
65
|
/**
|
|
87
|
-
*
|
|
88
|
-
* @param value - The formatted string to parse
|
|
89
|
-
* @returns
|
|
66
|
+
* Parse a formatted local string back to a number
|
|
67
|
+
* @param value - The formatted string to parse
|
|
68
|
+
* @returns
|
|
90
69
|
*/
|
|
91
70
|
parseLocalStringToNumber(value: string | undefined) {
|
|
92
71
|
if (value === undefined) {
|
|
@@ -95,27 +74,5 @@ export const NumberUtil = {
|
|
|
95
74
|
|
|
96
75
|
// Remove any commas used as thousand separators and parse the float
|
|
97
76
|
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
|
-
}
|
|
120
77
|
}
|
|
121
78
|
};
|
package/src/utils/PresetsUtil.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ConnectorType } from './TypeUtil';
|
|
1
2
|
import { ConstantsUtil } from './ConstantsUtil';
|
|
2
3
|
|
|
3
4
|
export const PresetsUtil = {
|
|
@@ -6,11 +7,11 @@ export const PresetsUtil = {
|
|
|
6
7
|
'fd20dc426fb37566d803205b19bbc1d4096b248ac04548e3cfb6b3a38bd033aa'
|
|
7
8
|
} as Record<string, string>,
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
EIP155NetworkImageIds: {
|
|
10
11
|
// Ethereum
|
|
11
12
|
1: 'ba0ba0cd-17c6-4806-ad93-f9d174f17900',
|
|
12
13
|
// Arbitrum
|
|
13
|
-
42161: '
|
|
14
|
+
42161: '600a9a04-c1b9-42ca-6785-9b4b6ff85200',
|
|
14
15
|
// Avalanche
|
|
15
16
|
43114: '30c46e53-e989-45fb-4549-be3bd4eb3b00',
|
|
16
17
|
// Binance Smart Chain
|
|
@@ -21,20 +22,6 @@ export const PresetsUtil = {
|
|
|
21
22
|
10: 'ab9c186a-c52f-464b-2906-ca59d760a400',
|
|
22
23
|
// Polygon
|
|
23
24
|
137: '41d04d42-da3b-4453-8506-668cc0727900',
|
|
24
|
-
// Mantle
|
|
25
|
-
5000: 'e86fae9b-b770-4eea-e520-150e12c81100',
|
|
26
|
-
// Hedera Mainnet
|
|
27
|
-
295: '6a97d510-cac8-4e58-c7ce-e8681b044c00',
|
|
28
|
-
// Sepolia
|
|
29
|
-
11_155_111: 'e909ea0a-f92a-4512-c8fc-748044ea6800',
|
|
30
|
-
// Base Sepolia
|
|
31
|
-
84532: 'a18a7ecd-e307-4360-4746-283182228e00',
|
|
32
|
-
// Unichain Sepolia
|
|
33
|
-
1301: '4eeea7ef-0014-4649-5d1d-07271a80f600',
|
|
34
|
-
// Unichain Mainnet
|
|
35
|
-
130: '2257980a-3463-48c6-cbac-a42d2a956e00',
|
|
36
|
-
// Monad Testnet
|
|
37
|
-
10_143: '0a728e83-bacb-46db-7844-948f05434900',
|
|
38
25
|
// Gnosis
|
|
39
26
|
100: '02b53f6a-e3d4-479e-1cb4-21178987d100',
|
|
40
27
|
// EVMos
|
|
@@ -58,26 +45,7 @@ export const PresetsUtil = {
|
|
|
58
45
|
// Base
|
|
59
46
|
8453: '7289c336-3981-4081-c5f4-efc26ac64a00',
|
|
60
47
|
// Aurora
|
|
61
|
-
1313161554: '3ff73439-a619-4894-9262-4470c773a100'
|
|
62
|
-
// Ronin Mainnet
|
|
63
|
-
2020: 'b8101fc0-9c19-4b6f-ec65-f6dfff106e00',
|
|
64
|
-
// Saigon Testnet (a.k.a. Ronin)
|
|
65
|
-
2021: 'b8101fc0-9c19-4b6f-ec65-f6dfff106e00',
|
|
66
|
-
// Berachain Mainnet
|
|
67
|
-
80094: 'e329c2c9-59b0-4a02-83e4-212ff3779900',
|
|
68
|
-
// Abstract Mainnet
|
|
69
|
-
2741: 'fc2427d1-5af9-4a9c-8da5-6f94627cd900',
|
|
70
|
-
|
|
71
|
-
// Solana networks
|
|
72
|
-
/// Mainnet
|
|
73
|
-
'5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp': 'a1b58899-f671-4276-6a5e-56ca5bd59700',
|
|
74
|
-
/// Testnet
|
|
75
|
-
'4uhcVJyU9pJkvQyS88uRDiswHXSCkY3z': 'a1b58899-f671-4276-6a5e-56ca5bd59700',
|
|
76
|
-
|
|
77
|
-
// Bitcoin
|
|
78
|
-
'000000000019d6689c085ae165831e93': '0b4838db-0161-4ffe-022d-532bf03dba00',
|
|
79
|
-
// Bitcoin Testnet
|
|
80
|
-
'000000000933ea01ad0ee984209779ba': '39354064-d79b-420b-065d-f980c4b78200'
|
|
48
|
+
1313161554: '3ff73439-a619-4894-9262-4470c773a100'
|
|
81
49
|
} as Record<string, string>,
|
|
82
50
|
|
|
83
51
|
ConnectorNamesMap: {
|
|
@@ -91,6 +59,12 @@ export const PresetsUtil = {
|
|
|
91
59
|
[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'ef1a1fcf-7fe8-4d69-bd6d-fda1345b4400'
|
|
92
60
|
} as Record<string, string>,
|
|
93
61
|
|
|
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
|
+
|
|
94
68
|
RpcChainIds: [
|
|
95
69
|
// Ethereum
|
|
96
70
|
1,
|
package/src/utils/TypeUtil.ts
CHANGED
|
@@ -1,66 +1,19 @@
|
|
|
1
|
-
import { EventEmitter } from 'events';
|
|
2
|
-
|
|
3
|
-
export type CaipAddress = `${string}:${string}:${string}`;
|
|
4
|
-
|
|
5
|
-
export type CaipNetworkId = `${string}:${string}`;
|
|
6
|
-
|
|
7
|
-
export type ChainNamespace = 'eip155' | 'solana' | 'polkadot' | 'bip122';
|
|
8
|
-
|
|
9
|
-
export type Network = {
|
|
10
|
-
// Core viem/chain properties
|
|
11
|
-
id: number | string;
|
|
12
|
-
name: string;
|
|
13
|
-
nativeCurrency: { name: string; symbol: string; decimals: number };
|
|
14
|
-
rpcUrls: {
|
|
15
|
-
default: { http: readonly string[] };
|
|
16
|
-
[key: string]: { http: readonly string[] } | undefined;
|
|
17
|
-
};
|
|
18
|
-
blockExplorers?: {
|
|
19
|
-
default: { name: string; url: string };
|
|
20
|
-
[key: string]: { name: string; url: string } | undefined;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
// AppKit specific / CAIP properties (Optional in type, but needed in practice)
|
|
24
|
-
chainNamespace?: ChainNamespace; // e.g., 'eip155'
|
|
25
|
-
caipNetworkId?: CaipNetworkId; // e.g., 'eip155:1'
|
|
26
|
-
testnet?: boolean;
|
|
27
|
-
deprecatedCaipNetworkId?: CaipNetworkId; // for Solana deprecated id
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
export type AppKitNetwork = Network & {
|
|
31
|
-
chainNamespace: ChainNamespace; // e.g., 'eip155'
|
|
32
|
-
caipNetworkId: CaipNetworkId; // e.g., 'eip155:1'
|
|
33
|
-
testnet?: boolean;
|
|
34
|
-
deprecatedCaipNetworkId?: CaipNetworkId; // for Solana deprecated id
|
|
35
|
-
};
|
|
36
|
-
|
|
37
|
-
export type AppKitConnectOptions = Pick<
|
|
38
|
-
ConnectOptions,
|
|
39
|
-
'namespaces' | 'defaultChain' | 'universalLink'
|
|
40
|
-
>;
|
|
41
|
-
|
|
42
|
-
export interface CaipNetwork {
|
|
43
|
-
id: CaipNetworkId;
|
|
44
|
-
name?: string;
|
|
45
|
-
imageId?: string;
|
|
46
|
-
imageUrl?: string;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
1
|
export interface Balance {
|
|
50
|
-
name
|
|
51
|
-
amount: string;
|
|
2
|
+
name: string;
|
|
52
3
|
symbol: string;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
value?: number; //total value of the amount in currency
|
|
60
|
-
price?: number; //price of the token in currency
|
|
61
|
-
iconUrl?: string;
|
|
4
|
+
chainId: string;
|
|
5
|
+
address?: string;
|
|
6
|
+
value?: number;
|
|
7
|
+
price: number;
|
|
8
|
+
quantity: BalanceQuantity;
|
|
9
|
+
iconUrl: string;
|
|
62
10
|
}
|
|
63
11
|
|
|
12
|
+
type BalanceQuantity = {
|
|
13
|
+
decimals: string;
|
|
14
|
+
numeric: string;
|
|
15
|
+
};
|
|
16
|
+
|
|
64
17
|
export type TransactionStatus = 'confirmed' | 'failed' | 'pending';
|
|
65
18
|
export type TransactionDirection = 'in' | 'out' | 'self';
|
|
66
19
|
export type TransactionImage = {
|
|
@@ -133,15 +86,7 @@ export interface TransactionQuantity {
|
|
|
133
86
|
numeric: string;
|
|
134
87
|
}
|
|
135
88
|
|
|
136
|
-
export type SocialProvider =
|
|
137
|
-
| 'google'
|
|
138
|
-
| 'facebook'
|
|
139
|
-
| 'github'
|
|
140
|
-
| 'apple'
|
|
141
|
-
| 'x'
|
|
142
|
-
| 'discord'
|
|
143
|
-
| 'email'
|
|
144
|
-
| 'farcaster';
|
|
89
|
+
export type SocialProvider = 'apple' | 'x' | 'discord' | 'farcaster';
|
|
145
90
|
|
|
146
91
|
export type ThemeMode = 'dark' | 'light';
|
|
147
92
|
|
|
@@ -149,311 +94,4 @@ export interface ThemeVariables {
|
|
|
149
94
|
accent?: string;
|
|
150
95
|
}
|
|
151
96
|
|
|
152
|
-
export interface Token {
|
|
153
|
-
address: string;
|
|
154
|
-
image?: string;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export type Tokens = Record<CaipNetworkId, Token>;
|
|
158
|
-
|
|
159
|
-
//TODO: remove this
|
|
160
97
|
export type ConnectorType = 'WALLET_CONNECT' | 'COINBASE' | 'AUTH' | 'EXTERNAL';
|
|
161
|
-
|
|
162
|
-
export type Metadata = {
|
|
163
|
-
name: string;
|
|
164
|
-
description: string;
|
|
165
|
-
url: string;
|
|
166
|
-
icons: string[];
|
|
167
|
-
redirect?: {
|
|
168
|
-
native?: string;
|
|
169
|
-
universal?: string;
|
|
170
|
-
linkMode?: boolean;
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
//********** Adapter Event Payloads **********//
|
|
175
|
-
export type AccountsChangedEvent = {
|
|
176
|
-
accounts: string[];
|
|
177
|
-
};
|
|
178
|
-
|
|
179
|
-
export type ChainChangedEvent = {
|
|
180
|
-
chainId: string;
|
|
181
|
-
};
|
|
182
|
-
|
|
183
|
-
export type DisconnectEvent = {};
|
|
184
|
-
|
|
185
|
-
export type BalanceChangedEvent = {
|
|
186
|
-
address: CaipAddress;
|
|
187
|
-
balance: Balance;
|
|
188
|
-
};
|
|
189
|
-
|
|
190
|
-
//********** Adapter Event Map **********//
|
|
191
|
-
export interface AdapterEvents {
|
|
192
|
-
accountsChanged: (event: AccountsChangedEvent) => void;
|
|
193
|
-
chainChanged: (event: ChainChangedEvent) => void;
|
|
194
|
-
disconnect: (event: DisconnectEvent) => void;
|
|
195
|
-
balanceChanged: (event: BalanceChangedEvent) => void;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
export interface GetBalanceParams {
|
|
199
|
-
network: AppKitNetwork;
|
|
200
|
-
address?: CaipAddress;
|
|
201
|
-
tokens?: Tokens;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
export type GetBalanceResponse = Balance;
|
|
205
|
-
|
|
206
|
-
//********** Connector Types **********//
|
|
207
|
-
interface BaseNamespace {
|
|
208
|
-
chains?: CaipNetworkId[];
|
|
209
|
-
accounts: CaipAddress[];
|
|
210
|
-
methods: string[];
|
|
211
|
-
events: string[];
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
type Namespace = BaseNamespace;
|
|
215
|
-
|
|
216
|
-
export type Namespaces = Record<string, Namespace>;
|
|
217
|
-
|
|
218
|
-
export type ProposalNamespaces = Record<
|
|
219
|
-
string,
|
|
220
|
-
Omit<Namespace, 'accounts'> &
|
|
221
|
-
Required<Pick<Namespace, 'chains'>> & { rpcMap: Record<string, string> }
|
|
222
|
-
>;
|
|
223
|
-
|
|
224
|
-
export type ConnectOptions = {
|
|
225
|
-
namespaces?: ProposalNamespaces;
|
|
226
|
-
defaultChain?: CaipNetworkId;
|
|
227
|
-
universalLink?: string;
|
|
228
|
-
siweConfig?: AppKitSIWEClient;
|
|
229
|
-
};
|
|
230
|
-
|
|
231
|
-
export type ConnectorInitOptions = {
|
|
232
|
-
storage: Storage;
|
|
233
|
-
metadata: Metadata;
|
|
234
|
-
};
|
|
235
|
-
|
|
236
|
-
export abstract class WalletConnector extends EventEmitter {
|
|
237
|
-
public type: New_ConnectorType;
|
|
238
|
-
protected provider?: Provider;
|
|
239
|
-
protected namespaces?: Namespaces;
|
|
240
|
-
protected wallet?: WalletInfo;
|
|
241
|
-
protected storage?: Storage;
|
|
242
|
-
protected metadata?: Metadata;
|
|
243
|
-
protected properties?: ConnectionProperties;
|
|
244
|
-
|
|
245
|
-
constructor({ type }: { type: New_ConnectorType }) {
|
|
246
|
-
super();
|
|
247
|
-
this.type = type;
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
public async init(ops: ConnectorInitOptions) {
|
|
251
|
-
this.storage = ops.storage;
|
|
252
|
-
this.metadata = ops.metadata;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
public setProvider(provider: Provider) {
|
|
256
|
-
this.provider = provider;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
public async disconnect() {
|
|
260
|
-
await this.provider?.disconnect();
|
|
261
|
-
this.namespaces = undefined;
|
|
262
|
-
this.wallet = undefined;
|
|
263
|
-
this.properties = undefined;
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
abstract connect(opts: ConnectOptions): Promise<Namespaces | undefined>;
|
|
267
|
-
abstract getProvider(): Provider;
|
|
268
|
-
abstract getNamespaces(): Namespaces;
|
|
269
|
-
abstract getChainId(namespace: ChainNamespace): CaipNetworkId | undefined;
|
|
270
|
-
abstract getWalletInfo(): WalletInfo | undefined;
|
|
271
|
-
abstract getProperties(): ConnectionProperties | undefined;
|
|
272
|
-
abstract switchNetwork(network: AppKitNetwork): Promise<void>;
|
|
273
|
-
abstract restoreSession(): Promise<boolean>;
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
//********** Provider Types **********//
|
|
277
|
-
|
|
278
|
-
export interface Provider {
|
|
279
|
-
connect<T>(params?: any): Promise<T>;
|
|
280
|
-
disconnect(): Promise<void>;
|
|
281
|
-
request<T = unknown>(
|
|
282
|
-
args: RequestArguments,
|
|
283
|
-
chain?: string | undefined,
|
|
284
|
-
expiry?: number | undefined
|
|
285
|
-
): Promise<T>;
|
|
286
|
-
on(event: string, listener: (args?: any) => void): any;
|
|
287
|
-
off(event: string, listener: (args?: any) => void): any;
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
export interface RequestArguments {
|
|
291
|
-
method: string;
|
|
292
|
-
params?: unknown[] | Record<string, unknown> | object | undefined;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
//TODO: rename this and remove the old one ConnectorType
|
|
296
|
-
export type New_ConnectorType = 'walletconnect' | 'coinbase' | 'auth' | 'phantom';
|
|
297
|
-
|
|
298
|
-
//********** Others **********//
|
|
299
|
-
|
|
300
|
-
export interface ConnectionResponse {
|
|
301
|
-
accounts: string[];
|
|
302
|
-
chainId: string;
|
|
303
|
-
[key: string]: any;
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
export interface WalletInfo {
|
|
307
|
-
name?: string;
|
|
308
|
-
icon?: string;
|
|
309
|
-
description?: string;
|
|
310
|
-
url?: string;
|
|
311
|
-
icons?: string[];
|
|
312
|
-
redirect?: {
|
|
313
|
-
native?: string;
|
|
314
|
-
universal?: string;
|
|
315
|
-
linkMode?: boolean;
|
|
316
|
-
};
|
|
317
|
-
[key: string]: unknown;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
export interface ConnectionProperties {
|
|
321
|
-
email?: string;
|
|
322
|
-
username?: string;
|
|
323
|
-
smartAccounts?: CaipAddress[];
|
|
324
|
-
provider?: SocialProvider;
|
|
325
|
-
sessionTopic?: string;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
export type AccountType = 'eoa' | 'smartAccount';
|
|
329
|
-
|
|
330
|
-
export interface Storage {
|
|
331
|
-
/**
|
|
332
|
-
* Returns all keys in storage.
|
|
333
|
-
*/
|
|
334
|
-
getKeys(): Promise<string[]>;
|
|
335
|
-
|
|
336
|
-
/**
|
|
337
|
-
* Returns all key-value entries in storage.
|
|
338
|
-
*/
|
|
339
|
-
getEntries<T = any>(): Promise<[string, T][]>;
|
|
340
|
-
|
|
341
|
-
/**
|
|
342
|
-
* Get an item from storage for a given key.
|
|
343
|
-
* @param key The key to retrieve.
|
|
344
|
-
*/
|
|
345
|
-
getItem<T = any>(key: string): Promise<T | undefined>;
|
|
346
|
-
|
|
347
|
-
/**
|
|
348
|
-
* Set an item in storage for a given key.
|
|
349
|
-
* @param key The key to set.
|
|
350
|
-
* @param value The value to set.
|
|
351
|
-
*/
|
|
352
|
-
setItem<T = any>(key: string, value: T): Promise<void>;
|
|
353
|
-
|
|
354
|
-
/**
|
|
355
|
-
* Remove an item from storage for a given key.
|
|
356
|
-
* @param key The key to remove.
|
|
357
|
-
*/
|
|
358
|
-
removeItem(key: string): Promise<void>;
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
//********** SIWE Types **********//
|
|
362
|
-
export interface SIWESession {
|
|
363
|
-
address: string;
|
|
364
|
-
chainId: number;
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
interface CacaoHeader {
|
|
368
|
-
t: 'caip122';
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
export interface SIWECreateMessageArgs {
|
|
372
|
-
chainId: number;
|
|
373
|
-
domain: string;
|
|
374
|
-
nonce: string;
|
|
375
|
-
uri: string;
|
|
376
|
-
address: string;
|
|
377
|
-
version: '1';
|
|
378
|
-
type?: CacaoHeader['t'];
|
|
379
|
-
nbf?: string;
|
|
380
|
-
exp?: string;
|
|
381
|
-
statement?: string;
|
|
382
|
-
requestId?: string;
|
|
383
|
-
resources?: string[];
|
|
384
|
-
expiry?: number;
|
|
385
|
-
iat?: string;
|
|
386
|
-
}
|
|
387
|
-
export type SIWEMessageArgs = {
|
|
388
|
-
chains: CaipNetworkId[];
|
|
389
|
-
methods?: string[];
|
|
390
|
-
} & Omit<SIWECreateMessageArgs, 'address' | 'chainId' | 'nonce' | 'version'>;
|
|
391
|
-
// Signed Cacao (CAIP-74)
|
|
392
|
-
interface CacaoPayload {
|
|
393
|
-
domain: string;
|
|
394
|
-
aud: string;
|
|
395
|
-
nonce: string;
|
|
396
|
-
iss: string;
|
|
397
|
-
version?: string;
|
|
398
|
-
iat?: string;
|
|
399
|
-
nbf?: string;
|
|
400
|
-
exp?: string;
|
|
401
|
-
statement?: string;
|
|
402
|
-
requestId?: string;
|
|
403
|
-
resources?: string[];
|
|
404
|
-
type?: string;
|
|
405
|
-
}
|
|
406
|
-
|
|
407
|
-
interface Cacao {
|
|
408
|
-
h: CacaoHeader;
|
|
409
|
-
p: CacaoPayload;
|
|
410
|
-
s: {
|
|
411
|
-
t: 'eip191' | 'eip1271';
|
|
412
|
-
s: string;
|
|
413
|
-
m?: string;
|
|
414
|
-
};
|
|
415
|
-
}
|
|
416
|
-
|
|
417
|
-
export interface SIWEVerifyMessageArgs {
|
|
418
|
-
message: string;
|
|
419
|
-
signature: string;
|
|
420
|
-
cacao?: Cacao;
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
export interface SIWEClientMethods {
|
|
424
|
-
getNonce: (address?: string) => Promise<string>;
|
|
425
|
-
createMessage: (args: SIWECreateMessageArgs) => string;
|
|
426
|
-
verifyMessage: (args: SIWEVerifyMessageArgs) => Promise<boolean>;
|
|
427
|
-
getSession: () => Promise<SIWESession | null>;
|
|
428
|
-
signOut: () => Promise<boolean>;
|
|
429
|
-
getMessageParams?: () => Promise<SIWEMessageArgs>;
|
|
430
|
-
onSignIn?: (session?: SIWESession) => void;
|
|
431
|
-
onSignOut?: () => void;
|
|
432
|
-
}
|
|
433
|
-
|
|
434
|
-
export interface SIWEConfig extends SIWEClientMethods {
|
|
435
|
-
// Defaults to true
|
|
436
|
-
enabled?: boolean;
|
|
437
|
-
// In milliseconds, defaults to 5 minutes
|
|
438
|
-
nonceRefetchIntervalMs?: number;
|
|
439
|
-
// In milliseconds, defaults to 5 minutes
|
|
440
|
-
sessionRefetchIntervalMs?: number;
|
|
441
|
-
// Defaults to true
|
|
442
|
-
signOutOnDisconnect?: boolean;
|
|
443
|
-
// Defaults to true
|
|
444
|
-
signOutOnAccountChange?: boolean;
|
|
445
|
-
// Defaults to true
|
|
446
|
-
signOutOnNetworkChange?: boolean;
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
export interface AppKitSIWEClient extends SIWEClientMethods {
|
|
450
|
-
signIn: () => Promise<SIWESession | undefined>;
|
|
451
|
-
options: {
|
|
452
|
-
enabled: boolean;
|
|
453
|
-
nonceRefetchIntervalMs: number;
|
|
454
|
-
sessionRefetchIntervalMs: number;
|
|
455
|
-
signOutOnDisconnect: boolean;
|
|
456
|
-
signOutOnAccountChange: boolean;
|
|
457
|
-
signOutOnNetworkChange: boolean;
|
|
458
|
-
};
|
|
459
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.BlockchainAdapter = void 0;
|
|
7
|
-
var _events = require("events");
|
|
8
|
-
class BlockchainAdapter extends _events.EventEmitter {
|
|
9
|
-
// Typed emit method
|
|
10
|
-
emit(event, payload) {
|
|
11
|
-
return super.emit(event, payload);
|
|
12
|
-
}
|
|
13
|
-
constructor({
|
|
14
|
-
projectId,
|
|
15
|
-
supportedNamespace
|
|
16
|
-
}) {
|
|
17
|
-
super();
|
|
18
|
-
this.projectId = projectId;
|
|
19
|
-
this.supportedNamespace = supportedNamespace;
|
|
20
|
-
}
|
|
21
|
-
setConnector(connector) {
|
|
22
|
-
this.connector = connector;
|
|
23
|
-
this.subscribeToEvents();
|
|
24
|
-
}
|
|
25
|
-
removeConnector() {
|
|
26
|
-
this.connector = undefined;
|
|
27
|
-
}
|
|
28
|
-
getProvider() {
|
|
29
|
-
if (!this.connector) throw new Error('No active connector');
|
|
30
|
-
return this.connector.getProvider();
|
|
31
|
-
}
|
|
32
|
-
subscribeToEvents() {
|
|
33
|
-
const provider = this.connector?.getProvider();
|
|
34
|
-
if (!provider) return;
|
|
35
|
-
provider.on('chainChanged', this.onChainChanged.bind(this));
|
|
36
|
-
provider.on('accountsChanged', this.onAccountsChanged.bind(this));
|
|
37
|
-
provider.on('disconnect', this.onDisconnect.bind(this));
|
|
38
|
-
}
|
|
39
|
-
onChainChanged(chainId) {
|
|
40
|
-
const _chains = this.getAccounts()?.map(account => account.split(':')[1]);
|
|
41
|
-
const shouldEmit = _chains?.some(chain => chain === chainId);
|
|
42
|
-
if (shouldEmit) {
|
|
43
|
-
this.emit('chainChanged', {
|
|
44
|
-
chainId
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
onAccountsChanged(accounts) {
|
|
49
|
-
const _accounts = this.getAccounts();
|
|
50
|
-
const shouldEmit = _accounts?.some(account => {
|
|
51
|
-
const accountAddress = account.split(':')[2];
|
|
52
|
-
return accountAddress !== undefined && accounts.includes(accountAddress);
|
|
53
|
-
});
|
|
54
|
-
if (shouldEmit) {
|
|
55
|
-
this.emit('accountsChanged', {
|
|
56
|
-
accounts
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
onDisconnect() {
|
|
61
|
-
this.emit('disconnect', {
|
|
62
|
-
namespace: this.getSupportedNamespace()
|
|
63
|
-
});
|
|
64
|
-
const provider = this.connector?.getProvider();
|
|
65
|
-
if (provider) {
|
|
66
|
-
provider.off('chainChanged', this.onChainChanged.bind(this));
|
|
67
|
-
provider.off('accountsChanged', this.onAccountsChanged.bind(this));
|
|
68
|
-
provider.off('disconnect', this.onDisconnect.bind(this));
|
|
69
|
-
}
|
|
70
|
-
this.connector = undefined;
|
|
71
|
-
}
|
|
72
|
-
parseUnits(value, decimals) {
|
|
73
|
-
const [whole, fraction = ''] = value.split('.');
|
|
74
|
-
const paddedFraction = (fraction + '0'.repeat(decimals)).slice(0, decimals);
|
|
75
|
-
return BigInt(whole + paddedFraction);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
exports.BlockchainAdapter = BlockchainAdapter;
|
|
79
|
-
//# sourceMappingURL=BlockchainAdapter.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["_events","require","BlockchainAdapter","EventEmitter","emit","event","payload","constructor","projectId","supportedNamespace","setConnector","connector","subscribeToEvents","removeConnector","undefined","getProvider","Error","provider","on","onChainChanged","bind","onAccountsChanged","onDisconnect","chainId","_chains","getAccounts","map","account","split","shouldEmit","some","chain","accounts","_accounts","accountAddress","includes","namespace","getSupportedNamespace","off","parseUnits","value","decimals","whole","fraction","padded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