@aa-sdk/ethers 4.0.0-alpha.9 → 4.0.0-beta.1

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.
@@ -4,16 +4,186 @@ import type { Deferrable } from "@ethersproject/properties";
4
4
  import { type TransactionRequest, type TransactionResponse } from "@ethersproject/providers";
5
5
  import { type Transport } from "viem";
6
6
  import { EthersProviderAdapter } from "./provider-adapter.js";
7
+ /**
8
+ * Implementation of the ethers Signer interface to use with Smart Contract Accounts
9
+ */
7
10
  export declare class AccountSigner<TAccount extends SmartContractAccount = SmartContractAccount, TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>> extends Signer {
8
11
  provider: EthersProviderAdapter;
9
12
  readonly account: TAccount;
10
13
  sendUserOperation: (args: UserOperationCallData | BatchUserOperationCallData, overrides?: UserOperationOverrides<TEntryPointVersion>) => Promise<import("@aa-sdk/core").SendUserOperationResult<keyof import("@aa-sdk/core").EntryPointRegistryBase<unknown>>>;
11
14
  waitForUserOperationTransaction: (args: import("@aa-sdk/core").WaitForUserOperationTxParameters) => Promise<`0x${string}`>;
15
+ /**
16
+ * Creates a new AccountSigner with the given ethers Provider and Smart Contract Account
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
21
+ * import { LocalAccountSigner } from "@aa-sdk/core";
22
+ * import { sepolia } from "@account-kit/infra";
23
+ * import { createLightAccount } from "@account-kit/smart-contracts";
24
+ * import { http } from "viem";
25
+ *
26
+ * const account = await createLightAccount({
27
+ * transport: http("https://rpc.testnet.aepps.com"),
28
+ * chain: sepolia,
29
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
30
+ * });
31
+ *
32
+ * const provider = new EthersProviderAdapter();
33
+ * const signer = new AccountSigner(provider, account);
34
+ * ```
35
+ *
36
+ * @template {SmartContractAccount} TAccount the type of the smart contract account
37
+ * @param {EthersProviderAdapter} provider the ethers provider to use
38
+ * @param {TAccount} account the smart contract account that will be used to sign user ops and send them
39
+ */
12
40
  constructor(provider: EthersProviderAdapter, account: TAccount);
13
- getAddress(): Promise<string>;
41
+ /**
42
+ * Returns the account address if the account exists.
43
+ *
44
+ * @example
45
+ * ```ts
46
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
47
+ * import { LocalAccountSigner } from "@aa-sdk/core";
48
+ * import { sepolia } from "@account-kit/infra";
49
+ * import { createLightAccount } from "@account-kit/smart-contracts";
50
+ * import { http } from "viem";
51
+ *
52
+ * const account = await createLightAccount({
53
+ * transport: http("https://rpc.testnet.aepps.com"),
54
+ * chain: sepolia,
55
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
56
+ * });
57
+ *
58
+ * const provider = new EthersProviderAdapter();
59
+ * const signer = new AccountSigner(provider, account);
60
+ *
61
+ * const address = await signer.getAddress();
62
+ * ```
63
+ *
64
+ * @returns {Promise<string>} a promise that resolves to the account address
65
+ * @throws {AccountNotFoundError} if the account is not found
66
+ */ getAddress(): Promise<string>;
67
+ /**
68
+ * Signs a message using the associated account.
69
+ *
70
+ * @example
71
+ * ```ts
72
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
73
+ * import { LocalAccountSigner } from "@aa-sdk/core";
74
+ * import { sepolia } from "@account-kit/infra";
75
+ * import { createLightAccount } from "@account-kit/smart-contracts";
76
+ * import { http } from "viem";
77
+ *
78
+ * const account = await createLightAccount({
79
+ * transport: http("https://rpc.testnet.aepps.com"),
80
+ * chain: sepolia,
81
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
82
+ * });
83
+ *
84
+ * const provider = new EthersProviderAdapter();
85
+ * const signer = new AccountSigner(provider, account);
86
+ *
87
+ * const message = await signer.signMessage("hello");
88
+ * ```
89
+ *
90
+ * @param {string | Uint8Array} message the message to be signed
91
+ * @returns {Promise<string>} a promise that resolves to the signed message
92
+ * @throws {AccountNotFoundError} if the account is not found
93
+ */
14
94
  signMessage(message: string | Uint8Array): Promise<string>;
95
+ /**
96
+ * Sends a transaction using the account provider and returns the transaction response.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
101
+ * import { LocalAccountSigner } from "@aa-sdk/core";
102
+ * import { sepolia } from "@account-kit/infra";
103
+ * import { createLightAccount } from "@account-kit/smart-contracts";
104
+ * import { http } from "viem";
105
+ *
106
+ * const account = await createLightAccount({
107
+ * transport: http("https://rpc.testnet.aepps.com"),
108
+ * chain: sepolia,
109
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
110
+ * });
111
+ *
112
+ * const provider = new EthersProviderAdapter();
113
+ * const signer = new AccountSigner(provider, account);
114
+ *
115
+ * const tx = await signer.sendTransaction({
116
+ * to: "0x1234567890123456789012345678901234567890",
117
+ * value: "0x0",
118
+ * data: "0x",
119
+ * });
120
+ * ```
121
+ *
122
+ * @param {Deferrable<TransactionRequest>} transaction the transaction request to be sent
123
+ * @returns {Promise<TransactionResponse>} a promise that resolves to the transaction response
124
+ * @throws {AccountNotFoundError} if the account is not found in the provider
125
+ */
15
126
  sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>;
127
+ /**
128
+ * Throws an error indicating that transaction signing is not supported and advises to use `sendUserOperation` instead.
129
+ *
130
+ * @param {Deferrable<TransactionRequest>} _transaction The transaction request
131
+ * @throws {Error} Will always throw an error indicating transaction signing is unsupported
132
+ */
16
133
  signTransaction(_transaction: Deferrable<TransactionRequest>): Promise<string>;
134
+ /**
135
+ * Retrieves the BundlerClient instance from the provider.
136
+ *
137
+ * @example
138
+ * ```ts
139
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
140
+ * import { LocalAccountSigner } from "@aa-sdk/core";
141
+ * import { sepolia } from "@account-kit/infra";
142
+ * import { createLightAccount } from "@account-kit/smart-contracts";
143
+ * import { http } from "viem";
144
+ *
145
+ * const account = await createLightAccount({
146
+ * transport: http("https://rpc.testnet.aepps.com"),
147
+ * chain: sepolia,
148
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
149
+ * });
150
+ *
151
+ * const provider = new EthersProviderAdapter();
152
+ * const signer = new AccountSigner(provider, account);
153
+ *
154
+ * const bundler = signer.getBundlerClient();
155
+ * ```
156
+ *
157
+ * @returns {BundlerClient<Transport>} The BundlerClient instance
158
+ */
17
159
  getBundlerClient(): BundlerClient<Transport>;
160
+ /**
161
+ * Sets the provider for the account signer and returns the updated account signer instance.
162
+ * Note: this is not necessary since the Provider is required by the constructor. This is useful
163
+ * if you want to change the provider after the account signer has been created.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
168
+ * import { LocalAccountSigner } from "@aa-sdk/core";
169
+ * import { sepolia } from "@account-kit/infra";
170
+ * import { createLightAccount } from "@account-kit/smart-contracts";
171
+ * import { http } from "viem";
172
+ *
173
+ * const account = await createLightAccount({
174
+ * transport: http("https://rpc.testnet.aepps.com"),
175
+ * chain: sepolia,
176
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
177
+ * });
178
+ *
179
+ * const provider = new EthersProviderAdapter();
180
+ * const signer = new AccountSigner(provider, account);
181
+ *
182
+ * signer.connect(provider);
183
+ * ```
184
+ *
185
+ * @param {EthersProviderAdapter} provider the provider to be set for the account signer
186
+ * @returns {AccountSigner<TAccount>} the updated account signer instance
187
+ */
18
188
  connect(provider: EthersProviderAdapter): AccountSigner<TAccount>;
19
189
  }
