thirdweb 5.48.1-nightly-7ef1c721ef693584d153554d46f2e70e8015b261-20240822000343 → 5.48.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.
Files changed (83) hide show
  1. package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js +3 -2
  2. package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
  3. package/dist/cjs/react/web/wallets/shared/SocialLogin.js +5 -2
  4. package/dist/cjs/react/web/wallets/shared/SocialLogin.js.map +1 -1
  5. package/dist/cjs/utils/fetch.js +2 -1
  6. package/dist/cjs/utils/fetch.js.map +1 -1
  7. package/dist/cjs/version.js +1 -1
  8. package/dist/cjs/version.js.map +1 -1
  9. package/dist/cjs/wallets/in-app/core/authentication/getLoginPath.js +8 -7
  10. package/dist/cjs/wallets/in-app/core/authentication/getLoginPath.js.map +1 -1
  11. package/dist/cjs/wallets/in-app/core/authentication/types.js.map +1 -1
  12. package/dist/cjs/wallets/in-app/core/wallet/index.js +2 -2
  13. package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
  14. package/dist/cjs/wallets/in-app/native/auth/native-auth.js +1 -1
  15. package/dist/cjs/wallets/in-app/web/lib/auth/index.js +3 -2
  16. package/dist/cjs/wallets/in-app/web/lib/auth/index.js.map +1 -1
  17. package/dist/cjs/wallets/in-app/web/lib/auth/oauth.js +4 -4
  18. package/dist/cjs/wallets/in-app/web/lib/auth/oauth.js.map +1 -1
  19. package/dist/cjs/wallets/in-app/web/lib/web-connector.js +5 -3
  20. package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
  21. package/dist/cjs/wallets/smart/lib/constants.js +6 -0
  22. package/dist/cjs/wallets/smart/lib/constants.js.map +1 -1
  23. package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js +3 -2
  24. package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
  25. package/dist/esm/react/web/wallets/shared/SocialLogin.js +5 -2
  26. package/dist/esm/react/web/wallets/shared/SocialLogin.js.map +1 -1
  27. package/dist/esm/utils/fetch.js +2 -1
  28. package/dist/esm/utils/fetch.js.map +1 -1
  29. package/dist/esm/version.js +1 -1
  30. package/dist/esm/version.js.map +1 -1
  31. package/dist/esm/wallets/in-app/core/authentication/getLoginPath.js +8 -7
  32. package/dist/esm/wallets/in-app/core/authentication/getLoginPath.js.map +1 -1
  33. package/dist/esm/wallets/in-app/core/authentication/types.js.map +1 -1
  34. package/dist/esm/wallets/in-app/core/wallet/index.js +2 -2
  35. package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
  36. package/dist/esm/wallets/in-app/native/auth/native-auth.js +1 -1
  37. package/dist/esm/wallets/in-app/web/lib/auth/index.js +3 -2
  38. package/dist/esm/wallets/in-app/web/lib/auth/index.js.map +1 -1
  39. package/dist/esm/wallets/in-app/web/lib/auth/oauth.js +4 -4
  40. package/dist/esm/wallets/in-app/web/lib/auth/oauth.js.map +1 -1
  41. package/dist/esm/wallets/in-app/web/lib/web-connector.js +5 -3
  42. package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
  43. package/dist/esm/wallets/smart/lib/constants.js +6 -0
  44. package/dist/esm/wallets/smart/lib/constants.js.map +1 -1
  45. package/dist/types/react/web/wallets/shared/ConnectWalletSocialOptions.d.ts.map +1 -1
  46. package/dist/types/react/web/wallets/shared/SocialLogin.d.ts.map +1 -1
  47. package/dist/types/utils/fetch.d.ts.map +1 -1
  48. package/dist/types/version.d.ts +1 -1
  49. package/dist/types/version.d.ts.map +1 -1
  50. package/dist/types/wallets/ecosystem/types.d.ts +1 -2
  51. package/dist/types/wallets/ecosystem/types.d.ts.map +1 -1
  52. package/dist/types/wallets/in-app/core/authentication/getLoginPath.d.ts +1 -1
  53. package/dist/types/wallets/in-app/core/authentication/getLoginPath.d.ts.map +1 -1
  54. package/dist/types/wallets/in-app/core/authentication/types.d.ts +1 -8
  55. package/dist/types/wallets/in-app/core/authentication/types.d.ts.map +1 -1
  56. package/dist/types/wallets/in-app/core/interfaces/connector.d.ts +1 -1
  57. package/dist/types/wallets/in-app/core/interfaces/connector.d.ts.map +1 -1
  58. package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
  59. package/dist/types/wallets/in-app/core/wallet/types.d.ts +1 -5
  60. package/dist/types/wallets/in-app/core/wallet/types.d.ts.map +1 -1
  61. package/dist/types/wallets/in-app/web/lib/auth/index.d.ts.map +1 -1
  62. package/dist/types/wallets/in-app/web/lib/auth/oauth.d.ts +1 -1
  63. package/dist/types/wallets/in-app/web/lib/auth/oauth.d.ts.map +1 -1
  64. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts +1 -1
  65. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
  66. package/dist/types/wallets/smart/lib/constants.d.ts.map +1 -1
  67. package/package.json +1 -1
  68. package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +3 -2
  69. package/src/react/web/wallets/shared/SocialLogin.tsx +7 -2
  70. package/src/utils/fetch.ts +4 -1
  71. package/src/version.ts +1 -1
  72. package/src/wallets/ecosystem/types.ts +1 -2
  73. package/src/wallets/in-app/core/authentication/getLoginPath.ts +11 -9
  74. package/src/wallets/in-app/core/authentication/types.ts +1 -8
  75. package/src/wallets/in-app/core/interfaces/connector.ts +5 -1
  76. package/src/wallets/in-app/core/wallet/index.ts +6 -2
  77. package/src/wallets/in-app/core/wallet/types.ts +1 -5
  78. package/src/wallets/in-app/native/auth/native-auth.ts +1 -1
  79. package/src/wallets/in-app/web/lib/auth/index.ts +7 -2
  80. package/src/wallets/in-app/web/lib/auth/oauth.ts +5 -5
  81. package/src/wallets/in-app/web/lib/web-connector.ts +9 -3
  82. package/src/wallets/smart/lib/constants.ts +6 -0
  83. package/src/wallets/smart/smart-wallet-dev.test.ts +86 -0
