@reown/appkit-common-react-native 2.0.0-alpha.1 → 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 +3 -1
- package/lib/commonjs/adapters/BlockchainAdapter.js.map +1 -1
- package/lib/commonjs/adapters/EvmAdapter.js +137 -16
- package/lib/commonjs/adapters/EvmAdapter.js.map +1 -1
- package/lib/commonjs/adapters/SolanaBaseAdapter.js +1 -3
- package/lib/commonjs/adapters/SolanaBaseAdapter.js.map +1 -1
- package/lib/commonjs/contracts/erc20.js.map +1 -1
- package/lib/commonjs/contracts/usdt.js.map +1 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/networks/bitcoin.js.map +1 -1
- package/lib/commonjs/networks/solana.js.map +1 -1
- 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 +1 -2
- 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 +10 -2
- package/lib/commonjs/utils/TypeUtil.js.map +1 -1
- package/lib/module/adapters/BlockchainAdapter.js +5 -1
- package/lib/module/adapters/BlockchainAdapter.js.map +1 -1
- package/lib/module/adapters/EvmAdapter.js +140 -16
- package/lib/module/adapters/EvmAdapter.js.map +1 -1
- package/lib/module/adapters/SolanaBaseAdapter.js +3 -3
- package/lib/module/adapters/SolanaBaseAdapter.js.map +1 -1
- 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 +2 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/networks/bitcoin.js +2 -0
- package/lib/module/networks/bitcoin.js.map +1 -1
- package/lib/module/networks/solana.js +2 -0
- package/lib/module/networks/solana.js.map +1 -1
- 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 +2 -0
- 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 +12 -2
- package/lib/module/utils/TypeUtil.js.map +1 -1
- package/lib/typescript/adapters/BlockchainAdapter.d.ts +3 -5
- package/lib/typescript/adapters/BlockchainAdapter.d.ts.map +1 -1
- package/lib/typescript/adapters/EvmAdapter.d.ts +22 -1
- package/lib/typescript/adapters/EvmAdapter.d.ts.map +1 -1
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts +2 -0
- package/lib/typescript/adapters/SolanaBaseAdapter.d.ts.map +1 -1
- 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/utils/ConstantsUtil.d.ts +27 -3
- package/lib/typescript/utils/ConstantsUtil.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 +145 -27
- package/lib/typescript/utils/TypeUtil.d.ts.map +1 -1
- package/package.json +7 -17
- package/src/adapters/BlockchainAdapter.ts +5 -7
- package/src/adapters/EvmAdapter.ts +198 -18
- package/src/adapters/SolanaBaseAdapter.ts +2 -1
- package/src/adapters/__tests__/EvmAdapter.test.ts +126 -0
- package/src/utils/ConstantsUtil.ts +33 -6
- package/src/utils/ErrorUtil.ts +2 -2
- package/src/utils/PresetsUtil.ts +0 -25
- package/src/utils/StringUtil.ts +7 -0
- package/src/utils/TypeUtil.ts +191 -34
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,8 +163,6 @@ export interface Token {
|
|
|
144
163
|
|
|
145
164
|
export type Tokens = Record<CaipNetworkId, Token>;
|
|
146
165
|
|
|
147
|
-
export type ConnectorType = 'WALLET_CONNECT' | 'COINBASE' | 'AUTH' | 'EXTERNAL';
|
|
148
|
-
|
|
149
166
|
export type Metadata = {
|
|
150
167
|
name: string;
|
|
151
168
|
description: string;
|
|
@@ -158,6 +175,28 @@ export type Metadata = {
|
|
|
158
175
|
};
|
|
159
176
|
};
|
|
160
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
|
+
|
|
161
200
|
//********** Adapter Event Payloads **********//
|
|
162
201
|
export type AccountsChangedEvent = {
|
|
163
202
|
accounts: string[];
|
|
@@ -171,11 +210,7 @@ export type DisconnectEvent = {};
|
|
|
171
210
|
|
|
172
211
|
export type BalanceChangedEvent = {
|
|
173
212
|
address: CaipAddress;
|
|
174
|
-
balance:
|
|
175
|
-
amount: string;
|
|
176
|
-
symbol: string;
|
|
177
|
-
contractAddress?: ContractAddress;
|
|
178
|
-
};
|
|
213
|
+
balance: Balance;
|
|
179
214
|
};
|
|
180
215
|
|
|
181
216
|
//********** Adapter Event Map **********//
|
|
@@ -187,18 +222,12 @@ export interface AdapterEvents {
|
|
|
187
222
|
}
|
|
188
223
|
|
|
189
224
|
export interface GetBalanceParams {
|
|
225
|
+
network: AppKitNetwork;
|
|
190
226
|
address?: CaipAddress;
|
|
191
|
-
network?: AppKitNetwork;
|
|
192
227
|
tokens?: Tokens;
|
|
193
228
|
}
|
|
194
229
|
|
|
195
|
-
type
|
|
196
|
-
|
|
197
|
-
export interface GetBalanceResponse {
|
|
198
|
-
amount: string;
|
|
199
|
-
symbol: string;
|
|
200
|
-
contractAddress?: ContractAddress;
|
|
201
|
-
}
|
|
230
|
+
export type GetBalanceResponse = Balance;
|
|
202
231
|
|
|
203
232
|
//********** Connector Types **********//
|
|
204
233
|
interface BaseNamespace {
|
|
@@ -222,6 +251,7 @@ export type ConnectOptions = {
|
|
|
222
251
|
namespaces?: ProposalNamespaces;
|
|
223
252
|
defaultChain?: CaipNetworkId;
|
|
224
253
|
universalLink?: string;
|
|
254
|
+
siweConfig?: AppKitSIWEClient;
|
|
225
255
|
};
|
|
226
256
|
|
|
227
257
|
export type ConnectorInitOptions = {
|
|
@@ -230,14 +260,15 @@ export type ConnectorInitOptions = {
|
|
|
230
260
|
};
|
|
231
261
|
|
|
232
262
|
export abstract class WalletConnector extends EventEmitter {
|
|
233
|
-
public type:
|
|
263
|
+
public type: ConnectorType;
|
|
234
264
|
protected provider?: Provider;
|
|
235
265
|
protected namespaces?: Namespaces;
|
|
236
266
|
protected wallet?: WalletInfo;
|
|
237
267
|
protected storage?: Storage;
|
|
238
268
|
protected metadata?: Metadata;
|
|
269
|
+
protected properties?: ConnectionProperties;
|
|
239
270
|
|
|
240
|
-
constructor({ type }: { type:
|
|
271
|
+
constructor({ type }: { type: ConnectorType }) {
|
|
241
272
|
super();
|
|
242
273
|
this.type = type;
|
|
243
274
|
}
|
|
@@ -251,15 +282,25 @@ export abstract class WalletConnector extends EventEmitter {
|
|
|
251
282
|
this.provider = provider;
|
|
252
283
|
}
|
|
253
284
|
|
|
285
|
+
public async disconnect() {
|
|
286
|
+
await this.provider?.disconnect();
|
|
287
|
+
this.namespaces = undefined;
|
|
288
|
+
this.wallet = undefined;
|
|
289
|
+
this.properties = undefined;
|
|
290
|
+
}
|
|
291
|
+
|
|
254
292
|
abstract connect(opts: ConnectOptions): Promise<Namespaces | undefined>;
|
|
255
|
-
abstract disconnect(): Promise<void>;
|
|
256
293
|
abstract getProvider(): Provider;
|
|
257
294
|
abstract getNamespaces(): Namespaces;
|
|
258
295
|
abstract getChainId(namespace: ChainNamespace): CaipNetworkId | undefined;
|
|
259
296
|
abstract getWalletInfo(): WalletInfo | undefined;
|
|
297
|
+
abstract getProperties(): ConnectionProperties | undefined;
|
|
260
298
|
abstract switchNetwork(network: AppKitNetwork): Promise<void>;
|
|
299
|
+
abstract restoreSession(): Promise<boolean>;
|
|
261
300
|
}
|
|
262
301
|
|
|
302
|
+
export type ConnectorType = 'walletconnect' | 'coinbase' | 'auth' | 'phantom';
|
|
303
|
+
|
|
263
304
|
//********** Provider Types **********//
|
|
264
305
|
|
|
265
306
|
export interface Provider {
|
|
@@ -279,9 +320,6 @@ export interface RequestArguments {
|
|
|
279
320
|
params?: unknown[] | Record<string, unknown> | object | undefined;
|
|
280
321
|
}
|
|
281
322
|
|
|
282
|
-
//TODO: rename this and remove the old one ConnectorType
|
|
283
|
-
export type New_ConnectorType = 'walletconnect' | 'coinbase' | 'auth' | 'phantom';
|
|
284
|
-
|
|
285
323
|
//********** Others **********//
|
|
286
324
|
|
|
287
325
|
export interface ConnectionResponse {
|
|
@@ -304,6 +342,26 @@ export interface WalletInfo {
|
|
|
304
342
|
[key: string]: unknown;
|
|
305
343
|
}
|
|
306
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
|
+
|
|
307
365
|
export interface Storage {
|
|
308
366
|
/**
|
|
309
367
|
* Returns all keys in storage.
|
|
@@ -334,3 +392,102 @@ export interface Storage {
|
|
|
334
392
|
*/
|
|
335
393
|
removeItem(key: string): Promise<void>;
|
|
336
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
|
+
}
|