@privy-io/react-auth 1.43.4 → 1.44.0-beta-20231020144049

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
@@ -220,6 +220,8 @@ type WalletConnectRequestDataType = {
220
220
  };
221
221
  type WalletRpcRequestDataType = {
222
222
  accessToken: string;
223
+ mfaCode?: string;
224
+ mfaMethod?: MfaMethod;
223
225
  address: string;
224
226
  request: RpcRequestType;
225
227
  };
@@ -290,6 +292,8 @@ declare enum PrivyErrorCode {
290
292
  GENERIC_CONNECT_WALLET_ERROR = "generic_connect_wallet_error",
291
293
  CLIENT_REQUEST_TIMEOUT = "client_request_timeout",
292
294
  INVALID_CREDENTIALS = "invalid_credentials",
295
+ MISSING_MFA_CREDENTIALS = "missing_mfa_credentials",
296
+ UNKNOWN_MFA_ERROR = "unknown_mfa_error",
293
297
  EMBEDDED_WALLET_ALREADY_EXISTS = "embedded_wallet_already_exists",
294
298
  UNKNOWN_EMBEDDED_WALLET_ERROR = "unknown_embedded_wallet_error",
295
299
  EMBEDDED_WALLET_PASSWORD_UNCONFIRMED = "embedded_wallet_password_unconfirmed",
@@ -565,10 +569,16 @@ interface ResponseCustomJwtAccount {
565
569
  verified_at: number;
566
570
  }
567
571
  type LinkedAccountsResponseType = Array<ResponseEmailAccount | ResponsePhoneAccount | ResponseEthereumAccount | ResponseOAuthGoogle | ResponseOAuthTwitter | ResponseOAuthDiscord | ResponseOAuthGithub | ResponseOAuthTiktok | ResponseOAuthLinkedIn | ResponseOAuthApple | ResponseCustomJwtAccount>;
572
+ interface ResponseSmsMfaMethod {
573
+ type: 'sms';
574
+ verified_at: number;
575
+ }
576
+ type LinkedMfaMethodsResponseType = Array<ResponseSmsMfaMethod>;
568
577
  interface GetCurrentUserResponse {
569
578
  id: string;
570
579
  created_at: number;
571
580
  linked_accounts: LinkedAccountsResponseType;
581
+ mfa_methods: LinkedMfaMethodsResponseType;
572
582
  }
573
583
 
574
584
  interface DefaultsType {
@@ -691,6 +701,16 @@ declare class ConnectorManager extends EventEmitter<ConnectorManagerEvents> {
691
701
  setActiveWallet(address: string): void;
692
702
  }
693
703
 
704
+ type MfaAuthMeta = {
705
+ [key: string]: any;
706
+ };
707
+ interface MfaFlow {
708
+ api?: Http;
709
+ meta?: MfaAuthMeta;
710
+ init(): Promise<void>;
711
+ authenticate(): Promise<User>;
712
+ }
713
+
694
714
  /**
695
715
  * This should not be directly used by developers at the moment,
696
716
  * so we doc-ignore it.
@@ -708,6 +728,7 @@ declare class PrivyClient {
708
728
  apiUrl: string;
709
729
  fallbackApiUrl: string;
710
730
  authFlow?: AuthFlow;
731
+ mfaFlow?: MfaFlow;
711
732
  connectors?: ConnectorManager;
712
733
  /**
713
734
  * Creates a new Privy client.
@@ -746,6 +767,7 @@ declare class PrivyClient {
746
767
  link(): Promise<User | null>;
747
768
  logout(): Promise<void>;
748
769
  startAuthFlow(authFlow: AuthFlow): void;
770
+ startMfaFlow(mfaFlow: MfaFlow): void;
749
771
  unlinkEmail(address: string): Promise<User>;
750
772
  unlinkPhone(phoneNumber: string): Promise<User>;
751
773
  unlinkWallet(address: string): Promise<User>;
@@ -829,6 +851,8 @@ type MoonpaySignResponse = {
829
851
  };
830
852
 
831
853
  declare const SUPPORTED_OAUTH_PROVIDERS: readonly ["google", "discord", "twitter", "github", "tiktok", "linkedin", "apple"];
854
+ declare const SUPPORTED_MFA_METHODS: readonly ["sms"];
855
+ type MfaMethod = (typeof SUPPORTED_MFA_METHODS)[number];
832
856
  type OAuthProviderType = (typeof SUPPORTED_OAUTH_PROVIDERS)[number];
833
857
  type EmbeddedWalletClientType = 'privy';
834
858
  type InjectedWalletClientType = 'metamask' | 'phantom';
@@ -1168,6 +1192,8 @@ interface User {
1168
1192
  /** The list of accounts associated with this user. Each account contains additional metadata
1169
1193
  * that may be helpful for advanced use cases. */
1170
1194
  linkedAccounts: Array<LinkedAccountWithMetadata>;
1195
+ /** The list of MFA Methods associated with this user. */
1196
+ mfaMethods: Array<MfaMethod>;
1171
1197
  }
1172
1198
  type PrivyServerConfig = {
1173
1199
  id?: string;
@@ -1795,6 +1821,42 @@ interface PrivyInterface {
1795
1821
  * @returns Promise for the signature as a string
1796
1822
  */
1797
1823
  signMessage: (message: string, uiOptions?: SignMessageModalUIOptions) => Promise<string>;
1824
+ /**
1825
+ * Initiate the enrollment flow for MFA for the current user.
1826
+ *
1827
+ * @param mfaMethod {@link MfaMethod} The MFA method to enroll for the current user.
1828
+ * @param meta {@link {phoneNumber: string}} The meta data needed to complete the MFA flow.
1829
+ * @returns Promise for enrolling the current user with the chosen MFA method.
1830
+ */
1831
+ initEnroll: (mfaMethod: MfaMethod, meta: {
1832
+ phoneNumber: string;
1833
+ }) => Promise<void>;
1834
+ /**
1835
+ * Submit the MFA code to complete enrollment process.
1836
+ *
1837
+ * @param method {@link MfaMethod} The MFA method to be used.
1838
+ * @param meta {@link {phoneNumber: string; mfaCode: string}} The MFA code and phone number to submit.
1839
+ * @returns Promise for the MFA code submission.
1840
+ */
1841
+ submitEnroll: (mfaMethod: MfaMethod, meta: {
1842
+ phoneNumber: string;
1843
+ mfaCode: string;
1844
+ }) => Promise<void>;
1845
+ /**
1846
+ * Initiate the MFA flow for the current user.
1847
+ *
1848
+ * @param mfaMethod {@link MfaMethod} The available MFA method to trigger for the current user.
1849
+ * @returns Promise for sending the MFA code to the user's device.
1850
+ */
1851
+ init: (mfaMethod: MfaMethod) => Promise<void>;
1852
+ /**
1853
+ * Submit the MFA code for the current user.
1854
+ *
1855
+ * @param method {@link MfaMethod} The MFA method to be used.
1856
+ * @param mfaCode {string} The MFA code to submit.
1857
+ * @returns Promise for the MFA code submission.
1858
+ */
1859
+ submit: (mfaMethod: MfaMethod, mfaCode: string) => Promise<void>;
1798
1860
  /**
1799
1861
  * Prompts a user to send a transaction using their embedded wallet.
1800
1862
  *
@@ -1843,8 +1905,6 @@ interface UseWalletsInterface {
1843
1905
  }
1844
1906
  declare function useWallets(): UseWalletsInterface;
1845
1907
 
1846
- declare const VERSION: string;
1847
-
1848
1908
  type CallbackError = (error: PrivyErrorCode) => void;
1849
1909
  type PrivyEvents = {
1850
1910
  login: {
@@ -1908,8 +1968,43 @@ type PrivyEvents = {
1908
1968
  */
1909
1969
  onError?: CallbackError;
1910
1970
  };
1971
+ configureMfa: {
1972
+ /**
1973
+ * Callback that will execute when MFA is required to complete a given action.
1974
+ * @param mfaMethods {@link MfaMethod[]} - List of MFA methods that the user can choose from
1975
+ */
1976
+ onPromptMfa: (mfaMethods: MfaMethod[]) => void;
1977
+ /**
1978
+ * Callback that will execute in the case of a non-successful MFA flow.
1979
+ *
1980
+ * @param error {PrivyErrorCode} - the corresponding error code
1981
+ *
1982
+ */
1983
+ onError?: CallbackError;
1984
+ };
1911
1985
  };
1912
1986
 
1987
+ /**
1988
+ * Use this hook to listen for MFA required events and prompt the user to complete MFA.
1989
+ *
1990
+ * @param callbacks.onPromptMfa {@link PrivyEvents} callback to execute to start `MFA Flow` when it is required for an action.
1991
+ * @param callbacks.onError {@link PrivyEvents} callback to execute if there is an error during `MFA Flow`.
1992
+ * @returns initMfa, submitMfa, cancelMfaFlow - Tells the developer where they are in the MFA flow.
1993
+ */
1994
+ declare function useConfigureMfa(callbacks: PrivyEvents['configureMfa']): {
1995
+ init: (mfaMethod: "sms") => Promise<void>;
1996
+ submit: (mfaMethod: "sms", mfaCode: string) => Promise<void>;
1997
+ submitEnroll: (mfaMethod: "sms", meta: {
1998
+ phoneNumber: string;
1999
+ mfaCode: string;
2000
+ }) => Promise<void>;
2001
+ initEnroll: (mfaMethod: "sms", meta: {
2002
+ phoneNumber: string;
2003
+ }) => Promise<void>;
2004
+ };
2005
+
2006
+ declare const VERSION: string;
2007
+
1913
2008
  /**
1914
2009
  * Use this hook to log the user in, and to attach callbacks
1915
2010
  * for successful `login`s, already-`authenticated` users, and
@@ -1980,4 +2075,4 @@ declare function useCreateWallet(callbacks?: PrivyEvents['createWallet']): {
1980
2075
  createWallet: () => Promise<Wallet>;
1981
2076
  };
1982
2077
 
1983
- export { Apple, AppleOAuthWithMetadata, AsExternalProvider, CallbackError, ConnectedWallet, ConnectorManager, ContractUIOptions, Discord, DiscordOAuthWithMetadata, EIP1193Provider, Email, EmailWithMetadata, FundWalletConfig, Github, GithubOAuthWithMetadata, Google, GoogleOAuthWithMetadata, LinkedIn, LinkedInOAuthWithMetadata, MoonpayConfig, MoonpayCurrencyCode, MoonpayPaymentMethod, Phone, PhoneWithMetadata, PrivyClient, PrivyClientConfig, PrivyEvents, PrivyInterface, PrivyProvider, PrivyProviderProps, PrivyProxyProvider, Quantity, DEFAULT_SUPPORTED_CHAINS as SUPPORTED_CHAINS, SendTransactionModalUIOptions, SignMessageModalUIOptions, Tiktok, TiktokOAuthWithMetadata, TransactionLog, TransactionReceipt, TransactionUIOptions, Twitter, TwitterOAuthWithMetadata, UnsignedTransactionRequest, UseWalletsInterface, User, VERSION, Wallet, WalletConnector, WalletWithMetadata, getAccessToken, useConnectWallet, useCreateWallet, useLogin, useLogout, usePrivy, useWallets };
2078
+ export { Apple, AppleOAuthWithMetadata, AsExternalProvider, CallbackError, ConnectedWallet, ConnectorManager, ContractUIOptions, Discord, DiscordOAuthWithMetadata, EIP1193Provider, Email, EmailWithMetadata, FundWalletConfig, Github, GithubOAuthWithMetadata, Google, GoogleOAuthWithMetadata, LinkedIn, LinkedInOAuthWithMetadata, MfaMethod, MoonpayConfig, MoonpayCurrencyCode, MoonpayPaymentMethod, Phone, PhoneWithMetadata, PrivyClient, PrivyClientConfig, PrivyEvents, PrivyInterface, PrivyProvider, PrivyProviderProps, PrivyProxyProvider, Quantity, DEFAULT_SUPPORTED_CHAINS as SUPPORTED_CHAINS, SendTransactionModalUIOptions, SignMessageModalUIOptions, Tiktok, TiktokOAuthWithMetadata, TransactionLog, TransactionReceipt, TransactionUIOptions, Twitter, TwitterOAuthWithMetadata, UnsignedTransactionRequest, UseWalletsInterface, User, VERSION, Wallet, WalletConnector, WalletWithMetadata, getAccessToken, useConfigureMfa, useConnectWallet, useCreateWallet, useLogin, useLogout, usePrivy, useWallets };