@aa-sdk/core 4.66.3 → 4.67.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (28) hide show
  1. package/dist/esm/actions/smartAccount/internal/initUserOperation.d.ts +2 -2
  2. package/dist/esm/actions/smartAccount/internal/initUserOperation.js +28 -0
  3. package/dist/esm/actions/smartAccount/internal/initUserOperation.js.map +1 -1
  4. package/dist/esm/middleware/defaults/7702gasEstimator.d.ts +1 -26
  5. package/dist/esm/middleware/defaults/7702gasEstimator.js +1 -26
  6. package/dist/esm/middleware/defaults/7702gasEstimator.js.map +1 -1
  7. package/dist/esm/middleware/defaults/7702signer.d.ts +1 -26
  8. package/dist/esm/middleware/defaults/7702signer.js +1 -26
  9. package/dist/esm/middleware/defaults/7702signer.js.map +1 -1
  10. package/dist/esm/middleware/defaults/userOpSigner.js +28 -0
  11. package/dist/esm/middleware/defaults/userOpSigner.js.map +1 -1
  12. package/dist/esm/version.d.ts +1 -1
  13. package/dist/esm/version.js +1 -1
  14. package/dist/esm/version.js.map +1 -1
  15. package/dist/types/actions/smartAccount/internal/initUserOperation.d.ts +2 -2
  16. package/dist/types/actions/smartAccount/internal/initUserOperation.d.ts.map +1 -1
  17. package/dist/types/middleware/defaults/7702gasEstimator.d.ts +1 -26
  18. package/dist/types/middleware/defaults/7702gasEstimator.d.ts.map +1 -1
  19. package/dist/types/middleware/defaults/7702signer.d.ts +1 -26
  20. package/dist/types/middleware/defaults/7702signer.d.ts.map +1 -1
  21. package/dist/types/middleware/defaults/userOpSigner.d.ts.map +1 -1
  22. package/dist/types/version.d.ts +1 -1
  23. package/package.json +2 -2
  24. package/src/actions/smartAccount/internal/initUserOperation.ts +38 -4
  25. package/src/middleware/defaults/7702gasEstimator.ts +1 -26
  26. package/src/middleware/defaults/7702signer.ts +1 -26
  27. package/src/middleware/defaults/userOpSigner.ts +40 -0
  28. package/src/version.ts +1 -1
@@ -1,5 +1,5 @@
1
- import type { Chain, Transport } from "viem";
2
- import type { GetEntryPointFromAccount, SmartContractAccount } from "../../../account/smartContractAccount.js";
1
+ import { type Chain, type Transport } from "viem";
2
+ import { type GetEntryPointFromAccount, type SmartContractAccount } from "../../../account/smartContractAccount.js";
3
3
  import type { BaseSmartAccountClient } from "../../../client/smartAccountClient.js";
4
4
  import type { UserOperationStruct } from "../../../types.js";
5
5
  import { type Deferrable } from "../../../utils/index.js";
@@ -1,3 +1,5 @@
1
+ import { concatHex, toHex, zeroHash } from "viem";
2
+ import { isSmartAccountWithSigner, } from "../../../account/smartContractAccount.js";
1
3
  import { AccountNotFoundError } from "../../../errors/account.js";
2
4
  import { ChainNotFoundError } from "../../../errors/client.js";
3
5
  import { conditionalReturn } from "../../../utils/index.js";
@@ -46,6 +48,32 @@ export async function _initUserOperation(client, args) {
46
48
  callData,
47
49
  signature,
48
50
  };
51
+ const is7702 = account.source === "ModularAccountV2" &&
52
+ isSmartAccountWithSigner(account) &&
53
+ (await account.getSigner().getAddress()).toLowerCase() ===
54
+ account.address.toLowerCase();
55
+ if (is7702) {
56
+ if (entryPoint.version !== "0.7.0") {
57
+ throw new Error("7702 is only compatible with EntryPoint v0.7.0");
58
+ }
59
+ const [implementationAddress, code = "0x", nonce] = await Promise.all([
60
+ account.getImplementationAddress(),
61
+ client.getCode({ address: account.address }),
62
+ client.getTransactionCount({ address: account.address }),
63
+ ]);
64
+ const isAlreadyDelegated = code.toLowerCase() ===
65
+ concatHex(["0xef0100", implementationAddress]).toLowerCase();
66
+ if (!isAlreadyDelegated) {
67
+ struct.eip7702Auth = {
68
+ chainId: toHex(client.chain.id),
69
+ nonce: toHex(nonce),
70
+ address: implementationAddress,
71
+ r: zeroHash, // aka `bytes32(0)`
72
+ s: zeroHash,
73
+ yParity: "0x0",
74
+ };
75
+ }
76
+ }
49
77
  return struct;
50
78
  }
51
79
  //# sourceMappingURL=initUserOperation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"initUserOperation.js","sourceRoot":"","sources":["../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C8C;QAC3D,CAAC,CAAE;YACC,OAAO,EAAE,iBAAiB,CACxB,OAAO,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EACzD,OAAO,CAAC,iBAAiB,CAC1B;YACD,WAAW,EAAE,iBAAiB,CAC5B,OAAO,CAAC,iBAAiB,EAAE,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,QAAQ,CAAC,EACzD,OAAO,CAAC,cAAc,CACvB;YACD,MAAM,EAAE,OAAO,CAAC,OAAO;YACvB,KAAK;YACL,QAAQ;YACR,SAAS;SAC8C,CAAC;IAEhE,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { Chain, Transport } from \"viem\";\nimport type {\n GetEntryPointFromAccount,\n SmartContractAccount,\n} from \"../../../account/smartContractAccount.js\";\nimport type { BaseSmartAccountClient } from \"../../../client/smartAccountClient.js\";\nimport { AccountNotFoundError } from \"../../../errors/account.js\";\nimport { ChainNotFoundError } from \"../../../errors/client.js\";\nimport type { UserOperationStruct } from \"../../../types.js\";\nimport { conditionalReturn, type Deferrable } from \"../../../utils/index.js\";\nimport type {\n BuildUserOperationParameters,\n SendUserOperationParameters,\n UserOperationContext,\n} from \"../types.js\";\n\n/**\n * Description internal action function of SmartAccountClient for initializing\n * a user operation for the sender account\n *\n * @template {Transport} TTransport\n * @template {Chain | undefined} TChain\n * @template {SmartContractAccount | undefined} TAccount\n * @template {UserOperationContext | undefined} TContext\n * @template {GetEntryPointFromAccount} TEntryPointVersion\n * @param {BaseSmartAccountClient<TTransport, TChain, TAccount>} client smart account client\n * @param {SendUserOperationParameters<TAccount, TContext, TEntryPointVersion> | BuildUserOperationParameters<TAccount, TContext, TEntryPointVersion>} args send user operation parameters\n * @returns {Promise<Deferrable<UserOperationStruct<TEntryPointVersion>>>} initialized user operation struct\n */\nexport async function _initUserOperation<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined,\n TEntryPointVersion extends\n GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>,\n>(\n client: BaseSmartAccountClient<TTransport, TChain, TAccount>,\n args:\n | SendUserOperationParameters<TAccount, TContext, TEntryPointVersion>\n | BuildUserOperationParameters<TAccount, TContext, TEntryPointVersion>,\n): Promise<Deferrable<UserOperationStruct<TEntryPointVersion>>> {\n const { account = client.account, uo, overrides } = args;\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const entryPoint = account.getEntryPoint();\n\n const callData = Array.isArray(uo)\n ? account.encodeBatchExecute(uo)\n : typeof uo === \"string\"\n ? uo\n : account.encodeExecute(uo);\n\n const signature = account.getDummySignature();\n\n const nonce =\n overrides?.nonce ?? account.getAccountNonce(overrides?.nonceKey);\n\n const struct =\n entryPoint.version === \"0.6.0\"\n ? ({\n initCode: account.getInitCode(),\n sender: account.address,\n nonce,\n callData,\n signature,\n } as Deferrable<UserOperationStruct<TEntryPointVersion>>)\n : ({\n factory: conditionalReturn(\n account.isAccountDeployed().then((deployed) => !deployed),\n account.getFactoryAddress,\n ),\n factoryData: conditionalReturn(\n account.isAccountDeployed().then((deployed) => !deployed),\n account.getFactoryData,\n ),\n sender: account.address,\n nonce,\n callData,\n signature,\n } as Deferrable<UserOperationStruct<TEntryPointVersion>>);\n\n return struct;\n}\n"]}
