@dynamic-labs/ethereum-aa 4.10.2 → 4.10.4-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 +15 -4
- 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 +52 -0
- package/src/ZKsync/types.d.ts +9 -0
- package/src/ZKsync/types.js +48 -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 +502 -0
- package/src/ZKsyncConnector.d.ts +24918 -0
- package/src/ZKsyncConnector.js +498 -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,48 @@
|
|
|
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 };
|
|
@@ -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 };
|