@aa-sdk/ethers 4.0.0-alpha.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/LICENSE +21 -0
- package/README.md +64 -0
- package/dist/cjs/account-signer.d.ts +19 -0
- package/dist/cjs/account-signer.js +91 -0
- package/dist/cjs/account-signer.js.map +1 -0
- package/dist/cjs/index.d.ts +3 -0
- package/dist/cjs/index.js +11 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/provider-adapter.d.ts +13 -0
- package/dist/cjs/provider-adapter.js +58 -0
- package/dist/cjs/provider-adapter.js.map +1 -0
- package/dist/cjs/types.d.ts +10 -0
- package/dist/cjs/types.js +3 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/cjs/utils.d.ts +5 -0
- package/dist/cjs/utils.js +28 -0
- package/dist/cjs/utils.js.map +1 -0
- package/dist/esm/account-signer.d.ts +19 -0
- package/dist/esm/account-signer.js +89 -0
- package/dist/esm/account-signer.js.map +1 -0
- package/dist/esm/index.d.ts +3 -0
- package/dist/esm/index.js +4 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/package.json +1 -0
- package/dist/esm/provider-adapter.d.ts +13 -0
- package/dist/esm/provider-adapter.js +54 -0
- package/dist/esm/provider-adapter.js.map +1 -0
- package/dist/esm/types.d.ts +10 -0
- package/dist/esm/types.js +2 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/utils.d.ts +5 -0
- package/dist/esm/utils.js +24 -0
- package/dist/esm/utils.js.map +1 -0
- package/dist/types/account-signer.d.ts +20 -0
- package/dist/types/account-signer.d.ts.map +1 -0
- package/dist/types/index.d.ts +4 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/provider-adapter.d.ts +35 -0
- package/dist/types/provider-adapter.d.ts.map +1 -0
- package/dist/types/types.d.ts +11 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/utils.d.ts +18 -0
- package/dist/types/utils.d.ts.map +1 -0
- package/package.json +74 -0
- package/src/account-signer.ts +114 -0
- package/src/index.ts +6 -0
- package/src/provider-adapter.ts +87 -0
- package/src/types.ts +24 -0
- package/src/utils.ts +67 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Alchemy Insights, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
# `@aa-sdk/ethers`
|
|
2
|
+
|
|
3
|
+
This package contains `EthersProviderAdapter` and `AccountSigner`, respective extensions of the [`JsonRpcProvider`](https://docs.ethers.org/v5/api/providers/jsonrpc-provider/) and [`Signer`](https://docs.ethers.org/v5/api/signer/) classes defined in [`ethers.js`](https://docs.ethers.org/v5/) external library.
|
|
4
|
+
|
|
5
|
+
If you currently rely `ethers.js` for web3 development, you can use these `ethers.js`-compatible `JsonRpcProvider` and `Signer` to integrate Account Abstraction into your dApp. You may also find the [`util`](https://accountkit.alchemy.com/packages/aa-ethers/utils/introduction.html) methods helpful.
|
|
6
|
+
|
|
7
|
+
This repo is community maintained and we welcome contributions!
|
|
8
|
+
|
|
9
|
+
## Getting started
|
|
10
|
+
|
|
11
|
+
If you are already using the `@aa-sdk/core` package, you can simply install this package and start using the `EthersProviderAdapter` and `AccountSigner`. If you are not using `@aa-sdk/core`, you can install it and follow the instructions in the ["Getting started"](https://accountkit.alchemy.com/packages/aa-ethers/) docs to get started.
|
|
12
|
+
|
|
13
|
+
```bash [yarn]
|
|
14
|
+
yarn add @aa-sdk/ethers
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
```bash [npm]
|
|
18
|
+
npm i -s @aa-sdk/ethers
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```bash [pnpm]
|
|
22
|
+
pnpm i @aa-sdk/ethers
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
|
|
27
|
+
You can create a provider and connect it to a signer account like so:
|
|
28
|
+
|
|
29
|
+
```typescript ethers-provider.ts
|
|
30
|
+
import {
|
|
31
|
+
LightSmartContractAccount,
|
|
32
|
+
getDefaultLightAccountFactoryAddress,
|
|
33
|
+
} from "@alchemy/aa-accounts";
|
|
34
|
+
import { EthersProviderAdapter } from "@aa-sdk/ethers";
|
|
35
|
+
import { LocalAccountSigner, SmartAccountSigner } from "@aa-sdk/core";
|
|
36
|
+
import { Alchemy, Network } from "alchemy-sdk";
|
|
37
|
+
import { polygonMumbai } from "@aa-sdk/core";
|
|
38
|
+
|
|
39
|
+
const chain = polygonMumbai;
|
|
40
|
+
|
|
41
|
+
// 1. Create a provider using EthersProviderAdapter
|
|
42
|
+
const alchemy = new Alchemy({
|
|
43
|
+
apiKey: process.env.API_KEY!,
|
|
44
|
+
network: Network.MATIC_MUMBAI,
|
|
45
|
+
});
|
|
46
|
+
const ethersProvider = await alchemy.config.getProvider();
|
|
47
|
+
|
|
48
|
+
const provider = EthersProviderAdapter.fromEthersProvider(ethersProvider);
|
|
49
|
+
|
|
50
|
+
const signer: SmartAccountSigner = LocalAccountSigner.mnemonicToAccountSigner(
|
|
51
|
+
process.env.YOUR_OWNER_MNEMONIC!
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
// 2. Connect the provider to the smart account signer
|
|
55
|
+
export const signer = provider.connectToAccount(
|
|
56
|
+
(rpcClient) =>
|
|
57
|
+
new LightSmartContractAccount({
|
|
58
|
+
chain,
|
|
59
|
+
factoryAddress: getDefaultLightAccountFactoryAddress(chain),
|
|
60
|
+
rpcClient,
|
|
61
|
+
signer,
|
|
62
|
+
})
|
|
63
|
+
);
|
|
64
|
+
```
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type BatchUserOperationCallData, type BundlerClient, type GetEntryPointFromAccount, type SmartContractAccount, type UserOperationCallData, type UserOperationOverrides } from "@aa-sdk/core";
|
|
2
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import type { Deferrable } from "@ethersproject/properties";
|
|
4
|
+
import { type TransactionRequest, type TransactionResponse } from "@ethersproject/providers";
|
|
5
|
+
import { type Transport } from "viem";
|
|
6
|
+
import { EthersProviderAdapter } from "./provider-adapter.js";
|
|
7
|
+
export declare class AccountSigner<TAccount extends SmartContractAccount = SmartContractAccount, TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>> extends Signer {
|
|
8
|
+
provider: EthersProviderAdapter;
|
|
9
|
+
readonly account: TAccount;
|
|
10
|
+
sendUserOperation: (args: UserOperationCallData | BatchUserOperationCallData, overrides?: UserOperationOverrides<TEntryPointVersion>) => Promise<import("@aa-sdk/core").SendUserOperationResult<keyof import("@aa-sdk/core").EntryPointRegistryBase<unknown>>>;
|
|
11
|
+
waitForUserOperationTransaction: (args: import("@aa-sdk/core").WaitForUserOperationTxParameters) => Promise<`0x${string}`>;
|
|
12
|
+
constructor(provider: EthersProviderAdapter, account: TAccount);
|
|
13
|
+
getAddress(): Promise<string>;
|
|
14
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
15
|
+
sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>;
|
|
16
|
+
signTransaction(_transaction: Deferrable<TransactionRequest>): Promise<string>;
|
|
17
|
+
getPublicErc4337Client(): BundlerClient<Transport>;
|
|
18
|
+
connect(provider: EthersProviderAdapter): AccountSigner<TAccount>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccountSigner = void 0;
|
|
4
|
+
const core_1 = require("@aa-sdk/core");
|
|
5
|
+
const abstract_signer_1 = require("@ethersproject/abstract-signer");
|
|
6
|
+
const bytes_1 = require("@ethersproject/bytes");
|
|
7
|
+
const viem_1 = require("viem");
|
|
8
|
+
const hexlifyOptional = (value) => {
|
|
9
|
+
if (value == null) {
|
|
10
|
+
return undefined;
|
|
11
|
+
}
|
|
12
|
+
return (0, bytes_1.hexlify)(value);
|
|
13
|
+
};
|
|
14
|
+
class AccountSigner extends abstract_signer_1.Signer {
|
|
15
|
+
constructor(provider, account) {
|
|
16
|
+
super();
|
|
17
|
+
Object.defineProperty(this, "provider", {
|
|
18
|
+
enumerable: true,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: true,
|
|
21
|
+
value: provider
|
|
22
|
+
});
|
|
23
|
+
Object.defineProperty(this, "account", {
|
|
24
|
+
enumerable: true,
|
|
25
|
+
configurable: true,
|
|
26
|
+
writable: true,
|
|
27
|
+
value: void 0
|
|
28
|
+
});
|
|
29
|
+
Object.defineProperty(this, "sendUserOperation", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
configurable: true,
|
|
32
|
+
writable: true,
|
|
33
|
+
value: void 0
|
|
34
|
+
});
|
|
35
|
+
Object.defineProperty(this, "waitForUserOperationTransaction", {
|
|
36
|
+
enumerable: true,
|
|
37
|
+
configurable: true,
|
|
38
|
+
writable: true,
|
|
39
|
+
value: void 0
|
|
40
|
+
});
|
|
41
|
+
this.account = account;
|
|
42
|
+
this.sendUserOperation = (args, overrides) => this.provider.accountProvider.sendUserOperation({
|
|
43
|
+
uo: args,
|
|
44
|
+
account,
|
|
45
|
+
overrides,
|
|
46
|
+
});
|
|
47
|
+
this.waitForUserOperationTransaction =
|
|
48
|
+
this.provider.accountProvider.waitForUserOperationTransaction.bind(this.provider.accountProvider);
|
|
49
|
+
}
|
|
50
|
+
async getAddress() {
|
|
51
|
+
if (!this.account) {
|
|
52
|
+
throw new core_1.AccountNotFoundError();
|
|
53
|
+
}
|
|
54
|
+
return this.account.address;
|
|
55
|
+
}
|
|
56
|
+
signMessage(message) {
|
|
57
|
+
if (!this.account) {
|
|
58
|
+
throw new core_1.AccountNotFoundError();
|
|
59
|
+
}
|
|
60
|
+
return this.account.signMessage({
|
|
61
|
+
message: typeof message === "string" && !(0, viem_1.isHex)(message)
|
|
62
|
+
? message
|
|
63
|
+
: { raw: (0, viem_1.isHex)(message) ? (0, viem_1.toBytes)(message) : message },
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
async sendTransaction(transaction) {
|
|
67
|
+
if (!this.provider.accountProvider.account || !this.account) {
|
|
68
|
+
throw new core_1.AccountNotFoundError();
|
|
69
|
+
}
|
|
70
|
+
const resolved = await (0, core_1.resolveProperties)(transaction);
|
|
71
|
+
const txHash = await this.provider.accountProvider.sendTransaction({
|
|
72
|
+
to: resolved.to,
|
|
73
|
+
data: hexlifyOptional(resolved.data),
|
|
74
|
+
chain: this.provider.accountProvider.chain,
|
|
75
|
+
account: this.account,
|
|
76
|
+
});
|
|
77
|
+
return this.provider.getTransaction(txHash);
|
|
78
|
+
}
|
|
79
|
+
signTransaction(_transaction) {
|
|
80
|
+
throw new Error("Transaction signing is not supported, use sendUserOperation instead");
|
|
81
|
+
}
|
|
82
|
+
getPublicErc4337Client() {
|
|
83
|
+
return this.provider.getBundlerClient();
|
|
84
|
+
}
|
|
85
|
+
connect(provider) {
|
|
86
|
+
this.provider = provider;
|
|
87
|
+
return this;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
exports.AccountSigner = AccountSigner;
|
|
91
|
+
//# sourceMappingURL=account-signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-signer.js","sourceRoot":"","sources":["../../src/account-signer.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n AccountNotFoundError,\n resolveProperties,\n type BatchUserOperationCallData,\n type BundlerClient,\n type GetEntryPointFromAccount,\n type SmartContractAccount,\n type UserOperationCallData,\n type UserOperationOverrides,\n} from \"@aa-sdk/core\";\nimport { Signer } from \"@ethersproject/abstract-signer\";\nimport { hexlify } from \"@ethersproject/bytes\";\nimport type { Deferrable } from \"@ethersproject/properties\";\nimport {\n type TransactionRequest,\n type TransactionResponse,\n} from \"@ethersproject/providers\";\nimport { isHex, toBytes, type Transport } from \"viem\";\nimport { EthersProviderAdapter } from \"./provider-adapter.js\";\n\nconst hexlifyOptional = (value: any): `0x${string}` | undefined => {\n if (value == null) {\n return undefined;\n }\n\n return hexlify(value) as `0x${string}`;\n};\n\nexport class AccountSigner<\n TAccount extends SmartContractAccount = SmartContractAccount,\n TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>\n> extends Signer {\n readonly account: TAccount;\n\n sendUserOperation;\n waitForUserOperationTransaction;\n\n constructor(public provider: EthersProviderAdapter, account: TAccount) {\n super();\n this.account = account;\n\n this.sendUserOperation = (\n args: UserOperationCallData | BatchUserOperationCallData,\n overrides?: UserOperationOverrides<TEntryPointVersion>\n ) =>\n this.provider.accountProvider.sendUserOperation({\n uo: args,\n account,\n overrides,\n });\n\n this.waitForUserOperationTransaction =\n this.provider.accountProvider.waitForUserOperationTransaction.bind(\n this.provider.accountProvider\n );\n }\n\n async getAddress(): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.address;\n }\n\n signMessage(message: string | Uint8Array): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.signMessage({\n message:\n typeof message === \"string\" && !isHex(message)\n ? message\n : { raw: isHex(message) ? toBytes(message) : message },\n });\n }\n\n async sendTransaction(\n transaction: Deferrable<TransactionRequest>\n ): Promise<TransactionResponse> {\n if (!this.provider.accountProvider.account || !this.account) {\n throw new AccountNotFoundError();\n }\n\n const resolved = await resolveProperties(transaction);\n const txHash = await this.provider.accountProvider.sendTransaction({\n to: resolved.to as `0x${string}` | undefined,\n data: hexlifyOptional(resolved.data),\n chain: this.provider.accountProvider.chain,\n account: this.account,\n });\n\n return this.provider.getTransaction(txHash);\n }\n\n signTransaction(\n _transaction: Deferrable<TransactionRequest>\n ): Promise<string> {\n throw new Error(\n \"Transaction signing is not supported, use sendUserOperation instead\"\n );\n }\n\n getPublicErc4337Client(): BundlerClient<Transport> {\n return this.provider.getBundlerClient();\n }\n\n connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {\n this.provider = provider;\n\n return this;\n }\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertWalletToAccountSigner = exports.convertEthersSignerToAccountSigner = exports.EthersProviderAdapter = exports.AccountSigner = void 0;
|
|
4
|
+
var account_signer_js_1 = require("./account-signer.js");
|
|
5
|
+
Object.defineProperty(exports, "AccountSigner", { enumerable: true, get: function () { return account_signer_js_1.AccountSigner; } });
|
|
6
|
+
var provider_adapter_js_1 = require("./provider-adapter.js");
|
|
7
|
+
Object.defineProperty(exports, "EthersProviderAdapter", { enumerable: true, get: function () { return provider_adapter_js_1.EthersProviderAdapter; } });
|
|
8
|
+
var utils_js_1 = require("./utils.js");
|
|
9
|
+
Object.defineProperty(exports, "convertEthersSignerToAccountSigner", { enumerable: true, get: function () { return utils_js_1.convertEthersSignerToAccountSigner; } });
|
|
10
|
+
Object.defineProperty(exports, "convertWalletToAccountSigner", { enumerable: true, get: function () { return utils_js_1.convertWalletToAccountSigner; } });
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;AAAA,yDAAoD;AAA3C,kHAAA,aAAa,OAAA;AACtB,6DAA8D;AAArD,4HAAA,qBAAqB,OAAA;AAC9B,uCAGoB;AAFlB,8HAAA,kCAAkC,OAAA;AAClC,wHAAA,4BAA4B,OAAA","sourcesContent":["export { AccountSigner } from \"./account-signer.js\";\nexport { EthersProviderAdapter } from \"./provider-adapter.js\";\nexport {\n convertEthersSignerToAccountSigner,\n convertWalletToAccountSigner,\n} from \"./utils.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
+
import { JsonRpcProvider } from "@ethersproject/providers";
|
|
3
|
+
import { type Transport } from "viem";
|
|
4
|
+
import { AccountSigner } from "./account-signer.js";
|
|
5
|
+
import type { EthersProviderAdapterOpts } from "./types.js";
|
|
6
|
+
export declare class EthersProviderAdapter extends JsonRpcProvider {
|
|
7
|
+
readonly accountProvider: SmartAccountClient;
|
|
8
|
+
constructor(opts: EthersProviderAdapterOpts);
|
|
9
|
+
send(method: any, params: any[]): Promise<any>;
|
|
10
|
+
connectToAccount<TAccount extends SmartContractAccount>(account: TAccount): AccountSigner<TAccount>;
|
|
11
|
+
getBundlerClient(): BundlerClient<Transport>;
|
|
12
|
+
static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter;
|
|
13
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EthersProviderAdapter = void 0;
|
|
4
|
+
const core_1 = require("@aa-sdk/core");
|
|
5
|
+
const providers_1 = require("@ethersproject/providers");
|
|
6
|
+
const viem_1 = require("viem");
|
|
7
|
+
const account_signer_js_1 = require("./account-signer.js");
|
|
8
|
+
class EthersProviderAdapter extends providers_1.JsonRpcProvider {
|
|
9
|
+
constructor(opts) {
|
|
10
|
+
super();
|
|
11
|
+
Object.defineProperty(this, "accountProvider", {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
configurable: true,
|
|
14
|
+
writable: true,
|
|
15
|
+
value: void 0
|
|
16
|
+
});
|
|
17
|
+
if ("accountProvider" in opts) {
|
|
18
|
+
this.accountProvider = opts.accountProvider;
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const chain = (0, core_1.getChain)(opts.chainId);
|
|
22
|
+
if (typeof opts.rpcProvider === "string") {
|
|
23
|
+
this.accountProvider = (0, core_1.createSmartAccountClient)({
|
|
24
|
+
transport: (0, viem_1.http)(opts.rpcProvider),
|
|
25
|
+
chain,
|
|
26
|
+
account: opts.account,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.accountProvider = (0, core_1.createSmartAccountClient)({
|
|
31
|
+
transport: (0, viem_1.custom)(opts.rpcProvider.transport),
|
|
32
|
+
chain,
|
|
33
|
+
account: opts.account,
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
send(method, params) {
|
|
39
|
+
return this.accountProvider.request({ method, params });
|
|
40
|
+
}
|
|
41
|
+
connectToAccount(account) {
|
|
42
|
+
return new account_signer_js_1.AccountSigner(this, account);
|
|
43
|
+
}
|
|
44
|
+
getBundlerClient() {
|
|
45
|
+
return (0, core_1.createBundlerClientFromExisting)((0, viem_1.createPublicClient)({
|
|
46
|
+
transport: (0, viem_1.custom)(this.accountProvider.transport),
|
|
47
|
+
chain: this.accountProvider.chain,
|
|
48
|
+
}));
|
|
49
|
+
}
|
|
50
|
+
static fromEthersProvider(provider) {
|
|
51
|
+
return new EthersProviderAdapter({
|
|
52
|
+
rpcProvider: provider.connection.url,
|
|
53
|
+
chainId: provider.network.chainId,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
exports.EthersProviderAdapter = EthersProviderAdapter;
|
|
58
|
+
//# sourceMappingURL=provider-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":";;;AAAA,uCAOsB;AACtB,wDAA2D;AAC3D,+BAAwE;AACxE,2DAAoD;AAKpD,MAAa,qBAAsB,SAAQ,2BAAe;IAGxD,YAAY,IAA+B;QACzC,KAAK,EAAE,CAAC;QAHD;;;;;WAAoC;QAI3C,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;gBACzC,IAAI,CAAC,eAAe,GAAG,IAAA,+BAAwB,EAAC;oBAC9C,SAAS,EAAE,IAAA,WAAI,EAAC,IAAI,CAAC,WAAW,CAAC;oBACjC,KAAK;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,eAAe,GAAG,IAAA,+BAAwB,EAAC;oBAC9C,SAAS,EAAE,IAAA,aAAM,EAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;oBAC7C,KAAK;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAUD,IAAI,CAAC,MAAW,EAAE,MAAa;QAE7B,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IAQD,gBAAgB,CACd,OAAiB;QAEjB,OAAO,IAAI,iCAAa,CAAW,IAAI,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,gBAAgB;QACd,OAAO,IAAA,sCAA+B,EACpC,IAAA,yBAAkB,EAAC;YACjB,SAAS,EAAE,IAAA,aAAM,EAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;YACjD,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,KAAM;SACnC,CAAC,CACH,CAAC;IACJ,CAAC;IAQD,MAAM,CAAC,kBAAkB,CAAC,QAAyB;QACjD,OAAO,IAAI,qBAAqB,CAAC;YAC/B,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG;YACpC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO;SAClC,CAAC,CAAC;IACL,CAAC;CACF;AAvED,sDAuEC","sourcesContent":["import {\n createBundlerClientFromExisting,\n createSmartAccountClient,\n getChain,\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { JsonRpcProvider } from \"@ethersproject/providers\";\nimport { createPublicClient, custom, http, type Transport } from \"viem\";\nimport { AccountSigner } from \"./account-signer.js\";\nimport type { EthersProviderAdapterOpts } from \"./types.js\";\n\n/** Lightweight Adapter for SmartAccountProvider to enable Signer Creation */\n// TODO: Add support for strong entry point version type\nexport class EthersProviderAdapter extends JsonRpcProvider {\n readonly accountProvider: SmartAccountClient;\n\n constructor(opts: EthersProviderAdapterOpts) {\n super();\n if (\"accountProvider\" in opts) {\n this.accountProvider = opts.accountProvider;\n } else {\n const chain = getChain(opts.chainId);\n if (typeof opts.rpcProvider === \"string\") {\n this.accountProvider = createSmartAccountClient({\n transport: http(opts.rpcProvider),\n chain,\n account: opts.account,\n });\n } else {\n this.accountProvider = createSmartAccountClient({\n transport: custom(opts.rpcProvider.transport),\n chain,\n account: opts.account,\n });\n }\n }\n }\n\n /**\n * Rewrites the send method to use the account provider's EIP-1193\n * compliant request method\n *\n * @param method - the RPC method to call\n * @param params - the params required by the RPC method\n * @returns the result of the RPC call\n */\n send(method: any, params: any[]): Promise<any> {\n // @ts-expect-error - viem is strongly typed on the request methods, but ethers is not\n return this.accountProvider.request({ method, params });\n }\n\n /**\n * Connects the Provider to an Account and returns a Signer\n *\n * @param account - the account to connect to\n * @returns an {@link AccountSigner} that can be used to sign and send user operations\n */\n connectToAccount<TAccount extends SmartContractAccount>(\n account: TAccount\n ): AccountSigner<TAccount> {\n return new AccountSigner<TAccount>(this, account);\n }\n\n getBundlerClient(): BundlerClient<Transport> {\n return createBundlerClientFromExisting(\n createPublicClient({\n transport: custom(this.accountProvider.transport),\n chain: this.accountProvider.chain!,\n })\n );\n }\n\n /**\n * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.\n *\n * @param provider - the ethers JSON RPC provider to convert\n * @returns an instance of {@link EthersProviderAdapter}\n */\n static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter {\n return new EthersProviderAdapter({\n rpcProvider: provider.connection.url,\n chainId: provider.network.chainId,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
+
import type { Chain, Transport } from "viem";
|
|
3
|
+
export type EthersProviderAdapterOpts<TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined> = {
|
|
4
|
+
account?: TAccount;
|
|
5
|
+
} & ({
|
|
6
|
+
rpcProvider: string | BundlerClient<TTransport>;
|
|
7
|
+
chainId: number;
|
|
8
|
+
} | {
|
|
9
|
+
accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Chain, Transport } from \"viem\";\n\nexport type EthersProviderAdapterOpts<\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n> = {\n account?: TAccount;\n} & (\n | {\n rpcProvider: string | BundlerClient<TTransport>;\n chainId: number;\n }\n | {\n accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;\n }\n);\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
+
import type { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
4
|
+
export declare const convertWalletToAccountSigner: (wallet: Wallet) => SmartAccountSigner<Wallet>;
|
|
5
|
+
export declare const convertEthersSignerToAccountSigner: (signer: Signer) => SmartAccountSigner<Signer>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertEthersSignerToAccountSigner = exports.convertWalletToAccountSigner = void 0;
|
|
4
|
+
const convertWalletToAccountSigner = (wallet) => {
|
|
5
|
+
return {
|
|
6
|
+
inner: wallet,
|
|
7
|
+
signerType: "local",
|
|
8
|
+
getAddress: async () => Promise.resolve(wallet.address),
|
|
9
|
+
signMessage: async (msg) => (await wallet.signMessage(typeof msg === "string" ? msg : msg.raw)),
|
|
10
|
+
signTypedData: async (params) => {
|
|
11
|
+
return (await wallet._signTypedData(params.domain ?? {}, params.types, params.message));
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
exports.convertWalletToAccountSigner = convertWalletToAccountSigner;
|
|
16
|
+
const convertEthersSignerToAccountSigner = (signer) => {
|
|
17
|
+
return {
|
|
18
|
+
inner: signer,
|
|
19
|
+
signerType: "json-rpc",
|
|
20
|
+
getAddress: async () => signer.getAddress(),
|
|
21
|
+
signMessage: async (msg) => (await signer.signMessage(typeof msg === "string" ? msg : msg.raw)),
|
|
22
|
+
signTypedData: async (_params) => {
|
|
23
|
+
throw new Error("signTypedData is not supported for ethers signers; use Wallet");
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
exports.convertEthersSignerToAccountSigner = convertEthersSignerToAccountSigner;
|
|
28
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAWO,MAAM,4BAA4B,GAAG,CAC1C,MAAc,EACc,EAAE;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,OAAO;QACnB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAwB,CAAC;QACxE,WAAW,EAAE,KAAK,EAAE,GAAoB,EAAE,EAAE,CAC1C,CAAC,MAAM,MAAM,CAAC,WAAW,CACvB,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CACxC,CAAkB;QACrB,aAAa,EAAE,KAAK,EAIlB,MAAqD,EACrD,EAAE;YACF,OAAO,CAAC,MAAM,MAAM,CAAC,cAAc,CACjC,MAAM,CAAC,MAAM,IAAI,EAAE,EAEnB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,OAAO,CACf,CAAkB,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,4BAA4B,gCAyBvC;AAQK,MAAM,kCAAkC,GAAG,CAChD,MAAc,EACc,EAAE;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,UAAU;QACtB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,UAAU,EAAsB;QAC/D,WAAW,EAAE,KAAK,EAAE,GAAoB,EAAE,EAAE,CAC1C,CAAC,MAAM,MAAM,CAAC,WAAW,CACvB,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CACxC,CAAkB;QACrB,aAAa,EAAE,KAAK,EAIlB,OAAsD,EACtD,EAAE;YACF,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,kCAAkC,sCAsB7C","sourcesContent":["import type { Address, SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Signer } from \"@ethersproject/abstract-signer\";\nimport { Wallet } from \"@ethersproject/wallet\";\nimport type { SignableMessage, TypedData, TypedDataDefinition } from \"viem\";\n\n/**\n * Converts a ethersjs Wallet to a SmartAccountSigner\n *\n * @param wallet - the Wallet to convert\n * @returns - a signer that can be used to sign and send user operations\n */\nexport const convertWalletToAccountSigner = (\n wallet: Wallet\n): SmartAccountSigner<Wallet> => {\n return {\n inner: wallet,\n signerType: \"local\",\n getAddress: async () => Promise.resolve(wallet.address as `0x${string}`),\n signMessage: async (msg: SignableMessage) =>\n (await wallet.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n return (await wallet._signTypedData(\n params.domain ?? {},\n // @ts-expect-error: these params should line up due to the spec for this function\n params.types,\n params.message\n )) as `0x${string}`;\n },\n };\n};\n\n/**\n * Converts a ethers.js Signer to a SmartAccountSigner\n *\n * @param signer - the Signer to convert\n * @returns - a signer that can be used to sign and send user operations\n */\nexport const convertEthersSignerToAccountSigner = (\n signer: Signer\n): SmartAccountSigner<Signer> => {\n return {\n inner: signer,\n signerType: \"json-rpc\",\n getAddress: async () => signer.getAddress() as Promise<Address>,\n signMessage: async (msg: SignableMessage) =>\n (await signer.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n _params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n throw new Error(\n \"signTypedData is not supported for ethers signers; use Wallet\"\n );\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { type BatchUserOperationCallData, type BundlerClient, type GetEntryPointFromAccount, type SmartContractAccount, type UserOperationCallData, type UserOperationOverrides } from "@aa-sdk/core";
|
|
2
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import type { Deferrable } from "@ethersproject/properties";
|
|
4
|
+
import { type TransactionRequest, type TransactionResponse } from "@ethersproject/providers";
|
|
5
|
+
import { type Transport } from "viem";
|
|
6
|
+
import { EthersProviderAdapter } from "./provider-adapter.js";
|
|
7
|
+
export declare class AccountSigner<TAccount extends SmartContractAccount = SmartContractAccount, TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>> extends Signer {
|
|
8
|
+
provider: EthersProviderAdapter;
|
|
9
|
+
readonly account: TAccount;
|
|
10
|
+
sendUserOperation: (args: UserOperationCallData | BatchUserOperationCallData, overrides?: UserOperationOverrides<TEntryPointVersion>) => Promise<import("@aa-sdk/core").SendUserOperationResult<keyof import("@aa-sdk/core").EntryPointRegistryBase<unknown>>>;
|
|
11
|
+
waitForUserOperationTransaction: (args: import("@aa-sdk/core").WaitForUserOperationTxParameters) => Promise<`0x${string}`>;
|
|
12
|
+
constructor(provider: EthersProviderAdapter, account: TAccount);
|
|
13
|
+
getAddress(): Promise<string>;
|
|
14
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
15
|
+
sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>;
|
|
16
|
+
signTransaction(_transaction: Deferrable<TransactionRequest>): Promise<string>;
|
|
17
|
+
getPublicErc4337Client(): BundlerClient<Transport>;
|
|
18
|
+
connect(provider: EthersProviderAdapter): AccountSigner<TAccount>;
|
|
19
|
+
}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { AccountNotFoundError, resolveProperties, } from "@aa-sdk/core";
|
|
2
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import { hexlify } from "@ethersproject/bytes";
|
|
4
|
+
import {} from "@ethersproject/providers";
|
|
5
|
+
import { isHex, toBytes } from "viem";
|
|
6
|
+
import { EthersProviderAdapter } from "./provider-adapter.js";
|
|
7
|
+
const hexlifyOptional = (value) => {
|
|
8
|
+
if (value == null) {
|
|
9
|
+
return undefined;
|
|
10
|
+
}
|
|
11
|
+
return hexlify(value);
|
|
12
|
+
};
|
|
13
|
+
export class AccountSigner extends Signer {
|
|
14
|
+
constructor(provider, account) {
|
|
15
|
+
super();
|
|
16
|
+
Object.defineProperty(this, "provider", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: provider
|
|
21
|
+
});
|
|
22
|
+
Object.defineProperty(this, "account", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
configurable: true,
|
|
25
|
+
writable: true,
|
|
26
|
+
value: void 0
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(this, "sendUserOperation", {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true,
|
|
32
|
+
value: void 0
|
|
33
|
+
});
|
|
34
|
+
Object.defineProperty(this, "waitForUserOperationTransaction", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: void 0
|
|
39
|
+
});
|
|
40
|
+
this.account = account;
|
|
41
|
+
this.sendUserOperation = (args, overrides) => this.provider.accountProvider.sendUserOperation({
|
|
42
|
+
uo: args,
|
|
43
|
+
account,
|
|
44
|
+
overrides,
|
|
45
|
+
});
|
|
46
|
+
this.waitForUserOperationTransaction =
|
|
47
|
+
this.provider.accountProvider.waitForUserOperationTransaction.bind(this.provider.accountProvider);
|
|
48
|
+
}
|
|
49
|
+
async getAddress() {
|
|
50
|
+
if (!this.account) {
|
|
51
|
+
throw new AccountNotFoundError();
|
|
52
|
+
}
|
|
53
|
+
return this.account.address;
|
|
54
|
+
}
|
|
55
|
+
signMessage(message) {
|
|
56
|
+
if (!this.account) {
|
|
57
|
+
throw new AccountNotFoundError();
|
|
58
|
+
}
|
|
59
|
+
return this.account.signMessage({
|
|
60
|
+
message: typeof message === "string" && !isHex(message)
|
|
61
|
+
? message
|
|
62
|
+
: { raw: isHex(message) ? toBytes(message) : message },
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
async sendTransaction(transaction) {
|
|
66
|
+
if (!this.provider.accountProvider.account || !this.account) {
|
|
67
|
+
throw new AccountNotFoundError();
|
|
68
|
+
}
|
|
69
|
+
const resolved = await resolveProperties(transaction);
|
|
70
|
+
const txHash = await this.provider.accountProvider.sendTransaction({
|
|
71
|
+
to: resolved.to,
|
|
72
|
+
data: hexlifyOptional(resolved.data),
|
|
73
|
+
chain: this.provider.accountProvider.chain,
|
|
74
|
+
account: this.account,
|
|
75
|
+
});
|
|
76
|
+
return this.provider.getTransaction(txHash);
|
|
77
|
+
}
|
|
78
|
+
signTransaction(_transaction) {
|
|
79
|
+
throw new Error("Transaction signing is not supported, use sendUserOperation instead");
|
|
80
|
+
}
|
|
81
|
+
getPublicErc4337Client() {
|
|
82
|
+
return this.provider.getBundlerClient();
|
|
83
|
+
}
|
|
84
|
+
connect(provider) {
|
|
85
|
+
this.provider = provider;
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
//# sourceMappingURL=account-signer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-signer.js","sourceRoot":"","sources":["../../src/account-signer.ts"],"names":[],"mappings":"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","sourcesContent":["import {\n AccountNotFoundError,\n resolveProperties,\n type BatchUserOperationCallData,\n type BundlerClient,\n type GetEntryPointFromAccount,\n type SmartContractAccount,\n type UserOperationCallData,\n type UserOperationOverrides,\n} from \"@aa-sdk/core\";\nimport { Signer } from \"@ethersproject/abstract-signer\";\nimport { hexlify } from \"@ethersproject/bytes\";\nimport type { Deferrable } from \"@ethersproject/properties\";\nimport {\n type TransactionRequest,\n type TransactionResponse,\n} from \"@ethersproject/providers\";\nimport { isHex, toBytes, type Transport } from \"viem\";\nimport { EthersProviderAdapter } from \"./provider-adapter.js\";\n\nconst hexlifyOptional = (value: any): `0x${string}` | undefined => {\n if (value == null) {\n return undefined;\n }\n\n return hexlify(value) as `0x${string}`;\n};\n\nexport class AccountSigner<\n TAccount extends SmartContractAccount = SmartContractAccount,\n TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>\n> extends Signer {\n readonly account: TAccount;\n\n sendUserOperation;\n waitForUserOperationTransaction;\n\n constructor(public provider: EthersProviderAdapter, account: TAccount) {\n super();\n this.account = account;\n\n this.sendUserOperation = (\n args: UserOperationCallData | BatchUserOperationCallData,\n overrides?: UserOperationOverrides<TEntryPointVersion>\n ) =>\n this.provider.accountProvider.sendUserOperation({\n uo: args,\n account,\n overrides,\n });\n\n this.waitForUserOperationTransaction =\n this.provider.accountProvider.waitForUserOperationTransaction.bind(\n this.provider.accountProvider\n );\n }\n\n async getAddress(): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.address;\n }\n\n signMessage(message: string | Uint8Array): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.signMessage({\n message:\n typeof message === \"string\" && !isHex(message)\n ? message\n : { raw: isHex(message) ? toBytes(message) : message },\n });\n }\n\n async sendTransaction(\n transaction: Deferrable<TransactionRequest>\n ): Promise<TransactionResponse> {\n if (!this.provider.accountProvider.account || !this.account) {\n throw new AccountNotFoundError();\n }\n\n const resolved = await resolveProperties(transaction);\n const txHash = await this.provider.accountProvider.sendTransaction({\n to: resolved.to as `0x${string}` | undefined,\n data: hexlifyOptional(resolved.data),\n chain: this.provider.accountProvider.chain,\n account: this.account,\n });\n\n return this.provider.getTransaction(txHash);\n }\n\n signTransaction(\n _transaction: Deferrable<TransactionRequest>\n ): Promise<string> {\n throw new Error(\n \"Transaction signing is not supported, use sendUserOperation instead\"\n );\n }\n\n getPublicErc4337Client(): BundlerClient<Transport> {\n return this.provider.getBundlerClient();\n }\n\n connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {\n this.provider = provider;\n\n return this;\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACL,kCAAkC,EAClC,4BAA4B,GAC7B,MAAM,YAAY,CAAC","sourcesContent":["export { AccountSigner } from \"./account-signer.js\";\nexport { EthersProviderAdapter } from \"./provider-adapter.js\";\nexport {\n convertEthersSignerToAccountSigner,\n convertWalletToAccountSigner,\n} from \"./utils.js\";\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
+
import { JsonRpcProvider } from "@ethersproject/providers";
|
|
3
|
+
import { type Transport } from "viem";
|
|
4
|
+
import { AccountSigner } from "./account-signer.js";
|
|
5
|
+
import type { EthersProviderAdapterOpts } from "./types.js";
|
|
6
|
+
export declare class EthersProviderAdapter extends JsonRpcProvider {
|
|
7
|
+
readonly accountProvider: SmartAccountClient;
|
|
8
|
+
constructor(opts: EthersProviderAdapterOpts);
|
|
9
|
+
send(method: any, params: any[]): Promise<any>;
|
|
10
|
+
connectToAccount<TAccount extends SmartContractAccount>(account: TAccount): AccountSigner<TAccount>;
|
|
11
|
+
getBundlerClient(): BundlerClient<Transport>;
|
|
12
|
+
static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter;
|
|
13
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { createBundlerClientFromExisting, createSmartAccountClient, getChain, } from "@aa-sdk/core";
|
|
2
|
+
import { JsonRpcProvider } from "@ethersproject/providers";
|
|
3
|
+
import { createPublicClient, custom, http } from "viem";
|
|
4
|
+
import { AccountSigner } from "./account-signer.js";
|
|
5
|
+
export class EthersProviderAdapter extends JsonRpcProvider {
|
|
6
|
+
constructor(opts) {
|
|
7
|
+
super();
|
|
8
|
+
Object.defineProperty(this, "accountProvider", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: void 0
|
|
13
|
+
});
|
|
14
|
+
if ("accountProvider" in opts) {
|
|
15
|
+
this.accountProvider = opts.accountProvider;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
const chain = getChain(opts.chainId);
|
|
19
|
+
if (typeof opts.rpcProvider === "string") {
|
|
20
|
+
this.accountProvider = createSmartAccountClient({
|
|
21
|
+
transport: http(opts.rpcProvider),
|
|
22
|
+
chain,
|
|
23
|
+
account: opts.account,
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
this.accountProvider = createSmartAccountClient({
|
|
28
|
+
transport: custom(opts.rpcProvider.transport),
|
|
29
|
+
chain,
|
|
30
|
+
account: opts.account,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
send(method, params) {
|
|
36
|
+
return this.accountProvider.request({ method, params });
|
|
37
|
+
}
|
|
38
|
+
connectToAccount(account) {
|
|
39
|
+
return new AccountSigner(this, account);
|
|
40
|
+
}
|
|
41
|
+
getBundlerClient() {
|
|
42
|
+
return createBundlerClientFromExisting(createPublicClient({
|
|
43
|
+
transport: custom(this.accountProvider.transport),
|
|
44
|
+
chain: this.accountProvider.chain,
|
|
45
|
+
}));
|
|
46
|
+
}
|
|
47
|
+
static fromEthersProvider(provider) {
|
|
48
|
+
return new EthersProviderAdapter({
|
|
49
|
+
rpcProvider: provider.connection.url,
|
|
50
|
+
chainId: provider.network.chainId,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=provider-adapter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,EACxB,QAAQ,GAIT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,EAAkB,MAAM,MAAM,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKpD,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IAGxD,YAAY,IAA+B;QACzC,KAAK,EAAE,CAAC;QAHD;;;;;WAAoC;QAI3C,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;gBACzC,IAAI,CAAC,eAAe,GAAG,wBAAwB,CAAC;oBAC9C,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;oBACjC,KAAK;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,eAAe,GAAG,wBAAwB,CAAC;oBAC9C,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;oBAC7C,KAAK;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAUD,IAAI,CAAC,MAAW,EAAE,MAAa;QAE7B,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IAQD,gBAAgB,CACd,OAAiB;QAEjB,OAAO,IAAI,aAAa,CAAW,IAAI,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,gBAAgB;QACd,OAAO,+BAA+B,CACpC,kBAAkB,CAAC;YACjB,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;YACjD,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,KAAM;SACnC,CAAC,CACH,CAAC;IACJ,CAAC;IAQD,MAAM,CAAC,kBAAkB,CAAC,QAAyB;QACjD,OAAO,IAAI,qBAAqB,CAAC;YAC/B,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG;YACpC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO;SAClC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {\n createBundlerClientFromExisting,\n createSmartAccountClient,\n getChain,\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { JsonRpcProvider } from \"@ethersproject/providers\";\nimport { createPublicClient, custom, http, type Transport } from \"viem\";\nimport { AccountSigner } from \"./account-signer.js\";\nimport type { EthersProviderAdapterOpts } from \"./types.js\";\n\n/** Lightweight Adapter for SmartAccountProvider to enable Signer Creation */\n// TODO: Add support for strong entry point version type\nexport class EthersProviderAdapter extends JsonRpcProvider {\n readonly accountProvider: SmartAccountClient;\n\n constructor(opts: EthersProviderAdapterOpts) {\n super();\n if (\"accountProvider\" in opts) {\n this.accountProvider = opts.accountProvider;\n } else {\n const chain = getChain(opts.chainId);\n if (typeof opts.rpcProvider === \"string\") {\n this.accountProvider = createSmartAccountClient({\n transport: http(opts.rpcProvider),\n chain,\n account: opts.account,\n });\n } else {\n this.accountProvider = createSmartAccountClient({\n transport: custom(opts.rpcProvider.transport),\n chain,\n account: opts.account,\n });\n }\n }\n }\n\n /**\n * Rewrites the send method to use the account provider's EIP-1193\n * compliant request method\n *\n * @param method - the RPC method to call\n * @param params - the params required by the RPC method\n * @returns the result of the RPC call\n */\n send(method: any, params: any[]): Promise<any> {\n // @ts-expect-error - viem is strongly typed on the request methods, but ethers is not\n return this.accountProvider.request({ method, params });\n }\n\n /**\n * Connects the Provider to an Account and returns a Signer\n *\n * @param account - the account to connect to\n * @returns an {@link AccountSigner} that can be used to sign and send user operations\n */\n connectToAccount<TAccount extends SmartContractAccount>(\n account: TAccount\n ): AccountSigner<TAccount> {\n return new AccountSigner<TAccount>(this, account);\n }\n\n getBundlerClient(): BundlerClient<Transport> {\n return createBundlerClientFromExisting(\n createPublicClient({\n transport: custom(this.accountProvider.transport),\n chain: this.accountProvider.chain!,\n })\n );\n }\n\n /**\n * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.\n *\n * @param provider - the ethers JSON RPC provider to convert\n * @returns an instance of {@link EthersProviderAdapter}\n */\n static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter {\n return new EthersProviderAdapter({\n rpcProvider: provider.connection.url,\n chainId: provider.network.chainId,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
+
import type { Chain, Transport } from "viem";
|
|
3
|
+
export type EthersProviderAdapterOpts<TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined> = {
|
|
4
|
+
account?: TAccount;
|
|
5
|
+
} & ({
|
|
6
|
+
rpcProvider: string | BundlerClient<TTransport>;
|
|
7
|
+
chainId: number;
|
|
8
|
+
} | {
|
|
9
|
+
accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
|
|
10
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,MAAM,cAAc,CAAC","sourcesContent":["import {\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Chain, Transport } from \"viem\";\n\nexport type EthersProviderAdapterOpts<\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n> = {\n account?: TAccount;\n} & (\n | {\n rpcProvider: string | BundlerClient<TTransport>;\n chainId: number;\n }\n | {\n accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;\n }\n);\n"]}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
+
import type { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
4
|
+
export declare const convertWalletToAccountSigner: (wallet: Wallet) => SmartAccountSigner<Wallet>;
|
|
5
|
+
export declare const convertEthersSignerToAccountSigner: (signer: Signer) => SmartAccountSigner<Signer>;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
2
|
+
export const convertWalletToAccountSigner = (wallet) => {
|
|
3
|
+
return {
|
|
4
|
+
inner: wallet,
|
|
5
|
+
signerType: "local",
|
|
6
|
+
getAddress: async () => Promise.resolve(wallet.address),
|
|
7
|
+
signMessage: async (msg) => (await wallet.signMessage(typeof msg === "string" ? msg : msg.raw)),
|
|
8
|
+
signTypedData: async (params) => {
|
|
9
|
+
return (await wallet._signTypedData(params.domain ?? {}, params.types, params.message));
|
|
10
|
+
},
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export const convertEthersSignerToAccountSigner = (signer) => {
|
|
14
|
+
return {
|
|
15
|
+
inner: signer,
|
|
16
|
+
signerType: "json-rpc",
|
|
17
|
+
getAddress: async () => signer.getAddress(),
|
|
18
|
+
signMessage: async (msg) => (await signer.signMessage(typeof msg === "string" ? msg : msg.raw)),
|
|
19
|
+
signTypedData: async (_params) => {
|
|
20
|
+
throw new Error("signTypedData is not supported for ethers signers; use Wallet");
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAS/C,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,MAAc,EACc,EAAE;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,OAAO;QACnB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAwB,CAAC;QACxE,WAAW,EAAE,KAAK,EAAE,GAAoB,EAAE,EAAE,CAC1C,CAAC,MAAM,MAAM,CAAC,WAAW,CACvB,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CACxC,CAAkB;QACrB,aAAa,EAAE,KAAK,EAIlB,MAAqD,EACrD,EAAE;YACF,OAAO,CAAC,MAAM,MAAM,CAAC,cAAc,CACjC,MAAM,CAAC,MAAM,IAAI,EAAE,EAEnB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,OAAO,CACf,CAAkB,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAQF,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,MAAc,EACc,EAAE;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,UAAU;QACtB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,UAAU,EAAsB;QAC/D,WAAW,EAAE,KAAK,EAAE,GAAoB,EAAE,EAAE,CAC1C,CAAC,MAAM,MAAM,CAAC,WAAW,CACvB,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CACxC,CAAkB;QACrB,aAAa,EAAE,KAAK,EAIlB,OAAsD,EACtD,EAAE;YACF,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Address, SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Signer } from \"@ethersproject/abstract-signer\";\nimport { Wallet } from \"@ethersproject/wallet\";\nimport type { SignableMessage, TypedData, TypedDataDefinition } from \"viem\";\n\n/**\n * Converts a ethersjs Wallet to a SmartAccountSigner\n *\n * @param wallet - the Wallet to convert\n * @returns - a signer that can be used to sign and send user operations\n */\nexport const convertWalletToAccountSigner = (\n wallet: Wallet\n): SmartAccountSigner<Wallet> => {\n return {\n inner: wallet,\n signerType: \"local\",\n getAddress: async () => Promise.resolve(wallet.address as `0x${string}`),\n signMessage: async (msg: SignableMessage) =>\n (await wallet.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n return (await wallet._signTypedData(\n params.domain ?? {},\n // @ts-expect-error: these params should line up due to the spec for this function\n params.types,\n params.message\n )) as `0x${string}`;\n },\n };\n};\n\n/**\n * Converts a ethers.js Signer to a SmartAccountSigner\n *\n * @param signer - the Signer to convert\n * @returns - a signer that can be used to sign and send user operations\n */\nexport const convertEthersSignerToAccountSigner = (\n signer: Signer\n): SmartAccountSigner<Signer> => {\n return {\n inner: signer,\n signerType: \"json-rpc\",\n getAddress: async () => signer.getAddress() as Promise<Address>,\n signMessage: async (msg: SignableMessage) =>\n (await signer.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n _params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n throw new Error(\n \"signTypedData is not supported for ethers signers; use Wallet\"\n );\n },\n };\n};\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { type BatchUserOperationCallData, type BundlerClient, type GetEntryPointFromAccount, type SmartContractAccount, type UserOperationCallData, type UserOperationOverrides } from "@aa-sdk/core";
|
|
2
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import type { Deferrable } from "@ethersproject/properties";
|
|
4
|
+
import { type TransactionRequest, type TransactionResponse } from "@ethersproject/providers";
|
|
5
|
+
import { type Transport } from "viem";
|
|
6
|
+
import { EthersProviderAdapter } from "./provider-adapter.js";
|
|
7
|
+
export declare class AccountSigner<TAccount extends SmartContractAccount = SmartContractAccount, TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>> extends Signer {
|
|
8
|
+
provider: EthersProviderAdapter;
|
|
9
|
+
readonly account: TAccount;
|
|
10
|
+
sendUserOperation: (args: UserOperationCallData | BatchUserOperationCallData, overrides?: UserOperationOverrides<TEntryPointVersion>) => Promise<import("@aa-sdk/core").SendUserOperationResult<keyof import("@aa-sdk/core").EntryPointRegistryBase<unknown>>>;
|
|
11
|
+
waitForUserOperationTransaction: (args: import("@aa-sdk/core").WaitForUserOperationTxParameters) => Promise<`0x${string}`>;
|
|
12
|
+
constructor(provider: EthersProviderAdapter, account: TAccount);
|
|
13
|
+
getAddress(): Promise<string>;
|
|
14
|
+
signMessage(message: string | Uint8Array): Promise<string>;
|
|
15
|
+
sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>;
|
|
16
|
+
signTransaction(_transaction: Deferrable<TransactionRequest>): Promise<string>;
|
|
17
|
+
getPublicErc4337Client(): BundlerClient<Transport>;
|
|
18
|
+
connect(provider: EthersProviderAdapter): AccountSigner<TAccount>;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=account-signer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"account-signer.d.ts","sourceRoot":"","sources":["../../src/account-signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,MAAM,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAU9D,qBAAa,aAAa,CACxB,QAAQ,SAAS,oBAAoB,GAAG,oBAAoB,EAC5D,kBAAkB,SAAS,wBAAwB,CAAC,QAAQ,CAAC,GAAG,wBAAwB,CAAC,QAAQ,CAAC,CAClG,SAAQ,MAAM;IAMK,QAAQ,EAAE,qBAAqB;IALlD,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC;IAE3B,iBAAiB,SAQP,qBAAqB,GAAG,0BAA0B,cAC5C,uBAAuB,kBAAkB,CAAC,2HATxC;IAClB,+BAA+B,4FAAC;gBAEb,QAAQ,EAAE,qBAAqB,EAAE,OAAO,EAAE,QAAQ;IAoB/D,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAQnC,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAapD,eAAe,CACnB,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,GAC1C,OAAO,CAAC,mBAAmB,CAAC;IAgB/B,eAAe,CACb,YAAY,EAAE,UAAU,CAAC,kBAAkB,CAAC,GAC3C,OAAO,CAAC,MAAM,CAAC;IAMlB,sBAAsB,IAAI,aAAa,CAAC,SAAS,CAAC;IAIlD,OAAO,CAAC,QAAQ,EAAE,qBAAqB,GAAG,aAAa,CAAC,QAAQ,CAAC;CAKlE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC9D,OAAO,EACL,kCAAkC,EAClC,4BAA4B,GAC7B,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
+
import { JsonRpcProvider } from "@ethersproject/providers";
|
|
3
|
+
import { type Transport } from "viem";
|
|
4
|
+
import { AccountSigner } from "./account-signer.js";
|
|
5
|
+
import type { EthersProviderAdapterOpts } from "./types.js";
|
|
6
|
+
/** Lightweight Adapter for SmartAccountProvider to enable Signer Creation */
|
|
7
|
+
export declare class EthersProviderAdapter extends JsonRpcProvider {
|
|
8
|
+
readonly accountProvider: SmartAccountClient;
|
|
9
|
+
constructor(opts: EthersProviderAdapterOpts);
|
|
10
|
+
/**
|
|
11
|
+
* Rewrites the send method to use the account provider's EIP-1193
|
|
12
|
+
* compliant request method
|
|
13
|
+
*
|
|
14
|
+
* @param method - the RPC method to call
|
|
15
|
+
* @param params - the params required by the RPC method
|
|
16
|
+
* @returns the result of the RPC call
|
|
17
|
+
*/
|
|
18
|
+
send(method: any, params: any[]): Promise<any>;
|
|
19
|
+
/**
|
|
20
|
+
* Connects the Provider to an Account and returns a Signer
|
|
21
|
+
*
|
|
22
|
+
* @param account - the account to connect to
|
|
23
|
+
* @returns an {@link AccountSigner} that can be used to sign and send user operations
|
|
24
|
+
*/
|
|
25
|
+
connectToAccount<TAccount extends SmartContractAccount>(account: TAccount): AccountSigner<TAccount>;
|
|
26
|
+
getBundlerClient(): BundlerClient<Transport>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.
|
|
29
|
+
*
|
|
30
|
+
* @param provider - the ethers JSON RPC provider to convert
|
|
31
|
+
* @returns an instance of {@link EthersProviderAdapter}
|
|
32
|
+
*/
|
|
33
|
+
static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=provider-adapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-adapter.d.ts","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,MAAM,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,6EAA6E;AAE7E,qBAAa,qBAAsB,SAAQ,eAAe;IACxD,QAAQ,CAAC,eAAe,EAAE,kBAAkB,CAAC;gBAEjC,IAAI,EAAE,yBAAyB;IAsB3C;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAK9C;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,SAAS,oBAAoB,EACpD,OAAO,EAAE,QAAQ,GAChB,aAAa,CAAC,QAAQ,CAAC;IAI1B,gBAAgB,IAAI,aAAa,CAAC,SAAS,CAAC;IAS5C;;;;;OAKG;IACH,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,qBAAqB;CAM5E"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
|
|
2
|
+
import type { Chain, Transport } from "viem";
|
|
3
|
+
export type EthersProviderAdapterOpts<TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends SmartContractAccount | undefined = SmartContractAccount | undefined> = {
|
|
4
|
+
account?: TAccount;
|
|
5
|
+
} & ({
|
|
6
|
+
rpcProvider: string | BundlerClient<TTransport>;
|
|
7
|
+
chainId: number;
|
|
8
|
+
} | {
|
|
9
|
+
accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAE7C,MAAM,MAAM,yBAAyB,CACnC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,QAAQ,SAAS,oBAAoB,GAAG,SAAS,GAC7C,oBAAoB,GACpB,SAAS,IACX;IACF,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB,GAAG,CACA;IACE,WAAW,EAAE,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,eAAe,EAAE,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;CACnE,CACJ,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
+
import type { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
4
|
+
/**
|
|
5
|
+
* Converts a ethersjs Wallet to a SmartAccountSigner
|
|
6
|
+
*
|
|
7
|
+
* @param wallet - the Wallet to convert
|
|
8
|
+
* @returns - a signer that can be used to sign and send user operations
|
|
9
|
+
*/
|
|
10
|
+
export declare const convertWalletToAccountSigner: (wallet: Wallet) => SmartAccountSigner<Wallet>;
|
|
11
|
+
/**
|
|
12
|
+
* Converts a ethers.js Signer to a SmartAccountSigner
|
|
13
|
+
*
|
|
14
|
+
* @param signer - the Signer to convert
|
|
15
|
+
* @returns - a signer that can be used to sign and send user operations
|
|
16
|
+
*/
|
|
17
|
+
export declare const convertEthersSignerToAccountSigner: (signer: Signer) => SmartAccountSigner<Signer>;
|
|
18
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAW,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAC7D,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,WAC/B,MAAM,KACb,mBAAmB,MAAM,CAuB3B,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kCAAkC,WACrC,MAAM,KACb,mBAAmB,MAAM,CAoB3B,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aa-sdk/ethers",
|
|
3
|
+
"license": "MIT",
|
|
4
|
+
"version": "4.0.0-alpha.0",
|
|
5
|
+
"description": "Ethers.js wrapper for @aa-sdk/core",
|
|
6
|
+
"author": "Alchemy",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "./dist/cjs/index.js",
|
|
9
|
+
"module": "./dist/esm/index.js",
|
|
10
|
+
"types": "./dist/types/index.d.ts",
|
|
11
|
+
"typings": "./dist/types/index.d.ts",
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"files": [
|
|
14
|
+
"dist",
|
|
15
|
+
"src/**/*.ts",
|
|
16
|
+
"!vitest.config.ts",
|
|
17
|
+
"!.env",
|
|
18
|
+
"!dist/**/*.tsbuildinfo",
|
|
19
|
+
"!src/**/*.test.ts",
|
|
20
|
+
"!src/__tests__/**/*"
|
|
21
|
+
],
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"types": "./dist/types/index.d.ts",
|
|
25
|
+
"import": "./dist/esm/index.js",
|
|
26
|
+
"default": "./dist/cjs/index.js"
|
|
27
|
+
},
|
|
28
|
+
"./package.json": "./package.json"
|
|
29
|
+
},
|
|
30
|
+
"publishConfig": {
|
|
31
|
+
"access": "public",
|
|
32
|
+
"registry": "https://registry.npmjs.org/"
|
|
33
|
+
},
|
|
34
|
+
"scripts": {
|
|
35
|
+
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
|
|
36
|
+
"build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
37
|
+
"build:esm": "tsc --project tsconfig.build.json --module es2020 --outDir ./dist/esm --removeComments && echo > ./dist/esm/package.json '{\"type\":\"module\"}'",
|
|
38
|
+
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
|
|
39
|
+
"clean": "rm -rf ./dist",
|
|
40
|
+
"test": "vitest",
|
|
41
|
+
"test:run": "vitest run",
|
|
42
|
+
"test:run-e2e": "vitest run --config vitest.config.e2e.ts"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"alchemy-sdk": "^3.0.0",
|
|
46
|
+
"dotenv": "^16.0.3",
|
|
47
|
+
"typescript": "^5.0.4",
|
|
48
|
+
"typescript-template": "*",
|
|
49
|
+
"vitest": "^0.31.0"
|
|
50
|
+
},
|
|
51
|
+
"dependencies": {
|
|
52
|
+
"@aa-sdk/core": "^4.0.0-alpha.0",
|
|
53
|
+
"@ethersproject/abi": "^5.7.0",
|
|
54
|
+
"@ethersproject/abstract-signer": "^5.7.0",
|
|
55
|
+
"@ethersproject/bytes": "^5.7.0",
|
|
56
|
+
"@ethersproject/contracts": "^5.7.0",
|
|
57
|
+
"@ethersproject/hash": "^5.7.0",
|
|
58
|
+
"@ethersproject/keccak256": "^5.7.0",
|
|
59
|
+
"@ethersproject/providers": "^5.7.2",
|
|
60
|
+
"@ethersproject/wallet": "^5.7.0",
|
|
61
|
+
"viem": "2.8.6"
|
|
62
|
+
},
|
|
63
|
+
"peerDependencies": {
|
|
64
|
+
"viem": "2.8.6"
|
|
65
|
+
},
|
|
66
|
+
"repository": {
|
|
67
|
+
"type": "git",
|
|
68
|
+
"url": "git+https://github.com/alchemyplatform/aa-sdk.git"
|
|
69
|
+
},
|
|
70
|
+
"bugs": {
|
|
71
|
+
"url": "https://github.com/alchemyplatform/aa-sdk/issues"
|
|
72
|
+
},
|
|
73
|
+
"gitHead": "bd1788c2bd7f28ba762a06c649f30b544f8bade9"
|
|
74
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AccountNotFoundError,
|
|
3
|
+
resolveProperties,
|
|
4
|
+
type BatchUserOperationCallData,
|
|
5
|
+
type BundlerClient,
|
|
6
|
+
type GetEntryPointFromAccount,
|
|
7
|
+
type SmartContractAccount,
|
|
8
|
+
type UserOperationCallData,
|
|
9
|
+
type UserOperationOverrides,
|
|
10
|
+
} from "@aa-sdk/core";
|
|
11
|
+
import { Signer } from "@ethersproject/abstract-signer";
|
|
12
|
+
import { hexlify } from "@ethersproject/bytes";
|
|
13
|
+
import type { Deferrable } from "@ethersproject/properties";
|
|
14
|
+
import {
|
|
15
|
+
type TransactionRequest,
|
|
16
|
+
type TransactionResponse,
|
|
17
|
+
} from "@ethersproject/providers";
|
|
18
|
+
import { isHex, toBytes, type Transport } from "viem";
|
|
19
|
+
import { EthersProviderAdapter } from "./provider-adapter.js";
|
|
20
|
+
|
|
21
|
+
const hexlifyOptional = (value: any): `0x${string}` | undefined => {
|
|
22
|
+
if (value == null) {
|
|
23
|
+
return undefined;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return hexlify(value) as `0x${string}`;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export class AccountSigner<
|
|
30
|
+
TAccount extends SmartContractAccount = SmartContractAccount,
|
|
31
|
+
TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>
|
|
32
|
+
> extends Signer {
|
|
33
|
+
readonly account: TAccount;
|
|
34
|
+
|
|
35
|
+
sendUserOperation;
|
|
36
|
+
waitForUserOperationTransaction;
|
|
37
|
+
|
|
38
|
+
constructor(public provider: EthersProviderAdapter, account: TAccount) {
|
|
39
|
+
super();
|
|
40
|
+
this.account = account;
|
|
41
|
+
|
|
42
|
+
this.sendUserOperation = (
|
|
43
|
+
args: UserOperationCallData | BatchUserOperationCallData,
|
|
44
|
+
overrides?: UserOperationOverrides<TEntryPointVersion>
|
|
45
|
+
) =>
|
|
46
|
+
this.provider.accountProvider.sendUserOperation({
|
|
47
|
+
uo: args,
|
|
48
|
+
account,
|
|
49
|
+
overrides,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
this.waitForUserOperationTransaction =
|
|
53
|
+
this.provider.accountProvider.waitForUserOperationTransaction.bind(
|
|
54
|
+
this.provider.accountProvider
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async getAddress(): Promise<string> {
|
|
59
|
+
if (!this.account) {
|
|
60
|
+
throw new AccountNotFoundError();
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return this.account.address;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
signMessage(message: string | Uint8Array): Promise<string> {
|
|
67
|
+
if (!this.account) {
|
|
68
|
+
throw new AccountNotFoundError();
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
return this.account.signMessage({
|
|
72
|
+
message:
|
|
73
|
+
typeof message === "string" && !isHex(message)
|
|
74
|
+
? message
|
|
75
|
+
: { raw: isHex(message) ? toBytes(message) : message },
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
async sendTransaction(
|
|
80
|
+
transaction: Deferrable<TransactionRequest>
|
|
81
|
+
): Promise<TransactionResponse> {
|
|
82
|
+
if (!this.provider.accountProvider.account || !this.account) {
|
|
83
|
+
throw new AccountNotFoundError();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const resolved = await resolveProperties(transaction);
|
|
87
|
+
const txHash = await this.provider.accountProvider.sendTransaction({
|
|
88
|
+
to: resolved.to as `0x${string}` | undefined,
|
|
89
|
+
data: hexlifyOptional(resolved.data),
|
|
90
|
+
chain: this.provider.accountProvider.chain,
|
|
91
|
+
account: this.account,
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
return this.provider.getTransaction(txHash);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
signTransaction(
|
|
98
|
+
_transaction: Deferrable<TransactionRequest>
|
|
99
|
+
): Promise<string> {
|
|
100
|
+
throw new Error(
|
|
101
|
+
"Transaction signing is not supported, use sendUserOperation instead"
|
|
102
|
+
);
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
getPublicErc4337Client(): BundlerClient<Transport> {
|
|
106
|
+
return this.provider.getBundlerClient();
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {
|
|
110
|
+
this.provider = provider;
|
|
111
|
+
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createBundlerClientFromExisting,
|
|
3
|
+
createSmartAccountClient,
|
|
4
|
+
getChain,
|
|
5
|
+
type BundlerClient,
|
|
6
|
+
type SmartAccountClient,
|
|
7
|
+
type SmartContractAccount,
|
|
8
|
+
} from "@aa-sdk/core";
|
|
9
|
+
import { JsonRpcProvider } from "@ethersproject/providers";
|
|
10
|
+
import { createPublicClient, custom, http, type Transport } from "viem";
|
|
11
|
+
import { AccountSigner } from "./account-signer.js";
|
|
12
|
+
import type { EthersProviderAdapterOpts } from "./types.js";
|
|
13
|
+
|
|
14
|
+
/** Lightweight Adapter for SmartAccountProvider to enable Signer Creation */
|
|
15
|
+
// TODO: Add support for strong entry point version type
|
|
16
|
+
export class EthersProviderAdapter extends JsonRpcProvider {
|
|
17
|
+
readonly accountProvider: SmartAccountClient;
|
|
18
|
+
|
|
19
|
+
constructor(opts: EthersProviderAdapterOpts) {
|
|
20
|
+
super();
|
|
21
|
+
if ("accountProvider" in opts) {
|
|
22
|
+
this.accountProvider = opts.accountProvider;
|
|
23
|
+
} else {
|
|
24
|
+
const chain = getChain(opts.chainId);
|
|
25
|
+
if (typeof opts.rpcProvider === "string") {
|
|
26
|
+
this.accountProvider = createSmartAccountClient({
|
|
27
|
+
transport: http(opts.rpcProvider),
|
|
28
|
+
chain,
|
|
29
|
+
account: opts.account,
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
this.accountProvider = createSmartAccountClient({
|
|
33
|
+
transport: custom(opts.rpcProvider.transport),
|
|
34
|
+
chain,
|
|
35
|
+
account: opts.account,
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Rewrites the send method to use the account provider's EIP-1193
|
|
43
|
+
* compliant request method
|
|
44
|
+
*
|
|
45
|
+
* @param method - the RPC method to call
|
|
46
|
+
* @param params - the params required by the RPC method
|
|
47
|
+
* @returns the result of the RPC call
|
|
48
|
+
*/
|
|
49
|
+
send(method: any, params: any[]): Promise<any> {
|
|
50
|
+
// @ts-expect-error - viem is strongly typed on the request methods, but ethers is not
|
|
51
|
+
return this.accountProvider.request({ method, params });
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Connects the Provider to an Account and returns a Signer
|
|
56
|
+
*
|
|
57
|
+
* @param account - the account to connect to
|
|
58
|
+
* @returns an {@link AccountSigner} that can be used to sign and send user operations
|
|
59
|
+
*/
|
|
60
|
+
connectToAccount<TAccount extends SmartContractAccount>(
|
|
61
|
+
account: TAccount
|
|
62
|
+
): AccountSigner<TAccount> {
|
|
63
|
+
return new AccountSigner<TAccount>(this, account);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
getBundlerClient(): BundlerClient<Transport> {
|
|
67
|
+
return createBundlerClientFromExisting(
|
|
68
|
+
createPublicClient({
|
|
69
|
+
transport: custom(this.accountProvider.transport),
|
|
70
|
+
chain: this.accountProvider.chain!,
|
|
71
|
+
})
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.
|
|
77
|
+
*
|
|
78
|
+
* @param provider - the ethers JSON RPC provider to convert
|
|
79
|
+
* @returns an instance of {@link EthersProviderAdapter}
|
|
80
|
+
*/
|
|
81
|
+
static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter {
|
|
82
|
+
return new EthersProviderAdapter({
|
|
83
|
+
rpcProvider: provider.connection.url,
|
|
84
|
+
chainId: provider.network.chainId,
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
package/src/types.ts
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type BundlerClient,
|
|
3
|
+
type SmartAccountClient,
|
|
4
|
+
type SmartContractAccount,
|
|
5
|
+
} from "@aa-sdk/core";
|
|
6
|
+
import type { Chain, Transport } from "viem";
|
|
7
|
+
|
|
8
|
+
export type EthersProviderAdapterOpts<
|
|
9
|
+
TTransport extends Transport = Transport,
|
|
10
|
+
TChain extends Chain = Chain,
|
|
11
|
+
TAccount extends SmartContractAccount | undefined =
|
|
12
|
+
| SmartContractAccount
|
|
13
|
+
| undefined
|
|
14
|
+
> = {
|
|
15
|
+
account?: TAccount;
|
|
16
|
+
} & (
|
|
17
|
+
| {
|
|
18
|
+
rpcProvider: string | BundlerClient<TTransport>;
|
|
19
|
+
chainId: number;
|
|
20
|
+
}
|
|
21
|
+
| {
|
|
22
|
+
accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
|
|
23
|
+
}
|
|
24
|
+
);
|
package/src/utils.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Address, SmartAccountSigner } from "@aa-sdk/core";
|
|
2
|
+
import type { Signer } from "@ethersproject/abstract-signer";
|
|
3
|
+
import { Wallet } from "@ethersproject/wallet";
|
|
4
|
+
import type { SignableMessage, TypedData, TypedDataDefinition } from "viem";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Converts a ethersjs Wallet to a SmartAccountSigner
|
|
8
|
+
*
|
|
9
|
+
* @param wallet - the Wallet to convert
|
|
10
|
+
* @returns - a signer that can be used to sign and send user operations
|
|
11
|
+
*/
|
|
12
|
+
export const convertWalletToAccountSigner = (
|
|
13
|
+
wallet: Wallet
|
|
14
|
+
): SmartAccountSigner<Wallet> => {
|
|
15
|
+
return {
|
|
16
|
+
inner: wallet,
|
|
17
|
+
signerType: "local",
|
|
18
|
+
getAddress: async () => Promise.resolve(wallet.address as `0x${string}`),
|
|
19
|
+
signMessage: async (msg: SignableMessage) =>
|
|
20
|
+
(await wallet.signMessage(
|
|
21
|
+
typeof msg === "string" ? msg : msg.raw
|
|
22
|
+
)) as `0x${string}`,
|
|
23
|
+
signTypedData: async <
|
|
24
|
+
const TTypedData extends TypedData | { [key: string]: unknown },
|
|
25
|
+
TPrimaryType extends string = string
|
|
26
|
+
>(
|
|
27
|
+
params: TypedDataDefinition<TTypedData, TPrimaryType>
|
|
28
|
+
) => {
|
|
29
|
+
return (await wallet._signTypedData(
|
|
30
|
+
params.domain ?? {},
|
|
31
|
+
// @ts-expect-error: these params should line up due to the spec for this function
|
|
32
|
+
params.types,
|
|
33
|
+
params.message
|
|
34
|
+
)) as `0x${string}`;
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Converts a ethers.js Signer to a SmartAccountSigner
|
|
41
|
+
*
|
|
42
|
+
* @param signer - the Signer to convert
|
|
43
|
+
* @returns - a signer that can be used to sign and send user operations
|
|
44
|
+
*/
|
|
45
|
+
export const convertEthersSignerToAccountSigner = (
|
|
46
|
+
signer: Signer
|
|
47
|
+
): SmartAccountSigner<Signer> => {
|
|
48
|
+
return {
|
|
49
|
+
inner: signer,
|
|
50
|
+
signerType: "json-rpc",
|
|
51
|
+
getAddress: async () => signer.getAddress() as Promise<Address>,
|
|
52
|
+
signMessage: async (msg: SignableMessage) =>
|
|
53
|
+
(await signer.signMessage(
|
|
54
|
+
typeof msg === "string" ? msg : msg.raw
|
|
55
|
+
)) as `0x${string}`,
|
|
56
|
+
signTypedData: async <
|
|
57
|
+
const TTypedData extends TypedData | { [key: string]: unknown },
|
|
58
|
+
TPrimaryType extends string = string
|
|
59
|
+
>(
|
|
60
|
+
_params: TypedDataDefinition<TTypedData, TPrimaryType>
|
|
61
|
+
) => {
|
|
62
|
+
throw new Error(
|
|
63
|
+
"signTypedData is not supported for ethers signers; use Wallet"
|
|
64
|
+
);
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
};
|