1
+ {"version":3,"file":"initUserOperation.js","sourceRoot":"","sources":["../../../../../src/actions/smartAccount/internal/initUserOperation.ts"],"names":[],"mappings":"AAAA,OAAO,EAA8B,SAAS,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AAC9E,OAAO,EACL,wBAAwB,GAGzB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EAAE,oBAAoB,EAAE,MAAM,4B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EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC/B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAC;gBACnB,OAAO,EAAE,qBAAqB;gBAC9B,CAAC,EAAE,QAAQ,EAAE,mBAAmB;gBAChC,CAAC,EAAE,QAAQ;gBACX,OAAO,EAAE,KAAK;aACf,CAAC;QACJ,CAAC;IACH,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { type Chain, type Transport, concatHex, toHex, zeroHash } from \"viem\";\nimport {\n isSmartAccountWithSigner,\n type GetEntryPointFromAccount,\n type SmartContractAccount,\n} from \"../../../account/smartContractAccount.js\";\nimport type { BaseSmartAccountClient } from \"../../../client/smartAccountClient.js\";\nimport { AccountNotFoundError } from \"../../../errors/account.js\";\nimport { ChainNotFoundError } from \"../../../errors/client.js\";\nimport type { UserOperationStruct } from \"../../../types.js\";\nimport { conditionalReturn, type Deferrable } from \"../../../utils/index.js\";\nimport type {\n BuildUserOperationParameters,\n SendUserOperationParameters,\n UserOperationContext,\n} from \"../types.js\";\n\n/**\n * Description internal action function of SmartAccountClient for initializing\n * a user operation for the sender account\n *\n * @template {Transport} TTransport\n * @template {Chain | undefined} TChain\n * @template {SmartContractAccount | undefined} TAccount\n * @template {UserOperationContext | undefined} TContext\n * @template {GetEntryPointFromAccount} TEntryPointVersion\n * @param {BaseSmartAccountClient<TTransport, TChain, TAccount>} client smart account client\n * @param {SendUserOperationParameters<TAccount, TContext, TEntryPointVersion> | BuildUserOperationParameters<TAccount, TContext, TEntryPointVersion>} args send user operation parameters\n * @returns {Promise<Deferrable<UserOperationStruct<TEntryPointVersion>>>} initialized user operation struct\n */\nexport async function _initUserOperation<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartContractAccount | undefined =\n | SmartContractAccount\n | undefined,\n TContext extends UserOperationContext | undefined =\n | UserOperationContext\n | undefined,\n TEntryPointVersion extends\n GetEntryPointFromAccount<TAccount> = GetEntryPointFromAccount<TAccount>,\n>(\n client: BaseSmartAccountClient<TTransport, TChain, TAccount>,\n args:\n | SendUserOperationParameters<TAccount, TContext, TEntryPointVersion>\n | BuildUserOperationParameters<TAccount, TContext, TEntryPointVersion>,\n): Promise<Deferrable<UserOperationStruct<TEntryPointVersion>>> {\n const { account = client.account, uo, overrides } = args;\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const entryPoint = account.getEntryPoint();\n\n const callData = Array.isArray(uo)\n ? account.encodeBatchExecute(uo)\n : typeof uo === \"string\"\n ? uo\n : account.encodeExecute(uo);\n\n const signature = account.getDummySignature();\n\n const nonce =\n overrides?.nonce ?? account.getAccountNonce(overrides?.nonceKey);\n\n const struct =\n entryPoint.version === \"0.6.0\"\n ? ({\n initCode: account.getInitCode(),\n sender: account.address,\n nonce,\n callData,\n signature,\n } as Deferrable<UserOperationStruct<TEntryPointVersion>>)\n : ({\n factory: conditionalReturn(\n account.isAccountDeployed().then((deployed) => !deployed),\n account.getFactoryAddress,\n ),\n factoryData: conditionalReturn(\n account.isAccountDeployed().then((deployed) => !deployed),\n account.getFactoryData,\n ),\n sender: account.address,\n nonce,\n callData,\n signature,\n } as Deferrable<UserOperationStruct<TEntryPointVersion>>);\n\n const is7702 =\n account.source === \"ModularAccountV2\" &&\n isSmartAccountWithSigner(account) &&\n (await account.getSigner().getAddress()).toLowerCase() ===\n account.address.toLowerCase();\n\n if (is7702) {\n if (entryPoint.version !== \"0.7.0\") {\n throw new Error(\"7702 is only compatible with EntryPoint v0.7.0\");\n }\n\n const [implementationAddress, code = \"0x\", nonce] = await Promise.all([\n account.getImplementationAddress(),\n client.getCode({ address: account.address }),\n client.getTransactionCount({ address: account.address }),\n ]);\n\n const isAlreadyDelegated =\n code.toLowerCase() ===\n concatHex([\"0xef0100\", implementationAddress]).toLowerCase();\n\n if (!isAlreadyDelegated) {\n (struct as UserOperationStruct<\"0.7.0\">).eip7702Auth = {\n chainId: toHex(client.chain.id),\n nonce: toHex(nonce),\n address: implementationAddress,\n r: zeroHash, // aka `bytes32(0)`\n s: zeroHash,\n yParity: \"0x0\",\n };\n }\n }\n\n return struct;\n}\n"]}
@@ -3,32 +3,7 @@ import type { ClientMiddlewareFn } from "../types";
3
3
  * A middleware function to estimate the gas usage of a user operation when using an EIP-7702 delegated account. Has an optional custom gas estimator.
4
4
  * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.
5
5
  *
6
- * @example
7
- * ```ts twoslash
8
- * import {
9
- * default7702GasEstimator,
10
- * default7702UserOpSigner,
11
- * createSmartAccountClient,
12
- * type SmartAccountClient,
13
- * } from "@aa-sdk/core";
14
- * import {
15
- * createModularAccountV2,
16
- * type CreateModularAccountV2ClientParams,
17
- * } from "@account-kit/smart-contracts";
18
- *
19
- * async function createSMA7702AccountClient(
20
- * config: CreateModularAccountV2ClientParams
21
- * ): Promise<SmartAccountClient> {
22
- * const sma7702Account = await createModularAccountV2({ ...config, mode: "7702" });
23
- *
24
- * return createSmartAccountClient({
25
- * account: sma7702Account,
26
- * gasEstimator: default7702GasEstimator(config.gasEstimator),
27
- * signUserOperation: default7702UserOpSigner(config.signUserOperation),
28
- * ...config,
29
- * });
30
- * }
31
- * ```
6
+ * @deprecated The EIP-7702 auth is now set in initUserOperation instead. This middleware is no longer necessary.
32
7
  *
33
8
  * @param {ClientMiddlewareFn} gasEstimator Optional custom gas estimator function
34
9
  * @returns {ClientMiddlewareFn} A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.
@@ -5,32 +5,7 @@ import { defaultGasEstimator } from "./gasEstimator.js";
5
5
  * A middleware function to estimate the gas usage of a user operation when using an EIP-7702 delegated account. Has an optional custom gas estimator.
6
6
  * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.
7
7
  *
