@dynamic-labs/ethereum-aa 4.10.4-preview.0 → 4.10.4-preview.2
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/CHANGELOG.md +22 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +9 -10
- package/src/ZKsyncConnector.cjs +106 -18
- package/src/ZKsyncConnector.d.ts +20 -17
- package/src/ZKsyncConnector.js +106 -18
- package/src/ZeroDevConnector.d.ts +2 -7
- package/src/ZKsync/client.cjs +0 -29
- package/src/ZKsync/client.d.ts +0 -24
- package/src/ZKsync/client.js +0 -25
- package/src/ZKsync/ecdsaAccount.cjs +0 -32
- package/src/ZKsync/ecdsaAccount.d.ts +0 -13
- package/src/ZKsync/ecdsaAccount.js +0 -28
- package/src/ZKsync/getEip712Domain.cjs +0 -62
- package/src/ZKsync/getEip712Domain.d.ts +0 -2
- package/src/ZKsync/getEip712Domain.js +0 -58
- package/src/ZKsync/types.cjs +0 -52
- package/src/ZKsync/types.d.ts +0 -9
- package/src/ZKsync/types.js +0 -48
- package/src/ZKsync/walletActions.cjs +0 -93
- package/src/ZKsync/walletActions.d.ts +0 -15
- package/src/ZKsync/walletActions.js +0 -87
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,26 @@
|
|
|
1
1
|
|
|
2
|
+
### [4.10.4-preview.2](https://github.com/dynamic-labs/dynamic-auth/compare/v4.10.4...v4.10.4-preview.2) (2025-04-09)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add session key client ([#8463](https://github.com/dynamic-labs/dynamic-auth/issues/8463)) ([d08019c](https://github.com/dynamic-labs/dynamic-auth/commit/d08019ccf82bfc75b26a24170bfa6086d80df69a))
|
|
8
|
+
* add zk sync aa connector ([baf6241](https://github.com/dynamic-labs/dynamic-auth/commit/baf6241119dde2c3ce6c4ae3ac5467d50e1b3953))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
### Bug Fixes
|
|
12
|
+
|
|
13
|
+
* **QNTM-3113:** fix network switcher fallback logic ([#8478](https://github.com/dynamic-labs/dynamic-auth/issues/8478)) ([173c4f7](https://github.com/dynamic-labs/dynamic-auth/commit/173c4f7a66e130dd8d5f9726596807489609bf14))
|
|
14
|
+
* retrieval of walletclient for zksync connector ([0707bc3](https://github.com/dynamic-labs/dynamic-auth/commit/0707bc39049c54bf5fe10953faf5486bcf317f20))
|
|
15
|
+
|
|
16
|
+
### [4.10.4-preview.1](https://github.com/dynamic-labs/dynamic-auth/compare/v4.10.4...v4.10.4-preview.1) (2025-04-08)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
### Features
|
|
20
|
+
|
|
21
|
+
* add session key client ([#8463](https://github.com/dynamic-labs/dynamic-auth/issues/8463)) ([6ed4ebd](https://github.com/dynamic-labs/dynamic-auth/commit/6ed4ebde3f7a8c48fc3461760690e9915e14e5b0))
|
|
22
|
+
* add zk sync aa connector ([c280038](https://github.com/dynamic-labs/dynamic-auth/commit/c280038a9d5e26c1dd1d2a5b71c6a7762a43d042))
|
|
23
|
+
|
|
2
24
|
### [4.10.4-preview.0](https://github.com/dynamic-labs/dynamic-auth/compare/v4.10.3...v4.10.4-preview.0) (2025-04-04)
|
|
3
25
|
|
|
4
26
|
|
package/package.cjs
CHANGED
package/package.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dynamic-labs/ethereum-aa",
|
|
3
|
-
"version": "4.10.4-preview.
|
|
3
|
+
"version": "4.10.4-preview.2",
|
|
4
4
|
"description": "A React SDK for implementing wallet web3 authentication and authorization to your website.",
|
|
5
5
|
"author": "Dynamic Labs, Inc.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,15 +22,14 @@
|
|
|
22
22
|
"@zerodev/ecdsa-validator": "5.4.4",
|
|
23
23
|
"@zerodev/multi-chain-ecdsa-validator": "5.4.3",
|
|
24
24
|
"@zerodev/sdk": "5.4.26",
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"@dynamic-labs/
|
|
28
|
-
"@dynamic-labs/
|
|
29
|
-
"@dynamic-labs/
|
|
30
|
-
"@dynamic-labs/
|
|
31
|
-
"@dynamic-labs/
|
|
32
|
-
"@dynamic-labs/wallet-
|
|
33
|
-
"@dynamic-labs/wallet-connector-core": "4.10.4-preview.0"
|
|
25
|
+
"zksync-sso": "0.0.0-beta.14",
|
|
26
|
+
"@dynamic-labs/assert-package-version": "4.10.4-preview.2",
|
|
27
|
+
"@dynamic-labs/ethereum-core": "4.10.4-preview.2",
|
|
28
|
+
"@dynamic-labs/logger": "4.10.4-preview.2",
|
|
29
|
+
"@dynamic-labs/types": "4.10.4-preview.2",
|
|
30
|
+
"@dynamic-labs/utils": "4.10.4-preview.2",
|
|
31
|
+
"@dynamic-labs/wallet-book": "4.10.4-preview.2",
|
|
32
|
+
"@dynamic-labs/wallet-connector-core": "4.10.4-preview.2"
|
|
34
33
|
},
|
|
35
34
|
"peerDependencies": {
|
|
36
35
|
"viem": "^2.21.55"
|
package/src/ZKsyncConnector.cjs
CHANGED
|
@@ -8,16 +8,16 @@ var viem = require('viem');
|
|
|
8
8
|
var zksync = require('viem/zksync');
|
|
9
9
|
var passkey = require('zksync-sso/client/passkey');
|
|
10
10
|
var utils$1 = require('zksync-sso/utils');
|
|
11
|
+
var client = require('zksync-sso/client');
|
|
12
|
+
var ecdsa = require('zksync-sso/client/ecdsa');
|
|
11
13
|
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
12
14
|
var utils = require('@dynamic-labs/utils');
|
|
13
15
|
var AccountAbstractionConnector = require('./AccountAbstractionConnector.cjs');
|
|
14
16
|
var abi = require('./utils/abi.cjs');
|
|
15
|
-
var client = require('./ZKsync/client.cjs');
|
|
16
|
-
var walletActions = require('./ZKsync/walletActions.cjs');
|
|
17
17
|
|
|
18
18
|
class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConnector {
|
|
19
19
|
constructor(props) {
|
|
20
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
20
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
21
21
|
super(props);
|
|
22
22
|
// Core wallet properties
|
|
23
23
|
this.ChainWallet = ethereumCore.EthereumWallet;
|
|
@@ -41,12 +41,12 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
41
41
|
this.providersConfig = (_a = props.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
42
42
|
this.chainId = (_b = props.apiProviders.zksync) === null || _b === void 0 ? void 0 : _b.defaultChainId;
|
|
43
43
|
this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks).filter((network) => network.chainId === this.chainId);
|
|
44
|
-
this.factoryAddress = (
|
|
45
|
-
this.paymasterAddress = (
|
|
46
|
-
this.passkeyAddress = (
|
|
47
|
-
this.sessionKeyAddress = (
|
|
44
|
+
this.factoryAddress = (_c = props.apiProviders.zksync) === null || _c === void 0 ? void 0 : _c.factoryAddress; // Fallback if not provided
|
|
45
|
+
this.paymasterAddress = (_d = props.apiProviders.zksync) === null || _d === void 0 ? void 0 : _d.paymasterAddress; // Fallback if not provided
|
|
46
|
+
this.passkeyAddress = (_e = props.apiProviders.zksync) === null || _e === void 0 ? void 0 : _e.passkeyAddress; // Fallback if not provided
|
|
47
|
+
this.sessionKeyAddress = (_f = props.apiProviders.zksync) === null || _f === void 0 ? void 0 : _f.sessionAddress; // Fallback if not provided
|
|
48
48
|
this.enablePasskeys =
|
|
49
|
-
(
|
|
49
|
+
(_h = (_g = props.settings.sdk.accountAbstraction) === null || _g === void 0 ? void 0 : _g.enablePasskeys) !== null && _h !== void 0 ? _h : false;
|
|
50
50
|
}
|
|
51
51
|
getEnabledNetworks() {
|
|
52
52
|
return this.evmNetworks;
|
|
@@ -87,12 +87,67 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
87
87
|
getAccountAbstractionProvider() {
|
|
88
88
|
return this.smartAccount;
|
|
89
89
|
}
|
|
90
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
91
90
|
getWalletClient() {
|
|
92
|
-
|
|
91
|
+
const smartAccountClient = this.smartAccount;
|
|
92
|
+
if (!smartAccountClient) {
|
|
93
93
|
return undefined;
|
|
94
94
|
}
|
|
95
|
-
|
|
95
|
+
const transport = this.getWalletClientTransport(smartAccountClient);
|
|
96
|
+
return viem.createWalletClient({
|
|
97
|
+
account: smartAccountClient.account,
|
|
98
|
+
chain: smartAccountClient.chain,
|
|
99
|
+
transport,
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
getWalletClientTransport(smartAccountClient) {
|
|
103
|
+
return viem.custom({
|
|
104
|
+
request: (_a) => _tslib.__awaiter(this, [_a], void 0, function* ({ method, params, }) {
|
|
105
|
+
const handleRequest = () => _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
106
|
+
var _b;
|
|
107
|
+
switch (method) {
|
|
108
|
+
case 'personal_sign':
|
|
109
|
+
// Delegate signing to the smart account client instance
|
|
110
|
+
return smartAccountClient.signMessage({ message: params[0] });
|
|
111
|
+
case 'eth_signTypedData_v4': {
|
|
112
|
+
// Delegate typed data signing to the smart account client instance
|
|
113
|
+
// Note: ZKsync usually expects JSON string for EIP712, but viem standard passes object.
|
|
114
|
+
// The smartAccountClient's signTypedData should handle the expected format internally.
|
|
115
|
+
const signTypedDataParams = params[1]; // Assuming standard viem format
|
|
116
|
+
return smartAccountClient.signTypedData(signTypedDataParams);
|
|
117
|
+
}
|
|
118
|
+
case 'eth_sendTransaction':
|
|
119
|
+
// Delegate transaction sending to the smart account client instance.
|
|
120
|
+
// This ensures deployment checks, paymaster logic, etc., are handled.
|
|
121
|
+
return smartAccountClient.sendTransaction(params[0]);
|
|
122
|
+
case 'eth_accounts':
|
|
123
|
+
case 'eth_requestAccounts':
|
|
124
|
+
// Return the smart account address
|
|
125
|
+
return ((_b = smartAccountClient.account) === null || _b === void 0 ? void 0 : _b.address)
|
|
126
|
+
? [smartAccountClient.account.address]
|
|
127
|
+
: [];
|
|
128
|
+
case 'eth_chainId': {
|
|
129
|
+
// Return chainId from the smart account client
|
|
130
|
+
const chainId = yield smartAccountClient.getChainId();
|
|
131
|
+
return viem.toHex(chainId);
|
|
132
|
+
}
|
|
133
|
+
default: {
|
|
134
|
+
// For other read-only methods, delegate to a basic public client transport.
|
|
135
|
+
// Avoid creating a new client/transport on every call if possible,
|
|
136
|
+
// but for simplicity here, we create it transiently.
|
|
137
|
+
// Consider caching this public client if performance becomes an issue.
|
|
138
|
+
const publicClient = viem.createPublicClient({
|
|
139
|
+
chain: smartAccountClient.chain,
|
|
140
|
+
transport: viem.http(undefined, this.providersConfig.httpTransportConfig), // Use configured transport if available
|
|
141
|
+
});
|
|
142
|
+
return publicClient.request({ method, params });
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
// The internal confirmationTransport used by smartAccountClient via its 'owner'
|
|
147
|
+
// should handle the UI prompts. We don't need to add extra prompts here.
|
|
148
|
+
return handleRequest();
|
|
149
|
+
}),
|
|
150
|
+
});
|
|
96
151
|
}
|
|
97
152
|
getTransport(provider) {
|
|
98
153
|
const transport = ethereumCore.confirmationTransport({
|
|
@@ -100,7 +155,9 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
100
155
|
onPersonalSign: (_a) => _tslib.__awaiter(this, [_a], void 0, function* ({ message }) {
|
|
101
156
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
102
157
|
if (!this._isSmartAccountDeployed) {
|
|
103
|
-
yield this.
|
|
158
|
+
yield this.deploySmartAccount({
|
|
159
|
+
withPaymaster: true,
|
|
160
|
+
});
|
|
104
161
|
}
|
|
105
162
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
106
163
|
return provider.signMessage({
|
|
@@ -111,7 +168,9 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
111
168
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
112
169
|
const signTypedData = JSON.parse(message);
|
|
113
170
|
if (!this._isSmartAccountDeployed) {
|
|
114
|
-
yield this.
|
|
171
|
+
yield this.deploySmartAccount({
|
|
172
|
+
withPaymaster: true,
|
|
173
|
+
});
|
|
115
174
|
}
|
|
116
175
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
117
176
|
return provider.signTypedData({
|
|
@@ -142,7 +201,7 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
142
201
|
}
|
|
143
202
|
const transport = this.getTransport(eoaSigner);
|
|
144
203
|
const ownerWithTransport = viem.createWalletClient(Object.assign(Object.assign({}, eoaSigner), { transport }));
|
|
145
|
-
const walletClient = yield
|
|
204
|
+
const walletClient = yield ecdsa.createZksyncEcdsaClient({
|
|
146
205
|
address: this.smartAccountAddress,
|
|
147
206
|
chain: ethereumCore.getOrMapViemChain(this.evmNetworks[0]),
|
|
148
207
|
contracts: {
|
|
@@ -150,7 +209,7 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
150
209
|
session: this.sessionKeyAddress,
|
|
151
210
|
},
|
|
152
211
|
owner: ownerWithTransport,
|
|
153
|
-
transport: viem.
|
|
212
|
+
transport: viem.custom(ownerWithTransport),
|
|
154
213
|
});
|
|
155
214
|
return walletClient;
|
|
156
215
|
});
|
|
@@ -173,6 +232,23 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
173
232
|
this.initializedDeferredPromise.resolve();
|
|
174
233
|
});
|
|
175
234
|
}
|
|
235
|
+
createSessionClient(sessionKey, sessionConfig) {
|
|
236
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
237
|
+
if (!this.smartAccountAddress) {
|
|
238
|
+
throw new Error('Smart account address is not initialized');
|
|
239
|
+
}
|
|
240
|
+
return client.createZksyncSessionClient({
|
|
241
|
+
address: this.smartAccountAddress,
|
|
242
|
+
chain: ethereumCore.getOrMapViemChain(this.evmNetworks[0]),
|
|
243
|
+
contracts: {
|
|
244
|
+
session: this.sessionKeyAddress,
|
|
245
|
+
},
|
|
246
|
+
sessionConfig,
|
|
247
|
+
sessionKey,
|
|
248
|
+
transport: viem.http(),
|
|
249
|
+
});
|
|
250
|
+
});
|
|
251
|
+
}
|
|
176
252
|
/**
|
|
177
253
|
* Creates a passkey client for ZKsync authentication
|
|
178
254
|
*
|
|
@@ -232,7 +308,7 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
232
308
|
}
|
|
233
309
|
deploySmartAccount(_a) {
|
|
234
310
|
return _tslib.__awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
|
|
235
|
-
if (withPaymaster) {
|
|
311
|
+
if (withPaymaster && this.paymasterAddress) {
|
|
236
312
|
yield this.deploySmartAccountWithPaymaster();
|
|
237
313
|
}
|
|
238
314
|
else {
|
|
@@ -242,6 +318,9 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
242
318
|
}
|
|
243
319
|
deploySmartAccountWithPaymaster() {
|
|
244
320
|
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
321
|
+
if (!this.paymasterAddress) {
|
|
322
|
+
throw new Error('Paymaster address is not initialized');
|
|
323
|
+
}
|
|
245
324
|
const paymaster = this.paymasterAddress;
|
|
246
325
|
const publicClient = yield this.getTypedPublicClient();
|
|
247
326
|
const walletClient = yield this.getTypedWalletClient();
|
|
@@ -309,7 +388,7 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
309
388
|
.extend(viem.publicActions)
|
|
310
389
|
.extend(viem.walletActions)
|
|
311
390
|
.extend(zksync.eip712WalletActions())
|
|
312
|
-
.extend(
|
|
391
|
+
.extend(ecdsa.zksyncSsoEcdsaWalletActions);
|
|
313
392
|
});
|
|
314
393
|
}
|
|
315
394
|
/**
|
|
@@ -322,10 +401,19 @@ class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConn
|
|
|
322
401
|
const salt = `0x${Buffer.from(viem.toBytes('DynamicLabs', { size: 32 })).toString('hex')}`;
|
|
323
402
|
const initialValidators = [];
|
|
324
403
|
const initialK1Owners = [this.eoaAddress];
|
|
325
|
-
|
|
404
|
+
// TODO: revisit this logic, maybe we should always add the passkey module data,
|
|
405
|
+
// otherwise if people active passkeys later, old accounts will not be able to use passkey module
|
|
406
|
+
if (this.enablePasskeys && this.passkeyAddress) {
|
|
326
407
|
const encodedPasskeyModuleData = yield this.getEncodedPasskeyModuleData();
|
|
327
408
|
initialValidators.push(encodedPasskeyModuleData);
|
|
328
409
|
}
|
|
410
|
+
if (this.sessionKeyAddress) {
|
|
411
|
+
const encodedSessionKeyModuleData = utils$1.encodeModuleData({
|
|
412
|
+
address: this.sessionKeyAddress,
|
|
413
|
+
parameters: '0x',
|
|
414
|
+
});
|
|
415
|
+
initialValidators.push(encodedSessionKeyModuleData);
|
|
416
|
+
}
|
|
329
417
|
return {
|
|
330
418
|
initialK1Owners,
|
|
331
419
|
initialValidators,
|
package/src/ZKsyncConnector.d.ts
CHANGED
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import { Account, RpcSchema, SignTypedDataParameters, Transport, type PublicClient, type Chain as ViemChain, type WalletClient } from 'viem';
|
|
1
|
+
import { Account, CustomTransport, RpcSchema, SignTypedDataParameters, Transport, type PublicClient, type Chain as ViemChain, type WalletClient } from 'viem';
|
|
2
2
|
import { ZksyncSsoPasskeyClient } from 'zksync-sso/client/passkey';
|
|
3
|
+
import { SessionConfig } from 'zksync-sso/utils';
|
|
4
|
+
import { ZksyncSsoSessionClient } from 'zksync-sso/client';
|
|
5
|
+
import { ZksyncSsoEcdsaClient } from 'zksync-sso/client/ecdsa';
|
|
3
6
|
import { EthereumWallet, RegisterEvmProvidersConfig } from '@dynamic-labs/ethereum-core';
|
|
4
7
|
import { ProjectSettings, Provider, ProviderEnum } from '@dynamic-labs/sdk-api-core';
|
|
5
8
|
import { EvmNetwork, GenericNetwork, IUITransaction, WalletUiUtils } from '@dynamic-labs/types';
|
|
6
9
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
7
10
|
import { Chain, InternalWalletConnector, IZKsyncConnector, WalletConnector } from '@dynamic-labs/wallet-connector-core';
|
|
8
11
|
import { AccountAbstractionConnector, AccountAbstractionConnectorProps } from './AccountAbstractionConnector';
|
|
9
|
-
import { ZksyncSsoEcdsaClient } from './ZKsync/client';
|
|
10
12
|
type ZKsyncConnectorProps = AccountAbstractionConnectorProps & {
|
|
11
13
|
apiProviders: {
|
|
12
14
|
[key in ProviderEnum]?: Provider;
|
|
@@ -65,6 +67,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
65
67
|
canSponsorTransactionGas(): Promise<boolean>;
|
|
66
68
|
getAccountAbstractionProvider<T = ZksyncSsoEcdsaClient<Transport, ViemChain, RpcSchema>>(): T;
|
|
67
69
|
getWalletClient(): WalletClient | undefined;
|
|
70
|
+
private getWalletClientTransport;
|
|
68
71
|
private getTransport;
|
|
69
72
|
getSigner(): Promise<{
|
|
70
73
|
account: Account | undefined;
|
|
@@ -8075,10 +8078,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
8075
8078
|
Parameters: import("viem").WatchAssetParams;
|
|
8076
8079
|
ReturnType: boolean;
|
|
8077
8080
|
}]>;
|
|
8078
|
-
transport: import("viem").TransportConfig<"
|
|
8079
|
-
fetchOptions?: Omit<RequestInit, "body"> | undefined;
|
|
8080
|
-
url?: string | undefined;
|
|
8081
|
-
};
|
|
8081
|
+
transport: import("viem").TransportConfig<"custom", import("viem").EIP1193RequestFn>;
|
|
8082
8082
|
type: string;
|
|
8083
8083
|
uid: string;
|
|
8084
8084
|
call: (parameters: import("viem").CallParameters<{
|
|
@@ -22445,7 +22445,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
22445
22445
|
testnet?: boolean | undefined;
|
|
22446
22446
|
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>>) => Promise<import("viem").TransactionReceipt>;
|
|
22447
22447
|
watchBlockNumber: (args: import("viem").WatchBlockNumberParameters) => import("viem").WatchBlockNumberReturnType;
|
|
22448
|
-
watchBlocks: <includeTransactions_1 extends boolean = false, blockTag_2 extends import("viem").BlockTag = "latest">(args: import("viem").WatchBlocksParameters<
|
|
22448
|
+
watchBlocks: <includeTransactions_1 extends boolean = false, blockTag_2 extends import("viem").BlockTag = "latest">(args: import("viem").WatchBlocksParameters<CustomTransport, {
|
|
22449
22449
|
blockExplorers?: {
|
|
22450
22450
|
[key: string]: {
|
|
22451
22451
|
name: string;
|
|
@@ -22487,9 +22487,9 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
22487
22487
|
sourceId?: number | undefined;
|
|
22488
22488
|
testnet?: boolean | undefined;
|
|
22489
22489
|
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, includeTransactions_1, blockTag_2>) => import("viem").WatchBlocksReturnType;
|
|
22490
|
-
watchContractEvent: <const abi_7 extends import("viem").Abi | readonly unknown[], eventName_4 extends import("viem").ContractEventName<abi_7>, strict_6 extends boolean | undefined = undefined>(args: import("viem").WatchContractEventParameters<abi_7, eventName_4, strict_6,
|
|
22491
|
-
watchEvent: <const abiEvent_2 extends import("viem").AbiEvent | undefined = undefined, const abiEvents_2 extends readonly unknown[] | readonly import("viem").AbiEvent[] | undefined = abiEvent_2 extends import("viem").AbiEvent ? [abiEvent_2] : undefined, strict_7 extends boolean | undefined = undefined>(args: import("viem").WatchEventParameters<abiEvent_2, abiEvents_2, strict_7,
|
|
22492
|
-
watchPendingTransactions: (args: import("viem").WatchPendingTransactionsParameters<
|
|
22490
|
+
watchContractEvent: <const abi_7 extends import("viem").Abi | readonly unknown[], eventName_4 extends import("viem").ContractEventName<abi_7>, strict_6 extends boolean | undefined = undefined>(args: import("viem").WatchContractEventParameters<abi_7, eventName_4, strict_6, CustomTransport>) => import("viem").WatchContractEventReturnType;
|
|
22491
|
+
watchEvent: <const abiEvent_2 extends import("viem").AbiEvent | undefined = undefined, const abiEvents_2 extends readonly unknown[] | readonly import("viem").AbiEvent[] | undefined = abiEvent_2 extends import("viem").AbiEvent ? [abiEvent_2] : undefined, strict_7 extends boolean | undefined = undefined>(args: import("viem").WatchEventParameters<abiEvent_2, abiEvents_2, strict_7, CustomTransport>) => import("viem").WatchEventReturnType;
|
|
22492
|
+
watchPendingTransactions: (args: import("viem").WatchPendingTransactionsParameters<CustomTransport>) => import("viem").WatchPendingTransactionsReturnType;
|
|
22493
22493
|
addChain: (args: import("viem").AddChainParameters) => Promise<void>;
|
|
22494
22494
|
deployContract: <const abi_8 extends import("viem").Abi | readonly unknown[], chainOverride_5 extends ViemChain | undefined>(args: import("viem").DeployContractParameters<abi_8, {
|
|
22495
22495
|
blockExplorers?: {
|
|
@@ -23891,6 +23891,8 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
23891
23891
|
sourceId?: number | undefined;
|
|
23892
23892
|
testnet?: boolean | undefined;
|
|
23893
23893
|
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account, chainOverride_8>) => Promise<`0x${string}`>;
|
|
23894
|
+
createSession: (args: Omit<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").CreateSessionArgs, "contracts">) => Promise<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").CreateSessionReturnType>;
|
|
23895
|
+
revokeSession: (args: Omit<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").RevokeSessionArgs, "contracts">) => Promise<import("node_modules/zksync-sso/dist/_types/client/session/actions/session").RevokeSessionReturnType>;
|
|
23894
23896
|
extend: <const client extends {
|
|
23895
23897
|
[x: string]: unknown;
|
|
23896
23898
|
account?: undefined;
|
|
@@ -23905,7 +23907,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
23905
23907
|
transport?: undefined;
|
|
23906
23908
|
type?: undefined;
|
|
23907
23909
|
uid?: undefined;
|
|
23908
|
-
} & import("viem").ExactPartial<Pick<import("viem").PublicActions<
|
|
23910
|
+
} & import("viem").ExactPartial<Pick<import("viem").PublicActions<CustomTransport, {
|
|
23909
23911
|
blockExplorers?: {
|
|
23910
23912
|
[key: string]: {
|
|
23911
23913
|
name: string;
|
|
@@ -23987,7 +23989,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
23987
23989
|
};
|
|
23988
23990
|
sourceId?: number | undefined;
|
|
23989
23991
|
testnet?: boolean | undefined;
|
|
23990
|
-
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<
|
|
23992
|
+
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account>, "sendTransaction" | "writeContract">>>(fn: (client: import("viem").Client<CustomTransport, {
|
|
23991
23993
|
blockExplorers?: {
|
|
23992
23994
|
[key: string]: {
|
|
23993
23995
|
name: string;
|
|
@@ -24322,7 +24324,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
24322
24324
|
Method: "wallet_watchAsset";
|
|
24323
24325
|
Parameters: import("viem").WatchAssetParams;
|
|
24324
24326
|
ReturnType: boolean;
|
|
24325
|
-
}], import("viem").PublicActions<
|
|
24327
|
+
}], import("viem").PublicActions<CustomTransport, {
|
|
24326
24328
|
blockExplorers?: {
|
|
24327
24329
|
[key: string]: {
|
|
24328
24330
|
name: string;
|
|
@@ -24404,7 +24406,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
24404
24406
|
};
|
|
24405
24407
|
sourceId?: number | undefined;
|
|
24406
24408
|
testnet?: boolean | undefined;
|
|
24407
|
-
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account
|
|
24409
|
+
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account> & import("zksync-sso/client/ecdsa").ZksyncSsoEcdsaActions>) => client) => import("viem").Client<CustomTransport, {
|
|
24408
24410
|
blockExplorers?: {
|
|
24409
24411
|
[key: string]: {
|
|
24410
24412
|
name: string;
|
|
@@ -24739,7 +24741,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
24739
24741
|
Method: "wallet_watchAsset";
|
|
24740
24742
|
Parameters: import("viem").WatchAssetParams;
|
|
24741
24743
|
ReturnType: boolean;
|
|
24742
|
-
}], { [K_3 in keyof client]: client[K_3]; } & import("viem").PublicActions<
|
|
24744
|
+
}], { [K_3 in keyof client]: client[K_3]; } & import("viem").PublicActions<CustomTransport, {
|
|
24743
24745
|
blockExplorers?: {
|
|
24744
24746
|
[key: string]: {
|
|
24745
24747
|
name: string;
|
|
@@ -24821,8 +24823,8 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
24821
24823
|
};
|
|
24822
24824
|
sourceId?: number | undefined;
|
|
24823
24825
|
testnet?: boolean | undefined;
|
|
24824
|
-
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account
|
|
24825
|
-
contracts: import("
|
|
24826
|
+
} & import("viem").ChainConfig<import("viem").ChainFormatters | undefined, Record<string, unknown> | undefined>, Account> & import("zksync-sso/client/ecdsa").ZksyncSsoEcdsaActions>;
|
|
24827
|
+
contracts: import("zksync-sso/client/ecdsa").EcdsaRequiredContracts;
|
|
24826
24828
|
paymasterHandler?: import("zksync-sso/paymaster").CustomPaymasterHandler | undefined;
|
|
24827
24829
|
}>;
|
|
24828
24830
|
/**
|
|
@@ -24834,6 +24836,7 @@ export declare class ZKsyncConnector extends AccountAbstractionConnector impleme
|
|
|
24834
24836
|
eoaConnector: WalletConnector;
|
|
24835
24837
|
smartAccountAddress: string;
|
|
24836
24838
|
}): Promise<void>;
|
|
24839
|
+
createSessionClient(sessionKey: `0x${string}`, sessionConfig: SessionConfig): Promise<ZksyncSsoSessionClient<Transport, ViemChain, RpcSchema>>;
|
|
24837
24840
|
/**
|
|
24838
24841
|
* Creates a passkey client for ZKsync authentication
|
|
24839
24842
|
*
|
package/src/ZKsyncConnector.js
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
-
import { createPublicClient, http,
|
|
3
|
+
import { createPublicClient, http, createWalletClient, custom, publicActions, walletActions, toBytes, keccak256, toHex } from 'viem';
|
|
4
4
|
import { getGeneralPaymasterInput, eip712WalletActions } from 'viem/zksync';
|
|
5
5
|
import { createZksyncPasskeyClient, registerNewPasskey } from 'zksync-sso/client/passkey';
|
|
6
|
-
import { getPublicKeyBytesFromPasskeySignature, encodePasskeyModuleParameters
|
|
6
|
+
import { encodeModuleData, getPublicKeyBytesFromPasskeySignature, encodePasskeyModuleParameters } from 'zksync-sso/utils';
|
|
7
|
+
import { createZksyncSessionClient } from 'zksync-sso/client';
|
|
8
|
+
import { createZksyncEcdsaClient, zksyncSsoEcdsaWalletActions } from 'zksync-sso/client/ecdsa';
|
|
7
9
|
import { EthereumWallet, getOrMapViemChain, confirmationTransport, createViemUiTransaction } from '@dynamic-labs/ethereum-core';
|
|
8
10
|
import { parseEvmNetworks, DeferredPromise, StorageService, DynamicError } from '@dynamic-labs/utils';
|
|
9
11
|
import { AccountAbstractionConnector } from './AccountAbstractionConnector.js';
|
|
10
12
|
import { AAFactoryABI } from './utils/abi.js';
|
|
11
|
-
import { createZksyncEcdsaClient } from './ZKsync/client.js';
|
|
12
|
-
import { zksyncSsoEcdsaWalletActions } from './ZKsync/walletActions.js';
|
|
13
13
|
|
|
14
14
|
class ZKsyncConnector extends AccountAbstractionConnector {
|
|
15
15
|
constructor(props) {
|
|
16
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
16
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
17
17
|
super(props);
|
|
18
18
|
// Core wallet properties
|
|
19
19
|
this.ChainWallet = EthereumWallet;
|
|
@@ -37,12 +37,12 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
37
37
|
this.providersConfig = (_a = props.providersConfig) !== null && _a !== void 0 ? _a : {};
|
|
38
38
|
this.chainId = (_b = props.apiProviders.zksync) === null || _b === void 0 ? void 0 : _b.defaultChainId;
|
|
39
39
|
this.evmNetworks = parseEvmNetworks(props.evmNetworks).filter((network) => network.chainId === this.chainId);
|
|
40
|
-
this.factoryAddress = (
|
|
41
|
-
this.paymasterAddress = (
|
|
42
|
-
this.passkeyAddress = (
|
|
43
|
-
this.sessionKeyAddress = (
|
|
40
|
+
this.factoryAddress = (_c = props.apiProviders.zksync) === null || _c === void 0 ? void 0 : _c.factoryAddress; // Fallback if not provided
|
|
41
|
+
this.paymasterAddress = (_d = props.apiProviders.zksync) === null || _d === void 0 ? void 0 : _d.paymasterAddress; // Fallback if not provided
|
|
42
|
+
this.passkeyAddress = (_e = props.apiProviders.zksync) === null || _e === void 0 ? void 0 : _e.passkeyAddress; // Fallback if not provided
|
|
43
|
+
this.sessionKeyAddress = (_f = props.apiProviders.zksync) === null || _f === void 0 ? void 0 : _f.sessionAddress; // Fallback if not provided
|
|
44
44
|
this.enablePasskeys =
|
|
45
|
-
(
|
|
45
|
+
(_h = (_g = props.settings.sdk.accountAbstraction) === null || _g === void 0 ? void 0 : _g.enablePasskeys) !== null && _h !== void 0 ? _h : false;
|
|
46
46
|
}
|
|
47
47
|
getEnabledNetworks() {
|
|
48
48
|
return this.evmNetworks;
|
|
@@ -83,12 +83,67 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
83
83
|
getAccountAbstractionProvider() {
|
|
84
84
|
return this.smartAccount;
|
|
85
85
|
}
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
87
86
|
getWalletClient() {
|
|
88
|
-
|
|
87
|
+
const smartAccountClient = this.smartAccount;
|
|
88
|
+
if (!smartAccountClient) {
|
|
89
89
|
return undefined;
|
|
90
90
|
}
|
|
91
|
-
|
|
91
|
+
const transport = this.getWalletClientTransport(smartAccountClient);
|
|
92
|
+
return createWalletClient({
|
|
93
|
+
account: smartAccountClient.account,
|
|
94
|
+
chain: smartAccountClient.chain,
|
|
95
|
+
transport,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
getWalletClientTransport(smartAccountClient) {
|
|
99
|
+
return custom({
|
|
100
|
+
request: (_a) => __awaiter(this, [_a], void 0, function* ({ method, params, }) {
|
|
101
|
+
const handleRequest = () => __awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
var _b;
|
|
103
|
+
switch (method) {
|
|
104
|
+
case 'personal_sign':
|
|
105
|
+
// Delegate signing to the smart account client instance
|
|
106
|
+
return smartAccountClient.signMessage({ message: params[0] });
|
|
107
|
+
case 'eth_signTypedData_v4': {
|
|
108
|
+
// Delegate typed data signing to the smart account client instance
|
|
109
|
+
// Note: ZKsync usually expects JSON string for EIP712, but viem standard passes object.
|
|
110
|
+
// The smartAccountClient's signTypedData should handle the expected format internally.
|
|
111
|
+
const signTypedDataParams = params[1]; // Assuming standard viem format
|
|
112
|
+
return smartAccountClient.signTypedData(signTypedDataParams);
|
|
113
|
+
}
|
|
114
|
+
case 'eth_sendTransaction':
|
|
115
|
+
// Delegate transaction sending to the smart account client instance.
|
|
116
|
+
// This ensures deployment checks, paymaster logic, etc., are handled.
|
|
117
|
+
return smartAccountClient.sendTransaction(params[0]);
|
|
118
|
+
case 'eth_accounts':
|
|
119
|
+
case 'eth_requestAccounts':
|
|
120
|
+
// Return the smart account address
|
|
121
|
+
return ((_b = smartAccountClient.account) === null || _b === void 0 ? void 0 : _b.address)
|
|
122
|
+
? [smartAccountClient.account.address]
|
|
123
|
+
: [];
|
|
124
|
+
case 'eth_chainId': {
|
|
125
|
+
// Return chainId from the smart account client
|
|
126
|
+
const chainId = yield smartAccountClient.getChainId();
|
|
127
|
+
return toHex(chainId);
|
|
128
|
+
}
|
|
129
|
+
default: {
|
|
130
|
+
// For other read-only methods, delegate to a basic public client transport.
|
|
131
|
+
// Avoid creating a new client/transport on every call if possible,
|
|
132
|
+
// but for simplicity here, we create it transiently.
|
|
133
|
+
// Consider caching this public client if performance becomes an issue.
|
|
134
|
+
const publicClient = createPublicClient({
|
|
135
|
+
chain: smartAccountClient.chain,
|
|
136
|
+
transport: http(undefined, this.providersConfig.httpTransportConfig), // Use configured transport if available
|
|
137
|
+
});
|
|
138
|
+
return publicClient.request({ method, params });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
// The internal confirmationTransport used by smartAccountClient via its 'owner'
|
|
143
|
+
// should handle the UI prompts. We don't need to add extra prompts here.
|
|
144
|
+
return handleRequest();
|
|
145
|
+
}),
|
|
146
|
+
});
|
|
92
147
|
}
|
|
93
148
|
getTransport(provider) {
|
|
94
149
|
const transport = confirmationTransport({
|
|
@@ -96,7 +151,9 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
96
151
|
onPersonalSign: (_a) => __awaiter(this, [_a], void 0, function* ({ message }) {
|
|
97
152
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
98
153
|
if (!this._isSmartAccountDeployed) {
|
|
99
|
-
yield this.
|
|
154
|
+
yield this.deploySmartAccount({
|
|
155
|
+
withPaymaster: true,
|
|
156
|
+
});
|
|
100
157
|
}
|
|
101
158
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
102
159
|
return provider.signMessage({
|
|
@@ -107,7 +164,9 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
107
164
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
108
165
|
const signTypedData = JSON.parse(message);
|
|
109
166
|
if (!this._isSmartAccountDeployed) {
|
|
110
|
-
yield this.
|
|
167
|
+
yield this.deploySmartAccount({
|
|
168
|
+
withPaymaster: true,
|
|
169
|
+
});
|
|
111
170
|
}
|
|
112
171
|
this._walletUiUtils.disabledConfirmationOnce();
|
|
113
172
|
return provider.signTypedData({
|
|
@@ -146,7 +205,7 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
146
205
|
session: this.sessionKeyAddress,
|
|
147
206
|
},
|
|
148
207
|
owner: ownerWithTransport,
|
|
149
|
-
transport:
|
|
208
|
+
transport: custom(ownerWithTransport),
|
|
150
209
|
});
|
|
151
210
|
return walletClient;
|
|
152
211
|
});
|
|
@@ -169,6 +228,23 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
169
228
|
this.initializedDeferredPromise.resolve();
|
|
170
229
|
});
|
|
171
230
|
}
|
|
231
|
+
createSessionClient(sessionKey, sessionConfig) {
|
|
232
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
233
|
+
if (!this.smartAccountAddress) {
|
|
234
|
+
throw new Error('Smart account address is not initialized');
|
|
235
|
+
}
|
|
236
|
+
return createZksyncSessionClient({
|
|
237
|
+
address: this.smartAccountAddress,
|
|
238
|
+
chain: getOrMapViemChain(this.evmNetworks[0]),
|
|
239
|
+
contracts: {
|
|
240
|
+
session: this.sessionKeyAddress,
|
|
241
|
+
},
|
|
242
|
+
sessionConfig,
|
|
243
|
+
sessionKey,
|
|
244
|
+
transport: http(),
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
172
248
|
/**
|
|
173
249
|
* Creates a passkey client for ZKsync authentication
|
|
174
250
|
*
|
|
@@ -228,7 +304,7 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
228
304
|
}
|
|
229
305
|
deploySmartAccount(_a) {
|
|
230
306
|
return __awaiter(this, arguments, void 0, function* ({ withPaymaster, }) {
|
|
231
|
-
if (withPaymaster) {
|
|
307
|
+
if (withPaymaster && this.paymasterAddress) {
|
|
232
308
|
yield this.deploySmartAccountWithPaymaster();
|
|
233
309
|
}
|
|
234
310
|
else {
|
|
@@ -238,6 +314,9 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
238
314
|
}
|
|
239
315
|
deploySmartAccountWithPaymaster() {
|
|
240
316
|
return __awaiter(this, void 0, void 0, function* () {
|
|
317
|
+
if (!this.paymasterAddress) {
|
|
318
|
+
throw new Error('Paymaster address is not initialized');
|
|
319
|
+
}
|
|
241
320
|
const paymaster = this.paymasterAddress;
|
|
242
321
|
const publicClient = yield this.getTypedPublicClient();
|
|
243
322
|
const walletClient = yield this.getTypedWalletClient();
|
|
@@ -318,10 +397,19 @@ class ZKsyncConnector extends AccountAbstractionConnector {
|
|
|
318
397
|
const salt = `0x${Buffer.from(toBytes('DynamicLabs', { size: 32 })).toString('hex')}`;
|
|
319
398
|
const initialValidators = [];
|
|
320
399
|
const initialK1Owners = [this.eoaAddress];
|
|
321
|
-
|
|
400
|
+
// TODO: revisit this logic, maybe we should always add the passkey module data,
|
|
401
|
+
// otherwise if people active passkeys later, old accounts will not be able to use passkey module
|
|
402
|
+
if (this.enablePasskeys && this.passkeyAddress) {
|
|
322
403
|
const encodedPasskeyModuleData = yield this.getEncodedPasskeyModuleData();
|
|
323
404
|
initialValidators.push(encodedPasskeyModuleData);
|
|
324
405
|
}
|
|
406
|
+
if (this.sessionKeyAddress) {
|
|
407
|
+
const encodedSessionKeyModuleData = encodeModuleData({
|
|
408
|
+
address: this.sessionKeyAddress,
|
|
409
|
+
parameters: '0x',
|
|
410
|
+
});
|
|
411
|
+
initialValidators.push(encodedSessionKeyModuleData);
|
|
412
|
+
}
|
|
325
413
|
return {
|
|
326
414
|
initialK1Owners,
|
|
327
415
|
initialValidators,
|
|
@@ -5,7 +5,7 @@ import { SignAuthorizationReturnType } from 'viem/accounts';
|
|
|
5
5
|
import { type Chain as ViemChain } from 'viem/chains';
|
|
6
6
|
import { EntryPointType, KERNEL_VERSION_TYPE } from '@zerodev/sdk/types';
|
|
7
7
|
import { EthereumWallet, RegisterEvmProvidersConfig } from '@dynamic-labs/ethereum-core';
|
|
8
|
-
import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders } from '@dynamic-labs/sdk-api-core';
|
|
8
|
+
import { EcdsaValidatorOptions, Provider, ProviderEntryPointVersionEnum, ProviderEnum, ProviderKernelVersionEnum, ProviderMultichainAccountAbstractionProviders, SmartWalletProperties } from '@dynamic-labs/sdk-api-core';
|
|
9
9
|
import { Chain, InternalWalletConnector, IZeroDevConnector } from '@dynamic-labs/wallet-connector-core';
|
|
10
10
|
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
11
11
|
import { GenericNetwork, IUITransaction, TransactionReceipt, WalletUiUtils } from '@dynamic-labs/types';
|
|
@@ -84,12 +84,7 @@ export declare class ZeroDevConnector extends AccountAbstractionConnector implem
|
|
|
84
84
|
eoaAddress: string;
|
|
85
85
|
eoaConnector: InternalWalletConnector;
|
|
86
86
|
shouldSetEoaConnector: boolean;
|
|
87
|
-
properties?:
|
|
88
|
-
ecdsaProviderType?: EcdsaValidatorOptions;
|
|
89
|
-
kernelVersion?: ProviderKernelVersionEnum;
|
|
90
|
-
entryPointVersion?: ProviderEntryPointVersionEnum;
|
|
91
|
-
enableKernelV3Migration?: boolean;
|
|
92
|
-
};
|
|
87
|
+
properties?: SmartWalletProperties;
|
|
93
88
|
}): Promise<void>;
|
|
94
89
|
registerEoa({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, ...properties }: {
|
|
95
90
|
smartWalletAddress: string;
|
package/src/ZKsync/client.cjs
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
-
var viem = require('viem');
|
|
8
|
-
var zksync = require('viem/zksync');
|
|
9
|
-
var ecdsaAccount = require('./ecdsaAccount.cjs');
|
|
10
|
-
var walletActions = require('./walletActions.cjs');
|
|
11
|
-
|
|
12
|
-
const createZksyncEcdsaClient = (_parameters) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
const parameters = Object.assign(Object.assign({}, _parameters), { address: viem.getAddress(_parameters.address), key: _parameters.key || 'zksync-sso-ecdsa-wallet', name: _parameters.name || 'ZKsync SSO ECDSA Client' });
|
|
14
|
-
const account = yield ecdsaAccount.toEcdsaAccount({
|
|
15
|
-
address: parameters.address,
|
|
16
|
-
owner: parameters.owner,
|
|
17
|
-
});
|
|
18
|
-
const client = viem.createClient(Object.assign(Object.assign({}, parameters), { account, type: 'walletClient' }))
|
|
19
|
-
.extend(() => ({
|
|
20
|
-
contracts: parameters.contracts,
|
|
21
|
-
}))
|
|
22
|
-
.extend(viem.publicActions)
|
|
23
|
-
.extend(viem.walletActions)
|
|
24
|
-
.extend(zksync.eip712WalletActions())
|
|
25
|
-
.extend(walletActions.zksyncSsoEcdsaWalletActions);
|
|
26
|
-
return client;
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
exports.createZksyncEcdsaClient = createZksyncEcdsaClient;
|
package/src/ZKsync/client.d.ts
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { type Account, type Address, type Chain, type Client, type Prettify, type PublicActions, type PublicRpcSchema, type RpcSchema, type Transport, type WalletActions, type WalletClientConfig, type WalletRpcSchema } from 'viem';
|
|
2
|
-
import { CustomPaymasterHandler } from 'zksync-sso/paymaster';
|
|
3
|
-
import { Signer } from './types';
|
|
4
|
-
export declare const createZksyncEcdsaClient: <transport extends Transport, chain extends Chain, rpcSchema extends RpcSchema | undefined = undefined>(_parameters: ZksyncSsoEcdsaClientConfig<transport, chain, rpcSchema>) => Promise<ZksyncSsoEcdsaClient<transport, chain, rpcSchema>>;
|
|
5
|
-
export type EcdsaRequiredContracts = {
|
|
6
|
-
session: Address;
|
|
7
|
-
accountFactory?: Address;
|
|
8
|
-
};
|
|
9
|
-
type ZksyncSsoEcdsaData = {
|
|
10
|
-
contracts: EcdsaRequiredContracts;
|
|
11
|
-
paymasterHandler?: CustomPaymasterHandler;
|
|
12
|
-
};
|
|
13
|
-
export type ClientWithZksyncSsoEcdsaData<transport extends Transport = Transport, chain extends Chain = Chain> = Client<transport, chain, Account> & ZksyncSsoEcdsaData;
|
|
14
|
-
export type ZksyncSsoEcdsaClient<transport extends Transport = Transport, chain extends Chain = Chain, rpcSchema extends RpcSchema | undefined = undefined, account extends Account = Account> = Prettify<Client<transport, chain, account, rpcSchema extends RpcSchema ? [...PublicRpcSchema, ...WalletRpcSchema, ...rpcSchema] : [...PublicRpcSchema, ...WalletRpcSchema], PublicActions<transport, chain, account> & WalletActions<chain, account>> & ZksyncSsoEcdsaData>;
|
|
15
|
-
export interface ZksyncSsoEcdsaClientConfig<transport extends Transport = Transport, chain extends Chain = Chain, rpcSchema extends RpcSchema | undefined = undefined> extends Omit<WalletClientConfig<transport, chain, Account, rpcSchema>, 'account'> {
|
|
16
|
-
chain: NonNullable<chain>;
|
|
17
|
-
address: Address;
|
|
18
|
-
owner: Signer;
|
|
19
|
-
contracts: EcdsaRequiredContracts;
|
|
20
|
-
key?: string;
|
|
21
|
-
name?: string;
|
|
22
|
-
paymasterHandler?: CustomPaymasterHandler;
|
|
23
|
-
}
|
|
24
|
-
export {};
|
package/src/ZKsync/client.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
-
import { getAddress, createClient, publicActions, walletActions } from 'viem';
|
|
4
|
-
import { eip712WalletActions } from 'viem/zksync';
|
|
5
|
-
import { toEcdsaAccount } from './ecdsaAccount.js';
|
|
6
|
-
import { zksyncSsoEcdsaWalletActions } from './walletActions.js';
|
|
7
|
-
|
|
8
|
-
const createZksyncEcdsaClient = (_parameters) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
-
const parameters = Object.assign(Object.assign({}, _parameters), { address: getAddress(_parameters.address), key: _parameters.key || 'zksync-sso-ecdsa-wallet', name: _parameters.name || 'ZKsync SSO ECDSA Client' });
|
|
10
|
-
const account = yield toEcdsaAccount({
|
|
11
|
-
address: parameters.address,
|
|
12
|
-
owner: parameters.owner,
|
|
13
|
-
});
|
|
14
|
-
const client = createClient(Object.assign(Object.assign({}, parameters), { account, type: 'walletClient' }))
|
|
15
|
-
.extend(() => ({
|
|
16
|
-
contracts: parameters.contracts,
|
|
17
|
-
}))
|
|
18
|
-
.extend(publicActions)
|
|
19
|
-
.extend(walletActions)
|
|
20
|
-
.extend(eip712WalletActions())
|
|
21
|
-
.extend(zksyncSsoEcdsaWalletActions);
|
|
22
|
-
return client;
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
export { createZksyncEcdsaClient };
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
-
var accounts = require('viem/accounts');
|
|
8
|
-
var zksync = require('viem/zksync');
|
|
9
|
-
var types = require('./types.cjs');
|
|
10
|
-
var getEip712Domain = require('./getEip712Domain.cjs');
|
|
11
|
-
|
|
12
|
-
const toEcdsaAccount = (parameters) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
-
const { address, owner } = parameters;
|
|
14
|
-
const localOwner = yield types.toOwner({ address, owner });
|
|
15
|
-
if (!address) {
|
|
16
|
-
throw new Error('Address is required');
|
|
17
|
-
}
|
|
18
|
-
const account = accounts.toAccount({
|
|
19
|
-
address,
|
|
20
|
-
signMessage: (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ message }) { return localOwner.signMessage({ message }); }),
|
|
21
|
-
signTransaction: (transaction) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
22
|
-
const signableTransaction = Object.assign(Object.assign({}, transaction), { from: address, type: 'eip712' });
|
|
23
|
-
const eip712DomainAndMessage = getEip712Domain.getEip712Domain(signableTransaction);
|
|
24
|
-
const signature = yield localOwner.signTypedData(eip712DomainAndMessage);
|
|
25
|
-
return zksync.serializeTransaction(Object.assign(Object.assign({}, signableTransaction), { customSignature: signature }));
|
|
26
|
-
}),
|
|
27
|
-
signTypedData: (typedData) => localOwner.signTypedData(typedData),
|
|
28
|
-
});
|
|
29
|
-
return Object.assign(Object.assign({}, account), { source: 'ssoEcdsaAccount' });
|
|
30
|
-
});
|
|
31
|
-
|
|
32
|
-
exports.toEcdsaAccount = toEcdsaAccount;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import type { Address } from 'abitype';
|
|
2
|
-
import { type CustomSource, type LocalAccount } from 'viem';
|
|
3
|
-
import { type Signer } from './types';
|
|
4
|
-
export type ToEcdsaAccountParameters = {
|
|
5
|
-
/** Address of the deployed SSO Wallet */
|
|
6
|
-
address: Address;
|
|
7
|
-
/** Owner of the EOA */
|
|
8
|
-
owner: Signer;
|
|
9
|
-
};
|
|
10
|
-
export type EcdsaAccount = LocalAccount<'ssoEcdsaAccount'> & {
|
|
11
|
-
sign: NonNullable<CustomSource['sign']>;
|
|
12
|
-
};
|
|
13
|
-
export declare const toEcdsaAccount: (parameters: ToEcdsaAccountParameters) => Promise<EcdsaAccount>;
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
-
import { toAccount } from 'viem/accounts';
|
|
4
|
-
import { serializeTransaction } from 'viem/zksync';
|
|
5
|
-
import { toOwner } from './types.js';
|
|
6
|
-
import { getEip712Domain } from './getEip712Domain.js';
|
|
7
|
-
|
|
8
|
-
const toEcdsaAccount = (parameters) => __awaiter(void 0, void 0, void 0, function* () {
|
|
9
|
-
const { address, owner } = parameters;
|
|
10
|
-
const localOwner = yield toOwner({ address, owner });
|
|
11
|
-
if (!address) {
|
|
12
|
-
throw new Error('Address is required');
|
|
13
|
-
}
|
|
14
|
-
const account = toAccount({
|
|
15
|
-
address,
|
|
16
|
-
signMessage: (_a) => __awaiter(void 0, [_a], void 0, function* ({ message }) { return localOwner.signMessage({ message }); }),
|
|
17
|
-
signTransaction: (transaction) => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
const signableTransaction = Object.assign(Object.assign({}, transaction), { from: address, type: 'eip712' });
|
|
19
|
-
const eip712DomainAndMessage = getEip712Domain(signableTransaction);
|
|
20
|
-
const signature = yield localOwner.signTypedData(eip712DomainAndMessage);
|
|
21
|
-
return serializeTransaction(Object.assign(Object.assign({}, signableTransaction), { customSignature: signature }));
|
|
22
|
-
}),
|
|
23
|
-
signTypedData: (typedData) => localOwner.signTypedData(typedData),
|
|
24
|
-
});
|
|
25
|
-
return Object.assign(Object.assign({}, account), { source: 'ssoEcdsaAccount' });
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
export { toEcdsaAccount };
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var viem = require('viem');
|
|
7
|
-
var zksync = require('viem/zksync');
|
|
8
|
-
|
|
9
|
-
const gasPerPubdataDefault = BigInt(50000);
|
|
10
|
-
const getEip712Domain = (transaction) => {
|
|
11
|
-
const message = transactionToMessage(transaction);
|
|
12
|
-
return {
|
|
13
|
-
domain: {
|
|
14
|
-
chainId: transaction.chainId,
|
|
15
|
-
// cspell:ignore zkSync
|
|
16
|
-
name: 'zkSync',
|
|
17
|
-
version: '2',
|
|
18
|
-
},
|
|
19
|
-
message: message,
|
|
20
|
-
primaryType: 'Transaction',
|
|
21
|
-
types: {
|
|
22
|
-
Transaction: [
|
|
23
|
-
{ name: 'txType', type: 'uint256' },
|
|
24
|
-
{ name: 'from', type: 'uint256' },
|
|
25
|
-
{ name: 'to', type: 'uint256' },
|
|
26
|
-
{ name: 'gasLimit', type: 'uint256' },
|
|
27
|
-
{ name: 'gasPerPubdataByteLimit', type: 'uint256' },
|
|
28
|
-
{ name: 'maxFeePerGas', type: 'uint256' },
|
|
29
|
-
{ name: 'maxPriorityFeePerGas', type: 'uint256' },
|
|
30
|
-
{ name: 'paymaster', type: 'uint256' },
|
|
31
|
-
{ name: 'nonce', type: 'uint256' },
|
|
32
|
-
{ name: 'value', type: 'uint256' },
|
|
33
|
-
{ name: 'data', type: 'bytes' },
|
|
34
|
-
{ name: 'factoryDeps', type: 'bytes32[]' },
|
|
35
|
-
{ name: 'paymasterInput', type: 'bytes' },
|
|
36
|
-
],
|
|
37
|
-
},
|
|
38
|
-
};
|
|
39
|
-
};
|
|
40
|
-
//////////////////////////////////////////////////////////////////////////////
|
|
41
|
-
// Utilities
|
|
42
|
-
const transactionToMessage = (transaction) => {
|
|
43
|
-
var _a;
|
|
44
|
-
const { gas, nonce, to, from, value, maxFeePerGas, maxPriorityFeePerGas, factoryDeps, paymaster, paymasterInput, gasPerPubdata, data, } = transaction;
|
|
45
|
-
return {
|
|
46
|
-
data: data ? data : '0x0',
|
|
47
|
-
factoryDeps: (_a = factoryDeps === null || factoryDeps === void 0 ? void 0 : factoryDeps.map((dep) => viem.toHex(zksync.hashBytecode(dep)))) !== null && _a !== void 0 ? _a : [],
|
|
48
|
-
from: BigInt(from),
|
|
49
|
-
gasLimit: gas !== null && gas !== void 0 ? gas : BigInt(0),
|
|
50
|
-
gasPerPubdataByteLimit: gasPerPubdata !== null && gasPerPubdata !== void 0 ? gasPerPubdata : gasPerPubdataDefault,
|
|
51
|
-
maxFeePerGas: maxFeePerGas !== null && maxFeePerGas !== void 0 ? maxFeePerGas : BigInt(0),
|
|
52
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas !== null && maxPriorityFeePerGas !== void 0 ? maxPriorityFeePerGas : BigInt(0),
|
|
53
|
-
nonce: nonce ? BigInt(nonce) : BigInt(0),
|
|
54
|
-
paymaster: paymaster ? BigInt(paymaster) : BigInt(0),
|
|
55
|
-
paymasterInput: paymasterInput ? paymasterInput : '0x',
|
|
56
|
-
to: to ? BigInt(to) : BigInt(0),
|
|
57
|
-
txType: BigInt(113),
|
|
58
|
-
value: value !== null && value !== void 0 ? value : BigInt(0),
|
|
59
|
-
};
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
exports.getEip712Domain = getEip712Domain;
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { toHex } from 'viem';
|
|
3
|
-
import { hashBytecode } from 'viem/zksync';
|
|
4
|
-
|
|
5
|
-
const gasPerPubdataDefault = BigInt(50000);
|
|
6
|
-
const getEip712Domain = (transaction) => {
|
|
7
|
-
const message = transactionToMessage(transaction);
|
|
8
|
-
return {
|
|
9
|
-
domain: {
|
|
10
|
-
chainId: transaction.chainId,
|
|
11
|
-
// cspell:ignore zkSync
|
|
12
|
-
name: 'zkSync',
|
|
13
|
-
version: '2',
|
|
14
|
-
},
|
|
15
|
-
message: message,
|
|
16
|
-
primaryType: 'Transaction',
|
|
17
|
-
types: {
|
|
18
|
-
Transaction: [
|
|
19
|
-
{ name: 'txType', type: 'uint256' },
|
|
20
|
-
{ name: 'from', type: 'uint256' },
|
|
21
|
-
{ name: 'to', type: 'uint256' },
|
|
22
|
-
{ name: 'gasLimit', type: 'uint256' },
|
|
23
|
-
{ name: 'gasPerPubdataByteLimit', type: 'uint256' },
|
|
24
|
-
{ name: 'maxFeePerGas', type: 'uint256' },
|
|
25
|
-
{ name: 'maxPriorityFeePerGas', type: 'uint256' },
|
|
26
|
-
{ name: 'paymaster', type: 'uint256' },
|
|
27
|
-
{ name: 'nonce', type: 'uint256' },
|
|
28
|
-
{ name: 'value', type: 'uint256' },
|
|
29
|
-
{ name: 'data', type: 'bytes' },
|
|
30
|
-
{ name: 'factoryDeps', type: 'bytes32[]' },
|
|
31
|
-
{ name: 'paymasterInput', type: 'bytes' },
|
|
32
|
-
],
|
|
33
|
-
},
|
|
34
|
-
};
|
|
35
|
-
};
|
|
36
|
-
//////////////////////////////////////////////////////////////////////////////
|
|
37
|
-
// Utilities
|
|
38
|
-
const transactionToMessage = (transaction) => {
|
|
39
|
-
var _a;
|
|
40
|
-
const { gas, nonce, to, from, value, maxFeePerGas, maxPriorityFeePerGas, factoryDeps, paymaster, paymasterInput, gasPerPubdata, data, } = transaction;
|
|
41
|
-
return {
|
|
42
|
-
data: data ? data : '0x0',
|
|
43
|
-
factoryDeps: (_a = factoryDeps === null || factoryDeps === void 0 ? void 0 : factoryDeps.map((dep) => toHex(hashBytecode(dep)))) !== null && _a !== void 0 ? _a : [],
|
|
44
|
-
from: BigInt(from),
|
|
45
|
-
gasLimit: gas !== null && gas !== void 0 ? gas : BigInt(0),
|
|
46
|
-
gasPerPubdataByteLimit: gasPerPubdata !== null && gasPerPubdata !== void 0 ? gasPerPubdata : gasPerPubdataDefault,
|
|
47
|
-
maxFeePerGas: maxFeePerGas !== null && maxFeePerGas !== void 0 ? maxFeePerGas : BigInt(0),
|
|
48
|
-
maxPriorityFeePerGas: maxPriorityFeePerGas !== null && maxPriorityFeePerGas !== void 0 ? maxPriorityFeePerGas : BigInt(0),
|
|
49
|
-
nonce: nonce ? BigInt(nonce) : BigInt(0),
|
|
50
|
-
paymaster: paymaster ? BigInt(paymaster) : BigInt(0),
|
|
51
|
-
paymasterInput: paymasterInput ? paymasterInput : '0x',
|
|
52
|
-
to: to ? BigInt(to) : BigInt(0),
|
|
53
|
-
txType: BigInt(113),
|
|
54
|
-
value: value !== null && value !== void 0 ? value : BigInt(0),
|
|
55
|
-
};
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
export { getEip712Domain };
|
package/src/ZKsync/types.cjs
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
-
var viem = require('viem');
|
|
8
|
-
var accounts = require('viem/accounts');
|
|
9
|
-
var actions = require('viem/actions');
|
|
10
|
-
var utils = require('viem/utils');
|
|
11
|
-
|
|
12
|
-
const toOwner = (_a) => _tslib.__awaiter(void 0, [_a], void 0, function* ({ owner, address, }) {
|
|
13
|
-
if ('type' in owner && owner.type === 'local') {
|
|
14
|
-
return owner;
|
|
15
|
-
}
|
|
16
|
-
let walletClient = undefined;
|
|
17
|
-
if ('request' in owner) {
|
|
18
|
-
if (!address) {
|
|
19
|
-
try {
|
|
20
|
-
[address] = yield owner.request({
|
|
21
|
-
method: 'eth_requestAccounts',
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
catch (_b) {
|
|
25
|
-
[address] = yield owner.request({
|
|
26
|
-
method: 'eth_accounts',
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (!address) {
|
|
31
|
-
// For TS to be happy
|
|
32
|
-
throw new Error('address is required');
|
|
33
|
-
}
|
|
34
|
-
walletClient = viem.createWalletClient({
|
|
35
|
-
account: address,
|
|
36
|
-
transport: viem.custom(owner),
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
if (!walletClient) {
|
|
40
|
-
walletClient = owner;
|
|
41
|
-
}
|
|
42
|
-
return accounts.toAccount({
|
|
43
|
-
address: walletClient.account.address,
|
|
44
|
-
signMessage: (_c) => _tslib.__awaiter(void 0, [_c], void 0, function* ({ message }) { return walletClient.signMessage({ message }); }),
|
|
45
|
-
signTransaction: () => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
46
|
-
throw new Error("Smart account signer doesn't need to sign transactions");
|
|
47
|
-
}),
|
|
48
|
-
signTypedData: (typedData) => _tslib.__awaiter(void 0, void 0, void 0, function* () { return utils.getAction(walletClient, actions.signTypedData, 'signTypedData')(typedData); }),
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
exports.toOwner = toOwner;
|
package/src/ZKsync/types.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Account, type Address, type Chain, type EIP1193Provider, type LocalAccount, type OneOf, type Transport, type WalletClient } from 'viem';
|
|
2
|
-
export type Signer = OneOf<EIP1193Provider | WalletClient<Transport, Chain | undefined, Account> | LocalAccount>;
|
|
3
|
-
export type EthereumProvider = OneOf<{
|
|
4
|
-
request(...args: any): Promise<any>;
|
|
5
|
-
} | EIP1193Provider>;
|
|
6
|
-
export declare const toOwner: <provider extends EthereumProvider>({ owner, address, }: {
|
|
7
|
-
owner: OneOf<provider | WalletClient<Transport, Chain | undefined, Account> | LocalAccount>;
|
|
8
|
-
address: Address;
|
|
9
|
-
}) => Promise<LocalAccount>;
|
package/src/ZKsync/types.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { __awaiter } from '../../_virtual/_tslib.js';
|
|
3
|
-
import { createWalletClient, custom } from 'viem';
|
|
4
|
-
import { toAccount } from 'viem/accounts';
|
|
5
|
-
import { signTypedData } from 'viem/actions';
|
|
6
|
-
import { getAction } from 'viem/utils';
|
|
7
|
-
|
|
8
|
-
const toOwner = (_a) => __awaiter(void 0, [_a], void 0, function* ({ owner, address, }) {
|
|
9
|
-
if ('type' in owner && owner.type === 'local') {
|
|
10
|
-
return owner;
|
|
11
|
-
}
|
|
12
|
-
let walletClient = undefined;
|
|
13
|
-
if ('request' in owner) {
|
|
14
|
-
if (!address) {
|
|
15
|
-
try {
|
|
16
|
-
[address] = yield owner.request({
|
|
17
|
-
method: 'eth_requestAccounts',
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
catch (_b) {
|
|
21
|
-
[address] = yield owner.request({
|
|
22
|
-
method: 'eth_accounts',
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (!address) {
|
|
27
|
-
// For TS to be happy
|
|
28
|
-
throw new Error('address is required');
|
|
29
|
-
}
|
|
30
|
-
walletClient = createWalletClient({
|
|
31
|
-
account: address,
|
|
32
|
-
transport: custom(owner),
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
if (!walletClient) {
|
|
36
|
-
walletClient = owner;
|
|
37
|
-
}
|
|
38
|
-
return toAccount({
|
|
39
|
-
address: walletClient.account.address,
|
|
40
|
-
signMessage: (_c) => __awaiter(void 0, [_c], void 0, function* ({ message }) { return walletClient.signMessage({ message }); }),
|
|
41
|
-
signTransaction: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
throw new Error("Smart account signer doesn't need to sign transactions");
|
|
43
|
-
}),
|
|
44
|
-
signTypedData: (typedData) => __awaiter(void 0, void 0, void 0, function* () { return getAction(walletClient, signTypedData, 'signTypedData')(typedData); }),
|
|
45
|
-
});
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
export { toOwner };
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
'use strict';
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
5
|
-
|
|
6
|
-
var _tslib = require('../../_virtual/_tslib.cjs');
|
|
7
|
-
var viem = require('viem');
|
|
8
|
-
var actions = require('viem/actions');
|
|
9
|
-
var zksync = require('viem/zksync');
|
|
10
|
-
var paymaster = require('zksync-sso/paymaster');
|
|
11
|
-
|
|
12
|
-
const zksyncSsoEcdsaWalletActions = (client) => ({
|
|
13
|
-
deployContract: (args) => actions.deployContract(client, args),
|
|
14
|
-
getAddresses: () => actions.getAddresses(client),
|
|
15
|
-
getChainId: () => actions.getChainId(client),
|
|
16
|
-
sendRawTransaction: (args) => actions.sendRawTransaction(client, args),
|
|
17
|
-
sendTransaction: (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
var _a, _b, _c, _d, _e;
|
|
19
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
20
|
-
const unformattedTx = Object.assign({}, args);
|
|
21
|
-
if ('eip712Meta' in unformattedTx) {
|
|
22
|
-
const eip712Meta = unformattedTx.eip712Meta;
|
|
23
|
-
unformattedTx.gasPerPubdata = eip712Meta.gasPerPubdata
|
|
24
|
-
? BigInt(eip712Meta.gasPerPubdata)
|
|
25
|
-
: undefined;
|
|
26
|
-
unformattedTx.factoryDeps = eip712Meta.factoryDeps;
|
|
27
|
-
unformattedTx.customSignature = eip712Meta.customSignature;
|
|
28
|
-
unformattedTx.paymaster = (_a = eip712Meta.paymasterParams) === null || _a === void 0 ? void 0 : _a.paymaster;
|
|
29
|
-
unformattedTx.paymasterInput = ((_b = eip712Meta.paymasterParams) === null || _b === void 0 ? void 0 : _b.paymasterInput)
|
|
30
|
-
? viem.bytesToHex(new Uint8Array((_c = eip712Meta.paymasterParams) === null || _c === void 0 ? void 0 : _c.paymasterInput))
|
|
31
|
-
: undefined;
|
|
32
|
-
delete unformattedTx.eip712Meta;
|
|
33
|
-
}
|
|
34
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
35
|
-
const _f = yield paymaster.getTransactionWithPaymasterData(client.chain.id, client.account.address, unformattedTx, client.paymasterHandler), unformattedTxWithPaymaster = _tslib.__rest(_f, ["chainId"]);
|
|
36
|
-
const formatters = (_d = client.chain) === null || _d === void 0 ? void 0 : _d.formatters;
|
|
37
|
-
const format = ((_e = formatters === null || formatters === void 0 ? void 0 : formatters.transaction) === null || _e === void 0 ? void 0 : _e.format) || viem.formatTransaction;
|
|
38
|
-
const tx = Object.assign(Object.assign({}, format(unformattedTxWithPaymaster)), { type: 'eip712' });
|
|
39
|
-
return yield sendEip712Transaction(client, tx);
|
|
40
|
-
}),
|
|
41
|
-
signMessage: (args) => actions.signMessage(client, args),
|
|
42
|
-
signTransaction: (args) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
44
|
-
const _g = yield paymaster.getTransactionWithPaymasterData(client.chain.id, client.account.address, args, client.paymasterHandler), unformattedTxWithPaymaster = _tslib.__rest(_g, ["chainId"]);
|
|
45
|
-
return zksync.signTransaction(client, Object.assign(Object.assign({}, args), { type: 'eip712', unformattedTxWithPaymaster }));
|
|
46
|
-
}),
|
|
47
|
-
signTypedData: (args) => actions.signTypedData(client, args),
|
|
48
|
-
writeContract: (args) => actions.writeContract(client, args),
|
|
49
|
-
});
|
|
50
|
-
const sendEip712Transaction = (client, parameters) => _tslib.__awaiter(void 0, void 0, void 0, function* () {
|
|
51
|
-
var _h;
|
|
52
|
-
const { account: account_ = client.account, chain = client.chain } = parameters, rest = _tslib.__rest(parameters, ["account", "chain"]);
|
|
53
|
-
if (!account_)
|
|
54
|
-
throw new Error('Account not found.');
|
|
55
|
-
const { account } = client;
|
|
56
|
-
if (!account)
|
|
57
|
-
throw new Error('Account not found.');
|
|
58
|
-
const request = yield getAction(client, actions.prepareTransactionRequest, 'prepareTransactionRequest')(Object.assign({ account,
|
|
59
|
-
chain, nonceManager: account.nonceManager }, rest));
|
|
60
|
-
const serializer = (_h = chain === null || chain === void 0 ? void 0 : chain.serializers) === null || _h === void 0 ? void 0 : _h.transaction;
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
62
|
-
const serializedTransaction = (yield account.signTransaction(request, {
|
|
63
|
-
serializer,
|
|
64
|
-
}));
|
|
65
|
-
return yield getAction(client, actions.sendRawTransaction, 'sendRawTransaction')({
|
|
66
|
-
serializedTransaction,
|
|
67
|
-
});
|
|
68
|
-
});
|
|
69
|
-
/**
|
|
70
|
-
* Retrieves and returns an action from the client (if exists), and falls
|
|
71
|
-
* back to the tree-shakable action.
|
|
72
|
-
*
|
|
73
|
-
* Useful for extracting overridden actions from a client (ie. if a consumer
|
|
74
|
-
* wants to override the `sendTransaction` implementation).
|
|
75
|
-
*/
|
|
76
|
-
const getAction = (client, actionFn,
|
|
77
|
-
// cspell:ignore minifiers
|
|
78
|
-
// Some minifiers drop `Function.prototype.name`, or replace it with short letters,
|
|
79
|
-
// meaning that `actionFn.name` will not always work. For that case, the consumer
|
|
80
|
-
// needs to pass the name explicitly.
|
|
81
|
-
name) => {
|
|
82
|
-
const action_implicit = client[actionFn.name];
|
|
83
|
-
if (typeof action_implicit === 'function')
|
|
84
|
-
return action_implicit;
|
|
85
|
-
const action_explicit = client[name];
|
|
86
|
-
if (typeof action_explicit === 'function')
|
|
87
|
-
return action_explicit;
|
|
88
|
-
return (params) => actionFn(client, params);
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
exports.getAction = getAction;
|
|
92
|
-
exports.sendEip712Transaction = sendEip712Transaction;
|
|
93
|
-
exports.zksyncSsoEcdsaWalletActions = zksyncSsoEcdsaWalletActions;
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type Account, type Chain, type Client, type PublicActions, type RpcSchema, type SendTransactionRequest, type Transport, type WalletActions } from 'viem';
|
|
2
|
-
import { type ChainEIP712, type SendEip712TransactionParameters, type SendEip712TransactionReturnType } from 'viem/zksync';
|
|
3
|
-
export type ZksyncSsoEcdsaWalletActions<chain extends Chain, account extends Account> = Omit<WalletActions<chain, account>, 'addChain' | 'getPermissions' | 'requestAddresses' | 'requestPermissions' | 'switchChain' | 'watchAsset' | 'prepareTransactionRequest'>;
|
|
4
|
-
export declare const zksyncSsoEcdsaWalletActions: <transport extends Transport, chain extends Chain, account extends Account>(client: Client<transport, chain, account>) => any;
|
|
5
|
-
export declare const sendEip712Transaction: <chain extends ChainEIP712 | undefined, account extends Account | undefined, request extends SendTransactionRequest<chain, chainOverride>, chainOverride extends ChainEIP712 | undefined = undefined>(client: Client<Transport, chain, account>, parameters: SendEip712TransactionParameters<chain, account, chainOverride, request>) => Promise<SendEip712TransactionReturnType>;
|
|
6
|
-
/**
|
|
7
|
-
* Retrieves and returns an action from the client (if exists), and falls
|
|
8
|
-
* back to the tree-shakable action.
|
|
9
|
-
*
|
|
10
|
-
* Useful for extracting overridden actions from a client (ie. if a consumer
|
|
11
|
-
* wants to override the `sendTransaction` implementation).
|
|
12
|
-
*/
|
|
13
|
-
export declare const getAction: <transport extends Transport, chain extends Chain | undefined, account extends Account | undefined, rpcSchema extends RpcSchema | undefined, extended extends {
|
|
14
|
-
[key: string]: unknown;
|
|
15
|
-
}, client extends Client<transport, chain, account, rpcSchema, extended>, parameters, returnType>(client: client, actionFn: (_: any, parameters: parameters) => returnType, name: keyof PublicActions | keyof WalletActions | string) => ((parameters: parameters) => returnType);
|
|
@@ -1,87 +0,0 @@
|
|
|
1
|
-
'use client'
|
|
2
|
-
import { __awaiter, __rest } from '../../_virtual/_tslib.js';
|
|
3
|
-
import { bytesToHex, formatTransaction } from 'viem';
|
|
4
|
-
import { deployContract, getAddresses, getChainId, sendRawTransaction, signMessage, signTypedData, writeContract, prepareTransactionRequest } from 'viem/actions';
|
|
5
|
-
import { signTransaction } from 'viem/zksync';
|
|
6
|
-
import { getTransactionWithPaymasterData } from 'zksync-sso/paymaster';
|
|
7
|
-
|
|
8
|
-
const zksyncSsoEcdsaWalletActions = (client) => ({
|
|
9
|
-
deployContract: (args) => deployContract(client, args),
|
|
10
|
-
getAddresses: () => getAddresses(client),
|
|
11
|
-
getChainId: () => getChainId(client),
|
|
12
|
-
sendRawTransaction: (args) => sendRawTransaction(client, args),
|
|
13
|
-
sendTransaction: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
14
|
-
var _a, _b, _c, _d, _e;
|
|
15
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
16
|
-
const unformattedTx = Object.assign({}, args);
|
|
17
|
-
if ('eip712Meta' in unformattedTx) {
|
|
18
|
-
const eip712Meta = unformattedTx.eip712Meta;
|
|
19
|
-
unformattedTx.gasPerPubdata = eip712Meta.gasPerPubdata
|
|
20
|
-
? BigInt(eip712Meta.gasPerPubdata)
|
|
21
|
-
: undefined;
|
|
22
|
-
unformattedTx.factoryDeps = eip712Meta.factoryDeps;
|
|
23
|
-
unformattedTx.customSignature = eip712Meta.customSignature;
|
|
24
|
-
unformattedTx.paymaster = (_a = eip712Meta.paymasterParams) === null || _a === void 0 ? void 0 : _a.paymaster;
|
|
25
|
-
unformattedTx.paymasterInput = ((_b = eip712Meta.paymasterParams) === null || _b === void 0 ? void 0 : _b.paymasterInput)
|
|
26
|
-
? bytesToHex(new Uint8Array((_c = eip712Meta.paymasterParams) === null || _c === void 0 ? void 0 : _c.paymasterInput))
|
|
27
|
-
: undefined;
|
|
28
|
-
delete unformattedTx.eip712Meta;
|
|
29
|
-
}
|
|
30
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
31
|
-
const _f = yield getTransactionWithPaymasterData(client.chain.id, client.account.address, unformattedTx, client.paymasterHandler), unformattedTxWithPaymaster = __rest(_f, ["chainId"]);
|
|
32
|
-
const formatters = (_d = client.chain) === null || _d === void 0 ? void 0 : _d.formatters;
|
|
33
|
-
const format = ((_e = formatters === null || formatters === void 0 ? void 0 : formatters.transaction) === null || _e === void 0 ? void 0 : _e.format) || formatTransaction;
|
|
34
|
-
const tx = Object.assign(Object.assign({}, format(unformattedTxWithPaymaster)), { type: 'eip712' });
|
|
35
|
-
return yield sendEip712Transaction(client, tx);
|
|
36
|
-
}),
|
|
37
|
-
signMessage: (args) => signMessage(client, args),
|
|
38
|
-
signTransaction: (args) => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
40
|
-
const _g = yield getTransactionWithPaymasterData(client.chain.id, client.account.address, args, client.paymasterHandler), unformattedTxWithPaymaster = __rest(_g, ["chainId"]);
|
|
41
|
-
return signTransaction(client, Object.assign(Object.assign({}, args), { type: 'eip712', unformattedTxWithPaymaster }));
|
|
42
|
-
}),
|
|
43
|
-
signTypedData: (args) => signTypedData(client, args),
|
|
44
|
-
writeContract: (args) => writeContract(client, args),
|
|
45
|
-
});
|
|
46
|
-
const sendEip712Transaction = (client, parameters) => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
-
var _h;
|
|
48
|
-
const { account: account_ = client.account, chain = client.chain } = parameters, rest = __rest(parameters, ["account", "chain"]);
|
|
49
|
-
if (!account_)
|
|
50
|
-
throw new Error('Account not found.');
|
|
51
|
-
const { account } = client;
|
|
52
|
-
if (!account)
|
|
53
|
-
throw new Error('Account not found.');
|
|
54
|
-
const request = yield getAction(client, prepareTransactionRequest, 'prepareTransactionRequest')(Object.assign({ account,
|
|
55
|
-
chain, nonceManager: account.nonceManager }, rest));
|
|
56
|
-
const serializer = (_h = chain === null || chain === void 0 ? void 0 : chain.serializers) === null || _h === void 0 ? void 0 : _h.transaction;
|
|
57
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
58
|
-
const serializedTransaction = (yield account.signTransaction(request, {
|
|
59
|
-
serializer,
|
|
60
|
-
}));
|
|
61
|
-
return yield getAction(client, sendRawTransaction, 'sendRawTransaction')({
|
|
62
|
-
serializedTransaction,
|
|
63
|
-
});
|
|
64
|
-
});
|
|
65
|
-
/**
|
|
66
|
-
* Retrieves and returns an action from the client (if exists), and falls
|
|
67
|
-
* back to the tree-shakable action.
|
|
68
|
-
*
|
|
69
|
-
* Useful for extracting overridden actions from a client (ie. if a consumer
|
|
70
|
-
* wants to override the `sendTransaction` implementation).
|
|
71
|
-
*/
|
|
72
|
-
const getAction = (client, actionFn,
|
|
73
|
-
// cspell:ignore minifiers
|
|
74
|
-
// Some minifiers drop `Function.prototype.name`, or replace it with short letters,
|
|
75
|
-
// meaning that `actionFn.name` will not always work. For that case, the consumer
|
|
76
|
-
// needs to pass the name explicitly.
|
|
77
|
-
name) => {
|
|
78
|
-
const action_implicit = client[actionFn.name];
|
|
79
|
-
if (typeof action_implicit === 'function')
|
|
80
|
-
return action_implicit;
|
|
81
|
-
const action_explicit = client[name];
|
|
82
|
-
if (typeof action_explicit === 'function')
|
|
83
|
-
return action_explicit;
|
|
84
|
-
return (params) => actionFn(client, params);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
export { getAction, sendEip712Transaction, zksyncSsoEcdsaWalletActions };
|