@reown/appkit-common-react-native 2.0.0-alpha.0 → 2.0.0-alpha.2
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/adapters/BlockchainAdapter.js +81 -0
- package/lib/commonjs/adapters/BlockchainAdapter.js.map +1 -0
- package/lib/commonjs/adapters/EvmAdapter.js +204 -0
- package/lib/commonjs/adapters/EvmAdapter.js.map +1 -0
- package/lib/commonjs/adapters/SolanaBaseAdapter.js +10 -0
- package/lib/commonjs/adapters/SolanaBaseAdapter.js.map +1 -0
- package/lib/commonjs/contracts/erc20.js.map +1 -1
- package/lib/commonjs/contracts/usdt.js.map +1 -1
- package/lib/commonjs/index.js +62 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/networks/bitcoin.js +40 -0
- package/lib/commonjs/networks/bitcoin.js.map +1 -0
- package/lib/commonjs/networks/solana.js +78 -0
- package/lib/commonjs/networks/solana.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/utils/ConstantsUtil.js +31 -5
- package/lib/commonjs/utils/ConstantsUtil.js.map +1 -1
- package/lib/commonjs/utils/ContractUtil.js.map +1 -1
- package/lib/commonjs/utils/DateUtil.js.map +1 -1
- package/lib/commonjs/utils/ErrorUtil.js +2 -2
- package/lib/commonjs/utils/ErrorUtil.js.map +1 -1
- package/lib/commonjs/utils/NamesUtil.js.map +1 -1
- package/lib/commonjs/utils/NetworkUtil.js.map +1 -1
- package/lib/commonjs/utils/NumberUtil.js +53 -13
- package/lib/commonjs/utils/NumberUtil.js.map +1 -1
- package/lib/commonjs/utils/PresetsUtil.js +0 -18
- package/lib/commonjs/utils/PresetsUtil.js.map +1 -1
- package/lib/commonjs/utils/StringUtil.js +7 -0
- package/lib/commonjs/utils/StringUtil.js.map +1 -1
- package/lib/commonjs/utils/TypeUtil.js +19 -81
- package/lib/commonjs/utils/TypeUtil.js.map +1 -1
- package/lib/module/adapters/BlockchainAdapter.js +76 -0
- package/lib/module/adapters/BlockchainAdapter.js.map +1 -0
- package/lib/module/adapters/EvmAdapter.js +200 -0
- package/lib/module/adapters/EvmAdapter.js.map +1 -0
- package/lib/module/adapters/SolanaBaseAdapter.js +5 -0
- package/lib/module/adapters/SolanaBaseAdapter.js.map +1 -0
- package/lib/module/contracts/erc20.js +2 -0
- package/lib/module/contracts/erc20.js.map +1 -1
- package/lib/module/contracts/usdt.js +2 -0
- package/lib/module/contracts/usdt.js.map +1 -1
- package/lib/module/index.js +7 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/networks/bitcoin.js +36 -0
- package/lib/module/networks/bitcoin.js.map +1 -0
- package/lib/module/networks/solana.js +74 -0
- package/lib/module/networks/solana.js.map +1 -0
- package/lib/module/utils/ConstantsUtil.js +33 -5
- package/lib/module/utils/ConstantsUtil.js.map +1 -1
- package/lib/module/utils/ContractUtil.js +2 -0
- package/lib/module/utils/ContractUtil.js.map +1 -1
- package/lib/module/utils/DateUtil.js +2 -0
- package/lib/module/utils/DateUtil.js.map +1 -1
- package/lib/module/utils/ErrorUtil.js +4 -2
- package/lib/module/utils/ErrorUtil.js.map +1 -1
- package/lib/module/utils/NamesUtil.js +2 -0
- package/lib/module/utils/NamesUtil.js.map +1 -1
- package/lib/module/utils/NetworkUtil.js +2 -0
- package/lib/module/utils/NetworkUtil.js.map +1 -1
- package/lib/module/utils/NumberUtil.js +54 -11
- package/lib/module/utils/NumberUtil.js.map +1 -1
- package/lib/module/utils/PresetsUtil.js +2 -18
- package/lib/module/utils/PresetsUtil.js.map +1 -1
- package/lib/module/utils/StringUtil.js +9 -0
- package/lib/module/utils/StringUtil.js.map +1 -1
- package/lib/module/utils/TypeUtil.js +19 -77
- package/lib/module/utils/TypeUtil.js.map +1 -1
- package/lib/typescript/adapters/BlockchainAdapter.d.ts +25 -0
- package/lib/typescript/adapters/BlockchainAdapter.d.ts.map +1 -0
- package/lib/typescript/adapters/EvmAdapter.d.ts +27 -0
- package/lib/typescript/adapters/EvmAdapter.d.ts.map +1 -0
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts +6 -0
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts.map +1 -0
- package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts +2 -0
- package/lib/typescript/adapters/__tests__/EvmAdapter.test.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +5 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/networks/bitcoin.d.ts +4 -0
- package/lib/typescript/networks/bitcoin.d.ts.map +1 -0
- package/lib/typescript/networks/solana.d.ts +5 -0
- package/lib/typescript/networks/solana.d.ts.map +1 -0
- package/lib/typescript/utils/ConstantsUtil.d.ts +27 -3
- package/lib/typescript/utils/ConstantsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/NumberUtil.d.ts +39 -11
- package/lib/typescript/utils/NumberUtil.d.ts.map +1 -1
- package/lib/typescript/utils/PresetsUtil.d.ts +0 -5
- package/lib/typescript/utils/PresetsUtil.d.ts.map +1 -1
- package/lib/typescript/utils/StringUtil.d.ts +1 -0
- package/lib/typescript/utils/StringUtil.d.ts.map +1 -1
- package/lib/typescript/utils/TypeUtil.d.ts +203 -68
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +7 -17
- package/src/adapters/BlockchainAdapter.ts +107 -0
- package/src/adapters/EvmAdapter.ts +259 -0
- package/src/adapters/SolanaBaseAdapter.ts +6 -0
- package/src/adapters/__tests__/EvmAdapter.test.ts +126 -0
- package/src/index.ts +5 -0
- package/src/networks/bitcoin.ts +32 -0
- package/src/networks/solana.ts +44 -0
- package/src/utils/ConstantsUtil.ts +33 -6
- package/src/utils/ErrorUtil.ts +2 -2
- package/src/utils/NumberUtil.ts +54 -11
- package/src/utils/PresetsUtil.ts +0 -25
- package/src/utils/StringUtil.ts +7 -0
- package/src/utils/TypeUtil.ts +259 -143
package/src/utils/PresetsUtil.ts
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
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
2
|
NetworkImageIds: {
|
|
11
3
|
// Ethereum
|
|
12
4
|
1: 'ba0ba0cd-17c6-4806-ad93-f9d174f17900',
|
|
@@ -81,23 +73,6 @@ export const PresetsUtil = {
|
|
|
81
73
|
'000000000933ea01ad0ee984209779ba': '39354064-d79b-420b-065d-f980c4b78200'
|
|
82
74
|
} as Record<string, string>,
|
|
83
75
|
|
|
84
|
-
ConnectorNamesMap: {
|
|
85
|
-
[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'WalletConnect',
|
|
86
|
-
[ConstantsUtil.COINBASE_CONNECTOR_ID]: 'Coinbase Wallet',
|
|
87
|
-
[ConstantsUtil.AUTH_CONNECTOR_ID]: 'AppKit Universal Wallet'
|
|
88
|
-
} as Record<string, string>,
|
|
89
|
-
|
|
90
|
-
ConnectorImageIds: {
|
|
91
|
-
[ConstantsUtil.COINBASE_CONNECTOR_ID]: '0c2840c3-5b04-4c44-9661-fbd4b49e1800',
|
|
92
|
-
[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'ef1a1fcf-7fe8-4d69-bd6d-fda1345b4400'
|
|
93
|
-
} as Record<string, string>,
|
|
94
|
-
|
|
95
|
-
ConnectorTypesMap: {
|
|
96
|
-
[ConstantsUtil.WALLET_CONNECT_CONNECTOR_ID]: 'WALLET_CONNECT',
|
|
97
|
-
[ConstantsUtil.COINBASE_CONNECTOR_ID]: 'COINBASE',
|
|
98
|
-
[ConstantsUtil.AUTH_CONNECTOR_ID]: 'AUTH'
|
|
99
|
-
} as Record<string, ConnectorType>,
|
|
100
|
-
|
|
101
76
|
RpcChainIds: [
|
|
102
77
|
// Ethereum
|
|
103
78
|
1,
|
package/src/utils/StringUtil.ts
CHANGED
|
@@ -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
|
};
|
package/src/utils/TypeUtil.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { EventEmitter } from 'events';
|
|
2
|
+
import type { BlockchainAdapter } from '../adapters/BlockchainAdapter';
|
|
2
3
|
|
|
3
4
|
export type CaipAddress = `${string}:${string}:${string}`;
|
|
4
5
|
|
|
@@ -6,6 +7,8 @@ export type CaipNetworkId = `${string}:${string}`;
|
|
|
6
7
|
|
|
7
8
|
export type ChainNamespace = 'eip155' | 'solana' | 'polkadot' | 'bip122';
|
|
8
9
|
|
|
10
|
+
export type AdapterType = 'solana' | 'wagmi' | 'ethers' | 'universal' | 'bip122';
|
|
11
|
+
|
|
9
12
|
export type Network = {
|
|
10
13
|
// Core viem/chain properties
|
|
11
14
|
id: number | string;
|
|
@@ -34,6 +37,15 @@ export type AppKitNetwork = Network & {
|
|
|
34
37
|
deprecatedCaipNetworkId?: CaipNetworkId; // for Solana deprecated id
|
|
35
38
|
};
|
|
36
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
|
+
|
|
37
49
|
export interface CaipNetwork {
|
|
38
50
|
id: CaipNetworkId;
|
|
39
51
|
name?: string;
|
|
@@ -42,21 +54,20 @@ export interface CaipNetwork {
|
|
|
42
54
|
}
|
|
43
55
|
|
|
44
56
|
export interface Balance {
|
|
45
|
-
name
|
|
57
|
+
name?: string;
|
|
58
|
+
amount: string;
|
|
46
59
|
symbol: string;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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;
|
|
53
69
|
}
|
|
54
70
|
|
|
55
|
-
type BalanceQuantity = {
|
|
56
|
-
decimals: string;
|
|
57
|
-
numeric: string;
|
|
58
|
-
};
|
|
59
|
-
|
|
60
71
|
export type TransactionStatus = 'confirmed' | 'failed' | 'pending';
|
|
61
72
|
export type TransactionDirection = 'in' | 'out' | 'self';
|
|
62
73
|
export type TransactionImage = {
|
|
@@ -129,7 +140,15 @@ export interface TransactionQuantity {
|
|
|
129
140
|
numeric: string;
|
|
130
141
|
}
|
|
131
142
|
|
|
132
|
-
export type SocialProvider =
|
|
143
|
+
export type SocialProvider =
|
|
144
|
+
| 'google'
|
|
145
|
+
| 'facebook'
|
|
146
|
+
| 'github'
|
|
147
|
+
| 'apple'
|
|
148
|
+
| 'x'
|
|
149
|
+
| 'discord'
|
|
150
|
+
| 'email'
|
|
151
|
+
| 'farcaster';
|
|
133
152
|
|
|
134
153
|
export type ThemeMode = 'dark' | 'light';
|
|
135
154
|
|
|
@@ -144,31 +163,54 @@ export interface Token {
|
|
|
144
163
|
|
|
145
164
|
export type Tokens = Record<CaipNetworkId, Token>;
|
|
146
165
|
|
|
147
|
-
export type
|
|
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
|
+
};
|
|
148
199
|
|
|
149
200
|
//********** Adapter Event Payloads **********//
|
|
150
201
|
export type AccountsChangedEvent = {
|
|
151
202
|
accounts: string[];
|
|
152
|
-
namespace: ChainNamespace;
|
|
153
203
|
};
|
|
154
204
|
|
|
155
205
|
export type ChainChangedEvent = {
|
|
156
206
|
chainId: string;
|
|
157
|
-
namespace: ChainNamespace;
|
|
158
207
|
};
|
|
159
208
|
|
|
160
|
-
export type DisconnectEvent = {
|
|
161
|
-
namespace: ChainNamespace;
|
|
162
|
-
};
|
|
209
|
+
export type DisconnectEvent = {};
|
|
163
210
|
|
|
164
211
|
export type BalanceChangedEvent = {
|
|
165
|
-
namespace: ChainNamespace;
|
|
166
212
|
address: CaipAddress;
|
|
167
|
-
balance:
|
|
168
|
-
amount: string;
|
|
169
|
-
symbol: string;
|
|
170
|
-
contractAddress?: ContractAddress;
|
|
171
|
-
};
|
|
213
|
+
balance: Balance;
|
|
172
214
|
};
|
|
173
215
|
|
|
174
216
|
//********** Adapter Event Map **********//
|
|
@@ -179,117 +221,13 @@ export interface AdapterEvents {
|
|
|
179
221
|
balanceChanged: (event: BalanceChangedEvent) => void;
|
|
180
222
|
}
|
|
181
223
|
|
|
182
|
-
//********** Adapter Types **********//
|
|
183
|
-
export abstract class BlockchainAdapter extends EventEmitter {
|
|
184
|
-
public projectId: string;
|
|
185
|
-
public connector?: WalletConnector;
|
|
186
|
-
public supportedNamespace: ChainNamespace;
|
|
187
|
-
|
|
188
|
-
// Typed emit method
|
|
189
|
-
override emit<K extends keyof AdapterEvents>(
|
|
190
|
-
event: K,
|
|
191
|
-
payload: Parameters<AdapterEvents[K]>[0]
|
|
192
|
-
): boolean {
|
|
193
|
-
return super.emit(event, payload);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
constructor({
|
|
197
|
-
projectId,
|
|
198
|
-
supportedNamespace
|
|
199
|
-
}: {
|
|
200
|
-
projectId: string;
|
|
201
|
-
supportedNamespace: ChainNamespace;
|
|
202
|
-
}) {
|
|
203
|
-
super();
|
|
204
|
-
this.projectId = projectId;
|
|
205
|
-
this.supportedNamespace = supportedNamespace;
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
setConnector(connector: WalletConnector) {
|
|
209
|
-
this.connector = connector;
|
|
210
|
-
this.subscribeToEvents();
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
removeConnector() {
|
|
214
|
-
this.connector = undefined;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
getProvider(): Provider {
|
|
218
|
-
if (!this.connector) throw new Error('No active connector');
|
|
219
|
-
|
|
220
|
-
return this.connector.getProvider();
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
subscribeToEvents(): void {
|
|
224
|
-
const provider = this.connector?.getProvider();
|
|
225
|
-
if (!provider) return;
|
|
226
|
-
|
|
227
|
-
provider.on('chainChanged', this.onChainChanged.bind(this));
|
|
228
|
-
provider.on('accountsChanged', this.onAccountsChanged.bind(this));
|
|
229
|
-
provider.on('disconnect', this.onDisconnect.bind(this));
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
onChainChanged(chainId: string): void {
|
|
233
|
-
const _chains = this.getAccounts()?.map(account => account.split(':')[1]);
|
|
234
|
-
const shouldEmit = _chains?.some(chain => chain === chainId);
|
|
235
|
-
|
|
236
|
-
if (shouldEmit) {
|
|
237
|
-
this.emit('chainChanged', { chainId, namespace: this.getSupportedNamespace() });
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
onAccountsChanged(accounts: string[]): void {
|
|
242
|
-
const _accounts = this.getAccounts();
|
|
243
|
-
const shouldEmit = _accounts?.some(account => {
|
|
244
|
-
const accountAddress = account.split(':')[2];
|
|
245
|
-
|
|
246
|
-
return accountAddress !== undefined && accounts.includes(accountAddress);
|
|
247
|
-
});
|
|
248
|
-
|
|
249
|
-
if (shouldEmit) {
|
|
250
|
-
this.emit('accountsChanged', { accounts, namespace: this.getSupportedNamespace() });
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
onDisconnect(): void {
|
|
255
|
-
this.emit('disconnect', { namespace: this.getSupportedNamespace() });
|
|
256
|
-
|
|
257
|
-
const provider = this.connector?.getProvider();
|
|
258
|
-
if (provider) {
|
|
259
|
-
provider.off('chainChanged', this.onChainChanged.bind(this));
|
|
260
|
-
provider.off('accountsChanged', this.onAccountsChanged.bind(this));
|
|
261
|
-
provider.off('disconnect', this.onDisconnect.bind(this));
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
this.connector = undefined;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
abstract disconnect(): Promise<void>;
|
|
268
|
-
abstract getSupportedNamespace(): ChainNamespace;
|
|
269
|
-
abstract getBalance(params: GetBalanceParams): Promise<GetBalanceResponse>;
|
|
270
|
-
abstract getAccounts(): CaipAddress[] | undefined;
|
|
271
|
-
abstract switchNetwork(network: AppKitNetwork): Promise<void>;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
export abstract class EVMAdapter extends BlockchainAdapter {
|
|
275
|
-
// ens logic
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
export abstract class SolanaBaseAdapter extends BlockchainAdapter {}
|
|
279
|
-
|
|
280
224
|
export interface GetBalanceParams {
|
|
225
|
+
network: AppKitNetwork;
|
|
281
226
|
address?: CaipAddress;
|
|
282
|
-
network?: AppKitNetwork;
|
|
283
227
|
tokens?: Tokens;
|
|
284
228
|
}
|
|
285
229
|
|
|
286
|
-
type
|
|
287
|
-
|
|
288
|
-
export interface GetBalanceResponse {
|
|
289
|
-
amount: string;
|
|
290
|
-
symbol: string;
|
|
291
|
-
contractAddress?: ContractAddress;
|
|
292
|
-
}
|
|
230
|
+
export type GetBalanceResponse = Balance;
|
|
293
231
|
|
|
294
232
|
//********** Connector Types **********//
|
|
295
233
|
interface BaseNamespace {
|
|
@@ -305,33 +243,64 @@ export type Namespaces = Record<string, Namespace>;
|
|
|
305
243
|
|
|
306
244
|
export type ProposalNamespaces = Record<
|
|
307
245
|
string,
|
|
308
|
-
Omit<Namespace, 'accounts'> &
|
|
246
|
+
Omit<Namespace, 'accounts'> &
|
|
247
|
+
Required<Pick<Namespace, 'chains'>> & { rpcMap: Record<string, string> }
|
|
309
248
|
>;
|
|
310
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
|
+
|
|
311
262
|
export abstract class WalletConnector extends EventEmitter {
|
|
312
|
-
public type:
|
|
313
|
-
protected provider
|
|
263
|
+
public type: ConnectorType;
|
|
264
|
+
protected provider?: Provider;
|
|
314
265
|
protected namespaces?: Namespaces;
|
|
315
266
|
protected wallet?: WalletInfo;
|
|
267
|
+
protected storage?: Storage;
|
|
268
|
+
protected metadata?: Metadata;
|
|
269
|
+
protected properties?: ConnectionProperties;
|
|
316
270
|
|
|
317
|
-
constructor({ type
|
|
271
|
+
constructor({ type }: { type: ConnectorType }) {
|
|
318
272
|
super();
|
|
319
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) {
|
|
320
282
|
this.provider = provider;
|
|
321
283
|
}
|
|
322
284
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
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>;
|
|
328
293
|
abstract getProvider(): Provider;
|
|
329
294
|
abstract getNamespaces(): Namespaces;
|
|
330
295
|
abstract getChainId(namespace: ChainNamespace): CaipNetworkId | undefined;
|
|
331
296
|
abstract getWalletInfo(): WalletInfo | undefined;
|
|
297
|
+
abstract getProperties(): ConnectionProperties | undefined;
|
|
332
298
|
abstract switchNetwork(network: AppKitNetwork): Promise<void>;
|
|
299
|
+
abstract restoreSession(): Promise<boolean>;
|
|
333
300
|
}
|
|
334
301
|
|
|
302
|
+
export type ConnectorType = 'walletconnect' | 'coinbase' | 'auth' | 'phantom';
|
|
303
|
+
|
|
335
304
|
//********** Provider Types **********//
|
|
336
305
|
|
|
337
306
|
export interface Provider {
|
|
@@ -351,9 +320,6 @@ export interface RequestArguments {
|
|
|
351
320
|
params?: unknown[] | Record<string, unknown> | object | undefined;
|
|
352
321
|
}
|
|
353
322
|
|
|
354
|
-
//TODO: rename this and remove the old one ConnectorType
|
|
355
|
-
export type New_ConnectorType = 'walletconnect' | 'coinbase' | 'auth';
|
|
356
|
-
|
|
357
323
|
//********** Others **********//
|
|
358
324
|
|
|
359
325
|
export interface ConnectionResponse {
|
|
@@ -375,3 +341,153 @@ export interface WalletInfo {
|
|
|
375
341
|
};
|
|
376
342
|
[key: string]: unknown;
|
|
377
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
|
+
}
|