8
- * @example
9
- * ```ts twoslash
10
- * import {
11
- * default7702GasEstimator,
12
- * default7702UserOpSigner,
13
- * createSmartAccountClient,
14
- * type SmartAccountClient,
15
- * } from "@aa-sdk/core";
16
- * import {
17
- * createModularAccountV2,
18
- * type CreateModularAccountV2ClientParams,
19
- * } from "@account-kit/smart-contracts";
20
- *
21
- * async function createSMA7702AccountClient(
22
- * config: CreateModularAccountV2ClientParams
23
- * ): Promise<SmartAccountClient> {
24
- * const sma7702Account = await createModularAccountV2({ ...config, mode: "7702" });
25
- *
26
- * return createSmartAccountClient({
27
- * account: sma7702Account,
28
- * gasEstimator: default7702GasEstimator(config.gasEstimator),
29
- * signUserOperation: default7702UserOpSigner(config.signUserOperation),
30
- * ...config,
31
- * });
32
- * }
33
- * ```
8
+ * @deprecated The EIP-7702 auth is now set in initUserOperation instead. This middleware is no longer necessary.
34
9
  *
35
10
  * @param {ClientMiddlewareFn} gasEstimator Optional custom gas estimator function
36
11
  * @returns {ClientMiddlewareFn} A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.
@@ -1 +1 @@
1
- {"version":3,"file":"7702gasEstimator.js","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702gasEstimator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAG/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGlC,CAAC,YAAiC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;IAC9D,MAAM,aAAa,GAAG,YAAY,IAAI,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEzE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAC3C,IAAI,UAAU,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,qBAAqB,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC7D,OAAO,CAAC,wBAAwB,EAAE;QAClC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;KAC3D,CAAC,CAAC;IAEH,MAAM,kBAAkB,GACtB,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAExE,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACvB,MAAuC,CAAC,WAAW,GAAG;YACrD,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;YAClD,KAAK,EAAE,WAAW,CAChB,MAAM,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;gBACtC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;aAChC,CAAC,CACH;YACD,OAAO,EAAE,qBAAqB;YAC9B,CAAC,EAAE,QAAQ,EAAE,mBAAmB;YAChC,CAAC,EAAE,QAAQ;YACX,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC,CAAC","sourcesContent":["import { concatHex, numberToHex, zeroHash } from \"viem\";\nimport { AccountNotFoundError } from \"../../errors/account.js\";\nimport type { UserOperationStruct } from \"../../types.js\";\nimport type { ClientMiddlewareFn } from \"../types\";\nimport { defaultGasEstimator } from \"./gasEstimator.js\";\n\n/**\n * A middleware function to estimate the gas usage of a user operation when using an EIP-7702 delegated account. Has an optional custom gas estimator.\n * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.\n *\n * @example\n * ```ts twoslash\n * import {\n * default7702GasEstimator,\n * default7702UserOpSigner,\n * createSmartAccountClient,\n * type SmartAccountClient,\n * } from \"@aa-sdk/core\";\n * import {\n * createModularAccountV2,\n * type CreateModularAccountV2ClientParams,\n * } from \"@account-kit/smart-contracts\";\n *\n * async function createSMA7702AccountClient(\n * config: CreateModularAccountV2ClientParams\n * ): Promise<SmartAccountClient> {\n * const sma7702Account = await createModularAccountV2({ ...config, mode: \"7702\" });\n *\n * return createSmartAccountClient({\n * account: sma7702Account,\n * gasEstimator: default7702GasEstimator(config.gasEstimator),\n * signUserOperation: default7702UserOpSigner(config.signUserOperation),\n * ...config,\n * });\n * }\n * ```\n *\n * @param {ClientMiddlewareFn} gasEstimator Optional custom gas estimator function\n * @returns {ClientMiddlewareFn} A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.\n */\nexport const default7702GasEstimator: (\n gasEstimator?: ClientMiddlewareFn,\n) => ClientMiddlewareFn =\n (gasEstimator?: ClientMiddlewareFn) => async (struct, params) => {\n const gasEstimator_ = gasEstimator ?? defaultGasEstimator(params.client);\n\n const account = params.account ?? params.client.account;\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n const entryPoint = account.getEntryPoint();\n if (entryPoint.version !== \"0.7.0\") {\n throw new Error(\n \"This middleware is only compatible with EntryPoint v0.7.0\",\n );\n }\n\n const [implementationAddress, code = \"0x\"] = await Promise.all([\n account.getImplementationAddress(),\n params.client.getCode({ address: params.account.address }),\n ]);\n\n const isAlreadyDelegated =\n code.toLowerCase() === concatHex([\"0xef0100\", implementationAddress]);\n\n if (!isAlreadyDelegated) {\n (struct as UserOperationStruct<\"0.7.0\">).eip7702Auth = {\n chainId: numberToHex(params.client.chain?.id ?? 0),\n nonce: numberToHex(\n await params.client.getTransactionCount({\n address: params.account.address,\n }),\n ),\n address: implementationAddress,\n r: zeroHash, // aka `bytes32(0)`\n s: zeroHash,\n yParity: \"0x0\",\n };\n }\n\n return gasEstimator_(struct, params);\n };\n"]}
1
+ {"version":3,"file":"7702gasEstimator.js","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702gasEstimator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAG/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGlC,CAAC,YAAiC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;IAC9D,MAAM,aAAa,GAAG,YAAY,IAAI,mBAAmB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEzE,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;IACxD,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,UAAU,GAAG,OAAO,CAAC,aAAa,EAAE,CAAC;IAC3C,IAAI,UAAU,CAAC,OAAO,KAAK,OAAO,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CACb,2DAA2D,CAC5D,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,qBAAqB,EAAE,IAAI,GAAG,IAAI,CAAC,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC;QAC7D,OAAO,CAAC,wBAAwB,EAAE;QAClC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;KAC3D,CAAC,CAAC;IAEH,MAAM,kBAAkB,GACtB,IAAI,CAAC,WAAW,EAAE,KAAK,SAAS,CAAC,CAAC,UAAU,EAAE,qBAAqB,CAAC,CAAC,CAAC;IAExE,IAAI,CAAC,kBAAkB,EAAE,CAAC;QACvB,MAAuC,CAAC,WAAW,GAAG;YACrD,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,IAAI,CAAC,CAAC;YAClD,KAAK,EAAE,WAAW,CAChB,MAAM,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;gBACtC,OAAO,EAAE,MAAM,CAAC,OAAO,CAAC,OAAO;aAChC,CAAC,CACH;YACD,OAAO,EAAE,qBAAqB;YAC9B,CAAC,EAAE,QAAQ,EAAE,mBAAmB;YAChC,CAAC,EAAE,QAAQ;YACX,OAAO,EAAE,KAAK;SACf,CAAC;IACJ,CAAC;IAED,OAAO,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AACvC,CAAC,CAAC","sourcesContent":["import { concatHex, numberToHex, zeroHash } from \"viem\";\nimport { AccountNotFoundError } from \"../../errors/account.js\";\nimport type { UserOperationStruct } from \"../../types.js\";\nimport type { ClientMiddlewareFn } from \"../types\";\nimport { defaultGasEstimator } from \"./gasEstimator.js\";\n\n/**\n * A middleware function to estimate the gas usage of a user operation when using an EIP-7702 delegated account. Has an optional custom gas estimator.\n * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.\n *\n * @deprecated The EIP-7702 auth is now set in initUserOperation instead. This middleware is no longer necessary.\n *\n * @param {ClientMiddlewareFn} gasEstimator Optional custom gas estimator function\n * @returns {ClientMiddlewareFn} A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.\n */\nexport const default7702GasEstimator: (\n gasEstimator?: ClientMiddlewareFn,\n) => ClientMiddlewareFn =\n (gasEstimator?: ClientMiddlewareFn) => async (struct, params) => {\n const gasEstimator_ = gasEstimator ?? defaultGasEstimator(params.client);\n\n const account = params.account ?? params.client.account;\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n const entryPoint = account.getEntryPoint();\n if (entryPoint.version !== \"0.7.0\") {\n throw new Error(\n \"This middleware is only compatible with EntryPoint v0.7.0\",\n );\n }\n\n const [implementationAddress, code = \"0x\"] = await Promise.all([\n account.getImplementationAddress(),\n params.client.getCode({ address: params.account.address }),\n ]);\n\n const isAlreadyDelegated =\n code.toLowerCase() === concatHex([\"0xef0100\", implementationAddress]);\n\n if (!isAlreadyDelegated) {\n (struct as UserOperationStruct<\"0.7.0\">).eip7702Auth = {\n chainId: numberToHex(params.client.chain?.id ?? 0),\n nonce: numberToHex(\n await params.client.getTransactionCount({\n address: params.account.address,\n }),\n ),\n address: implementationAddress,\n r: zeroHash, // aka `bytes32(0)`\n s: zeroHash,\n yParity: \"0x0\",\n };\n }\n\n return gasEstimator_(struct, params);\n };\n"]}
@@ -4,32 +4,7 @@ import type { ClientMiddlewareFn } from "../types";
4
4
  * If the signer doesn't support `signAuthorization`, then this just runs the provided `signUserOperation` middleware.
