@privy-io/react-auth 1.25.1 → 1.26.0-beta.10

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/dist/index.d.ts CHANGED
@@ -1,8 +1,7 @@
1
- import React, { ReactElement } from 'react';
1
+ import react, { ReactElement } from 'react';
2
2
  import { ExternalProvider, InfuraProvider, Web3Provider } from '@ethersproject/providers';
3
- import EventEmitter from 'eventemitter3';
4
- import WCProvider from '@walletconnect/web3-provider';
5
3
  import { AbstractProvider } from 'web3-core';
4
+ import EventEmitter from 'eventemitter3';
6
5
  import { AxiosResponse, AxiosRequestConfig } from 'axios';
7
6
 
8
7
  /**
@@ -103,10 +102,223 @@ interface eth_signTransactionResponse {
103
102
  type RpcRequestType = eth_signTransaction | eth_populateTransactionRequest | eth_sign | personal_sign;
104
103
  type RpcResponseType = eth_signTransactionResponse | eth_populateTransactionRequestResponse | eth_signResponse | personal_signResponse;
105
104
 
105
+ type WalletCreateRequestDataType = {
106
+ accessToken: string;
107
+ recoveryPin: string;
108
+ };
109
+ type WalletConnectRequestDataType = {
110
+ accessToken: string;
111
+ address: string;
112
+ };
113
+ type WalletRecoverRequestDataType = {
114
+ accessToken: string;
115
+ address: string;
116
+ recoveryPin: string;
117
+ };
118
+ type WalletRpcRequestDataType = {
119
+ accessToken: string;
120
+ address: string;
121
+ request: RpcRequestType;
122
+ };
123
+ type WalletCreateResponseDataType = {
124
+ address: string;
125
+ };
126
+ type WalletConnectResponseDataType = {
127
+ address: string;
128
+ };
129
+ type WalletRecoverResponseDataType = {
130
+ address: string;
131
+ };
132
+ type WalletRpcResponseDataType = {
133
+ address: string;
134
+ response: RpcResponseType;
135
+ };
136
+ interface EmbeddedWalletProxy {
137
+ create: (data: WalletCreateRequestDataType) => Promise<WalletCreateResponseDataType>;
138
+ connect: (data: WalletConnectRequestDataType) => Promise<WalletConnectResponseDataType>;
139
+ recover: (data: WalletRecoverRequestDataType) => Promise<WalletRecoverResponseDataType>;
140
+ rpc: (data: WalletRpcRequestDataType) => Promise<WalletRpcResponseDataType>;
141
+ }
142
+
143
+ declare global {
144
+ interface Window {
145
+ ethereum?: unknown;
146
+ }
147
+ }
148
+ type EIP1193OnEventHandler = ((accounts: string[]) => void) | ((chainId: string | number) => void);
149
+ interface EIP1193Provider {
150
+ request: (request: {
151
+ method: string;
152
+ params?: Array<any> | undefined;
153
+ }) => Promise<any>;
154
+ on: (eventName: string, listener: EIP1193OnEventHandler) => any;
155
+ removeListener: (eventName: string | symbol, listener: (...args: any[]) => void) => any;
156
+ }
157
+ /**
158
+ * The PrivyProxyProvider adds a middleware layer on top of the underlying wallet provider.
159
+ * @hidden
160
+ * */
161
+ declare class PrivyProxyProvider implements EIP1193Provider {
162
+ walletProvider?: EIP1193Provider;
163
+ private _subscriptions;
164
+ constructor(walletProvider?: EIP1193Provider);
165
+ on(eventName: string, listener: (...args: any[]) => void): any;
166
+ request(request: {
167
+ method: string;
168
+ params?: any[] | undefined;
169
+ }): Promise<any>;
170
+ removeListener: (eventName: string | symbol, listener: (...args: any[]) => void) => any;
171
+ setWalletProvider: (provider: EIP1193Provider) => void;
172
+ }
173
+ interface RequestArguments {
174
+ readonly method: string;
175
+ readonly params?: readonly unknown[] | object;
176
+ }
177
+ declare class Embedded1193Provider extends EventEmitter implements EIP1193Provider {
178
+ walletProxy: EmbeddedWalletProxy;
179
+ address: string;
180
+ infuraProvider: InfuraProvider;
181
+ chainId: number;
182
+ constructor(walletProxy: EmbeddedWalletProxy, address: string, chainId?: number);
183
+ handleSendTransaction(args: RequestArguments): Promise<string>;
184
+ private handleSwitchEthereumChain;
185
+ private handlePersonalSign;
186
+ private handleEstimateGas;
187
+ request(args: RequestArguments): Promise<unknown>;
188
+ connect(): Promise<string | null>;
189
+ }
190
+ /**
191
+ * Shim to convert to ethers-compatible ExternalProvider class.
192
+ * @hidden
193
+ */
194
+ declare class AsExternalProvider extends PrivyProxyProvider implements ExternalProvider {
195
+ constructor(provider: EIP1193Provider);
196
+ isMetaMask?: boolean;
197
+ isStatus?: boolean;
198
+ host?: string;
199
+ path?: string;
200
+ sendAsync?: (request: {
201
+ method: string;
202
+ params?: Array<any>;
203
+ }, callback: (error: any, response: any) => void) => void;
204
+ send?: (request: {
205
+ method: string;
206
+ params?: Array<any>;
207
+ }, callback: (error: any, response: any) => void) => void;
208
+ }
209
+
210
+ interface ConnectorEvents {
211
+ walletsUpdated(): void;
212
+ initialized(): void;
213
+ }
214
+ /**
215
+ * @hidden
216
+ *
217
+ * A WalletConnector is identified by a connectorType and walletClientType. A
218
+ * connectorType includes injected, wallet_connect, etc. A walletClientType
219
+ * includes metamask, trustwallet, etc.
220
+ *
221
+ * Each WalletConnector manages a list of wallets, identified by an address
222
+ * and chainId. Each wallet has a connected property indicating its current
223
+ * connection status, which is determined based on events emitted by the
224
+ * underlying provider.
225
+ *
226
+ * The WalletConnector also emits two events: walletsUpdated and initialized.
227
+ * The walletsUpdated event is triggered when the list of wallets changes,
228
+ * while the initialized event is triggered when the WalletConnector is
229
+ * ready and has successfully executed the syncAccounts() function for
230
+ * the first time.
231
+ */
232
+ declare abstract class WalletConnector extends EventEmitter<ConnectorEvents> {
233
+ connected: boolean;
234
+ initialized: boolean;
235
+ wallets: BaseConnectedWallet[];
236
+ walletClientType: WalletClientType;
237
+ abstract connectorType: ConnectorType;
238
+ abstract proxyProvider: PrivyProxyProvider | Embedded1193Provider;
239
+ constructor(walletClientType: WalletClientType);
240
+ /**
241
+ * Builds a connected wallet object to be exposed to the developer. This object
242
+ * contains the address, chainId, and a few helper methods.
243
+ *
244
+ * Provider methods share the PrivyProxyProvider instance. This means that multiple
245
+ * wallets may share the same provider if one wallet was disconnected and another
246
+ * wallet was connected.
247
+ *
248
+ * A wallet is considered connected if it is present in the wallets array and is
249
+ * in a connected state.
250
+ */
251
+ buildConnectedWallet(address: string, chainId: string): BaseConnectedWallet;
252
+ /**
253
+ * Sync all accounts available via the provider if the wallet is connected.
254
+ */
255
+ syncAccounts(): Promise<void>;
256
+ /**
257
+ * Get the most recently connected wallet.
258
+ */
259
+ getConnectedWallet(): Promise<BaseConnectedWallet | null>;
260
+ /**
261
+ * As a proxy for "connected", we call eth_accounts and consider the client
262
+ * connected if at least one account is returned.
263
+ */
264
+ isConnected(): Promise<boolean>;
265
+ /**
266
+ * Perform personal_sign with the user's wallet.
267
+ *
268
+ * @param {string} message The message to sign.
269
+ * @returns {string} The resulting signature.
270
+ */
271
+ sign(message: string): Promise<string>;
272
+ protected onAccountsChanged: (_: string[]) => void;
273
+ protected onChainChanged: (chainId: string) => void;
274
+ protected onDisconnect: () => void;
275
+ protected onConnect: () => void;
276
+ subscribeListeners(): void;
277
+ unsubscribeListeners(): void;
278
+ abstract get walletBranding(): WalletBranding;
279
+ abstract connect(options: {
280
+ showPrompt?: boolean;
281
+ chainId?: number;
282
+ }): Promise<BaseConnectedWallet | null>;
283
+ abstract disconnect(): void;
284
+ abstract promptConnection(walletClientType: WalletClientType): void;
285
+ }
286
+
106
287
  declare const SUPPORTED_OAUTH_PROVIDERS: readonly ["google", "discord", "twitter", "github", "apple"];
