@privy-io/react-auth 1.17.1 → 1.18.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
@@ -6,8 +6,15 @@ import { AxiosResponse, AxiosRequestConfig } from 'axios';
6
6
 
7
7
  declare const SUPPORTED_OAUTH_PROVIDERS: readonly ["google", "discord", "twitter", "github"];
8
8
  type OAuthProviderType = typeof SUPPORTED_OAUTH_PROVIDERS[number];
9
- declare const SUPPORTED_WALLET_TYPES: readonly ["metamask", "coinbase_wallet", "wallet_connect"];
10
- type WalletType = typeof SUPPORTED_WALLET_TYPES[number];
9
+ declare const SUPPORTED_WALLET_CONNECTION_TYPES: readonly ["metamask", "coinbase_wallet", "wallet_connect"];
10
+ type WalletType = typeof SUPPORTED_WALLET_CONNECTION_TYPES[number];
11
+ /**
12
+ * Wallet metadata currently for internal use only
13
+ */
14
+ type WalletBranding = {
15
+ name: string;
16
+ icon?: string | EmbeddedSVG;
17
+ };
11
18
  type LinkedAccountType = 'wallet' | 'email' | 'phone' | 'google_oauth' | 'twitter_oauth' | 'discord_oauth' | 'github_oauth';
12
19
  /** @ignore */