5
5
  * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.
6
6
  *
7
- * @example
8
- * ```ts twoslash
9
- * import {
10
- * default7702GasEstimator,
11
- * default7702UserOpSigner,
12
- * createSmartAccountClient,
13
- * type SmartAccountClient,
14
- * } from "@aa-sdk/core";
15
- * import {
16
- * createModularAccountV2,
17
- * type CreateModularAccountV2ClientParams,
18
- * } from "@account-kit/smart-contracts";
19
- *
20
- * async function createSMA7702AccountClient(
21
- * config: CreateModularAccountV2ClientParams
22
- * ): Promise<SmartAccountClient> {
23
- * const sma7702Account = await createModularAccountV2({ ...config, mode: "7702" });
24
- *
25
- * return createSmartAccountClient({
26
- * account: sma7702Account,
27
- * gasEstimator: default7702GasEstimator(config.gasEstimator),
28
- * signUserOperation: default7702UserOpSigner(config.signUserOperation),
29
- * ...config,
30
- * });
31
- * }
32
- * ```
7
+ * @deprecated The EIP-7702 auth signature is now handled by the defaultUserOpSigner middleware. This middleware is no longer necessary.
33
8
  *
34
9
  * @param {ClientMiddlewareFn} [userOpSigner] Optional user operation signer function
35
10
  * @returns {ClientMiddlewareFn} A middleware function that signs EIP-7702 authorization tuples if necessary, and also uses the provided or default user operation signer to generate the user op signature.
@@ -8,32 +8,7 @@ import { defaultUserOpSigner } from "./userOpSigner.js";
8
8
  * If the signer doesn't support `signAuthorization`, then this just runs the provided `signUserOperation` middleware.
9
9
  * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.
10
10
  *
11
- * @example
12
- * ```ts twoslash
13
- * import {
14
- * default7702GasEstimator,
15
- * default7702UserOpSigner,
16
- * createSmartAccountClient,
17
- * type SmartAccountClient,
18
- * } from "@aa-sdk/core";
19
- * import {
20
- * createModularAccountV2,
21
- * type CreateModularAccountV2ClientParams,
22
- * } from "@account-kit/smart-contracts";
23
- *
24
- * async function createSMA7702AccountClient(
25
- * config: CreateModularAccountV2ClientParams
26
- * ): Promise<SmartAccountClient> {
27
- * const sma7702Account = await createModularAccountV2({ ...config, mode: "7702" });
28
- *
29
- * return createSmartAccountClient({
30
- * account: sma7702Account,
31
- * gasEstimator: default7702GasEstimator(config.gasEstimator),
32
- * signUserOperation: default7702UserOpSigner(config.signUserOperation),
33
- * ...config,
34
- * });
35
- * }
36
- * ```
11
+ * @deprecated The EIP-7702 auth signature is now handled by the defaultUserOpSigner middleware. This middleware is no longer necessary.
37
12
  *
38
13
  * @param {ClientMiddlewareFn} [userOpSigner] Optional user operation signer function
39
14
  * @returns {ClientMiddlewareFn} A middleware function that signs EIP-7702 authorization tuples if necessary, and also uses the provided or default user operation signer to generate the user op signature.
