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.
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js +3 -2
- package/dist/cjs/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/cjs/react/web/wallets/shared/SocialLogin.js +5 -2
- package/dist/cjs/react/web/wallets/shared/SocialLogin.js.map +1 -1
- package/dist/cjs/utils/fetch.js +2 -1
- package/dist/cjs/utils/fetch.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/getLoginPath.js +8 -7
- package/dist/cjs/wallets/in-app/core/authentication/getLoginPath.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/authentication/types.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js +2 -2
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/cjs/wallets/in-app/native/auth/native-auth.js +1 -1
- package/dist/cjs/wallets/in-app/web/lib/auth/index.js +3 -2
- package/dist/cjs/wallets/in-app/web/lib/auth/index.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/auth/oauth.js +4 -4
- package/dist/cjs/wallets/in-app/web/lib/auth/oauth.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js +5 -3
- package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/constants.js +6 -0
- package/dist/cjs/wallets/smart/lib/constants.js.map +1 -1
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js +3 -2
- package/dist/esm/react/web/wallets/shared/ConnectWalletSocialOptions.js.map +1 -1
- package/dist/esm/react/web/wallets/shared/SocialLogin.js +5 -2
- package/dist/esm/react/web/wallets/shared/SocialLogin.js.map +1 -1
- package/dist/esm/utils/fetch.js +2 -1
- package/dist/esm/utils/fetch.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/wallets/in-app/core/authentication/getLoginPath.js +8 -7
- package/dist/esm/wallets/in-app/core/authentication/getLoginPath.js.map +1 -1
- package/dist/esm/wallets/in-app/core/authentication/types.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js +2 -2
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/wallets/in-app/native/auth/native-auth.js +1 -1
- package/dist/esm/wallets/in-app/web/lib/auth/index.js +3 -2
- package/dist/esm/wallets/in-app/web/lib/auth/index.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/auth/oauth.js +4 -4
- package/dist/esm/wallets/in-app/web/lib/auth/oauth.js.map +1 -1
- package/dist/esm/wallets/in-app/web/lib/web-connector.js +5 -3
- package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
- package/dist/esm/wallets/smart/lib/constants.js +6 -0
- package/dist/esm/wallets/smart/lib/constants.js.map +1 -1
- package/dist/types/react/web/wallets/shared/ConnectWalletSocialOptions.d.ts.map +1 -1
- package/dist/types/react/web/wallets/shared/SocialLogin.d.ts.map +1 -1
- package/dist/types/utils/fetch.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/dist/types/wallets/ecosystem/types.d.ts +1 -2
- package/dist/types/wallets/ecosystem/types.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/authentication/getLoginPath.d.ts +1 -1
- package/dist/types/wallets/in-app/core/authentication/getLoginPath.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/authentication/types.d.ts +1 -8
- package/dist/types/wallets/in-app/core/authentication/types.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/interfaces/connector.d.ts +1 -1
- package/dist/types/wallets/in-app/core/interfaces/connector.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/types.d.ts +1 -5
- package/dist/types/wallets/in-app/core/wallet/types.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/lib/auth/index.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/lib/auth/oauth.d.ts +1 -1
- package/dist/types/wallets/in-app/web/lib/auth/oauth.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/dist/types/wallets/smart/lib/constants.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/react/web/wallets/shared/ConnectWalletSocialOptions.tsx +3 -2
- package/src/react/web/wallets/shared/SocialLogin.tsx +7 -2
- package/src/utils/fetch.ts +4 -1
- package/src/version.ts +1 -1
- package/src/wallets/ecosystem/types.ts +1 -2
- package/src/wallets/in-app/core/authentication/getLoginPath.ts +11 -9
- package/src/wallets/in-app/core/authentication/types.ts +1 -8
- package/src/wallets/in-app/core/interfaces/connector.ts +5 -1
- package/src/wallets/in-app/core/wallet/index.ts +6 -2
- package/src/wallets/in-app/core/wallet/types.ts +1 -5
- package/src/wallets/in-app/native/auth/native-auth.ts +1 -1
- package/src/wallets/in-app/web/lib/auth/index.ts +7 -2
- package/src/wallets/in-app/web/lib/auth/oauth.ts +5 -5
- package/src/wallets/in-app/web/lib/web-connector.ts +9 -3
- package/src/wallets/smart/lib/constants.ts +6 -0
- 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" | "
|
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
|
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?(
|
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
|
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(
|
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
|
*/
|
@@ -156,7 +156,12 @@ export async function authenticate(
|
|
156
156
|
>,
|
157
157
|
) {
|
158
158
|
const connector = await getInAppWalletConnector(args.client, args.ecosystem);
|
159
|
-
|
160
|
-
|
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
|
-
|
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.
|
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(
|
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:
|
312
|
-
name:
|
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
|
+
);
|