107
288
  type OAuthProviderType = typeof SUPPORTED_OAUTH_PROVIDERS[number];
108
- declare const SUPPORTED_WALLET_CONNECTION_TYPES: readonly ["metamask", "phantom", "coinbase_wallet", "wallet_connect", "embedded"];
109
- type WalletType = typeof SUPPORTED_WALLET_CONNECTION_TYPES[number];
289
+ /** @hidden */
290
+ type EmbeddedWalletClientType = 'privy';
291
+ /** @hidden */
292
+ type InjectedWalletClientType = 'metamask' | 'phantom';
293
+ /** @hidden */
294
+ type CoinbaseWalletClientType = 'coinbase_wallet';
295
+ /** @hidden
296
+ *
297
+ * How this works:
298
+ *
299
+ * The raw data is pulled from https://registry.walletconnect.com/api/v2/wallets
300
+ * Some post-processing is done using the following script.
301
+ *
302
+ * const axios = require('axios');
303
+ * const walletTypes = [];
304
+ * axios.get("https://registry.walletconnect.com/api/v2/wallets").then((apiResult) => {
305
+ * Object.values(apiResult.data.listings).forEach((walletEntry) => {
306
+ * if (!walletEntry.mobile.native || !walletEntry.mobile.universal) return;
307
+ * if (!walletEntry.chains.includes('eip155:1')) return;
308
+ * if (!walletEntry.metadata.shortName) return;
309
+ * // Manually removed for cleanliness
310
+ * if (walletEntry.id === 'b2ce31fb31735fa886270806340de999f72342a7c29484badd8d4d013d77c8b8') return;
311
+ * if (walletEntry.id) walletTypes.push(`'${walletEntry.id}'`);
312
+ * });
313
+ * console.log(walletTypes.join("\n | "));
314
+ * });
315
+ */
316
+ type WalletConnectWalletClientType = 'rainbow' | 'trust' | 'uniswap' | 'metamask' | 'argent' | 'spot' | 'zerion' | 'bitkeep' | 'unstoppable' | 'omni' | 'mathwallet' | 'bitpay' | '1inch' | 'eidoo' | 'coin98' | 'unstoppable' | 'alphawallet' | 'rwallet' | 'plasmapay' | 'o3wallet' | 'hashkey_me' | 'defiant' | 'essentials' | 'stasis' | 'julwallet' | 'tangem' | 'secux' | 'linen' | 'ambire' | 'obvious' | 'easypocket' | 'rice_wallet' | 'safemoon' | 'simplehold' | 'bitizen' | 'slavi_wallet' | 'nufinetes' | 'now_wallet' | 'blocto' | 'timeless' | 'arculus_wallet' | 'card' | 'mew_wallet' | 'pltwallet' | 'avacus' | 'bitski' | 'hippowallet' | 'edge' | 'assure' | 'enjin_wallet' | 'slingshot' | 'coinstats' | 'bitcoincom_wallet' | 'defiant' | 'binance';
317
+ /** @hidden */
318
+ type UnknownWalletClientType = 'unknown';
319
+ type WalletClientType = InjectedWalletClientType | CoinbaseWalletClientType | WalletConnectWalletClientType | EmbeddedWalletClientType | UnknownWalletClientType;
320
+ declare const SUPPORTED_CONNECTOR_TYPES: string[];
321
+ type ConnectorType = typeof SUPPORTED_CONNECTOR_TYPES[number];
110
322
  /**
111
323
  * Wallet metadata currently for internal use only
112
324
  */