@@ -1 +1 @@
1
- {"version":3,"file":"7702signer.js","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702signer.ts"],"names":[],"mappings":"AAAA,OAAO,E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AM,WAAW,GAAG,MAAM,OAAO,CAAC,wBAAwB,EAAE,CAAC;IAE7D,MAAM,YAAY,GAAG,UAAU,GAAG,WAAW,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAEvD,IAAI,IAAI,CAAC,WAAW,EAAE,KAAK,YAAY,CAAC,WAAW,EAAE,EAAE,CAAC;QACtD,iHAAiH;QACjH,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,YAAY,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC;QAC3D,OAAO,EAAE,OAAO,CAAC,OAAO;KACzB,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC;QACnD,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE;QACxB,eAAe,EAAE,WAAW;QAC5B,KAAK,EAAE,YAAY;KACpB,CAAC,CAAC;IAEH,MAAM,EAAE,CAAC,EAAE,CAAC,EAAE,GAAG,aAAa,CAAC;IAE/B,MAAM,OAAO,GAAG,aAAa,CAAC,OAAO,IAAI,aAAa,CAAC,CAAC,GAAG,GAAG,CAAC;IAE/D,OAAO;QACL,GAAG,EAAE;QACL,WAAW,EAAE;YACX,kEAAkE;YAClE,OAAO,EAAE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,WAAW;YACpB,CAAC;YACD,CAAC;YACD,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;SACxB;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { toHex } from \"viem\";\nimport { isSmartAccountWithSigner } from \"../../account/smartContractAccount.js\";\nimport { AccountNotFoundError } from \"../../errors/account.js\";\nimport { ChainNotFoundError } from \"../../errors/client.js\";\nimport type { ClientMiddlewareFn } from \"../types\";\nimport { defaultUserOpSigner } from \"./userOpSigner.js\";\n\n/**\n * Provides a default middleware function for signing user operations with a client account when using EIP-7702 delegated accounts.\n * If the signer doesn't support `signAuthorization`, then this just runs the provided `signUserOperation` middleware.\n * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.\n *\n * @example\n * ```ts twoslash\n * import {\n * default7702GasEstimator,\n * default7702UserOpSigner,\n * createSmartAccountClient,\n * type SmartAccountClient,\n * } from \"@aa-sdk/core\";\n * import {\n * createModularAccountV2,\n * type CreateModularAccountV2ClientParams,\n * } from \"@account-kit/smart-contracts\";\n *\n * async function createSMA7702AccountClient(\n * config: CreateModularAccountV2ClientParams\n * ): Promise<SmartAccountClient> {\n * const sma7702Account = await createModularAccountV2({ ...config, mode: \"7702\" });\n *\n * return createSmartAccountClient({\n * account: sma7702Account,\n * gasEstimator: default7702GasEstimator(config.gasEstimator),\n * signUserOperation: default7702UserOpSigner(config.signUserOperation),\n * ...config,\n * });\n * }\n * ```\n *\n * @param {ClientMiddlewareFn} [userOpSigner] Optional user operation signer function\n * @returns {ClientMiddlewareFn} A middleware function that signs EIP-7702 authorization tuples if necessary, and also uses the provided or default user operation signer to generate the user op signature.\n */\nexport const default7702UserOpSigner: (\n userOpSigner?: ClientMiddlewareFn,\n) => ClientMiddlewareFn =\n (userOpSigner?: ClientMiddlewareFn) => async (struct, params) => {\n const userOpSigner_ = userOpSigner ?? defaultUserOpSigner;\n\n const uo = await userOpSigner_(\n {\n ...struct,\n // Strip out the dummy eip7702 fields.\n eip7702Auth: undefined,\n },\n params,\n );\n\n const account = params.account ?? params.client.account;\n const { client } = params;\n\n if (!account || !isSmartAccountWithSigner(account)) {\n throw new AccountNotFoundError();\n }\n\n const signer = account.getSigner();\n\n if (!signer.signAuthorization) {\n return uo;\n }\n\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const code = (await client.getCode({ address: account.address })) ?? \"0x\";\n\n const implAddress = await account.getImplementationAddress();\n\n const expectedCode = \"0xef0100\" + implAddress.slice(2);\n\n if (code.toLowerCase() === expectedCode.toLowerCase()) {\n // If the delegation already matches the expected, then we don't need to sign and include an authorization tuple.\n return uo;\n }\n\n const accountNonce = await params.client.getTransactionCount({\n address: account.address,\n });\n\n const authSignature = await signer.signAuthorization({\n chainId: client.chain.id,\n contractAddress: implAddress,\n nonce: accountNonce,\n });\n\n const { r, s } = authSignature;\n\n const yParity = authSignature.yParity ?? authSignature.v - 27n;\n\n return {\n ...uo,\n eip7702Auth: {\n // deepHexlify doesn't encode number(0) correctly, it returns \"0x\"\n chainId: toHex(client.chain.id),\n nonce: toHex(accountNonce),\n address: implAddress,\n r,\n s,\n yParity: toHex(yParity),\n },\n };\n };\n"]}
1
+ {"version":3,"file":"7702signer.js","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702signer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,CAAC;AAC7B,OAAO,EAAE,wBAAwB,EAAE,MAAM,uCAAuC,CAAC;AACjF,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAE5D,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAExD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,uBAAuB,GAGlC,CAAC,YAAiC,EAAE,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE;IAC9D,MAAM,aAAa,GAAG,YAAY,IAAI,mBAAmB,CAAC;IAE1D,MAAM,EAAE,GAAG,MAAM,aAAa,CAC5B;QACE,GAAG,MAAM;QACT,sCAAsC;QACtC,WAAW,EAAE,SAAS;KACvB,EACD,MAAM,CACP,CAAC;IAEF,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;IACxD,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAE1B,IAAI,CAAC,OAAO,IAAI,CAAC,wBAAwB,CAAC,O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AE,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YAC/B,KAAK,EAAE,KAAK,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,WAAW;YACpB,CAAC;YACD,CAAC;YACD,OAAO,EAAE,KAAK,CAAC,OAAO,CAAC;SACxB;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { toHex } from \"viem\";\nimport { isSmartAccountWithSigner } from \"../../account/smartContractAccount.js\";\nimport { AccountNotFoundError } from \"../../errors/account.js\";\nimport { ChainNotFoundError } from \"../../errors/client.js\";\nimport type { ClientMiddlewareFn } from \"../types\";\nimport { defaultUserOpSigner } from \"./userOpSigner.js\";\n\n/**\n * Provides a default middleware function for signing user operations with a client account when using EIP-7702 delegated accounts.\n * If the signer doesn't support `signAuthorization`, then this just runs the provided `signUserOperation` middleware.\n * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.\n *\n * @deprecated The EIP-7702 auth signature is now handled by the defaultUserOpSigner middleware. This middleware is no longer necessary.\n *\n * @param {ClientMiddlewareFn} [userOpSigner] Optional user operation signer function\n * @returns {ClientMiddlewareFn} A middleware function that signs EIP-7702 authorization tuples if necessary, and also uses the provided or default user operation signer to generate the user op signature.\n */\nexport const default7702UserOpSigner: (\n userOpSigner?: ClientMiddlewareFn,\n) => ClientMiddlewareFn =\n (userOpSigner?: ClientMiddlewareFn) => async (struct, params) => {\n const userOpSigner_ = userOpSigner ?? defaultUserOpSigner;\n\n const uo = await userOpSigner_(\n {\n ...struct,\n // Strip out the dummy eip7702 fields.\n eip7702Auth: undefined,\n },\n params,\n );\n\n const account = params.account ?? params.client.account;\n const { client } = params;\n\n if (!account || !isSmartAccountWithSigner(account)) {\n throw new AccountNotFoundError();\n }\n\n const signer = account.getSigner();\n\n if (!signer.signAuthorization) {\n return uo;\n }\n\n if (!client.chain) {\n throw new ChainNotFoundError();\n }\n\n const code = (await client.getCode({ address: account.address })) ?? \"0x\";\n\n const implAddress = await account.getImplementationAddress();\n\n const expectedCode = \"0xef0100\" + implAddress.slice(2);\n\n if (code.toLowerCase() === expectedCode.toLowerCase()) {\n // If the delegation already matches the expected, then we don't need to sign and include an authorization tuple.\n return uo;\n }\n\n const accountNonce = await params.client.getTransactionCount({\n address: account.address,\n });\n\n const authSignature = await signer.signAuthorization({\n chainId: client.chain.id,\n contractAddress: implAddress,\n nonce: accountNonce,\n });\n\n const { r, s } = authSignature;\n\n const yParity = authSignature.yParity ?? authSignature.v - 27n;\n\n return {\n ...uo,\n eip7702Auth: {\n // deepHexlify doesn't encode number(0) correctly, it returns \"0x\"\n chainId: toHex(client.chain.id),\n nonce: toHex(accountNonce),\n address: implAddress,\n r,\n s,\n yParity: toHex(yParity),\n },\n };\n };\n"]}
@@ -2,6 +2,9 @@ import { AccountNotFoundError } from "../../errors/account.js";
2
2
  import { ChainNotFoundError } from "../../errors/client.js";
3
3
  import { InvalidUserOperationError } from "../../errors/useroperation.js";
4
4
  import { deepHexlify, isValidRequest, resolveProperties, } from "../../utils/index.js";
