thirdweb 5.105.20 → 5.105.22
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/extensions/erc1155/read/getOwnedNFTs.js +1 -0
- package/dist/cjs/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
- package/dist/cjs/extensions/erc721/read/getOwnedNFTs.js +1 -0
- package/dist/cjs/extensions/erc721/read/getOwnedNFTs.js.map +1 -1
- package/dist/cjs/insight/get-nfts.js +3 -3
- package/dist/cjs/insight/get-nfts.js.map +1 -1
- package/dist/cjs/insight/get-tokens.js +3 -2
- package/dist/cjs/insight/get-tokens.js.map +1 -1
- package/dist/cjs/react/core/hooks/wallets/useConnect.js +10 -1
- package/dist/cjs/react/core/hooks/wallets/useConnect.js.map +1 -1
- package/dist/cjs/transaction/actions/estimate-gas.js +3 -24
- package/dist/cjs/transaction/actions/estimate-gas.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/wallets/coinbase/coinbase-web.js +56 -0
- package/dist/cjs/wallets/coinbase/coinbase-web.js.map +1 -1
- package/dist/cjs/wallets/create-wallet.js +62 -13
- package/dist/cjs/wallets/create-wallet.js.map +1 -1
- package/dist/cjs/wallets/eip5792/get-calls-status.js +40 -63
- package/dist/cjs/wallets/eip5792/get-calls-status.js.map +1 -1
- package/dist/cjs/wallets/eip5792/get-capabilities.js +14 -49
- package/dist/cjs/wallets/eip5792/get-capabilities.js.map +1 -1
- package/dist/cjs/wallets/eip5792/send-calls.js +34 -48
- package/dist/cjs/wallets/eip5792/send-calls.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/{eip5972 → eip5792}/in-app-wallet-calls.js +1 -5
- package/dist/cjs/wallets/in-app/core/eip5792/in-app-wallet-calls.js.map +1 -0
- package/dist/cjs/wallets/in-app/core/eip7702/minimal-account.js +650 -5
- package/dist/cjs/wallets/in-app/core/eip7702/minimal-account.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js +32 -1
- package/dist/cjs/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js +3 -3
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js.map +1 -1
- package/dist/cjs/wallets/in-app/web/in-app.js +18 -0
- package/dist/cjs/wallets/in-app/web/in-app.js.map +1 -1
- package/dist/cjs/wallets/injected/index.js +55 -0
- package/dist/cjs/wallets/injected/index.js.map +1 -1
- package/dist/cjs/wallets/smart/index.js +63 -2
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/cjs/wallets/smart/smart-wallet.js +1 -1
- package/dist/cjs/wallets/smart/smart-wallet.js.map +1 -1
- package/dist/cjs/wallets/wallet-connect/qr-overlay.js +231 -0
- package/dist/cjs/wallets/wallet-connect/qr-overlay.js.map +1 -0
- package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js +1 -0
- package/dist/esm/extensions/erc1155/read/getOwnedNFTs.js.map +1 -1
- package/dist/esm/extensions/erc721/read/getOwnedNFTs.js +1 -0
- package/dist/esm/extensions/erc721/read/getOwnedNFTs.js.map +1 -1
- package/dist/esm/insight/get-nfts.js +3 -3
- package/dist/esm/insight/get-nfts.js.map +1 -1
- package/dist/esm/insight/get-tokens.js +3 -2
- package/dist/esm/insight/get-tokens.js.map +1 -1
- package/dist/esm/react/core/hooks/wallets/useConnect.js +10 -1
- package/dist/esm/react/core/hooks/wallets/useConnect.js.map +1 -1
- package/dist/esm/transaction/actions/estimate-gas.js +3 -24
- package/dist/esm/transaction/actions/estimate-gas.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/wallets/coinbase/coinbase-web.js +56 -0
- package/dist/esm/wallets/coinbase/coinbase-web.js.map +1 -1
- package/dist/esm/wallets/create-wallet.js +62 -13
- package/dist/esm/wallets/create-wallet.js.map +1 -1
- package/dist/esm/wallets/eip5792/get-calls-status.js +39 -63
- package/dist/esm/wallets/eip5792/get-calls-status.js.map +1 -1
- package/dist/esm/wallets/eip5792/get-capabilities.js +13 -49
- package/dist/esm/wallets/eip5792/get-capabilities.js.map +1 -1
- package/dist/esm/wallets/eip5792/send-calls.js +33 -48
- package/dist/esm/wallets/eip5792/send-calls.js.map +1 -1
- package/dist/esm/wallets/in-app/core/{eip5972 → eip5792}/in-app-wallet-calls.js +1 -5
- package/dist/esm/wallets/in-app/core/eip5792/in-app-wallet-calls.js.map +1 -0
- package/dist/esm/wallets/in-app/core/eip7702/minimal-account.js +650 -5
- package/dist/esm/wallets/in-app/core/eip7702/minimal-account.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js +32 -1
- package/dist/esm/wallets/in-app/core/wallet/enclave-wallet.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js +3 -3
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js.map +1 -1
- package/dist/esm/wallets/in-app/web/in-app.js +18 -0
- package/dist/esm/wallets/in-app/web/in-app.js.map +1 -1
- package/dist/esm/wallets/injected/index.js +56 -1
- package/dist/esm/wallets/injected/index.js.map +1 -1
- package/dist/esm/wallets/smart/index.js +63 -2
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/esm/wallets/smart/smart-wallet.js +1 -1
- package/dist/esm/wallets/smart/smart-wallet.js.map +1 -1
- package/dist/esm/wallets/wallet-connect/qr-overlay.js +228 -0
- package/dist/esm/wallets/wallet-connect/qr-overlay.js.map +1 -0
- package/dist/types/bridge/Webhook.d.ts +2 -2
- package/dist/types/insight/get-nfts.d.ts +1 -0
- package/dist/types/insight/get-nfts.d.ts.map +1 -1
- package/dist/types/insight/get-tokens.d.ts +1 -0
- package/dist/types/insight/get-tokens.d.ts.map +1 -1
- package/dist/types/react/core/hooks/wallets/useConnect.d.ts +1 -0
- package/dist/types/react/core/hooks/wallets/useConnect.d.ts.map +1 -1
- package/dist/types/react/core/hooks/wallets/useWaitForCallsReceipt.d.ts +1 -1
- package/dist/types/react/core/utils/storage.d.ts +1 -1
- package/dist/types/react/web/utils/storage.d.ts +1 -1
- package/dist/types/transaction/actions/estimate-gas.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/wallets/coinbase/coinbase-web.d.ts.map +1 -1
- package/dist/types/wallets/create-wallet.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/get-calls-status.d.ts +2 -1
- package/dist/types/wallets/eip5792/get-calls-status.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/get-capabilities.d.ts +1 -0
- package/dist/types/wallets/eip5792/get-capabilities.d.ts.map +1 -1
- package/dist/types/wallets/eip5792/send-calls.d.ts +6 -1
- package/dist/types/wallets/eip5792/send-calls.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/{eip5972 → eip5792}/in-app-wallet-calls.d.ts +3 -2
- package/dist/types/wallets/in-app/core/eip5792/in-app-wallet-calls.d.ts.map +1 -0
- package/dist/types/wallets/in-app/core/eip7702/minimal-account.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/enclave-wallet.d.ts.map +1 -1
- package/dist/types/wallets/in-app/web/in-app.d.ts +18 -0
- package/dist/types/wallets/in-app/web/in-app.d.ts.map +1 -1
- package/dist/types/wallets/injected/index.d.ts.map +1 -1
- package/dist/types/wallets/interfaces/wallet.d.ts +22 -0
- package/dist/types/wallets/interfaces/wallet.d.ts.map +1 -1
- package/dist/types/wallets/smart/index.d.ts.map +1 -1
- package/dist/types/wallets/wallet-connect/qr-overlay.d.ts +58 -0
- package/dist/types/wallets/wallet-connect/qr-overlay.d.ts.map +1 -0
- package/dist/types/wallets/wallet-connect/types.d.ts +13 -0
- package/dist/types/wallets/wallet-connect/types.d.ts.map +1 -1
- package/package.json +4 -2
- package/src/extensions/erc1155/read/getOwnedNFTs.ts +1 -0
- package/src/extensions/erc721/read/getOwnedNFTs.ts +1 -0
- package/src/insight/get-nfts.ts +4 -3
- package/src/insight/get-tokens.ts +4 -2
- package/src/react/core/hooks/wallets/useConnect.ts +11 -1
- package/src/transaction/actions/estimate-gas.ts +14 -42
- package/src/version.ts +1 -1
- package/src/wallets/coinbase/coinbase-web.ts +66 -0
- package/src/wallets/create-wallet.ts +85 -24
- package/src/wallets/eip5792/get-calls-status.test.ts +156 -146
- package/src/wallets/eip5792/get-calls-status.ts +44 -73
- package/src/wallets/eip5792/get-capabilities.test.ts +216 -205
- package/src/wallets/eip5792/get-capabilities.ts +23 -64
- package/src/wallets/eip5792/send-calls.test.ts +183 -189
- package/src/wallets/eip5792/send-calls.ts +53 -71
- package/src/wallets/in-app/core/{eip5972 → eip5792}/in-app-wallet-calls.ts +4 -8
- package/src/wallets/in-app/core/eip7702/minimal-account.ts +666 -5
- package/src/wallets/in-app/core/wallet/enclave-wallet.ts +36 -1
- package/src/wallets/in-app/core/wallet/in-app-core.ts +4 -4
- package/src/wallets/in-app/web/in-app.ts +18 -0
- package/src/wallets/injected/index.ts +63 -0
- package/src/wallets/interfaces/wallet.ts +31 -0
- package/src/wallets/smart/index.ts +71 -3
- package/src/wallets/smart/smart-wallet.ts +1 -1
- package/src/wallets/wallet-connect/qr-overlay.ts +322 -0
- package/src/wallets/wallet-connect/types.ts +13 -0
- package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-calls.js.map +0 -1
- package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js +0 -41
- package/dist/cjs/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js.map +0 -1
- package/dist/cjs/wallets/smart/lib/smart-wallet-capabilities.js +0 -30
- package/dist/cjs/wallets/smart/lib/smart-wallet-capabilities.js.map +0 -1
- package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-calls.js.map +0 -1
- package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js +0 -38
- package/dist/esm/wallets/in-app/core/eip5972/in-app-wallet-capabilities.js.map +0 -1
- package/dist/esm/wallets/smart/lib/smart-wallet-capabilities.js +0 -27
- package/dist/esm/wallets/smart/lib/smart-wallet-capabilities.js.map +0 -1
- package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-calls.d.ts.map +0 -1
- package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-capabilities.d.ts +0 -20
- package/dist/types/wallets/in-app/core/eip5972/in-app-wallet-capabilities.d.ts.map +0 -1
- package/dist/types/wallets/smart/lib/smart-wallet-capabilities.d.ts +0 -20
- package/dist/types/wallets/smart/lib/smart-wallet-capabilities.d.ts.map +0 -1
- package/src/wallets/in-app/core/eip5972/in-app-wallet-capabilities.ts +0 -47
- package/src/wallets/smart/lib/smart-wallet-capabilities.ts +0 -32
|
@@ -179,7 +179,7 @@ export class EnclaveWallet implements IWebWallet {
|
|
|
179
179
|
storage,
|
|
180
180
|
});
|
|
181
181
|
};
|
|
182
|
-
|
|
182
|
+
const account: Account = {
|
|
183
183
|
address: getAddress(address),
|
|
184
184
|
async sendTransaction(tx) {
|
|
185
185
|
const rpcRequest = getRpcClient({
|
|
@@ -264,7 +264,42 @@ export class EnclaveWallet implements IWebWallet {
|
|
|
264
264
|
|
|
265
265
|
return signature as Hex;
|
|
266
266
|
},
|
|
267
|
+
sendCalls: async (options) => {
|
|
268
|
+
const { inAppWalletSendCalls } = await import(
|
|
269
|
+
"../eip5792/in-app-wallet-calls.js"
|
|
270
|
+
);
|
|
271
|
+
const firstCall = options.calls[0];
|
|
272
|
+
if (!firstCall) {
|
|
273
|
+
throw new Error("No calls to send");
|
|
274
|
+
}
|
|
275
|
+
const client = firstCall.client;
|
|
276
|
+
const chain = firstCall.chain || options.chain;
|
|
277
|
+
const id = await inAppWalletSendCalls({
|
|
278
|
+
account: account,
|
|
279
|
+
calls: options.calls,
|
|
280
|
+
});
|
|
281
|
+
return { chain, client, id };
|
|
282
|
+
},
|
|
283
|
+
getCallsStatus: async (options) => {
|
|
284
|
+
const { inAppWalletGetCallsStatus } = await import(
|
|
285
|
+
"../eip5792/in-app-wallet-calls.js"
|
|
286
|
+
);
|
|
287
|
+
return inAppWalletGetCallsStatus(options);
|
|
288
|
+
},
|
|
289
|
+
getCapabilities: async (options) => {
|
|
290
|
+
return {
|
|
291
|
+
[options.chainId ?? 1]: {
|
|
292
|
+
atomic: {
|
|
293
|
+
status: "unsupported",
|
|
294
|
+
},
|
|
295
|
+
paymasterService: {
|
|
296
|
+
supported: false,
|
|
297
|
+
},
|
|
298
|
+
},
|
|
299
|
+
};
|
|
300
|
+
},
|
|
267
301
|
};
|
|
302
|
+
return account;
|
|
268
303
|
}
|
|
269
304
|
}
|
|
270
305
|
|
|
@@ -57,7 +57,7 @@ export function createInAppWallet(args: {
|
|
|
57
57
|
let client: ThirdwebClient | undefined;
|
|
58
58
|
let authToken: string | null = null;
|
|
59
59
|
|
|
60
|
-
const resolveSmartAccountOptionsFromEcosystem = async (options
|
|
60
|
+
const resolveSmartAccountOptionsFromEcosystem = async (options?: {
|
|
61
61
|
chain?: Chain;
|
|
62
62
|
}) => {
|
|
63
63
|
if (ecosystem) {
|
|
@@ -78,7 +78,7 @@ export function createInAppWallet(args: {
|
|
|
78
78
|
// default to 4337
|
|
79
79
|
const { defaultChainId } = ecosystemOptions.smartAccountOptions;
|
|
80
80
|
const preferredChain =
|
|
81
|
-
options
|
|
81
|
+
options?.chain ??
|
|
82
82
|
(defaultChainId ? getCachedChain(defaultChainId) : undefined);
|
|
83
83
|
if (!preferredChain) {
|
|
84
84
|
throw new Error(
|
|
@@ -108,7 +108,7 @@ export function createInAppWallet(args: {
|
|
|
108
108
|
ecosystem,
|
|
109
109
|
);
|
|
110
110
|
|
|
111
|
-
await resolveSmartAccountOptionsFromEcosystem(
|
|
111
|
+
await resolveSmartAccountOptionsFromEcosystem();
|
|
112
112
|
|
|
113
113
|
const {
|
|
114
114
|
account: connectedAccount,
|
|
@@ -145,7 +145,7 @@ export function createInAppWallet(args: {
|
|
|
145
145
|
ecosystem,
|
|
146
146
|
);
|
|
147
147
|
|
|
148
|
-
await resolveSmartAccountOptionsFromEcosystem(
|
|
148
|
+
await resolveSmartAccountOptionsFromEcosystem();
|
|
149
149
|
|
|
150
150
|
const {
|
|
151
151
|
account: connectedAccount,
|
|
@@ -299,6 +299,24 @@ import type {
|
|
|
299
299
|
* });
|
|
300
300
|
* ```
|
|
301
301
|
*
|
|
302
|
+
* ### Get the auth token for the wallet
|
|
303
|
+
*
|
|
304
|
+
* You can get the auth token for the wallet by calling `wallet.getAuthToken()`.
|
|
305
|
+
*
|
|
306
|
+
* ```ts
|
|
307
|
+
* import { inAppWallet } from "thirdweb/wallets";
|
|
308
|
+
*
|
|
309
|
+
* const wallet = inAppWallet();
|
|
310
|
+
*
|
|
311
|
+
* await wallet.connect({
|
|
312
|
+
* client,
|
|
313
|
+
* strategy: "google",
|
|
314
|
+
* });
|
|
315
|
+
*
|
|
316
|
+
* const authToken = await wallet.getAuthToken(); // this will return a JWT token that can be used to authenticate the user in the backend
|
|
317
|
+
* console.log(authToken);
|
|
318
|
+
* ```
|
|
319
|
+
*
|
|
302
320
|
* @returns The created in-app wallet.
|
|
303
321
|
* @wallet
|
|
304
322
|
*/
|
|
@@ -3,6 +3,7 @@ import {
|
|
|
3
3
|
getTypesForEIP712Domain,
|
|
4
4
|
type SignTypedDataParameters,
|
|
5
5
|
serializeTypedData,
|
|
6
|
+
stringify,
|
|
6
7
|
validateTypedData,
|
|
7
8
|
} from "viem";
|
|
8
9
|
import { isInsufficientFundsError } from "../../analytics/track/helpers.js";
|
|
@@ -22,6 +23,10 @@ import {
|
|
|
22
23
|
} from "../../utils/encoding/hex.js";
|
|
23
24
|
import { parseTypedData } from "../../utils/signatures/helpers/parse-typed-data.js";
|
|
24
25
|
import type { InjectedSupportedWalletIds } from "../__generated__/wallet-ids.js";
|
|
26
|
+
import { toGetCallsStatusResponse } from "../eip5792/get-calls-status.js";
|
|
27
|
+
import { toGetCapabilitiesResult } from "../eip5792/get-capabilities.js";
|
|
28
|
+
import { toProviderCallParams } from "../eip5792/send-calls.js";
|
|
29
|
+
import type { GetCallsStatusRawResponse } from "../eip5792/types.js";
|
|
25
30
|
import type { Account, SendTransactionOption } from "../interfaces/wallet.js";
|
|
26
31
|
import type { DisconnectFn, SwitchChainFn } from "../types.js";
|
|
27
32
|
import { getValidPublicRPCUrl } from "../utils/chains.js";
|
|
@@ -300,6 +305,64 @@ function createAccount({
|
|
|
300
305
|
);
|
|
301
306
|
return result;
|
|
302
307
|
},
|
|
308
|
+
async sendCalls(options) {
|
|
309
|
+
try {
|
|
310
|
+
const { callParams, chain } = await toProviderCallParams(
|
|
311
|
+
options,
|
|
312
|
+
account,
|
|
313
|
+
);
|
|
314
|
+
const callId = await provider.request({
|
|
315
|
+
method: "wallet_sendCalls",
|
|
316
|
+
params: callParams,
|
|
317
|
+
});
|
|
318
|
+
if (callId && typeof callId === "object" && "id" in callId) {
|
|
319
|
+
return { chain, client, id: callId.id };
|
|
320
|
+
}
|
|
321
|
+
return { chain, client, id: callId };
|
|
322
|
+
} catch (error) {
|
|
323
|
+
if (/unsupport|not support/i.test((error as Error).message)) {
|
|
324
|
+
throw new Error(
|
|
325
|
+
`${id} errored calling wallet_sendCalls, with error: ${error instanceof Error ? error.message : stringify(error)}`,
|
|
326
|
+
);
|
|
327
|
+
}
|
|
328
|
+
throw error;
|
|
329
|
+
}
|
|
330
|
+
},
|
|
331
|
+
async getCallsStatus(options) {
|
|
332
|
+
try {
|
|
333
|
+
const rawResponse = (await provider.request({
|
|
334
|
+
method: "wallet_getCallsStatus",
|
|
335
|
+
params: [options.id],
|
|
336
|
+
})) as GetCallsStatusRawResponse;
|
|
337
|
+
return toGetCallsStatusResponse(rawResponse);
|
|
338
|
+
} catch (error) {
|
|
339
|
+
if (/unsupport|not support/i.test((error as Error).message)) {
|
|
340
|
+
throw new Error(
|
|
341
|
+
`${id} does not support wallet_getCallsStatus, reach out to them directly to request EIP-5792 support.`,
|
|
342
|
+
);
|
|
343
|
+
}
|
|
344
|
+
throw error;
|
|
345
|
+
}
|
|
346
|
+
},
|
|
347
|
+
async getCapabilities(options) {
|
|
348
|
+
const chainId = options.chainId;
|
|
349
|
+
try {
|
|
350
|
+
const result = await provider.request({
|
|
351
|
+
method: "wallet_getCapabilities",
|
|
352
|
+
params: [getAddress(account.address)],
|
|
353
|
+
});
|
|
354
|
+
return toGetCapabilitiesResult(result, chainId);
|
|
355
|
+
} catch (error: unknown) {
|
|
356
|
+
if (
|
|
357
|
+
/unsupport|not support|not available/i.test((error as Error).message)
|
|
358
|
+
) {
|
|
359
|
+
return {
|
|
360
|
+
message: `${id} does not support wallet_getCapabilities, reach out to them directly to request EIP-5792 support.`,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
throw error;
|
|
364
|
+
}
|
|
365
|
+
},
|
|
303
366
|
};
|
|
304
367
|
|
|
305
368
|
return account;
|
|
@@ -2,6 +2,7 @@ import type { Address } from "abitype";
|
|
|
2
2
|
import type * as ox__TypedData from "ox/TypedData";
|
|
3
3
|
import type { Hex, SignableMessage } from "viem";
|
|
4
4
|
import type { Chain } from "../../chains/types.js";
|
|
5
|
+
import type { ThirdwebClient } from "../../client/client.js";
|
|
5
6
|
import type {
|
|
6
7
|
AuthorizationRequest,
|
|
7
8
|
SignedAuthorization,
|
|
@@ -12,6 +13,15 @@ import type {
|
|
|
12
13
|
} from "../../transaction/prepare-transaction.js";
|
|
13
14
|
import type { SerializableTransaction } from "../../transaction/serialize-transaction.js";
|
|
14
15
|
import type { SendTransactionResult } from "../../transaction/types.js";
|
|
16
|
+
import type { GetCapabilitiesResult } from "../eip5792/get-capabilities.js";
|
|
17
|
+
import type {
|
|
18
|
+
SendCallsOptions,
|
|
19
|
+
SendCallsResult,
|
|
20
|
+
} from "../eip5792/send-calls.js";
|
|
21
|
+
import type {
|
|
22
|
+
GetCallsStatusResponse,
|
|
23
|
+
WalletSendCallsId,
|
|
24
|
+
} from "../eip5792/types.js";
|
|
15
25
|
import type { WalletEmitter } from "../wallet-emitter.js";
|
|
16
26
|
import type {
|
|
17
27
|
CreateWalletArgs,
|
|
@@ -300,4 +310,25 @@ export type Account = {
|
|
|
300
310
|
* ```
|
|
301
311
|
*/
|
|
302
312
|
watchAsset?: (asset: WatchAssetParams) => Promise<boolean>;
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* EIP-5792: Send the given array of calls via the wallet provider
|
|
316
|
+
*/
|
|
317
|
+
sendCalls?: (
|
|
318
|
+
calls: Omit<SendCallsOptions, "wallet">,
|
|
319
|
+
) => Promise<Omit<SendCallsResult, "wallet">>;
|
|
320
|
+
/**
|
|
321
|
+
* EIP-5792: Get the status of the given call bundle
|
|
322
|
+
*/
|
|
323
|
+
getCallsStatus?: (options: {
|
|
324
|
+
id: WalletSendCallsId;
|
|
325
|
+
chain: Chain;
|
|
326
|
+
client: ThirdwebClient;
|
|
327
|
+
}) => Promise<GetCallsStatusResponse>;
|
|
328
|
+
/**
|
|
329
|
+
* EIP-5792: Get the capabilities of the wallet
|
|
330
|
+
*/
|
|
331
|
+
getCapabilities?: (options: {
|
|
332
|
+
chainId?: number;
|
|
333
|
+
}) => Promise<GetCapabilitiesResult>;
|
|
303
334
|
};
|
|
@@ -80,7 +80,7 @@ export async function connectSmartAccount(
|
|
|
80
80
|
connectionOptions: SmartWalletConnectionOptions,
|
|
81
81
|
creationOptions: SmartWalletOptions,
|
|
82
82
|
): Promise<[Account, Chain]> {
|
|
83
|
-
const { personalAccount, client
|
|
83
|
+
const { personalAccount, client } = connectionOptions;
|
|
84
84
|
|
|
85
85
|
if (!personalAccount) {
|
|
86
86
|
throw new Error(
|
|
@@ -89,7 +89,7 @@ export async function connectSmartAccount(
|
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
const options = creationOptions;
|
|
92
|
-
const chain =
|
|
92
|
+
const chain = creationOptions.chain;
|
|
93
93
|
const sponsorGas =
|
|
94
94
|
"gasless" in options ? options.gasless : options.sponsorGas;
|
|
95
95
|
if (await isZkSyncChain(chain)) {
|
|
@@ -226,7 +226,7 @@ async function createSmartAccount(
|
|
|
226
226
|
);
|
|
227
227
|
}
|
|
228
228
|
}
|
|
229
|
-
|
|
229
|
+
const sponsorGas = options.sponsorGas;
|
|
230
230
|
let accountContract = options.accountContract;
|
|
231
231
|
const account: Account = {
|
|
232
232
|
address: getAddress(accountContract.address),
|
|
@@ -366,6 +366,40 @@ async function createSmartAccount(
|
|
|
366
366
|
typedData,
|
|
367
367
|
});
|
|
368
368
|
},
|
|
369
|
+
sendCalls: async (options) => {
|
|
370
|
+
const { inAppWalletSendCalls } = await import(
|
|
371
|
+
"../in-app/core/eip5792/in-app-wallet-calls.js"
|
|
372
|
+
);
|
|
373
|
+
const firstCall = options.calls[0];
|
|
374
|
+
if (!firstCall) {
|
|
375
|
+
throw new Error("No calls to send");
|
|
376
|
+
}
|
|
377
|
+
const client = firstCall.client;
|
|
378
|
+
const chain = firstCall.chain || options.chain;
|
|
379
|
+
const id = await inAppWalletSendCalls({
|
|
380
|
+
account: account,
|
|
381
|
+
calls: options.calls,
|
|
382
|
+
});
|
|
383
|
+
return { chain, client, id };
|
|
384
|
+
},
|
|
385
|
+
getCallsStatus: async (options) => {
|
|
386
|
+
const { inAppWalletGetCallsStatus } = await import(
|
|
387
|
+
"../in-app/core/eip5792/in-app-wallet-calls.js"
|
|
388
|
+
);
|
|
389
|
+
return inAppWalletGetCallsStatus(options);
|
|
390
|
+
},
|
|
391
|
+
getCapabilities: async (options) => {
|
|
392
|
+
return {
|
|
393
|
+
[options.chainId ?? 1]: {
|
|
394
|
+
atomic: {
|
|
395
|
+
status: "supported",
|
|
396
|
+
},
|
|
397
|
+
paymasterService: {
|
|
398
|
+
supported: sponsorGas ?? false,
|
|
399
|
+
},
|
|
400
|
+
},
|
|
401
|
+
};
|
|
402
|
+
},
|
|
369
403
|
};
|
|
370
404
|
return account;
|
|
371
405
|
}
|
|
@@ -509,6 +543,40 @@ function createZkSyncAccount(args: {
|
|
|
509
543
|
const typedData = parseTypedData(_typedData);
|
|
510
544
|
return connectionOptions.personalAccount.signTypedData(typedData);
|
|
511
545
|
},
|
|
546
|
+
sendCalls: async (options) => {
|
|
547
|
+
const { inAppWalletSendCalls } = await import(
|
|
548
|
+
"../in-app/core/eip5792/in-app-wallet-calls.js"
|
|
549
|
+
);
|
|
550
|
+
const firstCall = options.calls[0];
|
|
551
|
+
if (!firstCall) {
|
|
552
|
+
throw new Error("No calls to send");
|
|
553
|
+
}
|
|
554
|
+
const client = firstCall.client;
|
|
555
|
+
const chain = firstCall.chain || options.chain;
|
|
556
|
+
const id = await inAppWalletSendCalls({
|
|
557
|
+
account: account,
|
|
558
|
+
calls: options.calls,
|
|
559
|
+
});
|
|
560
|
+
return { chain, client, id };
|
|
561
|
+
},
|
|
562
|
+
getCallsStatus: async (options) => {
|
|
563
|
+
const { inAppWalletGetCallsStatus } = await import(
|
|
564
|
+
"../in-app/core/eip5792/in-app-wallet-calls.js"
|
|
565
|
+
);
|
|
566
|
+
return inAppWalletGetCallsStatus(options);
|
|
567
|
+
},
|
|
568
|
+
getCapabilities: async (options) => {
|
|
569
|
+
return {
|
|
570
|
+
[options.chainId ?? 1]: {
|
|
571
|
+
atomic: {
|
|
572
|
+
status: "unsupported",
|
|
573
|
+
},
|
|
574
|
+
paymasterService: {
|
|
575
|
+
supported: args.sponsorGas ?? false,
|
|
576
|
+
},
|
|
577
|
+
},
|
|
578
|
+
};
|
|
579
|
+
},
|
|
512
580
|
};
|
|
513
581
|
return account;
|
|
514
582
|
}
|
|
@@ -229,7 +229,7 @@ export function smartWallet(
|
|
|
229
229
|
const { connectSmartAccount } = await import("./index.js");
|
|
230
230
|
const [connectedAccount, connectedChain] = await connectSmartAccount(
|
|
231
231
|
{ ...lastConnectOptions, chain: newChain },
|
|
232
|
-
createOptions,
|
|
232
|
+
{ ...createOptions, chain: newChain },
|
|
233
233
|
);
|
|
234
234
|
// set the states
|
|
235
235
|
account = connectedAccount;
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Vanilla JavaScript QR Code overlay utility for WalletConnect URIs
|
|
3
|
+
* Works in any browser context without requiring React or other frameworks
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
interface QROverlayOptions {
|
|
7
|
+
/**
|
|
8
|
+
* Custom styles to apply to the overlay
|
|
9
|
+
*/
|
|
10
|
+
overlayStyles?: Partial<CSSStyleDeclaration>;
|
|
11
|
+
/**
|
|
12
|
+
* Custom styles to apply to the modal container
|
|
13
|
+
*/
|
|
14
|
+
modalStyles?: Partial<CSSStyleDeclaration>;
|
|
15
|
+
/**
|
|
16
|
+
* QR code size in pixels
|
|
17
|
+
*/
|
|
18
|
+
qrSize?: number;
|
|
19
|
+
/**
|
|
20
|
+
* Show close button
|
|
21
|
+
*/
|
|
22
|
+
showCloseButton?: boolean;
|
|
23
|
+
/**
|
|
24
|
+
* Custom close button text
|
|
25
|
+
*/
|
|
26
|
+
closeButtonText?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Theme preference
|
|
29
|
+
*/
|
|
30
|
+
theme?: "light" | "dark";
|
|
31
|
+
/**
|
|
32
|
+
* Custom container element to append the overlay to
|
|
33
|
+
*/
|
|
34
|
+
container?: HTMLElement;
|
|
35
|
+
/**
|
|
36
|
+
* Callback called when user cancels the overlay (closes without connecting)
|
|
37
|
+
*/
|
|
38
|
+
onCancel?: () => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface QROverlay {
|
|
42
|
+
/**
|
|
43
|
+
* Remove the overlay from the DOM
|
|
44
|
+
*/
|
|
45
|
+
destroy: () => void;
|
|
46
|
+
/**
|
|
47
|
+
* Hide the overlay (without removing from DOM)
|
|
48
|
+
*/
|
|
49
|
+
hide: () => void;
|
|
50
|
+
/**
|
|
51
|
+
* Show the overlay
|
|
52
|
+
*/
|
|
53
|
+
show: () => void;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Creates a QR code overlay for the given WalletConnect URI
|
|
58
|
+
*/
|
|
59
|
+
export function createQROverlay(
|
|
60
|
+
uri: string,
|
|
61
|
+
options: QROverlayOptions = {},
|
|
62
|
+
): QROverlay {
|
|
63
|
+
const {
|
|
64
|
+
qrSize = 280,
|
|
65
|
+
showCloseButton = true,
|
|
66
|
+
closeButtonText = "×",
|
|
67
|
+
theme = "light",
|
|
68
|
+
container = document.body,
|
|
69
|
+
onCancel,
|
|
70
|
+
} = options;
|
|
71
|
+
|
|
72
|
+
// Create overlay backdrop
|
|
73
|
+
const overlay = document.createElement("div");
|
|
74
|
+
overlay.style.cssText = `
|
|
75
|
+
position: fixed;
|
|
76
|
+
inset: 0;
|
|
77
|
+
background-color: ${theme === "dark" ? "rgba(0, 0, 0, 0.8)" : "rgba(0, 0, 0, 0.5)"};
|
|
78
|
+
backdrop-filter: blur(10px);
|
|
79
|
+
z-index: 9999;
|
|
80
|
+
display: flex;
|
|
81
|
+
align-items: center;
|
|
82
|
+
justify-content: center;
|
|
83
|
+
animation: fadeIn 300ms ease-out;
|
|
84
|
+
`;
|
|
85
|
+
|
|
86
|
+
// Apply custom overlay styles
|
|
87
|
+
if (options.overlayStyles) {
|
|
88
|
+
Object.assign(overlay.style, options.overlayStyles);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// Create modal container
|
|
92
|
+
const modal = document.createElement("div");
|
|
93
|
+
modal.style.cssText = `
|
|
94
|
+
background: ${theme === "dark" ? "#1f1f1f" : "#ffffff"};
|
|
95
|
+
border-radius: 16px;
|
|
96
|
+
padding: 24px;
|
|
97
|
+
box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04);
|
|
98
|
+
max-width: 90vw;
|
|
99
|
+
max-height: 90vh;
|
|
100
|
+
position: relative;
|
|
101
|
+
animation: scaleIn 300ms ease-out;
|
|
102
|
+
`;
|
|
103
|
+
|
|
104
|
+
// Apply custom modal styles
|
|
105
|
+
if (options.modalStyles) {
|
|
106
|
+
Object.assign(modal.style, options.modalStyles);
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Create close button
|
|
110
|
+
if (showCloseButton) {
|
|
111
|
+
const closeButton = document.createElement("button");
|
|
112
|
+
closeButton.textContent = closeButtonText;
|
|
113
|
+
closeButton.style.cssText = `
|
|
114
|
+
position: absolute;
|
|
115
|
+
top: 16px;
|
|
116
|
+
right: 16px;
|
|
117
|
+
background: none;
|
|
118
|
+
border: none;
|
|
119
|
+
font-size: 24px;
|
|
120
|
+
cursor: pointer;
|
|
121
|
+
color: ${theme === "dark" ? "#ffffff" : "#000000"};
|
|
122
|
+
width: 32px;
|
|
123
|
+
height: 32px;
|
|
124
|
+
display: flex;
|
|
125
|
+
align-items: center;
|
|
126
|
+
justify-content: center;
|
|
127
|
+
border-radius: 8px;
|
|
128
|
+
transition: background-color 0.2s;
|
|
129
|
+
`;
|
|
130
|
+
|
|
131
|
+
closeButton.addEventListener("mouseenter", () => {
|
|
132
|
+
closeButton.style.backgroundColor =
|
|
133
|
+
theme === "dark" ? "rgba(255, 255, 255, 0.1)" : "rgba(0, 0, 0, 0.1)";
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
closeButton.addEventListener("mouseleave", () => {
|
|
137
|
+
closeButton.style.backgroundColor = "transparent";
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
closeButton.addEventListener("click", () => {
|
|
141
|
+
destroyOverlay(true);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
modal.appendChild(closeButton);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// Create QR code container
|
|
148
|
+
const qrContainer = document.createElement("div");
|
|
149
|
+
qrContainer.style.cssText = `
|
|
150
|
+
display: flex;
|
|
151
|
+
flex-direction: column;
|
|
152
|
+
align-items: center;
|
|
153
|
+
gap: 16px;
|
|
154
|
+
`;
|
|
155
|
+
|
|
156
|
+
// Create title
|
|
157
|
+
const title = document.createElement("h3");
|
|
158
|
+
title.textContent = "Scan to Connect";
|
|
159
|
+
title.style.cssText = `
|
|
160
|
+
margin: 0;
|
|
161
|
+
font-size: 18px;
|
|
162
|
+
font-weight: 600;
|
|
163
|
+
color: ${theme === "dark" ? "#ffffff" : "#000000"};
|
|
164
|
+
text-align: center;
|
|
165
|
+
`;
|
|
166
|
+
|
|
167
|
+
// Create QR code canvas
|
|
168
|
+
const qrCanvas = document.createElement("canvas");
|
|
169
|
+
qrCanvas.width = qrSize;
|
|
170
|
+
qrCanvas.height = qrSize;
|
|
171
|
+
qrCanvas.style.cssText = `
|
|
172
|
+
border: 1px solid ${theme === "dark" ? "#333333" : "#e5e5e5"};
|
|
173
|
+
border-radius: 12px;
|
|
174
|
+
`;
|
|
175
|
+
|
|
176
|
+
// Generate QR code
|
|
177
|
+
generateQRCode(uri, qrCanvas, qrSize).catch(console.error);
|
|
178
|
+
|
|
179
|
+
// Create copy button for the URI
|
|
180
|
+
const copyButton = document.createElement("button");
|
|
181
|
+
copyButton.textContent = "Copy URI";
|
|
182
|
+
copyButton.style.cssText = `
|
|
183
|
+
background: ${theme === "dark" ? "#333333" : "#f5f5f5"};
|
|
184
|
+
border: 1px solid ${theme === "dark" ? "#444444" : "#e5e5e5"};
|
|
185
|
+
color: ${theme === "dark" ? "#ffffff" : "#000000"};
|
|
186
|
+
padding: 8px 16px;
|
|
187
|
+
border-radius: 8px;
|
|
188
|
+
cursor: pointer;
|
|
189
|
+
font-size: 14px;
|
|
190
|
+
transition: background-color 0.2s;
|
|
191
|
+
`;
|
|
192
|
+
|
|
193
|
+
copyButton.addEventListener("click", async () => {
|
|
194
|
+
try {
|
|
195
|
+
await navigator.clipboard.writeText(uri);
|
|
196
|
+
const originalText = copyButton.textContent;
|
|
197
|
+
copyButton.textContent = "Copied!";
|
|
198
|
+
setTimeout(() => {
|
|
199
|
+
copyButton.textContent = originalText;
|
|
200
|
+
}, 2000);
|
|
201
|
+
} catch (err) {
|
|
202
|
+
console.error("Failed to copy URI:", err);
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
// Assemble the modal
|
|
207
|
+
qrContainer.appendChild(title);
|
|
208
|
+
qrContainer.appendChild(qrCanvas);
|
|
209
|
+
qrContainer.appendChild(copyButton);
|
|
210
|
+
modal.appendChild(qrContainer);
|
|
211
|
+
overlay.appendChild(modal);
|
|
212
|
+
|
|
213
|
+
// Add CSS animations
|
|
214
|
+
const style = document.createElement("style");
|
|
215
|
+
style.textContent = `
|
|
216
|
+
@keyframes fadeIn {
|
|
217
|
+
from { opacity: 0; }
|
|
218
|
+
to { opacity: 1; }
|
|
219
|
+
}
|
|
220
|
+
@keyframes fadeOut {
|
|
221
|
+
from { opacity: 1; }
|
|
222
|
+
to { opacity: 0; }
|
|
223
|
+
}
|
|
224
|
+
@keyframes scaleIn {
|
|
225
|
+
from { transform: scale(0.9); opacity: 0; }
|
|
226
|
+
to { transform: scale(1); opacity: 1; }
|
|
227
|
+
}
|
|
228
|
+
@keyframes scaleOut {
|
|
229
|
+
from { transform: scale(1); opacity: 1; }
|
|
230
|
+
to { transform: scale(0.9); opacity: 0; }
|
|
231
|
+
}
|
|
232
|
+
`;
|
|
233
|
+
document.head.appendChild(style);
|
|
234
|
+
|
|
235
|
+
// Event handlers
|
|
236
|
+
const handleEscapeKey = (event: KeyboardEvent) => {
|
|
237
|
+
if (event.key === "Escape") {
|
|
238
|
+
destroyOverlay(true);
|
|
239
|
+
}
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const handleOverlayClick = (event: MouseEvent) => {
|
|
243
|
+
if (event.target === overlay) {
|
|
244
|
+
destroyOverlay(true);
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
// Add event listeners
|
|
249
|
+
document.addEventListener("keydown", handleEscapeKey);
|
|
250
|
+
overlay.addEventListener("click", handleOverlayClick);
|
|
251
|
+
|
|
252
|
+
// Append to container
|
|
253
|
+
container.appendChild(overlay);
|
|
254
|
+
|
|
255
|
+
function destroyOverlay(userInitiated = false) {
|
|
256
|
+
document.removeEventListener("keydown", handleEscapeKey);
|
|
257
|
+
overlay.removeEventListener("click", handleOverlayClick);
|
|
258
|
+
|
|
259
|
+
// Call onCancel callback only if user initiated the close action
|
|
260
|
+
if (userInitiated && onCancel) {
|
|
261
|
+
onCancel();
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// Animate both overlay and modal out
|
|
265
|
+
overlay.style.animation = "fadeOut 200ms ease-in";
|
|
266
|
+
modal.style.animation = "scaleOut 200ms ease-in";
|
|
267
|
+
|
|
268
|
+
const cleanup = () => {
|
|
269
|
+
if (overlay.parentNode) {
|
|
270
|
+
overlay.parentNode.removeChild(overlay);
|
|
271
|
+
}
|
|
272
|
+
if (style.parentNode) {
|
|
273
|
+
style.parentNode.removeChild(style);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
overlay.addEventListener("animationend", cleanup, { once: true });
|
|
278
|
+
|
|
279
|
+
// Fallback cleanup in case animation doesn't fire
|
|
280
|
+
setTimeout(cleanup, 250);
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
function hideOverlay() {
|
|
284
|
+
overlay.style.display = "none";
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function showOverlay() {
|
|
288
|
+
overlay.style.display = "flex";
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
return {
|
|
292
|
+
destroy: () => destroyOverlay(false), // Programmatic cleanup, don't call onCancel
|
|
293
|
+
hide: hideOverlay,
|
|
294
|
+
show: showOverlay,
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* QR code generator that tries to use a real QR library if available,
|
|
300
|
+
* otherwise falls back to a placeholder
|
|
301
|
+
*/
|
|
302
|
+
async function generateQRCode(
|
|
303
|
+
text: string,
|
|
304
|
+
canvas: HTMLCanvasElement,
|
|
305
|
+
size: number,
|
|
306
|
+
) {
|
|
307
|
+
const ctx = canvas.getContext("2d");
|
|
308
|
+
if (!ctx) return;
|
|
309
|
+
|
|
310
|
+
// Try to dynamically import a QR code library if available
|
|
311
|
+
// This allows the overlay to work with or without a QR code dependency
|
|
312
|
+
const { toCanvas } = await import("qrcode");
|
|
313
|
+
await toCanvas(canvas, text, {
|
|
314
|
+
width: size,
|
|
315
|
+
margin: 2,
|
|
316
|
+
color: {
|
|
317
|
+
dark: "#000000",
|
|
318
|
+
light: "#ffffff",
|
|
319
|
+
},
|
|
320
|
+
});
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
@@ -157,6 +157,19 @@ export type WCConnectOptions = {
|
|
|
157
157
|
* ```
|
|
158
158
|
*/
|
|
159
159
|
onDisplayUri?: (_uri: string) => void;
|
|
160
|
+
/**
|
|
161
|
+
* Callback that gets called when the user cancels the connection process (e.g., closes the QR modal).
|
|
162
|
+
* This is only called for user-initiated cancellations, not for programmatic cleanup.
|
|
163
|
+
*
|
|
164
|
+
* ```tsx
|
|
165
|
+
* await wallet.connect({
|
|
166
|
+
* onCancel: () => {
|
|
167
|
+
* console.log("User cancelled wallet connection");
|
|
168
|
+
* }
|
|
169
|
+
* })
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
onCancel?: () => void;
|
|
160
173
|
}
|
|
161
174
|
>;
|
|
162
175
|
};
|