@@ -25,9 +25,17 @@ export const getLoginUrl = ({
25
25
  authOption: AuthOption | "wallet";
26
26
  client: ThirdwebClient;
27
27
  ecosystem?: Ecosystem;
28
- mode?: "popup" | "redirect" | "mobile";
28
+ mode?: "popup" | "redirect" | "window";
29
29
  redirectUrl?: string;
30
30
  }) => {
31
+ if (mode === "popup" && redirectUrl) {
32
+ throw new Error("Redirect URL is not supported for popup mode");
33
+ }
34
+
35
+ if (mode === "window" && !redirectUrl) {
36
+ throw new Error("Redirect URL is required for window mode");
37
+ }
38
+
31
39
  const route = getLoginOptionRoute(authOption);
32
40
  let baseUrl = `${getThirdwebBaseUrl("inAppWallet")}/api/2024-05-05/login/${route}?clientId=${client.clientId}`;
33
41
  if (ecosystem?.partnerId) {
@@ -36,20 +44,14 @@ export const getLoginUrl = ({
36
44
  baseUrl = `${baseUrl}&ecosystemId=${ecosystem.id}`;
37
45
  }
38
46
 
39
- if (mode === "redirect") {
47
+ // Always append redirectUrl to the baseUrl if mode is not popup
48
+ if (mode !== "popup") {
40
49
  const formattedRedirectUrl = new URL(redirectUrl || window.location.href);
41
50
  formattedRedirectUrl.searchParams.set("walletId", ecosystem?.id || "inApp");
42
51
  formattedRedirectUrl.searchParams.set("authProvider", authOption);
43
52
  baseUrl = `${baseUrl}&redirectUrl=${encodeURIComponent(formattedRedirectUrl.toString())}`;
44
53
  }
45
54
 
46
- if (mode === "mobile") {
47
- if (!redirectUrl) {
48
- throw new Error("Redirect URL is required for mobile authentication");
49
- }
50
- baseUrl = `${baseUrl}&redirectUrl=${encodeURIComponent(redirectUrl)}`;
51
- }
52
-
53
55
  return baseUrl;
54
56
  };
55
57
 
@@ -30,6 +30,7 @@ export type SingleStepAuthArgsType =
30
30
  openedWindow?: Window;
31
31
  closeOpenedWindow?: (window: Window) => void;
32
32
  redirectUrl?: string;
33
+ mode?: "redirect" | "popup" | "window";
33
34
  }
34
35
  | { strategy: "jwt"; jwt: string; encryptionKey: string }
35
36
  | { strategy: "auth_endpoint"; payload: string; encryptionKey: string }
@@ -46,14 +47,6 @@ export type SingleStepAuthArgsType =
46
47
  * Optional name of the passkey to create, defaults to a generated name
47
48
  */
48
49
  passkeyName?: string;
49
- /**
50
- * Optional domain, defaults to current window location.
51
- * NOTE: this is required on native platforms.
52
- */
53
- domain?: {
54
- displayName: string;
55
- hostname: string;
56
- };
57
50
  }
58
51
  | {
59
52
  strategy: "wallet";
@@ -15,7 +15,11 @@ export interface InAppConnector {
15
15
  getAccount(): Promise<Account>;
16
16
  preAuthenticate(args: PreAuthArgsType): Promise<void>;
17
17
  // Authenticate generates an auth token, when redirecting it returns void as the user is redirected to a new page and the token is stored in the callback url
18
- authenticateWithRedirect?(strategy: SocialAuthOption): void;
18
+ authenticateWithRedirect?(
19
+ strategy: SocialAuthOption,
20
+ mode?: "redirect" | "popup" | "window",
21
+ redirectUrl?: string,
22
+ ): void;
19
23
  // Login takes an auth token and connects a user with it
20
24
  loginWithAuthToken?(
21
25
  authResult: AuthStoredTokenWithCookieReturnType,
@@ -40,12 +40,16 @@ export async function connectInAppWallet(
40
40
  connector: InAppConnector,
41
41
  ): Promise<[Account, Chain]> {
42
42
  if (
43
- createOptions?.auth?.mode === "redirect" &&
43
+ createOptions?.auth?.mode !== "popup" &&
44
44
  connector.authenticateWithRedirect
45
45
  ) {
46
46
  const strategy = options.strategy;
47
47
  if (socialAuthOptions.includes(strategy as SocialAuthOption)) {
48
- connector.authenticateWithRedirect(strategy as SocialAuthOption);
48
+ connector.authenticateWithRedirect(
49
+ strategy as SocialAuthOption,
50
+ createOptions?.auth?.mode,
51
+ createOptions?.auth?.redirectUrl,
52
+ );
49
53
  }
50
54
  }
51
55
  // If we don't have authenticateWithRedirect then it's likely react native, so the default is to redirect and we can carry on
@@ -36,15 +36,11 @@ export type InAppWalletCreationOptions =
36
36
  /**
37
37
  * Whether to display the social auth prompt in a popup or redirect
38
38
  */
39
- mode?: "popup" | "redirect";
39
+ mode?: "popup" | "redirect" | "window";
40
40
  /**
41
41
  * Optional url to redirect to after authentication
42
42
  */
43
43
  redirectUrl?: string;
44
- /**
45
- * Whether to handle the redirect in a new window
46
- */
47
- redirectExternally?: boolean;
48
44
  /**
49
45
  * The domain of the passkey to use for authentication
50
46
  */
@@ -59,7 +59,7 @@ export async function authenticate(
59
59
  const loginUrl = getLoginUrl({
60
60
  authOption: auth.strategy,
61
61
  client,
62
- mode: "mobile",
62
+ mode: "window",
63
63
  redirectUrl: auth.redirectUrl,
64
64
  });
65
65
 
@@ -156,7 +156,12 @@ export async function authenticate(
156
156
  >,
157
157
  ) {
158
158
  const connector = await getInAppWalletConnector(args.client, args.ecosystem);
159
- if (args.redirect && connector.authenticateWithRedirect)
160
- return connector.authenticateWithRedirect(args.strategy);
159
+ const isRedirect = args.redirect || args.mode !== "popup";
160
+ if (isRedirect && connector.authenticateWithRedirect && args.strategy)
161
+ return connector.authenticateWithRedirect(
162
+ args.strategy as SocialAuthOption,
163
+ args.mode,
164
+ args.redirectUrl,
165
+ );
161
166
  return connector.connect(args);
162
167
  }
@@ -31,16 +31,16 @@ export const loginWithOauthRedirect = (options: {
31
31
  client: ThirdwebClient;
32
32
  ecosystem?: Ecosystem;
33
33
  redirectUrl?: string;
34
- redirectExternally?: boolean;
34
+ mode?: "redirect" | "popup" | "window";
35
35
  }): void => {
36
36
  const loginUrl = getLoginUrl({
37
37
  ...options,
38
- mode: "redirect",
38
+ mode: options.mode || "redirect",
39
39
  });
40
- if (options.redirectExternally === true) {
41
- window.open(loginUrl);
42
- } else {
40
+ if (options.mode === "redirect") {
43
41
  window.location.href = loginUrl;
42
+ } else {
43
+ window.open(loginUrl);
44
44
  }
45
45
  };
46
46
 
@@ -150,11 +150,17 @@ export class InAppWebConnector implements InAppConnector {
150
150
  });
151
151
  }
152
152
 
153
- authenticateWithRedirect(strategy: SocialAuthOption): void {
153
+ authenticateWithRedirect(
154
+ strategy: SocialAuthOption,
155
+ mode?: "redirect" | "popup" | "window",
156
+ redirectUrl?: string,
157
+ ): void {
154
158
  loginWithOauthRedirect({
155
159
  authOption: strategy,
156
160
  client: this.wallet.client,
157
161
  ecosystem: this.wallet.ecosystem,
162
+ redirectUrl,
163
+ mode,
158
164
  });
159
165
  }
160
166
 
@@ -308,8 +314,8 @@ export class InAppWebConnector implements InAppConnector {
308
314
  passkeyClient,
309
315
  storage,
310
316
  rp: {
311
- id: args.domain?.hostname ?? window.location.hostname,
312
- name: args.domain?.displayName ?? window.document.title,
317
+ id: this.passkeyDomain ?? window.location.hostname,
318
+ name: this.passkeyDomain ?? window.document.title,
313
319
  },
314
320
  });
315
321
  }
@@ -19,6 +19,9 @@ export const MANAGED_ACCOUNT_GAS_BUFFER = 50000n;
19
19
  */
20
20
  export const getDefaultBundlerUrl = (chain: Chain) => {
21
21
  const domain = getThirdwebDomains().bundler;
22
+ if (domain.startsWith("localhost:")) {
23
+ return `http://${domain}?chain=${chain.id}`;
24
+ }
22
25
  return `https://${chain.id}.${domain}/`;
23
26
  };
24
27
 
@@ -27,5 +30,8 @@ export const getDefaultBundlerUrl = (chain: Chain) => {
27
30
  */
28
31
  export const getDefaultPaymasterUrl = (chain: Chain) => {
29
32
  const domain = getThirdwebDomains().bundler;
33
+ if (domain.startsWith("localhost:")) {
34
+ return `http://${domain}?chain=${chain.id}`;
35
+ }
30
36
  return `https://${chain.id}.${domain}/`;
31
37
  };
@@ -0,0 +1,86 @@
1
+ import { beforeAll, describe, expect, it } from "vitest";
2
+ import { TEST_CLIENT } from "../../../test/src/test-clients.js";
3
+ import { arbitrumSepolia } from "../../chains/chain-definitions/arbitrum-sepolia.js";
4
+ import { type ThirdwebContract, getContract } from "../../contract/contract.js";
5
+
6
+ import { balanceOf } from "../../extensions/erc1155/__generated__/IERC1155/read/balanceOf.js";
7
+ import { claimTo } from "../../extensions/erc1155/drops/write/claimTo.js";
8
+ import { sendAndConfirmTransaction } from "../../transaction/actions/send-and-confirm-transaction.js";
9
+ import type { Address } from "../../utils/address.js";
10
+ import { isContractDeployed } from "../../utils/bytecode/is-contract-deployed.js";
11
+ import { setThirdwebDomains } from "../../utils/domains.js";
12
+ import type { Account, Wallet } from "../interfaces/wallet.js";
13
+ import { generateAccount } from "../utils/generateAccount.js";
14
+ import { smartWallet } from "./smart-wallet.js";
15
+
16
+ let wallet: Wallet;
17
+ let smartAccount: Account;
18
+ let smartWalletAddress: Address;
19
+ let personalAccount: Account;
20
+ let accountContract: ThirdwebContract;
21
+
22
+ const chain = arbitrumSepolia;
23
+ const client = TEST_CLIENT;
24
+ const contract = getContract({
25
+ client,
26
+ chain,
27
+ address: "0x6A7a26c9a595E6893C255C9dF0b593e77518e0c3",
28
+ });
29
+ describe.runIf(process.env.TW_SECRET_KEY).skip.sequential(
30
+ "SmartWallet policy tests",
31
+ {
32
+ retry: 0,
33
+ timeout: 240_000,
34
+ },
35
+ () => {
36
+ beforeAll(async () => {
37
+ setThirdwebDomains({
38
+ rpc: "rpc.thirdweb-dev.com",
39
+ storage: "storage.thirdweb-dev.com",
40
+ bundler: "bundler.thirdweb-dev.com",
41
+ });
42
+ personalAccount = await generateAccount({
43
+ client,
44
+ });
45
+ wallet = smartWallet({
46
+ chain,
47
+ gasless: true,
48
+ });
49
+ smartAccount = await wallet.connect({
50
+ client: TEST_CLIENT,
51
+ personalAccount,
52
+ });
53
+ smartWalletAddress = smartAccount.address as Address;
54
+ accountContract = getContract({
55
+ address: smartWalletAddress,
56
+ chain,
57
+ client,
58
+ });
59
+ });
60
+
61
+ it("can connect", async () => {
62
+ expect(smartWalletAddress).toHaveLength(42);
63
+ });
64
+
65
+ it("can execute a tx", async () => {
66
+ const tx = await sendAndConfirmTransaction({
67
+ transaction: claimTo({
68
+ contract,
69
+ quantity: 1n,
70
+ to: smartWalletAddress,
71
+ tokenId: 0n,
72
+ }),
73
+ account: smartAccount,
74
+ });
75
+ expect(tx.transactionHash).toHaveLength(66);
76
+ const isDeployed = await isContractDeployed(accountContract);
77
+ expect(isDeployed).toEqual(true);
78
+ const balance = await balanceOf({
79
+ contract,
80
+ owner: smartWalletAddress,
81
+ tokenId: 0n,
82
+ });
83
+ expect(balance).toEqual(1n);
84
+ });
85
+ },
86
+ );