13
20
  interface LinkMetadata {
@@ -129,6 +136,9 @@ interface GithubOAuthWithMetadata extends LinkMetadata, Github {
129
136
  /** Denotes that this is a Github account. */
130
137
  type: 'github_oauth';
131
138
  }
139
+ /**
140
+ * Object representation of a user's linked accounts
141
+ */
132
142
  type LinkedAccountWithMetadata = WalletWithMetadata | EmailWithMetadata | PhoneWithMetadata | GoogleOAuthWithMetadata | TwitterOAuthWithMetadata | DiscordOAuthWithMetadata | GithubOAuthWithMetadata;
133
143
  interface User {
134
144
  /** The Privy-issued DID for the user. If you need to store additional information
@@ -207,14 +217,17 @@ interface PrivyProviderProps {
207
217
  *
208
218
  */
209
219
  onSuccess?: (user: User, isNewUser: boolean) => void;
210
- /** @ignore */
211
- children: React.ReactNode;
212
220
  /**
213
221
  * If true, the user will be prompted to create a Privy wallet
214
- * after they have successfully logged in if they do not currently
215
- * have any wallet associated with their user account.
222
+ * after successfully logging in, if they do not currently
223
+ * have any wallet associated with their user object.
216
224
  */
217
225
  createPrivyWalletOnLogin?: boolean;
226
+ /**
227
+ * @ignore
228
+ * @class
229
+ */
230
+ children: React.ReactNode;
218
231
  }
219
232
  /**
220
233
  * Passes the Privy authentication context to your React components.
@@ -249,14 +262,14 @@ interface EIP1193Provider {
249
262
  declare class PrivyProxyProvider implements EIP1193Provider {
250
263
  walletProvider?: EIP1193Provider;
251
264
  private _subscriptions;
252
- constructor(provider?: EIP1193Provider);
265
+ constructor(walletProvider?: EIP1193Provider);
253
266
  on(eventName: string, listener: (...args: any[]) => void): any;
254
267
  request(request: {
255
268
  method: string;
256
269
  params?: any[] | undefined;
257
270
  }): Promise<any>;
258
271
  removeListener: (eventName: string | symbol, listener: (...args: any[]) => void) => any;
259
- setProvider: (provider: EIP1193Provider) => void;
272
+ setWalletProvider: (provider: EIP1193Provider) => void;
260
273
  }
261
274
  declare class AsExternalProvider extends PrivyProxyProvider implements ExternalProvider {
262
275
  constructor(provider: EIP1193Provider);
@@ -275,15 +288,16 @@ declare class AsExternalProvider extends PrivyProxyProvider implements ExternalP
275
288
  }
276
289
 
277
290
  declare abstract class WalletConnector {
278
- provider: PrivyProxyProvider;
291
+ proxyProvider: PrivyProxyProvider;
279
292
  walletType: WalletType;
280
293
  connected: boolean;
281
294
  address: string | null;
282
295
  chain: string | null;
283
- constructor(walletType: WalletType, provider: PrivyProxyProvider, address: string | null);
296
+ constructor(walletType: WalletType, proxyProvider: PrivyProxyProvider, address: string | null);
284
297
  fetchAddress(): Promise<string | null>;
285
298
  fetchChainId(): Promise<string>;
286
299
  getConnectedWallet(): Promise<Wallet | null>;
300
+ abstract get walletBranding(): WalletBranding;
287
301
  abstract connect(options: {
288
302
  showPrompt: boolean;
289
303
  }): Promise<Wallet | null>;
@@ -293,24 +307,48 @@ declare abstract class WalletConnector {
293
307
  setActive(): Promise<boolean>;
294
308
  }
295
309
 
310
+ /**
311
+ * Types aren't included in the final distribution, so we can have the duplicates here to assure
312
+ * type-safety
313
+ */
314
+ 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';
315
+
296
316
  /**
297
317
  * Light wrapper around WCConnectionManager that uses the global connection manager
298
318
  * to manage the local storage layer and avoid conflicts.
319
+ * There can be multiple WCWalletConnectors, but should only ever be a single
320
+ * WCConnectionManager, which should be the class referenced - it will in turn find
321
+ * the appropriate WCWalletConnector for use with an action.
299
322
  */
300
323
  declare class WCWalletConnector extends WalletConnector {
301
- private _connectionManager;
302
- private _provider;
303
- constructor(connectionManager: WCConnectionManager, provider: PrivyProxyProvider, address: string | null);
324
+ private connectionManager;
325
+ constructor(connectionManager: WCConnectionManager, proxyProvider: PrivyProxyProvider, address: string | null);
326
+ setActive(): Promise<boolean>;
304
327
  connect(options: {
305
328
  showPrompt: boolean;
306
329
  }): Promise<Wallet | null>;
307
330
  isConnected(): Promise<boolean>;
331
+ /**
332
+ * Metadata about the wallet represented by this connector.
333
+ */
334
+ get walletBranding(): {
335
+ name: string;
336
+ icon: string | EmbeddedSVG;
337
+ };
308
338
  promptConnection(): Promise<void>;
309
339
  /**
310
- * Perform personal_sign with the user's wallet.
340
+ * Perform personal_sign with the user's first wallet associated with WalletConnect
311
341
  */
312
342
  sign(message: string): Promise<string>;
313
343
  disconnect(): void;
344
+ /**
345
+ * Access the underlying WCProvider directly with proper typings
346
+ */
347
+ private get walletProvider();
348
+ /**
349
+ * Set the underlying WCProvider with proper typings
350
+ */
351
+ setWalletProvider(walletProvider: WCProvider): void;
314
352
  }
315
353
  /**
316
354
  * An object representation of the Wallet Connect V1 protocol. This is used to initiate and manage connections
@@ -318,24 +356,59 @@ declare class WCWalletConnector extends WalletConnector {
318
356
  */
319
357
  declare class WCConnectionManager {
320
358
  private _storageIdToProvider;
321
- private _addressToStorageId;
359
+ private reconnectDelayMs;
360
+ private reconnectBackoff;
322
361
  constructor();
323
362
  /**
324
363
  * Builds a new WCWalletConnector instance
364
+ *
365
+ * If walletId is specified, attempts to launch into that specific flow.
366
+ *
367
+ * IMPORTANT! Nothing in this flow can be costly in order to properly launch our deep links. See:
368
+ * https://docs.walletconnect.com/1.0/mobile-linking#ios-app-link-constraints
369
+ */
370
+ createConnector(proxyProvider: PrivyProxyProvider, address: string | null,
371
+ /**
372
+ * If provided, the connector will attempt to establish a connection directly using this
373
+ * wallet. If omitted, but an address is provided, the connector may still attempt to link
374
+ * up to a wallet, but may be unable to. If a wallet cannot be determined, the standard WC
375
+ * modal is shown.
325
376
  */
326
- createConnector(provider: PrivyProxyProvider, address: string | null): WCWalletConnector;
377
+ walletId?: WalletId): WCWalletConnector;
327
378
  /**
328
379
  * Disconnects all active Wallet Connect sessions.
329
380
  */
330
381
  disconnect(): Promise<void>;
331
382
  /**
332
- * Handles storage retrieval and assignment for WalletConnectProvider instances
383
+ * Fetch a storage id for an address/walletId pair. If we don't match exactly, we still
384
+ * attempt to discover if any legacy keys were matched using instant launch methods (currently)
385
+ * just metamask and reuse if that. Admittedly, this method feels very fragile and unknown.
386
+ */
387
+ private getStorageId;
388
+ /**
389
+ * Given an address, either fetch (reusing a stored connection) or create a new one if no stored
390
+ * connection is found
391
+ */
392
+ getProviderForAddress(address: string | null, walletId: WalletId | undefined): WCProvider | undefined;
393
+ private createProviderWithStorageId;
394
+ /**
395
+ * Create a WC provider and add an entry to the internal provider registry keyed on the internal
396
+ * WC storageId. If walletId is specified, attempts to launch the WC flow for that particular
397
+ * wallet
398
+ */
399
+ createProvider(connector: WCWalletConnector, walletId?: WalletId): WCProvider;
400
+ /**
401
+ * Replace the given provider, *assuming it's the one with null address*
402
+ *
403
+ * Couldn't find any WC docs, but a reference implementation library had a similar error we were
404
+ * seeing - WC sessions wouldn't open a new modal/etc when doing `provider.enable()` if it had
405
+ * previously been rejected: https://github.com/Uniswap/web3-react/issues/217
333
406
  */
334
- getProviderForAddress(address: string | null): WCProvider;
407
+ replaceProvider(connector: WCWalletConnector, provider: WCProvider): WCProvider;
335
408
  /**
336
- * Updates internal global connector data structures with address mappings as new accounts are added
409
+ * Enables the provider. Under the hood, this calls connect() and 'eth_RequestAccounts'.
337
410
  */
338
- indexProvider(provider: WCProvider): void;
411
+ enableProvider(provider: WCProvider): Promise<string[]>;
339
412
  }
340
413
 
341
414
  declare class ConnectorManager {
@@ -353,7 +426,9 @@ declare class ConnectorManager {
353
426
  * initialize their WalletConnector objects accordingly.
354
427
  **/
355
428
  initializeLinkedWallets(user: User): void;
429
+ /** Load the state from storage and hydrate the instance with WalletConnectors. */
356
430
  load(): void;
431
+ /** Persist the instance state to storage to reload the connectors later. */
357
432
  save(): void;
358
433
  addWalletConnector(walletConnector: WalletConnector): void;
359
434
  getConnectorByAddress(address: string): WalletConnector | undefined;
@@ -369,7 +444,9 @@ declare class ConnectorManager {
369
444
  * If the connector was successfully found and set active, return true.
370
445
  */
371
446
  setActiveWallet(address: string | null): Promise<boolean>;
372
- createWalletConnector(walletType: WalletType, address: string | null): WalletConnector;
447
+ createWalletConnector(walletType: WalletType, address: string | null,
448
+ /** Only applicable for WalletConnect right now */
449
+ walletId?: WalletId): WalletConnector;
373
450
  }
374
451
 
375
452
  /**
@@ -478,6 +555,7 @@ interface PrivyInterface {
478
555
  unlinkPhone: (phoneNumber: string) => Promise<User>;
479
556
  /**
480
557
  * Unlink a wallet account from a user, by passing the public address. Note that you can only unlink a wallet account if the user has at least one other account.
558
+ * If the unlinked wallet was the active one, and more wallets are linked to the user, then we attempt to make the most recently linked wallet active.
481
559
  */
482
560
  unlinkWallet: (address: string) => Promise<User>;
483
561
  /**
@@ -499,11 +577,12 @@ interface PrivyInterface {
499
577
  /**
500
578
  * Set one of the authenticated wallet addresses (part of user.linkedAccounts with type 'wallet'). as the active wallet.
501
579
  * If you pass a wallet that's not one of the linkedAccounts, this will throw an error.
580
+ * This will prompt the user to reconnect their wallet if the connection is lost.
502
581
  *
503
582
  * The active wallet will be the one that getEthersProvider() will use as a signer (used for signing & transactions).
504
583
  * It is also the wallet present at `user.wallet`, and that value is updated when this is called.
505
584
  *
506
- * Note that when you link a new wallet, it becomes 'active' by default.
585
+ * Note that when you link a new wallet, it becomes active.
507
586
  */
508
587
  setActiveWallet: (address: string) => Promise<void>;
509
588
  /**