thirdweb 5.29.2 → 5.29.3-nightly-476b6cc271b0891fa01fb09ca509c564b850ccfa-20240614185219

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.
Files changed (192) hide show
  1. package/dist/cjs/exports/react-native/wallets/in-app.js +17 -0
  2. package/dist/cjs/exports/react-native/wallets/in-app.js.map +1 -0
  3. package/dist/cjs/exports/react-native/wallets.js +36 -0
  4. package/dist/cjs/exports/react-native/wallets.js.map +1 -0
  5. package/dist/cjs/exports/wallets/embedded.js +4 -4
  6. package/dist/cjs/exports/wallets/embedded.js.map +1 -1
  7. package/dist/cjs/exports/wallets/in-app.js +4 -3
  8. package/dist/cjs/exports/wallets/in-app.js.map +1 -1
  9. package/dist/cjs/exports/wallets/smart.js +2 -2
  10. package/dist/cjs/exports/wallets/smart.js.map +1 -1
  11. package/dist/cjs/exports/wallets.js +8 -5
  12. package/dist/cjs/exports/wallets.js.map +1 -1
  13. package/dist/cjs/react/web/ui/ConnectWallet/Details.js +1 -1
  14. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  15. package/dist/cjs/react/web/wallets/in-app/InAppWalletOTPLoginUI.js +1 -1
  16. package/dist/cjs/react/web/wallets/in-app/InAppWalletOTPLoginUI.js.map +1 -1
  17. package/dist/cjs/version.js +1 -1
  18. package/dist/cjs/version.js.map +1 -1
  19. package/dist/cjs/wallets/coinbase/coinbase-wallet.js +87 -0
  20. package/dist/cjs/wallets/coinbase/coinbase-wallet.js.map +1 -0
  21. package/dist/cjs/wallets/coinbase/coinbaseMobileSDK.js +17 -2
  22. package/dist/cjs/wallets/coinbase/coinbaseMobileSDK.js.map +1 -1
  23. package/dist/cjs/wallets/coinbase/coinbaseSDKWallet.js +12 -20
  24. package/dist/cjs/wallets/coinbase/coinbaseSDKWallet.js.map +1 -1
  25. package/dist/cjs/wallets/create-wallet.js +12 -300
  26. package/dist/cjs/wallets/create-wallet.js.map +1 -1
  27. package/dist/cjs/wallets/in-app/core/authentication/type.js +6 -1
  28. package/dist/cjs/wallets/in-app/core/authentication/type.js.map +1 -1
  29. package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js +100 -0
  30. package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js.map +1 -0
  31. package/dist/cjs/wallets/in-app/core/wallet/index.js +15 -7
  32. package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
  33. package/dist/cjs/wallets/in-app/{core/authentication → native/auth}/index.js +15 -42
  34. package/dist/cjs/wallets/in-app/native/auth/index.js.map +1 -0
  35. package/dist/cjs/wallets/in-app/native/{auth.js → auth/native-auth.js} +9 -9
  36. package/dist/cjs/wallets/in-app/native/auth/native-auth.js.map +1 -0
  37. package/dist/cjs/wallets/in-app/native/in-app.js +69 -0
  38. package/dist/cjs/wallets/in-app/native/in-app.js.map +1 -0
  39. package/dist/cjs/wallets/in-app/native/native-connector.js +9 -10
  40. package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
  41. package/dist/cjs/wallets/in-app/web/in-app.js +69 -0
  42. package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -0
  43. package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js +219 -0
  44. package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -0
  45. package/dist/cjs/wallets/in-app/web/lib/auth/index.js +121 -208
  46. package/dist/cjs/wallets/in-app/web/lib/auth/index.js.map +1 -1
  47. package/dist/cjs/wallets/in-app/web/lib/web-connector.js +3 -4
  48. package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
  49. package/dist/cjs/wallets/manager/index.js +2 -2
  50. package/dist/cjs/wallets/manager/index.js.map +1 -1
  51. package/dist/cjs/wallets/native/create-wallet.js +174 -0
  52. package/dist/cjs/wallets/native/create-wallet.js.map +1 -0
  53. package/dist/cjs/wallets/smart/smart-wallet.js +103 -0
  54. package/dist/cjs/wallets/smart/smart-wallet.js.map +1 -0
  55. package/dist/esm/exports/react-native/wallets/in-app.js +9 -0
  56. package/dist/esm/exports/react-native/wallets/in-app.js.map +1 -0
  57. package/dist/esm/exports/react-native/wallets.js +23 -0
  58. package/dist/esm/exports/react-native/wallets.js.map +1 -0
  59. package/dist/esm/exports/wallets/embedded.js +3 -2
  60. package/dist/esm/exports/wallets/embedded.js.map +1 -1
  61. package/dist/esm/exports/wallets/in-app.js +4 -2
  62. package/dist/esm/exports/wallets/in-app.js.map +1 -1
  63. package/dist/esm/exports/wallets/smart.js +1 -1
  64. package/dist/esm/exports/wallets/smart.js.map +1 -1
  65. package/dist/esm/exports/wallets.js +5 -2
  66. package/dist/esm/exports/wallets.js.map +1 -1
  67. package/dist/esm/react/web/ui/ConnectWallet/Details.js +1 -1
  68. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  69. package/dist/esm/react/web/wallets/in-app/InAppWalletOTPLoginUI.js +1 -1
  70. package/dist/esm/react/web/wallets/in-app/InAppWalletOTPLoginUI.js.map +1 -1
  71. package/dist/esm/version.js +1 -1
  72. package/dist/esm/version.js.map +1 -1
  73. package/dist/esm/wallets/coinbase/coinbase-wallet.js +83 -0
  74. package/dist/esm/wallets/coinbase/coinbase-wallet.js.map +1 -0
  75. package/dist/esm/wallets/coinbase/coinbaseMobileSDK.js +16 -1
  76. package/dist/esm/wallets/coinbase/coinbaseMobileSDK.js.map +1 -1
  77. package/dist/esm/wallets/coinbase/coinbaseSDKWallet.js +10 -19
  78. package/dist/esm/wallets/coinbase/coinbaseSDKWallet.js.map +1 -1
  79. package/dist/esm/wallets/create-wallet.js +9 -295
  80. package/dist/esm/wallets/create-wallet.js.map +1 -1
  81. package/dist/esm/wallets/in-app/core/authentication/type.js +5 -0
  82. package/dist/esm/wallets/in-app/core/authentication/type.js.map +1 -1
  83. package/dist/esm/wallets/in-app/core/wallet/in-app-core.js +95 -0
  84. package/dist/esm/wallets/in-app/core/wallet/in-app-core.js.map +1 -0
  85. package/dist/esm/wallets/in-app/core/wallet/index.js +15 -7
  86. package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
  87. package/dist/esm/wallets/in-app/{core/authentication → native/auth}/index.js +14 -40
  88. package/dist/esm/wallets/in-app/native/auth/index.js.map +1 -0
  89. package/dist/esm/wallets/in-app/native/{auth.js → auth/native-auth.js} +9 -9
  90. package/dist/esm/wallets/in-app/native/auth/native-auth.js.map +1 -0
  91. package/dist/esm/wallets/in-app/native/in-app.js +65 -0
  92. package/dist/esm/wallets/in-app/native/in-app.js.map +1 -0
  93. package/dist/esm/wallets/in-app/native/native-connector.js +2 -3
  94. package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
  95. package/dist/esm/wallets/in-app/web/in-app.js +65 -0
  96. package/dist/esm/wallets/in-app/web/in-app.js.map +1 -0
  97. package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js +215 -0
  98. package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -0
  99. package/dist/esm/wallets/in-app/web/lib/auth/index.js +115 -206
  100. package/dist/esm/wallets/in-app/web/lib/auth/index.js.map +1 -1
  101. package/dist/esm/wallets/in-app/web/lib/web-connector.js +2 -3
  102. package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
  103. package/dist/esm/wallets/manager/index.js +1 -1
  104. package/dist/esm/wallets/manager/index.js.map +1 -1
  105. package/dist/esm/wallets/native/create-wallet.js +169 -0
  106. package/dist/esm/wallets/native/create-wallet.js.map +1 -0
  107. package/dist/esm/wallets/smart/smart-wallet.js +99 -0
  108. package/dist/esm/wallets/smart/smart-wallet.js.map +1 -0
  109. package/dist/types/exports/react-native/wallets/in-app.d.ts +5 -0
  110. package/dist/types/exports/react-native/wallets/in-app.d.ts.map +1 -0
  111. package/dist/types/exports/react-native/wallets.d.ts +47 -0
  112. package/dist/types/exports/react-native/wallets.d.ts.map +1 -0
  113. package/dist/types/exports/wallets/embedded.d.ts +3 -2
  114. package/dist/types/exports/wallets/embedded.d.ts.map +1 -1
  115. package/dist/types/exports/wallets/in-app.d.ts +3 -2
  116. package/dist/types/exports/wallets/in-app.d.ts.map +1 -1
  117. package/dist/types/exports/wallets/smart.d.ts +1 -1
  118. package/dist/types/exports/wallets/smart.d.ts.map +1 -1
  119. package/dist/types/exports/wallets.d.ts +4 -2
  120. package/dist/types/exports/wallets.d.ts.map +1 -1
  121. package/dist/types/version.d.ts +1 -1
  122. package/dist/types/version.d.ts.map +1 -1
  123. package/dist/types/wallets/coinbase/coinbase-wallet.d.ts +15 -0
  124. package/dist/types/wallets/coinbase/coinbase-wallet.d.ts.map +1 -0
  125. package/dist/types/wallets/coinbase/coinbaseMobileSDK.d.ts +7 -7
  126. package/dist/types/wallets/coinbase/coinbaseMobileSDK.d.ts.map +1 -1
  127. package/dist/types/wallets/coinbase/coinbaseSDKWallet.d.ts +6 -2
  128. package/dist/types/wallets/coinbase/coinbaseSDKWallet.d.ts.map +1 -1
  129. package/dist/types/wallets/create-wallet.d.ts +0 -74
  130. package/dist/types/wallets/create-wallet.d.ts.map +1 -1
  131. package/dist/types/wallets/in-app/core/authentication/type.d.ts +4 -0
  132. package/dist/types/wallets/in-app/core/authentication/type.d.ts.map +1 -1
  133. package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts +16 -0
  134. package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts.map +1 -0
  135. package/dist/types/wallets/in-app/core/wallet/index.d.ts +3 -2
  136. package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
  137. package/dist/types/wallets/in-app/{core/authentication → native/auth}/index.d.ts +3 -12
  138. package/dist/types/wallets/in-app/native/auth/index.d.ts.map +1 -0
  139. package/dist/types/wallets/in-app/native/{auth.d.ts → auth/native-auth.d.ts} +3 -3
  140. package/dist/types/wallets/in-app/native/auth/native-auth.d.ts.map +1 -0
  141. package/dist/types/wallets/in-app/native/in-app.d.ts +56 -0
  142. package/dist/types/wallets/in-app/native/in-app.d.ts.map +1 -0
  143. package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
  144. package/dist/types/wallets/in-app/web/in-app.d.ts +56 -0
  145. package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -0
  146. package/dist/types/wallets/in-app/web/lib/auth/iframe-auth.d.ts +141 -0
  147. package/dist/types/wallets/in-app/web/lib/auth/iframe-auth.d.ts.map +1 -0
  148. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts +78 -137
  149. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts.map +1 -1
  150. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts +1 -1
  151. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
  152. package/dist/types/wallets/manager/index.d.ts.map +1 -1
  153. package/dist/types/wallets/native/create-wallet.d.ts +36 -0
  154. package/dist/types/wallets/native/create-wallet.d.ts.map +1 -0
  155. package/dist/types/wallets/smart/smart-wallet.d.ts +24 -0
  156. package/dist/types/wallets/smart/smart-wallet.d.ts.map +1 -0
  157. package/package.json +3 -1
  158. package/src/exports/react-native/wallets/in-app.ts +18 -0
  159. package/src/exports/react-native/wallets.ts +102 -0
  160. package/src/exports/wallets/embedded.ts +4 -3
  161. package/src/exports/wallets/in-app.ts +6 -3
  162. package/src/exports/wallets/smart.ts +1 -1
  163. package/src/exports/wallets.ts +7 -3
  164. package/src/react/web/ui/ConnectWallet/Details.tsx +1 -1
  165. package/src/react/web/wallets/in-app/InAppWalletOTPLoginUI.tsx +1 -1
  166. package/src/version.ts +1 -1
  167. package/src/wallets/coinbase/coinbase-wallet.ts +108 -0
  168. package/src/wallets/coinbase/coinbaseMobileSDK.ts +23 -1
  169. package/src/wallets/coinbase/coinbaseSDKWallet.ts +10 -21
  170. package/src/wallets/create-wallet.ts +9 -359
  171. package/src/wallets/in-app/core/authentication/type.ts +13 -0
  172. package/src/wallets/in-app/core/wallet/in-app-core.ts +134 -0
  173. package/src/wallets/in-app/core/wallet/index.ts +17 -6
  174. package/src/wallets/in-app/{core/authentication → native/auth}/index.ts +15 -57
  175. package/src/wallets/in-app/native/{auth.ts → auth/native-auth.ts} +10 -10
  176. package/src/wallets/in-app/native/in-app.ts +70 -0
  177. package/src/wallets/in-app/native/native-connector.ts +2 -2
  178. package/src/wallets/in-app/web/in-app.ts +70 -0
  179. package/src/wallets/in-app/web/lib/auth/iframe-auth.ts +266 -0
  180. package/src/wallets/in-app/web/lib/auth/index.ts +124 -249
  181. package/src/wallets/in-app/web/lib/web-connector.ts +2 -2
  182. package/src/wallets/manager/index.ts +1 -1
  183. package/src/wallets/native/create-wallet.ts +224 -0
  184. package/src/wallets/smart/smart-wallet-integration.test.ts +1 -1
  185. package/src/wallets/smart/smart-wallet-zksync.test.ts +1 -1
  186. package/src/wallets/smart/smart-wallet.ts +123 -0
  187. package/dist/cjs/wallets/in-app/core/authentication/index.js.map +0 -1
  188. package/dist/cjs/wallets/in-app/native/auth.js.map +0 -1
  189. package/dist/esm/wallets/in-app/core/authentication/index.js.map +0 -1
  190. package/dist/esm/wallets/in-app/native/auth.js.map +0 -1
  191. package/dist/types/wallets/in-app/core/authentication/index.d.ts.map +0 -1
  192. package/dist/types/wallets/in-app/native/auth.d.ts.map +0 -1