@@ -134,9 +346,6 @@ interface Wallet {
134
346
  * @experimental
135
347
  * DO NOT USE: This feature is under active development.
136
348
  *
137
- * The chain ID of the active connected wallet, if used to verify in the current session.
138
- * Only present for the active wallet.
139
- *
140
349
  * e.g. testnet, mainnet, goerli */
141
350
  chainId?: string;
142
351
  /**
@@ -152,6 +361,69 @@ interface Wallet {
152
361
  */
153
362
  walletClient: 'privy' | 'unknown';
154
363
  }
364
+ /**
365
+ * Object representation of a base connected wallet from a wallet connector.
366
+ */
367
+ interface BaseConnectedWallet {
368
+ /** The wallet address. */
369
+ address: string;
370
+ /** The current chain ID with CAIP-2 formatting. */
371
+ chainId: string;
372
+ /** The first time this wallet was connected without break. */
373
+ connectedAt: number;
374
+ /**
375
+ * @experimental **Experimental**: This property is {@link https://docs.privy.io/guide/guides/experimental-features subject to change at any time}.
376
+ *
377
+ * The wallet client where this key-pair is stored.
378
+ * e.g. metamask, rainbow, coinbase_wallet, etc.
379
+ */
380
+ walletClientType: WalletClientType;
381
+ /**
382
+ * @experimental **Experimental**: This property is {@link https://docs.privy.io/guide/guides/experimental-features subject to change at any time}.
383
+ *
384
+ * The connector used to initiate the connection with the wallet client.
385
+ * e.g. injected, wallet_connect, coinbase_wallet, etc.
386
+ */
387
+ connectorType: ConnectorType;
388
+ /** Returns true if the wallet is connected, false otherwise */
389
+ isConnected: () => Promise<boolean>;
390
+ /** Helper methods to build providers for interfacing with this wallet. */
391
+ getEthereumProvider: () => Promise<EIP1193Provider>;
392
+ getEthersProvider: () => Promise<Web3Provider>;
393
+ getWeb3jsProvider: () => Promise<AbstractProvider>;
394
+ /**
395
+ * Perform personal_sign with the user's wallet.
396
+ *
397
+ * @param {string} message The message to sign.
398
+ * @returns {string} The resulting signature.
399
+ */
400
+ sign: (message: string) => Promise<string>;
401
+ /**
402
+ * @experimental **Experimental**: This property is {@link https://docs.privy.io/guide/guides/experimental-features subject to change at any time}.
403
+ *
404
+ * Disconnect method does not work on all connector types and will no-op if
405
+ * an incompatible connector is used (metamask and phantom do not support
406
+ * programmatic disconnects)
407
+ */
408
+ disconnect: () => void;
409
+ }
410
+ /**
411
+ * Object representation of a connected wallet.
412
+ */
413
+ interface ConnectedWallet extends BaseConnectedWallet {
414
+ /** True if this wallet is linked to the authenticated user. False if it is not yet linked or
415
+ * the user has not yet authenticated. */
416
+ linked: boolean;
417
+ /** Link this wallet to the authenticated user. Throws a PrivyClientError if the user is not
418
+ * authenticated or if the wallet is not connected. */
419
+ link: () => Promise<void>;
420
+ /** Unlink this wallet to the authenticated user. Throws a PrivyClientError if the user is not
421
+ * authenticated. */
422
+ unlink: () => Promise<void>;
423
+ /** Login with this wallet. Throws a PrivyClientError if the user is already authenticated or
424
+ * the wallet is not connected. */
425
+ login: () => Promise<void>;
426
+ }
155
427
  /** Object representation of a user's email. */