5
+ import { hexToNumber, toHex } from "viem";
6
+ import { isSmartAccountWithSigner, } from "../../account/smartContractAccount.js";
7
+ import { BaseError } from "../../errors/base.js";
5
8
  /**
6
9
  * Provides a default middleware function for signing user operations with a client account. This function validates the request and adds the signature to it.
7
10
  * This is already included in the client returned from `createSmartAccountClient`
@@ -27,6 +30,31 @@ export const defaultUserOpSigner = async (struct, { client, account = client.acc
27
30
  return {
28
31
  ...resolvedStruct,
29
32
  signature: await account.signUserOperationHash(account.getEntryPoint().getUserOperationHash(request)),
33
+ ...(resolvedStruct.eip7702Auth && {
34
+ eip7702Auth: await signAuthorization(account, resolvedStruct.eip7702Auth),
35
+ }),
36
+ };
37
+ };
38
+ const signAuthorization = async (account, unsignedAuthorization) => {
39
+ if (!account || !isSmartAccountWithSigner(account)) {
40
+ throw new AccountNotFoundError();
41
+ }
42
+ const signer = account.getSigner();
43
+ if (!signer.signAuthorization) {
44
+ throw new BaseError("Signer must implement signAuthorization to sign EIP-7702 authorizations.");
45
+ }
46
+ const signedAuthorization = await signer.signAuthorization({
47
+ chainId: hexToNumber(unsignedAuthorization.chainId),
48
+ contractAddress: unsignedAuthorization.address,
49
+ nonce: hexToNumber(unsignedAuthorization.nonce),
50
+ });
51
+ return {
52
+ chainId: toHex(signedAuthorization.chainId),
53
+ nonce: toHex(signedAuthorization.nonce),
54
+ address: signedAuthorization.address,
55
+ r: signedAuthorization.r,
56
+ s: signedAuthorization.s,
57
+ yParity: toHex(signedAuthorization.yParity ?? signedAuthorization.v - 27n),
30
58
  };
31
59
  };
32
60
  //# sourceMappingURL=userOpSigner.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"userOpSigner.js","sourceRoot":"","sources":["../../../../src/middleware/defaults/userOpSigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAE,yBAAyB,EAAE,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EACL,WAAW,EACX,cAAc,EACd,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAG9B;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAuB,KAAK,EAC1D,MAAM,EACN,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC,OAAO,EAAE,EACpC,EAAE;IACF,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC;QACnB,MAAM,IAAI,kBAAkB,EAAE,CAAC;IACjC,CAAC;IAED,MAAM,cAAc,GAAG,MAAM,iBAAiB,CAAC,MAAM,CAAC,CAAC;IACvD,MAAM,OAAO,GAAG,WAAW,CAAC,cAAc,CAAC,CAAC;IAC5C,IAAI,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,yBAAyB,CAAC,cAAc,CAAC,CAAC;IACtD,CAAC;IAED,OAAO;QACL,GAAG,cAAc;QACjB,SAAS,EAAE,MAAM,OAAO,CAAC,qBAAqB,CAC5C,OAAO,CAAC,aAAa,EAAE,CAAC,oBAAoB,CAAC,OAAO,CAAC,CACtD;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { AccountNotFoundError } from \"../../errors/account.js\";\nimport { ChainNotFoundError } from \"../../errors/client.js\";\nimport { InvalidUserOperationError } from \"../../errors/useroperation.js\";\nimport {\n deepHexlify,\n isValidRequest,\n resolveProperties,\n} from \"../../utils/index.js\";\nimport type { ClientMiddlewareFn } from \"../types\";\n\n/**\n * Provides a default middleware function for signing user operations with a client account. This function validates the request and adds the signature to it.\n * This is already included in the client returned from `createSmartAccountClient`\n *\n * @param {UserOperationStruct} struct The user operation structure to be signed\n * @param {*} context The middleware context containing the client and account information\n * @param {Client} context.client The client object, which should include account and chain information\n * @param {Account} [context.account] Optional, the account used for signing, defaults to the client's account if not provided\n * @returns {Promise<UserOperationStruct>} A promise that resolves to the signed user operation structure\n */\nexport const defaultUserOpSigner: ClientMiddlewareFn = async (\n struct,\n { client, account = client.account },\n) => {\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!client?.chain) {\n throw new ChainNotFoundError();\n }\n\n const resolvedStruct = await resolveProperties(struct);\n const request = deepHexlify(resolvedStruct);\n if (!isValidRequest(request)) {\n throw new InvalidUserOperationError(resolvedStruct);\n }\n\n return {\n ...resolvedStruct,\n signature: await account.signUserOperationHash(\n account.getEntryPoint().getUserOperationHash(request),\n ),\n };\n};\n"]}
1
+ {"version":3,"file":"userOpSigner.js","sourceRoot":"","sources":["../../../../src/middleware/defaults/userOpSigner.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,yBAAyB,CAAC;AAC/D,OAAO,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CA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D,EAAE;IACF,IAAI,CAAC,OAAO,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,EAAE,CAAC;QACnD,MAAM,IAAI,oBAAoB,EAAE,CAAC;IACnC,CAAC;IAED,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IACnC,IAAI,CAAC,MAAM,CAAC,iBAAiB,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CACjB,0EAA0E,CAC3E,CAAC;IACJ,CAAC;IAED,MAAM,mBAAmB,GAAG,MAAM,MAAM,CAAC,iBAAiB,CAAC;QACzD,OAAO,EAAE,WAAW,CAAC,qBAAqB,CAAC,OAAO,CAAC;QACnD,eAAe,EAAE,qBAAqB,CAAC,OAAO;QAC9C,KAAK,EAAE,WAAW,CAAC,qBAAqB,CAAC,KAAK,CAAC;KAChD,CAAC,CAAC;IAEH,OAAO;QACL,OAAO,EAAE,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC;QAC3C,KAAK,EAAE,KAAK,CAAC,mBAAmB,CAAC,KAAK,CAAC;QACvC,OAAO,EAAE,mBAAmB,CAAC,OAAO;QACpC,CAAC,EAAE,mBAAmB,CAAC,CAAC;QACxB,CAAC,EAAE,mBAAmB,CAAC,CAAC;QACxB,OAAO,EAAE,KAAK,CAAC,mBAAmB,CAAC,OAAO,IAAI,mBAAmB,CAAC,CAAC,GAAG,GAAG,CAAC;KAC3E,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import { AccountNotFoundError } from \"../../errors/account.js\";\nimport { ChainNotFoundError } from \"../../errors/client.js\";\nimport { InvalidUserOperationError } from \"../../errors/useroperation.js\";\nimport {\n deepHexlify,\n isValidRequest,\n resolveProperties,\n} from \"../../utils/index.js\";\nimport type { ClientMiddlewareFn } from \"../types\";\nimport { type Authorization, type Hex, hexToNumber, toHex } from \"viem\";\nimport {\n isSmartAccountWithSigner,\n type SmartContractAccount,\n} from \"../../account/smartContractAccount.js\";\nimport { BaseError } from \"../../errors/base.js\";\n\n/**\n * Provides a default middleware function for signing user operations with a client account. This function validates the request and adds the signature to it.\n * This is already included in the client returned from `createSmartAccountClient`\n *\n * @param {UserOperationStruct} struct The user operation structure to be signed\n * @param {*} context The middleware context containing the client and account information\n * @param {Client} context.client The client object, which should include account and chain information\n * @param {Account} [context.account] Optional, the account used for signing, defaults to the client's account if not provided\n * @returns {Promise<UserOperationStruct>} A promise that resolves to the signed user operation structure\n */\nexport const defaultUserOpSigner: ClientMiddlewareFn = async (\n struct,\n { client, account = client.account },\n) => {\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!client?.chain) {\n throw new ChainNotFoundError();\n }\n\n const resolvedStruct = await resolveProperties(struct);\n const request = deepHexlify(resolvedStruct);\n if (!isValidRequest(request)) {\n throw new InvalidUserOperationError(resolvedStruct);\n }\n\n return {\n ...resolvedStruct,\n signature: await account.signUserOperationHash(\n account.getEntryPoint().getUserOperationHash(request),\n ),\n ...(resolvedStruct.eip7702Auth && {\n eip7702Auth: await signAuthorization(account, resolvedStruct.eip7702Auth),\n }),\n };\n};\n\nconst signAuthorization = async (\n account: SmartContractAccount,\n unsignedAuthorization: Authorization<Hex, false>,\n) => {\n if (!account || !isSmartAccountWithSigner(account)) {\n throw new AccountNotFoundError();\n }\n\n const signer = account.getSigner();\n if (!signer.signAuthorization) {\n throw new BaseError(\n \"Signer must implement signAuthorization to sign EIP-7702 authorizations.\",\n );\n }\n\n const signedAuthorization = await signer.signAuthorization({\n chainId: hexToNumber(unsignedAuthorization.chainId),\n contractAddress: unsignedAuthorization.address,\n nonce: hexToNumber(unsignedAuthorization.nonce),\n });\n\n return {\n chainId: toHex(signedAuthorization.chainId),\n nonce: toHex(signedAuthorization.nonce),\n address: signedAuthorization.address,\n r: signedAuthorization.r,\n s: signedAuthorization.s,\n yParity: toHex(signedAuthorization.yParity ?? signedAuthorization.v - 27n),\n };\n};\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "4.66.3";
1
+ export declare const VERSION = "4.67.0";
@@ -1,4 +1,4 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.66.3";
3
+ export const VERSION = "4.67.0";
4
4
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.66.3\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"4.67.0\";\n"]}
@@ -1,5 +1,5 @@
1
- import type { Chain, Transport } from "viem";
2
- import type { GetEntryPointFromAccount, SmartContractAccount } from "../../../account/smartContractAccount.js";
1
+ import { type Chain, type Transport } from "viem";
2
+ import { type GetEntryPointFromAccount, type SmartContractAccount } from "../../../account/smartContractAccount.js";
3
3
  import type { BaseSmartAccountClient } from "../../../client/smartAccountClient.js";
