@dynamic-labs/ethereum-aa 4.9.11 → 4.9.13-preview.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +17 -0
- package/package.cjs +1 -1
- package/package.js +1 -1
- package/package.json +11 -9
- package/src/AccountAbstractionConnector.cjs +75 -0
- package/src/AccountAbstractionConnector.d.ts +56 -0
- package/src/AccountAbstractionConnector.js +71 -0
- package/src/ZKsync/client.cjs +29 -0
- package/src/ZKsync/client.d.ts +24 -0
- package/src/ZKsync/client.js +25 -0
- package/src/ZKsync/ecdsaAccount.cjs +32 -0
- package/src/ZKsync/ecdsaAccount.d.ts +13 -0
- package/src/ZKsync/ecdsaAccount.js +28 -0
- package/src/ZKsync/getEip712Domain.cjs +62 -0
- package/src/ZKsync/getEip712Domain.d.ts +2 -0
- package/src/ZKsync/getEip712Domain.js +58 -0
- package/src/ZKsync/types.cjs +31 -0
- package/src/ZKsync/types.d.ts +9 -0
- package/src/ZKsync/types.js +27 -0
- package/src/ZKsync/walletActions.cjs +93 -0
- package/src/ZKsync/walletActions.d.ts +15 -0
- package/src/ZKsync/walletActions.js +87 -0
- package/src/ZKsyncConnector.cjs +430 -0
- package/src/ZKsyncConnector.d.ts +23259 -0
- package/src/ZKsyncConnector.js +426 -0
- package/src/ZeroDevConnector.cjs +17 -13
- package/src/ZeroDevConnector.d.ts +21 -15
- package/src/ZeroDevConnector.js +18 -14
- package/src/index.cjs +11 -0
- package/src/index.d.ts +2 -0
- package/src/index.js +10 -1
- package/src/utils/abi.cjs +88 -0
- package/src/utils/abi.d.ts +102 -0
- package/src/utils/abi.js +84 -0
- package/src/utils/isZKsyncConnector.cjs +8 -0
- package/src/utils/isZKsyncConnector.d.ts +3 -0
- package/src/utils/isZKsyncConnector.js +4 -0
|
@@ -0,0 +1,93 @@
|
|
|
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;
|
|
@@ -0,0 +1,15 @@
|
|
|
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);
|
|
@@ -0,0 +1,87 @@
|
|
|
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 };
|
|
@@ -0,0 +1,430 @@
|
|
|
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 client$1 = require('zksync-sso/client');
|
|
10
|
+
var passkey = require('zksync-sso/client/passkey');
|
|
11
|
+
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
12
|
+
var utils = require('@dynamic-labs/utils');
|
|
13
|
+
var AccountAbstractionConnector = require('./AccountAbstractionConnector.cjs');
|
|
14
|
+
var abi = require('./utils/abi.cjs');
|
|
15
|
+
var walletActions = require('./ZKsync/walletActions.cjs');
|
|
16
|
+
var client = require('./ZKsync/client.cjs');
|
|
17
|
+
|
|
18
|
+
class ZKsyncConnector extends AccountAbstractionConnector.AccountAbstractionConnector {
|
|
19
|
+
constructor(props) {
|
|
20
|
+
var _a, _b, _c, _d, _e;
|
|
21
|
+
super(props);
|
|
22
|
+
// Core wallet properties
|
|
23
|
+
this.ChainWallet = ethereumCore.EthereumWallet;
|
|
24
|
+
this.name = 'ZKsync';
|
|
25
|
+
this.overrideKey = 'zksync';
|
|
26
|
+
// Chain configuration
|
|
27
|
+
this.connectedChain = 'EVM';
|
|
28
|
+
this.evmNetworks = [];
|
|
29
|
+
this.supportedChains = ['ETH', 'EVM'];
|
|
30
|
+
this.enableEIP7702Mode = false;
|
|
31
|
+
this.walletFallback = {
|
|
32
|
+
brand: {
|
|
33
|
+
alt: 'Smart Wallet',
|
|
34
|
+
spriteId: 'smartwallet',
|
|
35
|
+
},
|
|
36
|
+
name: 'ZKsync',
|
|
37
|
+
};
|
|
38
|
+
this._walletUiUtils = props.walletUiUtils;
|
|
39
|
+
this.chainId = (_a = props.apiProviders.zksync) === null || _a === void 0 ? void 0 : _a.defaultChainId;
|
|
40
|
+
this.evmNetworks = utils.parseEvmNetworks(props.evmNetworks).filter((network) => network.chainId === this.chainId);
|
|
41
|
+
this.factoryAddress = ((_c = (_b = props.apiProviders.zksync) === null || _b === void 0 ? void 0 : _b.factoryAddress) !== null && _c !== void 0 ? _c : '0x2e620D52467CfA4C664F92005Ab0f0181d3d1E79'); // Fallback if not provided
|
|
42
|
+
this.paymasterAddress = ((_e = (_d = props.apiProviders.zksync) === null || _d === void 0 ? void 0 : _d.paymasterAddress) !== null && _e !== void 0 ? _e : '0xA78CAC56c9D491Ece2FF303aEcc627Bf71C6dc1c'); // Fallback if not provided
|
|
43
|
+
}
|
|
44
|
+
getEnabledNetworks() {
|
|
45
|
+
return this.evmNetworks;
|
|
46
|
+
}
|
|
47
|
+
getConnectedAccounts() {
|
|
48
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
if (!this.smartAccountAddress) {
|
|
50
|
+
throw new Error('Smart account address is not initialized');
|
|
51
|
+
}
|
|
52
|
+
return [this.smartAccountAddress];
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
getNetwork() {
|
|
56
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
57
|
+
if (!this.smartAccountAddress) {
|
|
58
|
+
throw new Error('Smart account address is not initialized');
|
|
59
|
+
}
|
|
60
|
+
return this.chainId;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
getPublicClient() {
|
|
64
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
65
|
+
return viem.createPublicClient({
|
|
66
|
+
chain: zksync.zksyncSepoliaTestnet,
|
|
67
|
+
transport: viem.http(),
|
|
68
|
+
});
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
canSponsorTransactionGas() {
|
|
72
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
return false;
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
getAccountAbstractionProvider() {
|
|
77
|
+
return this.smartAccount;
|
|
78
|
+
}
|
|
79
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
80
|
+
getWalletClient() {
|
|
81
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
82
|
+
var _a;
|
|
83
|
+
const eoaSigner = yield ((_a = this.eoaConnector) === null || _a === void 0 ? void 0 : _a.getSigner());
|
|
84
|
+
if (!eoaSigner) {
|
|
85
|
+
throw new Error('EOA wallet client not found');
|
|
86
|
+
}
|
|
87
|
+
const walletClient = yield client.createZksyncEcdsaClient({
|
|
88
|
+
address: this.smartAccountAddress,
|
|
89
|
+
chain: zksync.zksyncSepoliaTestnet,
|
|
90
|
+
contracts: {
|
|
91
|
+
accountFactory: this.factoryAddress,
|
|
92
|
+
session: '0x5Da0ba1366F05a14603FC6aC906B99CdC6BA851A',
|
|
93
|
+
},
|
|
94
|
+
owner: eoaSigner,
|
|
95
|
+
transport: viem.http(),
|
|
96
|
+
});
|
|
97
|
+
return walletClient;
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
getSigner() {
|
|
101
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
102
|
+
return this.getWalletClient();
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Implementation of the interface method required by IAccountAbstractionWalletConnector
|
|
107
|
+
* @param eoaConnector - The EOA connector to use for signing transactions
|
|
108
|
+
* @param smartAccountAddress - The address of the smart account
|
|
109
|
+
*/
|
|
110
|
+
initializeZksyncConnector(_a) {
|
|
111
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ eoaConnector, smartAccountAddress, }) {
|
|
112
|
+
this.eoaConnector = eoaConnector;
|
|
113
|
+
this.eoaAddress = yield eoaConnector.getAddress();
|
|
114
|
+
this.smartAccountAddress = smartAccountAddress;
|
|
115
|
+
this.smartAccount = (yield this.getWalletClient());
|
|
116
|
+
// Check if account needs deployment
|
|
117
|
+
const shouldDeploy = yield this.shouldDeployAccount(smartAccountAddress);
|
|
118
|
+
if (!shouldDeploy) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
createPasskeyClient() {
|
|
124
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
const storedCredentialPublicKey = utils.StorageService.getItem('credentialPublicKey');
|
|
126
|
+
const credentialPublicKey = storedCredentialPublicKey
|
|
127
|
+
? new Uint8Array(Object.values(storedCredentialPublicKey))
|
|
128
|
+
: null;
|
|
129
|
+
if (!credentialPublicKey) {
|
|
130
|
+
throw new Error('Credential public key not found');
|
|
131
|
+
}
|
|
132
|
+
const publicClient = yield this.getTypedPublicClient();
|
|
133
|
+
const { chain } = publicClient;
|
|
134
|
+
if (!chain) {
|
|
135
|
+
throw new Error('Chain not found');
|
|
136
|
+
}
|
|
137
|
+
const passkeyClient = passkey.createZksyncPasskeyClient({
|
|
138
|
+
address: '0xf2484bEA13038C2d110dCf0DfCF3b251B8d6A7Ea',
|
|
139
|
+
chain,
|
|
140
|
+
contracts: {
|
|
141
|
+
accountFactory: this.factoryAddress,
|
|
142
|
+
passkey: '0xF69e92B224f527365F4434B729134aE69C60B963',
|
|
143
|
+
session: '0x5Da0ba1366F05a14603FC6aC906B99CdC6BA851A',
|
|
144
|
+
},
|
|
145
|
+
credentialPublicKey,
|
|
146
|
+
transport: viem.http(),
|
|
147
|
+
userDisplayName: 'Vinicius',
|
|
148
|
+
userName: 'vinicius.macelai@gmail.com',
|
|
149
|
+
});
|
|
150
|
+
this.passkeyClient = passkeyClient;
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Create your account client
|
|
154
|
+
createSmartAccountClient() {
|
|
155
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
156
|
+
return this.smartAccount;
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
deploySmartAccountWithZksyncSso() {
|
|
160
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
const walletClient = yield this.getWalletClient();
|
|
163
|
+
if (!walletClient) {
|
|
164
|
+
throw new Error('Wallet client not found');
|
|
165
|
+
}
|
|
166
|
+
const deploymentParams = yield this.getDeploymentParameters();
|
|
167
|
+
if (!this.smartAccountAddress) {
|
|
168
|
+
throw new Error('Smart account address is not initialized');
|
|
169
|
+
}
|
|
170
|
+
const shouldDeploy = yield this.shouldDeployAccount(this.smartAccountAddress);
|
|
171
|
+
if (!shouldDeploy) {
|
|
172
|
+
throw new Error('Smart account already deployed');
|
|
173
|
+
}
|
|
174
|
+
const paymasterInput = zksync.getGeneralPaymasterInput({
|
|
175
|
+
innerInput: new Uint8Array(),
|
|
176
|
+
});
|
|
177
|
+
const storedCredentialPublicKey = utils.StorageService.getItem('credentialPublicKey');
|
|
178
|
+
let credentialPublicKey = storedCredentialPublicKey
|
|
179
|
+
? new Uint8Array(Object.values(storedCredentialPublicKey))
|
|
180
|
+
: null;
|
|
181
|
+
if (!credentialPublicKey) {
|
|
182
|
+
const { credentialPublicKey: newCredentialPublicKey } = yield passkey.registerNewPasskey({
|
|
183
|
+
attestationType: 'none',
|
|
184
|
+
authenticatorSelection: {
|
|
185
|
+
authenticatorAttachment: 'platform',
|
|
186
|
+
requireResidentKey: false,
|
|
187
|
+
userVerification: 'required',
|
|
188
|
+
},
|
|
189
|
+
userDisplayName: this.smartAccountAddress,
|
|
190
|
+
userName: this.smartAccountAddress,
|
|
191
|
+
});
|
|
192
|
+
utils.StorageService.setItem('credentialPublicKey', newCredentialPublicKey);
|
|
193
|
+
credentialPublicKey = new Uint8Array(newCredentialPublicKey);
|
|
194
|
+
}
|
|
195
|
+
if (!((_a = walletClient.account) === null || _a === void 0 ? void 0 : _a.address)) {
|
|
196
|
+
throw new Error('Wallet client not found');
|
|
197
|
+
}
|
|
198
|
+
yield client$1.deployAccount(walletClient, {
|
|
199
|
+
contracts: {
|
|
200
|
+
accountFactory: this.factoryAddress,
|
|
201
|
+
passkey: '0xa9ab0dE9d83cc4827261EaccF536859f4A562b72',
|
|
202
|
+
session: '0x5Da0ba1366F05a14603FC6aC906B99CdC6BA851A',
|
|
203
|
+
},
|
|
204
|
+
credentialId: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
|
|
205
|
+
credentialPublicKey,
|
|
206
|
+
paymasterAddress: '0xa20D5f00A693e4Eb260AAdc7458fe415981c8051',
|
|
207
|
+
paymasterInput: paymasterInput,
|
|
208
|
+
uniqueAccountId: deploymentParams.salt,
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
deploySmartAccountWithPaymaster() {
|
|
213
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
214
|
+
const paymaster = this.paymasterAddress;
|
|
215
|
+
const publicClient = yield this.getTypedPublicClient();
|
|
216
|
+
const walletClient = yield this.getTypedWalletClient();
|
|
217
|
+
const deploymentParams = yield this.getDeploymentParameters();
|
|
218
|
+
const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
|
|
219
|
+
const paymasterInput = zksync.getGeneralPaymasterInput({
|
|
220
|
+
innerInput: new Uint8Array(),
|
|
221
|
+
});
|
|
222
|
+
const requestWithPaymaster = Object.assign(Object.assign({}, request), { paymaster,
|
|
223
|
+
paymasterInput });
|
|
224
|
+
yield this.executeAccountDeployment(walletClient, requestWithPaymaster);
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
signMessage(message) {
|
|
228
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
229
|
+
const walletClient = yield this.getWalletClient();
|
|
230
|
+
if (!walletClient) {
|
|
231
|
+
throw new Error('Wallet client not found');
|
|
232
|
+
}
|
|
233
|
+
return yield walletClient.signMessage({
|
|
234
|
+
account: walletClient.account,
|
|
235
|
+
message,
|
|
236
|
+
});
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Deploys a new smart account contract
|
|
241
|
+
* @throws {ZkSyncConnectorError} If deployment fails
|
|
242
|
+
* @testable This method can be mocked in tests
|
|
243
|
+
*/
|
|
244
|
+
deploySmartAccount() {
|
|
245
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
246
|
+
if (!this.eoaConnector) {
|
|
247
|
+
throw new Error('EOA connector is not initialized');
|
|
248
|
+
}
|
|
249
|
+
const walletClient = yield this.getTypedWalletClient();
|
|
250
|
+
const publicClient = yield this.getTypedPublicClient();
|
|
251
|
+
const deploymentParams = yield this.getDeploymentParameters();
|
|
252
|
+
// Simulate the contract deployment first
|
|
253
|
+
const { request } = yield this.simulateAccountDeployment(publicClient, walletClient, deploymentParams, false);
|
|
254
|
+
// Execute the deployment transaction
|
|
255
|
+
yield this.executeAccountDeployment(walletClient, request);
|
|
256
|
+
});
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Gets typed public client from EOA connector
|
|
260
|
+
* @throws {ZkSyncConnectorError} If public client cannot be obtained
|
|
261
|
+
* @testable This method can be mocked in tests
|
|
262
|
+
*/
|
|
263
|
+
getTypedPublicClient() {
|
|
264
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
265
|
+
if (!this.eoaConnector) {
|
|
266
|
+
throw new Error('EOA connector is not initialized');
|
|
267
|
+
}
|
|
268
|
+
const publicClient = yield this.eoaConnector.getPublicClient();
|
|
269
|
+
if (!publicClient) {
|
|
270
|
+
throw new Error('Failed to get public client from EOA connector');
|
|
271
|
+
}
|
|
272
|
+
return publicClient;
|
|
273
|
+
});
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Gets typed wallet client from EOA connector
|
|
277
|
+
* @throws {ZkSyncConnectorError} If wallet client cannot be obtained
|
|
278
|
+
* @testable This method can be mocked in tests
|
|
279
|
+
*/
|
|
280
|
+
getTypedWalletClient() {
|
|
281
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
282
|
+
if (!this.eoaConnector) {
|
|
283
|
+
throw new Error('EOA connector is not initialized');
|
|
284
|
+
}
|
|
285
|
+
const walletClient = yield this.eoaConnector.getWalletClient();
|
|
286
|
+
if (!walletClient) {
|
|
287
|
+
throw new Error('Failed to get wallet client from EOA connector');
|
|
288
|
+
}
|
|
289
|
+
return walletClient
|
|
290
|
+
.extend(viem.publicActions)
|
|
291
|
+
.extend(viem.walletActions)
|
|
292
|
+
.extend(zksync.eip712WalletActions())
|
|
293
|
+
.extend(walletActions.zksyncSsoEcdsaWalletActions);
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Returns the parameters needed for deploying the smart account
|
|
298
|
+
* @returns Deployment parameters object
|
|
299
|
+
* @testable This method can be overridden in tests
|
|
300
|
+
*/
|
|
301
|
+
getDeploymentParameters() {
|
|
302
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
303
|
+
const salt = `0x${Buffer.from(viem.toBytes('DynamicLabs', { size: 32 })).toString('hex')}`;
|
|
304
|
+
const initialValidators = [];
|
|
305
|
+
const initialK1Owners = [this.eoaAddress];
|
|
306
|
+
return {
|
|
307
|
+
initialK1Owners,
|
|
308
|
+
initialValidators,
|
|
309
|
+
salt,
|
|
310
|
+
};
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Simulates the smart account deployment
|
|
315
|
+
* @param publicClient - The public client to use for simulation
|
|
316
|
+
* @param walletClient - The wallet client to use for account information
|
|
317
|
+
* @param params - The deployment parameters
|
|
318
|
+
* @returns The simulation result
|
|
319
|
+
* @throws {ZkSyncConnectorError} If simulation fails
|
|
320
|
+
* @testable This method can be mocked in tests
|
|
321
|
+
*/
|
|
322
|
+
simulateAccountDeployment(publicClient_1, walletClient_1, params_1) {
|
|
323
|
+
return _tslib.__awaiter(this, arguments, void 0, function* (publicClient, walletClient, params, checkBalance = true) {
|
|
324
|
+
var _a, _b, _c;
|
|
325
|
+
// this is to keep the same salt as calculated on zksync sso package
|
|
326
|
+
const salt = viem.keccak256(viem.toHex(params.salt));
|
|
327
|
+
const gasEstimate = yield publicClient.estimateContractGas({
|
|
328
|
+
abi: abi.AAFactoryABI,
|
|
329
|
+
account: (_a = walletClient.account) === null || _a === void 0 ? void 0 : _a.address,
|
|
330
|
+
address: this.factoryAddress,
|
|
331
|
+
args: [salt, params.initialValidators, params.initialK1Owners],
|
|
332
|
+
functionName: 'deployProxySsoAccount',
|
|
333
|
+
});
|
|
334
|
+
if (checkBalance) {
|
|
335
|
+
const balance = yield publicClient.getBalance({
|
|
336
|
+
address: (_b = walletClient.account) === null || _b === void 0 ? void 0 : _b.address,
|
|
337
|
+
});
|
|
338
|
+
if (balance < gasEstimate) {
|
|
339
|
+
throw new Error('Insufficient balance to deploy account');
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
// Simulate the contract call
|
|
343
|
+
return yield publicClient.simulateContract({
|
|
344
|
+
abi: abi.AAFactoryABI,
|
|
345
|
+
account: (_c = walletClient.account) === null || _c === void 0 ? void 0 : _c.address,
|
|
346
|
+
address: this.factoryAddress,
|
|
347
|
+
args: [salt, params.initialValidators, params.initialK1Owners],
|
|
348
|
+
functionName: 'deployProxySsoAccount',
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
/**
|
|
353
|
+
* Executes the smart account deployment transaction
|
|
354
|
+
* @param walletClient - The wallet client to use for transaction execution
|
|
355
|
+
* @param request - The request to execute
|
|
356
|
+
* @throws {ZkSyncConnectorError} If transaction execution fails
|
|
357
|
+
* @testable This method can be mocked in tests
|
|
358
|
+
*/
|
|
359
|
+
executeAccountDeployment(walletClient, request) {
|
|
360
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
361
|
+
if (!this.smartAccountAddress) {
|
|
362
|
+
throw new Error('Smart account address is not initialized');
|
|
363
|
+
}
|
|
364
|
+
const shouldDeploy = yield this.shouldDeployAccount(this.smartAccountAddress);
|
|
365
|
+
if (!shouldDeploy) {
|
|
366
|
+
throw new Error('Smart account already deployed');
|
|
367
|
+
}
|
|
368
|
+
yield walletClient.writeContract(request);
|
|
369
|
+
});
|
|
370
|
+
}
|
|
371
|
+
/**
|
|
372
|
+
* Checks if a smart account needs to be deployed
|
|
373
|
+
* @param smartAccountAddress - The address of the smart account
|
|
374
|
+
* @returns True if the account needs to be deployed, false otherwise
|
|
375
|
+
* @throws {ZkSyncConnectorError} If the check fails
|
|
376
|
+
* @testable This method can be mocked in tests
|
|
377
|
+
*/
|
|
378
|
+
shouldDeployAccount(smartAccountAddress) {
|
|
379
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
380
|
+
var _a;
|
|
381
|
+
const client = yield ((_a = this.eoaConnector) === null || _a === void 0 ? void 0 : _a.getPublicClient());
|
|
382
|
+
if (!client) {
|
|
383
|
+
throw new Error('Failed to get public client from EOA connector');
|
|
384
|
+
}
|
|
385
|
+
const code = yield client.getCode({
|
|
386
|
+
address: smartAccountAddress,
|
|
387
|
+
});
|
|
388
|
+
return !code || code === '0x';
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
getAddress() {
|
|
392
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
393
|
+
if (!this.smartAccount) {
|
|
394
|
+
throw new Error('Smart account is not initialized');
|
|
395
|
+
}
|
|
396
|
+
return this.smartAccountAddress;
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
validateActiveWallet(expectedAddress) {
|
|
400
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
401
|
+
const currentAddress = yield this.getAddress();
|
|
402
|
+
if (currentAddress !== expectedAddress) {
|
|
403
|
+
throw new utils.DynamicError('Invalid active wallet');
|
|
404
|
+
}
|
|
405
|
+
return;
|
|
406
|
+
});
|
|
407
|
+
}
|
|
408
|
+
createUiTransaction(from) {
|
|
409
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
410
|
+
yield this.validateActiveWallet(from);
|
|
411
|
+
const walletClient = this.getWalletClient();
|
|
412
|
+
const publicClient = yield this.getPublicClient();
|
|
413
|
+
if (!publicClient || !walletClient) {
|
|
414
|
+
throw new utils.DynamicError('No public client available');
|
|
415
|
+
}
|
|
416
|
+
return ethereumCore.createViemUiTransaction({
|
|
417
|
+
from: from,
|
|
418
|
+
publicClient: publicClient,
|
|
419
|
+
walletClient: walletClient,
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
registerEoa(_a) {
|
|
424
|
+
return _tslib.__awaiter(this, arguments, void 0, function* ({ smartWalletAddress, eoaAddress, eoaConnector, shouldSetEoaConnector, }) {
|
|
425
|
+
throw new Error('Not implemented');
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
exports.ZKsyncConnector = ZKsyncConnector;
|