@@ -1,266 +1,141 @@
1
1
  import type { ThirdwebClient } from "../../../../../client/client.js";
2
- import type {
3
- AuthAndWalletRpcReturnType,
4
- AuthLoginReturnType,
5
- AuthStoredTokenWithCookieReturnType,
6
- LogoutReturnType,
7
- SendEmailOtpReturnType,
2
+ import {
3
+ type AuthArgsType,
4
+ type AuthLoginReturnType,
5
+ type GetAuthenticatedUserParams,
6
+ type PreAuthArgsType,
7
+ UserWalletStatus,
8
8
  } from "../../../core/authentication/type.js";
9
- import type { ClientIdWithQuerierType } from "../../types.js";
10
- import { LocalStorage } from "../../utils/Storage/LocalStorage.js";
11
- import type { InAppWalletIframeCommunicator } from "../../utils/iFrameCommunication/InAppWalletIframeCommunicator.js";
12
- import { BaseLogin } from "./base-login.js";
9
+ import { getOrCreateInAppWalletConnector } from "../../../core/wallet/in-app-core.js";
13
10
 
14
- export type AuthQuerierTypes = {
15
- logout: undefined;
16
- initIframe: {
17
- clientId: string;
18
- authCookie: string;
19
- walletUserId: string;
20
- deviceShareStored: string;
21
- };
22
- loginWithStoredTokenDetails: {
23
- storedToken: AuthStoredTokenWithCookieReturnType["storedToken"];
24
- recoveryCode?: string;
25
- };
26
- };
11
+ // ---- KEEP IN SYNC WITH /wallets/in-app/native/auth/index.ts ---- //
12
+ // duplication needed for separate exports between web and native
27
13
 
28
14
  /**
29
- *
15
+ * @internal
30
16
  */
31
- export class Auth {
32
- protected client: ThirdwebClient;
33
- protected AuthQuerier: InAppWalletIframeCommunicator<AuthQuerierTypes>;
34
- protected localStorage: LocalStorage;
35
- protected onAuthSuccess: (
36
- authResults: AuthAndWalletRpcReturnType,
37
- ) => Promise<AuthLoginReturnType>;
38
- private BaseLogin: BaseLogin;
39
-
40
- /**
41
- * Used to manage the user's auth states. This should not be instantiated directly.
42
- * Call {@link InAppWalletSdk.auth} instead.
43
- * @internal
44
- */
45
- constructor({
46
- client,
47
- querier,
48
- onAuthSuccess,
49
- baseUrl,
50
- }: ClientIdWithQuerierType & {
51
- baseUrl: string;
52
- onAuthSuccess: (
53
- authDetails: AuthAndWalletRpcReturnType,
54
- ) => Promise<AuthLoginReturnType>;
55
- }) {
56
- this.client = client;
57
-
58
- this.AuthQuerier = querier;
59
- this.localStorage = new LocalStorage({ clientId: client.clientId });
60
- this.onAuthSuccess = onAuthSuccess;
61
- this.BaseLogin = new BaseLogin({
62
- postLogin: async (result) => {
63
- return this.postLogin(result);
64
- },
65
- preLogin: async () => {
66
- await this.preLogin();
67
- },
68
- querier: querier,
69
- client,
70
- baseUrl,
17
+ async function getInAppWalletConnector(client: ThirdwebClient) {
18
+ return getOrCreateInAppWalletConnector(client, async (client) => {
19
+ const { InAppWebConnector } = await import("../web-connector.js");
20
+ return new InAppWebConnector({
21
+ client: client,
71
22
  });
72
- }
73
-
74
- private async preLogin() {
75
- await this.logout();
76
- }
23
+ });
24
+ }
77
25
 
78
- private async postLogin({
79
- storedToken,
80
- walletDetails,
81
- }: AuthAndWalletRpcReturnType): Promise<AuthLoginReturnType> {
82
- if (storedToken.shouldStoreCookieString) {
83
- await this.localStorage.saveAuthCookie(storedToken.cookieString);
26
+ /**
27
+ * Retrieves the authenticated user for the active in-app wallet.
28
+ * @param options - The arguments for retrieving the authenticated user.
29
+ * @returns The authenticated user if logged in and wallet initialized, otherwise undefined.
30
+ * @example
31
+ * ```ts
32
+ * import { getAuthenticatedUser } from "thirdweb/wallets/in-app";
33
+ *
34
+ * const user = await getAuthenticatedUser({ client });
35
+ * if (user) {
36
+ * console.log(user.walletAddress);
37
+ * }
38
+ * ```
39
+ * @wallet
40
+ */
41
+ export async function getAuthenticatedUser(
42
+ options: GetAuthenticatedUserParams,
43
+ ) {
44
+ const { client } = options;
45
+ const connector = await getInAppWalletConnector(client);
46
+ const user = await connector.getUser();
47
+ switch (user.status) {
48
+ case UserWalletStatus.LOGGED_IN_WALLET_INITIALIZED: {
49
+ return user;
84
50
  }
85
- const initializedUser = await this.onAuthSuccess({
86
- storedToken,
87
- walletDetails,
88
- });
89
- return initializedUser;
90
- }
91
-
92
- async loginWithAuthToken(
93
- authToken: AuthStoredTokenWithCookieReturnType,
94
- recoveryCode?: string,
95
- ): Promise<AuthLoginReturnType> {
96
- await this.preLogin();
97
- const result = await this.AuthQuerier.call<AuthAndWalletRpcReturnType>({
98
- procedureName: "loginWithStoredTokenDetails",
99
- params: {
100
- storedToken: authToken.storedToken,
101
- recoveryCode,
102
- },
103
- });
104
- return this.postLogin(result);
105
- }
106
-
107
- /**
108
- * Used to log the user into their thirdweb wallet on your platform via a myriad of auth providers
109
- * @example
110
- * ```typescript
111
- * const thirdwebInAppWallet = new InAppWalletSdk({clientId: "YOUR_CLIENT_ID", chain: "Polygon"})
112
- * try {
113
- * const user = await thirdwebInAppWallet.auth.loginWithModal();
114
- * // user is now logged in
115
- * } catch (e) {
116
- * // User closed modal or something else went wrong during the authentication process
117
- * console.error(e)
118
- * }
119
- * ```
120
- * @returns `{{user: InitializedUser}}` An InitializedUser object.
121
- */
122
- async loginWithModal(): Promise<AuthLoginReturnType> {
123
- return this.BaseLogin.loginWithModal();
124
- }
125
-
126
- /**
127
- * Used to log the user into their thirdweb wallet using email OTP
128
- * @example
129
- * ```typescript
130
- * // Basic Flow
131
- * const thirdwebInAppWallet = new InAppWalletSdk({clientId: "", chain: "Polygon"});
132
- * try {
133
- * // prompts user to enter the code they received
134
- * const user = await thirdwebInAppWallet.auth.loginWithThirdwebEmailOtp({ email : "you@example.com" });
135
- * // user is now logged in
136
- * } catch (e) {
137
- * // User closed the OTP modal or something else went wrong during the authentication process
138
- * console.error(e)
139
- * }
140
- * ```
141
- * @param args - args.email: We will send the email an OTP that needs to be entered in order for them to be logged in.
142
- * @returns `{{user: InitializedUser}}` An InitializedUser object. See {@link InAppWalletSdk.getUser} for more
143
- */
144
- async loginWithEmailOtp(
145
- args: Parameters<BaseLogin["loginWithEmailOtp"]>[0],
146
- ): Promise<AuthLoginReturnType> {
147
- return this.BaseLogin.loginWithEmailOtp(args);
148
- }
149
-
150
- /**
151
- * @internal
152
- */
153
- async loginWithCustomJwt(
154
- args: Parameters<BaseLogin["loginWithCustomJwt"]>[0],
155
- ): Promise<AuthLoginReturnType> {
156
- return this.BaseLogin.loginWithCustomJwt(args);
157
- }
158
-
159
- /**
160
- * @internal
161
- */
162
- async loginWithCustomAuthEndpoint(
163
- args: Parameters<BaseLogin["loginWithCustomAuthEndpoint"]>[0],
164
- ): Promise<AuthLoginReturnType> {
165
- return this.BaseLogin.loginWithCustomAuthEndpoint(args);
166
- }
167
-
168
- /**
169
- * @internal
170
- */
171
- async loginWithOauth(
172
- args: Parameters<BaseLogin["loginWithOauth"]>[0],
173
- ): Promise<AuthLoginReturnType> {
174
- return this.BaseLogin.loginWithOauth(args);
175
- }
176
-
177
- /**
178
- * A headless way to send the users at the passed email an OTP code.
179
- * You need to then call {@link Auth.verifyEmailLoginOtp} in order to complete the login process
180
- * @example
181
- * @param param0.email
182
- * ```typescript
183
- * const thirdwebInAppWallet = new InAppWalletSdk({clientId: "", chain: "Polygon"});
184
- * // sends user an OTP code
185
- * try {
186
- * await thirdwebInAppWallet.auth.sendEmailLoginOtp({ email : "you@example.com" });
187
- * } catch(e) {
188
- * // Error Sending user's email an OTP code
189
- * console.error(e);
190
- * }
191
- *
192
- * // Then when your user is ready to verify their OTP
193
- * try {
194
- * const user = await thirdwebInAppWallet.auth.verifyEmailLoginOtp({ email: "you@example.com", otp: "6-DIGIT_CODE_HERE" });
195
- * } catch(e) {
196
- * // Error verifying the OTP code
197
- * console.error(e)
198
- * }
199
- * ```
200
- * @param param0 - param0.email We will send the email an OTP that needs to be entered in order for them to be logged in.
201
- * @returns `{{ isNewUser: boolean }}` IsNewUser indicates if the user is a new user to your platform
202
- * @internal
203
- */
204
- async sendEmailLoginOtp({
205
- email,
206
- }: Parameters<
207
- BaseLogin["sendEmailLoginOtp"]
208
- >[0]): Promise<SendEmailOtpReturnType> {
209
- return this.BaseLogin.sendEmailLoginOtp({
210
- email,
211
- });
212
- }
213
-
214
- /**
215
- * @internal
216
- */
217
- async sendSmsLoginOtp({
218
- phoneNumber,
219
- }: Parameters<
220
- BaseLogin["sendSmsLoginOtp"]
221
- >[0]): Promise<SendEmailOtpReturnType> {
222
- return this.BaseLogin.sendSmsLoginOtp({
223
- phoneNumber,
224
- });
225
51
  }
52
+ return undefined;
53
+ }
226
54
 
227
- /**
228
- * Used to verify the otp that the user receives from thirdweb
229
- *
230
- * See {@link Auth.sendEmailLoginOtp} for how the headless call flow looks like. Simply swap out the calls to `loginWithThirdwebEmailOtp` with `verifyThirdwebEmailLoginOtp`
231
- * @param args - props.email We will send the email an OTP that needs to be entered in order for them to be logged in.
232
- * props.otp The code that the user received in their email
233
- * @returns `{{user: InitializedUser}}` An InitializedUser object containing the user's status, wallet, authDetails, and more
234
- * @internal
235
- */
236
- async verifyEmailLoginOtp(
237
- args: Parameters<BaseLogin["verifyEmailLoginOtp"]>[0],
238
- ) {
239
- return this.BaseLogin.verifyEmailLoginOtp(args);
55
+ /**
56
+ * Retrieves the authenticated user email for the active in-app wallet.
57
+ * @param options - The arguments for retrieving the authenticated user.
58
+ * @returns The authenticated user email if logged in and wallet initialized, otherwise undefined.
59
+ * @example
60
+ * ```ts
61
+ * import { getUserEmail } from "thirdweb/wallets/in-app";
62
+ *
63
+ * const email = await getUserEmail({ client });
64
+ * console.log(email);
65
+ * ```
66
+ * @wallet
67
+ */
68
+ export async function getUserEmail(options: GetAuthenticatedUserParams) {
69
+ const user = await getAuthenticatedUser(options);
70
+ if (user && "email" in user.authDetails) {
71
+ return user.authDetails.email;
240
72
  }
73
+ return undefined;
74
+ }
241
75
 
242
- /**
243
- * @internal
244
- */
245
- async verifySmsLoginOtp(args: Parameters<BaseLogin["verifySmsLoginOtp"]>[0]) {
246
- return this.BaseLogin.verifySmsLoginOtp(args);
76
+ /**
77
+ * Retrieves the authenticated user phone number for the active embedded wallet.
78
+ * @param options - The arguments for retrieving the authenticated user.
79
+ * @returns The authenticated user phone number if authenticated with phone number, otherwise undefined.
80
+ * @example
81
+ * ```ts
82
+ * import { getUserPhoneNumber } from "thirdweb/wallets/embedded";
83
+ *
84
+ * const phoneNumber = await getUserPhoneNumber({ client });
85
+ * console.log(phoneNumber);
86
+ * ```
87
+ * @wallet
88
+ */
89
+ export async function getUserPhoneNumber(options: GetAuthenticatedUserParams) {
90
+ const user = await getAuthenticatedUser(options);
91
+ if (user && "phoneNumber" in user.authDetails) {
92
+ return user.authDetails.phoneNumber;
247
93
  }
94
+ return undefined;
95
+ }
248
96
 
249
- /**
250
- * Logs any existing user out of their wallet.
251
- * @returns `{{success: boolean}}` true if a user is successfully logged out. false if there's no user currently logged in.
252
- * @internal
253
- */
254
- async logout(): Promise<LogoutReturnType> {
255
- const { success } = await this.AuthQuerier.call<LogoutReturnType>({
256
- procedureName: "logout",
257
- params: undefined,
258
- });
259
- const isRemoveAuthCookie = await this.localStorage.removeAuthCookie();
260
- const isRemoveUserId = await this.localStorage.removeWalletUserId();
97
+ /**
98
+ * Pre-authenticates the user based on the provided authentication strategy.
99
+ * @param args - The arguments required for pre-authentication.
100
+ * @returns A promise that resolves to the pre-authentication result.
101
+ * @throws An error if the provided authentication strategy doesn't require pre-authentication.
102
+ * @example
103
+ * ```ts
104
+ * import { preAuthenticate } from "thirdweb/wallets/in-app";
105
+ *
106
+ * const result = await preAuthenticate({
107
+ * client,
108
+ * strategy: "email",
109
+ * email: "example@example.org",
110
+ * });
111
+ * ```
112
+ * @wallet
113
+ */
114
+ export async function preAuthenticate(args: PreAuthArgsType) {
115
+ const connector = await getInAppWalletConnector(args.client);
116
+ return connector.preAuthenticate(args);
117
+ }
261
118
 
262
- return {
263
- success: success || isRemoveAuthCookie || isRemoveUserId,
264
- };
265
- }
119
+ /**
120
+ * Authenticates the user based on the provided authentication arguments.
121
+ * @param args - The authentication arguments.
122
+ * @returns A promise that resolves to the authentication result.
123
+ * @example
124
+ * ```ts
125
+ * import { authenticate } from "thirdweb/wallets/in-app";
126
+ *
127
+ * const result = await authenticate({
128
+ * client,
129
+ * strategy: "email",
130
+ * email: "example@example.org",
131
+ * verificationCode: "123456",
132
+ * });
133
+ * ```
134
+ * @wallet
135
+ */
136
+ export async function authenticate(
137
+ args: AuthArgsType,
138
+ ): Promise<AuthLoginReturnType> {
139
+ const connector = await getInAppWalletConnector(args.client);
140
+ return connector.authenticate(args);
266
141
  }
@@ -1,7 +1,6 @@
1
1
  import type { ThirdwebClient } from "../../../../client/client.js";
2
2
  import { getThirdwebBaseUrl } from "../../../../utils/domains.js";
3
3
  import type { Account } from "../../../interfaces/wallet.js";
4
- import { oauthStrategyToAuthProvider } from "../../core/authentication/index.js";
5
4
  import {
6
5
  type AuthArgsType,
7
6
  type AuthLoginReturnType,
@@ -10,11 +9,12 @@ import {
10
9
  type PreAuthArgsType,
11
10
  type SendEmailOtpReturnType,
12
11
  UserWalletStatus,
12
+ oauthStrategyToAuthProvider,
13
13
  } from "../../core/authentication/type.js";
14
14
  import type { InAppConnector } from "../../core/interfaces/connector.js";
15
15
  import type { InAppWalletConstructorType } from "../types.js";
16
16
  import { InAppWalletIframeCommunicator } from "../utils/iFrameCommunication/InAppWalletIframeCommunicator.js";
17
- import { Auth, type AuthQuerierTypes } from "./auth/index.js";
17
+ import { Auth, type AuthQuerierTypes } from "./auth/iframe-auth.js";
18
18
  import { loginWithPasskey, registerPasskey } from "./auth/passkeys.js";
19
19
  import { IFrameWallet } from "./in-app-account.js";
20
20
 
@@ -4,8 +4,8 @@ import { hasSmartAccount } from "../../react/web/utils/isSmartWallet.js";
4
4
  import { computedStore } from "../../reactive/computedStore.js";
5
5
  import { effect } from "../../reactive/effect.js";
6
6
  import { createStore } from "../../reactive/store.js";
7
- import { smartWallet } from "../create-wallet.js";
8
7
  import type { Account, Wallet } from "../interfaces/wallet.js";
8
+ import { smartWallet } from "../smart/smart-wallet.js";
9
9
  import type { SmartWalletOptions } from "../smart/types.js";
10
10
  import type { AsyncStorage } from "../storage/AsyncStorage.js";
11
11
  import { deleteConnectParamsFromStorage } from "../storage/walletStorage.js";
@@ -0,0 +1,224 @@
1
+ // TODO: figure out how to define the type without tuple args type and using function overloads
2
+
3
+ import { trackConnect } from "../../analytics/track.js";
4
+ import type { Chain } from "../../chains/types.js";
5
+ import type { WCSupportedWalletIds } from "../__generated__/wallet-ids.js";
6
+ import { coinbaseWalletSDK } from "../coinbase/coinbase-wallet.js";
7
+ import { getCoinbaseMobileProvider } from "../coinbase/coinbaseMobileSDK.js";
8
+ import { COINBASE } from "../constants.js";
9
+ import type { Account, Wallet } from "../interfaces/wallet.js";
10
+ import { smartWallet } from "../smart/smart-wallet.js";
11
+ import type { WCConnectOptions } from "../wallet-connect/types.js";
12
+ import { createWalletEmitter } from "../wallet-emitter.js";
13
+ import type {
14
+ CreateWalletArgs,
15
+ WalletAutoConnectionOption,
16
+ WalletId,
17
+ } from "../wallet-types.js";
18
+
19
+ /**
20
+ * Creates a wallet based on the provided ID and arguments.
21
+ * @param args - The arguments for creating the wallet.
22
+ * @returns - The created wallet.
23
+ * @example
24
+ * ```ts
25
+ * import { createWallet } from "thirdweb/wallets";
26
+ *
27
+ * const metamaskWallet = createWallet("io.metamask");
28
+ *
29
+ * const account = await metamaskWallet.connect({
30
+ * client,
31
+ * });
32
+ * ```
33
+ * @wallet
34
+ */
35
+ export function createWallet<const ID extends WalletId>(
36
+ ...args: CreateWalletArgs<ID>
37
+ ): Wallet<ID> {
38
+ const [id, creationOptions] = args;
39
+
40
+ switch (id) {
41
+ /**
42
+ * SMART WALLET
43
+ */
44
+ case "smart": {
45
+ // same as web
46
+ return smartWallet(
47
+ creationOptions as CreateWalletArgs<"smart">[1],
48
+ ) as Wallet<ID>;
49
+ }
50
+ /**
51
+ * IN-APP WALLET
52
+ */
53
+ case "embedded":
54
+ case "inApp": {
55
+ // TODO pass RN connector
56
+ throw new Error("TODO");
57
+ // return inAppWallet(
58
+ // creationOptions as CreateWalletArgs<"inApp">[1],
59
+ // ) as Wallet<ID>;
60
+ }
61
+
62
+ /**
63
+ * COINBASE WALLET VIA SDK
64
+ * -> if no injected coinbase found, we'll use the coinbase SDK
65
+ */
66
+ case COINBASE: {
67
+ const options = creationOptions as CreateWalletArgs<typeof COINBASE>[1];
68
+ return coinbaseWalletSDK({
69
+ createOptions: options,
70
+ providerFactory: () => getCoinbaseMobileProvider(options),
71
+ }) as Wallet<ID>;
72
+ }
73
+
74
+ /**
75
+ * WALLET CONNECT AND INJECTED WALLETS + walletConnect standalone
76
+ * TODO extract into a core + inject storage and link open callback
77
+ */
78
+ default: {
79
+ const emitter = createWalletEmitter<ID>();
80
+ let account: Account | undefined = undefined;
81
+ let chain: Chain | undefined = undefined;
82
+
83
+ const unsubscribeChain = emitter.subscribe("chainChanged", (newChain) => {
84
+ chain = newChain;
85
+ });
86
+
87
+ function reset() {
88
+ account = undefined;
89
+ chain = undefined;
90
+ }
91
+
92
+ let handleDisconnect = async () => {};
93
+
94
+ const unsubscribeDisconnect = emitter.subscribe("disconnect", () => {
95
+ reset();
96
+ unsubscribeChain();
97
+ unsubscribeDisconnect();
98
+ });
99
+
100
+ emitter.subscribe("accountChanged", (_account) => {
101
+ account = _account;
102
+ });
103
+
104
+ let handleSwitchChain: (chain: Chain) => Promise<void> = async () => {
105
+ throw new Error("Not implemented yet");
106
+ };
107
+
108
+ const wallet: Wallet<ID> = {
109
+ id,
110
+ subscribe: emitter.subscribe,
111
+ getConfig: () => args[1],
112
+ getChain: () => chain,
113
+ getAccount: () => account,
114
+ autoConnect: async (
115
+ options: WalletAutoConnectionOption<WCSupportedWalletIds>,
116
+ ) => {
117
+ if (options && "client" in options) {
118
+ const { autoConnectWC } = await import(
119
+ "../wallet-connect/controller.js"
120
+ );
121
+
122
+ const [
123
+ connectedAccount,
124
+ connectedChain,
125
+ doDisconnect,
126
+ doSwitchChain,
127
+ ] = await autoConnectWC(
128
+ options,
129
+ emitter,
130
+ wallet.id as WCSupportedWalletIds,
131
+ );
132
+ // set the states
133
+ account = connectedAccount;
134
+ chain = connectedChain;
135
+ handleDisconnect = doDisconnect;
136
+ handleSwitchChain = doSwitchChain;
137
+ trackConnect({
138
+ client: options.client,
139
+ walletType: id,
140
+ walletAddress: account.address,
141
+ });
142
+ // return account
143
+ return account;
144
+ }
145
+ throw new Error("Failed to auto connect");
146
+ },
147
+ connect: async (options) => {
148
+ async function wcConnect(wcOptions: WCConnectOptions) {
149
+ const { connectWC } = await import(
150
+ "../wallet-connect/controller.js"
151
+ );
152
+
153
+ const [
154
+ connectedAccount,
155
+ connectedChain,
156
+ doDisconnect,
157
+ doSwitchChain,
158
+ ] = await connectWC(
159
+ wcOptions,
160
+ emitter,
161
+ wallet.id as WCSupportedWalletIds | "walletConnect",
162
+ );
163
+ // set the states
164
+ account = connectedAccount;
165
+ chain = connectedChain;
166
+ handleDisconnect = doDisconnect;
167
+ handleSwitchChain = doSwitchChain;
168
+ trackConnect({
169
+ client: wcOptions.client,
170
+ walletType: id,
171
+ walletAddress: account.address,
172
+ });
173
+ return account;
174
+ }
175
+
176
+ if (id === "walletConnect") {
177
+ const { client, chain: _chain, ...walletConnectOptions } = options;
178
+
179
+ return wcConnect({
180
+ client,
181
+ chain: _chain,
182
+ walletConnect: {
183
+ ...walletConnectOptions,
184
+ },
185
+ });
186
+ }
187
+
188
+ if (options && "client" in options) {
189
+ return wcConnect(options);
190
+ }
191
+ throw new Error("Failed to connect");
192
+ },
193
+ // these get overridden in connect and autoConnect
194
+ disconnect: async () => {
195
+ reset();
196
+ await handleDisconnect();
197
+ },
198
+ switchChain: (c) => handleSwitchChain(c),
199
+ };
200
+ return wallet;
201
+ }
202
+ }
203
+ }
204
+
205
+ /**
206
+ * Creates a wallet that allows connecting to any wallet that supports the WalletConnect protocol.
207
+ * @returns The created smart wallet.
208
+ * @example
209
+ * ```ts
210
+ * import { walletConnect } from "thirdweb/wallets";
211
+ *
212
+ * const wallet = walletConnect();
213
+ *
214
+ * const account = await wallet.connect({
215
+ * client
216
+ * });
217
+ * ```
218
+ * @wallet
219
+ */
220
+ export function walletConnect() {
221
+ return createWallet("walletConnect");
222
+ }
223
+
224
+ // TODO in-app wallet
@@ -18,9 +18,9 @@ import { estimateGasCost } from "../../transaction/actions/estimate-gas-cost.js"
18
18
  import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
19
19
  import { sendBatchTransaction } from "../../transaction/actions/send-batch-transaction.js";
20
20
  import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
21
- import { smartWallet } from "../create-wallet.js";
22
21
  import type { Account, Wallet } from "../interfaces/wallet.js";
23
22
  import { generateAccount } from "../utils/generateAccount.js";
23
+ import { smartWallet } from "./smart-wallet.js";
24
24
 
25
25
  let wallet: Wallet;
26
26
  let smartAccount: Account;
@@ -7,9 +7,9 @@ import { getContract } from "../../contract/contract.js";
7
7
  import { claimTo } from "../../extensions/erc1155/drops/write/claimTo.js";
8
8
  import { sendTransaction } from "../../transaction/actions/send-transaction.js";
9
9
  import { prepareTransaction } from "../../transaction/prepare-transaction.js";
10
- import { smartWallet } from "../create-wallet.js";
11
10
  import type { Account, Wallet } from "../interfaces/wallet.js";
12
11
  import { privateKeyToAccount } from "../private-key.js";
12
+ import { smartWallet } from "./smart-wallet.js";
13
13
 
14
14
  let wallet: Wallet;
15
15
  let smartAccount: Account;