@privy-io/react-auth 1.35.2-beta.2 → 1.36.0-beta.1

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
@@ -419,6 +419,364 @@ declare abstract class WalletConnector extends EventEmitter<ConnectorEvents> {
419
419
  abstract promptConnection(walletClientType: WalletClientType): void;
420
420
  }
421
421
 
422
+ interface ResponseEmailAccount {
423
+ type: 'email';
424
+ address: string;
425
+ verified_at: number;
426
+ }
427
+ interface ResponsePhoneAccount {
428
+ type: 'phone';
429
+ phoneNumber: string;
430
+ verified_at: number;
431
+ }
432
+ interface ResponseEthereumAccount {
433
+ type: 'wallet';
434
+ address: string;
435
+ /**
436
+ * @deprecated This will be removed in favor of the CAIP-2 formatted chain_id field.
437
+ *
438
+ * Chain type of the wallet address.
439
+ */
440
+ chain_type: 'ethereum';
441
+ chain_id?: string;
442
+ /**
443
+ * @deprecated Use `wallet_client_type` instead.
444
+ */
445
+ wallet_client: 'privy' | 'unknown';
446
+ wallet_client_type?: string;
447
+ connector_type?: string;
448
+ recovery_method?: 'privy' | 'user-passcode';
449
+ verified_at: number;
450
+ }
451
+ interface ResponseOAuthGoogle {
452
+ type: 'google_oauth';
453
+ subject: string;
454
+ email: string;
455
+ name: string | null;
456
+ verified_at: number;
457
+ }
458
+ interface ResponseOAuthTwitter {
459
+ type: 'twitter_oauth';
460
+ subject: string;
461
+ username: string | null;
462
+ name: string | null;
463
+ verified_at: number;
464
+ }
465
+ interface ResponseOAuthDiscord {
466
+ type: 'discord_oauth';
467
+ subject: string;
468
+ username: string | null;
469
+ email: string | null;
470
+ verified_at: number;
471
+ }
472
+ interface ResponseOAuthGithub {
473
+ type: 'github_oauth';
474
+ subject: string;
475
+ username: string | null;
476
+ name: string | null;
477
+ email: string | null;
478
+ verified_at: number;
479
+ }
480
+ interface ResponseOAuthApple {
481
+ type: 'apple_oauth';
482
+ subject: string;
483
+ email: string;
484
+ verified_at: number;
485
+ }
486
+ interface ResponseCustomJwtAccount {
487
+ type: 'custom_auth';
488
+ custom_user_id: string;
489
+ verified_at: number;
490
+ }
491
+ type LinkedAccountsResponseType = Array<ResponseEmailAccount | ResponsePhoneAccount | ResponseEthereumAccount | ResponseOAuthGoogle | ResponseOAuthTwitter | ResponseOAuthDiscord | ResponseOAuthGithub | ResponseOAuthApple | ResponseCustomJwtAccount>;
492
+ interface GetCurrentUserResponse {
493
+ id: string;
494
+ created_at: number;
495
+ linked_accounts: LinkedAccountsResponseType;
496
+ }
497
+
498
+ interface DefaultsType {
499
+ baseURL: string;
500
+ timeout: number;
501
+ }
502
+ /**
503
+ * A raw http handler for making requests to the Privy API. It requires a Session
504
+ * object, which is used for fetching and including any tokens that are required
505
+ * for requests.
506
+ *
507
+ * Should not be used for external requests, as we attach a good deal of metadata to requests.
508
+ */
509
+ declare class Http {
510
+ fallbackApiUrl: string;
511
+ private appId;
512
+ private client;
513
+ private defaults;
514
+ private sdkVersion;
515
+ private baseFetch;
516
+ constructor(appId: string, client: PrivyClient, defaults: DefaultsType);
517
+ get<T = any>(path: string, config?: FetchOptions<'json'>): Promise<T>;
518
+ post<T = any, D = any>(path: string, data?: D, config?: FetchOptions<'json'>): Promise<T>;
519
+ delete<T = any>(path: string, config?: FetchOptions<'json'>): Promise<T>;
520
+ }
521
+
522
+ /**
523
+ * Valid /session and <>/authenticate calls will respond with a token
524
+ * as well as a valid user object for streamlining.
525
+ */
526
+ interface ValidSessionResponse {
527
+ user: GetCurrentUserResponse;
528
+ token: string;
529
+ refresh_token: string | null;
530
+ is_new_user?: boolean;
531
+ }
532
+
533
+ type AuthMeta = {
534
+ [key: string]: any;
535
+ };
536
+ /**
537
+ * An auth flow is an encapsulation of the business logic required for a given
538
+ * authentication process. It requires at least one definitive `authenticate`
539
+ * method that does the final token handshaking with the API, but may also
540
+ * include any number of methods/API calls necessary to set up the state (e.g.
541
+ * sending an email before being able to do a passwordless code login)
542
+ */
543
+ interface AuthFlow {
544
+ api?: Http;
545
+ /**
546
+ * Any meta information necessary for the auth flow, that may also need to be
547
+ * shared out to things like frontend components for displaying state of the
548
+ * auth flow
549
+ */
550
+ meta: AuthMeta;
551
+ /**
552
+ * Handles the API authentication call(s) to log users in.
553
+ * Any preconditions must be addressed prior to calling
554
+ */
555
+ authenticate(): Promise<ValidSessionResponse>;
556
+ /**
557
+ * Handles the API link call(s) to link new user accounts.
558
+ * Requires user to already be logged in when called.
559
+ * Any preconditions must be addressed prior to calling
560
+ */
561
+ link(): Promise<GetCurrentUserResponse>;
562
+ }
563
+
564
+ interface ConnectorManagerEvents {
565
+ walletsUpdated(): void;
566
+ }
567
+ /** @hidden */
568
+ declare class ConnectorManager extends EventEmitter<ConnectorManagerEvents> {
569
+ walletConnectors: WalletConnector[];
570
+ initialized: boolean;
571
+ private storedConnections;
572
+ private activeWallet?;
573
+ private walletConnectCloudProjectId;
574
+ private rpcConfig;
575
+ constructor(walletConnectCloudProjectId: string, rpcConfig: RpcConfig);
576
+ /**
577
+ * The core wallets array that is exposed to developers. It builds
578
+ * the wallets away with the following logic:
579
+ *
580
+ * 1. Flatten all wallets from all connectors
581
+ * 2. Sorted by connectedAt
582
+ * 3. Active wallet is moved to front of array (if it exists)
583
+ */
584
+ get wallets(): BaseConnectedWallet[];
585
+ /**
586
+ * Detect and add all valid wallet connectors.
587
+ */
588
+ initialize(): void;
589
+ /**
590
+ * Helper function to find a wallet connector by connector type and wallet client type.
591
+ */
592
+ findWalletConnector(connectorType: ConnectorType, walletClientType: WalletClientType): WalletConnector | null;
593
+ /**
594
+ * Add any connectedAt overrides for newly initialized wallets and pass-through change events.
595
+ */
596
+ private onInitialized;
597
+ /**
598
+ * Save connection history and pass-through change events.
599
+ */
600
+ private onWalletsUpdated;
601
+ addEmbeddedWalletConnector(walletProxy: EmbeddedWalletProxy, address: string): void;
602
+ /**
603
+ * Normally, we do not remove connectors after creation. Privy embedded wallets are an exception
604
+ * because they are closely tied with an authenticated state.
605
+ */
606
+ removeEmbeddedWalletConnector(): void;
607
+ /**
608
+ * Creates a new wallet connector for the given connector type and wallet client type.
609
+ * If a connector already exists, it will be returned instead.
610
+ */
611
+ createWalletConnector(connectorType: ConnectorType, walletClientType: WalletClientType): Promise<WalletConnector | null>;
612
+ private addWalletConnector;
613
+ /**
614
+ * Upon initialization, loads previous connections from local storage. If local storage
615
+ * is misformatted (e.g. due to previous privy:connectors usage), it returns an empty array that
616
+ * will be overwritten later.
617
+ *
618
+ * @returns StoredConnection[] list of stored connections from previous session
619
+ */
620
+ private loadConnectionHistory;
621
+ /**
622
+ * Saves all current connections to local storage overridding any previous connections.
623
+ */
624
+ private saveConnectionHistory;
625
+ /**
626
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
627
+ * interfacing with wallets directly (wallets[0].getEthereumProvider()).
628
+ *
629
+ * Build an Ethereum provider for the most recently connected wallet.
630
+ */
631
+ getEthereumProvider: () => EIP1193Provider;
632
+ /**
633
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
634
+ * interfacing with `wallets` directly.
635
+ *
636
+ * Performing personal_sign with the most recently connected wallet.
637
+ * If there is not a wallet connected, return null.
638
+ */
639
+ activeWalletSign(message: string): Promise<string | null>;
640
+ /**
641
+ * @deprecated **Deprecated**: This feature will be removed and should be replaced by
642
+ * interfacing with `wallets` directly.
643
+ */
644
+ setActiveWallet(address: string): void;
645
+ }
646
+
647
+ /**
648
+ * This should not be directly used by developers at the moment,
649
+ * so we doc-ignore it.
650
+ * @ignore
651
+ *
652
+ */
653
+ declare class PrivyClient {
654
+ private api;
655
+ private appId;
656
+ private session;
657
+ private timeout;
658
+ private clientAnalyticsId;
659
+ useServerCookies: boolean;
660
+ apiUrl: string;
661
+ fallbackApiUrl: string;
662
+ authFlow?: AuthFlow;
663
+ connectors?: ConnectorManager;
664
+ /**
665
+ * Creates a new Privy client.
666
+ * @param options Initialization options.
667
+ */
668
+ constructor(options: {
669
+ /**
670
+ * The URL of the Privy API. Defaults to `https://api.privy.io/v0`.
671
+ */
672
+ apiUrl?: string;
673
+ /**
674
+ * The app id from your console
675
+ */
676
+ appId: string;
677
+ /**
678
+ * Time in milliseconds after which to timeout requests to the API. Defaults to `10000` (10 seconds).
679
+ */
680
+ timeout?: number;
681
+ });
682
+ /**
683
+ * ConnectorManager initialization is deferred because the input parameter may be overridden by the server
684
+ * config. We can set this once and only once. If it is set twice, event listeners will be created
685
+ * on the first ConnectorManager and are not re-created.
686
+ */
687
+ initializeConnectorManager(walletConnectCloudProjectId: string, rpcConfig: RpcConfig): void;
688
+ generateApi(): Http;
689
+ /**
690
+ * In the case of cookie-based auth, re-initialize the http client with the custom api url.
691
+ * @param customApiUrl the custom api url to use for cookie-based authFlow
692
+ */
693
+ updateApiUrl(customApiUrl?: string | null): void;
694
+ authenticate(): Promise<{
695
+ user: User | null;
696
+ isNewUser?: boolean | undefined;
697
+ }>;
698
+ link(): Promise<User | null>;
699
+ logout(): Promise<void>;
700
+ startAuthFlow(authFlow: AuthFlow): void;
701
+ unlinkEmail(address: string): Promise<User>;
702
+ unlinkPhone(phoneNumber: string): Promise<User>;
703
+ unlinkWallet(address: string): Promise<User>;
704
+ unlinkOAuth(provider: OAuthProviderType, subject: string): Promise<User>;
705
+ createAnalyticsEvent(eventName: string, payload?: {
706
+ [key: string]: any;
707
+ }, timestamp?: Date): Promise<void>;
708
+ signMoonpayOnRampUrl(signRequestData: MoonpaySignRequest): Promise<MoonpaySignResponse>;
709
+ /** DATA METHODS */
710
+ /**
711
+ * Fetches the currently authenticed user from the API or
712
+ * returns null if the user is not authenticated.
713
+ *
714
+ * This will refresh the user's access token and rotate
715
+ * the refresh token if needed.
716
+ *
717
+ * @returns Promise<User | null>
718
+ */
719
+ getAuthenticatedUser(): Promise<User | null>;
720
+ /**
721
+ * Grab the Privy access token for the currently logged in user. Verifies that the
722
+ * token has a valid signature, was issued by 'privy.io', and corresponds to the
723
+ * current app ID. If no valid token is found, this method will force a logout and return null.
724
+ *
725
+ * If the token is expired or expiring soon, this will attempt to
726
+ * first refresh the access token to ensure that the token is active. You can
727
+ * disable this behavior using `disableAutoRefresh`, although it is not
728
+ * recommended.
729
+ *
730
+ * @param disableAutoRefresh not recommended - optionally disable automatic
731
+ * token refresh when the token is
732
+ *
733
+ * @returns Promise<string | null>
734
+ */
735
+ getAccessToken(options?: {
736
+ disableAutoRefresh?: boolean;
737
+ }): Promise<string | null>;
738
+ getServerConfig(): Promise<PrivyServerConfig>;
739
+ getUsdTokenPrice(chainId: string | number): Promise<number | undefined>;
740
+ /**
741
+ * Get a short-lived token to start a new Privy session from the existing authenticated session.
742
+ *
743
+ * Rotates the access token and refresh token.
744
+ * Raises an exception if the current session was already forked from a previous session,
745
+ * or if the current session is not authenticated.
746
+ *
747
+ * @returns Promise<string>
748
+ */
749
+ forkSession(): Promise<string>;
750
+ }
751
+
752
+ /**
753
+ * Accepted payment methods for the MoonPay fiat on-ramp.
754
+ */
755
+ type MoonpayPaymentMethod = 'ach_bank_transfer' | 'credit_debit_card' | 'gbp_bank_transfer' | 'gbp_open_banking_payment' | 'mobile_wallet' | 'sepa_bank_transfer' | 'sepa_open_banking_payment' | 'pix_instant_payment' | 'yellow_card_bank_transfer';
756
+ /**
757
+ * Cryptocurrency codes for the MoonPay fiat on-ramp. These codes
758
+ * follow the format {TOKEN_NAME}_{NETWORK_NAME}.
759
+ */
760
+ type MoonpayCurrencyCode = 'AVAX_CCHAIN' | 'CELO_CELO' | 'CUSD_CELO' | 'DAI_ETHEREUM' | 'ETH_ETHEREUM' | 'ETH_ARBITRUM' | 'ETH_POLYGON' | 'FIL_FVM' | 'MATIC_ETHEREUM' | 'MATIC_POLYGON' | 'USDC_ETHEREUM' | 'USDC_ARBITRUM' | 'USDC_OPTIMISM' | 'USDC_POLYGON' | 'USDT_ETHEREUM' | 'USDT_POLYGON' | 'WETH_POLYGON' | 'WBTC_ETHEREUM';
761
+ type MoonpayConfig = {
762
+ currencyCode?: MoonpayCurrencyCode;
763
+ quoteCurrencyAmount?: number;
764
+ paymentMethod?: MoonpayPaymentMethod;
765
+ uiConfig?: {
766
+ accentColor?: string;
767
+ theme?: 'light' | 'dark';
768
+ };
769
+ };
770
+ type MoonpaySignRequest = {
771
+ address: string;
772
+ config: MoonpayConfig;
773
+ useSandbox: boolean;
774
+ };
775
+ type MoonpaySignResponse = {
776
+ signedUrl: string;
777
+ externalTransactionId: string;
778
+ };
779
+
422
780
  declare const SUPPORTED_OAUTH_PROVIDERS: readonly ["google", "discord", "twitter", "github", "apple"];