4
4
  import type { UserOperationStruct } from "../../../types.js";
5
5
  import { type Deferrable } from "../../../utils/index.js";
@@ -1 +1 @@
1
- {"version":3,"file":"initUserOperation.d.ts","sourceRoot":"","sources":["../../../../../src/actions/smartAccount/internal/initUserOperation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,MAAM,CAAC;AAC7C,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,MAAM,0CAA0C,CAAC;AAClD,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAGpF,OAAO,KAAK,EAAE,mBAAmB,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M,yBAAyB,CAAC;AAC7E,OAAO,KAAK,EACV,4BAA4B,EAC5B,2BAA2B,EAC3B,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB;;;;;;;;;;;;GAYG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,MAAM,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,EACpD,QAAQ,SAAS,oBAAoB,GAAG,SAAS,GAC7C,oBAAoB,GACpB,SAAS,EACb,QAAQ,SAAS,oBAAoB,GAAG,SAAS,GAC7C,oBAAoB,GACpB,SAAS,EACb,kBAAkB,SAChB,wBAAwB,CAAC,QAAQ,CAAC,GAAG,wBAAwB,CAAC,QAAQ,CAAC,EAEzE,MAAM,EAAE,sBAAsB,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,EAC5D,IAAI,EACA,2BAA2B,CAAC,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,CAAC,GACnE,4BAA4B,CAAC,QAAQ,EAAE,QAAQ,EAAE,kBAAkB,CAAC,GACvE,OAAO,CAAC,UAAU,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAiF9D"}
@@ -3,32 +3,7 @@ import type { ClientMiddlewareFn } from "../types";
3
3
  * A middleware function to estimate the gas usage of a user operation when using an EIP-7702 delegated account. Has an optional custom gas estimator.
4
4
  * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.
5
5
  *
6
- * @example
7
- * ```ts twoslash
8
- * import {
9
- * default7702GasEstimator,
10
- * default7702UserOpSigner,
11
- * createSmartAccountClient,
12
- * type SmartAccountClient,
13
- * } from "@aa-sdk/core";
14
- * import {
15
- * createModularAccountV2,
16
- * type CreateModularAccountV2ClientParams,
17
- * } from "@account-kit/smart-contracts";
18
- *
19
- * async function createSMA7702AccountClient(
20
- * config: CreateModularAccountV2ClientParams
21
- * ): Promise<SmartAccountClient> {
22
- * const sma7702Account = await createModularAccountV2({ ...config, mode: "7702" });
23
- *
24
- * return createSmartAccountClient({
25
- * account: sma7702Account,
26
- * gasEstimator: default7702GasEstimator(config.gasEstimator),
27
- * signUserOperation: default7702UserOpSigner(config.signUserOperation),
28
- * ...config,
29
- * });
30
- * }
31
- * ```
6
+ * @deprecated The EIP-7702 auth is now set in initUserOperation instead. This middleware is no longer necessary.
32
7
  *
33
8
  * @param {ClientMiddlewareFn} gasEstimator Optional custom gas estimator function
34
9
  * @returns {ClientMiddlewareFn} A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.
@@ -1 +1 @@
1
- {"version":3,"file":"7702gasEstimator.d.ts","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702gasEstimator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,eAAO,MAAM,uBAAuB,EAAE,CACpC,YAAY,CAAC,EAAE,kBAAkB,KAC9B,kBAwCF,CAAC"}
1
+ {"version":3,"file":"7702gasEstimator.d.ts","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702gasEstimator.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD;;;;;;;;GAQG;AACH,eAAO,MAAM,uBAAuB,EAAE,CACpC,YAAY,CAAC,EAAE,kBAAkB,KAC9B,kBAwCF,CAAC"}
@@ -4,32 +4,7 @@ import type { ClientMiddlewareFn } from "../types";
4
4
  * If the signer doesn't support `signAuthorization`, then this just runs the provided `signUserOperation` middleware.
5
5
  * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.
6
6
  *
7
- * @example
8
- * ```ts twoslash
9
- * import {
10
- * default7702GasEstimator,
11
- * default7702UserOpSigner,
12
- * createSmartAccountClient,
13
- * type SmartAccountClient,
14
- * } from "@aa-sdk/core";
15
- * import {
16
- * createModularAccountV2,
17
- * type CreateModularAccountV2ClientParams,
18
- * } from "@account-kit/smart-contracts";
19
- *
20
- * async function createSMA7702AccountClient(
21
- * config: CreateModularAccountV2ClientParams
22
- * ): Promise<SmartAccountClient> {
23
- * const sma7702Account = await createModularAccountV2({ ...config, mode: "7702" });
24
- *
25
- * return createSmartAccountClient({
26
- * account: sma7702Account,
27
- * gasEstimator: default7702GasEstimator(config.gasEstimator),
28
- * signUserOperation: default7702UserOpSigner(config.signUserOperation),
29
- * ...config,
30
- * });
31
- * }
32
- * ```
7
+ * @deprecated The EIP-7702 auth signature is now handled by the defaultUserOpSigner middleware. This middleware is no longer necessary.
33
8
  *
34
9
  * @param {ClientMiddlewareFn} [userOpSigner] Optional user operation signer function
35
10
  * @returns {ClientMiddlewareFn} A middleware function that signs EIP-7702 authorization tuples if necessary, and also uses the provided or default user operation signer to generate the user op signature.
@@ -1 +1 @@
1
- {"version":3,"file":"7702signer.d.ts","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702signer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,uBAAuB,EAAE,CACpC,YAAY,CAAC,EAAE,kBAAkB,KAC9B,kBAmEF,CAAC"}
1
+ {"version":3,"file":"7702signer.d.ts","sourceRoot":"","sources":["../../../../src/middleware/defaults/7702signer.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAGnD;;;;;;;;;GASG;AACH,eAAO,MAAM,uBAAuB,EAAE,CACpC,YAAY,CAAC,EAAE,kBAAkB,KAC9B,kBAmEF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"userOpSigner.d.ts","sourceRoot":"","sources":["../../../../src/middleware/defaults/userOpSigner.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAEnD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBAwBjC,CAAC"}
1
+ {"version":3,"file":"userOpSigner.d.ts","sourceRoot":"","sources":["../../../../src/middleware/defaults/userOpSigner.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAQnD;;;;;;;;;GASG;AACH,eAAO,MAAM,mBAAmB,EAAE,kBA2BjC,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "4.66.3";
1
+ export declare const VERSION = "4.67.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@aa-sdk/core",
3
3
  "license": "MIT",
4
- "version": "4.66.3",
4
+ "version": "4.67.0",
5
5
  "description": "viem based SDK that enables interactions with ERC-4337 Smart Accounts. ABIs are based off the definitions generated in @account-abstraction/contracts",
6
6
  "author": "Alchemy",
7
7
  "type": "module",
@@ -61,5 +61,5 @@
61
61
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
62
62
  },
63
63
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
64
- "gitHead": "33b7e38e6f83cc7a5bae3976b6c8a54b15f6cd4e"
64
+ "gitHead": "6b6896197bab0752b677f659443c900c71e45afd"
65
65
  }
@@ -1,7 +1,8 @@
1
- import type { Chain, Transport } from "viem";
2
- import type {
3
- GetEntryPointFromAccount,
4
- SmartContractAccount,
1
+ import { type Chain, type Transport, concatHex, toHex, zeroHash } from "viem";
2
+ import {
3
+ isSmartAccountWithSigner,
4
+ type GetEntryPointFromAccount,
5
+ type SmartContractAccount,
5
6
  } from "../../../account/smartContractAccount.js";
6
7
  import type { BaseSmartAccountClient } from "../../../client/smartAccountClient.js";
7
8
  import { AccountNotFoundError } from "../../../errors/account.js";
@@ -90,5 +91,38 @@ export async function _initUserOperation<
90
91
  signature,
91
92
  } as Deferrable<UserOperationStruct<TEntryPointVersion>>);
92
93
 
94
+ const is7702 =
95
+ account.source === "ModularAccountV2" &&
96
+ isSmartAccountWithSigner(account) &&
97
+ (await account.getSigner().getAddress()).toLowerCase() ===
98
+ account.address.toLowerCase();
99
+
100
+ if (is7702) {
101
+ if (entryPoint.version !== "0.7.0") {
102
+ throw new Error("7702 is only compatible with EntryPoint v0.7.0");
103
+ }
104
+
105
+ const [implementationAddress, code = "0x", nonce] = await Promise.all([
106
+ account.getImplementationAddress(),
107
+ client.getCode({ address: account.address }),
108
+ client.getTransactionCount({ address: account.address }),
109
+ ]);
110
+
111
+ const isAlreadyDelegated =
112
+ code.toLowerCase() ===
113
+ concatHex(["0xef0100", implementationAddress]).toLowerCase();
114
+
115
+ if (!isAlreadyDelegated) {
116
+ (struct as UserOperationStruct<"0.7.0">).eip7702Auth = {
117
+ chainId: toHex(client.chain.id),
118
+ nonce: toHex(nonce),
119
+ address: implementationAddress,
120
+ r: zeroHash, // aka `bytes32(0)`
121
+ s: zeroHash,
122
+ yParity: "0x0",
123
+ };
124
+ }
125
+ }
126
+
93
127
  return struct;
94
128
  }
@@ -8,32 +8,7 @@ import { defaultGasEstimator } from "./gasEstimator.js";
8
8
  * A middleware function to estimate the gas usage of a user operation when using an EIP-7702 delegated account. Has an optional custom gas estimator.
9
9
  * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.
10
10
  *
11
- * @example
12
- * ```ts twoslash
13
- * import {
14
- * default7702GasEstimator,
15
- * default7702UserOpSigner,
16
- * createSmartAccountClient,
17
- * type SmartAccountClient,
18
- * } from "@aa-sdk/core";
19
- * import {
20
- * createModularAccountV2,
21
- * type CreateModularAccountV2ClientParams,
22
- * } from "@account-kit/smart-contracts";
23
- *
24
- * async function createSMA7702AccountClient(
25
- * config: CreateModularAccountV2ClientParams
26
- * ): Promise<SmartAccountClient> {
27
- * const sma7702Account = await createModularAccountV2({ ...config, mode: "7702" });
28
- *
29
- * return createSmartAccountClient({
30
- * account: sma7702Account,
31
- * gasEstimator: default7702GasEstimator(config.gasEstimator),
32
- * signUserOperation: default7702UserOpSigner(config.signUserOperation),
33
- * ...config,
34
- * });
35
- * }
36
- * ```
11
+ * @deprecated The EIP-7702 auth is now set in initUserOperation instead. This middleware is no longer necessary.
37
12
  *
38
13
  * @param {ClientMiddlewareFn} gasEstimator Optional custom gas estimator function
39
14
  * @returns {ClientMiddlewareFn} A function that takes user operation struct and parameters, estimates gas usage, and returns the user operation with gas limits.
@@ -10,32 +10,7 @@ import { defaultUserOpSigner } from "./userOpSigner.js";
10
10
  * If the signer doesn't support `signAuthorization`, then this just runs the provided `signUserOperation` middleware.
11
11
  * This function is only compatible with accounts using EntryPoint v0.7.0, and the account must have an implementation address defined in `getImplementationAddress()`.
12
12
  *
13
- * @example
14
- * ```ts twoslash
15
- * import {
16
- * default7702GasEstimator,
17
- * default7702UserOpSigner,
18
- * createSmartAccountClient,
19
- * type SmartAccountClient,
20
- * } from "@aa-sdk/core";
21
- * import {
22
- * createModularAccountV2,
23
- * type CreateModularAccountV2ClientParams,
24
- * } from "@account-kit/smart-contracts";
25
- *
26
- * async function createSMA7702AccountClient(
27
- * config: CreateModularAccountV2ClientParams
28
- * ): Promise<SmartAccountClient> {
29
- * const sma7702Account = await createModularAccountV2({ ...config, mode: "7702" });
30
- *
31
- * return createSmartAccountClient({
32
- * account: sma7702Account,
33
- * gasEstimator: default7702GasEstimator(config.gasEstimator),
34
- * signUserOperation: default7702UserOpSigner(config.signUserOperation),
35
- * ...config,
36
- * });
37
- * }
38
- * ```
13
+ * @deprecated The EIP-7702 auth signature is now handled by the defaultUserOpSigner middleware. This middleware is no longer necessary.
39
14
  *
40
15
  * @param {ClientMiddlewareFn} [userOpSigner] Optional user operation signer function
41
16
  * @returns {ClientMiddlewareFn} A middleware function that signs EIP-7702 authorization tuples if necessary, and also uses the provided or default user operation signer to generate the user op signature.
@@ -7,6 +7,12 @@ import {
7
7
  resolveProperties,
8
8
  } from "../../utils/index.js";
9
9
  import type { ClientMiddlewareFn } from "../types";
10
+ import { type Authorization, type Hex, hexToNumber, toHex } from "viem";
11
+ import {
12
+ isSmartAccountWithSigner,
13
+ type SmartContractAccount,
14
+ } from "../../account/smartContractAccount.js";
15
+ import { BaseError } from "../../errors/base.js";
10
16
 
11
17
  /**
12
18
  * Provides a default middleware function for signing user operations with a client account. This function validates the request and adds the signature to it.
@@ -41,5 +47,39 @@ export const defaultUserOpSigner: ClientMiddlewareFn = async (
41
47
  signature: await account.signUserOperationHash(
42
48
  account.getEntryPoint().getUserOperationHash(request),
43
49
  ),
50
+ ...(resolvedStruct.eip7702Auth && {
51
+ eip7702Auth: await signAuthorization(account, resolvedStruct.eip7702Auth),
52
+ }),
53
+ };
54
+ };
55
+
56
+ const signAuthorization = async (
57
+ account: SmartContractAccount,
58
+ unsignedAuthorization: Authorization<Hex, false>,
59
+ ) => {
60
+ if (!account || !isSmartAccountWithSigner(account)) {
61
+ throw new AccountNotFoundError();
62
+ }
63
+
64
+ const signer = account.getSigner();
65
+ if (!signer.signAuthorization) {
66
+ throw new BaseError(
67
+ "Signer must implement signAuthorization to sign EIP-7702 authorizations.",
68
+ );
69
+ }
70
+
71
+ const signedAuthorization = await signer.signAuthorization({
72
+ chainId: hexToNumber(unsignedAuthorization.chainId),
73
+ contractAddress: unsignedAuthorization.address,
74
+ nonce: hexToNumber(unsignedAuthorization.nonce),
75
+ });
76
+
77
+ return {
78
+ chainId: toHex(signedAuthorization.chainId),
79
+ nonce: toHex(signedAuthorization.nonce),
80
+ address: signedAuthorization.address,
81
+ r: signedAuthorization.r,
82
+ s: signedAuthorization.s,
83
+ yParity: toHex(signedAuthorization.yParity ?? signedAuthorization.v - 27n),
44
84
  };
45
85
  };
package/src/version.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  // This file is autogenerated by inject-version.ts. Any changes will be
2
2
  // overwritten on commit!
3
- export const VERSION = "4.66.3";
3
+ export const VERSION = "4.67.0";