thirdweb 5.65.2 → 5.66.0

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 (100) hide show
  1. package/dist/cjs/exports/react.js +4 -1
  2. package/dist/cjs/exports/react.js.map +1 -1
  3. package/dist/cjs/react/core/hooks/contract/useContractEvents.js +1 -1
  4. package/dist/cjs/react/core/hooks/contract/useContractEvents.js.map +1 -1
  5. package/dist/cjs/react/core/hooks/wallets/useAutoConnect.js +19 -2
  6. package/dist/cjs/react/core/hooks/wallets/useAutoConnect.js.map +1 -1
  7. package/dist/cjs/react/native/ui/connect/ConnectModal.js.map +1 -1
  8. package/dist/cjs/react/native/ui/connect/ConnectedModal.js.map +1 -1
  9. package/dist/cjs/react/web/ui/ConnectWallet/Details.js.map +1 -1
  10. package/dist/cjs/react/web/ui/MediaRenderer/ModelViewer.js +3 -1
  11. package/dist/cjs/react/web/ui/MediaRenderer/ModelViewer.js.map +1 -1
  12. package/dist/cjs/react/web/ui/SiteEmbed.js +63 -0
  13. package/dist/cjs/react/web/ui/SiteEmbed.js.map +1 -0
  14. package/dist/cjs/react/web/wallets/in-app/WalletAuth.js +1 -1
  15. package/dist/cjs/react/web/wallets/in-app/WalletAuth.js.map +1 -1
  16. package/dist/cjs/react/web/wallets/shared/PassKeyLogin.js +2 -1
  17. package/dist/cjs/react/web/wallets/shared/PassKeyLogin.js.map +1 -1
  18. package/dist/cjs/version.js +1 -1
  19. package/dist/cjs/wallets/in-app/core/actions/generate-wallet.enclave.js +1 -1
  20. package/dist/cjs/wallets/in-app/core/actions/generate-wallet.enclave.js.map +1 -1
  21. package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js +2 -2
  22. package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
  23. package/dist/cjs/wallets/in-app/native/native-connector.js +15 -15
  24. package/dist/cjs/wallets/in-app/native/native-connector.js.map +1 -1
  25. package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js +1 -1
  26. package/dist/cjs/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -1
  27. package/dist/cjs/wallets/in-app/web/lib/get-url-token.js +10 -4
  28. package/dist/cjs/wallets/in-app/web/lib/get-url-token.js.map +1 -1
  29. package/dist/cjs/wallets/in-app/web/lib/web-connector.js +7 -9
  30. package/dist/cjs/wallets/in-app/web/lib/web-connector.js.map +1 -1
  31. package/dist/esm/exports/react.js +2 -0
  32. package/dist/esm/exports/react.js.map +1 -1
  33. package/dist/esm/react/core/hooks/contract/useContractEvents.js +1 -1
  34. package/dist/esm/react/core/hooks/contract/useContractEvents.js.map +1 -1
  35. package/dist/esm/react/core/hooks/wallets/useAutoConnect.js +19 -2
  36. package/dist/esm/react/core/hooks/wallets/useAutoConnect.js.map +1 -1
  37. package/dist/esm/react/native/ui/connect/ConnectModal.js.map +1 -1
  38. package/dist/esm/react/native/ui/connect/ConnectedModal.js.map +1 -1
  39. package/dist/esm/react/web/ui/ConnectWallet/Details.js.map +1 -1
  40. package/dist/esm/react/web/ui/MediaRenderer/ModelViewer.js +3 -1
  41. package/dist/esm/react/web/ui/MediaRenderer/ModelViewer.js.map +1 -1
  42. package/dist/esm/react/web/ui/SiteEmbed.js +60 -0
  43. package/dist/esm/react/web/ui/SiteEmbed.js.map +1 -0
  44. package/dist/esm/react/web/wallets/in-app/WalletAuth.js +1 -1
  45. package/dist/esm/react/web/wallets/in-app/WalletAuth.js.map +1 -1
  46. package/dist/esm/react/web/wallets/shared/PassKeyLogin.js +2 -1
  47. package/dist/esm/react/web/wallets/shared/PassKeyLogin.js.map +1 -1
  48. package/dist/esm/version.js +1 -1
  49. package/dist/esm/wallets/in-app/core/actions/generate-wallet.enclave.js +1 -1
  50. package/dist/esm/wallets/in-app/core/actions/generate-wallet.enclave.js.map +1 -1
  51. package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js +2 -2
  52. package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
  53. package/dist/esm/wallets/in-app/native/native-connector.js +15 -15
  54. package/dist/esm/wallets/in-app/native/native-connector.js.map +1 -1
  55. package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js +1 -1
  56. package/dist/esm/wallets/in-app/web/lib/auth/iframe-auth.js.map +1 -1
  57. package/dist/esm/wallets/in-app/web/lib/get-url-token.js +10 -4
  58. package/dist/esm/wallets/in-app/web/lib/get-url-token.js.map +1 -1
  59. package/dist/esm/wallets/in-app/web/lib/web-connector.js +7 -9
  60. package/dist/esm/wallets/in-app/web/lib/web-connector.js.map +1 -1
  61. package/dist/types/exports/react.d.ts +1 -0
  62. package/dist/types/exports/react.d.ts.map +1 -1
  63. package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts +1 -0
  64. package/dist/types/react/core/hooks/connection/ConnectButtonProps.d.ts.map +1 -1
  65. package/dist/types/react/core/hooks/wallets/useAutoConnect.d.ts.map +1 -1
  66. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts +1 -0
  67. package/dist/types/react/web/ui/ConnectWallet/Details.d.ts.map +1 -1
  68. package/dist/types/react/web/ui/MediaRenderer/ModelViewer.d.ts +0 -8
  69. package/dist/types/react/web/ui/MediaRenderer/ModelViewer.d.ts.map +1 -1
  70. package/dist/types/react/web/ui/SiteEmbed.d.ts +27 -0
  71. package/dist/types/react/web/ui/SiteEmbed.d.ts.map +1 -0
  72. package/dist/types/react/web/ui/components/Drawer.d.ts +2 -2
  73. package/dist/types/version.d.ts +1 -1
  74. package/dist/types/wallets/in-app/core/actions/generate-wallet.enclave.d.ts +2 -2
  75. package/dist/types/wallets/in-app/core/actions/generate-wallet.enclave.d.ts.map +1 -1
  76. package/dist/types/wallets/in-app/native/native-connector.d.ts.map +1 -1
  77. package/dist/types/wallets/in-app/web/lib/get-url-token.d.ts +1 -0
  78. package/dist/types/wallets/in-app/web/lib/get-url-token.d.ts.map +1 -1
  79. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts +2 -1
  80. package/dist/types/wallets/in-app/web/lib/web-connector.d.ts.map +1 -1
  81. package/package.json +29 -29
  82. package/src/exports/react.ts +3 -0
  83. package/src/react/core/hooks/connection/ConnectButtonProps.ts +1 -0
  84. package/src/react/core/hooks/contract/useContractEvents.ts +1 -1
  85. package/src/react/core/hooks/wallets/useAutoConnect.ts +21 -2
  86. package/src/react/native/ui/connect/ConnectModal.tsx +1 -1
  87. package/src/react/native/ui/connect/ConnectedModal.tsx +1 -1
  88. package/src/react/web/ui/ConnectWallet/Details.tsx +1 -1
  89. package/src/react/web/ui/MediaRenderer/ModelViewer.tsx +1 -9
  90. package/src/react/web/ui/SiteEmbed.test.tsx +39 -0
  91. package/src/react/web/ui/SiteEmbed.tsx +90 -0
  92. package/src/react/web/wallets/in-app/WalletAuth.tsx +1 -1
  93. package/src/react/web/wallets/shared/PassKeyLogin.tsx +2 -1
  94. package/src/version.ts +1 -1
  95. package/src/wallets/in-app/core/actions/generate-wallet.enclave.ts +2 -2
  96. package/src/wallets/in-app/core/wallet/enclave-wallet.ts +2 -2
  97. package/src/wallets/in-app/native/native-connector.ts +18 -19
  98. package/src/wallets/in-app/web/lib/auth/iframe-auth.ts +1 -1
  99. package/src/wallets/in-app/web/lib/get-url-token.ts +11 -4
  100. package/src/wallets/in-app/web/lib/web-connector.ts +13 -12