156
428
  interface Email {
157
429
  /** The email address. */
@@ -261,10 +533,9 @@ interface User {
261
533
  email?: Email;
262
534
  /** The user's phone number, if they have linked one. It cannot be linked to another user. */
263
535
  phone?: Phone;
264
- /** The user's active wallet address, if they have linked at least one wallet. It cannot be linked to another user.
265
- * If a user links a new wallet, that one is automatically set as active.
266
- * Developers can call setActiveWallet() to change the active wallet.
267
- * The active wallet is the wallet that will be used for transactions and signing.
536
+ /** The user's most recently linked wallet, if they have linked at least one wallet.
537
+ * It cannot be linked to another user.
538
+ * This wallet is the wallet that will be used for transactions and signing if it is connected.
268
539
  **/
269
540
  wallet?: Wallet;
270
541
  /** The user's Google account, if they have linked one. It cannot be linked to another user. */
@@ -440,7 +711,7 @@ interface PrivyProviderProps {
440
711
  * @ignore
441
712
  * @class
442
713
  */
443
- children: React.ReactNode;
714
+ children: react.ReactNode;
444
715
  }
445
716
  /**
446
717
  * Passes the Privy authentication context to your React components.
@@ -459,282 +730,89 @@ interface PrivyProviderProps {
459
730
  */
460
731
  declare const PrivyProvider: (props: PrivyProviderProps) => JSX.Element;
461
732
 
462
- type WalletCreateRequestDataType = {
463
- accessToken: string;
464
- recoveryPin: string;
465
- };
466
- type WalletConnectRequestDataType = {
467
- accessToken: string;
468
- address: string;
469
- };
470
- type WalletRecoverRequestDataType = {
471
- accessToken: string;
472
- address: string;
473
- recoveryPin: string;
474
- };
475
- type WalletRpcRequestDataType = {
476
- accessToken: string;
477
- address: string;
478
- request: RpcRequestType;
479
- };
480
- type WalletCreateResponseDataType = {
481
- address: string;
482
- };
483
- type WalletConnectResponseDataType = {
484
- address: string;
485
- };
486
- type WalletRecoverResponseDataType = {
487
- address: string;
488
- };
489
- type WalletRpcResponseDataType = {
490
- address: string;
491
- response: RpcResponseType;
492
- };
493
- interface EmbeddedWalletProxy {
494
- create: (data: WalletCreateRequestDataType) => Promise<WalletCreateResponseDataType>;
495
- connect: (data: WalletConnectRequestDataType) => Promise<WalletConnectResponseDataType>;
496
- recover: (data: WalletRecoverRequestDataType) => Promise<WalletRecoverResponseDataType>;
497
- rpc: (data: WalletRpcRequestDataType) => Promise<WalletRpcResponseDataType>;
498
- }
499
-
500
- declare global {
501
- interface Window {
502
- ethereum?: any;
503
- }
504
- }
505
- interface EIP1193Provider {
506
- request: (request: {
507
- method: string;
508
- params?: Array<any> | undefined;
509
- }) => Promise<any>;
510
- on: (eventName: string, listener: (...args: unknown[]) => void) => any;
511
- removeListener: (eventName: string | symbol, listener: (...args: any[]) => void) => any;
512
- }
513
- /**
514
- * The PrivyProxyProvider adds a middleware layer on top of the underlying wallet provider.
515
- * @hidden
516
- * */
517
- declare class PrivyProxyProvider implements EIP1193Provider {
518
- walletProvider?: EIP1193Provider;
519
- private _subscriptions;
520
- constructor(walletProvider?: EIP1193Provider);
521
- on(eventName: string, listener: (...args: any[]) => void): any;
522
- request(request: {
523
- method: string;
524
- params?: any[] | undefined;
525
- }): Promise<any>;
526
- removeListener: (eventName: string | symbol, listener: (...args: any[]) => void) => any;
527
- setWalletProvider: (provider: EIP1193Provider) => void;
528
- }
529
- interface RequestArguments {
530
- readonly method: string;
531
- readonly params?: readonly unknown[] | object;
532
- }
533
- declare class Embedded1193Provider extends EventEmitter implements EIP1193Provider {
534
- walletProxy: EmbeddedWalletProxy;
535
- address: string;
536
- infuraProvider: InfuraProvider;
537
- chainId: number;
538
- constructor(walletProxy: EmbeddedWalletProxy, address: string, chainId?: number);
539
- handleSendTransaction(args: RequestArguments): Promise<string>;
540
- private handleSwitchEthereumChain;
541
- private handlePersonalSign;
542
- private handleEstimateGas;
543
- request(args: RequestArguments): Promise<unknown>;
544
- connect(): Promise<string | null>;
733
+ interface ConnectorManagerEvents {
734
+ walletsUpdated(): void;
545
735
  }
546
- /**
547
- * Shim to convert to ethers-compatible ExternalProvider class.
548
- * @hidden
549
- */
550
- declare class AsExternalProvider extends PrivyProxyProvider implements ExternalProvider {
551
- constructor(provider: EIP1193Provider);
552
- isMetaMask?: boolean;
553
- isStatus?: boolean;
554
- host?: string;
555
- path?: string;
556
- sendAsync?: (request: {
557
- method: string;
558
- params?: Array<any>;
559
- }, callback: (error: any, response: any) => void) => void;
560
- send?: (request: {
561
- method: string;
562
- params?: Array<any>;
563
- }, callback: (error: any, response: any) => void) => void;
564
- }
565
-
566
736
  /** @hidden */
567
- declare abstract class WalletConnector {
568
- proxyProvider: PrivyProxyProvider | Embedded1193Provider;
569
- walletType: WalletType;
570
- connected: boolean;
571
- address: string | null;
572
- chain: string | null;
573
- constructor(walletType: WalletType, proxyProvider: PrivyProxyProvider | Embedded1193Provider, address: string | null);
574
- fetchAddress(): Promise<string | null>;
575
- fetchChainId(): Promise<string>;
576
- getConnectedWallet(): Promise<Wallet | null>;
577
- abstract get walletBranding(): WalletBranding;
578
- abstract connect(options: {
579
- showPrompt: boolean;
580
- chainId?: number;
581
- }): Promise<Wallet | null>;
582
- abstract disconnect(): void;
583
- abstract isConnected(): Promise<boolean>;
584
- abstract promptConnection(walletType: WalletType): void;
585
- setActive(): Promise<boolean>;
737
+ declare class ConnectorManager extends EventEmitter<ConnectorManagerEvents> {
738
+ walletConnectors: WalletConnector[];
739
+ initialized: boolean;
740
+ private storedConnections;
741
+ private activeWallet?;
742
+ constructor();
586
743
  /**
587
- * Perform personal_sign with the user's wallet.
744
+ * The core wallets array that is exposed to developers. It builds
745
+ * the wallets away with the following logic:
588
746
  *
589
- * @param {string} message The message to sign.
590
- * @returns {string} The resulting signature.
591
- */
592
- sign(message: string): Promise<string>;
593
- }
594
-
595
- /**
596
- * Types aren't included in the final distribution, so we can have the duplicates here to assure
597
- * type-safety
598
- */
599
- type WalletId = '1ae92b26df02f0abca6304df07debccd18262fdf5fe82daa81593582dac9a369' | '4622a2b2d6af1c9844944291e5e7351a6aa24cd7b23099efac1b2fd875da31a0' | 'c57ca95b47569778a828d19178114f4db188b89b763c899ba0be274e97267d96' | '225affb176778569276e484e1b92637ad061b01e13a048b35a9d280c3b58970f' | '74f8092562bd79675e276d8b2062a83601a4106d30202f2d509195e30e19673d' | 'ecc4036f814562b41a5268adc86270fba1365471402006302e70169465b7ac18' | '8308656f4548bb81b3508afe355cfbb7f0cb6253d1cc7f998080601f838ecee3' | '38f5d18bd8522c244bdd70cb4a68e0e718865155811c043f052fb9f1c51de662' | 'afbd95522f4041c71dd4f1a065f971fd32372865b416f95a0b1db759ae33f2a7' | 'ccb714920401f7d008dbe11281ae70e3a4bfb621763b187b9e4a3ce1ab8faa3b' | '7674bb4e353bf52886768a3ddc2a4562ce2f4191c80831291218ebd90f5f5e26' | '2863183c3299d820fb9a4cb8aab4a34f50380c9992e8be871fd60a62e8d36481' | 'efba9ae0a9e0fdd9e3e055ddf3c8e75f294babb8aea3499456eff27f771fda61' | 'b021913ba555948a1c81eb3d89b372be46f8354e926679de648e4fa2938bed3e' | '7e90b95230bc462869bbb59f952273d89841e1c76bcc5319898e08c9f34bd4cd' | '138f51c8d00ac7b9ac9d8dc75344d096a7dfe370a568aa167eabc0a21830ed98' | '468b4ab3582757233017ec10735863489104515ab160c053074905a1eecb7e63' | '29f4a70ad5993f3f73ae8119f0e78ecbae51deec2a021a770225c644935c0f09' | '8240fb8a7b117aed27f04aa8870c714eeb910f7c1b16c9b868e793c1836335b8' | '15d7610042217f691385d20e640869dc7273e991b04e8f476417cdc5ec856955' | 'a395dbfc92b5519cbd1cc6937a4e79830187daaeb2c6fcdf9b9cce4255f2dcd5' | '0b415a746fb9ee99cce155c2ceca0c6f6061b1dbca2d722b3ba16381d0562150' | '881946407ff22a32ec0e42b2cd31ea5dab52242dc3648d777b511a0440d59efb' | '3b0e861b3a57e98325b82ab687fe0a712c81366d521ceec49eebc35591f1b5d1' | '38ee551a01e3c5af9d8a9715768861e4d642e2381a62245083f96672b5646c6b' | 'f2436c67184f158d1beda5df53298ee84abfc367581e4505134b5bcf5f46697d' | '15d1d97de89526a3c259a235304a7c510c40cda3331f0f8433da860ecc528bef' | '19ad8334f0f034f4176a95722b5746b539b47b37ce17a5abde4755956d05d44c' | '95501c1a07c8eb575cb28c753ab9044259546ebcefcd3645461086e49b671f5c' | '2ed796df33fdbde6a3ea6a47d3636b8341fe285038d844c7a78267b465b27028' | '4e6af4201658b52daad51a279bb363a08b3927e74c0f27abeca3b0110bddf0a9' | 'b13fcc7e3500a4580c9a5341ed64c49c17d7f864497881048eb160c089be5346' | '13c6a06b733edf51784f669f508826b2ab0dc80122a8b5d25d84b17d94bbdf70' | '0aafbedfb8eb56dae59ecc37c9a5388509cf9c082635e3f752581cc7128a17c0' | '761d3d98fd77bdb06e6c90092ee7071c6001e93401d05dcf2b007c1a6c9c222c' | 'ffa139f74d1c8ebbb748cf0166f92d886e8c81b521c2193aa940e00626f4e215' | '717911f4db0c5eda0e02e76ed179b7940ba1eefffdfb3c9e6540696226860da0' | '9d6c614d1995741d5313f1f3dbf1f66dcba694de782087d13b8721822502692f' | 'a6ffb821a3c32d36fc9d29e29c2ff79a0cd1db0bca453714777846ddf3fdff76' | '76745388a50e6fea982c4dee2a3ad61a8aa417668be870754689caa8a7506c93' | '6464873279d46030c0b6b005b33da6be5ed57a752be3ef1f857dc10eaf8028aa' | '2c81da3add65899baeac53758a07e652eea46dbb5195b8074772c62a77bbf568' | 'b823fb0d7228ef8e3c0bc9607df9ed79dae2ab3a2811d33f22ade4f573c18232' | 'dccbd717df77b395445cc6080e01fffada9d8b92dacfda312a26c70c2e9af673' | 'c6f3d04a4e1a51e7d2045f347a5ebdab30fc600950a740fca21f0c92e230ee05' | 'c482dfe368d4f004479977fd88e80dc9e81107f3245d706811581a6dfe69c534' | '14e7176536cb3706e221daaa3cfd7b88b7da8c7dfb64d1d241044164802c6bdd' | '0e4915107da5b3408b38e248f7a710f4529d54cd30e9d12ff0eb886d45c18e92' | 'a2c031fccd13a6c16d7745c303507f78ae4da53fed064542804e9657d73e8b5c' | 'f593f4eb9755ff047681a37ebc46706e0e915cf1c2fe0102f5ae47c9f6aa4082' | '5859076ade608fbc4e9d3fe2f95e8527de80f8451ecbb1dced54ca84deae0dd6' | 'bb88a220ed4dcd3d717ec19b6ac00a672edf92e97ef7c243d35e25ff56a07301' | 'cbe13eb482c76f1fa401ff4c84d9acd0b8bc9af311ca0620a0b192fb28359b4e' | 'b83a346877b71c02b8531f53485ce12bc00033eabcc1213ca3329cbc744813a5' | 'a92d512c649e87a5acba5885ac03f62662cff1f647c20a63833eb45a71a6f877' | '226d8a12a2e6e5c4185fa9c24313824bfb144c2a180325bddbd121844f497afa' | '11c5487e4d8dd8bf32d4c92222363df8296a27307b2531be1e25770365392ecb' | 'f5b4eeb6015d66be3f5940a895cbaa49ef3439e518cd771270e6b553b48f31d2' | '576c90ceaea34f29ff0104837cf2b2e23d201be43be1433feeb18d375430e1fd' | '94f785c0c8fb8c4f38cd9cd704416430bcaa2137f27e1468782d624bcd155a43' | 'bc949c5d968ae81310268bf9193f9c9fb7bb4e1283e1284af8f2bd4992535fd6' | '664b505fea4c2117b8a55c054ef209664e0a68ddaafd7534df739f97a293fa1d' | '0c5bba82e70a2b62405871af809020a077d110d765c0798eb660ad5d3131b328' | '792fbacfe787d67595dd4eb38ac308e14b3bbc810393db56f477a92e5ac8764b' | '7ef337ff00714f179d38b8142398efa2ab902a53430e99ebce02892053d7a310' | '7e94e75c90964a69ea375b92214f50c4223dfbfa4913a3733b615444b322f687' | '107bb20463699c4e614d3a2fb7b961e66f48774cb8f6d6c1aee789853280972c' | '1986e7c874bb906f057d5d64a4806c004e021689536e5228c74d64a6058e8bac' | '19418ecfd44963883e4d6abca1adeb2036f3b5ffb9bee0ec61f267a9641f878b' | '37a686ab6223cd42e2886ed6e5477fce100a4fb565dcd57ed4f81f7c12e93053' | '4f5de5333fed2ccf47c690579aba3b9128aea78175339ff51ef61704bde7502a' | '9034d54985807aaf3d7780f50f155f954daa468fb58d7b14b216fc79d68bbd14' | 'c39d8ee468e50474fdf3a0bd6b981be404d4671e2702a3d633aae95bcbaa032a' | 'e9ff15be73584489ca4a66f64d32c4537711797e30b6660dbcb71ea72a42b1f4' | '114efdbef4ce710081c1507f3dbc51f439c96a342cf33397799cd1c84b01a8c5' | '5b8e33346dfb2a532748c247876db8d596734da8977905a27b947ba1e2cf465b' | '2cca8c1b0bea04ba37dee4017991d348cdb7b826804ab2bd31073254f345b715' | 'e3787ea98d014ca77e2c3794db97c02ef8bcb39347705f5e79502a55434a1ecf' | '159b0423ce9075d5662f588f805931d989627affab3e63e4dd7ebc62b9c6738c' | 'fbea6f68df4e6ce163c144df86da89f24cb244f19b53903e26aea9ab7de6393c' | '1aedbcfc1f31aade56ca34c38b0a1607b41cccfa3de93c946ef3b4ba2dfab11c' | '14e5d957c6eb62d3ee8fc6239703ac2d537d7e3552154836ca0beef775f630bc' | '031f0187049b7f96c6f039d1c9c8138ff7a17fd75d38b34350c7182232cc29aa' | 'c40b9bcef32fa6ce4e0df98be1420628bbc4957646f742380fe618fcb4ab74f1' | 'b265ce38b94d602957a0946673c59a99a15d69adda4317544fec7298ea2d1387' | 'dc5415b6ea8114db518ae91195b027d690a11a1d2bfdd1a904e93c5cb746380e' | '41f20106359ff63cf732adf1f7dc1a157176c9b02fd266b50da6dcc1e9b86071';
600
-
601
- /**
602
- * Light wrapper around WCConnectionManager that uses the global connection manager
603
- * to manage the local storage layer and avoid conflicts.
604
- * There can be multiple WCWalletConnectors, but should only ever be a single
605
- * WCConnectionManager, which should be the class referenced - it will in turn find
606
- * the appropriate WCWalletConnector for use with an action.
607
- */
608
- declare class WCWalletConnector extends WalletConnector {
609
- private connectionManager;
610
- proxyProvider: PrivyProxyProvider;
611
- constructor(connectionManager: WCConnectionManager, proxyProvider: PrivyProxyProvider, address: string | null);
612
- setActive(): Promise<boolean>;
613
- connect(options: {
614
- showPrompt: boolean;
615
- }): Promise<Wallet | null>;
616
- isConnected(): Promise<boolean>;
617
- /**
618
- * Metadata about the wallet represented by this connector.
747
+ * 1. Flatten all wallets from all connectors
748
+ * 2. Sorted by connectedAT
749
+ * 3. Active wallet is moved to front of array (if it exists)
619
750
  */
620
- get walletBranding(): {
621
- name: string;
622
- icon: string | EmbeddedSVG;
623
- };
624
- promptConnection(): Promise<void>;
751
+ get wallets(): BaseConnectedWallet[];
625
752
  /**
626
- * Perform personal_sign with the user's first wallet associated with WalletConnect
753
+ * Detect and add all valid wallet connectors.
627
754
  */
628
- sign(message: string): Promise<string>;
629
- disconnect(): void;
755
+ initialize(): void;
630
756
  /**
631
- * Access the underlying WCProvider directly with proper typings
757
+ * Restore previous Wallet Connect connections that have been stored in local storage.
632
758
  */
633
- private get walletProvider();
759
+ restoreWalletConnectConnectors(): void;
634
760
  /**
635
- * Set the underlying WCProvider with proper typings
761
+ * Helper function to find a wallet connector by connector type and wallet client type.
636
762
  */
637
- setWalletProvider(walletProvider: WCProvider): void;
638
- }
639
- /**
640
- * An object representation of the Wallet Connect V1 protocol. This is used to initiate and manage connections
641
- * with any number of wallets.
642
- */
643
- declare class WCConnectionManager {
644
- private _storageIdToProvider;
645
- private reconnectDelayMs;
646
- private reconnectBackoff;
647
- constructor();
763
+ findWalletConnector(connectorType: ConnectorType, walletClientType: WalletClientType): WalletConnector | null;
648
764
  /**
649
- * Builds a new WCWalletConnector instance
650
- *
651
- * If walletId is specified, attempts to launch into that specific flow.
652
- *
653
- * IMPORTANT! Nothing in this flow can be costly in order to properly launch our deep links. See:
654
- * https://docs.walletconnect.com/1.0/mobile-linking#ios-app-link-constraints
765
+ * Add any connectedAt overrides for newly initialized wallets and pass-through change events.
655
766
  */
656
- createConnector(proxyProvider: PrivyProxyProvider, address: string | null,
767
+ private onInitialized;
657
768
  /**
658
- * If provided, the connector will attempt to establish a connection directly using this
659
- * wallet. If omitted, but an address is provided, the connector may still attempt to link
660
- * up to a wallet, but may be unable to. If a wallet cannot be determined, the standard WC
661
- * modal is shown.
769
+ * Save connection history and pass-through change events.
662
770
  */
663
- walletId?: WalletId): WCWalletConnector;
771
+ private onWalletsUpdated;
772
+ addEmbeddedWalletConnector(walletProxy: EmbeddedWalletProxy, address: string): void;
664
773
  /**
665
- * Disconnects all active Wallet Connect sessions.
774
+ * Normally, we do not remove connectors after creation. Privy embedded wallets are an exception
775
+ * because they are closely tied with an authenticated state.
666
776
  */
667
- disconnect(): Promise<void>;
777
+ removeEmbeddedWalletConnector(): void;
668
778
  /**
669
- * Fetch a storage id for an address/walletId pair. If we don't match exactly, we still
670
- * attempt to discover if any legacy keys were matched using instant launch methods (currently)
671
- * just metamask and reuse if that. Admittedly, this method feels very fragile and unknown.
779
+ * Creates a new wallet connector for the given connector type and wallet client type.
780
+ * If a connector already exists, it will be returned instead.
672
781
  */
673
- private getStorageId;
782
+ createWalletConnector(connectorType: ConnectorType, walletClientType: WalletClientType): WalletConnector | null;
783
+ private addWalletConnector;
674
784
  /**
675
- * Given an address, either fetch (reusing a stored connection) or create a new one if no stored
676
- * connection is found
785
+ * Upon initialization, loads previous connections from local storage. If local storage
786
+ * is misformatted (e.g. due to previous privy:connectors usage), it returns an empty array that
787
+ * will be overwritten later.
788
+ *
789
+ * @returns StoredConnection[] list of stored connections from previous session
677
790
  */
678
- getProviderForAddress(address: string | null, walletId: WalletId | undefined): WCProvider | undefined;
679
- private createProviderWithStorageId;
791
+ private loadConnectionHistory;
680
792
  /**
681
- * Create a WC provider and add an entry to the internal provider registry keyed on the internal
682
- * WC storageId. If walletId is specified, attempts to launch the WC flow for that particular
683
- * wallet
793
+ * Saves all current connections to local storage overridding any previous connections.
684
794
  */
685
- createProvider(connector: WCWalletConnector, walletId?: WalletId): WCProvider;
795
+ private saveConnectionHistory;
686
796
  /**
687
- * Replace the given provider, *assuming it's the one with null address*
797
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
798
+ * interfacing with wallets directly (wallets[0].getEthereumProvider()).
688
799
  *
689
- * Couldn't find any WC docs, but a reference implementation library had a similar error we were
690
- * seeing - WC sessions wouldn't open a new modal/etc when doing `provider.enable()` if it had
691
- * previously been rejected: https://github.com/Uniswap/web3-react/issues/217
800
+ * Build an Ethereum provider for the most recently connected wallet.
692
801
  */
693
- replaceProvider(connector: WCWalletConnector, provider: WCProvider): WCProvider;
694
- /**
695
- * Enables the provider. Under the hood, this calls connect() and 'eth_RequestAccounts'.
696
- */
697
- enableProvider(provider: WCProvider): Promise<string[]>;
698
- }
699
-
700
- /** @hidden */
701
- declare class ConnectorManager {
702
- walletConnectors: WalletConnector[];
703
- activeWalletConnector?: WalletConnector;
704
- initialized: boolean;
705
- wcConnectionManager: WCConnectionManager;
706
- constructor();
707
- initialize(): void;
708
802
  getEthereumProvider: () => EIP1193Provider;
709
803
  /**
710
- * Load state from the server user object (linked wallets).
711
- * Currently, we can't load them because we don't know the wallet type.
712
- * Once we've fixed this, we can load the wallets from the server and
713
- * initialize their WalletConnector objects accordingly.
714
- **/
715
- initializeLinkedWallets(user: User): void;
716
- /** Load the state from storage and hydrate the instance with WalletConnectors. */
717
- load(): void;
718
- /** Persist the instance state to storage to reload the connectors later. */
719
- save(): void;
720
- addEmbeddedWalletConnector(walletProxy: EmbeddedWalletProxy, address: string): void;
721
- addWalletConnector(walletConnector: WalletConnector): void;
722
- getConnectorByAddress(address: string): WalletConnector | undefined;
723
- removeWallet(address: string): Promise<void>;
724
- /**
725
- * Performing personal_sign with the active wallet
726
- * If the active wallet is not connected, we connect it in just-in-time" fashion.
804
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
805
+ * interfacing with `wallets` directly.
806
+ *
807
+ * Performing personal_sign with the most recently connected wallet.
808
+ * If there is not a wallet connected, return null.
727
809
  */
728
810
  activeWalletSign(message: string): Promise<string | null>;
729
811
  /**
730
- * Set a wallet as active, by passing the address.
731
- * If the address is null or not found, do nothing and return false.
732
- * If the connector was successfully found and set active, return true.
812
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
813
+ * interfacing with `wallets` directly.
733
814
  */
734
- setActiveWallet(address: string | null): Promise<boolean>;
735
- createWalletConnector(walletType: WalletType, address: string | null,
736
- /** Only applicable for WalletConnect right now */
737
- walletId?: WalletId): WalletConnector;
815
+ setActiveWallet(address: string): void;
738
816
  }
739
817
 
740
818
  /**
@@ -759,6 +837,10 @@ interface PrivyInterface {
759
837
  * The user object, or null if the user is not authenticated.
760
838
  */
761
839
  user: User | null;
840
+ /**
841
+ * Opens the Privy modal and prompts the user to connect a wallet.
842
+ */
843
+ connectWallet: () => void;
762
844
  /**
763
845
  * Opens the Privy login modal and prompts the user to login.
764
846
  */
@@ -818,22 +900,33 @@ interface PrivyInterface {
818
900
  */
819
901
  getAccessToken: () => Promise<string | null>;
820
902
  /**
903
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
904
+ * interfacing with wallets directly (wallets[0].getEthereumProvider()).
905
+ *
821
906
  * Get an [EIP-1193](https://eips.ethereum.org/EIPS/eip-1193)-compatible provider from the user's wallet, if the user has connected one.
822
907
  *
823
908
  * You may then use the Ethereum Javascript API syntax to send JSON-RPC requests to the user's wallet.
824
909
  */
825
910
  getEthereumProvider: () => EIP1193Provider;
826
911
  /**
912
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
913
+ * interfacing with wallets directly (wallets[0].getEthersProvider()).
827
914
  *
828
915
  * Get an [ethers.js](https://docs.ethers.io/v5/)-compatible provider from the user's wallet, if the user has connected one.
829
916
  *
830
917
  */
831
918
  getEthersProvider: () => Web3Provider;
832
919
  /**
920
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
921
+ * interfacing with wallets directly (wallets[0].getWeb3jsProvider()).
922
+ *
833
923
  * Get a [web3.js](https://web3js.readthedocs.io/en/v1.8.0/)-compatible provider from the user's wallet, if the user has connected one.
834
924
  */
835
925
  getWeb3jsProvider: () => AbstractProvider;
836
926
  /**
927
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by the
928
+ * `useWallet` hook.
929
+ *
837
930
  * Get the ConnectorManager object
838
931
  * This shouldn't need to be used directly unless creating a plugin, like a WAGMI plugin
839
932
  */
@@ -872,24 +965,20 @@ interface PrivyInterface {
872
965
  */
873
966
  unlinkApple: (subject: string) => Promise<User>;
874
967
  /**
875
- * Set one of the authenticated wallet addresses (part of user.linkedAccounts with type 'wallet'). as the active wallet.
876
- * If you pass a wallet that's not one of the linkedAccounts, this will throw an error.
877
- * This will prompt the user to reconnect their wallet if the connection is lost.
968
+ * @deprecated **Deprecated**: This feature will be removed and behaves the same as connectWallet(). Instead, please
969
+ * interact with the wallets array directly.
878
970
  *
879
- * The active wallet will be the one that getEthersProvider() will use as a signer (used for signing & transactions).
880
- * It is also the wallet present at `user.wallet`, and that value is updated when this is called.
881
- *
882
- * Note that when you link a new wallet, it becomes active.
971
+ * Note that when you connect a new wallet, it becomes first in the wallets array.
883
972
  */
884
973
  setActiveWallet: (address: string) => Promise<void>;
885
974
  /**
886
- * @experimental **Experimental**: This feature is {@link https://docs.privy.io/guide/faq/experimental-features subject to change at any time}.
975
+ * @experimental **Experimental**: This feature is {@link https://docs.privy.io/guide/guides/experimental-features subject to change at any time}.
887
976
  *
888
977
  * Get a short-lived, one-time-use token to start a new Privy session from the existing authenticated session. Raises an exception if the current session was already forked from a previous session.
889
978
  */
890
979
  forkSession: () => Promise<string>;
891
980
  /**
892
- * @experimental **Experimental**: This feature is {@link https://docs.privy.io/guide/faq/experimental-features subject to change at any time}.
981
+ * @experimental **Experimental**: This feature is {@link https://docs.privy.io/guide/guides/experimental-features subject to change at any time}.
893
982
  *
894
983
  * Prompts a user to create an Ethereum wallet through Privy.
895
984
  *
@@ -901,7 +990,7 @@ interface PrivyInterface {
901
990
  */
902
991
  createWallet: () => Promise<Wallet>;
903
992
  /**
904
- * @experimental **Experimental**: This feature is {@link https://docs.privy.io/guide/faq/experimental-features subject to change at any time}.
993
+ * @experimental **Experimental**: This feature is {@link https://docs.privy.io/guide/guides/experimental-features subject to change at any time}.
905
994
  *
906
995
  * Prompts a user to sign a message using their Privy wallet.
907
996
  *
@@ -920,6 +1009,18 @@ interface PrivyInterface {
920
1009
  */
921
1010
  declare const usePrivy: () => PrivyInterface;
922
1011
 
1012
+ /**
1013
+ * Allows you to manage the user's currently connected wallets.
1014
+ * You can access the fields and methods documented here via the {@link useWallets} hook.
1015
+ */
1016
+ interface UseWalletsInterface {
1017
+ /**
1018
+ * The user's connected wallets.
1019
+ */
1020
+ wallets: ConnectedWallet[];
1021
+ }
1022
+ declare function useWallets(): UseWalletsInterface;
1023
+
923
1024
  declare const VERSION: string;
924
1025
 
925
1026
  interface ResponseEmailAccount {
@@ -1130,7 +1231,6 @@ declare class PrivyClient {
1130
1231
  }): Promise<string | null>;
1131
1232
  getServerConfig(): Promise<PrivyServerConfig>;
1132
1233
  getUsdTokenPrice(chainId: string | number): Promise<number | undefined>;
1133
- setActiveWallet(address: string, user: User): Promise<User>;
1134
1234
  /**
1135
1235
  * Get a short-lived token to start a new Privy session from the existing authenticated session.
1136
1236
  *
@@ -1143,4 +1243,4 @@ declare class PrivyClient {
1143
1243
  forkSession(): Promise<string>;
1144
1244
  }
1145
1245
 
1146
- export { Apple, AppleOAuthWithMetadata, AsExternalProvider, ConnectorManager, Discord, DiscordOAuthWithMetadata, Email, EmailWithMetadata, Github, GithubOAuthWithMetadata, Google, GoogleOAuthWithMetadata, Phone, PhoneWithMetadata, PrivyClient, PrivyClientConfig, PrivyInterface, PrivyProvider, PrivyProviderProps, PrivyProxyProvider, Quantity, SendTransactionModalUIOptions, SignMessageModalUIOptions, TransactionLog, TransactionReceipt, Twitter, TwitterOAuthWithMetadata, UnsignedTransactionRequest, User, VERSION, Wallet, WalletConnector, WalletWithMetadata, getAccessToken, usePrivy };
1246
+ export { Apple, AppleOAuthWithMetadata, AsExternalProvider, ConnectedWallet, ConnectorManager, Discord, DiscordOAuthWithMetadata, EIP1193Provider, Email, EmailWithMetadata, Github, GithubOAuthWithMetadata, Google, GoogleOAuthWithMetadata, Phone, PhoneWithMetadata, PrivyClient, PrivyClientConfig, PrivyInterface, PrivyProvider, PrivyProviderProps, PrivyProxyProvider, Quantity, SendTransactionModalUIOptions, SignMessageModalUIOptions, TransactionLog, TransactionReceipt, Twitter, TwitterOAuthWithMetadata, UnsignedTransactionRequest, UseWalletsInterface, User, VERSION, Wallet, WalletConnector, WalletWithMetadata, getAccessToken, usePrivy, useWallets };