thirdweb 5.105.19 → 5.105.21
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/pay/buyWithCrypto/getQuote.js +8 -8
- package/dist/cjs/pay/buyWithCrypto/getQuote.js.map +1 -1
- package/dist/cjs/pay/buyWithCrypto/getTransfer.js +4 -4
- package/dist/cjs/pay/buyWithCrypto/getTransfer.js.map +1 -1
- package/dist/cjs/pay/buyWithFiat/getQuote.js +3 -3
- package/dist/cjs/pay/buyWithFiat/getQuote.js.map +1 -1
- package/dist/cjs/react/core/hooks/usePaymentMethods.js +2 -2
- package/dist/cjs/react/core/hooks/usePaymentMethods.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/version.js +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/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/smart/index.js +2 -2
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/signing.js +26 -95
- package/dist/cjs/wallets/smart/lib/signing.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/pay/buyWithCrypto/getQuote.js +8 -8
- package/dist/esm/pay/buyWithCrypto/getQuote.js.map +1 -1
- package/dist/esm/pay/buyWithCrypto/getTransfer.js +4 -4
- package/dist/esm/pay/buyWithCrypto/getTransfer.js.map +1 -1
- package/dist/esm/pay/buyWithFiat/getQuote.js +3 -3
- package/dist/esm/pay/buyWithFiat/getQuote.js.map +1 -1
- package/dist/esm/react/core/hooks/usePaymentMethods.js +2 -2
- package/dist/esm/react/core/hooks/usePaymentMethods.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/version.js +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/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/smart/index.js +2 -2
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/esm/wallets/smart/lib/signing.js +27 -96
- package/dist/esm/wallets/smart/lib/signing.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/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/version.d.ts +1 -1
- package/dist/types/wallets/create-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/smart/lib/signing.d.ts +2 -3
- package/dist/types/wallets/smart/lib/signing.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 +5 -3
- package/src/pay/buyWithCrypto/getQuote.ts +8 -8
- package/src/pay/buyWithCrypto/getTransfer.ts +4 -4
- package/src/pay/buyWithFiat/getQuote.ts +3 -3
- package/src/react/core/hooks/usePaymentMethods.ts +2 -2
- package/src/react/core/hooks/wallets/useConnect.ts +11 -1
- package/src/version.ts +1 -1
- package/src/wallets/create-wallet.ts +85 -24
- 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/smart/index.ts +2 -2
- package/src/wallets/smart/lib/signing.ts +34 -121
- package/src/wallets/smart/smart-wallet-integration.test.ts +1 -76
- 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
|
@@ -240,10 +240,10 @@ export function usePaymentMethods(options: {
|
|
|
240
240
|
validOwnedTokens.sort((a, b) => {
|
|
241
241
|
const aDollarBalance =
|
|
242
242
|
Number.parseFloat(toTokens(a.balance, a.originToken.decimals)) *
|
|
243
|
-
(a.originToken.prices
|
|
243
|
+
(a.originToken.prices.USD || 0);
|
|
244
244
|
const bDollarBalance =
|
|
245
245
|
Number.parseFloat(toTokens(b.balance, b.originToken.decimals)) *
|
|
246
|
-
(b.originToken.prices
|
|
246
|
+
(b.originToken.prices.USD || 0);
|
|
247
247
|
return bDollarBalance - aDollarBalance;
|
|
248
248
|
});
|
|
249
249
|
|
|
@@ -79,5 +79,15 @@ export function useConnect(options?: ConnectManagerOptions) {
|
|
|
79
79
|
[connect, options, setConnectionStatus],
|
|
80
80
|
);
|
|
81
81
|
|
|
82
|
-
|
|
82
|
+
const cancelConnection = useCallback(() => {
|
|
83
|
+
setIsConnecting(false);
|
|
84
|
+
setConnectionStatus("disconnected");
|
|
85
|
+
}, [setConnectionStatus]);
|
|
86
|
+
|
|
87
|
+
return {
|
|
88
|
+
connect: handleConnection,
|
|
89
|
+
error,
|
|
90
|
+
isConnecting,
|
|
91
|
+
cancelConnection,
|
|
92
|
+
} as const;
|
|
83
93
|
}
|
package/src/version.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "5.105.
|
|
1
|
+
export const version = "5.105.21";
|
|
@@ -17,6 +17,7 @@ import { inAppWallet } from "./in-app/web/in-app.js";
|
|
|
17
17
|
import { getInjectedProvider } from "./injected/index.js";
|
|
18
18
|
import type { Account, Wallet } from "./interfaces/wallet.js";
|
|
19
19
|
import { smartWallet } from "./smart/smart-wallet.js";
|
|
20
|
+
import type { QROverlay } from "./wallet-connect/qr-overlay.js";
|
|
20
21
|
import type { WCConnectOptions } from "./wallet-connect/types.js";
|
|
21
22
|
import { createWalletEmitter } from "./wallet-emitter.js";
|
|
22
23
|
import type {
|
|
@@ -299,30 +300,90 @@ export function createWallet<const ID extends WalletId>(
|
|
|
299
300
|
"./wallet-connect/controller.js"
|
|
300
301
|
);
|
|
301
302
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
303
|
+
let qrOverlay: QROverlay | undefined;
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
const [
|
|
307
|
+
connectedAccount,
|
|
308
|
+
connectedChain,
|
|
309
|
+
doDisconnect,
|
|
310
|
+
doSwitchChain,
|
|
311
|
+
] = await connectWC(
|
|
312
|
+
{
|
|
313
|
+
...wcOptions,
|
|
314
|
+
walletConnect: {
|
|
315
|
+
...wcOptions.walletConnect,
|
|
316
|
+
onDisplayUri: wcOptions.walletConnect?.showQrModal
|
|
317
|
+
? async (uri) => {
|
|
318
|
+
// Check if we're in a browser environment
|
|
319
|
+
if (
|
|
320
|
+
typeof window !== "undefined" &&
|
|
321
|
+
typeof document !== "undefined"
|
|
322
|
+
) {
|
|
323
|
+
try {
|
|
324
|
+
const { createQROverlay } = await import(
|
|
325
|
+
"./wallet-connect/qr-overlay.js"
|
|
326
|
+
);
|
|
327
|
+
|
|
328
|
+
// Clean up any existing overlay
|
|
329
|
+
if (qrOverlay) {
|
|
330
|
+
qrOverlay.destroy();
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
// Create new QR overlay
|
|
334
|
+
qrOverlay = createQROverlay(uri, {
|
|
335
|
+
theme:
|
|
336
|
+
wcOptions.walletConnect?.qrModalOptions
|
|
337
|
+
?.themeMode ?? "dark",
|
|
338
|
+
qrSize: 280,
|
|
339
|
+
showCloseButton: true,
|
|
340
|
+
onCancel: () => {
|
|
341
|
+
wcOptions.walletConnect?.onCancel?.();
|
|
342
|
+
},
|
|
343
|
+
});
|
|
344
|
+
} catch (error) {
|
|
345
|
+
console.error(
|
|
346
|
+
"Failed to create QR overlay:",
|
|
347
|
+
error,
|
|
348
|
+
);
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
: undefined,
|
|
353
|
+
},
|
|
354
|
+
},
|
|
355
|
+
emitter,
|
|
356
|
+
wallet.id as WCSupportedWalletIds | "walletConnect",
|
|
357
|
+
webLocalStorage,
|
|
358
|
+
sessionHandler,
|
|
359
|
+
);
|
|
360
|
+
|
|
361
|
+
// Clean up QR overlay on successful connection
|
|
362
|
+
if (qrOverlay) {
|
|
363
|
+
qrOverlay.destroy();
|
|
364
|
+
qrOverlay = undefined;
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
// set the states
|
|
368
|
+
account = connectedAccount;
|
|
369
|
+
chain = connectedChain;
|
|
370
|
+
handleDisconnect = doDisconnect;
|
|
371
|
+
handleSwitchChain = doSwitchChain;
|
|
372
|
+
trackConnect({
|
|
373
|
+
chainId: chain.id,
|
|
374
|
+
client: wcOptions.client,
|
|
375
|
+
walletAddress: account.address,
|
|
376
|
+
walletType: id,
|
|
377
|
+
});
|
|
378
|
+
return account;
|
|
379
|
+
} catch (error) {
|
|
380
|
+
// Clean up QR overlay on connection error
|
|
381
|
+
if (qrOverlay) {
|
|
382
|
+
qrOverlay.destroy();
|
|
383
|
+
qrOverlay = undefined;
|
|
384
|
+
}
|
|
385
|
+
throw error;
|
|
386
|
+
}
|
|
326
387
|
}
|
|
327
388
|
|
|
328
389
|
if (id === "walletConnect") {
|
|
@@ -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
|
*/
|
|
@@ -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)) {
|
|
@@ -1,20 +1,12 @@
|
|
|
1
1
|
import type * as ox__TypedData from "ox/TypedData";
|
|
2
2
|
import { serializeErc6492Signature } from "../../../auth/serialize-erc6492-signature.js";
|
|
3
|
-
import {
|
|
4
|
-
verifyEip1271Signature,
|
|
5
|
-
verifyHash,
|
|
6
|
-
} from "../../../auth/verify-hash.js";
|
|
3
|
+
import { verifyEip1271Signature } from "../../../auth/verify-hash.js";
|
|
7
4
|
import type { Chain } from "../../../chains/types.js";
|
|
8
5
|
import type { ThirdwebClient } from "../../../client/client.js";
|
|
9
|
-
import {
|
|
10
|
-
getContract,
|
|
11
|
-
type ThirdwebContract,
|
|
12
|
-
} from "../../../contract/contract.js";
|
|
6
|
+
import type { ThirdwebContract } from "../../../contract/contract.js";
|
|
13
7
|
import { encode } from "../../../transaction/actions/encode.js";
|
|
14
|
-
import { readContract } from "../../../transaction/read-contract.js";
|
|
15
8
|
import { encodeAbiParameters } from "../../../utils/abi/encodeAbiParameters.js";
|
|
16
9
|
import { isContractDeployed } from "../../../utils/bytecode/is-contract-deployed.js";
|
|
17
|
-
import type { Hex } from "../../../utils/encoding/hex.js";
|
|
18
10
|
import { hashMessage } from "../../../utils/hashing/hashMessage.js";
|
|
19
11
|
import { hashTypedData } from "../../../utils/hashing/hashTypedData.js";
|
|
20
12
|
import type { SignableMessage } from "../../../utils/types.js";
|
|
@@ -40,33 +32,24 @@ export async function smartAccountSignMessage({
|
|
|
40
32
|
message: SignableMessage;
|
|
41
33
|
}) {
|
|
42
34
|
const originalMsgHash = hashMessage(message);
|
|
43
|
-
const is712Factory = await checkFor712Factory({
|
|
44
|
-
accountContract,
|
|
45
|
-
factoryContract,
|
|
46
|
-
originalMsgHash,
|
|
47
|
-
});
|
|
48
35
|
|
|
49
36
|
let sig: `0x${string}`;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
);
|
|
37
|
+
const wrappedMessageHash = encodeAbiParameters(
|
|
38
|
+
[{ type: "bytes32" }],
|
|
39
|
+
[originalMsgHash],
|
|
40
|
+
);
|
|
55
41
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
} else {
|
|
68
|
-
sig = await options.personalAccount.signMessage({ message });
|
|
69
|
-
}
|
|
42
|
+
sig = await options.personalAccount.signTypedData({
|
|
43
|
+
domain: {
|
|
44
|
+
chainId: options.chain.id,
|
|
45
|
+
name: "Account",
|
|
46
|
+
verifyingContract: accountContract.address,
|
|
47
|
+
version: "1",
|
|
48
|
+
},
|
|
49
|
+
message: { message: wrappedMessageHash },
|
|
50
|
+
primaryType: "AccountMessage",
|
|
51
|
+
types: { AccountMessage: [{ name: "message", type: "bytes" }] },
|
|
52
|
+
});
|
|
70
53
|
|
|
71
54
|
const isDeployed = await isContractDeployed(accountContract);
|
|
72
55
|
if (isDeployed) {
|
|
@@ -96,19 +79,7 @@ export async function smartAccountSignMessage({
|
|
|
96
79
|
signature: sig,
|
|
97
80
|
});
|
|
98
81
|
|
|
99
|
-
|
|
100
|
-
const isValid = await verifyHash({
|
|
101
|
-
address: accountContract.address,
|
|
102
|
-
chain: accountContract.chain,
|
|
103
|
-
client: accountContract.client,
|
|
104
|
-
hash: originalMsgHash,
|
|
105
|
-
signature: erc6492Sig,
|
|
106
|
-
});
|
|
107
|
-
|
|
108
|
-
if (isValid) {
|
|
109
|
-
return erc6492Sig;
|
|
110
|
-
}
|
|
111
|
-
throw new Error("Unable to verify ERC-6492 signature after signing.");
|
|
82
|
+
return erc6492Sig;
|
|
112
83
|
}
|
|
113
84
|
}
|
|
114
85
|
|
|
@@ -138,33 +109,23 @@ export async function smartAccountSignTypedData<
|
|
|
138
109
|
}
|
|
139
110
|
|
|
140
111
|
const originalMsgHash = hashTypedData(typedData);
|
|
141
|
-
// check if the account contract supports EIP721 domain separator based signing
|
|
142
|
-
const is712Factory = await checkFor712Factory({
|
|
143
|
-
accountContract,
|
|
144
|
-
factoryContract,
|
|
145
|
-
originalMsgHash,
|
|
146
|
-
});
|
|
147
112
|
|
|
148
113
|
let sig: `0x${string}`;
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
});
|
|
165
|
-
} else {
|
|
166
|
-
sig = await options.personalAccount.signTypedData(typedData);
|
|
167
|
-
}
|
|
114
|
+
const wrappedMessageHash = encodeAbiParameters(
|
|
115
|
+
[{ type: "bytes32" }],
|
|
116
|
+
[originalMsgHash],
|
|
117
|
+
);
|
|
118
|
+
sig = await options.personalAccount.signTypedData({
|
|
119
|
+
domain: {
|
|
120
|
+
chainId: options.chain.id,
|
|
121
|
+
name: "Account",
|
|
122
|
+
verifyingContract: accountContract.address,
|
|
123
|
+
version: "1",
|
|
124
|
+
},
|
|
125
|
+
message: { message: wrappedMessageHash },
|
|
126
|
+
primaryType: "AccountMessage",
|
|
127
|
+
types: { AccountMessage: [{ name: "message", type: "bytes" }] },
|
|
128
|
+
});
|
|
168
129
|
|
|
169
130
|
const isDeployed = await isContractDeployed(accountContract);
|
|
170
131
|
if (isDeployed) {
|
|
@@ -194,21 +155,7 @@ export async function smartAccountSignTypedData<
|
|
|
194
155
|
signature: sig,
|
|
195
156
|
});
|
|
196
157
|
|
|
197
|
-
|
|
198
|
-
const isValid = await verifyHash({
|
|
199
|
-
address: accountContract.address,
|
|
200
|
-
chain: accountContract.chain,
|
|
201
|
-
client: accountContract.client,
|
|
202
|
-
hash: originalMsgHash,
|
|
203
|
-
signature: erc6492Sig,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
if (isValid) {
|
|
207
|
-
return erc6492Sig;
|
|
208
|
-
}
|
|
209
|
-
throw new Error(
|
|
210
|
-
"Unable to verify signature on smart account, please make sure the admin wallet has permissions and the signature is valid.",
|
|
211
|
-
);
|
|
158
|
+
return erc6492Sig;
|
|
212
159
|
}
|
|
213
160
|
}
|
|
214
161
|
|
|
@@ -233,40 +180,6 @@ export async function confirmContractDeployment(args: {
|
|
|
233
180
|
}
|
|
234
181
|
}
|
|
235
182
|
|
|
236
|
-
async function checkFor712Factory({
|
|
237
|
-
factoryContract,
|
|
238
|
-
accountContract,
|
|
239
|
-
originalMsgHash,
|
|
240
|
-
}: {
|
|
241
|
-
factoryContract: ThirdwebContract;
|
|
242
|
-
accountContract: ThirdwebContract;
|
|
243
|
-
originalMsgHash: Hex;
|
|
244
|
-
}) {
|
|
245
|
-
try {
|
|
246
|
-
const implementationAccount = await readContract({
|
|
247
|
-
contract: factoryContract,
|
|
248
|
-
method: "function accountImplementation() public view returns (address)",
|
|
249
|
-
});
|
|
250
|
-
// check if the account contract supports EIP721 domain separator or modular based signing
|
|
251
|
-
const is712Factory = await readContract({
|
|
252
|
-
contract: getContract({
|
|
253
|
-
address: implementationAccount,
|
|
254
|
-
chain: accountContract.chain,
|
|
255
|
-
client: accountContract.client,
|
|
256
|
-
}),
|
|
257
|
-
method:
|
|
258
|
-
"function getMessageHash(bytes32 _hash) public view returns (bytes32)",
|
|
259
|
-
params: [originalMsgHash],
|
|
260
|
-
})
|
|
261
|
-
.then((res) => res !== "0x")
|
|
262
|
-
.catch(() => false);
|
|
263
|
-
|
|
264
|
-
return is712Factory;
|
|
265
|
-
} catch {
|
|
266
|
-
return false;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
183
|
/**
|
|
271
184
|
* Deployes a smart account via a dummy transaction. If the account is already deployed, this will do nothing.
|
|
272
185
|
*
|
|
@@ -47,7 +47,6 @@ const contract = getContract({
|
|
|
47
47
|
chain,
|
|
48
48
|
client,
|
|
49
49
|
});
|
|
50
|
-
const factoryAddress = "0x564cf6453a1b0FF8DB603E92EA4BbD410dea45F3"; // pre 712
|
|
51
50
|
|
|
52
51
|
describe.runIf(process.env.TW_SECRET_KEY).sequential(
|
|
53
52
|
"SmartWallet core tests",
|
|
@@ -301,79 +300,6 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
|
|
|
301
300
|
expect(logs.some((l) => l.args.isAdmin)).toBe(true);
|
|
302
301
|
});
|
|
303
302
|
|
|
304
|
-
it("can use a different factory without replay protection", async () => {
|
|
305
|
-
const wallet = smartWallet({
|
|
306
|
-
chain,
|
|
307
|
-
factoryAddress: factoryAddress,
|
|
308
|
-
gasless: true,
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
// should not be able to switch chains before connecting
|
|
312
|
-
await expect(
|
|
313
|
-
wallet.switchChain(baseSepolia),
|
|
314
|
-
).rejects.toMatchInlineSnapshot(
|
|
315
|
-
"[Error: Cannot switch chain without a previous connection]",
|
|
316
|
-
);
|
|
317
|
-
|
|
318
|
-
const newAccount = await wallet.connect({ client, personalAccount });
|
|
319
|
-
const message = "hello world";
|
|
320
|
-
const signature = await newAccount.signMessage({ message });
|
|
321
|
-
const isValidV1 = await verifySignature({
|
|
322
|
-
address: newAccount.address,
|
|
323
|
-
chain,
|
|
324
|
-
client,
|
|
325
|
-
message,
|
|
326
|
-
signature,
|
|
327
|
-
});
|
|
328
|
-
expect(isValidV1).toEqual(true);
|
|
329
|
-
|
|
330
|
-
// sign typed data
|
|
331
|
-
const signatureTyped = await newAccount.signTypedData({
|
|
332
|
-
...typedData.basic,
|
|
333
|
-
primaryType: "Mail",
|
|
334
|
-
});
|
|
335
|
-
const isValidV2 = await verifyTypedData({
|
|
336
|
-
address: newAccount.address,
|
|
337
|
-
chain,
|
|
338
|
-
client,
|
|
339
|
-
signature: signatureTyped,
|
|
340
|
-
...typedData.basic,
|
|
341
|
-
});
|
|
342
|
-
expect(isValidV2).toEqual(true);
|
|
343
|
-
|
|
344
|
-
// add admin pre-deployment
|
|
345
|
-
const newAdmin = await generateAccount({ client });
|
|
346
|
-
const receipt = await sendAndConfirmTransaction({
|
|
347
|
-
account: newAccount,
|
|
348
|
-
transaction: addAdmin({
|
|
349
|
-
account: newAccount,
|
|
350
|
-
adminAddress: newAdmin.address,
|
|
351
|
-
contract: getContract({
|
|
352
|
-
address: newAccount.address,
|
|
353
|
-
chain,
|
|
354
|
-
client,
|
|
355
|
-
}),
|
|
356
|
-
}),
|
|
357
|
-
});
|
|
358
|
-
const logs = parseEventLogs({
|
|
359
|
-
events: [adminUpdatedEvent()],
|
|
360
|
-
logs: receipt.logs,
|
|
361
|
-
});
|
|
362
|
-
expect(logs.map((l) => l.args.signer)).toContain(newAdmin.address);
|
|
363
|
-
expect(logs.map((l) => l.args.isAdmin)).toContain(true);
|
|
364
|
-
|
|
365
|
-
// should not be able to switch chains since factory not deployed elsewhere
|
|
366
|
-
await expect(
|
|
367
|
-
wallet.switchChain(baseSepolia),
|
|
368
|
-
).rejects.toMatchInlineSnapshot(
|
|
369
|
-
"[Error: Factory contract not deployed on chain: 84532]",
|
|
370
|
-
);
|
|
371
|
-
|
|
372
|
-
// check can disconnnect
|
|
373
|
-
await wallet.disconnect();
|
|
374
|
-
expect(wallet.getAccount()).toBeUndefined();
|
|
375
|
-
});
|
|
376
|
-
|
|
377
303
|
it("can switch chains", async () => {
|
|
378
304
|
await wallet.switchChain(baseSepolia);
|
|
379
305
|
expect(wallet.getChain()?.id).toEqual(baseSepolia.id);
|
|
@@ -424,7 +350,7 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
|
|
|
424
350
|
tokenId: 0n,
|
|
425
351
|
}),
|
|
426
352
|
}),
|
|
427
|
-
sleep(
|
|
353
|
+
sleep(1500).then(() =>
|
|
428
354
|
sendAndConfirmTransaction({
|
|
429
355
|
account: newSmartAccount,
|
|
430
356
|
transaction: claimTo({
|
|
@@ -453,7 +379,6 @@ describe.runIf(process.env.TW_SECRET_KEY).sequential(
|
|
|
453
379
|
it("can use a different paymaster", async () => {
|
|
454
380
|
const wallet = smartWallet({
|
|
455
381
|
chain,
|
|
456
|
-
factoryAddress: factoryAddress,
|
|
457
382
|
gasless: true,
|
|
458
383
|
overrides: {
|
|
459
384
|
paymaster: async () => {
|
|
@@ -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;
|