@@ -0,0 +1,90 @@
1
+ "use client";
2
+ import { useQuery } from "@tanstack/react-query";
3
+ import type { ThirdwebClient } from "../../../client/client.js";
4
+ import { getLastAuthProvider } from "../../../react/core/utils/storage.js";
5
+ import { webLocalStorage } from "../../../utils/storage/webStorage.js";
6
+ import { isEcosystemWallet } from "../../../wallets/ecosystem/is-ecosystem-wallet.js";
7
+ import { ClientScopedStorage } from "../../../wallets/in-app/core/authentication/client-scoped-storage.js";
8
+ import type { Ecosystem } from "../../../wallets/in-app/core/wallet/types.js";
9
+ import { useActiveWallet } from "../../core/hooks/wallets/useActiveWallet.js";
10
+
11
+ /**
12
+ * Embeds another thirdweb-supported site for seamless in-app and ecosystem wallet connection.
13
+ *
14
+ * @note Make sure the embedded site includes <AutoConnect /> and supports frame ancestors, see [here](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/frame-ancestors) for more information.
15
+ *
16
+ * @note The embedded site must support the connected wallet (ecosystem or in-app).
17
+ *
18
+ * @param {Object} props - The props to pass to the iframe
19
+ * @param {String} props.src - The URL of the site to embed
20
+ * @param {ThirdwebClient} props.client - The client to use for the embedded site
21
+ * @param {Ecosystem} [props.ecosystem] - The ecosystem to use for the embedded site
22
+ *
23
+ * @example
24
+ * ```tsx
25
+ * import { SiteEmbed } from "thirdweb/react";
26
+ *
27
+ * <SiteEmbed src="https://thirdweb.com" clientId="thirdweb-client-id" />
28
+ * ```
29
+ */
30
+ export function SiteEmbed({
31
+ src,
32
+ client,
33
+ ecosystem,
34
+ ...props
35
+ }: {
36
+ src: string;
37
+ client: ThirdwebClient;
38
+ ecosystem?: Ecosystem;
39
+ } & React.DetailedHTMLProps<
40
+ React.IframeHTMLAttributes<HTMLIFrameElement>,
41
+ HTMLIFrameElement
42
+ >) {
43
+ if (!client.clientId) {
44
+ throw new Error("The SiteEmbed client must have a clientId");
45
+ }
46
+
47
+ const activeWallet = useActiveWallet();
48
+ const walletId = activeWallet?.id;
49
+
50
+ const {
51
+ data: { authProvider, authCookie } = {},
52
+ } = useQuery({
53
+ queryKey: ["site-embed", walletId, src, client.clientId, ecosystem],
54
+ enabled:
55
+ activeWallet && (isEcosystemWallet(activeWallet) || walletId === "inApp"),
56
+ queryFn: async () => {
57
+ const storage = new ClientScopedStorage({
58
+ storage: webLocalStorage,
59
+ clientId: client.clientId,
60
+ ecosystem,
61
+ });
62
+
63
+ const authProvider = await getLastAuthProvider(webLocalStorage);
64
+ const authCookie = await storage.getAuthCookie();
65
+
66
+ return { authProvider, authCookie };
67
+ },
68
+ });
69
+
70
+ const url = new URL(src);
71
+ if (walletId) {
72
+ url.searchParams.set("walletId", walletId);
73
+ }
74
+ if (authProvider) {
75
+ url.searchParams.set("authProvider", authProvider);
76
+ }
77
+ if (authCookie) {
78
+ url.searchParams.set("authCookie", authCookie);
79
+ }
80
+
81
+ return (
82
+ <iframe
83
+ src={encodeURI(url.toString())}
84
+ width="100%"
85
+ height="100%"
86
+ allowFullScreen
87
+ {...props}
88
+ />
89
+ );
90
+ }
@@ -39,7 +39,7 @@ export function WalletAuth(props: {
39
39
  }) {
40
40
  const { wallet, done } = props;
41
41
  const addConnectedWallet = useAddConnectedWallet();
42
- const walletToConnect = useRef<Wallet>();
42
+ const walletToConnect = useRef<Wallet>(undefined);
43
43
  const [status, setStatus] = useState<"loading" | "error" | "selecting">(
44
44
  "selecting",
45
45
  );
@@ -160,7 +160,8 @@ function LoginScreen(props: {
160
160
  await setLastAuthProvider("passkey", webLocalStorage);
161
161
  }
162
162
  done();
163
- } catch {
163
+ } catch (e) {
164
+ console.error("Failed to login with passkey", e);
164
165
  setStatus("error");
165
166
  }
166
167
  }
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const version = "5.65.2";
1
+ export const version = "5.66.0";
@@ -9,13 +9,13 @@ import type { Ecosystem } from "../wallet/types.js";
9
9
  * @internal