423
781
  type OAuthProviderType = typeof SUPPORTED_OAUTH_PROVIDERS[number];
424
782
  /** @hidden */
@@ -469,6 +827,10 @@ interface LinkMetadata {
469
827
  /** Datetime when this account was linked to the user. */
470
828
  verifiedAt: Date;
471
829
  }
830
+ type FundWalletConfig = {
831
+ config: MoonpayConfig;
832
+ provider?: 'moonpay';
833
+ };
472
834
  /**
473
835
  * Object representation of a user's wallet.
474
836
  */
@@ -577,6 +939,20 @@ interface ConnectedWallet extends BaseConnectedWallet {
577
939
  * Throws a PrivyClientError if the wallet is not connected.
578
940
  */
579
941
  loginOrLink: () => Promise<void>;
942
+ /** Prompt the user to go through the fiat onramp flow.
943
+ *
944
+ * This will open the modal with a prompt for the user to navigate to a third-party on-ramp provider.
945
+ *
946
+ * Once the user continues to the on-ramp flow, Privy will display the on-ramp status screen, and wait
947
+ * for the transaction to complete.
948
+ *
949
+ * Note: Even after a successful funding, funds can take a few minutes to arrive in the user's wallet.
950
+ *
951
+ * The current supported provider is Moonpay.
952
+ *
953
+ * @param {FundWalletConfig} fundWalletConfig The configuration for the fiat onramp flow.
954
+ * **/
955
+ fund: (fundWalletConfig?: FundWalletConfig) => Promise<void>;
580
956
  /** Unlink this wallet to the authenticated user. Throws a PrivyClientError if the user is not
581
957
  * authenticated. */
582
958
  unlink: () => Promise<void>;
@@ -739,6 +1115,7 @@ type PrivyServerConfig = {
739
1115
  customApiUrl?: string | null;
740
1116
  walletConnectCloudProjectId?: string | null;
741
1117
  embeddedWalletConfig: EmbeddedWalletsConfig;
1118
+ fiatOnRampEnabled?: boolean;
742
1119
  captchaEnabled?: boolean;
743
1120
  /** May be deprecated from the server config in a future release */
744
1121
  logoUrl?: string;
@@ -878,6 +1255,17 @@ type PrivyClientConfig = {
878
1255
  */
879
1256
  noPromptOnSignature?: boolean;
880
1257
  };
1258
+ /**
1259
+ * Setting associated with fiat-on-ramp flows
1260
+ */
1261
+ fiatOnRamp?: {
1262
+ /**
1263
+ * Determines whether to use the sandbox flow.
1264
+ *
1265
+ * Defaults to false.
1266
+ */
1267
+ useSandbox?: boolean;
1268
+ };
881
1269
  /**
882
1270
  * Override the default rendering settings, used for displaying in a non-modal setting.
883
1271
  * For internal use only.
@@ -1074,99 +1462,16 @@ interface PrivyProviderProps {
1074
1462
  * This should wrap any components that will to use the Privy SDK via the {@link usePrivy} hook. As an example:
1075
1463
  *
1076
1464
  * ```typescript
1077
- * // At your application root (e.g. `_app.tsx` in NextJS):
1078
- * import {PrivyProvider} from '@privy-io/react-auth';
1079
- *
1080
- * <PrivyProvider appId="APP_ID_FROM_CONSOLE" onSuccess={() => console.log('Success!')}>
1081
- * <Component {...pageProps} />
1082
- * </PrivyProvider>
1083
- * ```
1084
- *
1085
- */
1086
- declare const PrivyProvider: ({ config, ...props }: PrivyProviderProps) => JSX.Element;
1087
-
1088
- interface ConnectorManagerEvents {
1089
- walletsUpdated(): void;
1090
- }
1091
- /** @hidden */
1092
- declare class ConnectorManager extends EventEmitter<ConnectorManagerEvents> {
1093
- walletConnectors: WalletConnector[];
1094
- initialized: boolean;
1095
- private storedConnections;
1096
- private activeWallet?;
1097
- private walletConnectCloudProjectId;
1098
- private rpcConfig;
1099
- constructor(walletConnectCloudProjectId: string, rpcConfig: RpcConfig);
1100
- /**
1101
- * The core wallets array that is exposed to developers. It builds
1102
- * the wallets away with the following logic:
1103
- *
1104
- * 1. Flatten all wallets from all connectors
1105
- * 2. Sorted by connectedAt
1106
- * 3. Active wallet is moved to front of array (if it exists)
1107
- */
1108
- get wallets(): BaseConnectedWallet[];
1109
- /**
1110
- * Detect and add all valid wallet connectors.
1111
- */
1112
- initialize(): void;
1113
- /**
1114
- * Helper function to find a wallet connector by connector type and wallet client type.
1115
- */
1116
- findWalletConnector(connectorType: ConnectorType, walletClientType: WalletClientType): WalletConnector | null;
1117
- /**
1118
- * Add any connectedAt overrides for newly initialized wallets and pass-through change events.
1119
- */
1120
- private onInitialized;
1121
- /**
1122
- * Save connection history and pass-through change events.
1123
- */
1124
- private onWalletsUpdated;
1125
- addEmbeddedWalletConnector(walletProxy: EmbeddedWalletProxy, address: string): void;
1126
- /**
1127
- * Normally, we do not remove connectors after creation. Privy embedded wallets are an exception
1128
- * because they are closely tied with an authenticated state.
1129
- */
1130
- removeEmbeddedWalletConnector(): void;
1131
- /**
1132
- * Creates a new wallet connector for the given connector type and wallet client type.
1133
- * If a connector already exists, it will be returned instead.
1134
- */
1135
- createWalletConnector(connectorType: ConnectorType, walletClientType: WalletClientType): Promise<WalletConnector | null>;
1136
- private addWalletConnector;
1137
- /**
1138
- * Upon initialization, loads previous connections from local storage. If local storage
1139
- * is misformatted (e.g. due to previous privy:connectors usage), it returns an empty array that
1140
- * will be overwritten later.
1141
- *
1142
- * @returns StoredConnection[] list of stored connections from previous session
1143
- */
1144
- private loadConnectionHistory;
1145
- /**
1146
- * Saves all current connections to local storage overridding any previous connections.
1147
- */
1148
- private saveConnectionHistory;
1149
- /**
1150
- * @deprecated **Deprecated**: This feature will be removed and should be replaced by
1151
- * interfacing with wallets directly (wallets[0].getEthereumProvider()).
1152
- *
1153
- * Build an Ethereum provider for the most recently connected wallet.
1154
- */
1155
- getEthereumProvider: () => EIP1193Provider;
1156
- /**
1157
- * @deprecated **Deprecated**: This feature will be removed and should be replaced by
1158
- * interfacing with `wallets` directly.
1159
- *
1160
- * Performing personal_sign with the most recently connected wallet.
1161
- * If there is not a wallet connected, return null.
1162
- */
1163
- activeWalletSign(message: string): Promise<string | null>;
1164
- /**
1165
- * @deprecated **Deprecated**: This feature will be removed and should be replaced by
1166
- * interfacing with `wallets` directly.
1167
- */
1168
- setActiveWallet(address: string): void;
1169
- }
1465
+ * // At your application root (e.g. `_app.tsx` in NextJS):
1466
+ * import {PrivyProvider} from '@privy-io/react-auth';
1467
+ *
1468
+ * <PrivyProvider appId="APP_ID_FROM_CONSOLE" onSuccess={() => console.log('Success!')}>
1469
+ * <Component {...pageProps} />
1470
+ * </PrivyProvider>
1471
+ * ```
1472
+ *
1473
+ */
1474
+ declare const PrivyProvider: ({ config, ...props }: PrivyProviderProps) => JSX.Element;
1170
1475
 
1171
1476
  /**
1172
1477
  * Allows you to manage the user's current authentication state and access their linked accounts.
@@ -1402,9 +1707,10 @@ interface PrivyInterface {
1402
1707
  *
1403
1708
  * @param data {@link UnsignedTransactionRequest} transaction to be sent
1404
1709
  * @param uiOptions {@link SendTransactionModalUIOptions} (optional) UI options to customize the transaction request modal
1710
+ * @param fundWalletConfig {@link FundWalletConfig} (optional) Configuration surrounding funding the wallet (if enabled), in the case of insufficient funds
1405
1711
  * @returns Promise for the transaction's {@link TransactionReceipt}
1406
1712
  */
1407
- sendTransaction: (data: UnsignedTransactionRequest, uiOptions?: SendTransactionModalUIOptions) => Promise<TransactionReceipt>;
1713
+ sendTransaction: (data: UnsignedTransactionRequest, uiOptions?: SendTransactionModalUIOptions, fundWalletConfig?: FundWalletConfig) => Promise<TransactionReceipt>;
1408
1714
  /**
1409
1715
  * Shows the user a Privy modal, from which they can copy their embedded wallet's private
1410
1716
  * key for easy export to another wallet client (e.g. MetaMask). The private key is loaded
@@ -1436,252 +1742,6 @@ declare function useWallets(): UseWalletsInterface;
1436
1742
 
1437
1743
  declare const VERSION: string;
1438
1744
 
1439
- interface ResponseEmailAccount {
1440
- type: 'email';
1441
- address: string;
1442
- verified_at: number;
1443
- }
1444
- interface ResponsePhoneAccount {
1445
- type: 'phone';
1446
- phoneNumber: string;
1447
- verified_at: number;
1448
- }
1449
- interface ResponseEthereumAccount {
1450
- type: 'wallet';
1451
- address: string;
1452
- /**
1453
- * @deprecated This will be removed in favor of the CAIP-2 formatted chain_id field.
1454
- *
1455
- * Chain type of the wallet address.
1456
- */
1457
- chain_type: 'ethereum';
1458
- chain_id?: string;
1459
- /**
1460
- * @deprecated Use `wallet_client_type` instead.
1461
- */
1462
- wallet_client: 'privy' | 'unknown';
1463
- wallet_client_type?: string;
1464
- connector_type?: string;
1465
- recovery_method?: 'privy' | 'user-passcode';
1466
- verified_at: number;
1467
- }
1468
- interface ResponseOAuthGoogle {
1469
- type: 'google_oauth';
1470
- subject: string;
1471
- email: string;
1472
- name: string | null;
1473
- verified_at: number;
1474
- }
1475
- interface ResponseOAuthTwitter {
1476
- type: 'twitter_oauth';
1477
- subject: string;
1478
- username: string | null;
1479
- name: string | null;
1480
- verified_at: number;
1481
- }
1482
- interface ResponseOAuthDiscord {
1483
- type: 'discord_oauth';
1484
- subject: string;
1485
- username: string | null;
1486
- email: string | null;
1487
- verified_at: number;
1488
- }
1489
- interface ResponseOAuthGithub {
1490
- type: 'github_oauth';
1491
- subject: string;
1492
- username: string | null;
1493
- name: string | null;
1494
- email: string | null;
1495
- verified_at: number;
1496
- }
1497
- interface ResponseOAuthApple {
1498
- type: 'apple_oauth';
1499
- subject: string;
1500
- email: string;
1501
- verified_at: number;
1502
- }
1503
- interface ResponseCustomJwtAccount {
1504
- type: 'custom_auth';
1505
- custom_user_id: string;
1506
- verified_at: number;
1507
- }
1508
- type LinkedAccountsResponseType = Array<ResponseEmailAccount | ResponsePhoneAccount | ResponseEthereumAccount | ResponseOAuthGoogle | ResponseOAuthTwitter | ResponseOAuthDiscord | ResponseOAuthGithub | ResponseOAuthApple | ResponseCustomJwtAccount>;
1509
- interface GetCurrentUserResponse {
1510
- id: string;
1511
- created_at: number;
1512
- linked_accounts: LinkedAccountsResponseType;
1513
- }
1514
-
1515
- interface DefaultsType {
1516
- baseURL: string;
1517
- timeout: number;
1518
- }
1519
- /**
1520
- * A raw http handler for making requests to the Privy API. It requires a Session
1521
- * object, which is used for fetching and including any tokens that are required
1522
- * for requests.
1523
- *
1524
- * Should not be used for external requests, as we attach a good deal of metadata to requests.
1525
- */
1526
- declare class Http {
1527
- fallbackApiUrl: string;
1528
- private appId;
1529
- private client;
1530
- private defaults;
1531
- private sdkVersion;
1532
- private baseFetch;
1533
- constructor(appId: string, client: PrivyClient, defaults: DefaultsType);
1534
- get<T = any>(path: string, config?: FetchOptions<'json'>): Promise<T>;
1535
- post<T = any, D = any>(path: string, data?: D, config?: FetchOptions<'json'>): Promise<T>;
1536
- delete<T = any>(path: string, config?: FetchOptions<'json'>): Promise<T>;
1537
- }
1538
-
1539
- /**
1540
- * Valid /session and <>/authenticate calls will respond with a token
1541
- * as well as a valid user object for streamlining.
1542
- */
1543
- interface ValidSessionResponse {
1544
- user: GetCurrentUserResponse;
1545
- token: string;
1546
- refresh_token: string | null;
1547
- is_new_user?: boolean;
1548
- }
1549
-
1550
- type AuthMeta = {
1551
- [key: string]: any;
1552
- };
1553
- /**
1554
- * An auth flow is an encapsulation of the business logic required for a given
1555
- * authentication process. It requires at least one definitive `authenticate`
1556
- * method that does the final token handshaking with the API, but may also
1557
- * include any number of methods/API calls necessary to set up the state (e.g.
1558
- * sending an email before being able to do a passwordless code login)
1559
- */
1560
- interface AuthFlow {
1561
- api?: Http;
1562
- /**
1563
- * Any meta information necessary for the auth flow, that may also need to be
1564
- * shared out to things like frontend components for displaying state of the
1565
- * auth flow
1566
- */
1567
- meta: AuthMeta;
1568
- /**
1569
- * Handles the API authentication call(s) to log users in.
1570
- * Any preconditions must be addressed prior to calling
1571
- */
1572
- authenticate(): Promise<ValidSessionResponse>;
1573
- /**
1574
- * Handles the API link call(s) to link new user accounts.
1575
- * Requires user to already be logged in when called.
1576
- * Any preconditions must be addressed prior to calling
1577
- */
1578
- link(): Promise<GetCurrentUserResponse>;
1579
- }
1580
-
1581
- /**
1582
- * This should not be directly used by developers at the moment,
1583
- * so we doc-ignore it.
1584
- * @ignore
1585
- *
1586
- */
1587
- declare class PrivyClient {
1588
- private api;
1589
- private appId;
1590
- private session;
1591
- private timeout;
1592
- private clientAnalyticsId;
1593
- useServerCookies: boolean;
1594
- apiUrl: string;
1595
- fallbackApiUrl: string;
1596
- authFlow?: AuthFlow;
1597
- connectors?: ConnectorManager;
1598
- /**
1599
- * Creates a new Privy client.
1600
- * @param options Initialization options.
1601
- */
1602
- constructor(options: {
1603
- /**
1604
- * The URL of the Privy API. Defaults to `https://api.privy.io/v0`.
1605
- */
1606
- apiUrl?: string;
1607
- /**
1608
- * The app id from your console
1609
- */
1610
- appId: string;
1611
- /**
1612
- * Time in milliseconds after which to timeout requests to the API. Defaults to `10000` (10 seconds).
1613
- */
1614
- timeout?: number;
1615
- });
1616
- /**
1617
- * ConnectorManager initialization is deferred because the input parameter may be overridden by the server
1618
- * config. We can set this once and only once. If it is set twice, event listeners will be created
1619
- * on the first ConnectorManager and are not re-created.
1620
- */
1621
- initializeConnectorManager(walletConnectCloudProjectId: string, rpcConfig: RpcConfig): void;
1622
- generateApi(): Http;
1623
- /**
1624
- * In the case of cookie-based auth, re-initialize the http client with the custom api url.
1625
- * @param customApiUrl the custom api url to use for cookie-based authFlow
1626
- */
1627
- updateApiUrl(customApiUrl?: string | null): void;
1628
- authenticate(): Promise<{
1629
- user: User | null;
1630
- isNewUser?: boolean | undefined;
1631
- }>;
1632
- link(): Promise<User | null>;
1633
- logout(): Promise<void>;
1634
- startAuthFlow(authFlow: AuthFlow): void;
1635
- unlinkEmail(address: string): Promise<User>;
1636
- unlinkPhone(phoneNumber: string): Promise<User>;
1637
- unlinkWallet(address: string): Promise<User>;
1638
- unlinkOAuth(provider: OAuthProviderType, subject: string): Promise<User>;
1639
- createAnalyticsEvent(eventName: string, payload?: {
1640
- [key: string]: any;
1641
- }, timestamp?: Date): Promise<void>;
1642
- /** DATA METHODS */
1643
- /**
1644
- * Fetches the currently authenticed user from the API or
1645
- * returns null if the user is not authenticated.
1646
- *
1647
- * This will refresh the user's access token and rotate
1648
- * the refresh token if needed.
1649
- *
1650
- * @returns Promise<User | null>
1651
- */
1652
- getAuthenticatedUser(): Promise<User | null>;
1653
- /**
1654
- * Grab the Privy access token for the currently logged in user. Verifies that the
1655
- * token has a valid signature, was issued by 'privy.io', and corresponds to the
1656
- * current app ID. If no valid token is found, this method will force a logout and return null.
1657
- *
1658
- * If the token is expired or expiring soon, this will attempt to
1659
- * first refresh the access token to ensure that the token is active. You can
1660
- * disable this behavior using `disableAutoRefresh`, although it is not
1661
- * recommended.
1662
- *
1663
- * @param disableAutoRefresh not recommended - optionally disable automatic
1664
- * token refresh when the token is
1665
- *
1666
- * @returns Promise<string | null>
1667
- */
1668
- getAccessToken(options?: {
1669
- disableAutoRefresh?: boolean;
1670
- }): Promise<string | null>;
1671
- getServerConfig(): Promise<PrivyServerConfig>;
1672
- getUsdTokenPrice(chainId: string | number): Promise<number | undefined>;
1673
- /**
1674
- * Get a short-lived token to start a new Privy session from the existing authenticated session.
1675
- *
1676
- * Rotates the access token and refresh token.
1677
- * Raises an exception if the current session was already forked from a previous session,
1678
- * or if the current session is not authenticated.
1679
- *
1680
- * @returns Promise<string>
1681
- */
1682
- forkSession(): Promise<string>;
1683
- }
1684
-
1685
1745
  type CallbackError = (error: PrivyErrorCode) => void;
