@aa-sdk/ethers 4.0.0-alpha.0 → 4.0.0-alpha.10

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.
@@ -14,6 +14,6 @@ export declare class AccountSigner<TAccount extends SmartContractAccount = Smart
14
14
  signMessage(message: string | Uint8Array): Promise<string>;
15
15
  sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>;
16
16
  signTransaction(_transaction: Deferrable<TransactionRequest>): Promise<string>;
17
- getPublicErc4337Client(): BundlerClient<Transport>;
17
+ getBundlerClient(): BundlerClient<Transport>;
18
18
  connect(provider: EthersProviderAdapter): AccountSigner<TAccount>;
19
19
  }
@@ -79,7 +79,7 @@ class AccountSigner extends abstract_signer_1.Signer {
79
79
  signTransaction(_transaction) {
80
80
  throw new Error("Transaction signing is not supported, use sendUserOperation instead");
81
81
  }
82
- getPublicErc4337Client() {
82
+ getBundlerClient() {
83
83
  return this.provider.getBundlerClient();
84
84
  }
85
85
  connect(provider) {
@@ -1 +1 @@
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;AAEF,MAAa,aAGX,SAAQ,wBAAM;IAMd,YAAmB,QAA+B,EAAE,OAAiB;QACnE,KAAK,EAAE,CAAC;QADE;;;;mBAAO,QAAQ;WAAuB;QALzC;;;;;WAAkB;QAE3B;;;;;WAAkB;QAClB;;;;;WAAgC;QAI9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,iBAAiB,GAAG,CAC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AM,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;IAED,eAAe,CACb,YAA4C;QAE5C,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IAED,sBAAsB;QACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IAC1C,CAAC;IAED,OAAO,CAAC,QAA+B;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AArFD,sCAqFC","sourcesContent":["import {\n AccountNotFoundError,\n resolveProperties,\n type BatchUserOperationCallData,\n type BundlerClient,\n type GetEntryPointFromAccount,\n type SmartContractAccount,\n type UserOperationCallData,\n type UserOperationOverrides,\n} from \"@aa-sdk/core\";\nimport { Signer } from \"@ethersproject/abstract-signer\";\nimport { hexlify } from \"@ethersproject/bytes\";\nimport type { Deferrable } from \"@ethersproject/properties\";\nimport {\n type TransactionRequest,\n type TransactionResponse,\n} from \"@ethersproject/providers\";\nimport { isHex, toBytes, type Transport } from \"viem\";\nimport { EthersProviderAdapter } from \"./provider-adapter.js\";\n\nconst hexlifyOptional = (value: any): `0x${string}` | undefined => {\n if (value == null) {\n return undefined;\n }\n\n return hexlify(value) as `0x${string}`;\n};\n\nexport class AccountSigner<\n TAccount extends SmartContractAccount = SmartContractAccount,\n TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>\n> extends Signer {\n readonly account: TAccount;\n\n sendUserOperation;\n waitForUserOperationTransaction;\n\n constructor(public provider: EthersProviderAdapter, account: TAccount) {\n super();\n this.account = account;\n\n this.sendUserOperation = (\n args: UserOperationCallData | BatchUserOperationCallData,\n overrides?: UserOperationOverrides<TEntryPointVersion>\n ) =>\n this.provider.accountProvider.sendUserOperation({\n uo: args,\n account,\n overrides,\n });\n\n this.waitForUserOperationTransaction =\n this.provider.accountProvider.waitForUserOperationTransaction.bind(\n this.provider.accountProvider\n );\n }\n\n async getAddress(): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.address;\n }\n\n signMessage(message: string | Uint8Array): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.signMessage({\n message:\n typeof message === \"string\" && !isHex(message)\n ? message\n : { raw: isHex(message) ? toBytes(message) : message },\n });\n }\n\n async sendTransaction(\n transaction: Deferrable<TransactionRequest>\n ): Promise<TransactionResponse> {\n if (!this.provider.accountProvider.account || !this.account) {\n throw new AccountNotFoundError();\n }\n\n const resolved = await resolveProperties(transaction);\n const txHash = await this.provider.accountProvider.sendTransaction({\n to: resolved.to as `0x${string}` | undefined,\n data: hexlifyOptional(resolved.data),\n chain: this.provider.accountProvider.chain,\n account: this.account,\n });\n\n return this.provider.getTransaction(txHash);\n }\n\n signTransaction(\n _transaction: Deferrable<TransactionRequest>\n ): Promise<string> {\n throw new Error(\n \"Transaction signing is not supported, use sendUserOperation instead\"\n );\n }\n\n getPublicErc4337Client(): BundlerClient<Transport> {\n return this.provider.getBundlerClient();\n }\n\n connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {\n this.provider = provider;\n\n return this;\n }\n}\n"]}
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,KA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,CAAC,CAAC,CAAC,IAAA,cAAO,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,EAAE;SAC3D,CAAC,CAAC;IACL,CAAC;IAiCD,KAAK,CAAC,eAAe,CACnB,WAA2C;QAE3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,IAAI,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,6 +1,6 @@
1
1
  import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
2
  import { JsonRpcProvider } from "@ethersproject/providers";
3
- import { type Transport } from "viem";
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
6
  export declare class EthersProviderAdapter extends JsonRpcProvider {
@@ -9,5 +9,5 @@ export declare class EthersProviderAdapter extends JsonRpcProvider {
9
9
  send(method: any, params: any[]): Promise<any>;
10
10
  connectToAccount<TAccount extends SmartContractAccount>(account: TAccount): AccountSigner<TAccount>;
11
11
  getBundlerClient(): BundlerClient<Transport>;
12
- static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter;
12
+ static fromEthersProvider(provider: JsonRpcProvider, chain: Chain): EthersProviderAdapter;
13
13
  }
@@ -18,7 +18,7 @@ class EthersProviderAdapter extends providers_1.JsonRpcProvider {
18
18
  this.accountProvider = opts.accountProvider;
19
19
  }
20
20
  else {
21
- const chain = (0, core_1.getChain)(opts.chainId);
21
+ const { chain } = opts;
22
22
  if (typeof opts.rpcProvider === "string") {
23
23
  this.accountProvider = (0, core_1.createSmartAccountClient)({
24
24
  transport: (0, viem_1.http)(opts.rpcProvider),
@@ -47,10 +47,10 @@ class EthersProviderAdapter extends providers_1.JsonRpcProvider {
47
47
  chain: this.accountProvider.chain,
48
48
  }));
49
49
  }
50
- static fromEthersProvider(provider) {
50
+ static fromEthersProvider(provider, chain) {
51
51
  return new EthersProviderAdapter({
52
52
  rpcProvider: provider.connection.url,
53
- chainId: provider.network.chainId,
53
+ chain,
54
54
  });
55
55
  }
56
56
  }
@@ -1 +1 @@
1
- {"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":";;;AAAA,uCAOsB;AACtB,wDAA2D;AAC3D,+BAAwE;AACxE,2DAAoD;AAKpD,MAAa,qBAAsB,SAAQ,2BAAe;IAGxD,YAAY,IAA+B;QACzC,KAAK,EAAE,CAAC;QAHD;;;;;WAAoC;QAI3C,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,IAAA,eAAQ,EAAC,IAAI,CAAC,OAAO,CAAC,C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ain,\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { JsonRpcProvider } from \"@ethersproject/providers\";\nimport { createPublicClient, custom, http, type Transport } from \"viem\";\nimport { AccountSigner } from \"./account-signer.js\";\nimport type { EthersProviderAdapterOpts } from \"./types.js\";\n\n/** Lightweight Adapter for SmartAccountProvider to enable Signer Creation */\n// TODO: Add support for strong entry point version type\nexport class EthersProviderAdapter extends JsonRpcProvider {\n readonly accountProvider: SmartAccountClient;\n\n constructor(opts: EthersProviderAdapterOpts) {\n super();\n if (\"accountProvider\" in opts) {\n this.accountProvider = opts.accountProvider;\n } else {\n const chain = getChain(opts.chainId);\n if (typeof opts.rpcProvider === \"string\") {\n this.accountProvider = createSmartAccountClient({\n transport: http(opts.rpcProvider),\n chain,\n account: opts.account,\n });\n } else {\n this.accountProvider = createSmartAccountClient({\n transport: custom(opts.rpcProvider.transport),\n chain,\n account: opts.account,\n });\n }\n }\n }\n\n /**\n * Rewrites the send method to use the account provider's EIP-1193\n * compliant request method\n *\n * @param method - the RPC method to call\n * @param params - the params required by the RPC method\n * @returns the result of the RPC call\n */\n send(method: any, params: any[]): Promise<any> {\n // @ts-expect-error - viem is strongly typed on the request methods, but ethers is not\n return this.accountProvider.request({ method, params });\n }\n\n /**\n * Connects the Provider to an Account and returns a Signer\n *\n * @param account - the account to connect to\n * @returns an {@link AccountSigner} that can be used to sign and send user operations\n */\n connectToAccount<TAccount extends SmartContractAccount>(\n account: TAccount\n ): AccountSigner<TAccount> {\n return new AccountSigner<TAccount>(this, account);\n }\n\n getBundlerClient(): BundlerClient<Transport> {\n return createBundlerClientFromExisting(\n createPublicClient({\n transport: custom(this.accountProvider.transport),\n chain: this.accountProvider.chain!,\n })\n );\n }\n\n /**\n * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.\n *\n * @param provider - the ethers JSON RPC provider to convert\n * @returns an instance of {@link EthersProviderAdapter}\n */\n static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter {\n return new EthersProviderAdapter({\n rpcProvider: provider.connection.url,\n chainId: provider.network.chainId,\n });\n }\n}\n"]}
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,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,IAAA,+BAAwB,EAAC;oBAC9C,SAAS,EAAE,IAAA,WAAI,EAAC,IAAI,CAAC,WAAW,CAAC;oBACjC,KAAK;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,eAAe,GAAG,IAAA,+BAAwB,EAAC;oBAC9C,SAAS,EAAE,IAAA,aAAM,EAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;oBAC7C,KAAK;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAUD,IAAI,CAAC,MAAW,EAAE,MAAa;QAE7B,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IAQD,gBAAgB,CACd,OAAiB;QAEjB,OAAO,IAAI,iCAAa,CAAW,IAAI,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IA6BD,gBAAgB;QACd,OAAO,IAAA,sCAA+B,EACpC,IAAA,yBAAkB,EAAC;YACjB,SAAS,EAAE,IAAA,aAAM,EAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;YACjD,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,KAAM;SACnC,CAAC,CACH,CAAC;IACJ,CAAC;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;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"]}
@@ -4,7 +4,7 @@ export type EthersProviderAdapterOpts<TTransport extends Transport = Transport,
4
4
  account?: TAccount;
5
5
  } & ({
6
6
  rpcProvider: string | BundlerClient<TTransport>;
7
- chainId: number;
7
+ chain: Chain;
8
8
  } | {
9
9
  accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
10
10
  });
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import {\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Chain, Transport } from \"viem\";\n\nexport type EthersProviderAdapterOpts<\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n> = {\n account?: TAccount;\n} & (\n | {\n rpcProvider: string | BundlerClient<TTransport>;\n chainId: number;\n }\n | {\n accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;\n }\n);\n"]}
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 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":";;;AAWO,MAAM,4BAA4B,GAAG,CAC1C,MAAc,EACc,EAAE;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,OAAO;QACnB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAwB,CAAC;QACxE,WAAW,EAAE,KAAK,EAAE,GAAoB,EAAE,EAAE,CAC1C,CAAC,MAAM,MAAM,CAAC,WAAW,CACvB,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CACxC,CAAkB;QACrB,aAAa,EAAE,KAAK,EAIlB,MAAqD,EACrD,EAAE;YACF,OAAO,CAAC,MAAM,MAAM,CAAC,cAAc,CACjC,MAAM,CAAC,MAAM,IAAI,EAAE,EAEnB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,OAAO,CACf,CAAkB,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAzBW,QAAA,4BAA4B,gCAyBvC;AAQK,MAAM,kCAAkC,GAAG,CAChD,MAAc,EACc,EAAE;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,UAAU;QACtB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,UAAU,EAAsB;QAC/D,WAAW,EAAE,KAAK,EAAE,GAAoB,EAAE,EAAE,CAC1C,CAAC,MAAM,MAAM,CAAC,WAAW,CACvB,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CACxC,CAAkB;QACrB,aAAa,EAAE,KAAK,EAIlB,OAAsD,EACtD,EAAE;YACF,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAtBW,QAAA,kCAAkC,sCAsB7C","sourcesContent":["import type { Address, SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Signer } from \"@ethersproject/abstract-signer\";\nimport { Wallet } from \"@ethersproject/wallet\";\nimport type { SignableMessage, TypedData, TypedDataDefinition } from \"viem\";\n\n/**\n * Converts a ethersjs Wallet to a SmartAccountSigner\n *\n * @param wallet - the Wallet to convert\n * @returns - a signer that can be used to sign and send user operations\n */\nexport const convertWalletToAccountSigner = (\n wallet: Wallet\n): SmartAccountSigner<Wallet> => {\n return {\n inner: wallet,\n signerType: \"local\",\n getAddress: async () => Promise.resolve(wallet.address as `0x${string}`),\n signMessage: async (msg: SignableMessage) =>\n (await wallet.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n return (await wallet._signTypedData(\n params.domain ?? {},\n // @ts-expect-error: these params should line up due to the spec for this function\n params.types,\n params.message\n )) as `0x${string}`;\n },\n };\n};\n\n/**\n * Converts a ethers.js Signer to a SmartAccountSigner\n *\n * @param signer - the Signer to convert\n * @returns - a signer that can be used to sign and send user operations\n */\nexport const convertEthersSignerToAccountSigner = (\n signer: Signer\n): SmartAccountSigner<Signer> => {\n return {\n inner: signer,\n signerType: \"json-rpc\",\n getAddress: async () => signer.getAddress() as Promise<Address>,\n signMessage: async (msg: SignableMessage) =>\n (await signer.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n _params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n throw new Error(\n \"signTypedData is not supported for ethers signers; use Wallet\"\n );\n },\n };\n};\n"]}
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"]}
@@ -14,6 +14,6 @@ export declare class AccountSigner<TAccount extends SmartContractAccount = Smart
14
14
  signMessage(message: string | Uint8Array): Promise<string>;