10
10
  */
11
11
  export async function generateWallet({
12
- authToken,
13
12
  client,
14
13
  ecosystem,
14
+ authToken,
15
15
  }: {
16
16
  client: ThirdwebClient;
17
- ecosystem: Ecosystem;
18
17
  authToken: string;
18
+ ecosystem?: Ecosystem;
19
19
  }) {
20
20
  const clientFetch = getClientFetch(client, ecosystem);
21
21
  const response = await clientFetch(
@@ -139,8 +139,8 @@ export class EnclaveWallet implements IWebWallet {
139
139
  chain: getCachedChain(tx.chainId),
140
140
  });
141
141
  const transaction: Record<string, Hex | number | undefined> = {
142
- to: (tx.to as Hex) ?? undefined,
143
- data: tx.data ? toHex(tx.data) : undefined,
142
+ to: tx.to ? getAddress(tx.to) : undefined,
143
+ data: tx.data,
144
144
  value: tx.value ? toHex(tx.value) : undefined,
145
145
  gas: tx.gas ? toHex(tx.gas + tx.gas / BigInt(10)) : undefined, // Add a 10% buffer to gas
146
146
  nonce: tx.nonce
@@ -80,27 +80,26 @@ export class InAppNativeConnector implements InAppConnector {
80
80
  }
81
81
  let wallet = user.wallets[0];
82
82
 
83
- // TODO (enclaves): Migration to enclave wallet for in-app wallets as well
84
- if (
85
- authResult &&
86
- this.storage.ecosystem &&
87
- wallet &&
88
- wallet.type === "sharded"
89
- ) {
90
- const { migrateToEnclaveWallet } = await import(
91
- "./helpers/wallet/migration.js"
92
- );
93
- wallet = await migrateToEnclaveWallet({
94
- client: this.client,
95
- storage: this.storage,
96
- storedToken: authResult.storedToken,
97
- encryptionKey,
98
- });
83
+ if (authResult && wallet && wallet.type === "sharded") {
84
+ try {
85
+ const { migrateToEnclaveWallet } = await import(
86
+ "./helpers/wallet/migration.js"
87
+ );
88
+ wallet = await migrateToEnclaveWallet({
89
+ client: this.client,
90
+ storage: this.storage,
91
+ storedToken: authResult.storedToken,
92
+ encryptionKey,
93
+ });
94
+ } catch {
95
+ console.warn(
96
+ "Failed to migrate from sharded to enclave wallet, continuing with sharded wallet",
97
+ );
98
+ }
99
99
  }
100
100
 
101
- if (authResult && this.ecosystem && !wallet) {
102
- // new ecosystem user, generate enclave wallet
103
- // TODO (enclaves): same flow for in-app wallets
101
+ if (authResult && !wallet) {
102
+ // new user, generate enclave wallet
104
103
  const { generateWallet } = await import(
105
104
  "../core/actions/generate-wallet.enclave.js"
106
105
  );
@@ -128,7 +128,7 @@ export class Auth {
128
128
  });
129
129
  }
130
130
 
131
- if (user.wallets.length === 0 && this.ecosystem) {
131
+ if (user.wallets.length === 0) {
132
132
  // If this is a new ecosystem wallet without an enclave yet, we'll generate an enclave
133
133
  const result = await generateWallet({
134
134
  authToken: authToken.storedToken.cookieString,
@@ -9,6 +9,7 @@ export function getUrlToken(): {
9
9
  walletId?: WalletId;
10
10
  authResult?: AuthStoredTokenWithCookieReturnType;
11
11
  authProvider?: AuthOption;
12
+ authCookie?: string;
12
13
  } {
13
14
  if (!window?.location) {
14
15
  // Not in web
@@ -20,18 +21,24 @@ export function getUrlToken(): {
20
21
  const authResultString = params.get("authResult");
21
22
  const walletId = params.get("walletId") as WalletId | undefined;
22
23
  const authProvider = params.get("authProvider") as AuthOption | undefined;
24
+ const authCookie = params.get("authCookie") as string | undefined;
23
25
 
24
- if (authResultString && walletId) {
25
- const authResult = JSON.parse(authResultString);
26
- params.delete("authResult");
26
+ if ((authCookie || authResultString) && walletId) {
27
+ const authResult = (() => {
28
+ if (authResultString) {
29
+ params.delete("authResult");
30
+ return JSON.parse(decodeURIComponent(authResultString));
31
+ }
32
+ })();
27
33
  params.delete("walletId");
28
34
  params.delete("authProvider");
35
+ params.delete("authCookie");
29
36
  window.history.pushState(
30
37
  {},
31
38
  "",
32
39
  `${window.location.pathname}?${params.toString()}`,
33
40
  );
34
- return { walletId, authResult, authProvider };
41
+ return { walletId, authResult, authProvider, authCookie };
35
42
  }
36
43
  return {};
37
44
  }
@@ -101,10 +101,7 @@ export class InAppWebConnector implements InAppConnector {
101
101
  onAuthSuccess: async (authResult) => {
102
102
  onAuthSuccess?.(authResult);
103
103
 
104
- if (
105
- this.ecosystem &&
106
- authResult.storedToken.authDetails.walletType === "sharded"
107
- ) {
104
+ if (authResult.storedToken.authDetails.walletType === "sharded") {
108
105
  // If this is an existing sharded ecosystem wallet, we'll need to migrate
109
106
  const result = await this.querier.call<boolean>({
110
107
  procedureName: "migrateFromShardToEnclave",
@@ -113,11 +110,15 @@ export class InAppWebConnector implements InAppConnector {
113
110
  },
114
111
  });
115
112
  if (!result) {
116
- throw new Error("Failed to migrate from sharded to enclave wallet");
113
+ console.warn(
114
+ "Failed to migrate from sharded to enclave wallet, continuing with sharded wallet",
115
+ );
117
116
  }
118
117
  }
119
118
 
120
- await this.initializeWallet(authResult.storedToken.cookieString);
119
+ this.wallet = await this.initializeWallet(
120
+ authResult.storedToken.cookieString,
121
+ );
121
122
 
122
123
  if (!this.wallet) {
123
124
  throw new Error("Failed to initialize wallet");
@@ -133,7 +134,7 @@ export class InAppWebConnector implements InAppConnector {
133
134
  deviceShareStored,
134
135
  });
135
136
 
136
- if (authResult.storedToken.authDetails.walletType !== "enclave") {
137
+ if (this.wallet instanceof IFrameWallet) {
137
138
  await this.querier.call({
138
139
  procedureName: "initIframe",
139
140
  params: {
@@ -163,7 +164,7 @@ export class InAppWebConnector implements InAppConnector {
163
164
  });
164
165
  }
165
166
 
166
- async initializeWallet(authToken?: string) {
167
+ async initializeWallet(authToken?: string): Promise<IWebWallet> {
167
168
  const storedAuthToken = await this.storage.getAuthCookie();
168
169
  if (!authToken && storedAuthToken === null) {
169
170
  throw new Error(
@@ -176,6 +177,7 @@ export class InAppWebConnector implements InAppConnector {
176
177
  client: this.client,
177
178
  ecosystem: this.ecosystem,
178
179
  });
180
+
179
181
  if (!user) {
180
182
  throw new Error("Cannot initialize wallet, no user logged in");
181
183
  }
@@ -186,16 +188,15 @@ export class InAppWebConnector implements InAppConnector {
186
188
  }
187
189
 
188
190
  if (user.wallets[0]?.type === "enclave") {
189
- this.wallet = new EnclaveWallet({
191
+ return new EnclaveWallet({
190
192
  client: this.client,
191
193
  ecosystem: this.ecosystem,
192
194
  address: user.wallets[0].address,
193
195
  storage: this.storage,
194
196
  });
195
- return;
196
197
  }
197
198
 
198
- this.wallet = new IFrameWallet({
199
+ return new IFrameWallet({
199
200
  client: this.client,
200
201
  ecosystem: this.ecosystem,
201
202
  querier: this.querier,
@@ -233,7 +234,7 @@ export class InAppWebConnector implements InAppConnector {
233
234
  if (!localAuthToken) {
234
235
  return { status: "Logged Out" };
235
236
  }
236
- await this.initializeWallet(localAuthToken);
237
+ this.wallet = await this.initializeWallet(localAuthToken);
237
238
  }
238
239
  if (!this.wallet) {
239
240
  throw new Error("Wallet not initialized");