thirdweb 5.29.3-nightly-ffaff744f72d2cb22896e7501677b48f76ea857a-20240614184424 → 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.
- package/dist/cjs/exports/react-native/wallets/in-app.js +17 -0
- package/dist/cjs/exports/react-native/wallets/in-app.js.map +1 -0
- package/dist/cjs/exports/react-native/wallets.js +4 -2
- package/dist/cjs/exports/react-native/wallets.js.map +1 -1
- package/dist/cjs/exports/wallets/embedded.js +4 -4
- package/dist/cjs/exports/wallets/embedded.js.map +1 -1
- package/dist/cjs/exports/wallets/in-app.js +4 -3
- package/dist/cjs/exports/wallets/in-app.js.map +1 -1
- package/dist/cjs/exports/wallets.js +6 -4
- package/dist/cjs/exports/wallets.js.map +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js +1 -1
- package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/cjs/react/web/wallets/in-app/InAppWalletOTPLoginUI.js +1 -1
- package/dist/cjs/react/web/wallets/in-app/InAppWalletOTPLoginUI.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/create-wallet.js +3 -128
- package/dist/cjs/wallets/create-wallet.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/type.js +6 -1
- package/dist/cjs/wallets/in-app/core/authentication/type.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js +100 -0
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js.map +1 -0
- package/dist/cjs/wallets/in-app/core/wallet/index.js +14 -6
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/cjs/wallets/in-app/{core/authentication → native/auth}/index.js +15 -42
- package/dist/cjs/wallets/in-app/native/auth/index.js.map +1 -0
- package/dist/cjs/wallets/in-app/native/{auth.js → auth/native-auth.js} +9 -9
- package/dist/cjs/wallets/in-app/native/auth/native-auth.js.map +1 -0
- package/dist/cjs/wallets/in-app/native/in-app.js +69 -0
- package/dist/cjs/wallets/in-app/native/in-app.js.map +1 -0
- package/dist/cjs/wallets/in-app/native/native-connector.js +9 -10
- package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/in-app.js +69 -0
- package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -0
- package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js +219 -0
- package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -0
- package/dist/cjs/wallets/in-app/web/lib/auth/index.js +121 -208
- package/dist/cjs/wallets/in-app/web/lib/auth/index.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js +3 -4
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/esm/exports/react-native/wallets/in-app.js +9 -0
- package/dist/esm/exports/react-native/wallets/in-app.js.map +1 -0
- package/dist/esm/exports/react-native/wallets.js +3 -3
- package/dist/esm/exports/react-native/wallets.js.map +1 -1
- package/dist/esm/exports/wallets/embedded.js +3 -2
- package/dist/esm/exports/wallets/embedded.js.map +1 -1
- package/dist/esm/exports/wallets/in-app.js +4 -2
- package/dist/esm/exports/wallets/in-app.js.map +1 -1
- package/dist/esm/exports/wallets.js +4 -2
- package/dist/esm/exports/wallets.js.map +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js +1 -1
- package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
- package/dist/esm/react/web/wallets/in-app/InAppWalletOTPLoginUI.js +1 -1
- package/dist/esm/react/web/wallets/in-app/InAppWalletOTPLoginUI.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/create-wallet.js +1 -125
- package/dist/esm/wallets/create-wallet.js.map +1 -1
- package/dist/esm/wallets/in-app/core/authentication/type.js +5 -0
- package/dist/esm/wallets/in-app/core/authentication/type.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js +95 -0
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js.map +1 -0
- package/dist/esm/wallets/in-app/core/wallet/index.js +14 -6
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/wallets/in-app/{core/authentication → native/auth}/index.js +14 -40
- package/dist/esm/wallets/in-app/native/auth/index.js.map +1 -0
- package/dist/esm/wallets/in-app/native/{auth.js → auth/native-auth.js} +9 -9
- package/dist/esm/wallets/in-app/native/auth/native-auth.js.map +1 -0
- package/dist/esm/wallets/in-app/native/in-app.js +65 -0
- package/dist/esm/wallets/in-app/native/in-app.js.map +1 -0
- package/dist/esm/wallets/in-app/native/native-connector.js +2 -3
- package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
- package/dist/esm/wallets/in-app/web/in-app.js +65 -0
- package/dist/esm/wallets/in-app/web/in-app.js.map +1 -0
- package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js +215 -0
- package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -0
- package/dist/esm/wallets/in-app/web/lib/auth/index.js +115 -206
- package/dist/esm/wallets/in-app/web/lib/auth/index.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/web-connector.js +2 -3
- package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/types/exports/react-native/wallets/in-app.d.ts +5 -0
- package/dist/types/exports/react-native/wallets/in-app.d.ts.map +1 -0
- package/dist/types/exports/react-native/wallets.d.ts +1 -0
- package/dist/types/exports/react-native/wallets.d.ts.map +1 -1
- package/dist/types/exports/wallets/embedded.d.ts +3 -2
- package/dist/types/exports/wallets/embedded.d.ts.map +1 -1
- package/dist/types/exports/wallets/in-app.d.ts +3 -2
- package/dist/types/exports/wallets/in-app.d.ts.map +1 -1
- package/dist/types/exports/wallets.d.ts +3 -2
- package/dist/types/exports/wallets.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/create-wallet.d.ts +0 -53
- package/dist/types/wallets/create-wallet.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/authentication/type.d.ts +4 -0
- package/dist/types/wallets/in-app/core/authentication/type.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts +16 -0
- package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts.map +1 -0
- package/dist/types/wallets/in-app/core/wallet/index.d.ts +3 -2
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/{core/authentication → native/auth}/index.d.ts +3 -12
- package/dist/types/wallets/in-app/native/auth/index.d.ts.map +1 -0
- package/dist/types/wallets/in-app/native/{auth.d.ts → auth/native-auth.d.ts} +3 -3
- package/dist/types/wallets/in-app/native/auth/native-auth.d.ts.map +1 -0
- package/dist/types/wallets/in-app/native/in-app.d.ts +56 -0
- package/dist/types/wallets/in-app/native/in-app.d.ts.map +1 -0
- package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/in-app.d.ts +56 -0
- package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -0
- package/dist/types/wallets/in-app/web/lib/auth/iframe-auth.d.ts +141 -0
- package/dist/types/wallets/in-app/web/lib/auth/iframe-auth.d.ts.map +1 -0
- package/dist/types/wallets/in-app/web/lib/auth/index.d.ts +78 -137
- package/dist/types/wallets/in-app/web/lib/auth/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/lib/web-connector.d.ts +1 -1
- package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/exports/react-native/wallets/in-app.ts +18 -0
- package/src/exports/react-native/wallets.ts +3 -1
- package/src/exports/wallets/embedded.ts +4 -3
- package/src/exports/wallets/in-app.ts +6 -3
- package/src/exports/wallets.ts +6 -2
- package/src/react/web/ui/ConnectWallet/Details.tsx +1 -1
- package/src/react/web/wallets/in-app/InAppWalletOTPLoginUI.tsx +1 -1
- package/src/version.ts +1 -1
- package/src/wallets/create-wallet.ts +1 -146
- package/src/wallets/in-app/core/authentication/type.ts +13 -0
- package/src/wallets/in-app/core/wallet/in-app-core.ts +134 -0
- package/src/wallets/in-app/core/wallet/index.ts +16 -5
- package/src/wallets/in-app/{core/authentication → native/auth}/index.ts +15 -57
- package/src/wallets/in-app/native/{auth.ts → auth/native-auth.ts} +10 -10
- package/src/wallets/in-app/native/in-app.ts +70 -0
- package/src/wallets/in-app/native/native-connector.ts +2 -2
- package/src/wallets/in-app/web/in-app.ts +70 -0
- package/src/wallets/in-app/web/lib/auth/iframe-auth.ts +266 -0
- package/src/wallets/in-app/web/lib/auth/index.ts +124 -249
- package/src/wallets/in-app/web/lib/web-connector.ts +2 -2
- package/dist/cjs/wallets/in-app/core/authentication/index.js.map +0 -1
- package/dist/cjs/wallets/in-app/native/auth.js.map +0 -1
- package/dist/esm/wallets/in-app/core/authentication/index.js.map +0 -1
- package/dist/esm/wallets/in-app/native/auth.js.map +0 -1
- package/dist/types/wallets/in-app/core/authentication/index.d.ts.map +0 -1
- package/dist/types/wallets/in-app/native/auth.d.ts.map +0 -1
@@ -4,11 +4,12 @@ export {
|
|
4
4
|
* @deprecated use inAppWallet instead
|
5
5
|
*/
|
6
6
|
inAppWallet as embeddedWallet,
|
7
|
-
} from "../../wallets/
|
7
|
+
} from "../../wallets/in-app/web/in-app.js";
|
8
8
|
|
9
9
|
export {
|
10
10
|
preAuthenticate,
|
11
11
|
authenticate,
|
12
12
|
getUserEmail,
|
13
|
-
|
14
|
-
|
13
|
+
} from "../../wallets/in-app/web/lib/auth/index.js";
|
14
|
+
|
15
|
+
export { type GetAuthenticatedUserParams } from "../../wallets/in-app/core/authentication/type.js";
|
@@ -1,12 +1,15 @@
|
|
1
|
-
|
1
|
+
// --- KEEEP IN SYNC with exports/react-native/wallets/in-app ---
|
2
|
+
|
3
|
+
export { inAppWallet } from "../../wallets/in-app/web/in-app.js";
|
2
4
|
|
3
5
|
export {
|
4
6
|
preAuthenticate,
|
5
7
|
authenticate,
|
6
8
|
getUserEmail,
|
7
9
|
getUserPhoneNumber,
|
8
|
-
|
9
|
-
|
10
|
+
} from "../../wallets/in-app/web/lib/auth/index.js";
|
11
|
+
|
12
|
+
export { type GetAuthenticatedUserParams } from "../../wallets/in-app/core/authentication/type.js";
|
10
13
|
|
11
14
|
export { hasStoredPasskey } from "../../wallets/in-app/web/lib/auth/passkeys.js";
|
12
15
|
|
package/src/exports/wallets.ts
CHANGED
@@ -1,12 +1,16 @@
|
|
1
|
+
// --- KEEEP IN SYNC with exports/react-native/wallets.ts ---
|
2
|
+
|
1
3
|
export {
|
2
4
|
createWallet,
|
5
|
+
walletConnect,
|
6
|
+
} from "../wallets/create-wallet.js";
|
7
|
+
export {
|
3
8
|
inAppWallet,
|
4
9
|
/**
|
5
10
|
* @deprecated use inAppWallet instead
|
6
11
|
*/
|
7
12
|
inAppWallet as embeddedWallet,
|
8
|
-
|
9
|
-
} from "../wallets/create-wallet.js";
|
13
|
+
} from "../wallets/in-app/web/in-app.js";
|
10
14
|
export { smartWallet } from "../wallets/smart/smart-wallet.js";
|
11
15
|
|
12
16
|
export type { Wallet, Account } from "../wallets/interfaces/wallet.js";
|
@@ -916,7 +916,7 @@ function InAppWalletUserInfo(props: {
|
|
916
916
|
queryKey: ["in-app-wallet-user", client, account?.address],
|
917
917
|
queryFn: async () => {
|
918
918
|
const { getUserEmail, getUserPhoneNumber } = await import(
|
919
|
-
"../../../../wallets/in-app/
|
919
|
+
"../../../../wallets/in-app/web/lib/auth/index.js"
|
920
920
|
);
|
921
921
|
|
922
922
|
const [email, phone] = await Promise.all([
|
@@ -1,7 +1,7 @@
|
|
1
1
|
"use client";
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "react";
|
3
|
-
import { preAuthenticate } from "../../../../wallets/in-app/core/authentication/index.js";
|
4
3
|
import type { SendEmailOtpReturnType } from "../../../../wallets/in-app/core/authentication/type.js";
|
4
|
+
import { preAuthenticate } from "../../../../wallets/in-app/web/lib/auth/index.js";
|
5
5
|
import type { Wallet } from "../../../../wallets/interfaces/wallet.js";
|
6
6
|
import { useCustomTheme } from "../../../core/design-system/CustomThemeProvider.js";
|
7
7
|
import { fontSize } from "../../../core/design-system/index.js";
|
package/src/version.ts
CHANGED
@@ -1 +1 @@
|
|
1
|
-
export const version = "5.29.3-nightly-
|
1
|
+
export const version = "5.29.3-nightly-476b6cc271b0891fa01fb09ca509c564b850ccfa-20240614185219";
|
@@ -12,11 +12,10 @@ import type {
|
|
12
12
|
} from "./wallet-types.js";
|
13
13
|
|
14
14
|
import { trackConnect } from "../analytics/track.js";
|
15
|
-
import type { ThirdwebClient } from "../client/client.js";
|
16
15
|
import { coinbaseWalletSDK } from "./coinbase/coinbase-wallet.js";
|
17
16
|
import { getCoinbaseWebProvider } from "./coinbase/coinbaseSDKWallet.js";
|
18
17
|
import { COINBASE } from "./constants.js";
|
19
|
-
import {
|
18
|
+
import { inAppWallet } from "./in-app/web/in-app.js";
|
20
19
|
import { smartWallet } from "./smart/smart-wallet.js";
|
21
20
|
import type { WCConnectOptions } from "./wallet-connect/types.js";
|
22
21
|
import { createWalletEmitter } from "./wallet-emitter.js";
|
@@ -290,147 +289,3 @@ export function createWallet<const ID extends WalletId>(
|
|
290
289
|
export function walletConnect() {
|
291
290
|
return createWallet("walletConnect");
|
292
291
|
}
|
293
|
-
|
294
|
-
/**
|
295
|
-
* Creates an in-app wallet.
|
296
|
-
* @param createOptions - configuration options
|
297
|
-
* @returns The created in-app wallet.
|
298
|
-
* @example
|
299
|
-
* ```ts
|
300
|
-
* import { inAppWallet } from "thirdweb/wallets";
|
301
|
-
*
|
302
|
-
* const wallet = inAppWallet();
|
303
|
-
*
|
304
|
-
* const account = await wallet.connect({
|
305
|
-
* client,
|
306
|
-
* chain,
|
307
|
-
* strategy: "google",
|
308
|
-
* });
|
309
|
-
* ```
|
310
|
-
*
|
311
|
-
* Enable smart accounts and sponsor gas for your users:
|
312
|
-
* ```ts
|
313
|
-
* import { inAppWallet } from "thirdweb/wallets";
|
314
|
-
* const wallet = inAppWallet({
|
315
|
-
* smartAccount: {
|
316
|
-
* chain: sepolia,
|
317
|
-
* sponsorGas: true,
|
318
|
-
* },
|
319
|
-
* });
|
320
|
-
* ```
|
321
|
-
*
|
322
|
-
* Specify a logo for your login page
|
323
|
-
* ```ts
|
324
|
-
* import { inAppWallet } from "thirdweb/wallets";
|
325
|
-
* const wallet = inAppWallet({
|
326
|
-
* metadata: {
|
327
|
-
* image: {
|
328
|
-
* src: "https://example.com/logo.png",
|
329
|
-
* alt: "My logo",
|
330
|
-
* width: 100,
|
331
|
-
* height: 100,
|
332
|
-
* },
|
333
|
-
* },
|
334
|
-
* });
|
335
|
-
* ```
|
336
|
-
*
|
337
|
-
* Hide the ability to export the private key within the Connect Modal
|
338
|
-
* ```ts
|
339
|
-
* import { inAppWallet } from "thirdweb/wallets";
|
340
|
-
* const wallet = inAppWallet({
|
341
|
-
* hidePrivateKeyExport: true
|
342
|
-
* });
|
343
|
-
* ```
|
344
|
-
* @wallet
|
345
|
-
*/
|
346
|
-
export function inAppWallet(
|
347
|
-
createOptions?: CreateWalletArgs<"inApp">[1],
|
348
|
-
): Wallet<"inApp"> {
|
349
|
-
const emitter = createWalletEmitter<"inApp">();
|
350
|
-
let account: Account | undefined = undefined;
|
351
|
-
let chain: Chain | undefined = undefined;
|
352
|
-
let client: ThirdwebClient | undefined;
|
353
|
-
|
354
|
-
return {
|
355
|
-
id: "inApp",
|
356
|
-
subscribe: emitter.subscribe,
|
357
|
-
getChain: () => chain,
|
358
|
-
getConfig: () => createOptions,
|
359
|
-
getAccount: () => account,
|
360
|
-
autoConnect: async (options) => {
|
361
|
-
const { autoConnectInAppWallet } = await import(
|
362
|
-
"./in-app/core/wallet/index.js"
|
363
|
-
);
|
364
|
-
|
365
|
-
const [connectedAccount, connectedChain] = await autoConnectInAppWallet(
|
366
|
-
options,
|
367
|
-
createOptions,
|
368
|
-
);
|
369
|
-
// set the states
|
370
|
-
client = options.client;
|
371
|
-
account = connectedAccount;
|
372
|
-
chain = connectedChain;
|
373
|
-
trackConnect({
|
374
|
-
client: options.client,
|
375
|
-
walletType: "inApp",
|
376
|
-
walletAddress: account.address,
|
377
|
-
});
|
378
|
-
// return only the account
|
379
|
-
return account;
|
380
|
-
},
|
381
|
-
connect: async (options) => {
|
382
|
-
const { connectInAppWallet } = await import(
|
383
|
-
"./in-app/core/wallet/index.js"
|
384
|
-
);
|
385
|
-
|
386
|
-
const [connectedAccount, connectedChain] = await connectInAppWallet(
|
387
|
-
options,
|
388
|
-
createOptions,
|
389
|
-
);
|
390
|
-
// set the states
|
391
|
-
client = options.client;
|
392
|
-
account = connectedAccount;
|
393
|
-
chain = connectedChain;
|
394
|
-
trackConnect({
|
395
|
-
client: options.client,
|
396
|
-
walletType: "inApp",
|
397
|
-
walletAddress: account.address,
|
398
|
-
});
|
399
|
-
// return only the account
|
400
|
-
return account;
|
401
|
-
},
|
402
|
-
disconnect: async () => {
|
403
|
-
// If no client is assigned, we should be fine just unsetting the states
|
404
|
-
if (client) {
|
405
|
-
const result = await logoutAuthenticatedUser({ client });
|
406
|
-
if (!result.success) {
|
407
|
-
throw new Error("Failed to logout");
|
408
|
-
}
|
409
|
-
}
|
410
|
-
account = undefined;
|
411
|
-
chain = undefined;
|
412
|
-
emitter.emit("disconnect", undefined);
|
413
|
-
},
|
414
|
-
switchChain: async (newChain) => {
|
415
|
-
if (createOptions?.smartAccount && client && account) {
|
416
|
-
// if account abstraction is enabled, reconnect to smart account on the new chain
|
417
|
-
const { autoConnectInAppWallet } = await import(
|
418
|
-
"./in-app/core/wallet/index.js"
|
419
|
-
);
|
420
|
-
const [connectedAccount, connectedChain] = await autoConnectInAppWallet(
|
421
|
-
{
|
422
|
-
chain: newChain,
|
423
|
-
client,
|
424
|
-
},
|
425
|
-
createOptions,
|
426
|
-
);
|
427
|
-
account = connectedAccount;
|
428
|
-
chain = connectedChain;
|
429
|
-
} else {
|
430
|
-
// if not, simply set the new chain
|
431
|
-
chain = newChain;
|
432
|
-
}
|
433
|
-
emitter.emit("chainChanged", newChain);
|
434
|
-
},
|
435
|
-
};
|
436
|
-
}
|
@@ -210,3 +210,16 @@ export type GetUser =
|
|
210
210
|
walletAddress: string;
|
211
211
|
}
|
212
212
|
| InitializedUser;
|
213
|
+
|
214
|
+
export type GetAuthenticatedUserParams = {
|
215
|
+
client: ThirdwebClient;
|
216
|
+
};
|
217
|
+
|
218
|
+
export const oauthStrategyToAuthProvider: Record<
|
219
|
+
"google" | "facebook" | "apple",
|
220
|
+
AuthProvider
|
221
|
+
> = {
|
222
|
+
google: AuthProvider.GOOGLE,
|
223
|
+
facebook: AuthProvider.FACEBOOK,
|
224
|
+
apple: AuthProvider.APPLE,
|
225
|
+
};
|
@@ -0,0 +1,134 @@
|
|
1
|
+
import { trackConnect } from "../../../../analytics/track.js";
|
2
|
+
import type { Chain } from "../../../../chains/types.js";
|
3
|
+
import type { ThirdwebClient } from "../../../../client/client.js";
|
4
|
+
import type { Account, Wallet } from "../../../interfaces/wallet.js";
|
5
|
+
import { createWalletEmitter } from "../../../wallet-emitter.js";
|
6
|
+
import type { CreateWalletArgs } from "../../../wallet-types.js";
|
7
|
+
import type { InAppConnector } from "../interfaces/connector.js";
|
8
|
+
|
9
|
+
const connectorCache = new WeakMap<ThirdwebClient, InAppConnector>();
|
10
|
+
|
11
|
+
/**
|
12
|
+
* @internal
|
13
|
+
*/
|
14
|
+
export async function getOrCreateInAppWalletConnector(
|
15
|
+
client: ThirdwebClient,
|
16
|
+
connectorFactory: (client: ThirdwebClient) => Promise<InAppConnector>,
|
17
|
+
) {
|
18
|
+
if (connectorCache.has(client)) {
|
19
|
+
return connectorCache.get(client) as InAppConnector;
|
20
|
+
}
|
21
|
+
const connector = await connectorFactory(client);
|
22
|
+
connectorCache.set(client, connector);
|
23
|
+
return connector;
|
24
|
+
}
|
25
|
+
|
26
|
+
/**
|
27
|
+
* @internal
|
28
|
+
*/
|
29
|
+
export function createInAppWallet(args: {
|
30
|
+
createOptions?: CreateWalletArgs<"inApp">[1];
|
31
|
+
connectorFactory: (client: ThirdwebClient) => Promise<InAppConnector>;
|
32
|
+
}): Wallet<"inApp"> {
|
33
|
+
const { createOptions, connectorFactory } = args;
|
34
|
+
const emitter = createWalletEmitter<"inApp">();
|
35
|
+
let account: Account | undefined = undefined;
|
36
|
+
let chain: Chain | undefined = undefined;
|
37
|
+
let client: ThirdwebClient | undefined;
|
38
|
+
|
39
|
+
return {
|
40
|
+
id: "inApp",
|
41
|
+
subscribe: emitter.subscribe,
|
42
|
+
getChain: () => chain,
|
43
|
+
getConfig: () => createOptions,
|
44
|
+
getAccount: () => account,
|
45
|
+
autoConnect: async (options) => {
|
46
|
+
const { autoConnectInAppWallet } = await import("./index.js");
|
47
|
+
|
48
|
+
const connector = await getOrCreateInAppWalletConnector(
|
49
|
+
options.client,
|
50
|
+
connectorFactory,
|
51
|
+
);
|
52
|
+
const [connectedAccount, connectedChain] = await autoConnectInAppWallet(
|
53
|
+
options,
|
54
|
+
createOptions,
|
55
|
+
connector,
|
56
|
+
);
|
57
|
+
// set the states
|
58
|
+
client = options.client;
|
59
|
+
account = connectedAccount;
|
60
|
+
chain = connectedChain;
|
61
|
+
trackConnect({
|
62
|
+
client: options.client,
|
63
|
+
walletType: "inApp",
|
64
|
+
walletAddress: account.address,
|
65
|
+
});
|
66
|
+
// return only the account
|
67
|
+
return account;
|
68
|
+
},
|
69
|
+
connect: async (options) => {
|
70
|
+
const { connectInAppWallet } = await import("./index.js");
|
71
|
+
|
72
|
+
const connector = await getOrCreateInAppWalletConnector(
|
73
|
+
options.client,
|
74
|
+
connectorFactory,
|
75
|
+
);
|
76
|
+
const [connectedAccount, connectedChain] = await connectInAppWallet(
|
77
|
+
options,
|
78
|
+
createOptions,
|
79
|
+
connector,
|
80
|
+
);
|
81
|
+
// set the states
|
82
|
+
client = options.client;
|
83
|
+
account = connectedAccount;
|
84
|
+
chain = connectedChain;
|
85
|
+
trackConnect({
|
86
|
+
client: options.client,
|
87
|
+
walletType: "inApp",
|
88
|
+
walletAddress: account.address,
|
89
|
+
});
|
90
|
+
// return only the account
|
91
|
+
return account;
|
92
|
+
},
|
93
|
+
disconnect: async () => {
|
94
|
+
// If no client is assigned, we should be fine just unsetting the states
|
95
|
+
if (client) {
|
96
|
+
const connector = await getOrCreateInAppWalletConnector(
|
97
|
+
client,
|
98
|
+
connectorFactory,
|
99
|
+
);
|
100
|
+
const result = await connector.logout();
|
101
|
+
if (!result.success) {
|
102
|
+
throw new Error("Failed to logout");
|
103
|
+
}
|
104
|
+
}
|
105
|
+
account = undefined;
|
106
|
+
chain = undefined;
|
107
|
+
emitter.emit("disconnect", undefined);
|
108
|
+
},
|
109
|
+
switchChain: async (newChain) => {
|
110
|
+
if (createOptions?.smartAccount && client && account) {
|
111
|
+
// if account abstraction is enabled, reconnect to smart account on the new chain
|
112
|
+
const { autoConnectInAppWallet } = await import("./index.js");
|
113
|
+
const connector = await getOrCreateInAppWalletConnector(
|
114
|
+
client,
|
115
|
+
connectorFactory,
|
116
|
+
);
|
117
|
+
const [connectedAccount, connectedChain] = await autoConnectInAppWallet(
|
118
|
+
{
|
119
|
+
chain: newChain,
|
120
|
+
client,
|
121
|
+
},
|
122
|
+
createOptions,
|
123
|
+
connector,
|
124
|
+
);
|
125
|
+
account = connectedAccount;
|
126
|
+
chain = connectedChain;
|
127
|
+
} else {
|
128
|
+
// if not, simply set the new chain
|
129
|
+
chain = newChain;
|
130
|
+
}
|
131
|
+
emitter.emit("chainChanged", newChain);
|
132
|
+
},
|
133
|
+
};
|
134
|
+
}
|
@@ -8,6 +8,8 @@ import type {
|
|
8
8
|
WalletAutoConnectionOption,
|
9
9
|
WalletConnectionOption,
|
10
10
|
} from "../../../wallet-types.js";
|
11
|
+
import { UserWalletStatus } from "../authentication/type.js";
|
12
|
+
import type { InAppConnector } from "../interfaces/connector.js";
|
11
13
|
|
12
14
|
/**
|
13
15
|
* Checks if the provided wallet is an in-app wallet.
|
@@ -27,10 +29,9 @@ export function isInAppWallet(
|
|
27
29
|
export async function connectInAppWallet(
|
28
30
|
options: WalletConnectionOption<"inApp">,
|
29
31
|
createOptions: CreateWalletArgs<"inApp">[1],
|
32
|
+
connector: InAppConnector,
|
30
33
|
): Promise<[Account, Chain]> {
|
31
|
-
const
|
32
|
-
|
33
|
-
const authResult = await authenticate(options);
|
34
|
+
const authResult = await connector.authenticate(options);
|
34
35
|
const authAccount = authResult.user.account;
|
35
36
|
|
36
37
|
if (createOptions?.smartAccount) {
|
@@ -54,9 +55,9 @@ export async function connectInAppWallet(
|
|
54
55
|
export async function autoConnectInAppWallet(
|
55
56
|
options: WalletAutoConnectionOption<"inApp">,
|
56
57
|
createOptions: CreateWalletArgs<"inApp">[1],
|
58
|
+
connector: InAppConnector,
|
57
59
|
): Promise<[Account, Chain]> {
|
58
|
-
const
|
59
|
-
const user = await getAuthenticatedUser({ client: options.client });
|
60
|
+
const user = await getAuthenticatedUser(connector);
|
60
61
|
if (!user) {
|
61
62
|
throw new Error("not authenticated");
|
62
63
|
}
|
@@ -100,3 +101,13 @@ async function convertToSmartAccount(options: {
|
|
100
101
|
options.smartAccountOptions,
|
101
102
|
);
|
102
103
|
}
|
104
|
+
|
105
|
+
async function getAuthenticatedUser(connector: InAppConnector) {
|
106
|
+
const user = await connector.getUser();
|
107
|
+
switch (user.status) {
|
108
|
+
case UserWalletStatus.LOGGED_IN_WALLET_INITIALIZED: {
|
109
|
+
return user;
|
110
|
+
}
|
111
|
+
}
|
112
|
+
return undefined;
|
113
|
+
}
|
@@ -1,59 +1,26 @@
|
|
1
1
|
import type { ThirdwebClient } from "../../../../client/client.js";
|
2
|
-
import { isBrowser, isReactNative } from "../../../../utils/platform.js";
|
3
|
-
import type { InAppConnector } from "../interfaces/connector.js";
|
4
2
|
import {
|
5
3
|
type AuthArgsType,
|
6
4
|
type AuthLoginReturnType,
|
7
|
-
|
5
|
+
type GetAuthenticatedUserParams,
|
8
6
|
type PreAuthArgsType,
|
9
7
|
UserWalletStatus,
|
10
|
-
} from "
|
8
|
+
} from "../../core/authentication/type.js";
|
9
|
+
import { getOrCreateInAppWalletConnector } from "../../core/wallet/in-app-core.js";
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
};
|
15
|
-
|
16
|
-
const ewsSDKCache = new WeakMap<ThirdwebClient, InAppConnector>();
|
11
|
+
// ---- KEEP IN SYNC WITH /wallets/in-app/web/lib/auth/index.ts ---- //
|
12
|
+
// duplication needed for separate exports between web and native
|
17
13
|
|
18
14
|
/**
|
19
15
|
* @internal
|
20
16
|
*/
|
21
17
|
async function getInAppWalletConnector(client: ThirdwebClient) {
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
let ewSDK: InAppConnector;
|
27
|
-
if (isBrowser()) {
|
28
|
-
const { InAppWebConnector } = await import(
|
29
|
-
"../../web/lib/web-connector.js"
|
30
|
-
);
|
31
|
-
ewSDK = new InAppWebConnector({
|
18
|
+
return getOrCreateInAppWalletConnector(client, async (client) => {
|
19
|
+
const { InAppNativeConnector } = await import("../native-connector.js");
|
20
|
+
return new InAppNativeConnector({
|
32
21
|
client: client,
|
33
22
|
});
|
34
|
-
}
|
35
|
-
const {
|
36
|
-
InAppNativeConnector,
|
37
|
-
} = require("../../native/native-connector.js");
|
38
|
-
ewSDK = new InAppNativeConnector({
|
39
|
-
client,
|
40
|
-
});
|
41
|
-
} else {
|
42
|
-
throw new Error("Unsupported platform");
|
43
|
-
}
|
44
|
-
|
45
|
-
ewsSDKCache.set(client, ewSDK);
|
46
|
-
return ewSDK;
|
47
|
-
}
|
48
|
-
|
49
|
-
/**
|
50
|
-
* @internal
|
51
|
-
*/
|
52
|
-
export async function logoutAuthenticatedUser(
|
53
|
-
options: GetAuthenticatedUserParams,
|
54
|
-
) {
|
55
|
-
const ewSDK = await getInAppWalletConnector(options.client);
|
56
|
-
return ewSDK.logout();
|
23
|
+
});
|
57
24
|
}
|
58
25
|
|
59
26
|
/**
|
@@ -75,8 +42,8 @@ export async function getAuthenticatedUser(
|
|
75
42
|
options: GetAuthenticatedUserParams,
|
76
43
|
) {
|
77
44
|
const { client } = options;
|
78
|
-
const
|
79
|
-
const user = await
|
45
|
+
const connector = await getInAppWalletConnector(client);
|
46
|
+
const user = await connector.getUser();
|
80
47
|
switch (user.status) {
|
81
48
|
case UserWalletStatus.LOGGED_IN_WALLET_INITIALIZED: {
|
82
49
|
return user;
|
@@ -145,8 +112,8 @@ export async function getUserPhoneNumber(options: GetAuthenticatedUserParams) {
|
|
145
112
|
* @wallet
|
146
113
|
*/
|
147
114
|
export async function preAuthenticate(args: PreAuthArgsType) {
|
148
|
-
const
|
149
|
-
return
|
115
|
+
const connector = await getInAppWalletConnector(args.client);
|
116
|
+
return connector.preAuthenticate(args);
|
150
117
|
}
|
151
118
|
|
152
119
|
/**
|
@@ -169,15 +136,6 @@ export async function preAuthenticate(args: PreAuthArgsType) {
|
|
169
136
|
export async function authenticate(
|
170
137
|
args: AuthArgsType,
|
171
138
|
): Promise<AuthLoginReturnType> {
|
172
|
-
const
|
173
|
-
return
|
139
|
+
const connector = await getInAppWalletConnector(args.client);
|
140
|
+
return connector.authenticate(args);
|
174
141
|
}
|
175
|
-
|
176
|
-
export const oauthStrategyToAuthProvider: Record<
|
177
|
-
"google" | "facebook" | "apple",
|
178
|
-
AuthProvider
|
179
|
-
> = {
|
180
|
-
google: AuthProvider.GOOGLE,
|
181
|
-
facebook: AuthProvider.FACEBOOK,
|
182
|
-
apple: AuthProvider.APPLE,
|
183
|
-
};
|
@@ -2,42 +2,42 @@ import type { CognitoUser } from "amazon-cognito-identity-js";
|
|
2
2
|
|
3
3
|
import { Auth } from "aws-amplify";
|
4
4
|
import * as WebBrowser from "expo-web-browser";
|
5
|
-
import type { ThirdwebClient } from "
|
5
|
+
import type { ThirdwebClient } from "../../../../client/client.js";
|
6
6
|
import {
|
7
7
|
AuthProvider,
|
8
8
|
type AuthStoredTokenWithCookieReturnType,
|
9
9
|
type OauthOption,
|
10
10
|
RecoveryShareManagement,
|
11
11
|
type SendEmailOtpReturnType,
|
12
|
-
} from "
|
12
|
+
} from "../../core/authentication/type.js";
|
13
13
|
import {
|
14
14
|
deleteAccount,
|
15
15
|
fetchUserDetails,
|
16
16
|
generateAuthTokenFromCognitoEmailOtp,
|
17
17
|
getSessionHeaders,
|
18
18
|
verifyClientId,
|
19
|
-
} from "
|
19
|
+
} from "../helpers/api/fetchers.js";
|
20
20
|
import {
|
21
21
|
cognitoEmailSignIn,
|
22
22
|
cognitoEmailSignUp,
|
23
23
|
cognitoPhoneSignIn,
|
24
24
|
cognitoPhoneSignUp,
|
25
|
-
} from "
|
25
|
+
} from "../helpers/auth/cognitoAuth.js";
|
26
26
|
import {
|
27
27
|
postAuth,
|
28
28
|
postAuthUserManaged,
|
29
29
|
preAuth,
|
30
|
-
} from "
|
30
|
+
} from "../helpers/auth/middleware.js";
|
31
31
|
import {
|
32
32
|
DOMAIN_URL_2023,
|
33
33
|
ROUTE_AUTH_ENDPOINT_CALLBACK,
|
34
34
|
ROUTE_AUTH_JWT_CALLBACK,
|
35
35
|
ROUTE_HEADLESS_OAUTH_LOGIN,
|
36
|
-
} from "
|
37
|
-
import { createErrorMessage } from "
|
38
|
-
import { isDeviceSharePresentForUser } from "
|
39
|
-
import { getCognitoUser, setCognitoUser } from "
|
40
|
-
import type { VerifiedTokenResponse } from "
|
36
|
+
} from "../helpers/constants.js";
|
37
|
+
import { createErrorMessage } from "../helpers/errors.js";
|
38
|
+
import { isDeviceSharePresentForUser } from "../helpers/storage/local.js";
|
39
|
+
import { getCognitoUser, setCognitoUser } from "../helpers/storage/state.js";
|
40
|
+
import type { VerifiedTokenResponse } from "../helpers/types.js";
|
41
41
|
|
42
42
|
export async function sendVerificationEmail(options: {
|
43
43
|
email: string;
|
@@ -0,0 +1,70 @@
|
|
1
|
+
import type { ThirdwebClient } from "../../../client/client.js";
|
2
|
+
import type { Wallet } from "../../interfaces/wallet.js";
|
3
|
+
import type { CreateWalletArgs } from "../../wallet-types.js";
|
4
|
+
import { createInAppWallet } from "../core/wallet/in-app-core.js";
|
5
|
+
|
6
|
+
/**
|
7
|
+
* Creates an in-app wallet.
|
8
|
+
* @param createOptions - configuration options
|
9
|
+
* @returns The created in-app wallet.
|
10
|
+
* @example
|
11
|
+
* ```ts
|
12
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
13
|
+
*
|
14
|
+
* const wallet = inAppWallet();
|
15
|
+
*
|
16
|
+
* const account = await wallet.connect({
|
17
|
+
* client,
|
18
|
+
* chain,
|
19
|
+
* strategy: "google",
|
20
|
+
* });
|
21
|
+
* ```
|
22
|
+
*
|
23
|
+
* Enable smart accounts and sponsor gas for your users:
|
24
|
+
* ```ts
|
25
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
26
|
+
* const wallet = inAppWallet({
|
27
|
+
* smartAccount: {
|
28
|
+
* chain: sepolia,
|
29
|
+
* sponsorGas: true,
|
30
|
+
* },
|
31
|
+
* });
|
32
|
+
* ```
|
33
|
+
*
|
34
|
+
* Specify a logo for your login page
|
35
|
+
* ```ts
|
36
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
37
|
+
* const wallet = inAppWallet({
|
38
|
+
* metadata: {
|
39
|
+
* image: {
|
40
|
+
* src: "https://example.com/logo.png",
|
41
|
+
* alt: "My logo",
|
42
|
+
* width: 100,
|
43
|
+
* height: 100,
|
44
|
+
* },
|
45
|
+
* },
|
46
|
+
* });
|
47
|
+
* ```
|
48
|
+
*
|
49
|
+
* Hide the ability to export the private key within the Connect Modal
|
50
|
+
* ```ts
|
51
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
52
|
+
* const wallet = inAppWallet({
|
53
|
+
* hidePrivateKeyExport: true
|
54
|
+
* });
|
55
|
+
* ```
|
56
|
+
* @wallet
|
57
|
+
*/
|
58
|
+
export function inAppWallet(
|
59
|
+
createOptions?: CreateWalletArgs<"inApp">[1],
|
60
|
+
): Wallet<"inApp"> {
|
61
|
+
return createInAppWallet({
|
62
|
+
createOptions,
|
63
|
+
connectorFactory: async (client: ThirdwebClient) => {
|
64
|
+
const { InAppNativeConnector } = await import("./native-connector.js");
|
65
|
+
return new InAppNativeConnector({
|
66
|
+
client,
|
67
|
+
});
|
68
|
+
},
|
69
|
+
});
|
70
|
+
}
|