1686
1746
  type PrivyEvents = {
1687
1747
  login: {
@@ -1774,4 +1834,4 @@ declare function useConnectWallet(callbacks?: PrivyEvents['connectWallet']): {
1774
1834
  connectWallet: () => void;
1775
1835
  };
1776
1836
 
1777
- export { Apple, AppleOAuthWithMetadata, AsExternalProvider, CallbackError, ConnectedWallet, ConnectorManager, ContractUIOptions, Discord, DiscordOAuthWithMetadata, EIP1193Provider, Email, EmailWithMetadata, Github, GithubOAuthWithMetadata, Google, GoogleOAuthWithMetadata, Phone, PhoneWithMetadata, PrivyClient, PrivyClientConfig, PrivyEvents, PrivyInterface, PrivyProvider, PrivyProviderProps, PrivyProxyProvider, Quantity, SUPPORTED_CHAINS, SendTransactionModalUIOptions, SignMessageModalUIOptions, TransactionLog, TransactionReceipt, TransactionUIOptions, Twitter, TwitterOAuthWithMetadata, UnsignedTransactionRequest, UseWalletsInterface, User, VERSION, Wallet, WalletConnector, WalletWithMetadata, getAccessToken, useConnectWallet, useLogin, useLogout, usePrivy, useWallets };
1837
+ export { Apple, AppleOAuthWithMetadata, AsExternalProvider, CallbackError, ConnectedWallet, ConnectorManager, ContractUIOptions, Discord, DiscordOAuthWithMetadata, EIP1193Provider, Email, EmailWithMetadata, Github, GithubOAuthWithMetadata, Google, GoogleOAuthWithMetadata, MoonpayConfig, MoonpayCurrencyCode, MoonpayPaymentMethod, Phone, PhoneWithMetadata, PrivyClient, PrivyClientConfig, PrivyEvents, PrivyInterface, PrivyProvider, PrivyProviderProps, PrivyProxyProvider, Quantity, SUPPORTED_CHAINS, SendTransactionModalUIOptions, SignMessageModalUIOptions, TransactionLog, TransactionReceipt, TransactionUIOptions, Twitter, TwitterOAuthWithMetadata, UnsignedTransactionRequest, UseWalletsInterface, User, VERSION, Wallet, WalletConnector, WalletWithMetadata, getAccessToken, useConnectWallet, useLogin, useLogout, usePrivy, useWallets };