@dynamic-labs/ethereum-aa 4.10.3 → 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 +7 -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
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
|
|
2
|
+
### [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
|
+
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
* add zk sync aa connector ([9835145](https://github.com/dynamic-labs/dynamic-auth/commit/9835145987a859bf2da894bf49521afce66bf9f1))
|
|
8
|
+
|
|
2
9
|
### [4.10.3](https://github.com/dynamic-labs/dynamic-auth/compare/v4.10.2...v4.10.3) (2025-04-04)
|
|
3
10
|
|
|
4
11
|
|
|
@@ -15,7 +22,6 @@
|
|
|
15
22
|
* add walletTabSelected event ([#8430](https://github.com/dynamic-labs/dynamic-auth/issues/8430)) ([01ef815](https://github.com/dynamic-labs/dynamic-auth/commit/01ef815330e6c5433f7c135f561ed86621cc2bd9))
|
|
16
23
|
|
|
17
24
|
|
|
18
|
-
### Bug Fixes
|
|
19
25
|
|
|
20
26
|
* disconect wallets on logout ([#8399](https://github.com/dynamic-labs/dynamic-auth/issues/8399)) ([148bc0d](https://github.com/dynamic-labs/dynamic-auth/commit/148bc0dd175048fa8a9a675383e8e6d93c7d16ac))
|
|
21
27
|
* ensure primary wallet is still a valid credential when calling resfreshUser ([#8439](https://github.com/dynamic-labs/dynamic-auth/issues/8439)) ([2e567e5](https://github.com/dynamic-labs/dynamic-auth/commit/2e567e53ea7738d4a42f3d54bb40a294403a1c36))
|
|
@@ -31,9 +37,6 @@
|
|
|
31
37
|
* Sui Support for branded wallets
|
|
32
38
|
* better handling of non-multiasset balance fetching ([#8419](https://github.com/dynamic-labs/dynamic-auth/issues/8419)) ([574d4ea](https://github.com/dynamic-labs/dynamic-auth/commit/574d4eabf85e6f85325dc374b6cd84aa9fdd7ed4))
|
|
33
39
|
|
|
34
|
-
|
|
35
|
-
### Bug Fixes
|
|
36
|
-
|
|
37
40
|
* do not prompt passkey with 7702 on v2 wallets ([#8391](https://github.com/dynamic-labs/dynamic-auth/issues/8391)) ([bb91396](https://github.com/dynamic-labs/dynamic-auth/commit/bb913965121e97801922f5ca828d11e4a551a3b6))
|
|
38
41
|
* ensure the global wallet app url is used ([#8404](https://github.com/dynamic-labs/dynamic-auth/issues/8404)) ([23a7d91](https://github.com/dynamic-labs/dynamic-auth/commit/23a7d91b50cc85e67de52306f91163c675e0f007))
|
|
39
42
|
* **global-wallet-client:** use global wallet env id when storing data to ls ([#8405](https://github.com/dynamic-labs/dynamic-auth/issues/8405)) ([2b3d9ce](https://github.com/dynamic-labs/dynamic-auth/commit/2b3d9ce8dd82dda487759e0621c73bfad2842aef))
|
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.
|
|
3
|
+
"version": "4.10.4-preview.0",
|
|
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",
|
|
@@ -18,17 +18,19 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://www.dynamic.xyz/",
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"@dynamic-labs/sdk-api-core": "0.0.
|
|
21
|
+
"@dynamic-labs/sdk-api-core": "0.0.656",
|
|
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/
|
|
25
|
+
"abitype": "1.0.2",
|
|
26
|
+
"zksync-sso": "0.0.0-beta.12",
|
|
27
|
+
"@dynamic-labs/assert-package-version": "4.10.4-preview.0",
|
|
28
|
+
"@dynamic-labs/ethereum-core": "4.10.4-preview.0",
|
|
29
|
+
"@dynamic-labs/logger": "4.10.4-preview.0",
|
|
30
|
+
"@dynamic-labs/types": "4.10.4-preview.0",
|
|
31
|
+
"@dynamic-labs/utils": "4.10.4-preview.0",
|
|
32
|
+
"@dynamic-labs/wallet-book": "4.10.4-preview.0",
|
|
33
|
+
"@dynamic-labs/wallet-connector-core": "4.10.4-preview.0"
|
|
32
34
|
},
|
|
33
35
|
"peerDependencies": {
|
|
34
36
|
"viem": "^2.21.55"
|
|
@@ -0,0 +1,75 @@
|
|
|
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 walletConnectorCore = require('@dynamic-labs/wallet-connector-core');
|
|
9
|
+
var utils = require('@dynamic-labs/utils');
|
|
10
|
+
var ethereumCore = require('@dynamic-labs/ethereum-core');
|
|
11
|
+
|
|
12
|
+
class AccountAbstractionConnector extends walletConnectorCore.WalletConnectorBase {
|
|
13
|
+
constructor(opts) {
|
|
14
|
+
super({ walletBook: opts.walletBook });
|
|
15
|
+
this._isGasSponsorshipDisabled = false;
|
|
16
|
+
this.evmNetworks = [];
|
|
17
|
+
this.ChainWallet = ethereumCore.EthereumWallet;
|
|
18
|
+
this.isEmbeddedWallet = true;
|
|
19
|
+
this.connectedChain = 'EVM';
|
|
20
|
+
this.supportedChains = ['ETH', 'EVM'];
|
|
21
|
+
this._walletUiUtils = opts.walletUiUtils;
|
|
22
|
+
this.evmNetworks = opts.evmNetworks;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Gets the EOA connector associated with this account abstraction wallet
|
|
26
|
+
* @deprecated Use getEOAConnector with a specific smart contract wallet address instead
|
|
27
|
+
*/
|
|
28
|
+
getEOAConnector() {
|
|
29
|
+
return this.eoaConnector;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Disables gas sponsorship for the next transaction
|
|
33
|
+
*/
|
|
34
|
+
disableGasSponsorshipOnce() {
|
|
35
|
+
this._isGasSponsorshipDisabled = true;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Protected method to check if gas sponsorship is disabled
|
|
39
|
+
*/
|
|
40
|
+
isGasSponsorshipDisabled() {
|
|
41
|
+
return this._isGasSponsorshipDisabled;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Gets the enabled networks
|
|
45
|
+
*/
|
|
46
|
+
getEnabledNetworks() {
|
|
47
|
+
return this.evmNetworks;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Gets the balance for an address
|
|
51
|
+
*/
|
|
52
|
+
getBalance(address) {
|
|
53
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
54
|
+
const publicClient = yield this.getPublicClient();
|
|
55
|
+
if (!publicClient) {
|
|
56
|
+
throw new utils.DynamicError('No public client available');
|
|
57
|
+
}
|
|
58
|
+
const balance = yield publicClient.getBalance({ address });
|
|
59
|
+
return viem.formatEther(balance);
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Validates that the expected wallet is active
|
|
64
|
+
*/
|
|
65
|
+
validateActiveWallet(expectedAddress) {
|
|
66
|
+
return _tslib.__awaiter(this, void 0, void 0, function* () {
|
|
67
|
+
const currentAddress = yield this.getAddress();
|
|
68
|
+
if ((currentAddress === null || currentAddress === void 0 ? void 0 : currentAddress.toLowerCase()) !== expectedAddress.toLowerCase()) {
|
|
69
|
+
throw new utils.DynamicError('Invalid active wallet');
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
exports.AccountAbstractionConnector = AccountAbstractionConnector;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Chain, InternalWalletConnector, WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
2
|
+
import { EthereumWallet } from '@dynamic-labs/ethereum-core';
|
|
3
|
+
import { IUITransaction, WalletUiUtils, GenericNetwork } from '@dynamic-labs/types';
|
|
4
|
+
import { WalletBookSchema } from '@dynamic-labs/wallet-book';
|
|
5
|
+
export type AccountAbstractionConnectorProps = {
|
|
6
|
+
walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
7
|
+
walletBook: WalletBookSchema;
|
|
8
|
+
evmNetworks: GenericNetwork[];
|
|
9
|
+
};
|
|
10
|
+
export declare abstract class AccountAbstractionConnector extends WalletConnectorBase<typeof EthereumWallet> {
|
|
11
|
+
abstract eoaConnector: InternalWalletConnector | undefined;
|
|
12
|
+
abstract eoaAddress: string | undefined;
|
|
13
|
+
protected _walletUiUtils: WalletUiUtils<InternalWalletConnector>;
|
|
14
|
+
private _isGasSponsorshipDisabled;
|
|
15
|
+
protected evmNetworks: GenericNetwork[];
|
|
16
|
+
ChainWallet: typeof EthereumWallet;
|
|
17
|
+
isEmbeddedWallet: boolean;
|
|
18
|
+
connectedChain: Chain;
|
|
19
|
+
supportedChains: Chain[];
|
|
20
|
+
constructor(opts: AccountAbstractionConnectorProps);
|
|
21
|
+
/**
|
|
22
|
+
* Gets the EOA connector associated with this account abstraction wallet
|
|
23
|
+
* @deprecated Use getEOAConnector with a specific smart contract wallet address instead
|
|
24
|
+
*/
|
|
25
|
+
getEOAConnector(): InternalWalletConnector | undefined;
|
|
26
|
+
/**
|
|
27
|
+
* Disables gas sponsorship for the next transaction
|
|
28
|
+
*/
|
|
29
|
+
disableGasSponsorshipOnce(): void;
|
|
30
|
+
/**
|
|
31
|
+
* Protected method to check if gas sponsorship is disabled
|
|
32
|
+
*/
|
|
33
|
+
protected isGasSponsorshipDisabled(): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Gets the enabled networks
|
|
36
|
+
*/
|
|
37
|
+
getEnabledNetworks(): GenericNetwork[];
|
|
38
|
+
/**
|
|
39
|
+
* Gets the balance for an address
|
|
40
|
+
*/
|
|
41
|
+
getBalance(address: string): Promise<string | undefined>;
|
|
42
|
+
/**
|
|
43
|
+
* Validates that the expected wallet is active
|
|
44
|
+
*/
|
|
45
|
+
validateActiveWallet(expectedAddress: string): Promise<void>;
|
|
46
|
+
abstract canSponsorTransactionGas(transaction: {
|
|
47
|
+
from: string;
|
|
48
|
+
to?: string;
|
|
49
|
+
value?: bigint;
|
|
50
|
+
data?: string;
|
|
51
|
+
}): Promise<boolean>;
|
|
52
|
+
abstract createUiTransaction(from: string): Promise<IUITransaction>;
|
|
53
|
+
abstract getAccountAbstractionProvider<T>({ withSponsorship, }: {
|
|
54
|
+
withSponsorship: boolean;
|
|
55
|
+
}): Promise<T>;
|
|
56
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
'use client'
|
|
2
|
+
import { __awaiter } from '../_virtual/_tslib.js';
|
|
3
|
+
import { formatEther } from 'viem';
|
|
4
|
+
import { WalletConnectorBase } from '@dynamic-labs/wallet-connector-core';
|
|
5
|
+
import { DynamicError } from '@dynamic-labs/utils';
|
|
6
|
+
import { EthereumWallet } from '@dynamic-labs/ethereum-core';
|
|
7
|
+
|
|
8
|
+
class AccountAbstractionConnector extends WalletConnectorBase {
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
super({ walletBook: opts.walletBook });
|
|
11
|
+
this._isGasSponsorshipDisabled = false;
|
|
12
|
+
this.evmNetworks = [];
|
|
13
|
+
this.ChainWallet = EthereumWallet;
|
|
14
|
+
this.isEmbeddedWallet = true;
|
|
15
|
+
this.connectedChain = 'EVM';
|
|
16
|
+
this.supportedChains = ['ETH', 'EVM'];
|
|
17
|
+
this._walletUiUtils = opts.walletUiUtils;
|
|
18
|
+
this.evmNetworks = opts.evmNetworks;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Gets the EOA connector associated with this account abstraction wallet
|
|
22
|
+
* @deprecated Use getEOAConnector with a specific smart contract wallet address instead
|
|
23
|
+
*/
|
|
24
|
+
getEOAConnector() {
|
|
25
|
+
return this.eoaConnector;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Disables gas sponsorship for the next transaction
|
|
29
|
+
*/
|
|
30
|
+
disableGasSponsorshipOnce() {
|
|
31
|
+
this._isGasSponsorshipDisabled = true;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Protected method to check if gas sponsorship is disabled
|
|
35
|
+
*/
|
|
36
|
+
isGasSponsorshipDisabled() {
|
|
37
|
+
return this._isGasSponsorshipDisabled;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Gets the enabled networks
|
|
41
|
+
*/
|
|
42
|
+
getEnabledNetworks() {
|
|
43
|
+
return this.evmNetworks;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Gets the balance for an address
|
|
47
|
+
*/
|
|
48
|
+
getBalance(address) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
const publicClient = yield this.getPublicClient();
|
|
51
|
+
if (!publicClient) {
|
|
52
|
+
throw new DynamicError('No public client available');
|
|
53
|
+
}
|
|
54
|
+
const balance = yield publicClient.getBalance({ address });
|
|
55
|
+
return formatEther(balance);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Validates that the expected wallet is active
|
|
60
|
+
*/
|
|
61
|
+
validateActiveWallet(expectedAddress) {
|
|
62
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
const currentAddress = yield this.getAddress();
|
|
64
|
+
if ((currentAddress === null || currentAddress === void 0 ? void 0 : currentAddress.toLowerCase()) !== expectedAddress.toLowerCase()) {
|
|
65
|
+
throw new DynamicError('Invalid active wallet');
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { AccountAbstractionConnector };
|
|
@@ -0,0 +1,29 @@
|
|
|
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;
|
|
@@ -0,0 +1,24 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,25 @@
|
|
|
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 };
|
|
@@ -0,0 +1,32 @@
|
|
|
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;
|
|
@@ -0,0 +1,13 @@
|
|
|
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>;
|
|
@@ -0,0 +1,28 @@
|
|
|
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 };
|
|
@@ -0,0 +1,62 @@
|
|
|
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;
|
|
@@ -0,0 +1,58 @@
|
|
|
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 };
|
|
@@ -0,0 +1,52 @@
|
|
|
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;
|
|
@@ -0,0 +1,9 @@
|
|
|
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>;
|