@@ -10,7 +10,35 @@ const hexlifyOptional = (value) => {
10
10
  }
11
11
  return hexlify(value);
12
12
  };
13
+ /**
14
+ * Implementation of the ethers Signer interface to use with Smart Contract Accounts
15
+ */
13
16
  export class AccountSigner extends Signer {
17
+ /**
18
+ * Creates a new AccountSigner with the given ethers Provider and Smart Contract Account
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
23
+ * import { LocalAccountSigner } from "@aa-sdk/core";
24
+ * import { sepolia } from "@account-kit/infra";
25
+ * import { createLightAccount } from "@account-kit/smart-contracts";
26
+ * import { http } from "viem";
27
+ *
28
+ * const account = await createLightAccount({
29
+ * transport: http("https://rpc.testnet.aepps.com"),
30
+ * chain: sepolia,
31
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
32
+ * });
33
+ *
34
+ * const provider = new EthersProviderAdapter();
35
+ * const signer = new AccountSigner(provider, account);
36
+ * ```
37
+ *
38
+ * @template {SmartContractAccount} TAccount the type of the smart contract account
39
+ * @param {EthersProviderAdapter} provider the ethers provider to use
40
+ * @param {TAccount} account the smart contract account that will be used to sign user ops and send them
41
+ */
14
42
  constructor(provider, account) {
15
43
  super();
16
44
  Object.defineProperty(this, "provider", {
@@ -46,12 +74,64 @@ export class AccountSigner extends Signer {
46
74
  this.waitForUserOperationTransaction =
47
75
  this.provider.accountProvider.waitForUserOperationTransaction.bind(this.provider.accountProvider);
48
76
  }
49
- async getAddress() {
77
+ /**
78
+ * Returns the account address if the account exists.
79
+ *
80
+ * @example
81
+ * ```ts
82
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
83
+ * import { LocalAccountSigner } from "@aa-sdk/core";
84
+ * import { sepolia } from "@account-kit/infra";
85
+ * import { createLightAccount } from "@account-kit/smart-contracts";
86
+ * import { http } from "viem";
87
+ *
88
+ * const account = await createLightAccount({
89
+ * transport: http("https://rpc.testnet.aepps.com"),
90
+ * chain: sepolia,
91
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
92
+ * });
93
+ *
94
+ * const provider = new EthersProviderAdapter();
95
+ * const signer = new AccountSigner(provider, account);
96
+ *
97
+ * const address = await signer.getAddress();
98
+ * ```
99
+ *
100
+ * @returns {Promise<string>} a promise that resolves to the account address
101
+ * @throws {AccountNotFoundError} if the account is not found
102
+ */ async getAddress() {
50
103
  if (!this.account) {
51
104
  throw new AccountNotFoundError();
52
105
  }
53
106
  return this.account.address;
54
107
  }
108
+ /**
109
+ * Signs a message using the associated account.
110
+ *
111
+ * @example
112
+ * ```ts
113
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
114
+ * import { LocalAccountSigner } from "@aa-sdk/core";
115
+ * import { sepolia } from "@account-kit/infra";
116
+ * import { createLightAccount } from "@account-kit/smart-contracts";
117
+ * import { http } from "viem";
118
+ *
119
+ * const account = await createLightAccount({
120
+ * transport: http("https://rpc.testnet.aepps.com"),
121
+ * chain: sepolia,
122
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
123
+ * });
124
+ *
125
+ * const provider = new EthersProviderAdapter();
126
+ * const signer = new AccountSigner(provider, account);
127
+ *
128
+ * const message = await signer.signMessage("hello");
129
+ * ```
130
+ *
131
+ * @param {string | Uint8Array} message the message to be signed
132
+ * @returns {Promise<string>} a promise that resolves to the signed message
133
+ * @throws {AccountNotFoundError} if the account is not found
134
+ */
55
135
  signMessage(message) {
56
136
  if (!this.account) {
57
137
  throw new AccountNotFoundError();
@@ -62,6 +142,37 @@ export class AccountSigner extends Signer {
62
142
  : { raw: isHex(message) ? toBytes(message) : message },
63
143
  });
64
144
  }
145
+ /**
146
+ * Sends a transaction using the account provider and returns the transaction response.
147
+ *
148
+ * @example
149
+ * ```ts
150
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
151
+ * import { LocalAccountSigner } from "@aa-sdk/core";
152
+ * import { sepolia } from "@account-kit/infra";
153
+ * import { createLightAccount } from "@account-kit/smart-contracts";
154
+ * import { http } from "viem";
155
+ *
156
+ * const account = await createLightAccount({
157
+ * transport: http("https://rpc.testnet.aepps.com"),
158
+ * chain: sepolia,
159
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
160
+ * });
161
+ *
162
+ * const provider = new EthersProviderAdapter();
163
+ * const signer = new AccountSigner(provider, account);
164
+ *
165
+ * const tx = await signer.sendTransaction({
166
+ * to: "0x1234567890123456789012345678901234567890",
167
+ * value: "0x0",
168
+ * data: "0x",
169
+ * });
170
+ * ```
171
+ *
172
+ * @param {Deferrable<TransactionRequest>} transaction the transaction request to be sent
173
+ * @returns {Promise<TransactionResponse>} a promise that resolves to the transaction response
174
+ * @throws {AccountNotFoundError} if the account is not found in the provider
175
+ */
65
176
  async sendTransaction(transaction) {
66
177
  if (!this.provider.accountProvider.account || !this.account) {
67
178
  throw new AccountNotFoundError();
@@ -75,12 +186,71 @@ export class AccountSigner extends Signer {
75
186
  });
76
187
  return this.provider.getTransaction(txHash);
77
188
  }
189
+ /**
190
+ * Throws an error indicating that transaction signing is not supported and advises to use `sendUserOperation` instead.
191
+ *
192
+ * @param {Deferrable<TransactionRequest>} _transaction The transaction request
193
+ * @throws {Error} Will always throw an error indicating transaction signing is unsupported
194
+ */
78
195
  signTransaction(_transaction) {
79
196
  throw new Error("Transaction signing is not supported, use sendUserOperation instead");
80
197
  }
198
+ /**
199
+ * Retrieves the BundlerClient instance from the provider.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
204
+ * import { LocalAccountSigner } from "@aa-sdk/core";
205
+ * import { sepolia } from "@account-kit/infra";
206
+ * import { createLightAccount } from "@account-kit/smart-contracts";
207
+ * import { http } from "viem";
208
+ *
209
+ * const account = await createLightAccount({
210
+ * transport: http("https://rpc.testnet.aepps.com"),
211
+ * chain: sepolia,
212
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
213
+ * });
214
+ *
215
+ * const provider = new EthersProviderAdapter();
216
+ * const signer = new AccountSigner(provider, account);
217
+ *
218
+ * const bundler = signer.getBundlerClient();
219
+ * ```
220
+ *
221
+ * @returns {BundlerClient<Transport>} The BundlerClient instance
222
+ */
81
223
  getBundlerClient() {
82
224
  return this.provider.getBundlerClient();
83
225
  }
226
+ /**
227
+ * Sets the provider for the account signer and returns the updated account signer instance.
228
+ * Note: this is not necessary since the Provider is required by the constructor. This is useful
229
+ * if you want to change the provider after the account signer has been created.
230
+ *
231
+ * @example
232
+ * ```ts
233
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
234
+ * import { LocalAccountSigner } from "@aa-sdk/core";
235
+ * import { sepolia } from "@account-kit/infra";
236
+ * import { createLightAccount } from "@account-kit/smart-contracts";
237
+ * import { http } from "viem";
238
+ *
239
+ * const account = await createLightAccount({
240
+ * transport: http("https://rpc.testnet.aepps.com"),
241
+ * chain: sepolia,
242
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
243
+ * });
244
+ *
245
+ * const provider = new EthersProviderAdapter();
246
+ * const signer = new AccountSigner(provider, account);
247
+ *
248
+ * signer.connect(provider);
249
+ * ```
250
+ *
251
+ * @param {EthersProviderAdapter} provider the provider to be set for the account signer
252
+ * @returns {AccountSigner<TAccount>} the updated account signer instance
253
+ */
84
254
  connect(provider) {
85
255
  this.provider = provider;
86
256
  return this;
@@ -1 +1 @@
1
- {"version":3,"file":"account-signer.js","sourceRoot":"","sources":["../../src/account-signer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAOlB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAGN,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAkB,MAAM,MAAM,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,MAAM,eAAe,GAAG,CAAC,KAAU,EAA6B,EAAE;IAChE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,OAAO,CAAC,KAAK,CAAkB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AAK,CAAC,eAAe,CACnB,WAA2C;QAE3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5D,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,WAAW,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,eAAe,CAAC;YACjE,EAAE,EAAE,QAAQ,CAAC,EAA+B;YAC5C,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC;YACpC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK;YAC1C,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAQD,eAAe,CACb,YAA4C;QAE5C,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IA2BD,gBAAgB;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IAC1C,CAAC;IA8BD,OAAO,CAAC,QAA+B;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF","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\n/**\n * Implementation of the ethers Signer interface to use with Smart Contract Accounts\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 /**\n * Creates a new AccountSigner with the given ethers Provider and Smart Contract Account\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n * ```\n *\n * @template {SmartContractAccount} TAccount the type of the smart contract account\n * @param {EthersProviderAdapter} provider the ethers provider to use\n * @param {TAccount} account the smart contract account that will be used to sign user ops and send them\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 /**\n * Returns the account address if the account exists.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const address = await signer.getAddress();\n * ```\n *\n * @returns {Promise<string>} a promise that resolves to the account address\n * @throws {AccountNotFoundError} if the account is not found\n */ async getAddress(): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.address;\n }\n\n /**\n * Signs a message using the associated account.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const message = await signer.signMessage(\"hello\");\n * ```\n *\n * @param {string | Uint8Array} message the message to be signed\n * @returns {Promise<string>} a promise that resolves to the signed message\n * @throws {AccountNotFoundError} if the account is not found\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 /**\n * Sends a transaction using the account provider and returns the transaction response.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const tx = await signer.sendTransaction({\n * to: \"0x1234567890123456789012345678901234567890\",\n * value: \"0x0\",\n * data: \"0x\",\n * });\n * ```\n *\n * @param {Deferrable<TransactionRequest>} transaction the transaction request to be sent\n * @returns {Promise<TransactionResponse>} a promise that resolves to the transaction response\n * @throws {AccountNotFoundError} if the account is not found in the provider\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 /**\n * Throws an error indicating that transaction signing is not supported and advises to use `sendUserOperation` instead.\n *\n * @param {Deferrable<TransactionRequest>} _transaction The transaction request\n * @throws {Error} Will always throw an error indicating transaction signing is unsupported\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 /**\n * Retrieves the BundlerClient instance from the provider.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const bundler = signer.getBundlerClient();\n * ```\n *\n * @returns {BundlerClient<Transport>} The BundlerClient instance\n */\n getBundlerClient(): BundlerClient<Transport> {\n return this.provider.getBundlerClient();\n }\n\n /**\n * Sets the provider for the account signer and returns the updated account signer instance.\n * Note: this is not necessary since the Provider is required by the constructor. This is useful\n * if you want to change the provider after the account signer has been created.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * signer.connect(provider);\n * ```\n *\n * @param {EthersProviderAdapter} provider the provider to be set for the account signer\n * @returns {AccountSigner<TAccount>} the updated account signer instance\n */\n connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {\n this.provider = provider;\n\n return this;\n }\n}\n"]}
1
+ {"version":3,"file":"account-signer.js","sourceRoot":"","sources":["../../src/account-signer.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,iBAAiB,GAOlB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAE/C,OAAO,EAGN,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,KAAK,EAAE,OAAO,EAAkB,MAAM,MAAM,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAE9D,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C,QAA+B;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF","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\n/**\n * Implementation of the ethers Signer interface to use with Smart Contract Accounts\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 /**\n * Creates a new AccountSigner with the given ethers Provider and Smart Contract Account\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n * ```\n *\n * @template {SmartContractAccount} TAccount the type of the smart contract account\n * @param {EthersProviderAdapter} provider the ethers provider to use\n * @param {TAccount} account the smart contract account that will be used to sign user ops and send them\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 /**\n * Returns the account address if the account exists.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const address = await signer.getAddress();\n * ```\n *\n * @returns {Promise<string>} a promise that resolves to the account address\n * @throws {AccountNotFoundError} if the account is not found\n */ async getAddress(): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.address;\n }\n\n /**\n * Signs a message using the associated account.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const message = await signer.signMessage(\"hello\");\n * ```\n *\n * @param {string | Uint8Array} message the message to be signed\n * @returns {Promise<string>} a promise that resolves to the signed message\n * @throws {AccountNotFoundError} if the account is not found\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 /**\n * Sends a transaction using the account provider and returns the transaction response.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const tx = await signer.sendTransaction({\n * to: \"0x1234567890123456789012345678901234567890\",\n * value: \"0x0\",\n * data: \"0x\",\n * });\n * ```\n *\n * @param {Deferrable<TransactionRequest>} transaction the transaction request to be sent\n * @returns {Promise<TransactionResponse>} a promise that resolves to the transaction response\n * @throws {AccountNotFoundError} if the account is not found in the provider\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 /**\n * Throws an error indicating that transaction signing is not supported and advises to use `sendUserOperation` instead.\n *\n * @param {Deferrable<TransactionRequest>} _transaction The transaction request\n * @throws {Error} Will always throw an error indicating transaction signing is unsupported\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 /**\n * Retrieves the BundlerClient instance from the provider.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const bundler = signer.getBundlerClient();\n * ```\n *\n * @returns {BundlerClient<Transport>} The BundlerClient instance\n */\n getBundlerClient(): BundlerClient<Transport> {\n return this.provider.getBundlerClient();\n }\n\n /**\n * Sets the provider for the account signer and returns the updated account signer instance.\n * Note: this is not necessary since the Provider is required by the constructor. This is useful\n * if you want to change the provider after the account signer has been created.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * signer.connect(provider);\n * ```\n *\n * @param {EthersProviderAdapter} provider the provider to be set for the account signer\n * @returns {AccountSigner<TAccount>} the updated account signer instance\n */\n connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {\n this.provider = provider;\n\n return this;\n }\n}\n"]}
@@ -3,11 +3,85 @@ import { JsonRpcProvider } from "@ethersproject/providers";
3
3
  import { type Chain, type Transport } from "viem";
4
4
  import { AccountSigner } from "./account-signer.js";
5
5
  import type { EthersProviderAdapterOpts } from "./types.js";
6
+ /** Lightweight Adapter for SmtAccountProvider to enable Signer Creation */
6
7
  export declare class EthersProviderAdapter extends JsonRpcProvider {
7
8
  readonly accountProvider: SmartAccountClient;
9
+ /**
10
+ * Configures and initializes the account provider based on the given options.
11
+ *
12
+ * @example
13
+ * ```ts
14
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
15
+ * import { LocalAccountSigner } from "@aa-sdk/core";
16
+ * import { sepolia } from "@account-kit/infra";
17
+ * import { createLightAccount } from "@account-kit/smart-contracts";
18
+ *
19
+ * const account = await createLightAccount({
20
+ * transport: http("https://rpc.testnet.aepps.com"),
21
+ * chain: sepolia,
22
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
23
+ * });
24
+ *
25
+ * const provider = new EthersProviderAdapter({
26
+ * account,
27
+ * chain: sepolia,
28
+ * rpcProvider: "https://eth-sepolia.g.alchemy.com/v2/your-api-key"
29
+ * });
30
+ * ```
31
+ *
32
+ * @param {EthersProviderAdapterOpts} opts The options for setting up the ethers provider adapter
33
+ */
8
34
  constructor(opts: EthersProviderAdapterOpts);
35
+ /**
36
+ * Rewrites the send method to use the account provider's EIP-1193
37
+ * compliant request method
38
+ *
39
+ * @param {any} method - the RPC method to call
40
+ * @param {any[]} params - the params required by the RPC method
41
+ * @returns {Promise<any>} the result of the RPC call
42
+ */
9
43
  send(method: any, params: any[]): Promise<any>;
44
+ /**
45
+ * Connects the Provider to an Account and returns a Signer
46
+ *
47
+ * @param {SmartContractAccount} account - the account to connect to
48
+ * @returns {AccountSigner} an AccountSigner that can be used to sign and send user operations
49
+ */
10
50
  connectToAccount<TAccount extends SmartContractAccount>(account: TAccount): AccountSigner<TAccount>;
51
+ /**
52
+ * Creates and returns a BundlerClient using the existing account provider's transport and chain.
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
57
+ * import { LocalAccountSigner } from "@aa-sdk/core";
58
+ * import { sepolia } from "@account-kit/infra";
59
+ * import { createLightAccount } from "@account-kit/smart-contracts";
60
+ *
61
+ * const account = await createLightAccount({
62
+ * transport: http("https://rpc.testnet.aepps.com"),
63
+ * chain: sepolia,
64
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
65
+ * });
66
+ *
67
+ * const provider = new EthersProviderAdapter({
68
+ * account,
69
+ * chain: sepolia,
70
+ * rpcProvider: "https://eth-sepolia.g.alchemy.com/v2/your-api-key"
71
+ * });
72
+ *
73
+ * const bundlerClient = provider.getBundlerClient();
74
+ * ```
75
+ *
76
+ * @returns {BundlerClient<Transport>} A bundler client configured with the existing account provider.
77
+ */
11
78
  getBundlerClient(): BundlerClient<Transport>;
79
+ /**
80
+ * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.
81
+ *
82
+ * @param {JsonRpcProvider} provider the ethers JSON RPC provider to convert
83
+ * @param {Chain} chain the chain to connect to
84
+ * @returns {EthersProviderAdapter} an instance of EthersProviderAdapter
85
+ */
12
86
  static fromEthersProvider(provider: JsonRpcProvider, chain: Chain): EthersProviderAdapter;
13
87
  }
@@ -2,7 +2,33 @@ import { createBundlerClientFromExisting, createSmartAccountClient, } from "@aa-
2
2
  import { JsonRpcProvider } from "@ethersproject/providers";
3
3
  import { createPublicClient, custom, http, } from "viem";
4
4
  import { AccountSigner } from "./account-signer.js";
5
+ /** Lightweight Adapter for SmtAccountProvider to enable Signer Creation */
5
6
  export class EthersProviderAdapter extends JsonRpcProvider {
7
+ /**
8
+ * Configures and initializes the account provider based on the given options.
9
+ *
10
+ * @example
11
+ * ```ts
12
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
13
+ * import { LocalAccountSigner } from "@aa-sdk/core";
14
+ * import { sepolia } from "@account-kit/infra";
15
+ * import { createLightAccount } from "@account-kit/smart-contracts";
16
+ *
17
+ * const account = await createLightAccount({
18
+ * transport: http("https://rpc.testnet.aepps.com"),
19
+ * chain: sepolia,
20
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
21
+ * });
22
+ *
23
+ * const provider = new EthersProviderAdapter({
24
+ * account,
25
+ * chain: sepolia,
26
+ * rpcProvider: "https://eth-sepolia.g.alchemy.com/v2/your-api-key"
27
+ * });
28
+ * ```
29
+ *
30
+ * @param {EthersProviderAdapterOpts} opts The options for setting up the ethers provider adapter
31
+ */
6
32
  constructor(opts) {
7
33
  super();
8
34
  Object.defineProperty(this, "accountProvider", {
@@ -32,18 +58,67 @@ export class EthersProviderAdapter extends JsonRpcProvider {
32
58
  }
33
59
  }
34
60
  }
61
+ /**
62
+ * Rewrites the send method to use the account provider's EIP-1193
63
+ * compliant request method
64
+ *
65
+ * @param {any} method - the RPC method to call
66
+ * @param {any[]} params - the params required by the RPC method
67
+ * @returns {Promise<any>} the result of the RPC call
68
+ */
35
69
  send(method, params) {
70
+ // @ts-expect-error - viem is strongly typed on the request methods, but ethers is not
36
71
  return this.accountProvider.request({ method, params });
37
72
  }
73
+ /**
74
+ * Connects the Provider to an Account and returns a Signer
75
+ *
76
+ * @param {SmartContractAccount} account - the account to connect to
77
+ * @returns {AccountSigner} an AccountSigner that can be used to sign and send user operations
78
+ */
38
79
  connectToAccount(account) {
39
80
  return new AccountSigner(this, account);
40
81
  }
82
+ /**
83
+ * Creates and returns a BundlerClient using the existing account provider's transport and chain.
84
+ *
85
+ * @example
86
+ * ```ts
87
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
88
+ * import { LocalAccountSigner } from "@aa-sdk/core";
89
+ * import { sepolia } from "@account-kit/infra";
90
+ * import { createLightAccount } from "@account-kit/smart-contracts";
91
+ *
92
+ * const account = await createLightAccount({
93
+ * transport: http("https://rpc.testnet.aepps.com"),
94
+ * chain: sepolia,
95
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
96
+ * });
97
+ *
98
+ * const provider = new EthersProviderAdapter({
99
+ * account,
100
+ * chain: sepolia,
101
+ * rpcProvider: "https://eth-sepolia.g.alchemy.com/v2/your-api-key"
102
+ * });
103
+ *
104
+ * const bundlerClient = provider.getBundlerClient();
105
+ * ```
106
+ *
107
+ * @returns {BundlerClient<Transport>} A bundler client configured with the existing account provider.
108
+ */
41
109
  getBundlerClient() {
42
110
  return createBundlerClientFromExisting(createPublicClient({
43
111
  transport: custom(this.accountProvider.transport),
44
112
  chain: this.accountProvider.chain,
45
113
  }));
46
114
  }
115
+ /**
116
+ * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.
117
+ *
118
+ * @param {JsonRpcProvider} provider the ethers JSON RPC provider to convert
119
+ * @param {Chain} chain the chain to connect to
120
+ * @returns {EthersProviderAdapter} an instance of EthersProviderAdapter
121
+ */
47
122
  static fromEthersProvider(provider, chain) {
48
123
  return new EthersProviderAdapter({
49
124
  rpcProvider: provider.connection.url,
@@ -1 +1 @@
1
- {"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,GAIzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,IAAI,GAGL,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IA4BxD,YAAY,IAA+B;QACzC,KAAK,EAAE,CAAC;QA5BD;;;;;WAAoC;QA6B3C,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,EAAE,KAAK,EAAE,GAAG,IAAI,CAAC;YAEvB,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;IA6BD,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;IASD,MAAM,CAAC,kBAAkB,CACvB,QAAyB,EACzB,KAAY;QAEZ,OAAO,IAAI,qBAAqB,CAAC;YAC/B,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG;YACpC,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {\n createBundlerClientFromExisting,\n createSmartAccountClient,\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { JsonRpcProvider } from \"@ethersproject/providers\";\nimport {\n createPublicClient,\n custom,\n http,\n type Chain,\n type Transport,\n} from \"viem\";\nimport { AccountSigner } from \"./account-signer.js\";\nimport type { EthersProviderAdapterOpts } from \"./types.js\";\n\n/** Lightweight Adapter for SmtAccountProvider to enable Signer Creation */\nexport class EthersProviderAdapter extends JsonRpcProvider {\n readonly accountProvider: SmartAccountClient;\n\n /**\n * Configures and initializes the account provider based on the given options.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter({\n * account,\n * chain: sepolia,\n * rpcProvider: \"https://eth-sepolia.g.alchemy.com/v2/your-api-key\"\n * });\n * ```\n *\n * @param {EthersProviderAdapterOpts} opts The options for setting up the ethers provider adapter\n */\n constructor(opts: EthersProviderAdapterOpts) {\n super();\n if (\"accountProvider\" in opts) {\n this.accountProvider = opts.accountProvider;\n } else {\n const { chain } = opts;\n\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 {any} method - the RPC method to call\n * @param {any[]} params - the params required by the RPC method\n * @returns {Promise<any>} 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 {SmartContractAccount} account - the account to connect to\n * @returns {AccountSigner} an 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 /**\n * Creates and returns a BundlerClient using the existing account provider's transport and chain.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter({\n * account,\n * chain: sepolia,\n * rpcProvider: \"https://eth-sepolia.g.alchemy.com/v2/your-api-key\"\n * });\n *\n * const bundlerClient = provider.getBundlerClient();\n * ```\n *\n * @returns {BundlerClient<Transport>} A bundler client configured with the existing account provider.\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 {JsonRpcProvider} provider the ethers JSON RPC provider to convert\n * @param {Chain} chain the chain to connect to\n * @returns {EthersProviderAdapter} an instance of EthersProviderAdapter\n */\n static fromEthersProvider(\n provider: JsonRpcProvider,\n chain: Chain\n ): EthersProviderAdapter {\n return new EthersProviderAdapter({\n rpcProvider: provider.connection.url,\n chain,\n });\n }\n}\n"]}
1
+ {"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,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IAAI,aAAa,CAAW,IAAI,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,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;IAED;;;;;;OAMG;IACH,MAAM,CAAC,kBAAkB,CACvB,QAAyB,EACzB,KAAY;QAEZ,OAAO,IAAI,qBAAqB,CAAC;YAC/B,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG;YACpC,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {\n createBundlerClientFromExisting,\n createSmartAccountClient,\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { JsonRpcProvider } from \"@ethersproject/providers\";\nimport {\n createPublicClient,\n custom,\n http,\n type Chain,\n type Transport,\n} from \"viem\";\nimport { AccountSigner } from \"./account-signer.js\";\nimport type { EthersProviderAdapterOpts } from \"./types.js\";\n\n/** Lightweight Adapter for SmtAccountProvider to enable Signer Creation */\nexport class EthersProviderAdapter extends JsonRpcProvider {\n readonly accountProvider: SmartAccountClient;\n\n /**\n * Configures and initializes the account provider based on the given options.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter({\n * account,\n * chain: sepolia,\n * rpcProvider: \"https://eth-sepolia.g.alchemy.com/v2/your-api-key\"\n * });\n * ```\n *\n * @param {EthersProviderAdapterOpts} opts The options for setting up the ethers provider adapter\n */\n constructor(opts: EthersProviderAdapterOpts) {\n super();\n if (\"accountProvider\" in opts) {\n this.accountProvider = opts.accountProvider;\n } else {\n const { chain } = opts;\n\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 {any} method - the RPC method to call\n * @param {any[]} params - the params required by the RPC method\n * @returns {Promise<any>} 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 {SmartContractAccount} account - the account to connect to\n * @returns {AccountSigner} an 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 /**\n * Creates and returns a BundlerClient using the existing account provider's transport and chain.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter({\n * account,\n * chain: sepolia,\n * rpcProvider: \"https://eth-sepolia.g.alchemy.com/v2/your-api-key\"\n * });\n *\n * const bundlerClient = provider.getBundlerClient();\n * ```\n *\n * @returns {BundlerClient<Transport>} A bundler client configured with the existing account provider.\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 {JsonRpcProvider} provider the ethers JSON RPC provider to convert\n * @param {Chain} chain the chain to connect to\n * @returns {EthersProviderAdapter} an instance of EthersProviderAdapter\n */\n static fromEthersProvider(\n provider: JsonRpcProvider,\n chain: Chain\n ): EthersProviderAdapter {\n return new EthersProviderAdapter({\n rpcProvider: provider.connection.url,\n chain,\n });\n }\n}\n"]}
@@ -1,5 +1,17 @@
1
1
  import type { SmartAccountSigner } from "@aa-sdk/core";
2
2
  import type { Signer } from "@ethersproject/abstract-signer";
3
3
  import { Wallet } from "@ethersproject/wallet";
4
+ /**
5
+ * Converts a ethersjs Wallet to a SmartAccountSigner
6
+ *
7
+ * @param {Wallet} wallet - the Wallet to convert
8
+ * @returns {SmartAccountSigner<Wallet>} a signer that can be used to sign and send user operations
9
+ */
4
10
  export declare const convertWalletToAccountSigner: (wallet: Wallet) => SmartAccountSigner<Wallet>;
11
+ /**
12
+ * Converts a ethers.js Signer to a SmartAccountSigner
13
+ *
14
+ * @param {Signer} signer - the Signer to convert
15
+ * @returns {SmartAccountSigner<Signer>} a signer that can be used to sign and send user operations
16
+ */
5
17
  export declare const convertEthersSignerToAccountSigner: (signer: Signer) => SmartAccountSigner<Signer>;
package/dist/esm/utils.js CHANGED
@@ -1,4 +1,10 @@
1
1
  import { Wallet } from "@ethersproject/wallet";
2
+ /**
3
+ * Converts a ethersjs Wallet to a SmartAccountSigner
4
+ *
5
+ * @param {Wallet} wallet - the Wallet to convert
6
+ * @returns {SmartAccountSigner<Wallet>} a signer that can be used to sign and send user operations
7
+ */
2
8
  export const convertWalletToAccountSigner = (wallet) => {
3
9
  return {
4
10
  inner: wallet,
@@ -6,10 +12,18 @@ export const convertWalletToAccountSigner = (wallet) => {
6
12
  getAddress: async () => Promise.resolve(wallet.address),
7
13
  signMessage: async (msg) => (await wallet.signMessage(typeof msg === "string" ? msg : msg.raw)),
8
14
  signTypedData: async (params) => {
9
- return (await wallet._signTypedData(params.domain ?? {}, params.types, params.message));
15
+ return (await wallet._signTypedData(params.domain ?? {},
16
+ // @ts-expect-error: these params should line up due to the spec for this function
17
+ params.types, params.message));
10
18
  },
11
19
  };
12
20
  };
21
+ /**
22
+ * Converts a ethers.js Signer to a SmartAccountSigner
23
+ *
24
+ * @param {Signer} signer - the Signer to convert
25
+ * @returns {SmartAccountSigner<Signer>} a signer that can be used to sign and send user operations
26
+ */
13
27
  export const convertEthersSignerToAccountSigner = (signer) => {
14
28
  return {
15
29
  inner: signer,
@@ -1 +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} wallet - the Wallet to convert\n * @returns {SmartAccountSigner<Wallet>} 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} signer - the Signer to convert\n * @returns {SmartAccountSigner<Signer>} 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"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAG/C;;;;;GAKG;AACH,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;YACnB,kFAAkF;YAClF,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,OAAO,CACf,CAAkB,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;GAKG;AACH,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} wallet - the Wallet to convert\n * @returns {SmartAccountSigner<Wallet>} 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 keyof TTypedData | \"EIP712Domain\" = keyof TTypedData\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} signer - the Signer to convert\n * @returns {SmartAccountSigner<Signer>} 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 keyof TTypedData | \"EIP712Domain\" = keyof TTypedData\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"]}
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
2
  "name": "@aa-sdk/ethers",
3
3
  "license": "MIT",
4
- "version": "4.0.0-alpha.9",
4
+ "version": "4.0.0-beta.1",
5
5
  "description": "Ethers.js wrapper for @aa-sdk/core",
6
6
  "author": "Alchemy",
7
7
  "type": "module",
8
- "main": "./dist/cjs/index.js",
8
+ "main": "./dist/esm/index.js",
9
9
  "module": "./dist/esm/index.js",
10
10
  "types": "./dist/types/index.d.ts",
11
11
  "typings": "./dist/types/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  ".": {
24
24
  "types": "./dist/types/index.d.ts",
25
25
  "import": "./dist/esm/index.js",
26
- "default": "./dist/cjs/index.js"
26
+ "default": "./dist/esm/index.js"
27
27
  },
28
28
  "./package.json": "./package.json"
29
29
  },
@@ -32,10 +32,9 @@
32
32
  "registry": "https://registry.npmjs.org/"
33
33
  },
34
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",
35
+ "build": "yarn clean && yarn build:esm && yarn build:types",
36
+ "build:esm": "tsc --project tsconfig.build.json --outDir ./dist/esm",
37
+ "build:types": "tsc --project tsconfig.build.json --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
39
38
  "docs:gen": "npx ak-docgen generate --in ./src/index.ts --out ../../site/pages/reference/aa-sdk/ethers",
40
39
  "clean": "rm -rf ./dist",
41
40
  "test": "vitest",
@@ -43,7 +42,7 @@
43
42
  "test:run-e2e": "vitest run --config vitest.config.e2e.ts"
44
43
  },
45
44
  "devDependencies": {
46
- "@account-kit/smart-contracts": "4.0.0-alpha.4",
45
+ "@account-kit/smart-contracts": "^4.0.0-beta.1",
47
46
  "alchemy-sdk": "^3.0.0",
48
47
  "dotenv": "^16.0.3",
49
48
  "typescript": "^5.0.4",
@@ -51,7 +50,7 @@
51
50
  "vitest": "^2.0.4"
52
51
  },
53
52
  "dependencies": {
54
- "@aa-sdk/core": "^4.0.0-alpha.9",
53
+ "@aa-sdk/core": "^4.0.0-beta.1",
55
54
  "@ethersproject/abi": "^5.7.0",
56
55
  "@ethersproject/abstract-signer": "^5.7.0",
57
56
  "@ethersproject/bytes": "^5.7.0",
@@ -59,11 +58,10 @@
59
58
  "@ethersproject/hash": "^5.7.0",
60
59
  "@ethersproject/keccak256": "^5.7.0",
61
60
  "@ethersproject/providers": "^5.7.2",
62
- "@ethersproject/wallet": "^5.7.0",
63
- "viem": "2.8.6"
61
+ "@ethersproject/wallet": "^5.7.0"
64
62
  },
65
63
  "peerDependencies": {
66
- "viem": "2.8.6"
64
+ "viem": "^2.20.0"
67
65
  },
68
66
  "repository": {
69
67
  "type": "git",
@@ -72,5 +70,5 @@
72
70
  "bugs": {
73
71
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
74
72
  },
75
- "gitHead": "9616a7ab7dc70320b508e5674bb61ef0723a8b59"
73
+ "gitHead": "5e0db61aaa6b55e7da3e04d00822392b946b3882"
76
74
  }
package/src/utils.ts CHANGED
@@ -22,7 +22,7 @@ export const convertWalletToAccountSigner = (
22
22
  )) as `0x${string}`,
23
23
  signTypedData: async <
24
24
  const TTypedData extends TypedData | { [key: string]: unknown },
25
- TPrimaryType extends string = string
25
+ TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData
26
26
  >(
27
27
  params: TypedDataDefinition<TTypedData, TPrimaryType>
28
28
  ) => {
@@ -55,7 +55,7 @@ export const convertEthersSignerToAccountSigner = (
55
55
  )) as `0x${string}`,
56
56
  signTypedData: async <
57
57
  const TTypedData extends TypedData | { [key: string]: unknown },
58
- TPrimaryType extends string = string
58
+ TPrimaryType extends keyof TTypedData | "EIP712Domain" = keyof TTypedData
59
59
  >(
60
60
  _params: TypedDataDefinition<TTypedData, TPrimaryType>
61
61
  ) => {
@@ -1,19 +0,0 @@
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
- getBundlerClient(): BundlerClient<Transport>;
18
- connect(provider: EthersProviderAdapter): AccountSigner<TAccount>;
19
- }
@@ -1,91 +0,0 @@
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
- getBundlerClient() {
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
@@ -1 +0,0 @@
1
- {"version":3,"file":"account-signer.js","sourceRoot":"","sources":["../../src/account-signer.ts"],"names":[],"mappings":";;;AAAA,uCASsB;AACtB,oEAAwD;AACxD,gDAA+C;AAM/C,+BAAsD;AAGtD,MAAM,eAAe,GAAG,CAAC,KAAU,EAA6B,EAAE;IAChE,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAA,eAAO,EAAC,KAAK,CAAkB,CAAC;AACzC,CAAC,CAAC;AAKF,MAAa,aAGX,SAAQ,wBAAM;IA+Bd,YAAmB,QAA+B,EAAE,OAAiB;QACnE,KAAK,EAA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I,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5D,MAAM,IAAI,2BAAoB,EAAE,CAAC;QACnC,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,IAAA,wBAAiB,EAAC,WAAW,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,eAAe,CAAC;YACjE,EAAE,EAAE,QAAQ,CAAC,EAA+B;YAC5C,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC;YACpC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK;YAC1C,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAQD,eAAe,CACb,YAA4C;QAE5C,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IA2BD,gBAAgB;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IAC1C,CAAC;IA8BD,OAAO,CAAC,QAA+B;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA5PD,sCA4PC","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\n/**\n * Implementation of the ethers Signer interface to use with Smart Contract Accounts\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 /**\n * Creates a new AccountSigner with the given ethers Provider and Smart Contract Account\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n * ```\n *\n * @template {SmartContractAccount} TAccount the type of the smart contract account\n * @param {EthersProviderAdapter} provider the ethers provider to use\n * @param {TAccount} account the smart contract account that will be used to sign user ops and send them\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 /**\n * Returns the account address if the account exists.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const address = await signer.getAddress();\n * ```\n *\n * @returns {Promise<string>} a promise that resolves to the account address\n * @throws {AccountNotFoundError} if the account is not found\n */ async getAddress(): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.address;\n }\n\n /**\n * Signs a message using the associated account.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const message = await signer.signMessage(\"hello\");\n * ```\n *\n * @param {string | Uint8Array} message the message to be signed\n * @returns {Promise<string>} a promise that resolves to the signed message\n * @throws {AccountNotFoundError} if the account is not found\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 /**\n * Sends a transaction using the account provider and returns the transaction response.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const tx = await signer.sendTransaction({\n * to: \"0x1234567890123456789012345678901234567890\",\n * value: \"0x0\",\n * data: \"0x\",\n * });\n * ```\n *\n * @param {Deferrable<TransactionRequest>} transaction the transaction request to be sent\n * @returns {Promise<TransactionResponse>} a promise that resolves to the transaction response\n * @throws {AccountNotFoundError} if the account is not found in the provider\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 /**\n * Throws an error indicating that transaction signing is not supported and advises to use `sendUserOperation` instead.\n *\n * @param {Deferrable<TransactionRequest>} _transaction The transaction request\n * @throws {Error} Will always throw an error indicating transaction signing is unsupported\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 /**\n * Retrieves the BundlerClient instance from the provider.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const bundler = signer.getBundlerClient();\n * ```\n *\n * @returns {BundlerClient<Transport>} The BundlerClient instance\n */\n getBundlerClient(): BundlerClient<Transport> {\n return this.provider.getBundlerClient();\n }\n\n /**\n * Sets the provider for the account signer and returns the updated account signer instance.\n * Note: this is not necessary since the Provider is required by the constructor. This is useful\n * if you want to change the provider after the account signer has been created.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * signer.connect(provider);\n * ```\n *\n * @param {EthersProviderAdapter} provider the provider to be set for the account signer\n * @returns {AccountSigner<TAccount>} the updated account signer instance\n */\n connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {\n this.provider = provider;\n\n return this;\n }\n}\n"]}
@@ -1,3 +0,0 @@
1
- export { AccountSigner } from "./account-signer.js";
2
- export { EthersProviderAdapter } from "./provider-adapter.js";
3
- export { convertEthersSignerToAccountSigner, convertWalletToAccountSigner, } from "./utils.js";
package/dist/cjs/index.js DELETED
@@ -1,11 +0,0 @@
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
@@ -1 +0,0 @@
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"]}
@@ -1 +0,0 @@
1
- {"type":"commonjs"}
@@ -1,13 +0,0 @@
1
- import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
- import { JsonRpcProvider } from "@ethersproject/providers";
3
- import { type Chain, 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, chain: Chain): EthersProviderAdapter;
13
- }
@@ -1,58 +0,0 @@
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 } = opts;
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, chain) {
51
- return new EthersProviderAdapter({
52
- rpcProvider: provider.connection.url,
53
- chain,
54
- });
55
- }
56
- }
57
- exports.EthersProviderAdapter = EthersProviderAdapter;
58
- //# sourceMappingURL=provider-adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":";;;AAAA,uCAMsB;AACtB,wDAA2D;AAC3D,+BAMc;AACd,2DAAoD;AAIpD,MAAa,qBAAsB,SAAQ,2BAAe;IA4BxD,YAAY,IAA+B;QACzC,KAAK,EAAE,CAAC;QA5BD;;;;;WAAoC;QA6B3C,IAAI,iBAAiB,IAA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CAAC,GAAG;YACpC,KAAK;SACN,CAAC,CAAC;IACL,CAAC;CACF;AAhID,sDAgIC","sourcesContent":["import {\n createBundlerClientFromExisting,\n createSmartAccountClient,\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { JsonRpcProvider } from \"@ethersproject/providers\";\nimport {\n createPublicClient,\n custom,\n http,\n type Chain,\n type Transport,\n} from \"viem\";\nimport { AccountSigner } from \"./account-signer.js\";\nimport type { EthersProviderAdapterOpts } from \"./types.js\";\n\n/** Lightweight Adapter for SmtAccountProvider to enable Signer Creation */\nexport class EthersProviderAdapter extends JsonRpcProvider {\n readonly accountProvider: SmartAccountClient;\n\n /**\n * Configures and initializes the account provider based on the given options.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter({\n * account,\n * chain: sepolia,\n * rpcProvider: \"https://eth-sepolia.g.alchemy.com/v2/your-api-key\"\n * });\n * ```\n *\n * @param {EthersProviderAdapterOpts} opts The options for setting up the ethers provider adapter\n */\n constructor(opts: EthersProviderAdapterOpts) {\n super();\n if (\"accountProvider\" in opts) {\n this.accountProvider = opts.accountProvider;\n } else {\n const { chain } = opts;\n\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 {any} method - the RPC method to call\n * @param {any[]} params - the params required by the RPC method\n * @returns {Promise<any>} 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 {SmartContractAccount} account - the account to connect to\n * @returns {AccountSigner} an 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 /**\n * Creates and returns a BundlerClient using the existing account provider's transport and chain.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter({\n * account,\n * chain: sepolia,\n * rpcProvider: \"https://eth-sepolia.g.alchemy.com/v2/your-api-key\"\n * });\n *\n * const bundlerClient = provider.getBundlerClient();\n * ```\n *\n * @returns {BundlerClient<Transport>} A bundler client configured with the existing account provider.\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 {JsonRpcProvider} provider the ethers JSON RPC provider to convert\n * @param {Chain} chain the chain to connect to\n * @returns {EthersProviderAdapter} an instance of EthersProviderAdapter\n */\n static fromEthersProvider(\n provider: JsonRpcProvider,\n chain: Chain\n ): EthersProviderAdapter {\n return new EthersProviderAdapter({\n rpcProvider: provider.connection.url,\n chain,\n });\n }\n}\n"]}
@@ -1,10 +0,0 @@
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
- chain: Chain;
8
- } | {
9
- accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
10
- });
package/dist/cjs/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
@@ -1 +0,0 @@
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 chain: Chain;\n }\n | {\n accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;\n }\n);\n"]}
@@ -1,5 +0,0 @@
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>;
package/dist/cjs/utils.js DELETED
@@ -1,28 +0,0 @@
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
@@ -1 +0,0 @@
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} wallet - the Wallet to convert\n * @returns {SmartAccountSigner<Wallet>} 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} signer - the Signer to convert\n * @returns {SmartAccountSigner<Signer>} 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"]}
@@ -1 +0,0 @@
1
- {"type":"module"}