15
15
  sendTransaction(transaction: Deferrable<TransactionRequest>): Promise<TransactionResponse>;
16
16
  signTransaction(_transaction: Deferrable<TransactionRequest>): Promise<string>;
17
- getPublicErc4337Client(): BundlerClient<Transport>;
17
+ getBundlerClient(): BundlerClient<Transport>;
18
18
  connect(provider: EthersProviderAdapter): AccountSigner<TAccount>;
19
19
  }
@@ -78,7 +78,7 @@ export class AccountSigner extends Signer {
78
78
  signTransaction(_transaction) {
79
79
  throw new Error("Transaction signing is not supported, use sendUserOperation instead");
80
80
  }
81
- getPublicErc4337Client() {
81
+ getBundlerClient() {
82
82
  return this.provider.getBundlerClient();
83
83
  }
84
84
  connect(provider) {
@@ -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,CAAC;AACzC,CAAC,CAAC;AAEF,MAAM,OAAO,aAGX,SAAQ,MAAM;I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e,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;IAED,eAAe,CACb,YAA4C;QAE5C,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IAED,sBAAsB;QACpB,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IAC1C,CAAC;IAED,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\nexport class AccountSigner<\n TAccount extends SmartContractAccount = SmartContractAccount,\n TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>\n> extends Signer {\n readonly account: TAccount;\n\n sendUserOperation;\n waitForUserOperationTransaction;\n\n constructor(public provider: EthersProviderAdapter, account: TAccount) {\n super();\n this.account = account;\n\n this.sendUserOperation = (\n args: UserOperationCallData | BatchUserOperationCallData,\n overrides?: UserOperationOverrides<TEntryPointVersion>\n ) =>\n this.provider.accountProvider.sendUserOperation({\n uo: args,\n account,\n overrides,\n });\n\n this.waitForUserOperationTransaction =\n this.provider.accountProvider.waitForUserOperationTransaction.bind(\n this.provider.accountProvider\n );\n }\n\n async getAddress(): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.address;\n }\n\n signMessage(message: string | Uint8Array): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.signMessage({\n message:\n typeof message === \"string\" && !isHex(message)\n ? message\n : { raw: isHex(message) ? toBytes(message) : message },\n });\n }\n\n async sendTransaction(\n transaction: Deferrable<TransactionRequest>\n ): Promise<TransactionResponse> {\n if (!this.provider.accountProvider.account || !this.account) {\n throw new AccountNotFoundError();\n }\n\n const resolved = await resolveProperties(transaction);\n const txHash = await this.provider.accountProvider.sendTransaction({\n to: resolved.to as `0x${string}` | undefined,\n data: hexlifyOptional(resolved.data),\n chain: this.provider.accountProvider.chain,\n account: this.account,\n });\n\n return this.provider.getTransaction(txHash);\n }\n\n signTransaction(\n _transaction: Deferrable<TransactionRequest>\n ): Promise<string> {\n throw new Error(\n \"Transaction signing is not supported, use sendUserOperation instead\"\n );\n }\n\n getPublicErc4337Client(): BundlerClient<Transport> {\n return this.provider.getBundlerClient();\n }\n\n connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {\n this.provider = provider;\n\n return this;\n }\n}\n"]}
1
+ {"version":3,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AAC;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,6 +1,6 @@
1
1
  import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
2
  import { JsonRpcProvider } from "@ethersproject/providers";
3
- import { type Transport } from "viem";
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
6
  export declare class EthersProviderAdapter extends JsonRpcProvider {
@@ -9,5 +9,5 @@ export declare class EthersProviderAdapter extends JsonRpcProvider {
9
9
  send(method: any, params: any[]): Promise<any>;
10
10
  connectToAccount<TAccount extends SmartContractAccount>(account: TAccount): AccountSigner<TAccount>;
11
11
  getBundlerClient(): BundlerClient<Transport>;
12
- static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter;
12
+ static fromEthersProvider(provider: JsonRpcProvider, chain: Chain): EthersProviderAdapter;
13
13
  }
@@ -1,6 +1,6 @@
1
- import { createBundlerClientFromExisting, createSmartAccountClient, getChain, } from "@aa-sdk/core";
1
+ import { createBundlerClientFromExisting, createSmartAccountClient, } from "@aa-sdk/core";
2
2
  import { JsonRpcProvider } from "@ethersproject/providers";
3
- import { createPublicClient, custom, http } from "viem";
3
+ import { createPublicClient, custom, http, } from "viem";
4
4
  import { AccountSigner } from "./account-signer.js";
5
5
  export class EthersProviderAdapter extends JsonRpcProvider {
6
6
  constructor(opts) {
@@ -15,7 +15,7 @@ export class EthersProviderAdapter extends JsonRpcProvider {
15
15
  this.accountProvider = opts.accountProvider;
16
16
  }
17
17
  else {
18
- const chain = getChain(opts.chainId);
18
+ const { chain } = opts;
19
19
  if (typeof opts.rpcProvider === "string") {
20
20
  this.accountProvider = createSmartAccountClient({
21
21
  transport: http(opts.rpcProvider),
@@ -44,10 +44,10 @@ export class EthersProviderAdapter extends JsonRpcProvider {
44
44
  chain: this.accountProvider.chain,
45
45
  }));
46
46
  }
47
- static fromEthersProvider(provider) {
47
+ static fromEthersProvider(provider, chain) {
48
48
  return new EthersProviderAdapter({
49
49
  rpcProvider: provider.connection.url,
50
- chainId: provider.network.chainId,
50
+ chain,
51
51
  });
52
52
  }
53
53
  }
@@ -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,EACxB,QAAQ,GAIT,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,kBAAkB,EAAE,MAAM,EAAE,IAAI,EAAkB,MAAM,MAAM,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAKpD,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IAGxD,YAAY,IAA+B;QACzC,KAAK,EAAE,CAAC;QAHD;;;;;WAAoC;QAI3C,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC,eAAe,GAAG,IAAI,CAAC,eAAe,CAAC;QAC9C,CAAC;aAAM,CAAC;YACN,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;YACrC,IAAI,OAAO,IAAI,CAAC,WAAW,KAAK,QAAQ,EAAE,CAAC;gBACzC,IAAI,CAAC,eAAe,GAAG,wBAAwB,CAAC;oBAC9C,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC;oBACjC,KAAK;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,eAAe,GAAG,wBAAwB,CAAC;oBAC9C,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,SAAS,CAAC;oBAC7C,KAAK;oBACL,OAAO,EAAE,IAAI,CAAC,OAAO;iBACtB,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAUD,IAAI,CAAC,MAAW,EAAE,MAAa;QAE7B,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1D,CAAC;IAQD,gBAAgB,CACd,OAAiB;QAEjB,OAAO,IAAI,aAAa,CAAW,IAAI,EAAE,OAAO,CAAC,CAAC;IACpD,CAAC;IAED,gBAAgB;QACd,OAAO,+BAA+B,CACpC,kBAAkB,CAAC;YACjB,SAAS,EAAE,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC,SAAS,CAAC;YACjD,KAAK,EAAE,IAAI,CAAC,eAAe,CAAC,KAAM;SACnC,CAAC,CACH,CAAC;IACJ,CAAC;IAQD,MAAM,CAAC,kBAAkB,CAAC,QAAyB;QACjD,OAAO,IAAI,qBAAqB,CAAC;YAC/B,WAAW,EAAE,QAAQ,CAAC,UAAU,CAAC,GAAG;YACpC,OAAO,EAAE,QAAQ,CAAC,OAAO,CAAC,OAAO;SAClC,CAAC,CAAC;IACL,CAAC;CACF","sourcesContent":["import {\n createBundlerClientFromExisting,\n createSmartAccountClient,\n getChain,\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { JsonRpcProvider } from \"@ethersproject/providers\";\nimport { createPublicClient, custom, http, type Transport } from \"viem\";\nimport { AccountSigner } from \"./account-signer.js\";\nimport type { EthersProviderAdapterOpts } from \"./types.js\";\n\n/** Lightweight Adapter for SmartAccountProvider to enable Signer Creation */\n// TODO: Add support for strong entry point version type\nexport class EthersProviderAdapter extends JsonRpcProvider {\n readonly accountProvider: SmartAccountClient;\n\n constructor(opts: EthersProviderAdapterOpts) {\n super();\n if (\"accountProvider\" in opts) {\n this.accountProvider = opts.accountProvider;\n } else {\n const chain = getChain(opts.chainId);\n if (typeof opts.rpcProvider === \"string\") {\n this.accountProvider = createSmartAccountClient({\n transport: http(opts.rpcProvider),\n chain,\n account: opts.account,\n });\n } else {\n this.accountProvider = createSmartAccountClient({\n transport: custom(opts.rpcProvider.transport),\n chain,\n account: opts.account,\n });\n }\n }\n }\n\n /**\n * Rewrites the send method to use the account provider's EIP-1193\n * compliant request method\n *\n * @param method - the RPC method to call\n * @param params - the params required by the RPC method\n * @returns the result of the RPC call\n */\n send(method: any, params: any[]): Promise<any> {\n // @ts-expect-error - viem is strongly typed on the request methods, but ethers is not\n return this.accountProvider.request({ method, params });\n }\n\n /**\n * Connects the Provider to an Account and returns a Signer\n *\n * @param account - the account to connect to\n * @returns an {@link AccountSigner} that can be used to sign and send user operations\n */\n connectToAccount<TAccount extends SmartContractAccount>(\n account: TAccount\n ): AccountSigner<TAccount> {\n return new AccountSigner<TAccount>(this, account);\n }\n\n getBundlerClient(): BundlerClient<Transport> {\n return createBundlerClientFromExisting(\n createPublicClient({\n transport: custom(this.accountProvider.transport),\n chain: this.accountProvider.chain!,\n })\n );\n }\n\n /**\n * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.\n *\n * @param provider - the ethers JSON RPC provider to convert\n * @returns an instance of {@link EthersProviderAdapter}\n */\n static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter {\n return new EthersProviderAdapter({\n rpcProvider: provider.connection.url,\n chainId: provider.network.chainId,\n });\n }\n}\n"]}
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,qBA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,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"]}
@@ -4,7 +4,7 @@ export type EthersProviderAdapterOpts<TTransport extends Transport = Transport,
4
4
  account?: TAccount;
5
5
  } & ({
6
6
  rpcProvider: string | BundlerClient<TTransport>;
7
- chainId: number;
7
+ chain: Chain;
8
8
  } | {
9
9
  accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
10
10
  });
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,MAAM,cAAc,CAAC","sourcesContent":["import {\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Chain, Transport } from \"viem\";\n\nexport type EthersProviderAdapterOpts<\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n> = {\n account?: TAccount;\n} & (\n | {\n rpcProvider: string | BundlerClient<TTransport>;\n chainId: number;\n }\n | {\n accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;\n }\n);\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAIN,MAAM,cAAc,CAAC","sourcesContent":["import {\n type BundlerClient,\n type SmartAccountClient,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport type { Chain, Transport } from \"viem\";\n\nexport type EthersProviderAdapterOpts<\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined\n> = {\n account?: TAccount;\n} & (\n | {\n rpcProvider: string | BundlerClient<TTransport>;\n chain: Chain;\n }\n | {\n accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;\n }\n);\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.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esContent":["import type { Address, SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Signer } from \"@ethersproject/abstract-signer\";\nimport { Wallet } from \"@ethersproject/wallet\";\nimport type { SignableMessage, TypedData, TypedDataDefinition } from \"viem\";\n\n/**\n * Converts a ethersjs Wallet to a SmartAccountSigner\n *\n * @param wallet - the Wallet to convert\n * @returns - a signer that can be used to sign and send user operations\n */\nexport const convertWalletToAccountSigner = (\n wallet: Wallet\n): SmartAccountSigner<Wallet> => {\n return {\n inner: wallet,\n signerType: \"local\",\n getAddress: async () => Promise.resolve(wallet.address as `0x${string}`),\n signMessage: async (msg: SignableMessage) =>\n (await wallet.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n return (await wallet._signTypedData(\n params.domain ?? {},\n // @ts-expect-error: these params should line up due to the spec for this function\n params.types,\n params.message\n )) as `0x${string}`;\n },\n };\n};\n\n/**\n * Converts a ethers.js Signer to a SmartAccountSigner\n *\n * @param signer - the Signer to convert\n * @returns - a signer that can be used to sign and send user operations\n */\nexport const convertEthersSignerToAccountSigner = (\n signer: Signer\n): SmartAccountSigner<Signer> => {\n return {\n inner: signer,\n signerType: \"json-rpc\",\n getAddress: async () => signer.getAddress() as Promise<Address>,\n signMessage: async (msg: SignableMessage) =>\n (await signer.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n _params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n throw new Error(\n \"signTypedData is not supported for ethers signers; use Wallet\"\n );\n },\n };\n};\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,uBA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"@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"]}
@@ -4,17 +4,187 @@ 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>;
17
- getPublicErc4337Client(): BundlerClient<Transport>;
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
+ */
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
  }
20
190
  //# sourceMappingURL=account-signer.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"account-signer.d.ts","sourceRoot":"","sources":["../../src/account-signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,0BAA0B,EAC/B,KAAK,aAAa,EAClB,KAAK,wBAAwB,EAC7B,KAAK,oBAAoB,EACzB,KAAK,qBAAqB,EAC1B,KAAK,sBAAsB,EAC5B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,MAAM,EAAE,MAAM,gCAAgC,CAAC;AAExD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,OAAO,EACL,KAAK,kBAAkB,EACvB,KAA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AAI,aAAa,CAAC,SAAS,CAAC;IAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,OAAO,CAAC,QAAQ,EAAE,qBAAqB,GAAG,aAAa,CAAC,QAAQ,CAAC;CAKlE"}
@@ -1,35 +1,88 @@
1
1
  import { type BundlerClient, type SmartAccountClient, type SmartContractAccount } from "@aa-sdk/core";
2
2
  import { JsonRpcProvider } from "@ethersproject/providers";
3
- import { type Transport } from "viem";
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 SmartAccountProvider to enable Signer Creation */
6
+ /** Lightweight Adapter for SmtAccountProvider to enable Signer Creation */
7
7
  export declare class EthersProviderAdapter extends JsonRpcProvider {
8
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
+ */
9
34
  constructor(opts: EthersProviderAdapterOpts);
10
35
  /**
11
36
  * Rewrites the send method to use the account provider's EIP-1193
12
37
  * compliant request method
13
38
  *
14
- * @param method - the RPC method to call
15
- * @param params - the params required by the RPC method
16
- * @returns the result of the RPC call
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
17
42
  */
18
43
  send(method: any, params: any[]): Promise<any>;
19
44
  /**
20
45
  * Connects the Provider to an Account and returns a Signer
21
46
  *
22
- * @param account - the account to connect to
23
- * @returns an {@link AccountSigner} that can be used to sign and send user operations
47
+ * @param {SmartContractAccount} account - the account to connect to
48
+ * @returns {AccountSigner} an AccountSigner that can be used to sign and send user operations
24
49
  */
25
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
+ */
26
78
  getBundlerClient(): BundlerClient<Transport>;
27
79
  /**
28
80
  * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.
29
81
  *
30
- * @param provider - the ethers JSON RPC provider to convert
31
- * @returns an instance of {@link EthersProviderAdapter}
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
32
85
  */
33
- static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter;
86
+ static fromEthersProvider(provider: JsonRpcProvider, chain: Chain): EthersProviderAdapter;
34
87
  }
35
88
  //# sourceMappingURL=provider-adapter.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"provider-adapter.d.ts","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAoC,KAAK,SAAS,EAAE,MAAM,MAAM,CAAC;AACxE,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,6EAA6E;AAE7E,qBAAa,qBAAsB,SAAQ,eAAe;IACxD,QAAQ,CAAC,eAAe,EAAE,kBAAkB,CAAC;gBAEjC,IAAI,EAAE,yBAAyB;IAsB3C;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAK9C;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,SAAS,oBAAoB,EACpD,OAAO,EAAE,QAAQ,GAChB,aAAa,CAAC,QAAQ,CAAC;IAI1B,gBAAgB,IAAI,aAAa,CAAC,SAAS,CAAC;IAS5C;;;;;OAKG;IACH,MAAM,CAAC,kBAAkB,CAAC,QAAQ,EAAE,eAAe,GAAG,qBAAqB;CAM5E"}
1
+ {"version":3,"file":"provider-adapter.d.ts","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAIL,KAAK,KAAK,EACV,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,2EAA2E;AAC3E,qBAAa,qBAAsB,SAAQ,eAAe;IACxD,QAAQ,CAAC,eAAe,EAAE,kBAAkB,CAAC;IAE7C;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;gBACS,IAAI,EAAE,yBAAyB;IAuB3C;;;;;;;OAOG;IACH,IAAI,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,GAAG,CAAC;IAK9C;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,SAAS,oBAAoB,EACpD,OAAO,EAAE,QAAQ,GAChB,aAAa,CAAC,QAAQ,CAAC;IAI1B;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,gBAAgB,IAAI,aAAa,CAAC,SAAS,CAAC;IAS5C;;;;;;OAMG;IACH,MAAM,CAAC,kBAAkB,CACvB,QAAQ,EAAE,eAAe,EACzB,KAAK,EAAE,KAAK,GACX,qBAAqB;CAMzB"}
@@ -4,7 +4,7 @@ export type EthersProviderAdapterOpts<TTransport extends Transport = Transport,
4
4
  account?: TAccount;
5
5
  } & ({
6
6
  rpcProvider: string | BundlerClient<TTransport>;
7
- chainId: number;
7
+ chain: Chain;
8
8
  } | {
9
9
  accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
10
10
  });
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAE7C,MAAM,MAAM,yBAAyB,CACnC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,QAAQ,SAAS,oBAAoB,GAAG,SAAS,GAC7C,oBAAoB,GACpB,SAAS,IACX;IACF,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB,GAAG,CACA;IACE,WAAW,EAAE,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IAChD,OAAO,EAAE,MAAM,CAAC;CACjB,GACD;IACE,eAAe,EAAE,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;CACnE,CACJ,CAAC"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,aAAa,EAClB,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAE7C,MAAM,MAAM,yBAAyB,CACnC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,QAAQ,SAAS,oBAAoB,GAAG,SAAS,GAC7C,oBAAoB,GACpB,SAAS,IACX;IACF,OAAO,CAAC,EAAE,QAAQ,CAAC;CACpB,GAAG,CACA;IACE,WAAW,EAAE,MAAM,GAAG,aAAa,CAAC,UAAU,CAAC,CAAC;IAChD,KAAK,EAAE,KAAK,CAAC;CACd,GACD;IACE,eAAe,EAAE,kBAAkB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,CAAC;CACnE,CACJ,CAAC"}
@@ -4,15 +4,15 @@ import { Wallet } from "@ethersproject/wallet";
4
4
  /**
5
5
  * Converts a ethersjs Wallet to a SmartAccountSigner
6
6
  *
7
- * @param wallet - the Wallet to convert
8
- * @returns - a signer that can be used to sign and send user operations
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
9
  */
10
10
  export declare const convertWalletToAccountSigner: (wallet: Wallet) => SmartAccountSigner<Wallet>;
11
11
  /**
12
12
  * Converts a ethers.js Signer to a SmartAccountSigner
13
13
  *
14
- * @param signer - the Signer to convert
15
- * @returns - a signer that can be used to sign and send user operations
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
16
  */
17
17
  export declare const convertEthersSignerToAccountSigner: (signer: Signer) => SmartAccountSigner<Signer>;
18
18
  //# sourceMappingURL=utils.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aa-sdk/ethers",
3
3
  "license": "MIT",
4
- "version": "4.0.0-alpha.0",
4
+ "version": "4.0.0-alpha.10",
5
5
  "description": "Ethers.js wrapper for @aa-sdk/core",
6
6
  "author": "Alchemy",
7
7
  "type": "module",
@@ -36,20 +36,22 @@
36
36
  "build:cjs": "tsc --project tsconfig.build.json --module commonjs --outDir ./dist/cjs --removeComments --verbatimModuleSyntax false && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
37
37
  "build:esm": "tsc --project tsconfig.build.json --module es2020 --outDir ./dist/esm --removeComments && echo > ./dist/esm/package.json '{\"type\":\"module\"}'",
38
38
  "build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
39
+ "docs:gen": "npx ak-docgen generate --in ./src/index.ts --out ../../site/pages/reference/aa-sdk/ethers",
39
40
  "clean": "rm -rf ./dist",
40
41
  "test": "vitest",
41
42
  "test:run": "vitest run",
42
43
  "test:run-e2e": "vitest run --config vitest.config.e2e.ts"
43
44
  },
44
45
  "devDependencies": {
46
+ "@account-kit/smart-contracts": "4.0.0-alpha.4",
45
47
  "alchemy-sdk": "^3.0.0",
46
48
  "dotenv": "^16.0.3",
47
49
  "typescript": "^5.0.4",
48
50
  "typescript-template": "*",
49
- "vitest": "^0.31.0"
51
+ "vitest": "^2.0.4"
50
52
  },
51
53
  "dependencies": {
52
- "@aa-sdk/core": "^4.0.0-alpha.0",
54
+ "@aa-sdk/core": "^4.0.0-alpha.10",
53
55
  "@ethersproject/abi": "^5.7.0",
54
56
  "@ethersproject/abstract-signer": "^5.7.0",
55
57
  "@ethersproject/bytes": "^5.7.0",
@@ -70,5 +72,5 @@
70
72
  "bugs": {
71
73
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
72
74
  },
73
- "gitHead": "bd1788c2bd7f28ba762a06c649f30b544f8bade9"
75
+ "gitHead": "e3446b95cdee38c248f336857b24f78a32694076"
74
76
  }
@@ -26,6 +26,9 @@ const hexlifyOptional = (value: any): `0x${string}` | undefined => {
26
26
  return hexlify(value) as `0x${string}`;
27
27
  };
28
28
 
29
+ /**
30
+ * Implementation of the ethers Signer interface to use with Smart Contract Accounts
31
+ */
29
32
  export class AccountSigner<
30
33
  TAccount extends SmartContractAccount = SmartContractAccount,
31
34
  TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>
@@ -35,6 +38,31 @@ export class AccountSigner<
35
38
  sendUserOperation;
36
39
  waitForUserOperationTransaction;
37
40
 
41
+ /**
42
+ * Creates a new AccountSigner with the given ethers Provider and Smart Contract Account
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
+ *
62
+ * @template {SmartContractAccount} TAccount the type of the smart contract account
63
+ * @param {EthersProviderAdapter} provider the ethers provider to use
64
+ * @param {TAccount} account the smart contract account that will be used to sign user ops and send them
65
+ */
38
66
  constructor(public provider: EthersProviderAdapter, account: TAccount) {
39
67
  super();
40
68
  this.account = account;
@@ -55,7 +83,32 @@ export class AccountSigner<
55
83
  );
56
84
  }
57
85
 
58
- async getAddress(): Promise<string> {
86
+ /**
87
+ * Returns the account address if the account exists.
88
+ *
89
+ * @example
90
+ * ```ts
91
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
92
+ * import { LocalAccountSigner } from "@aa-sdk/core";
93
+ * import { sepolia } from "@account-kit/infra";
94
+ * import { createLightAccount } from "@account-kit/smart-contracts";
95
+ * import { http } from "viem";
96
+ *
97
+ * const account = await createLightAccount({
98
+ * transport: http("https://rpc.testnet.aepps.com"),
99
+ * chain: sepolia,
100
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
101
+ * });
102
+ *
103
+ * const provider = new EthersProviderAdapter();
104
+ * const signer = new AccountSigner(provider, account);
105
+ *
106
+ * const address = await signer.getAddress();
107
+ * ```
108
+ *
109
+ * @returns {Promise<string>} a promise that resolves to the account address
110
+ * @throws {AccountNotFoundError} if the account is not found
111
+ */ async getAddress(): Promise<string> {
59
112
  if (!this.account) {
60
113
  throw new AccountNotFoundError();
61
114
  }
@@ -63,6 +116,33 @@ export class AccountSigner<
63
116
  return this.account.address;
64
117
  }
65
118
 
119
+ /**
120
+ * Signs a message using the associated account.
121
+ *
122
+ * @example
123
+ * ```ts
124
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
125
+ * import { LocalAccountSigner } from "@aa-sdk/core";
126
+ * import { sepolia } from "@account-kit/infra";
127
+ * import { createLightAccount } from "@account-kit/smart-contracts";
128
+ * import { http } from "viem";
129
+ *
130
+ * const account = await createLightAccount({
131
+ * transport: http("https://rpc.testnet.aepps.com"),
132
+ * chain: sepolia,
133
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
134
+ * });
135
+ *
136
+ * const provider = new EthersProviderAdapter();
137
+ * const signer = new AccountSigner(provider, account);
138
+ *
139
+ * const message = await signer.signMessage("hello");
140
+ * ```
141
+ *
142
+ * @param {string | Uint8Array} message the message to be signed
143
+ * @returns {Promise<string>} a promise that resolves to the signed message
144
+ * @throws {AccountNotFoundError} if the account is not found
145
+ */
66
146
  signMessage(message: string | Uint8Array): Promise<string> {
67
147
  if (!this.account) {
68
148
  throw new AccountNotFoundError();
@@ -76,6 +156,37 @@ export class AccountSigner<
76
156
  });
77
157
  }
78
158
 
159
+ /**
160
+ * Sends a transaction using the account provider and returns the transaction response.
161
+ *
162
+ * @example
163
+ * ```ts
164
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
165
+ * import { LocalAccountSigner } from "@aa-sdk/core";
166
+ * import { sepolia } from "@account-kit/infra";
167
+ * import { createLightAccount } from "@account-kit/smart-contracts";
168
+ * import { http } from "viem";
169
+ *
170
+ * const account = await createLightAccount({
171
+ * transport: http("https://rpc.testnet.aepps.com"),
172
+ * chain: sepolia,
173
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
174
+ * });
175
+ *
176
+ * const provider = new EthersProviderAdapter();
177
+ * const signer = new AccountSigner(provider, account);
178
+ *
179
+ * const tx = await signer.sendTransaction({
180
+ * to: "0x1234567890123456789012345678901234567890",
181
+ * value: "0x0",
182
+ * data: "0x",
183
+ * });
184
+ * ```
185
+ *
186
+ * @param {Deferrable<TransactionRequest>} transaction the transaction request to be sent
187
+ * @returns {Promise<TransactionResponse>} a promise that resolves to the transaction response
188
+ * @throws {AccountNotFoundError} if the account is not found in the provider
189
+ */
79
190
  async sendTransaction(
80
191
  transaction: Deferrable<TransactionRequest>
81
192
  ): Promise<TransactionResponse> {
@@ -94,6 +205,12 @@ export class AccountSigner<
94
205
  return this.provider.getTransaction(txHash);
95
206
  }
96
207
 
208
+ /**
209
+ * Throws an error indicating that transaction signing is not supported and advises to use `sendUserOperation` instead.
210
+ *
211
+ * @param {Deferrable<TransactionRequest>} _transaction The transaction request
212
+ * @throws {Error} Will always throw an error indicating transaction signing is unsupported
213
+ */
97
214
  signTransaction(
98
215
  _transaction: Deferrable<TransactionRequest>
99
216
  ): Promise<string> {
@@ -102,10 +219,63 @@ export class AccountSigner<
102
219
  );
103
220
  }
104
221
 
105
- getPublicErc4337Client(): BundlerClient<Transport> {
222
+ /**
223
+ * Retrieves the BundlerClient instance from the provider.
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
228
+ * import { LocalAccountSigner } from "@aa-sdk/core";
229
+ * import { sepolia } from "@account-kit/infra";
230
+ * import { createLightAccount } from "@account-kit/smart-contracts";
231
+ * import { http } from "viem";
232
+ *
233
+ * const account = await createLightAccount({
234
+ * transport: http("https://rpc.testnet.aepps.com"),
235
+ * chain: sepolia,
236
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
237
+ * });
238
+ *
239
+ * const provider = new EthersProviderAdapter();
240
+ * const signer = new AccountSigner(provider, account);
241
+ *
242
+ * const bundler = signer.getBundlerClient();
243
+ * ```
244
+ *
245
+ * @returns {BundlerClient<Transport>} The BundlerClient instance
246
+ */
247
+ getBundlerClient(): BundlerClient<Transport> {
106
248
  return this.provider.getBundlerClient();
107
249
  }
108
250
 
251
+ /**
252
+ * Sets the provider for the account signer and returns the updated account signer instance.
253
+ * Note: this is not necessary since the Provider is required by the constructor. This is useful
254
+ * if you want to change the provider after the account signer has been created.
255
+ *
256
+ * @example
257
+ * ```ts
258
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
259
+ * import { LocalAccountSigner } from "@aa-sdk/core";
260
+ * import { sepolia } from "@account-kit/infra";
261
+ * import { createLightAccount } from "@account-kit/smart-contracts";
262
+ * import { http } from "viem";
263
+ *
264
+ * const account = await createLightAccount({
265
+ * transport: http("https://rpc.testnet.aepps.com"),
266
+ * chain: sepolia,
267
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
268
+ * });
269
+ *
270
+ * const provider = new EthersProviderAdapter();
271
+ * const signer = new AccountSigner(provider, account);
272
+ *
273
+ * signer.connect(provider);
274
+ * ```
275
+ *
276
+ * @param {EthersProviderAdapter} provider the provider to be set for the account signer
277
+ * @returns {AccountSigner<TAccount>} the updated account signer instance
278
+ */
109
279
  connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {
110
280
  this.provider = provider;
111
281
 
@@ -1,27 +1,57 @@
1
1
  import {
2
2
  createBundlerClientFromExisting,
3
3
  createSmartAccountClient,
4
- getChain,
5
4
  type BundlerClient,
6
5
  type SmartAccountClient,
7
6
  type SmartContractAccount,
8
7
  } from "@aa-sdk/core";
9
8
  import { JsonRpcProvider } from "@ethersproject/providers";
10
- import { createPublicClient, custom, http, type Transport } from "viem";
9
+ import {
10
+ createPublicClient,
11
+ custom,
12
+ http,
13
+ type Chain,
14
+ type Transport,
15
+ } from "viem";
11
16
  import { AccountSigner } from "./account-signer.js";
12
17
  import type { EthersProviderAdapterOpts } from "./types.js";
13
18
 
14
- /** Lightweight Adapter for SmartAccountProvider to enable Signer Creation */
15
- // TODO: Add support for strong entry point version type
19
+ /** Lightweight Adapter for SmtAccountProvider to enable Signer Creation */
16
20
  export class EthersProviderAdapter extends JsonRpcProvider {
17
21
  readonly accountProvider: SmartAccountClient;
18
22
 
23
+ /**
24
+ * Configures and initializes the account provider based on the given options.
25
+ *
26
+ * @example
27
+ * ```ts
28
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
29
+ * import { LocalAccountSigner } from "@aa-sdk/core";
30
+ * import { sepolia } from "@account-kit/infra";
31
+ * import { createLightAccount } from "@account-kit/smart-contracts";
32
+ *
33
+ * const account = await createLightAccount({
34
+ * transport: http("https://rpc.testnet.aepps.com"),
35
+ * chain: sepolia,
36
+ * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())
37
+ * });
38
+ *
39
+ * const provider = new EthersProviderAdapter({
40
+ * account,
41
+ * chain: sepolia,
42
+ * rpcProvider: "https://eth-sepolia.g.alchemy.com/v2/your-api-key"
43
+ * });
44
+ * ```
45
+ *
46
+ * @param {EthersProviderAdapterOpts} opts The options for setting up the ethers provider adapter
47
+ */
19
48
  constructor(opts: EthersProviderAdapterOpts) {
20
49
  super();
21
50
  if ("accountProvider" in opts) {
22
51
  this.accountProvider = opts.accountProvider;
23
52
  } else {
24
- const chain = getChain(opts.chainId);
53
+ const { chain } = opts;
54
+
25
55
  if (typeof opts.rpcProvider === "string") {
26
56
  this.accountProvider = createSmartAccountClient({
27
57
  transport: http(opts.rpcProvider),
@@ -42,9 +72,9 @@ export class EthersProviderAdapter extends JsonRpcProvider {
42
72
  * Rewrites the send method to use the account provider's EIP-1193
43
73
  * compliant request method
44
74
  *
45
- * @param method - the RPC method to call
46
- * @param params - the params required by the RPC method
47
- * @returns the result of the RPC call
75
+ * @param {any} method - the RPC method to call
76
+ * @param {any[]} params - the params required by the RPC method
77
+ * @returns {Promise<any>} the result of the RPC call
48
78
  */
49
79
  send(method: any, params: any[]): Promise<any> {
50
80
  // @ts-expect-error - viem is strongly typed on the request methods, but ethers is not
@@ -54,8 +84,8 @@ export class EthersProviderAdapter extends JsonRpcProvider {
54
84
  /**
55
85
  * Connects the Provider to an Account and returns a Signer
56
86
  *
57
- * @param account - the account to connect to
58
- * @returns an {@link AccountSigner} that can be used to sign and send user operations
87
+ * @param {SmartContractAccount} account - the account to connect to
88
+ * @returns {AccountSigner} an AccountSigner that can be used to sign and send user operations
59
89
  */
60
90
  connectToAccount<TAccount extends SmartContractAccount>(
61
91
  account: TAccount
@@ -63,6 +93,33 @@ export class EthersProviderAdapter extends JsonRpcProvider {
63
93
  return new AccountSigner<TAccount>(this, account);
64
94
  }
65
95
 
96
+ /**
97
+ * Creates and returns a BundlerClient using the existing account provider's transport and chain.
98
+ *
99
+ * @example
100
+ * ```ts
101
+ * import { AccountSigner, EthersProviderAdapter } from "@aa-sdk/ethers";
102
+ * import { LocalAccountSigner } from "@aa-sdk/core";
103
+ * import { sepolia } from "@account-kit/infra";
104
+ * import { createLightAccount } from "@account-kit/smart-contracts";
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
+ * account,
114
+ * chain: sepolia,
115
+ * rpcProvider: "https://eth-sepolia.g.alchemy.com/v2/your-api-key"
116
+ * });
117
+ *
118
+ * const bundlerClient = provider.getBundlerClient();
119
+ * ```
120
+ *
121
+ * @returns {BundlerClient<Transport>} A bundler client configured with the existing account provider.
122
+ */
66
123
  getBundlerClient(): BundlerClient<Transport> {
67
124
  return createBundlerClientFromExisting(
68
125
  createPublicClient({
@@ -75,13 +132,17 @@ export class EthersProviderAdapter extends JsonRpcProvider {
75
132
  /**
76
133
  * Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.
77
134
  *
78
- * @param provider - the ethers JSON RPC provider to convert
79
- * @returns an instance of {@link EthersProviderAdapter}
135
+ * @param {JsonRpcProvider} provider the ethers JSON RPC provider to convert
136
+ * @param {Chain} chain the chain to connect to
137
+ * @returns {EthersProviderAdapter} an instance of EthersProviderAdapter
80
138
  */
81
- static fromEthersProvider(provider: JsonRpcProvider): EthersProviderAdapter {
139
+ static fromEthersProvider(
140
+ provider: JsonRpcProvider,
141
+ chain: Chain
142
+ ): EthersProviderAdapter {
82
143
  return new EthersProviderAdapter({
83
144
  rpcProvider: provider.connection.url,
84
- chainId: provider.network.chainId,
145
+ chain,
85
146
  });
86
147
  }
87
148
  }
package/src/types.ts CHANGED
@@ -16,7 +16,7 @@ export type EthersProviderAdapterOpts<
16
16
  } & (
17
17
  | {
18
18
  rpcProvider: string | BundlerClient<TTransport>;
19
- chainId: number;
19
+ chain: Chain;
20
20
  }
21
21
  | {
22
22
  accountProvider: SmartAccountClient<TTransport, TChain, TAccount>;
package/src/utils.ts CHANGED
@@ -6,8 +6,8 @@ import type { SignableMessage, TypedData, TypedDataDefinition } from "viem";
6
6
  /**
7
7
  * Converts a ethersjs Wallet to a SmartAccountSigner
8
8
  *
9
- * @param wallet - the Wallet to convert
10
- * @returns - a signer that can be used to sign and send user operations
9
+ * @param {Wallet} wallet - the Wallet to convert
10
+ * @returns {SmartAccountSigner<Wallet>} a signer that can be used to sign and send user operations
11
11
  */
12
12
  export const convertWalletToAccountSigner = (
13
13
  wallet: Wallet
@@ -39,8 +39,8 @@ export const convertWalletToAccountSigner = (
39
39
  /**
40
40
  * Converts a ethers.js Signer to a SmartAccountSigner
41
41
  *
42
- * @param signer - the Signer to convert
43
- * @returns - a signer that can be used to sign and send user operations
42
+ * @param {Signer} signer - the Signer to convert
43
+ * @returns {SmartAccountSigner<Signer>} a signer that can be used to sign and send user operations
44
44
  */
45
45
  export const convertEthersSignerToAccountSigner = (
46
46
  signer: Signer