@aa-sdk/ethers 4.0.0-alpha.4 → 4.0.0-alpha.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/account-signer.d.ts +1 -1
- package/dist/cjs/account-signer.js +1 -1
- package/dist/cjs/account-signer.js.map +1 -1
- package/dist/cjs/provider-adapter.js.map +1 -1
- package/dist/cjs/utils.js.map +1 -1
- package/dist/esm/account-signer.d.ts +1 -1
- package/dist/esm/account-signer.js +1 -1
- package/dist/esm/account-signer.js.map +1 -1
- package/dist/esm/provider-adapter.js.map +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/dist/types/account-signer.d.ts +162 -2
- package/dist/types/account-signer.d.ts.map +1 -1
- package/dist/types/provider-adapter.d.ts +61 -9
- package/dist/types/provider-adapter.d.ts.map +1 -1
- package/dist/types/utils.d.ts +4 -4
- package/package.json +5 -3
- package/src/account-signer.ts +162 -2
- package/src/provider-adapter.ts +61 -10
- package/src/utils.ts +4 -4
|
@@ -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
|
-
|
|
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
|
-
|
|
82
|
+
getBundlerClient() {
|
|
83
83
|
return this.provider.getBundlerClient();
|
|
84
84
|
}
|
|
85
85
|
connect(provider) {
|
|
@@ -1 +1 @@
|
|
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":["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 * @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 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,KAAK,IAAI,IAAI,EAAE,CAAC;QAClB,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,OAAO,IAAA,eAAO,EAAC,KAAK,CAAkB,CAAC;AACzC,CAAC,CAAC;AAKF,MAAa,aAGX,SAAQ,wBAAM;IA+Bd,YAAmB,QAA+B,EAAE,OAAiB;QACnE,KAAK,EAAE,CAAC;QADE;;;;mBAAO,QAAQ;WAAuB;QA9BzC;;;;;WAAkB;QAE3B;;;;;WAAkB;QAClB;;;;;WAAgC;QA6B9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,iBAAiB,GAAG,CACvB,IAAwD,EACxD,SAAsD,EACtD,EAAE,CACF,IAAI,CA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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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":";;;AAAA,uCAMsB;AACtB,wDAA2D;AAC3D,+BAMc;AACd,2DAAoD;
|
|
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"]}
|
package/dist/cjs/utils.js.map
CHANGED
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
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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E3C,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC5D,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,MAAM,QAAQ,GAAG,MAAM,iBAAiB,CAAC,WAAW,CAAC,CAAC;QACtD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,eAAe,CAAC;YACjE,EAAE,EAAE,QAAQ,CAAC,EAA+B;YAC5C,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,IAAI,CAAC;YACpC,KAAK,EAAE,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK;YAC1C,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;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\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 * @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 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,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;AAKF,MAAM,OAAO,aAGX,SAAQ,MAAM;IA+Bd,YAAmB,QAA+B,EAAE,OAAiB;QACnE,KAAK,EAAE,CAAC;QADE;;;;mBAAO,QAAQ;WAAuB;QA9BzC;;;;;WAAkB;QAE3B;;;;;WAAkB;QAClB;;;;;WAAgC;QA6B9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QAEvB,IAAI,CAAC,iBAAiB,GAAG,CACvB,IAAwD,EACxD,SAAsD,EACtD,EAAE,CACF,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,iBAAiB,CAAC;YAC9C,EAAE,EAAE,IAAI;YACR,OAAO;YACP,SAAS;SACV,CAA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E,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,KAAK;YAC1C,OAAO,EAAE,IAAI,CAAC,OAAO;SACtB,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IAC9C,CAAC;IAQD,eAAe,CACb,YAA4C;QAE5C,MAAM,IAAI,KAAK,CACb,qEAAqE,CACtE,CAAC;IACJ,CAAC;IA2BD,gBAAgB;QACd,OAAO,IAAI,CAAC,QAAQ,CAAC,gBAAgB,EAAE,CAAC;IAC1C,CAAC;IA8BD,OAAO,CAAC,QAA+B;QACrC,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QAEzB,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import {\n AccountNotFoundError,\n resolveProperties,\n type BatchUserOperationCallData,\n type BundlerClient,\n type GetEntryPointFromAccount,\n type SmartContractAccount,\n type UserOperationCallData,\n type UserOperationOverrides,\n} from \"@aa-sdk/core\";\nimport { Signer } from \"@ethersproject/abstract-signer\";\nimport { hexlify } from \"@ethersproject/bytes\";\nimport type { Deferrable } from \"@ethersproject/properties\";\nimport {\n type TransactionRequest,\n type TransactionResponse,\n} from \"@ethersproject/providers\";\nimport { isHex, toBytes, type Transport } from \"viem\";\nimport { EthersProviderAdapter } from \"./provider-adapter.js\";\n\nconst hexlifyOptional = (value: any): `0x${string}` | undefined => {\n if (value == null) {\n return undefined;\n }\n\n return hexlify(value) as `0x${string}`;\n};\n\n/**\n * Implementation of the ethers Signer interface to use with Smart Contract Accounts\n */\nexport class AccountSigner<\n TAccount extends SmartContractAccount = SmartContractAccount,\n TEntryPointVersion extends GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>\n> extends Signer {\n readonly account: TAccount;\n\n sendUserOperation;\n waitForUserOperationTransaction;\n\n /**\n * Creates a new AccountSigner with the given ethers Provider and Smart Contract Account\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n * ```\n *\n * @template {SmartContractAccount} TAccount the type of the smart contract account\n * @param {EthersProviderAdapter} provider the ethers provider to use\n * @param {TAccount} account the smart contract account that will be used to sign user ops and send them\n */\n constructor(public provider: EthersProviderAdapter, account: TAccount) {\n super();\n this.account = account;\n\n this.sendUserOperation = (\n args: UserOperationCallData | BatchUserOperationCallData,\n overrides?: UserOperationOverrides<TEntryPointVersion>\n ) =>\n this.provider.accountProvider.sendUserOperation({\n uo: args,\n account,\n overrides,\n });\n\n this.waitForUserOperationTransaction =\n this.provider.accountProvider.waitForUserOperationTransaction.bind(\n this.provider.accountProvider\n );\n }\n\n /**\n * Returns the account address if the account exists.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const address = await signer.getAddress();\n * ```\n *\n * @returns {Promise<string>} a promise that resolves to the account address\n * @throws {AccountNotFoundError} if the account is not found\n */ async getAddress(): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.address;\n }\n\n /**\n * Signs a message using the associated account.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const message = await signer.signMessage(\"hello\");\n * ```\n *\n * @param {string | Uint8Array} message the message to be signed\n * @returns {Promise<string>} a promise that resolves to the signed message\n * @throws {AccountNotFoundError} if the account is not found\n */\n signMessage(message: string | Uint8Array): Promise<string> {\n if (!this.account) {\n throw new AccountNotFoundError();\n }\n\n return this.account.signMessage({\n message:\n typeof message === \"string\" && !isHex(message)\n ? message\n : { raw: isHex(message) ? toBytes(message) : message },\n });\n }\n\n /**\n * Sends a transaction using the account provider and returns the transaction response.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const tx = await signer.sendTransaction({\n * to: \"0x1234567890123456789012345678901234567890\",\n * value: \"0x0\",\n * data: \"0x\",\n * });\n * ```\n *\n * @param {Deferrable<TransactionRequest>} transaction the transaction request to be sent\n * @returns {Promise<TransactionResponse>} a promise that resolves to the transaction response\n * @throws {AccountNotFoundError} if the account is not found in the provider\n */\n async sendTransaction(\n transaction: Deferrable<TransactionRequest>\n ): Promise<TransactionResponse> {\n if (!this.provider.accountProvider.account || !this.account) {\n throw new AccountNotFoundError();\n }\n\n const resolved = await resolveProperties(transaction);\n const txHash = await this.provider.accountProvider.sendTransaction({\n to: resolved.to as `0x${string}` | undefined,\n data: hexlifyOptional(resolved.data),\n chain: this.provider.accountProvider.chain,\n account: this.account,\n });\n\n return this.provider.getTransaction(txHash);\n }\n\n /**\n * Throws an error indicating that transaction signing is not supported and advises to use `sendUserOperation` instead.\n *\n * @param {Deferrable<TransactionRequest>} _transaction The transaction request\n * @throws {Error} Will always throw an error indicating transaction signing is unsupported\n */\n signTransaction(\n _transaction: Deferrable<TransactionRequest>\n ): Promise<string> {\n throw new Error(\n \"Transaction signing is not supported, use sendUserOperation instead\"\n );\n }\n\n /**\n * Retrieves the BundlerClient instance from the provider.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * const bundler = signer.getBundlerClient();\n * ```\n *\n * @returns {BundlerClient<Transport>} The BundlerClient instance\n */\n getBundlerClient(): BundlerClient<Transport> {\n return this.provider.getBundlerClient();\n }\n\n /**\n * Sets the provider for the account signer and returns the updated account signer instance.\n * Note: this is not necessary since the Provider is required by the constructor. This is useful\n * if you want to change the provider after the account signer has been created.\n *\n * @example\n * ```ts\n * import { AccountSigner, EthersProviderAdapter } from \"@aa-sdk/ethers\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n * import { sepolia } from \"@account-kit/infra\";\n * import { createLightAccount } from \"@account-kit/smart-contracts\";\n * import { http } from \"viem\";\n *\n * const account = await createLightAccount({\n * transport: http(\"https://rpc.testnet.aepps.com\"),\n * chain: sepolia,\n * signer: LocalAccountSigner.privateKeyToAccountSigner(generatePrivateKey())\n * });\n *\n * const provider = new EthersProviderAdapter();\n * const signer = new AccountSigner(provider, account);\n *\n * signer.connect(provider);\n * ```\n *\n * @param {EthersProviderAdapter} provider the provider to be set for the account signer\n * @returns {AccountSigner<TAccount>} the updated account signer instance\n */\n connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {\n this.provider = provider;\n\n return this;\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,GAIzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,IAAI,GAGL,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"provider-adapter.js","sourceRoot":"","sources":["../../src/provider-adapter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,wBAAwB,GAIzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EACL,kBAAkB,EAClB,MAAM,EACN,IAAI,GAGL,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAIpD,MAAM,OAAO,qBAAsB,SAAQ,eAAe;IA4BxD,YAAY,IAA+B;QACzC,KAAK,EAAE,CAAC;QA5BD;;;;;WAAoC;QA6B3C,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC;YAC9B,IAAI,CAAC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Existing,\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"]}
|
package/dist/esm/utils.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file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;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Address, SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Signer } from \"@ethersproject/abstract-signer\";\nimport { Wallet } from \"@ethersproject/wallet\";\nimport type { SignableMessage, TypedData, TypedDataDefinition } from \"viem\";\n\n/**\n * Converts a ethersjs Wallet to a SmartAccountSigner\n *\n * @param wallet - the Wallet to convert\n * @returns
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAS/C,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,MAAc,EACc,EAAE;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,OAAO;QACnB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,OAAwB,CAAC;QACxE,WAAW,EAAE,KAAK,EAAE,GAAoB,EAAE,EAAE,CAC1C,CAAC,MAAM,MAAM,CAAC,WAAW,CACvB,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CACxC,CAAkB;QACrB,aAAa,EAAE,KAAK,EAIlB,MAAqD,EACrD,EAAE;YACF,OAAO,CAAC,MAAM,MAAM,CAAC,cAAc,CACjC,MAAM,CAAC,MAAM,IAAI,EAAE,EAEnB,MAAM,CAAC,KAAK,EACZ,MAAM,CAAC,OAAO,CACf,CAAkB,CAAC;QACtB,CAAC;KACF,CAAC;AACJ,CAAC,CAAC;AAQF,MAAM,CAAC,MAAM,kCAAkC,GAAG,CAChD,MAAc,EACc,EAAE;IAC9B,OAAO;QACL,KAAK,EAAE,MAAM;QACb,UAAU,EAAE,UAAU;QACtB,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,MAAM,CAAC,UAAU,EAAsB;QAC/D,WAAW,EAAE,KAAK,EAAE,GAAoB,EAAE,EAAE,CAC1C,CAAC,MAAM,MAAM,CAAC,WAAW,CACvB,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CACxC,CAAkB;QACrB,aAAa,EAAE,KAAK,EAIlB,OAAsD,EACtD,EAAE;YACF,MAAM,IAAI,KAAK,CACb,+DAA+D,CAChE,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { Address, SmartAccountSigner } from \"@aa-sdk/core\";\nimport type { Signer } from \"@ethersproject/abstract-signer\";\nimport { Wallet } from \"@ethersproject/wallet\";\nimport type { SignableMessage, TypedData, TypedDataDefinition } from \"viem\";\n\n/**\n * Converts a ethersjs Wallet to a SmartAccountSigner\n *\n * @param {Wallet} wallet - the Wallet to convert\n * @returns {SmartAccountSigner<Wallet>} a signer that can be used to sign and send user operations\n */\nexport const convertWalletToAccountSigner = (\n wallet: Wallet\n): SmartAccountSigner<Wallet> => {\n return {\n inner: wallet,\n signerType: \"local\",\n getAddress: async () => Promise.resolve(wallet.address as `0x${string}`),\n signMessage: async (msg: SignableMessage) =>\n (await wallet.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n return (await wallet._signTypedData(\n params.domain ?? {},\n // @ts-expect-error: these params should line up due to the spec for this function\n params.types,\n params.message\n )) as `0x${string}`;\n },\n };\n};\n\n/**\n * Converts a ethers.js Signer to a SmartAccountSigner\n *\n * @param {Signer} signer - the Signer to convert\n * @returns {SmartAccountSigner<Signer>} a signer that can be used to sign and send user operations\n */\nexport const convertEthersSignerToAccountSigner = (\n signer: Signer\n): SmartAccountSigner<Signer> => {\n return {\n inner: signer,\n signerType: \"json-rpc\",\n getAddress: async () => signer.getAddress() as Promise<Address>,\n signMessage: async (msg: SignableMessage) =>\n (await signer.signMessage(\n typeof msg === \"string\" ? msg : msg.raw\n )) as `0x${string}`,\n signTypedData: async <\n const TTypedData extends TypedData | { [key: string]: unknown },\n TPrimaryType extends string = string\n >(\n _params: TypedDataDefinition<TTypedData, TPrimaryType>\n ) => {\n throw new Error(\n \"signTypedData is not supported for ethers signers; use Wallet\"\n );\n },\n };\n};\n"]}
|
|
@@ -15,16 +15,176 @@ export declare class AccountSigner<TAccount extends SmartContractAccount = Smart
|
|
|
15
15
|
/**
|
|
16
16
|
* Creates a new AccountSigner with the given ethers Provider and Smart Contract Account
|
|
17
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
|
+
*
|
|
18
36
|
* @template {SmartContractAccount} TAccount the type of the smart contract account
|
|
19
37
|
* @param {EthersProviderAdapter} provider the ethers provider to use
|
|
20
38
|
* @param {TAccount} account the smart contract account that will be used to sign user ops and send them
|
|
21
39
|
*/
|
|
22
40
|
constructor(provider: EthersProviderAdapter, account: TAccount);
|
|
23
|
-
|
|
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
|
+
*/
|
|
24
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
|
+
*/
|
|
25
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
|
+
*/
|
|
26
133
|
signTransaction(_transaction: Deferrable<TransactionRequest>): Promise<string>;
|
|
27
|
-
|
|
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
|
+
*/
|
|
28
188
|
connect(provider: EthersProviderAdapter): AccountSigner<TAccount>;
|
|
29
189
|
}
|
|
30
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,KAAK,mBAAmB,EACzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAkB,KAAK,SAAS,EAAE,MAAM,MAAM,CAAC;AACtD,OAAO,EAAE,qBAAqB,EAAE,MAAM,uBAAuB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U,IAAI,OAAO,CAAC,MAAM,CAAC;IAQvC;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC;IAa1D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA8BG;IACG,eAAe,CACnB,WAAW,EAAE,UAAU,CAAC,kBAAkB,CAAC,GAC1C,OAAO,CAAC,mBAAmB,CAAC;IAgB/B;;;;;OAKG;IACH,eAAe,CACb,YAAY,EAAE,UAAU,CAAC,kBAAkB,CAAC,GAC3C,OAAO,CAAC,MAAM,CAAC;IAMlB;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,gBAAgB,IAAI,aAAa,CAAC,SAAS,CAAC;IAI5C;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2BG;IACH,OAAO,CAAC,QAAQ,EAAE,qBAAqB,GAAG,aAAa,CAAC,QAAQ,CAAC;CAKlE"}
|
|
@@ -3,33 +3,85 @@ import { JsonRpcProvider } from "@ethersproject/providers";
|
|
|
3
3
|
import { type Chain, type Transport } from "viem";
|
|
4
4
|
import { AccountSigner } from "./account-signer.js";
|
|
5
5
|
import type { EthersProviderAdapterOpts } from "./types.js";
|
|
6
|
-
/** Lightweight Adapter for
|
|
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
|
|
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
|
-
* @param chain the chain to connect to
|
|
32
|
-
* @returns an instance of
|
|
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
|
|
33
85
|
*/
|
|
34
86
|
static fromEthersProvider(provider: JsonRpcProvider, chain: Chain): EthersProviderAdapter;
|
|
35
87
|
}
|
|
@@ -1 +1 @@
|
|
|
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,KAA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AAe,EACzB,KAAK,EAAE,KAAK,GACX,qBAAqB;CAMzB"}
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
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.
|
|
4
|
+
"version": "4.0.0-alpha.6",
|
|
5
5
|
"description": "Ethers.js wrapper for @aa-sdk/core",
|
|
6
6
|
"author": "Alchemy",
|
|
7
7
|
"type": "module",
|
|
@@ -36,12 +36,14 @@
|
|
|
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",
|
|
@@ -49,7 +51,7 @@
|
|
|
49
51
|
"vitest": "^0.31.0"
|
|
50
52
|
},
|
|
51
53
|
"dependencies": {
|
|
52
|
-
"@aa-sdk/core": "^4.0.0-alpha.
|
|
54
|
+
"@aa-sdk/core": "^4.0.0-alpha.6",
|
|
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": "
|
|
75
|
+
"gitHead": "2c35ec701f526c77ea5e00e2e6f147156c7ac0e4"
|
|
74
76
|
}
|
package/src/account-signer.ts
CHANGED
|
@@ -41,6 +41,24 @@ export class AccountSigner<
|
|
|
41
41
|
/**
|
|
42
42
|
* Creates a new AccountSigner with the given ethers Provider and Smart Contract Account
|
|
43
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
|
+
*
|
|
44
62
|
* @template {SmartContractAccount} TAccount the type of the smart contract account
|
|
45
63
|
* @param {EthersProviderAdapter} provider the ethers provider to use
|
|
46
64
|
* @param {TAccount} account the smart contract account that will be used to sign user ops and send them
|
|
@@ -65,7 +83,32 @@ export class AccountSigner<
|
|
|
65
83
|
);
|
|
66
84
|
}
|
|
67
85
|
|
|
68
|
-
|
|
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> {
|
|
69
112
|
if (!this.account) {
|
|
70
113
|
throw new AccountNotFoundError();
|
|
71
114
|
}
|
|
@@ -73,6 +116,33 @@ export class AccountSigner<
|
|
|
73
116
|
return this.account.address;
|
|
74
117
|
}
|
|
75
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
|
+
*/
|
|
76
146
|
signMessage(message: string | Uint8Array): Promise<string> {
|
|
77
147
|
if (!this.account) {
|
|
78
148
|
throw new AccountNotFoundError();
|
|
@@ -86,6 +156,37 @@ export class AccountSigner<
|
|
|
86
156
|
});
|
|
87
157
|
}
|
|
88
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
|
+
*/
|
|
89
190
|
async sendTransaction(
|
|
90
191
|
transaction: Deferrable<TransactionRequest>
|
|
91
192
|
): Promise<TransactionResponse> {
|
|
@@ -104,6 +205,12 @@ export class AccountSigner<
|
|
|
104
205
|
return this.provider.getTransaction(txHash);
|
|
105
206
|
}
|
|
106
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
|
+
*/
|
|
107
214
|
signTransaction(
|
|
108
215
|
_transaction: Deferrable<TransactionRequest>
|
|
109
216
|
): Promise<string> {
|
|
@@ -112,10 +219,63 @@ export class AccountSigner<
|
|
|
112
219
|
);
|
|
113
220
|
}
|
|
114
221
|
|
|
115
|
-
|
|
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> {
|
|
116
248
|
return this.provider.getBundlerClient();
|
|
117
249
|
}
|
|
118
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
|
+
*/
|
|
119
279
|
connect(provider: EthersProviderAdapter): AccountSigner<TAccount> {
|
|
120
280
|
this.provider = provider;
|
|
121
281
|
|
package/src/provider-adapter.ts
CHANGED
|
@@ -16,11 +16,35 @@ import {
|
|
|
16
16
|
import { AccountSigner } from "./account-signer.js";
|
|
17
17
|
import type { EthersProviderAdapterOpts } from "./types.js";
|
|
18
18
|
|
|
19
|
-
/** Lightweight Adapter for
|
|
20
|
-
// TODO: Add support for strong entry point version type
|
|
19
|
+
/** Lightweight Adapter for SmtAccountProvider to enable Signer Creation */
|
|
21
20
|
export class EthersProviderAdapter extends JsonRpcProvider {
|
|
22
21
|
readonly accountProvider: SmartAccountClient;
|
|
23
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
|
+
*/
|
|
24
48
|
constructor(opts: EthersProviderAdapterOpts) {
|
|
25
49
|
super();
|
|
26
50
|
if ("accountProvider" in opts) {
|
|
@@ -48,9 +72,9 @@ export class EthersProviderAdapter extends JsonRpcProvider {
|
|
|
48
72
|
* Rewrites the send method to use the account provider's EIP-1193
|
|
49
73
|
* compliant request method
|
|
50
74
|
*
|
|
51
|
-
* @param method - the RPC method to call
|
|
52
|
-
* @param params - the params required by the RPC method
|
|
53
|
-
* @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
|
|
54
78
|
*/
|
|
55
79
|
send(method: any, params: any[]): Promise<any> {
|
|
56
80
|
// @ts-expect-error - viem is strongly typed on the request methods, but ethers is not
|
|
@@ -60,8 +84,8 @@ export class EthersProviderAdapter extends JsonRpcProvider {
|
|
|
60
84
|
/**
|
|
61
85
|
* Connects the Provider to an Account and returns a Signer
|
|
62
86
|
*
|
|
63
|
-
* @param account - the account to connect to
|
|
64
|
-
* @returns
|
|
87
|
+
* @param {SmartContractAccount} account - the account to connect to
|
|
88
|
+
* @returns {AccountSigner} an AccountSigner that can be used to sign and send user operations
|
|
65
89
|
*/
|
|
66
90
|
connectToAccount<TAccount extends SmartContractAccount>(
|
|
67
91
|
account: TAccount
|
|
@@ -69,6 +93,33 @@ export class EthersProviderAdapter extends JsonRpcProvider {
|
|
|
69
93
|
return new AccountSigner<TAccount>(this, account);
|
|
70
94
|
}
|
|
71
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
|
+
*/
|
|
72
123
|
getBundlerClient(): BundlerClient<Transport> {
|
|
73
124
|
return createBundlerClientFromExisting(
|
|
74
125
|
createPublicClient({
|
|
@@ -81,9 +132,9 @@ export class EthersProviderAdapter extends JsonRpcProvider {
|
|
|
81
132
|
/**
|
|
82
133
|
* Creates an instance of EthersProviderAdapter from an ethers.js JsonRpcProvider.
|
|
83
134
|
*
|
|
84
|
-
* @param provider the ethers JSON RPC provider to convert
|
|
85
|
-
* @param chain the chain to connect to
|
|
86
|
-
* @returns an instance of
|
|
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
|
|
87
138
|
*/
|
|
88
139
|
static fromEthersProvider(
|
|
89
140
|
provider: JsonRpcProvider,
|
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
|
|
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
|
|
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
|