@account-kit/wallet-client 0.1.0-alpha.10 → 0.1.0-alpha.12
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/esm/client/actions/getCallsStatus.d.ts +4 -3
- package/dist/esm/client/actions/getCallsStatus.js +1 -0
- package/dist/esm/client/actions/getCallsStatus.js.map +1 -1
- package/dist/esm/client/actions/grantPermissions.d.ts +5 -4
- package/dist/esm/client/actions/grantPermissions.js +21 -5
- package/dist/esm/client/actions/grantPermissions.js.map +1 -1
- package/dist/esm/client/actions/prepareCalls.d.ts +4 -3
- package/dist/esm/client/actions/prepareCalls.js +1 -0
- package/dist/esm/client/actions/prepareCalls.js.map +1 -1
- package/dist/esm/client/actions/prepareSign.d.ts +4 -3
- package/dist/esm/client/actions/prepareSign.js +1 -0
- package/dist/esm/client/actions/prepareSign.js.map +1 -1
- package/dist/esm/client/actions/requestAccount.js +3 -3
- package/dist/esm/client/actions/requestAccount.js.map +1 -1
- package/dist/esm/client/actions/signSignatureRequest.d.ts +3 -3
- package/dist/esm/client/actions/signSignatureRequest.js.map +1 -1
- package/dist/esm/client/client.e2e-test.js +190 -329
- package/dist/esm/client/client.e2e-test.js.map +1 -1
- package/dist/esm/client/index.d.ts +1 -4
- package/dist/esm/client/index.js +13 -18
- package/dist/esm/client/index.js.map +1 -1
- package/dist/esm/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +3 -7
- package/dist/esm/{isomorphic/utils/createAccount.js → internal/account.js} +9 -33
- package/dist/esm/internal/account.js.map +1 -0
- package/dist/esm/types.d.ts +2 -8
- package/dist/esm/types.js.map +1 -1
- package/dist/types/client/actions/getCallsStatus.d.ts +4 -3
- package/dist/types/client/actions/getCallsStatus.d.ts.map +1 -1
- package/dist/types/client/actions/grantPermissions.d.ts +5 -4
- package/dist/types/client/actions/grantPermissions.d.ts.map +1 -1
- package/dist/types/client/actions/prepareCalls.d.ts +4 -3
- package/dist/types/client/actions/prepareCalls.d.ts.map +1 -1
- package/dist/types/client/actions/prepareSign.d.ts +4 -3
- package/dist/types/client/actions/prepareSign.d.ts.map +1 -1
- package/dist/types/client/actions/requestAccount.d.ts.map +1 -1
- package/dist/types/client/actions/signSignatureRequest.d.ts +3 -3
- package/dist/types/client/actions/signSignatureRequest.d.ts.map +1 -1
- package/dist/types/client/index.d.ts +1 -4
- package/dist/types/client/index.d.ts.map +1 -1
- package/dist/types/{isomorphic/utils/createAccount.d.ts → internal/account.d.ts} +4 -8
- package/dist/types/internal/account.d.ts.map +1 -0
- package/dist/types/types.d.ts +2 -8
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +3 -8
- package/src/client/actions/getCallsStatus.ts +8 -6
- package/src/client/actions/grantPermissions.ts +41 -10
- package/src/client/actions/prepareCalls.ts +11 -6
- package/src/client/actions/prepareSign.ts +9 -6
- package/src/client/actions/requestAccount.ts +3 -3
- package/src/client/actions/signSignatureRequest.ts +8 -8
- package/src/client/client.e2e-test.ts +143 -298
- package/src/client/index.ts +22 -23
- package/src/{isomorphic/utils/createAccount.ts → internal/account.ts} +11 -51
- package/src/types.ts +4 -15
- package/dist/esm/exports/internal.d.ts +0 -4
- package/dist/esm/exports/internal.js +0 -3
- package/dist/esm/exports/internal.js.map +0 -1
- package/dist/esm/isomorphic/actions/createSession.d.ts +0 -13
- package/dist/esm/isomorphic/actions/createSession.js +0 -94
- package/dist/esm/isomorphic/actions/createSession.js.map +0 -1
- package/dist/esm/isomorphic/actions/formatSign.d.ts +0 -8
- package/dist/esm/isomorphic/actions/formatSign.js +0 -42
- package/dist/esm/isomorphic/actions/formatSign.js.map +0 -1
- package/dist/esm/isomorphic/actions/getCallsStatus.d.ts +0 -7
- package/dist/esm/isomorphic/actions/getCallsStatus.js +0 -71
- package/dist/esm/isomorphic/actions/getCallsStatus.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareCalls.d.ts +0 -7
- package/dist/esm/isomorphic/actions/prepareCalls.js +0 -116
- package/dist/esm/isomorphic/actions/prepareCalls.js.map +0 -1
- package/dist/esm/isomorphic/actions/prepareSign.d.ts +0 -7
- package/dist/esm/isomorphic/actions/prepareSign.js +0 -49
- package/dist/esm/isomorphic/actions/prepareSign.js.map +0 -1
- package/dist/esm/isomorphic/actions/sendPreparedCalls.d.ts +0 -7
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js +0 -156
- package/dist/esm/isomorphic/actions/sendPreparedCalls.js.map +0 -1
- package/dist/esm/isomorphic/client.d.ts +0 -275
- package/dist/esm/isomorphic/client.js +0 -41
- package/dist/esm/isomorphic/client.js.map +0 -1
- package/dist/esm/isomorphic/utils/7702.d.ts +0 -19
- package/dist/esm/isomorphic/utils/7702.js +0 -70
- package/dist/esm/isomorphic/utils/7702.js.map +0 -1
- package/dist/esm/isomorphic/utils/createAccount.js.map +0 -1
- package/dist/esm/isomorphic/utils/createDummySigner.d.ts +0 -3
- package/dist/esm/isomorphic/utils/createDummySigner.js +0 -17
- package/dist/esm/isomorphic/utils/createDummySigner.js.map +0 -1
- package/dist/esm/isomorphic/utils/decodeSignature.d.ts +0 -3
- package/dist/esm/isomorphic/utils/decodeSignature.js +0 -15
- package/dist/esm/isomorphic/utils/decodeSignature.js.map +0 -1
- package/dist/esm/isomorphic/utils/parsePermissionsContext.d.ts +0 -21
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js +0 -34
- package/dist/esm/isomorphic/utils/parsePermissionsContext.js.map +0 -1
- package/dist/esm/isomorphic/utils/supportsFeature.d.ts +0 -4
- package/dist/esm/isomorphic/utils/supportsFeature.js +0 -21
- package/dist/esm/isomorphic/utils/supportsFeature.js.map +0 -1
- package/dist/esm/local/client.d.ts +0 -3
- package/dist/esm/local/client.js +0 -97
- package/dist/esm/local/client.js.map +0 -1
- package/dist/esm/remote/client.d.ts +0 -9
- package/dist/esm/remote/client.js +0 -41
- package/dist/esm/remote/client.js.map +0 -1
- package/dist/types/exports/internal.d.ts +0 -5
- package/dist/types/exports/internal.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/createSession.d.ts +0 -14
- package/dist/types/isomorphic/actions/createSession.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/formatSign.d.ts +0 -9
- package/dist/types/isomorphic/actions/formatSign.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts +0 -8
- package/dist/types/isomorphic/actions/getCallsStatus.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareCalls.d.ts +0 -8
- package/dist/types/isomorphic/actions/prepareCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/prepareSign.d.ts +0 -8
- package/dist/types/isomorphic/actions/prepareSign.d.ts.map +0 -1
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts +0 -8
- package/dist/types/isomorphic/actions/sendPreparedCalls.d.ts.map +0 -1
- package/dist/types/isomorphic/client.d.ts +0 -276
- package/dist/types/isomorphic/client.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/7702.d.ts +0 -20
- package/dist/types/isomorphic/utils/7702.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createAccount.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/createDummySigner.d.ts +0 -4
- package/dist/types/isomorphic/utils/createDummySigner.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/decodeSignature.d.ts +0 -4
- package/dist/types/isomorphic/utils/decodeSignature.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts +0 -22
- package/dist/types/isomorphic/utils/parsePermissionsContext.d.ts.map +0 -1
- package/dist/types/isomorphic/utils/supportsFeature.d.ts +0 -5
- package/dist/types/isomorphic/utils/supportsFeature.d.ts.map +0 -1
- package/dist/types/local/client.d.ts +0 -4
- package/dist/types/local/client.d.ts.map +0 -1
- package/dist/types/remote/client.d.ts +0 -10
- package/dist/types/remote/client.d.ts.map +0 -1
- package/src/exports/internal.ts +0 -8
- package/src/isomorphic/actions/createSession.ts +0 -163
- package/src/isomorphic/actions/formatSign.ts +0 -76
- package/src/isomorphic/actions/getCallsStatus.ts +0 -112
- package/src/isomorphic/actions/prepareCalls.ts +0 -172
- package/src/isomorphic/actions/prepareSign.ts +0 -91
- package/src/isomorphic/actions/sendPreparedCalls.ts +0 -234
- package/src/isomorphic/client.ts +0 -102
- package/src/isomorphic/utils/7702.ts +0 -135
- package/src/isomorphic/utils/createDummySigner.ts +0 -27
- package/src/isomorphic/utils/decodeSignature.ts +0 -21
- package/src/isomorphic/utils/parsePermissionsContext.ts +0 -51
- package/src/isomorphic/utils/supportsFeature.ts +0 -34
- package/src/local/client.ts +0 -136
- package/src/remote/client.ts +0 -67
|
@@ -3,6 +3,7 @@ import { alchemy, arbitrumSepolia } from "@account-kit/infra";
|
|
|
3
3
|
import { describe, expect, it } from "bun:test";
|
|
4
4
|
import { createPublicClient, zeroAddress } from "viem";
|
|
5
5
|
import { createSmartWalletClient } from "./index.js";
|
|
6
|
+
import { sleep } from "bun";
|
|
6
7
|
describe("Client E2E Tests", () => {
|
|
7
8
|
const transport = alchemy(process.env.ALCHEMY_PROXY_RPC_URL
|
|
8
9
|
? {
|
|
@@ -11,361 +12,203 @@ describe("Client E2E Tests", () => {
|
|
|
11
12
|
: {
|
|
12
13
|
apiKey: process.env.TEST_ALCHEMY_API_KEY,
|
|
13
14
|
});
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
const signer = LocalAccountSigner.privateKeyToAccountSigner("0xd7b061ef04d29cf68b3c89356678eccec9988de8d5ed892c19461c4a9d65925d");
|
|
16
|
+
const client = createSmartWalletClient({
|
|
17
|
+
transport,
|
|
18
|
+
chain: arbitrumSepolia,
|
|
19
|
+
signer,
|
|
20
|
+
});
|
|
21
|
+
const publicClient = createPublicClient({
|
|
22
|
+
chain: arbitrumSepolia,
|
|
23
|
+
transport,
|
|
24
|
+
});
|
|
25
|
+
it("should successfully get a counterfactual address", async () => {
|
|
26
|
+
const account = await client.requestAccount();
|
|
27
|
+
expect(account.address).toMatchInlineSnapshot(`"0x76E765e80FFAC96ac10Aa8908a8267A3B80d606D"`);
|
|
28
|
+
});
|
|
29
|
+
it("should successfully request account with different salt", async () => {
|
|
30
|
+
const account = await client.requestAccount({
|
|
31
|
+
id: "26b375e3-c94a-4e98-b6b7-5a97121aa583",
|
|
32
|
+
creationHint: { salt: "0x1" },
|
|
21
33
|
});
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
34
|
+
expect(account.address).toMatchInlineSnapshot(`"0xdfdd407b9569D40BEFa503208753E59cAc9713fA"`);
|
|
35
|
+
});
|
|
36
|
+
it("should not cache account if different inputs provided", async () => {
|
|
37
|
+
const account = await client.requestAccount();
|
|
38
|
+
const account2 = await client.requestAccount({
|
|
39
|
+
id: "2a3320b4-6ed2-4833-a488-5188e9bdd9d2",
|
|
40
|
+
creationHint: { salt: "0x2" },
|
|
25
41
|
});
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
42
|
+
expect(account.address).not.toEqual(account2.address);
|
|
43
|
+
});
|
|
44
|
+
it("can correctly sign a message", async () => {
|
|
45
|
+
const account = await client.requestAccount();
|
|
46
|
+
const message = "hello world";
|
|
47
|
+
const signature = await client.signMessage({ message });
|
|
48
|
+
const isValid = await publicClient.verifyMessage({
|
|
49
|
+
address: account.address,
|
|
50
|
+
message: "hello world",
|
|
51
|
+
signature,
|
|
29
52
|
});
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
53
|
+
expect(isValid).toBeTrue();
|
|
54
|
+
});
|
|
55
|
+
it("can correctly sign typed data", async () => {
|
|
56
|
+
const account = await client.requestAccount();
|
|
57
|
+
const signature = await client.signTypedData(givenTypedData);
|
|
58
|
+
const isValid = await publicClient.verifyTypedData({
|
|
59
|
+
...givenTypedData,
|
|
60
|
+
signature,
|
|
61
|
+
address: account.address,
|
|
36
62
|
});
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
expect(account.address).not.toEqual(account2.address);
|
|
63
|
+
expect(isValid).toBeTrue();
|
|
64
|
+
});
|
|
65
|
+
it("can correctly sign a message with a different account", async () => {
|
|
66
|
+
const account = await client.requestAccount({
|
|
67
|
+
id: "26b375e3-c94a-4e98-b6b7-5a97121aa583",
|
|
68
|
+
creationHint: { salt: "0x1" },
|
|
44
69
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const isValid = await publicClient.verifyMessage({
|
|
50
|
-
address: account.address,
|
|
51
|
-
message,
|
|
52
|
-
signature,
|
|
53
|
-
});
|
|
54
|
-
expect(isValid).toBeTrue();
|
|
70
|
+
const message = "hello world";
|
|
71
|
+
const signature = await client.signMessage({
|
|
72
|
+
message,
|
|
73
|
+
account: account.address,
|
|
55
74
|
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
...givenTypedData,
|
|
61
|
-
signature,
|
|
62
|
-
address: account.address,
|
|
63
|
-
});
|
|
64
|
-
expect(isValid).toBeTrue();
|
|
75
|
+
const isValid = await publicClient.verifyMessage({
|
|
76
|
+
address: account.address,
|
|
77
|
+
message: "hello world",
|
|
78
|
+
signature,
|
|
65
79
|
});
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
const signature = await client.signMessage({
|
|
73
|
-
message,
|
|
74
|
-
account: account.address,
|
|
75
|
-
});
|
|
76
|
-
const isValid = await publicClient.verifyMessage({
|
|
77
|
-
address: account.address,
|
|
78
|
-
message,
|
|
79
|
-
signature,
|
|
80
|
-
});
|
|
81
|
-
expect(isValid).toBeTrue();
|
|
80
|
+
expect(isValid).toBeTrue();
|
|
81
|
+
});
|
|
82
|
+
it("can correctly sign typed data with a different account", async () => {
|
|
83
|
+
const account = await client.requestAccount({
|
|
84
|
+
id: "26b375e3-c94a-4e98-b6b7-5a97121aa583",
|
|
85
|
+
creationHint: { salt: "0x1" },
|
|
82
86
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
creationHint: { salt: "0x1" },
|
|
87
|
-
});
|
|
88
|
-
const signature = await client.signTypedData({
|
|
89
|
-
...givenTypedData,
|
|
90
|
-
account: account.address,
|
|
91
|
-
});
|
|
92
|
-
const isValid = await publicClient.verifyTypedData({
|
|
93
|
-
...givenTypedData,
|
|
94
|
-
signature,
|
|
95
|
-
address: account.address,
|
|
96
|
-
});
|
|
97
|
-
expect(isValid).toBeTrue();
|
|
87
|
+
const signature = await client.signTypedData({
|
|
88
|
+
...givenTypedData,
|
|
89
|
+
account: account.address,
|
|
98
90
|
});
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
chain: arbitrumSepolia,
|
|
104
|
-
mode: "local",
|
|
105
|
-
signer: _signer,
|
|
106
|
-
});
|
|
107
|
-
const account = await _client.requestAccount({
|
|
108
|
-
creationHint: {
|
|
109
|
-
accountType: "7702",
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
const preparedCalls = await _client.prepareCalls({
|
|
113
|
-
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
114
|
-
from: account.address,
|
|
115
|
-
capabilities: {
|
|
116
|
-
paymasterService: {
|
|
117
|
-
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
118
|
-
},
|
|
119
|
-
},
|
|
120
|
-
});
|
|
121
|
-
const signedCalls = await _client.signPreparedCalls(preparedCalls);
|
|
122
|
-
const result = await _client.sendPreparedCalls(signedCalls);
|
|
123
|
-
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
91
|
+
const isValid = await publicClient.verifyTypedData({
|
|
92
|
+
...givenTypedData,
|
|
93
|
+
signature,
|
|
94
|
+
address: account.address,
|
|
124
95
|
});
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
96
|
+
expect(isValid).toBeTrue();
|
|
97
|
+
});
|
|
98
|
+
it("should successfully send a UO with paymaster", async () => {
|
|
99
|
+
const account = await client.requestAccount();
|
|
100
|
+
const preparedCalls = await client.prepareCalls({
|
|
101
|
+
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
102
|
+
from: account.address,
|
|
103
|
+
capabilities: {
|
|
104
|
+
paymasterService: {
|
|
105
|
+
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
134
106
|
},
|
|
135
|
-
}
|
|
136
|
-
const signedCalls = await client.signPreparedCalls(preparedCalls);
|
|
137
|
-
const result = await client.sendPreparedCalls(signedCalls);
|
|
138
|
-
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
107
|
+
},
|
|
139
108
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
mode: "local",
|
|
156
|
-
signer: sessionKey,
|
|
157
|
-
});
|
|
158
|
-
const preparedCalls = await sessionKeyClient.prepareCalls({
|
|
159
|
-
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
160
|
-
from: account.address,
|
|
161
|
-
capabilities: {
|
|
162
|
-
paymasterService: {
|
|
163
|
-
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
164
|
-
},
|
|
165
|
-
permissions,
|
|
109
|
+
const signedCalls = await client.signPreparedCalls(preparedCalls);
|
|
110
|
+
const result = await client.sendPreparedCalls(signedCalls);
|
|
111
|
+
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
112
|
+
await waitForUserOpSuccess(client, result.preparedCallIds[0]);
|
|
113
|
+
}, {
|
|
114
|
+
timeout: 45_000,
|
|
115
|
+
});
|
|
116
|
+
it("should successfully drop and replace a UO with repeat calls", async () => {
|
|
117
|
+
const account = await client.requestAccount();
|
|
118
|
+
const preparedCalls = await client.prepareCalls({
|
|
119
|
+
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
120
|
+
from: account.address,
|
|
121
|
+
capabilities: {
|
|
122
|
+
paymasterService: {
|
|
123
|
+
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
166
124
|
},
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
125
|
+
},
|
|
126
|
+
});
|
|
127
|
+
const signedCalls = await client.signPreparedCalls(preparedCalls);
|
|
128
|
+
const result = await client.sendPreparedCalls(signedCalls);
|
|
129
|
+
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
130
|
+
await waitForUserOpSuccess(client, result.preparedCallIds[0]);
|
|
131
|
+
const prepareCalls2 = await client.prepareCalls({
|
|
132
|
+
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
133
|
+
from: account.address,
|
|
134
|
+
capabilities: {
|
|
135
|
+
paymasterService: {
|
|
136
|
+
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
173
137
|
},
|
|
174
|
-
}
|
|
175
|
-
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
138
|
+
},
|
|
176
139
|
});
|
|
140
|
+
const signedCalls2 = await client.signPreparedCalls(prepareCalls2);
|
|
141
|
+
const result2 = await client.sendPreparedCalls(signedCalls2);
|
|
142
|
+
expect(result2.preparedCallIds).toBeArrayOfSize(1);
|
|
143
|
+
await waitForUserOpSuccess(client, result2.preparedCallIds[0]);
|
|
144
|
+
}, {
|
|
145
|
+
timeout: 90_000,
|
|
177
146
|
});
|
|
178
|
-
|
|
179
|
-
const
|
|
180
|
-
const
|
|
147
|
+
it("should successfully send a UO with paymaster using 7702", async () => {
|
|
148
|
+
const _signer = LocalAccountSigner.privateKeyToAccountSigner("0x00d35c6d307b5cddeb70aeed96ee27a551fee58bf1a43858477e6c11f9172ba8");
|
|
149
|
+
const _client = createSmartWalletClient({
|
|
181
150
|
transport,
|
|
182
151
|
chain: arbitrumSepolia,
|
|
183
|
-
|
|
184
|
-
signer,
|
|
185
|
-
});
|
|
186
|
-
const publicClient = createPublicClient({
|
|
187
|
-
chain: arbitrumSepolia,
|
|
188
|
-
transport,
|
|
189
|
-
});
|
|
190
|
-
it("should successfully get a counterfactual address", async () => {
|
|
191
|
-
const account = await client.requestAccount();
|
|
192
|
-
expect(account.address).toMatchInlineSnapshot(`"0x76E765e80FFAC96ac10Aa8908a8267A3B80d606D"`);
|
|
193
|
-
});
|
|
194
|
-
it("should successfully request account with different salt", async () => {
|
|
195
|
-
const account = await client.requestAccount({
|
|
196
|
-
id: "26b375e3-c94a-4e98-b6b7-5a97121aa583",
|
|
197
|
-
creationHint: { salt: "0x1" },
|
|
198
|
-
});
|
|
199
|
-
expect(account.address).toMatchInlineSnapshot(`"0xdfdd407b9569D40BEFa503208753E59cAc9713fA"`);
|
|
200
|
-
});
|
|
201
|
-
it("should not cache account if different inputs provided", async () => {
|
|
202
|
-
const account = await client.requestAccount();
|
|
203
|
-
const account2 = await client.requestAccount({
|
|
204
|
-
id: "2a3320b4-6ed2-4833-a488-5188e9bdd9d2",
|
|
205
|
-
creationHint: { salt: "0x2" },
|
|
206
|
-
});
|
|
207
|
-
expect(account.address).not.toEqual(account2.address);
|
|
208
|
-
});
|
|
209
|
-
it("can correctly sign a message", async () => {
|
|
210
|
-
const account = await client.requestAccount();
|
|
211
|
-
const message = "hello world";
|
|
212
|
-
const signature = await client.signMessage({ message });
|
|
213
|
-
const isValid = await publicClient.verifyMessage({
|
|
214
|
-
address: account.address,
|
|
215
|
-
message: "hello world",
|
|
216
|
-
signature,
|
|
217
|
-
});
|
|
218
|
-
expect(isValid).toBeTrue();
|
|
219
|
-
});
|
|
220
|
-
it("can correctly sign typed data", async () => {
|
|
221
|
-
const account = await client.requestAccount();
|
|
222
|
-
const signature = await client.signTypedData(givenTypedData);
|
|
223
|
-
const isValid = await publicClient.verifyTypedData({
|
|
224
|
-
...givenTypedData,
|
|
225
|
-
signature,
|
|
226
|
-
address: account.address,
|
|
227
|
-
});
|
|
228
|
-
expect(isValid).toBeTrue();
|
|
152
|
+
signer: _signer,
|
|
229
153
|
});
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
});
|
|
235
|
-
const message = "hello world";
|
|
236
|
-
const signature = await client.signMessage({
|
|
237
|
-
message,
|
|
238
|
-
account: account.address,
|
|
239
|
-
});
|
|
240
|
-
const isValid = await publicClient.verifyMessage({
|
|
241
|
-
address: account.address,
|
|
242
|
-
message: "hello world",
|
|
243
|
-
signature,
|
|
244
|
-
});
|
|
245
|
-
expect(isValid).toBeTrue();
|
|
246
|
-
});
|
|
247
|
-
it("can correctly sign typed data with a different account", async () => {
|
|
248
|
-
const account = await client.requestAccount({
|
|
249
|
-
id: "26b375e3-c94a-4e98-b6b7-5a97121aa583",
|
|
250
|
-
creationHint: { salt: "0x1" },
|
|
251
|
-
});
|
|
252
|
-
const signature = await client.signTypedData({
|
|
253
|
-
...givenTypedData,
|
|
254
|
-
account: account.address,
|
|
255
|
-
});
|
|
256
|
-
const isValid = await publicClient.verifyTypedData({
|
|
257
|
-
...givenTypedData,
|
|
258
|
-
signature,
|
|
259
|
-
address: account.address,
|
|
260
|
-
});
|
|
261
|
-
expect(isValid).toBeTrue();
|
|
154
|
+
const account = await _client.requestAccount({
|
|
155
|
+
creationHint: {
|
|
156
|
+
accountType: "7702",
|
|
157
|
+
},
|
|
262
158
|
});
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
271
|
-
},
|
|
159
|
+
expect(account.address).toBe(await _signer.getAddress());
|
|
160
|
+
const preparedCalls = await _client.prepareCalls({
|
|
161
|
+
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
162
|
+
from: account.address,
|
|
163
|
+
capabilities: {
|
|
164
|
+
paymasterService: {
|
|
165
|
+
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
272
166
|
},
|
|
273
|
-
}
|
|
274
|
-
const signedCalls = await client.signPreparedCalls(preparedCalls);
|
|
275
|
-
const result = await client.sendPreparedCalls(signedCalls);
|
|
276
|
-
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
167
|
+
},
|
|
277
168
|
});
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
from: account.address,
|
|
295
|
-
capabilities: {
|
|
296
|
-
paymasterService: {
|
|
297
|
-
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
298
|
-
},
|
|
299
|
-
},
|
|
300
|
-
});
|
|
301
|
-
const signedCalls2 = await client.signPreparedCalls(prepareCalls2);
|
|
302
|
-
const result2 = await client.sendPreparedCalls(signedCalls2);
|
|
303
|
-
expect(result2.preparedCallIds).toBeArrayOfSize(1);
|
|
169
|
+
const signedCalls = await _client.signPreparedCalls(preparedCalls);
|
|
170
|
+
const result = await _client.sendPreparedCalls(signedCalls);
|
|
171
|
+
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
172
|
+
await waitForUserOpSuccess(client, result.preparedCallIds[0]);
|
|
173
|
+
}, { timeout: 45_000 });
|
|
174
|
+
it("should successfully create a session with grantPermissions and send a UO", async () => {
|
|
175
|
+
const account = await client.requestAccount();
|
|
176
|
+
const sessionKey = LocalAccountSigner.generatePrivateKeySigner();
|
|
177
|
+
const permissions = await client.grantPermissions({
|
|
178
|
+
account: account.address,
|
|
179
|
+
expirySec: Math.floor(Date.now() / 1000) + 60 * 60,
|
|
180
|
+
key: {
|
|
181
|
+
publicKey: await sessionKey.getAddress(),
|
|
182
|
+
type: "secp256k1",
|
|
183
|
+
},
|
|
184
|
+
permissions: [{ type: "root" }],
|
|
304
185
|
});
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
chain: arbitrumSepolia,
|
|
310
|
-
mode: "remote",
|
|
311
|
-
signer: _signer,
|
|
312
|
-
});
|
|
313
|
-
const account = await _client.requestAccount({
|
|
314
|
-
creationHint: {
|
|
315
|
-
accountType: "7702",
|
|
316
|
-
},
|
|
317
|
-
});
|
|
318
|
-
expect(account.address).toBe(await _signer.getAddress());
|
|
319
|
-
const preparedCalls = await _client.prepareCalls({
|
|
320
|
-
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
321
|
-
from: account.address,
|
|
322
|
-
capabilities: {
|
|
323
|
-
paymasterService: {
|
|
324
|
-
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
325
|
-
},
|
|
326
|
-
},
|
|
327
|
-
});
|
|
328
|
-
const signedCalls = await _client.signPreparedCalls(preparedCalls);
|
|
329
|
-
const result = await _client.sendPreparedCalls(signedCalls);
|
|
330
|
-
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
186
|
+
const sessionKeyClient = createSmartWalletClient({
|
|
187
|
+
transport,
|
|
188
|
+
chain: arbitrumSepolia,
|
|
189
|
+
signer: sessionKey,
|
|
331
190
|
});
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
key: {
|
|
339
|
-
publicKey: await sessionKey.getAddress(),
|
|
340
|
-
type: "secp256k1",
|
|
341
|
-
},
|
|
342
|
-
permissions: [{ type: "root" }],
|
|
343
|
-
});
|
|
344
|
-
const sessionKeyClient = createSmartWalletClient({
|
|
345
|
-
transport,
|
|
346
|
-
chain: arbitrumSepolia,
|
|
347
|
-
mode: "remote",
|
|
348
|
-
signer: sessionKey,
|
|
349
|
-
});
|
|
350
|
-
const preparedCalls = await sessionKeyClient.prepareCalls({
|
|
351
|
-
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
352
|
-
from: account.address,
|
|
353
|
-
capabilities: {
|
|
354
|
-
paymasterService: {
|
|
355
|
-
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
356
|
-
},
|
|
357
|
-
permissions,
|
|
358
|
-
},
|
|
359
|
-
});
|
|
360
|
-
const signedCalls = await sessionKeyClient.signPreparedCalls(preparedCalls);
|
|
361
|
-
const result = await sessionKeyClient.sendPreparedCalls({
|
|
362
|
-
...signedCalls,
|
|
363
|
-
capabilities: {
|
|
364
|
-
permissions,
|
|
191
|
+
const preparedCalls = await sessionKeyClient.prepareCalls({
|
|
192
|
+
calls: [{ to: zeroAddress, value: "0x0" }],
|
|
193
|
+
from: account.address,
|
|
194
|
+
capabilities: {
|
|
195
|
+
paymasterService: {
|
|
196
|
+
policyId: process.env.TEST_PAYMASTER_POLICY_ID,
|
|
365
197
|
},
|
|
366
|
-
|
|
367
|
-
|
|
198
|
+
permissions,
|
|
199
|
+
},
|
|
200
|
+
});
|
|
201
|
+
const signedCalls = await sessionKeyClient.signPreparedCalls(preparedCalls);
|
|
202
|
+
const result = await sessionKeyClient.sendPreparedCalls({
|
|
203
|
+
...signedCalls,
|
|
204
|
+
capabilities: {
|
|
205
|
+
permissions,
|
|
206
|
+
},
|
|
368
207
|
});
|
|
208
|
+
expect(result.preparedCallIds).toBeArrayOfSize(1);
|
|
209
|
+
await waitForUserOpSuccess(client, result.preparedCallIds[0]);
|
|
210
|
+
}, {
|
|
211
|
+
timeout: 45_000,
|
|
369
212
|
});
|
|
370
213
|
const givenTypedData = {
|
|
371
214
|
types: {
|
|
@@ -399,4 +242,22 @@ describe("Client E2E Tests", () => {
|
|
|
399
242
|
},
|
|
400
243
|
};
|
|
401
244
|
});
|
|
245
|
+
const waitForUserOpSuccess = async (client, preparedCallId) => {
|
|
246
|
+
const maxTimeoutMs = 1000 * 30;
|
|
247
|
+
const deadline = Date.now() + maxTimeoutMs;
|
|
248
|
+
while (Date.now() < deadline) {
|
|
249
|
+
const status = (await client.getCallsStatus(preparedCallId)).status;
|
|
250
|
+
if (status === 200) {
|
|
251
|
+
// Success.
|
|
252
|
+
return;
|
|
253
|
+
}
|
|
254
|
+
if (status !== 100) {
|
|
255
|
+
// Error.
|
|
256
|
+
throw new Error(`Get call status failed with status ${status}.`);
|
|
257
|
+
}
|
|
258
|
+
// Pending.
|
|
259
|
+
await sleep(5000);
|
|
260
|
+
}
|
|
261
|
+
throw new Error("Timed out waiting for successful call status.");
|
|
262
|
+
};
|
|
402
263
|
//# sourceMappingURL=client.e2e-test.js.map
|