thirdweb 5.80.1-nightly-430475913d30ef7a30cb3092f6ef09c0c998a9b6-20250106000343 → 5.82.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.
- package/dist/cjs/adapters/ethers5.js +1 -1
- package/dist/cjs/adapters/ethers5.js.map +1 -1
- package/dist/cjs/auth/verify-hash.js +13 -8
- package/dist/cjs/auth/verify-hash.js.map +1 -1
- package/dist/cjs/contract/types.js +3 -0
- package/dist/cjs/contract/types.js.map +1 -0
- package/dist/cjs/exports/thirdweb.js +5 -1
- package/dist/cjs/exports/thirdweb.js.map +1 -1
- package/dist/cjs/exports/transaction.js +3 -1
- package/dist/cjs/exports/transaction.js.map +1 -1
- package/dist/cjs/exports/wallets.js +3 -1
- package/dist/cjs/exports/wallets.js.map +1 -1
- package/dist/cjs/extensions/erc721/lazyMinting/read/getBatchesToReveal.js +1 -1
- package/dist/cjs/extensions/erc721/lazyMinting/read/getBatchesToReveal.js.map +1 -1
- package/dist/cjs/extensions/types.js +3 -0
- package/dist/cjs/extensions/types.js.map +1 -0
- package/dist/cjs/gas/estimate-l1-fee.js +3 -4
- package/dist/cjs/gas/estimate-l1-fee.js.map +1 -1
- package/dist/cjs/react/core/hooks/contract/useReadContract.js +31 -29
- package/dist/cjs/react/core/hooks/contract/useReadContract.js.map +1 -1
- package/dist/cjs/react/core/hooks/types.js +3 -0
- package/dist/cjs/react/core/hooks/types.js.map +1 -0
- package/dist/cjs/transaction/actions/eip7702/authorization.js +33 -0
- package/dist/cjs/transaction/actions/eip7702/authorization.js.map +1 -0
- package/dist/cjs/transaction/actions/estimate-gas.js +16 -4
- package/dist/cjs/transaction/actions/estimate-gas.js.map +1 -1
- package/dist/cjs/transaction/actions/send-transaction.js +32 -1
- package/dist/cjs/transaction/actions/send-transaction.js.map +1 -1
- package/dist/cjs/transaction/actions/to-serializable-transaction.js +13 -4
- package/dist/cjs/transaction/actions/to-serializable-transaction.js.map +1 -1
- package/dist/cjs/transaction/prepare-transaction.js.map +1 -1
- package/dist/cjs/transaction/serialize-transaction.js +11 -0
- package/dist/cjs/transaction/serialize-transaction.js.map +1 -1
- package/dist/cjs/utils/abi/decodeError.js +3 -3
- package/dist/cjs/utils/abi/decodeError.js.map +1 -1
- package/dist/cjs/utils/abi/decodeFunctionData.js +3 -3
- package/dist/cjs/utils/abi/decodeFunctionData.js.map +1 -1
- package/dist/cjs/utils/abi/decodeFunctionResult.js +3 -3
- package/dist/cjs/utils/abi/decodeFunctionResult.js.map +1 -1
- package/dist/cjs/utils/hashing/hashMessage.js +2 -2
- package/dist/cjs/utils/hashing/hashMessage.js.map +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/cjs/version.js.map +1 -1
- package/dist/cjs/wallets/create-wallet.js +16 -0
- package/dist/cjs/wallets/create-wallet.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js +9 -3
- package/dist/cjs/wallets/in-app/core/wallet/in-app-core.js.map +1 -1
- package/dist/cjs/wallets/in-app/core/wallet/index.js +8 -10
- package/dist/cjs/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/cjs/wallets/private-key.js +9 -0
- package/dist/cjs/wallets/private-key.js.map +1 -1
- package/dist/cjs/wallets/smart/index.js +34 -32
- package/dist/cjs/wallets/smart/index.js.map +1 -1
- package/dist/cjs/wallets/smart/lib/signing.js +139 -54
- package/dist/cjs/wallets/smart/lib/signing.js.map +1 -1
- package/dist/cjs/wallets/smart/presets/7579.js +11 -10
- package/dist/cjs/wallets/smart/presets/7579.js.map +1 -1
- package/dist/cjs/wallets/smart/smart-wallet.js +12 -10
- package/dist/cjs/wallets/smart/smart-wallet.js.map +1 -1
- package/dist/esm/adapters/ethers5.js +1 -1
- package/dist/esm/adapters/ethers5.js.map +1 -1
- package/dist/esm/auth/verify-hash.js +13 -9
- package/dist/esm/auth/verify-hash.js.map +1 -1
- package/dist/esm/contract/types.js +2 -0
- package/dist/esm/contract/types.js.map +1 -0
- package/dist/esm/exports/thirdweb.js +2 -0
- package/dist/esm/exports/thirdweb.js.map +1 -1
- package/dist/esm/exports/transaction.js +1 -0
- package/dist/esm/exports/transaction.js.map +1 -1
- package/dist/esm/exports/wallets.js +1 -0
- package/dist/esm/exports/wallets.js.map +1 -1
- package/dist/esm/extensions/erc721/lazyMinting/read/getBatchesToReveal.js +1 -1
- package/dist/esm/extensions/erc721/lazyMinting/read/getBatchesToReveal.js.map +1 -1
- package/dist/esm/extensions/types.js +2 -0
- package/dist/esm/extensions/types.js.map +1 -0
- package/dist/esm/gas/estimate-l1-fee.js +2 -3
- package/dist/esm/gas/estimate-l1-fee.js.map +1 -1
- package/dist/esm/react/core/hooks/contract/useReadContract.js +31 -29
- package/dist/esm/react/core/hooks/contract/useReadContract.js.map +1 -1
- package/dist/esm/react/core/hooks/types.js +2 -0
- package/dist/esm/react/core/hooks/types.js.map +1 -0
- package/dist/esm/transaction/actions/eip7702/authorization.js +30 -0
- package/dist/esm/transaction/actions/eip7702/authorization.js.map +1 -0
- package/dist/esm/transaction/actions/estimate-gas.js +16 -4
- package/dist/esm/transaction/actions/estimate-gas.js.map +1 -1
- package/dist/esm/transaction/actions/send-transaction.js +32 -1
- package/dist/esm/transaction/actions/send-transaction.js.map +1 -1
- package/dist/esm/transaction/actions/to-serializable-transaction.js +13 -4
- package/dist/esm/transaction/actions/to-serializable-transaction.js.map +1 -1
- package/dist/esm/transaction/prepare-transaction.js.map +1 -1
- package/dist/esm/transaction/serialize-transaction.js +11 -0
- package/dist/esm/transaction/serialize-transaction.js.map +1 -1
- package/dist/esm/utils/abi/decodeError.js +3 -3
- package/dist/esm/utils/abi/decodeError.js.map +1 -1
- package/dist/esm/utils/abi/decodeFunctionData.js +3 -3
- package/dist/esm/utils/abi/decodeFunctionData.js.map +1 -1
- package/dist/esm/utils/abi/decodeFunctionResult.js +3 -3
- package/dist/esm/utils/abi/decodeFunctionResult.js.map +1 -1
- package/dist/esm/utils/hashing/hashMessage.js +1 -1
- package/dist/esm/utils/hashing/hashMessage.js.map +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/esm/wallets/create-wallet.js +16 -0
- package/dist/esm/wallets/create-wallet.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js +9 -3
- package/dist/esm/wallets/in-app/core/wallet/in-app-core.js.map +1 -1
- package/dist/esm/wallets/in-app/core/wallet/index.js +8 -10
- package/dist/esm/wallets/in-app/core/wallet/index.js.map +1 -1
- package/dist/esm/wallets/private-key.js +9 -0
- package/dist/esm/wallets/private-key.js.map +1 -1
- package/dist/esm/wallets/smart/index.js +32 -30
- package/dist/esm/wallets/smart/index.js.map +1 -1
- package/dist/esm/wallets/smart/lib/signing.js +137 -53
- package/dist/esm/wallets/smart/lib/signing.js.map +1 -1
- package/dist/esm/wallets/smart/presets/7579.js +11 -10
- package/dist/esm/wallets/smart/presets/7579.js.map +1 -1
- package/dist/esm/wallets/smart/smart-wallet.js +12 -10
- package/dist/esm/wallets/smart/smart-wallet.js.map +1 -1
- package/dist/types/auth/verify-hash.d.ts +6 -0
- package/dist/types/auth/verify-hash.d.ts.map +1 -1
- package/dist/types/contract/types.d.ts +7 -0
- package/dist/types/contract/types.d.ts.map +1 -0
- package/dist/types/exports/thirdweb.d.ts +6 -0
- package/dist/types/exports/thirdweb.d.ts.map +1 -1
- package/dist/types/exports/transaction.d.ts +5 -0
- package/dist/types/exports/transaction.d.ts.map +1 -1
- package/dist/types/exports/wallets.d.ts +1 -0
- package/dist/types/exports/wallets.d.ts.map +1 -1
- package/dist/types/extensions/erc721/lazyMinting/read/getBatchesToReveal.d.ts +1 -1
- package/dist/types/extensions/erc721/lazyMinting/read/getBatchesToReveal.d.ts.map +1 -1
- package/dist/types/extensions/types.d.ts +4 -0
- package/dist/types/extensions/types.d.ts.map +1 -0
- package/dist/types/gas/estimate-l1-fee.d.ts.map +1 -1
- package/dist/types/react/core/hooks/contract/useReadContract.d.ts +9 -16
- package/dist/types/react/core/hooks/contract/useReadContract.d.ts.map +1 -1
- package/dist/types/react/core/hooks/types.d.ts +13 -0
- package/dist/types/react/core/hooks/types.d.ts.map +1 -0
- package/dist/types/transaction/actions/eip7702/authorization.d.ts +48 -0
- package/dist/types/transaction/actions/eip7702/authorization.d.ts.map +1 -0
- package/dist/types/transaction/actions/estimate-gas.d.ts +3 -1
- package/dist/types/transaction/actions/estimate-gas.d.ts.map +1 -1
- package/dist/types/transaction/actions/send-transaction.d.ts +31 -0
- package/dist/types/transaction/actions/send-transaction.d.ts.map +1 -1
- package/dist/types/transaction/actions/to-serializable-transaction.d.ts +19 -2
- package/dist/types/transaction/actions/to-serializable-transaction.d.ts.map +1 -1
- package/dist/types/transaction/prepare-transaction.d.ts +2 -0
- package/dist/types/transaction/prepare-transaction.d.ts.map +1 -1
- package/dist/types/transaction/serialize-transaction.d.ts +2 -0
- package/dist/types/transaction/serialize-transaction.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeError.d.ts +2 -2
- package/dist/types/utils/abi/decodeError.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeFunctionData.d.ts +6 -4
- package/dist/types/utils/abi/decodeFunctionData.d.ts.map +1 -1
- package/dist/types/utils/abi/decodeFunctionResult.d.ts +6 -4
- package/dist/types/utils/abi/decodeFunctionResult.d.ts.map +1 -1
- package/dist/types/utils/hashing/hashMessage.d.ts +1 -1
- package/dist/types/utils/hashing/hashMessage.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/create-wallet.d.ts +16 -0
- package/dist/types/wallets/create-wallet.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/in-app-core.d.ts.map +1 -1
- package/dist/types/wallets/in-app/core/wallet/index.d.ts +10 -2
- package/dist/types/wallets/in-app/core/wallet/index.d.ts.map +1 -1
- package/dist/types/wallets/interfaces/wallet.d.ts +9 -0
- package/dist/types/wallets/interfaces/wallet.d.ts.map +1 -1
- package/dist/types/wallets/private-key.d.ts.map +1 -1
- package/dist/types/wallets/smart/index.d.ts +2 -2
- package/dist/types/wallets/smart/index.d.ts.map +1 -1
- package/dist/types/wallets/smart/lib/signing.d.ts +46 -2
- package/dist/types/wallets/smart/lib/signing.d.ts.map +1 -1
- package/dist/types/wallets/smart/presets/7579.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/adapters/ethers5.ts +1 -1
- package/src/auth/verify-hash.ts +12 -9
- package/src/contract/types.ts +8 -0
- package/src/exports/thirdweb.ts +10 -0
- package/src/exports/transaction.ts +9 -0
- package/src/exports/wallets.ts +2 -0
- package/src/extensions/erc721/lazyMinting/read/getBatchesToReveal.ts +2 -2
- package/src/extensions/types.ts +6 -0
- package/src/gas/estimate-l1-fee.ts +2 -3
- package/src/react/core/hooks/contract/useReadContract.ts +83 -74
- package/src/react/core/hooks/types.ts +13 -0
- package/src/transaction/actions/eip7702/authorization.test.ts +27 -0
- package/src/transaction/actions/eip7702/authorization.ts +58 -0
- package/src/transaction/actions/estimate-gas.ts +26 -9
- package/src/transaction/actions/send-transaction.ts +32 -2
- package/src/transaction/actions/to-serializable-transaction.test.ts +68 -0
- package/src/transaction/actions/to-serializable-transaction.ts +42 -30
- package/src/transaction/prepare-transaction.test.ts +28 -0
- package/src/transaction/prepare-transaction.ts +3 -0
- package/src/transaction/serialize-transaction.test.ts +108 -1
- package/src/transaction/serialize-transaction.ts +18 -0
- package/src/utils/abi/decodeError.ts +5 -4
- package/src/utils/abi/decodeFunctionData.ts +7 -5
- package/src/utils/abi/decodeFunctionResult.ts +7 -5
- package/src/utils/hashing/hashMessage.ts +1 -1
- package/src/utils/signatures/sign-message.test.ts +2 -2
- package/src/version.ts +1 -1
- package/src/wallets/create-wallet.ts +16 -0
- package/src/wallets/in-app/core/wallet/in-app-core.test.ts +115 -54
- package/src/wallets/in-app/core/wallet/in-app-core.ts +22 -11
- package/src/wallets/in-app/core/wallet/index.ts +10 -13
- package/src/wallets/interfaces/wallet.ts +15 -0
- package/src/wallets/private-key.test.ts +1 -0
- package/src/wallets/private-key.ts +10 -0
- package/src/wallets/smart/index.ts +34 -37
- package/src/wallets/smart/lib/signing.ts +154 -59
- package/src/wallets/smart/presets/7579.ts +13 -12
- package/src/wallets/smart/smart-wallet-integration-v07.test.ts +49 -9
- package/src/wallets/smart/smart-wallet-integration.test.ts +48 -1
- package/src/wallets/smart/smart-wallet.ts +13 -13
- package/src/wallets/smart/smart.test.ts +19 -39
@@ -1,42 +1,54 @@
|
|
1
1
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
2
|
+
import { TEST_CLIENT } from "../../../../../test/src/test-clients.js";
|
3
|
+
import { TEST_ACCOUNT_A } from "../../../../../test/src/test-wallets.js";
|
2
4
|
import { baseSepolia } from "../../../../chains/chain-definitions/base-sepolia.js";
|
3
|
-
import { createThirdwebClient } from "../../../../client/client.js";
|
4
5
|
import { getEcosystemInfo } from "../../../ecosystem/get-ecosystem-wallet-auth-options.js";
|
5
|
-
import
|
6
|
+
import { predictSmartAccountAddress } from "../../../smart/lib/calls.js";
|
7
|
+
import { DEFAULT_ACCOUNT_FACTORY_V0_6 } from "../../../smart/lib/constants.js";
|
8
|
+
import type { AuthLoginReturnType } from "../authentication/types.js";
|
6
9
|
import type { InAppConnector } from "../interfaces/connector.js";
|
7
10
|
import { createInAppWallet } from "./in-app-core.js";
|
8
|
-
import
|
11
|
+
import * as InAppWallet from "./index.js";
|
9
12
|
|
10
13
|
vi.mock("../../../../analytics/track/connect.js", () => ({
|
11
14
|
trackConnect: vi.fn(),
|
12
15
|
}));
|
13
16
|
|
14
|
-
vi.
|
15
|
-
|
16
|
-
connectInAppWallet: vi.fn(),
|
17
|
-
}));
|
18
|
-
|
17
|
+
vi.spyOn(InAppWallet, "connectInAppWallet");
|
18
|
+
vi.spyOn(InAppWallet, "autoConnectInAppWallet");
|
19
19
|
vi.mock("../../../ecosystem/get-ecosystem-wallet-auth-options.js", () => ({
|
20
20
|
getEcosystemInfo: vi.fn(),
|
21
21
|
}));
|
22
22
|
|
23
|
-
describe("createInAppWallet", () => {
|
24
|
-
const mockClient =
|
25
|
-
clientId: "test-client",
|
26
|
-
});
|
23
|
+
describe.runIf(process.env.TW_SECRET_KEY)("createInAppWallet", () => {
|
24
|
+
const mockClient = TEST_CLIENT;
|
27
25
|
const mockChain = baseSepolia;
|
28
|
-
const mockAccount =
|
26
|
+
const mockAccount = TEST_ACCOUNT_A;
|
27
|
+
const mockUser = {
|
28
|
+
status: "Logged In, Wallet Initialized",
|
29
|
+
walletAddress: TEST_ACCOUNT_A.address,
|
30
|
+
authDetails: {
|
31
|
+
userWalletId: TEST_ACCOUNT_A.address,
|
32
|
+
recoveryShareManagement: "ENCLAVE",
|
33
|
+
email: "test@test.com",
|
34
|
+
},
|
35
|
+
account: mockAccount,
|
36
|
+
} as const;
|
37
|
+
const mockAuthResult: AuthLoginReturnType = {
|
38
|
+
user: mockUser,
|
39
|
+
};
|
29
40
|
|
30
41
|
const mockConnectorFactory = vi.fn(() =>
|
31
42
|
Promise.resolve({
|
32
|
-
connect: vi.fn(),
|
43
|
+
connect: vi.fn().mockResolvedValue(mockAuthResult),
|
33
44
|
logout: vi.fn(() => Promise.resolve({ success: true })),
|
34
45
|
authenticate: vi.fn(),
|
35
46
|
getAccounts: vi.fn(),
|
36
47
|
getAccount: vi.fn(),
|
37
48
|
getProfiles: vi.fn(),
|
38
|
-
getUser: vi.fn(),
|
49
|
+
getUser: vi.fn().mockResolvedValue(mockUser),
|
39
50
|
linkProfile: vi.fn(),
|
51
|
+
unlinkProfile: vi.fn(),
|
40
52
|
preAuthenticate: vi.fn(),
|
41
53
|
} as InAppConnector),
|
42
54
|
);
|
@@ -46,8 +58,6 @@ describe("createInAppWallet", () => {
|
|
46
58
|
});
|
47
59
|
|
48
60
|
it("should connect successfully", async () => {
|
49
|
-
vi.mocked(connectInAppWallet).mockResolvedValue([mockAccount, mockChain]);
|
50
|
-
|
51
61
|
const wallet = createInAppWallet({
|
52
62
|
connectorFactory: mockConnectorFactory,
|
53
63
|
});
|
@@ -61,7 +71,7 @@ describe("createInAppWallet", () => {
|
|
61
71
|
});
|
62
72
|
|
63
73
|
expect(result).toBe(mockAccount);
|
64
|
-
expect(connectInAppWallet).toHaveBeenCalledWith(
|
74
|
+
expect(InAppWallet.connectInAppWallet).toHaveBeenCalledWith(
|
65
75
|
expect.objectContaining({
|
66
76
|
client: mockClient,
|
67
77
|
chain: mockChain,
|
@@ -72,11 +82,6 @@ describe("createInAppWallet", () => {
|
|
72
82
|
});
|
73
83
|
|
74
84
|
it("should auto connect successfully", async () => {
|
75
|
-
vi.mocked(autoConnectInAppWallet).mockResolvedValue([
|
76
|
-
mockAccount,
|
77
|
-
mockChain,
|
78
|
-
]);
|
79
|
-
|
80
85
|
const wallet = createInAppWallet({
|
81
86
|
connectorFactory: mockConnectorFactory,
|
82
87
|
});
|
@@ -87,7 +92,7 @@ describe("createInAppWallet", () => {
|
|
87
92
|
});
|
88
93
|
|
89
94
|
expect(result).toBe(mockAccount);
|
90
|
-
expect(autoConnectInAppWallet).toHaveBeenCalledWith(
|
95
|
+
expect(InAppWallet.autoConnectInAppWallet).toHaveBeenCalledWith(
|
91
96
|
expect.objectContaining({
|
92
97
|
client: mockClient,
|
93
98
|
chain: mockChain,
|
@@ -102,15 +107,13 @@ describe("createInAppWallet", () => {
|
|
102
107
|
smartAccountOptions: {
|
103
108
|
defaultChainId: mockChain.id,
|
104
109
|
sponsorGas: true,
|
105
|
-
accountFactoryAddress:
|
110
|
+
accountFactoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
106
111
|
},
|
107
112
|
authOptions: [],
|
108
113
|
name: "hello world",
|
109
114
|
slug: "test-ecosystem",
|
110
115
|
});
|
111
116
|
|
112
|
-
vi.mocked(connectInAppWallet).mockResolvedValue([mockAccount, mockChain]);
|
113
|
-
|
114
117
|
const wallet = createInAppWallet({
|
115
118
|
connectorFactory: mockConnectorFactory,
|
116
119
|
ecosystem: { id: "ecosystem.test-ecosystem" },
|
@@ -124,8 +127,14 @@ describe("createInAppWallet", () => {
|
|
124
127
|
verificationCode: "",
|
125
128
|
});
|
126
129
|
|
127
|
-
|
128
|
-
|
130
|
+
const expectedSmartAccountAddress = await predictSmartAccountAddress({
|
131
|
+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
132
|
+
chain: mockChain,
|
133
|
+
adminAddress: TEST_ACCOUNT_A.address,
|
134
|
+
client: mockClient,
|
135
|
+
});
|
136
|
+
expect(result.address).toBe(expectedSmartAccountAddress);
|
137
|
+
expect(InAppWallet.connectInAppWallet).toHaveBeenCalledWith(
|
129
138
|
expect.objectContaining({
|
130
139
|
client: mockClient,
|
131
140
|
chain: mockChain,
|
@@ -134,7 +143,7 @@ describe("createInAppWallet", () => {
|
|
134
143
|
smartAccount: expect.objectContaining({
|
135
144
|
chain: mockChain,
|
136
145
|
sponsorGas: true,
|
137
|
-
factoryAddress:
|
146
|
+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
138
147
|
}),
|
139
148
|
}),
|
140
149
|
expect.any(Object),
|
@@ -145,15 +154,13 @@ describe("createInAppWallet", () => {
|
|
145
154
|
smartAccountOptions: {
|
146
155
|
defaultChainId: mockChain.id,
|
147
156
|
sponsorGas: true,
|
148
|
-
accountFactoryAddress:
|
157
|
+
accountFactoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
149
158
|
},
|
150
159
|
authOptions: [],
|
151
160
|
name: "hello world",
|
152
161
|
slug: "test-ecosystem",
|
153
162
|
});
|
154
163
|
|
155
|
-
vi.mocked(connectInAppWallet).mockResolvedValue([mockAccount, mockChain]);
|
156
|
-
|
157
164
|
const wallet = createInAppWallet({
|
158
165
|
connectorFactory: mockConnectorFactory,
|
159
166
|
ecosystem: { id: "ecosystem.test-ecosystem" },
|
@@ -166,8 +173,14 @@ describe("createInAppWallet", () => {
|
|
166
173
|
verificationCode: "",
|
167
174
|
});
|
168
175
|
|
169
|
-
|
170
|
-
|
176
|
+
const expectedSmartAccountAddress = await predictSmartAccountAddress({
|
177
|
+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
178
|
+
chain: mockChain,
|
179
|
+
adminAddress: TEST_ACCOUNT_A.address,
|
180
|
+
client: mockClient,
|
181
|
+
});
|
182
|
+
expect(result.address).toBe(expectedSmartAccountAddress);
|
183
|
+
expect(InAppWallet.connectInAppWallet).toHaveBeenCalledWith(
|
171
184
|
expect.objectContaining({
|
172
185
|
client: mockClient,
|
173
186
|
}),
|
@@ -175,7 +188,7 @@ describe("createInAppWallet", () => {
|
|
175
188
|
smartAccount: expect.objectContaining({
|
176
189
|
chain: mockChain,
|
177
190
|
sponsorGas: true,
|
178
|
-
factoryAddress:
|
191
|
+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
179
192
|
}),
|
180
193
|
}),
|
181
194
|
expect.any(Object),
|
@@ -187,18 +200,13 @@ describe("createInAppWallet", () => {
|
|
187
200
|
smartAccountOptions: {
|
188
201
|
defaultChainId: mockChain.id,
|
189
202
|
sponsorGas: true,
|
190
|
-
accountFactoryAddress:
|
203
|
+
accountFactoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
191
204
|
},
|
192
205
|
authOptions: [],
|
193
206
|
name: "hello world",
|
194
207
|
slug: "test-ecosystem",
|
195
208
|
});
|
196
209
|
|
197
|
-
vi.mocked(autoConnectInAppWallet).mockResolvedValue([
|
198
|
-
mockAccount,
|
199
|
-
mockChain,
|
200
|
-
]);
|
201
|
-
|
202
210
|
const wallet = createInAppWallet({
|
203
211
|
connectorFactory: mockConnectorFactory,
|
204
212
|
ecosystem: { id: "ecosystem.test-ecosystem" },
|
@@ -209,8 +217,14 @@ describe("createInAppWallet", () => {
|
|
209
217
|
chain: mockChain,
|
210
218
|
});
|
211
219
|
|
212
|
-
|
213
|
-
|
220
|
+
const expectedSmartAccountAddress = await predictSmartAccountAddress({
|
221
|
+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
222
|
+
chain: mockChain,
|
223
|
+
adminAddress: TEST_ACCOUNT_A.address,
|
224
|
+
client: mockClient,
|
225
|
+
});
|
226
|
+
expect(result.address).toBe(expectedSmartAccountAddress);
|
227
|
+
expect(InAppWallet.autoConnectInAppWallet).toHaveBeenCalledWith(
|
214
228
|
expect.objectContaining({
|
215
229
|
client: mockClient,
|
216
230
|
chain: mockChain,
|
@@ -219,7 +233,7 @@ describe("createInAppWallet", () => {
|
|
219
233
|
smartAccount: expect.objectContaining({
|
220
234
|
chain: mockChain,
|
221
235
|
sponsorGas: true,
|
222
|
-
factoryAddress:
|
236
|
+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
223
237
|
}),
|
224
238
|
}),
|
225
239
|
expect.any(Object),
|
@@ -231,18 +245,13 @@ describe("createInAppWallet", () => {
|
|
231
245
|
smartAccountOptions: {
|
232
246
|
defaultChainId: mockChain.id,
|
233
247
|
sponsorGas: true,
|
234
|
-
accountFactoryAddress:
|
248
|
+
accountFactoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
235
249
|
},
|
236
250
|
authOptions: [],
|
237
251
|
name: "hello world",
|
238
252
|
slug: "test-ecosystem",
|
239
253
|
});
|
240
254
|
|
241
|
-
vi.mocked(autoConnectInAppWallet).mockResolvedValue([
|
242
|
-
mockAccount,
|
243
|
-
mockChain,
|
244
|
-
]);
|
245
|
-
|
246
255
|
const wallet = createInAppWallet({
|
247
256
|
connectorFactory: mockConnectorFactory,
|
248
257
|
ecosystem: { id: "ecosystem.test-ecosystem" },
|
@@ -252,8 +261,14 @@ describe("createInAppWallet", () => {
|
|
252
261
|
client: mockClient,
|
253
262
|
});
|
254
263
|
|
255
|
-
|
256
|
-
|
264
|
+
const expectedSmartAccountAddress = await predictSmartAccountAddress({
|
265
|
+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
266
|
+
chain: mockChain,
|
267
|
+
adminAddress: TEST_ACCOUNT_A.address,
|
268
|
+
client: mockClient,
|
269
|
+
});
|
270
|
+
expect(result.address).toBe(expectedSmartAccountAddress);
|
271
|
+
expect(InAppWallet.autoConnectInAppWallet).toHaveBeenCalledWith(
|
257
272
|
expect.objectContaining({
|
258
273
|
client: mockClient,
|
259
274
|
}),
|
@@ -261,10 +276,56 @@ describe("createInAppWallet", () => {
|
|
261
276
|
smartAccount: expect.objectContaining({
|
262
277
|
chain: mockChain,
|
263
278
|
sponsorGas: true,
|
264
|
-
factoryAddress:
|
279
|
+
factoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
265
280
|
}),
|
266
281
|
}),
|
267
282
|
expect.any(Object),
|
268
283
|
);
|
269
284
|
});
|
285
|
+
|
286
|
+
it("should return undefined for getAdminAccount if the account is not a smart account", () => {
|
287
|
+
const wallet = createInAppWallet({
|
288
|
+
connectorFactory: mockConnectorFactory,
|
289
|
+
});
|
290
|
+
|
291
|
+
expect(wallet.getAdminAccount?.()).toBeUndefined();
|
292
|
+
});
|
293
|
+
|
294
|
+
it("should return undefined if no account is connected", () => {
|
295
|
+
const wallet = createInAppWallet({
|
296
|
+
connectorFactory: mockConnectorFactory,
|
297
|
+
});
|
298
|
+
|
299
|
+
expect(wallet.getAdminAccount?.()).toBeUndefined();
|
300
|
+
});
|
301
|
+
|
302
|
+
it("should return the admin account for a smart account", async () => {
|
303
|
+
vi.unmock("./index.js");
|
304
|
+
vi.mocked(getEcosystemInfo).mockResolvedValue({
|
305
|
+
smartAccountOptions: {
|
306
|
+
defaultChainId: mockChain.id,
|
307
|
+
sponsorGas: true,
|
308
|
+
accountFactoryAddress: DEFAULT_ACCOUNT_FACTORY_V0_6,
|
309
|
+
},
|
310
|
+
authOptions: [],
|
311
|
+
name: "hello world",
|
312
|
+
slug: "test-ecosystem",
|
313
|
+
});
|
314
|
+
|
315
|
+
const wallet = createInAppWallet({
|
316
|
+
connectorFactory: mockConnectorFactory,
|
317
|
+
ecosystem: { id: "ecosystem.test-ecosystem" },
|
318
|
+
});
|
319
|
+
|
320
|
+
const smartAccount = await wallet.connect({
|
321
|
+
client: mockClient,
|
322
|
+
strategy: "email",
|
323
|
+
email: "",
|
324
|
+
verificationCode: "",
|
325
|
+
});
|
326
|
+
|
327
|
+
const adminAccount = wallet.getAdminAccount?.();
|
328
|
+
expect(adminAccount).toBeDefined();
|
329
|
+
expect(adminAccount?.address).not.toBe(smartAccount.address);
|
330
|
+
});
|
270
331
|
});
|
@@ -48,6 +48,7 @@ export function createInAppWallet(args: {
|
|
48
48
|
const emitter = createWalletEmitter<"inApp">();
|
49
49
|
let createOptions = _createOptions;
|
50
50
|
let account: Account | undefined = undefined;
|
51
|
+
let adminAccount: Account | undefined = undefined; // Admin account if smartAccountOptions were provided with connection
|
51
52
|
let chain: Chain | undefined = undefined;
|
52
53
|
let client: ThirdwebClient | undefined;
|
53
54
|
|
@@ -98,15 +99,16 @@ export function createInAppWallet(args: {
|
|
98
99
|
}
|
99
100
|
}
|
100
101
|
|
101
|
-
const
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
);
|
102
|
+
const {
|
103
|
+
account: connectedAccount,
|
104
|
+
chain: connectedChain,
|
105
|
+
adminAccount: _adminAccount,
|
106
|
+
} = await autoConnectInAppWallet(options, createOptions, connector);
|
106
107
|
|
107
108
|
// set the states
|
108
109
|
client = options.client;
|
109
110
|
account = connectedAccount;
|
111
|
+
adminAccount = _adminAccount;
|
110
112
|
chain = connectedChain;
|
111
113
|
trackConnect({
|
112
114
|
client: options.client,
|
@@ -151,14 +153,16 @@ export function createInAppWallet(args: {
|
|
151
153
|
}
|
152
154
|
}
|
153
155
|
|
154
|
-
const
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
);
|
156
|
+
const {
|
157
|
+
account: connectedAccount,
|
158
|
+
chain: connectedChain,
|
159
|
+
adminAccount: _adminAccount,
|
160
|
+
} = await connectInAppWallet(options, createOptions, connector);
|
161
|
+
|
159
162
|
// set the states
|
160
163
|
client = options.client;
|
161
164
|
account = connectedAccount;
|
165
|
+
adminAccount = _adminAccount;
|
162
166
|
chain = connectedChain;
|
163
167
|
trackConnect({
|
164
168
|
client: options.client,
|
@@ -184,6 +188,7 @@ export function createInAppWallet(args: {
|
|
184
188
|
}
|
185
189
|
}
|
186
190
|
account = undefined;
|
191
|
+
adminAccount = undefined;
|
187
192
|
chain = undefined;
|
188
193
|
emitter.emit("disconnect", undefined);
|
189
194
|
},
|
@@ -212,7 +217,11 @@ export function createInAppWallet(args: {
|
|
212
217
|
}
|
213
218
|
}
|
214
219
|
|
215
|
-
const
|
220
|
+
const {
|
221
|
+
account: connectedAccount,
|
222
|
+
chain: connectedChain,
|
223
|
+
adminAccount: _adminAccount,
|
224
|
+
} = await autoConnectInAppWallet(
|
216
225
|
{
|
217
226
|
chain: newChain,
|
218
227
|
client,
|
@@ -220,6 +229,7 @@ export function createInAppWallet(args: {
|
|
220
229
|
createOptions,
|
221
230
|
connector,
|
222
231
|
);
|
232
|
+
adminAccount = _adminAccount;
|
223
233
|
account = connectedAccount;
|
224
234
|
chain = connectedChain;
|
225
235
|
} else {
|
@@ -228,5 +238,6 @@ export function createInAppWallet(args: {
|
|
228
238
|
}
|
229
239
|
emitter.emit("chainChanged", newChain);
|
230
240
|
},
|
241
|
+
getAdminAccount: () => adminAccount,
|
231
242
|
};
|
232
243
|
}
|
@@ -37,7 +37,7 @@ export async function connectInAppWallet(
|
|
37
37
|
| CreateWalletArgs<"inApp">[1]
|
38
38
|
| CreateWalletArgs<EcosystemWalletId>[1],
|
39
39
|
connector: InAppConnector,
|
40
|
-
): Promise<
|
40
|
+
): Promise<{ account: Account; chain: Chain; adminAccount?: Account }> {
|
41
41
|
if (
|
42
42
|
// if auth mode is not specified, the default is popup
|
43
43
|
createOptions?.auth?.mode !== "popup" &&
|
@@ -65,15 +65,16 @@ export async function connectInAppWallet(
|
|
65
65
|
"smartAccount" in createOptions &&
|
66
66
|
createOptions?.smartAccount
|
67
67
|
) {
|
68
|
-
|
68
|
+
const [account, chain] = await convertToSmartAccount({
|
69
69
|
client: options.client,
|
70
70
|
authAccount,
|
71
71
|
smartAccountOptions: createOptions.smartAccount,
|
72
72
|
chain: options.chain,
|
73
73
|
});
|
74
|
+
return { account, chain, adminAccount: authAccount };
|
74
75
|
}
|
75
76
|
|
76
|
-
return
|
77
|
+
return { account: authAccount, chain: options.chain || ethereum } as const;
|
77
78
|
}
|
78
79
|
|
79
80
|
/**
|
@@ -87,7 +88,7 @@ export async function autoConnectInAppWallet(
|
|
87
88
|
| CreateWalletArgs<"inApp">[1]
|
88
89
|
| CreateWalletArgs<EcosystemWalletId>[1],
|
89
90
|
connector: InAppConnector,
|
90
|
-
): Promise<
|
91
|
+
): Promise<{ account: Account; chain: Chain; adminAccount?: Account }> {
|
91
92
|
if (options.authResult && connector.loginWithAuthToken) {
|
92
93
|
await connector.loginWithAuthToken(options.authResult);
|
93
94
|
}
|
@@ -104,15 +105,16 @@ export async function autoConnectInAppWallet(
|
|
104
105
|
"smartAccount" in createOptions &&
|
105
106
|
createOptions?.smartAccount
|
106
107
|
) {
|
107
|
-
|
108
|
+
const [account, chain] = await convertToSmartAccount({
|
108
109
|
client: options.client,
|
109
110
|
authAccount,
|
110
111
|
smartAccountOptions: createOptions.smartAccount,
|
111
112
|
chain: options.chain,
|
112
113
|
});
|
114
|
+
return { account, chain, adminAccount: authAccount };
|
113
115
|
}
|
114
116
|
|
115
|
-
return
|
117
|
+
return { account: authAccount, chain: options.chain || ethereum } as const;
|
116
118
|
}
|
117
119
|
|
118
120
|
async function convertToSmartAccount(options: {
|
@@ -121,14 +123,9 @@ async function convertToSmartAccount(options: {
|
|
121
123
|
smartAccountOptions: CreateWalletArgs<"smart">[1];
|
122
124
|
chain?: Chain;
|
123
125
|
}) {
|
124
|
-
const
|
125
|
-
import("../../../smart/smart-wallet.js"),
|
126
|
-
import("../../../smart/index.js"),
|
127
|
-
]);
|
126
|
+
const { connectSmartAccount } = await import("../../../smart/index.js");
|
128
127
|
|
129
|
-
|
130
|
-
return connectSmartWallet(
|
131
|
-
sa,
|
128
|
+
return connectSmartAccount(
|
132
129
|
{
|
133
130
|
client: options.client,
|
134
131
|
personalAccount: options.authAccount,
|
@@ -2,6 +2,10 @@ 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 {
|
6
|
+
AuthorizationRequest,
|
7
|
+
SignedAuthorization,
|
8
|
+
} from "../../transaction/actions/eip7702/authorization.js";
|
5
9
|
import type {
|
6
10
|
EIP712TransactionOptions,
|
7
11
|
PreparedTransaction,
|
@@ -195,6 +199,17 @@ export type Account = {
|
|
195
199
|
|
196
200
|
// OPTIONAL
|
197
201
|
|
202
|
+
/**
|
203
|
+
* Sign the given EIP-7702 authorization object.
|
204
|
+
* @example
|
205
|
+
* ```ts
|
206
|
+
* const signedAuthorization = await account.signAuthorization({ address: "0x...", chainId: 1, nonce: 1n });
|
207
|
+
* ```
|
208
|
+
*/
|
209
|
+
signAuthorization?: (
|
210
|
+
authorization: AuthorizationRequest,
|
211
|
+
) => Promise<SignedAuthorization>;
|
212
|
+
|
198
213
|
/**
|
199
214
|
* Estimate the gas required to execute the given transaction.
|
200
215
|
*
|
@@ -1,10 +1,13 @@
|
|
1
1
|
import { secp256k1 } from "@noble/curves/secp256k1";
|
2
|
+
import * as ox__Authorization from "ox/Authorization";
|
3
|
+
import * as ox__Secp256k1 from "ox/Secp256k1";
|
2
4
|
import type * as ox__TypedData from "ox/TypedData";
|
3
5
|
import { publicKeyToAddress } from "viem/utils";
|
4
6
|
import { getCachedChain } from "../chains/utils.js";
|
5
7
|
import type { ThirdwebClient } from "../client/client.js";
|
6
8
|
import { eth_sendRawTransaction } from "../rpc/actions/eth_sendRawTransaction.js";
|
7
9
|
import { getRpcClient } from "../rpc/rpc.js";
|
10
|
+
import type { AuthorizationRequest } from "../transaction/actions/eip7702/authorization.js";
|
8
11
|
import { signTransaction } from "../transaction/actions/sign-transaction.js";
|
9
12
|
import type { SerializableTransaction } from "../transaction/serialize-transaction.js";
|
10
13
|
import { type Hex, toHex } from "../utils/encoding/hex.js";
|
@@ -119,6 +122,13 @@ export function privateKeyToAccount(
|
|
119
122
|
privateKey,
|
120
123
|
});
|
121
124
|
},
|
125
|
+
signAuthorization: async (authorization: AuthorizationRequest) => {
|
126
|
+
const signature = ox__Secp256k1.sign({
|
127
|
+
payload: ox__Authorization.getSignPayload(authorization),
|
128
|
+
privateKey: privateKey,
|
129
|
+
});
|
130
|
+
return ox__Authorization.from(authorization, { signature });
|
131
|
+
},
|
122
132
|
};
|
123
133
|
|
124
134
|
return account satisfies Account;
|