@alchemy/smart-accounts 5.0.0-beta.22 → 5.0.0-beta.24

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 (37) hide show
  1. package/README.md +2 -0
  2. package/dist/esm/index.d.ts +1 -1
  3. package/dist/esm/index.js +1 -1
  4. package/dist/esm/index.js.map +1 -1
  5. package/dist/esm/ma-v2/accounts/account.d.ts +39 -0
  6. package/dist/esm/ma-v2/accounts/account.js +39 -0
  7. package/dist/esm/ma-v2/accounts/account.js.map +1 -1
  8. package/dist/esm/ma-v2/decorators/deferralActions.d.ts +3 -3
  9. package/dist/esm/ma-v2/decorators/deferralActions.js +3 -3
  10. package/dist/esm/ma-v2/decorators/deferralActions.js.map +1 -1
  11. package/dist/esm/ma-v2/permissionBuilder.d.ts +2 -2
  12. package/dist/esm/ma-v2/permissionBuilder.js +21 -7
  13. package/dist/esm/ma-v2/permissionBuilder.js.map +1 -1
  14. package/dist/esm/ma-v2/utils/deferredActions.d.ts +6 -6
  15. package/dist/esm/ma-v2/utils/deferredActions.js +5 -5
  16. package/dist/esm/ma-v2/utils/deferredActions.js.map +1 -1
  17. package/dist/esm/version.d.ts +1 -1
  18. package/dist/esm/version.js +1 -1
  19. package/dist/esm/version.js.map +1 -1
  20. package/dist/types/index.d.ts +1 -1
  21. package/dist/types/index.d.ts.map +1 -1
  22. package/dist/types/ma-v2/accounts/account.d.ts +39 -0
  23. package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
  24. package/dist/types/ma-v2/decorators/deferralActions.d.ts +3 -3
  25. package/dist/types/ma-v2/decorators/deferralActions.d.ts.map +1 -1
  26. package/dist/types/ma-v2/permissionBuilder.d.ts +2 -2
  27. package/dist/types/ma-v2/permissionBuilder.d.ts.map +1 -1
  28. package/dist/types/ma-v2/utils/deferredActions.d.ts +6 -6
  29. package/dist/types/ma-v2/utils/deferredActions.d.ts.map +1 -1
  30. package/dist/types/version.d.ts +1 -1
  31. package/package.json +4 -4
  32. package/src/index.ts +1 -1
  33. package/src/ma-v2/accounts/account.ts +39 -0
  34. package/src/ma-v2/decorators/deferralActions.ts +7 -7
  35. package/src/ma-v2/permissionBuilder.ts +27 -9
  36. package/src/ma-v2/utils/deferredActions.ts +9 -9
  37. package/src/version.ts +1 -1
package/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # @alchemy/smart-accounts
2
2
 
3
+ **Beta** — This package replaces `@account-kit/smart-contracts`. This is a low-level package. Most users should use [`@alchemy/wallet-apis`](https://www.alchemy.com/docs/wallets/reference/wallet-apis) unless you need to use interface with Smart Accounts directly via viem.
4
+
3
5
  Viem-compatible smart account implementations for Alchemy's smart contract accounts. Supports LightAccount, Modular Account v1, and Modular Account v2 with EIP-7702.
4
6
 
5
7
  ## Installation
@@ -43,7 +43,7 @@ export type * from "./ma-v2/types.js";
43
43
  export type * from "./ma-v2/utils/account.js";
44
44
  export { DefaultAddress, DefaultModuleAddress, DEFAULT_OWNER_ENTITY_ID, EXECUTE_USER_OP_SELECTOR, getMAV2UpgradeToData, buildFullNonceKey, serializeModuleEntity, isModularAccountV2, } from "./ma-v2/utils/account.js";
45
45
  export type * from "./ma-v2/utils/deferredActions.js";
46
- export { parseDeferredAction, buildDeferredActionDigest, } from "./ma-v2/utils/deferredActions.js";
46
+ export { parseDeferredAction, encodeDeferredActionWithSignature, } from "./ma-v2/utils/deferredActions.js";
47
47
  export type * from "./ma-v2/utils/hooks.js";
48
48
  export { serializeValidationConfig, serializeHookConfig, } from "./ma-v2/utils/hooks.js";
49
49
  export type * from "./ma-v2/utils/signature.js";
package/dist/esm/index.js CHANGED
@@ -26,7 +26,7 @@ export { TimeRangeModule } from "./ma-v2/modules/time-range-module/module.js";
26
26
  export { PermissionBuilder, PermissionType, } from "./ma-v2/permissionBuilder.js";
27
27
  export { predictModularAccountV2Address } from "./ma-v2/predictAddress.js";
28
28
  export { DefaultAddress, DefaultModuleAddress, DEFAULT_OWNER_ENTITY_ID, EXECUTE_USER_OP_SELECTOR, getMAV2UpgradeToData, buildFullNonceKey, serializeModuleEntity, isModularAccountV2, } from "./ma-v2/utils/account.js";
29
- export { parseDeferredAction, buildDeferredActionDigest, } from "./ma-v2/utils/deferredActions.js";
29
+ export { parseDeferredAction, encodeDeferredActionWithSignature, } from "./ma-v2/utils/deferredActions.js";
30
30
  export { serializeValidationConfig, serializeHookConfig, } from "./ma-v2/utils/hooks.js";
31
31
  export { packUOSignature, pack1271Signature, toReplaySafeTypedData, } from "./ma-v2/utils/signature.js";
32
32
  // Errors
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAGrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAG3F,OAAO,EACL,0BAA0B,EAC1B,oCAAoC,GACrC,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAErE,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,oCAAoC,EACpC,gCAAgC,GACjC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EACb,aAAa,GACd,MAAM,2CAA2C,CAAC;AAEnD,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,2CAA2C,CAAC;AAInD,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAGlE,OAAO,EAAE,4BAA4B,EAAE,MAAM,yCAAyC,CAAC;AAGvF,OAAO,EAAE,wCAAwC,EAAE,MAAM,2BAA2B,CAAC;AAErF,OAAO,EAAE,kCAAkC,EAAE,MAAM,2BAA2B,CAAC;AAE/E,OAAO,EACL,kBAAkB,EAClB,wBAAwB,GACzB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,eAAe,EACf,eAAe,G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AA6C,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,gCAAgC,EAChC,gBAAgB,EAChB,qBAAqB,EACrB,8BAA8B,EAC9B,kBAAkB,GACnB,MAAM,qCAAqC,CAAC","sourcesContent":["export type * from \"./types.js\";\n\n// LightAccount\nexport type * from \"./light-account/accounts/account.js\";\nexport { toLightAccount } from \"./light-account/accounts/account.js\";\n\nexport type * from \"./light-account/accounts/multi-owner-account.js\";\nexport { toMultiOwnerLightAccount } from \"./light-account/accounts/multi-owner-account.js\";\n\nexport type * from \"./light-account/predictAddress.js\";\nexport {\n predictLightAccountAddress,\n predictMultiOwnerLightAccountAddress,\n} from \"./light-account/predictAddress.js\";\n\nexport { AccountVersionRegistry } from \"./light-account/registry.js\";\nexport type * from \"./light-account/registry.js\";\nexport {\n defaultLightAccountVersion,\n getLightAccountImplAddress,\n LightAccountUnsupported1271Factories,\n LightAccountUnsupported1271Impls,\n} from \"./light-account/utils.js\";\n\nexport {\n encodeCallsLA,\n decodeCallsLA,\n} from \"./light-account/accounts/calldataCodec.js\";\n\nexport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./light-account/lightAccountStaticImpl.js\";\n\n// ModularAccountV1\nexport type * from \"./ma-v1/accounts/base.js\";\nexport { toModularAccountV1Base } from \"./ma-v1/accounts/base.js\";\n\nexport type * from \"./ma-v1/accounts/multi-owner-account.js\";\nexport { toMultiOwnerModularAccountV1 } from \"./ma-v1/accounts/multi-owner-account.js\";\n\nexport type * from \"./ma-v1/predictAddress.js\";\nexport { predictMultiOwnerModularAccountV1Address } from \"./ma-v1/predictAddress.js\";\n\nexport { multiOwnerModularAccountStaticImpl } from \"./ma-v1/mav1StaticImpl.js\";\n\nexport {\n DefaultMaV1Address,\n DefaultMaV1PluginAddress,\n} from \"./ma-v1/account.js\";\n\nexport {\n encodeCallsMAv1,\n decodeCallsMAv1,\n} from \"./ma-v1/accounts/calldataCodec.js\";\n\n// ModularAccountV2\nexport type * from \"./ma-v2/accounts/account.js\";\nexport { toModularAccountV2 } from \"./ma-v2/accounts/account.js\";\n\nexport type * from \"./ma-v2/accounts/base.js\";\nexport { toModularAccountV2Base } from \"./ma-v2/accounts/base.js\";\n\nexport {\n encodeCallsMAv2,\n decodeCallsMAv2,\n} from \"./ma-v2/accounts/calldataCodec.js\";\n\nexport type * from \"./ma-v2/decorators/deferralActions.js\";\nexport { deferralActions } from \"./ma-v2/decorators/deferralActions.js\";\n\nexport type * from \"./ma-v2/decorators/installValidation.js\";\nexport { installValidationActions } from \"./ma-v2/decorators/installValidation.js\";\n\nexport {\n semiModularAccountV2StaticImpl,\n semiModularAccount7702StaticImpl,\n} from \"./ma-v2/mav2StaticImpl.js\";\nexport type * from \"./ma-v2/mav2StaticImpl.js\";\n\n// Modules\nexport { AllowlistModule } from \"./ma-v2/modules/allowlist-module/module.js\";\nexport { NativeTokenLimitModule } from \"./ma-v2/modules/native-token-limit-module/module.js\";\nexport { PaymasterGuardModule } from \"./ma-v2/modules/paymaster-guard-module/module.js\";\nexport { SingleSignerValidationModule } from \"./ma-v2/modules/single-signer-validation/module.js\";\nexport { TimeRangeModule } from \"./ma-v2/modules/time-range-module/module.js\";\n\nexport type * from \"./ma-v2/permissionBuilder.js\";\nexport {\n PermissionBuilder,\n PermissionType,\n} from \"./ma-v2/permissionBuilder.js\";\n\nexport type * from \"./ma-v2/predictAddress.js\";\nexport { predictModularAccountV2Address } from \"./ma-v2/predictAddress.js\";\n\nexport type * from \"./ma-v2/types.js\";\n\nexport type * from \"./ma-v2/utils/account.js\";\nexport {\n DefaultAddress,\n DefaultModuleAddress,\n DEFAULT_OWNER_ENTITY_ID,\n EXECUTE_USER_OP_SELECTOR,\n getMAV2UpgradeToData,\n buildFullNonceKey,\n serializeModuleEntity,\n isModularAccountV2,\n} from \"./ma-v2/utils/account.js\";\n\nexport type * from \"./ma-v2/utils/deferredActions.js\";\nexport {\n parseDeferredAction,\n buildDeferredActionDigest,\n} from \"./ma-v2/utils/deferredActions.js\";\n\nexport type * from \"./ma-v2/utils/hooks.js\";\nexport {\n serializeValidationConfig,\n serializeHookConfig,\n} from \"./ma-v2/utils/hooks.js\";\n\nexport type * from \"./ma-v2/utils/signature.js\";\nexport {\n packUOSignature,\n pack1271Signature,\n toReplaySafeTypedData,\n} from \"./ma-v2/utils/signature.js\";\n\n// Errors\nexport { EntityIdOverrideError } from \"./errors/EntityIdOverrideError.js\";\nexport { InvalidDeferredActionNonceError } from \"./errors/InvalidDeferredActionNonceError.js\";\nexport { InvalidEntityIdError } from \"./errors/InvalidEntityIdError.js\";\nexport { InvalidNonceKeyError } from \"./errors/InvalidNonceKeyError.js\";\nexport { InvalidOwnerError } from \"./errors/InvalidOwnerError.js\";\nexport {\n PermissionBuilderError,\n RootPermissionOnlyError,\n AccountAddressAsTargetError,\n DuplicateTargetAddressError,\n NoFunctionsProvidedError,\n ExpiredDeadlineError,\n DeadlineOverLimitError,\n ValidationConfigUnsetError,\n MultipleNativeTokenTransferError,\n ZeroAddressError,\n MultipleGasLimitError,\n UnsupportedPermissionTypeError,\n SelectorNotAllowed,\n} from \"./errors/permissionBuilderErrors.js\";\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAGrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAG3F,OA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kD,CAAC;AACxF,OAAO,EAAE,4BAA4B,EAAE,MAAM,oDAAoD,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,6CAA6C,CAAC;AAG9E,OAAO,EACL,iBAAiB,EACjB,cAAc,GACf,MAAM,8BAA8B,CAAC;AAGtC,OAAO,EAAE,8BAA8B,EAAE,MAAM,2BAA2B,CAAC;AAK3E,OAAO,EACL,cAAc,EACd,oBAAoB,EACpB,uBAAuB,EACvB,wBAAwB,EACxB,oBAAoB,EACpB,iBAAiB,EACjB,qBAAqB,EACrB,kBAAkB,GACnB,MAAM,0BAA0B,CAAC;AAGlC,OAAO,EACL,mBAAmB,EACnB,iCAAiC,GAClC,MAAM,kCAAkC,CAAC;AAG1C,OAAO,EACL,yBAAyB,EACzB,mBAAmB,GACpB,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,SAAS;AACT,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,gCAAgC,EAChC,gBAAgB,EAChB,qBAAqB,EACrB,8BAA8B,EAC9B,kBAAkB,GACnB,MAAM,qCAAqC,CAAC","sourcesContent":["export type * from \"./types.js\";\n\n// LightAccount\nexport type * from \"./light-account/accounts/account.js\";\nexport { toLightAccount } from \"./light-account/accounts/account.js\";\n\nexport type * from \"./light-account/accounts/multi-owner-account.js\";\nexport { toMultiOwnerLightAccount } from \"./light-account/accounts/multi-owner-account.js\";\n\nexport type * from \"./light-account/predictAddress.js\";\nexport {\n predictLightAccountAddress,\n predictMultiOwnerLightAccountAddress,\n} from \"./light-account/predictAddress.js\";\n\nexport { AccountVersionRegistry } from \"./light-account/registry.js\";\nexport type * from \"./light-account/registry.js\";\nexport {\n defaultLightAccountVersion,\n getLightAccountImplAddress,\n LightAccountUnsupported1271Factories,\n LightAccountUnsupported1271Impls,\n} from \"./light-account/utils.js\";\n\nexport {\n encodeCallsLA,\n decodeCallsLA,\n} from \"./light-account/accounts/calldataCodec.js\";\n\nexport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./light-account/lightAccountStaticImpl.js\";\n\n// ModularAccountV1\nexport type * from \"./ma-v1/accounts/base.js\";\nexport { toModularAccountV1Base } from \"./ma-v1/accounts/base.js\";\n\nexport type * from \"./ma-v1/accounts/multi-owner-account.js\";\nexport { toMultiOwnerModularAccountV1 } from \"./ma-v1/accounts/multi-owner-account.js\";\n\nexport type * from \"./ma-v1/predictAddress.js\";\nexport { predictMultiOwnerModularAccountV1Address } from \"./ma-v1/predictAddress.js\";\n\nexport { multiOwnerModularAccountStaticImpl } from \"./ma-v1/mav1StaticImpl.js\";\n\nexport {\n DefaultMaV1Address,\n DefaultMaV1PluginAddress,\n} from \"./ma-v1/account.js\";\n\nexport {\n encodeCallsMAv1,\n decodeCallsMAv1,\n} from \"./ma-v1/accounts/calldataCodec.js\";\n\n// ModularAccountV2\nexport type * from \"./ma-v2/accounts/account.js\";\nexport { toModularAccountV2 } from \"./ma-v2/accounts/account.js\";\n\nexport type * from \"./ma-v2/accounts/base.js\";\nexport { toModularAccountV2Base } from \"./ma-v2/accounts/base.js\";\n\nexport {\n encodeCallsMAv2,\n decodeCallsMAv2,\n} from \"./ma-v2/accounts/calldataCodec.js\";\n\nexport type * from \"./ma-v2/decorators/deferralActions.js\";\nexport { deferralActions } from \"./ma-v2/decorators/deferralActions.js\";\n\nexport type * from \"./ma-v2/decorators/installValidation.js\";\nexport { installValidationActions } from \"./ma-v2/decorators/installValidation.js\";\n\nexport {\n semiModularAccountV2StaticImpl,\n semiModularAccount7702StaticImpl,\n} from \"./ma-v2/mav2StaticImpl.js\";\nexport type * from \"./ma-v2/mav2StaticImpl.js\";\n\n// Modules\nexport { AllowlistModule } from \"./ma-v2/modules/allowlist-module/module.js\";\nexport { NativeTokenLimitModule } from \"./ma-v2/modules/native-token-limit-module/module.js\";\nexport { PaymasterGuardModule } from \"./ma-v2/modules/paymaster-guard-module/module.js\";\nexport { SingleSignerValidationModule } from \"./ma-v2/modules/single-signer-validation/module.js\";\nexport { TimeRangeModule } from \"./ma-v2/modules/time-range-module/module.js\";\n\nexport type * from \"./ma-v2/permissionBuilder.js\";\nexport {\n PermissionBuilder,\n PermissionType,\n} from \"./ma-v2/permissionBuilder.js\";\n\nexport type * from \"./ma-v2/predictAddress.js\";\nexport { predictModularAccountV2Address } from \"./ma-v2/predictAddress.js\";\n\nexport type * from \"./ma-v2/types.js\";\n\nexport type * from \"./ma-v2/utils/account.js\";\nexport {\n DefaultAddress,\n DefaultModuleAddress,\n DEFAULT_OWNER_ENTITY_ID,\n EXECUTE_USER_OP_SELECTOR,\n getMAV2UpgradeToData,\n buildFullNonceKey,\n serializeModuleEntity,\n isModularAccountV2,\n} from \"./ma-v2/utils/account.js\";\n\nexport type * from \"./ma-v2/utils/deferredActions.js\";\nexport {\n parseDeferredAction,\n encodeDeferredActionWithSignature,\n} from \"./ma-v2/utils/deferredActions.js\";\n\nexport type * from \"./ma-v2/utils/hooks.js\";\nexport {\n serializeValidationConfig,\n serializeHookConfig,\n} from \"./ma-v2/utils/hooks.js\";\n\nexport type * from \"./ma-v2/utils/signature.js\";\nexport {\n packUOSignature,\n pack1271Signature,\n toReplaySafeTypedData,\n} from \"./ma-v2/utils/signature.js\";\n\n// Errors\nexport { EntityIdOverrideError } from \"./errors/EntityIdOverrideError.js\";\nexport { InvalidDeferredActionNonceError } from \"./errors/InvalidDeferredActionNonceError.js\";\nexport { InvalidEntityIdError } from \"./errors/InvalidEntityIdError.js\";\nexport { InvalidNonceKeyError } from \"./errors/InvalidNonceKeyError.js\";\nexport { InvalidOwnerError } from \"./errors/InvalidOwnerError.js\";\nexport {\n PermissionBuilderError,\n RootPermissionOnlyError,\n AccountAddressAsTargetError,\n DuplicateTargetAddressError,\n NoFunctionsProvidedError,\n ExpiredDeadlineError,\n DeadlineOverLimitError,\n ValidationConfigUnsetError,\n MultipleNativeTokenTransferError,\n ZeroAddressError,\n MultipleGasLimitError,\n UnsupportedPermissionTypeError,\n SelectorNotAllowed,\n} from \"./errors/permissionBuilderErrors.js\";\n"]}
@@ -30,6 +30,45 @@ export type ToModularAccountV2Params<TMode extends Mode | undefined = Mode | und
30
30
  *
31
31
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
32
32
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { createPublicClient } from "viem";
37
+ * import { createBundlerClient, createPaymasterClient } from "viem/account-abstraction";
38
+ * import { sepolia } from "viem/chains";
39
+ * import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
40
+ * import { alchemyTransport } from "@alchemy/common";
41
+ * import { estimateFeesPerGas } from "@alchemy/aa-infra";
42
+ * import { toModularAccountV2 } from "@alchemy/smart-accounts";
43
+ *
44
+ * const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });
45
+ *
46
+ * // 1. Create a MAv2 smart account
47
+ * const account = await toModularAccountV2({
48
+ * client: createPublicClient({ chain: sepolia, transport }),
49
+ * owner: privateKeyToAccount(generatePrivateKey()),
50
+ * });
51
+ *
52
+ * // 2. Create a bundler client with the account
53
+ * const bundlerClient = createBundlerClient({
54
+ * account,
55
+ * chain: sepolia,
56
+ * transport,
57
+ * userOperation: {
58
+ * estimateFeesPerGas,
59
+ * },
60
+ * // Optional: sponsor gas with a paymaster
61
+ * paymaster: createPaymasterClient({ transport }),
62
+ * paymasterContext: { policyId: "YOUR_POLICY_ID" },
63
+ * });
64
+ *
65
+ * // 3. Send a user operation
66
+ * const hash = await bundlerClient.sendUserOperation({
67
+ * calls: [{ to: "0x...", value: 0n, data: "0x" }],
68
+ * });
69
+ *
70
+ * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
71
+ * ```
33
72
  */
34
73
  export declare function toModularAccountV2<TMode extends Mode = Mode>({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt, factory, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2>;
35
74
  export {};
@@ -12,6 +12,45 @@ import { LOGGER } from "../../logger.js";
12
12
  *
13
13
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
14
14
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
15
+ *
16
+ * @example
17
+ * ```ts
18
+ * import { createPublicClient } from "viem";
19
+ * import { createBundlerClient, createPaymasterClient } from "viem/account-abstraction";
20
+ * import { sepolia } from "viem/chains";
21
+ * import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
22
+ * import { alchemyTransport } from "@alchemy/common";
23
+ * import { estimateFeesPerGas } from "@alchemy/aa-infra";
24
+ * import { toModularAccountV2 } from "@alchemy/smart-accounts";
25
+ *
26
+ * const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });
27
+ *
28
+ * // 1. Create a MAv2 smart account
29
+ * const account = await toModularAccountV2({
30
+ * client: createPublicClient({ chain: sepolia, transport }),
31
+ * owner: privateKeyToAccount(generatePrivateKey()),
32
+ * });
33
+ *
34
+ * // 2. Create a bundler client with the account
35
+ * const bundlerClient = createBundlerClient({
36
+ * account,
37
+ * chain: sepolia,
38
+ * transport,
39
+ * userOperation: {
40
+ * estimateFeesPerGas,
41
+ * },
42
+ * // Optional: sponsor gas with a paymaster
43
+ * paymaster: createPaymasterClient({ transport }),
44
+ * paymasterContext: { policyId: "YOUR_POLICY_ID" },
45
+ * });
46
+ *
47
+ * // 3. Send a user operation
48
+ * const hash = await bundlerClient.sendUserOperation({
49
+ * calls: [{ to: "0x...", value: 0n, data: "0x" }],
50
+ * });
51
+ *
52
+ * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
53
+ * ```
15
54
  */
16
55
  export async function toModularAccountV2({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt = 0n, factory, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }) {
17
56
  const is7702 = mode === "7702";
@@ -1 +1 @@
1
- {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GASnB,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EACL,yCAAyC,EACzC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqCzC;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAA4B,EAClE,MAAM,EACN,KAAK,EACL,cAAc,EACd,YAAY,EACZ,cAAc,EAAE,eAAe,EAC/B,IAAI,GAAG,EAAE,EACT,OAAO,EACP,WAAW,EAAE,YAAY,EACzB,qBAAqB,EAAE,sBAAsB,EA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Ac;QACd,YAAY;QACZ,cAAc;QACd,aAAa;KACd,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,4EAA4E;KAC7E,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type PrivateKeyAccount,\n type Transport,\n} from \"viem\";\nimport {\n type ToSmartAccountParameters,\n entryPoint07Address,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport {\n getModularAccountV2AddressFromFactoryData,\n predictModularAccountV2Address,\n} from \"../predictAddress.js\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// This may be extended in the future with additional MAv2-specific methods.\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factory?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n factory?: Address;\n implementationAddress?: Address;\n } & (\n | {\n salt?: bigint;\n factoryData?: never;\n }\n | {\n salt?: never;\n factoryData?: Hex;\n }\n ));\n\n/**\n * Creates a MAv2 account.\n *\n * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.\n * @returns {Promise<ModularAccountV2>} A MAv2 account.\n */\nexport async function toModularAccountV2<TMode extends Mode = Mode>({\n client,\n owner,\n deferredAction,\n signerEntity,\n accountAddress: accountAddress_,\n salt = 0n,\n factory,\n factoryData: factoryData_,\n implementationAddress: implementationAddress_,\n mode,\n}: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2> {\n const is7702 = mode === \"7702\";\n\n LOGGER.debug(\"toModularAccountV2:start\", {\n ownerType: owner.type,\n mode,\n hasDeferredAction: !!deferredAction,\n hasAccountAddress: !!accountAddress_,\n });\n\n const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;\n\n const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);\n\n const getFactoryArgs = async () => {\n if (is7702) {\n // This is only for EP 0.8.0.\n // return {\n // factory: \"0x7702\",\n // factoryData: \"0x\",\n // } as const;\n return {\n factory: undefined,\n factoryData: undefined,\n } as const;\n }\n\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [owner.address, salt],\n }),\n };\n };\n\n const accountAddress =\n accountAddress_ ??\n (is7702\n ? owner.address\n : factoryData_\n ? await getModularAccountV2AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData: factoryData_,\n implementationAddress,\n entryPoint: {\n version: \"0.7\",\n address: entryPoint07Address,\n },\n })\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: owner.address,\n }));\n\n LOGGER.debug(\"toModularAccountV2:address-resolved\", {\n accountAddress,\n is7702,\n });\n\n let authorization: ToSmartAccountParameters[\"authorization\"];\n if (is7702) {\n LOGGER.debug(\"toModularAccountV2:7702-mode\");\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // This may be extended in the future with additional MAv2-specific methods.\n };\n}\n"]}
1
+ {"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GASnB,MAAM,MAAM,CAAC;AACd,OAAO,EAEL,mBAAmB,GACpB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAE9E,OAAO,EACL,yCAAyC,EACzC,8BAA8B,GAC/B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAAE,uBAAuB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAqCzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,CAAC,KAA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C/D,wCAAwC;YACxC,OAAO,EAAE,KAA0B;YACnC,OAAO,EAAE,cAAc,CAAC,UAAU;SACnC,CAAC;IACJ,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,sBAAsB,CAAC;QACxC,MAAM;QACN,KAAK;QACL,cAAc;QACd,cAAc;QACd,YAAY;QACZ,cAAc;QACd,aAAa;KACd,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,IAAI;QACP,4EAA4E;KAC7E,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type PrivateKeyAccount,\n type Transport,\n} from \"viem\";\nimport {\n type ToSmartAccountParameters,\n entryPoint07Address,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport {\n getModularAccountV2AddressFromFactoryData,\n predictModularAccountV2Address,\n} from \"../predictAddress.js\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { EntityIdOverrideError } from \"../../errors/EntityIdOverrideError.js\";\nimport { InvalidOwnerError } from \"../../errors/InvalidOwnerError.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from \"../utils/account.js\";\nimport { LOGGER } from \"../../logger.js\";\n\ntype Mode = \"default\" | \"7702\";\n\n// This may be extended in the future with additional MAv2-specific methods.\nexport type ModularAccountV2 = ModularAccountV2Base & {};\n\nexport type ToModularAccountV2Params<\n TMode extends Mode | undefined = Mode | undefined,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factory?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n factory?: Address;\n implementationAddress?: Address;\n } & (\n | {\n salt?: bigint;\n factoryData?: never;\n }\n | {\n salt?: never;\n factoryData?: Hex;\n }\n ));\n\n/**\n * Creates a MAv2 account.\n *\n * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.\n * @returns {Promise<ModularAccountV2>} A MAv2 account.\n *\n * @example\n * ```ts\n * import { createPublicClient } from \"viem\";\n * import { createBundlerClient, createPaymasterClient } from \"viem/account-abstraction\";\n * import { sepolia } from \"viem/chains\";\n * import { generatePrivateKey, privateKeyToAccount } from \"viem/accounts\";\n * import { alchemyTransport } from \"@alchemy/common\";\n * import { estimateFeesPerGas } from \"@alchemy/aa-infra\";\n * import { toModularAccountV2 } from \"@alchemy/smart-accounts\";\n *\n * const transport = alchemyTransport({ apiKey: \"YOUR_API_KEY\" });\n *\n * // 1. Create a MAv2 smart account\n * const account = await toModularAccountV2({\n * client: createPublicClient({ chain: sepolia, transport }),\n * owner: privateKeyToAccount(generatePrivateKey()),\n * });\n *\n * // 2. Create a bundler client with the account\n * const bundlerClient = createBundlerClient({\n * account,\n * chain: sepolia,\n * transport,\n * userOperation: {\n * estimateFeesPerGas,\n * },\n * // Optional: sponsor gas with a paymaster\n * paymaster: createPaymasterClient({ transport }),\n * paymasterContext: { policyId: \"YOUR_POLICY_ID\" },\n * });\n *\n * // 3. Send a user operation\n * const hash = await bundlerClient.sendUserOperation({\n * calls: [{ to: \"0x...\", value: 0n, data: \"0x\" }],\n * });\n *\n * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });\n * ```\n */\nexport async function toModularAccountV2<TMode extends Mode = Mode>({\n client,\n owner,\n deferredAction,\n signerEntity,\n accountAddress: accountAddress_,\n salt = 0n,\n factory,\n factoryData: factoryData_,\n implementationAddress: implementationAddress_,\n mode,\n}: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2> {\n const is7702 = mode === \"7702\";\n\n LOGGER.debug(\"toModularAccountV2:start\", {\n ownerType: owner.type,\n mode,\n hasDeferredAction: !!deferredAction,\n hasAccountAddress: !!accountAddress_,\n });\n\n const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;\n\n const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);\n\n const getFactoryArgs = async () => {\n if (is7702) {\n // This is only for EP 0.8.0.\n // return {\n // factory: \"0x7702\",\n // factoryData: \"0x\",\n // } as const;\n return {\n factory: undefined,\n factoryData: undefined,\n } as const;\n }\n\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [owner.address, salt],\n }),\n };\n };\n\n const accountAddress =\n accountAddress_ ??\n (is7702\n ? owner.address\n : factoryData_\n ? await getModularAccountV2AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData: factoryData_,\n implementationAddress,\n entryPoint: {\n version: \"0.7\",\n address: entryPoint07Address,\n },\n })\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n type: \"SMA\",\n ownerAddress: owner.address,\n }));\n\n LOGGER.debug(\"toModularAccountV2:address-resolved\", {\n accountAddress,\n is7702,\n });\n\n let authorization: ToSmartAccountParameters[\"authorization\"];\n if (is7702) {\n LOGGER.debug(\"toModularAccountV2:7702-mode\");\n if (owner.type !== \"local\") {\n LOGGER.error(\"toModularAccountV2:invalid-owner-type\", {\n ownerType: owner.type,\n });\n throw new InvalidOwnerError(\n `Owner of type ${owner.type} is unsupported for 7702 mode.`,\n );\n }\n if (owner.signAuthorization == null) {\n LOGGER.error(\"toModularAccountV2:missing-signAuthorization\");\n throw new InvalidOwnerError(\n \"Owner must implement `signAuthorization` to be used with 7702 mode.\",\n );\n }\n if (\n entityId === DEFAULT_OWNER_ENTITY_ID &&\n owner.address !== accountAddress\n ) {\n LOGGER.error(\"toModularAccountV2:entity-id-override\");\n throw new EntityIdOverrideError();\n }\n authorization = {\n // The current version of Viem has some pretty strict constraints\n // on a `PrivateKeyAccount`, but this seems safe as long as the\n // owner is able to `signAuthorization`.\n account: owner as PrivateKeyAccount,\n address: DefaultAddress.SMAV2_7702,\n };\n }\n\n const base = await toModularAccountV2Base({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity,\n deferredAction,\n authorization,\n });\n\n return {\n ...base,\n // This may be extended in the future with additional MAv2-specific methods.\n };\n}\n"]}
@@ -25,7 +25,7 @@ export type CreateDeferredActionTypedDataParams = {
25
25
  deadline: number;
26
26
  nonce: bigint;
27
27
  };
28
- export type BuildPreSignatureDeferredActionDigestParams = {
28
+ export type BuildPreSignatureDeferredActionPayloadParams = {
29
29
  typedData: DeferredActionTypedData;
30
30
  };
31
31
  export type EntityIdAndNonceParams = {
@@ -36,7 +36,7 @@ export type EntityIdAndNonceParams = {
36
36
  };
37
37
  export type DeferralActions = {
38
38
  createDeferredActionTypedDataObject: (args: CreateDeferredActionTypedDataParams) => Promise<DeferredActionReturnData>;
39
- buildPreSignatureDeferredActionDigest: (args: BuildPreSignatureDeferredActionDigestParams) => Hex;
39
+ buildPreSignatureDeferredActionPayload: (args: BuildPreSignatureDeferredActionPayloadParams) => Hex;
40
40
  getEntityIdAndNonce: (args: EntityIdAndNonceParams) => Promise<{
41
41
  nonce: bigint;
42
42
  entityId: number;
@@ -46,6 +46,6 @@ export type DeferralActions = {
46
46
  * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
47
47
  *
48
48
  * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
49
- * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
49
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildPreSignatureDeferredActionPayload`, and `buildUserOperationWithDeferredAction`.
50
50
  */
51
51
  export declare const deferralActions: <TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends SmartAccount = SmartAccount>(client: Client<TTransport, TChain, TAccount>) => DeferralActions;
@@ -10,7 +10,7 @@ export const ENTITY_ID_AND_NONCE_READER_BYTECODE = "0x60806040523480156100105760
10
10
  * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
11
11
  *
12
12
  * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
13
- * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
13
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildPreSignatureDeferredActionPayload`, and `buildUserOperationWithDeferredAction`.
14
14
  */
15
15
  export const deferralActions = (client) => {
16
16
  const createDeferredActionTypedDataObject = async ({ callData, deadline, nonce, }) => {
@@ -40,7 +40,7 @@ export const deferralActions = (client) => {
40
40
  },
41
41
  };
42
42
  };
43
- const buildPreSignatureDeferredActionDigest = ({ typedData, }) => {
43
+ const buildPreSignatureDeferredActionPayload = ({ typedData, }) => {
44
44
  const account = client.account;
45
45
  if (!account || !isModularAccountV2(account)) {
46
46
  throw new AccountNotFoundError();
@@ -93,7 +93,7 @@ export const deferralActions = (client) => {
93
93
  };
94
94
  return {
95
95
  createDeferredActionTypedDataObject,
96
- buildPreSignatureDeferredActionDigest,
96
+ buildPreSignatureDeferredActionPayload,
97
97
  getEntityIdAndNonce,
98
98
  };
99
99
  };
@@ -1 +1 @@
1
- {"version":3,"file":"deferralActions.js","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/deferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAKT,YAAY,EACZ,IAAI,EACJ,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,KAAK,GAEN,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,IAAI,E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AAC,QAAQ,CAAC,CAAC;QAC3C,CAAC;QAED,MAAM,QAAQ,GAAG,gBAAgB,CAAC;YAChC,GAAG,EAAE,yBAAyB;YAC9B,QAAQ,EAAE,mCAAmC;YAC7C,IAAI,EAAE;gBACJ,OAAO,CAAC,OAAO;gBACf,OAAO,CAAC,UAAU,CAAC,OAAO;gBAC1B,iBAAiB,CAAC;oBAChB,QAAQ;oBACR,QAAQ;oBACR,kBAAkB;oBAClB,gBAAgB;iBACjB,CAAC;aACH;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;QAC/C,MAAM,EAAE,IAAI,EAAE,GAAG,MAAM,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC,CAAC;QAClD,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;QAC7D,CAAC;QACD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC;YACnB,QAAQ,EAAE,WAAW,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;SACjD,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,mCAAmC;QACnC,qCAAqC;QACrC,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n concatHex,\n type Hex,\n type Client,\n type Chain,\n type Transport,\n encodePacked,\n size,\n toHex,\n maxUint152,\n encodeDeployData,\n hexToNumber,\n isHex,\n type TypedDataDefinition,\n} from \"viem\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { entityIdAndNonceReaderAbi } from \"../abis/entityIdAndNonceReader.js\";\nimport { getAction } from \"viem/utils\";\nimport { call } from \"viem/actions\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { buildFullNonceKey, isModularAccountV2 } from \"../utils/account.js\";\nimport { AccountNotFoundError, BaseError } from \"@alchemy/common\";\n\nexport const ENTITY_ID_AND_NONCE_READER_BYTECODE =\n \"0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe\";\n\nexport type DeferredActionTypedData = TypedDataDefinition<\n {\n DeferredAction: [\n { name: \"nonce\"; type: \"uint256\" },\n { name: \"deadline\"; type: \"uint48\" },\n { name: \"call\"; type: \"bytes\" },\n ];\n },\n \"DeferredAction\"\n>;\n\nexport type DeferredActionReturnData = {\n typedData: DeferredActionTypedData;\n};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n nonce: bigint;\n};\n\nexport type BuildPreSignatureDeferredActionDigestParams = {\n typedData: DeferredActionTypedData;\n};\n\nexport type EntityIdAndNonceParams = {\n entityId?: number;\n nonceKey?: bigint;\n isGlobalValidation: boolean;\n isDeferredAction?: boolean;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams,\n ) => Promise<DeferredActionReturnData>;\n buildPreSignatureDeferredActionDigest: (\n args: BuildPreSignatureDeferredActionDigestParams,\n ) => Hex;\n getEntityIdAndNonce: (\n args: EntityIdAndNonceParams,\n ) => Promise<{ nonce: bigint; entityId: number }>;\n};\n\n/**\n * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.\n */\nexport const deferralActions = <\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartAccount = SmartAccount,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): DeferralActions => {\n const createDeferredActionTypedDataObject = async ({\n callData,\n deadline,\n nonce,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n return {\n typedData: {\n domain: {\n chainId: client.chain.id,\n verifyingContract: client.account.address,\n },\n types: {\n DeferredAction: [\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint48\" },\n { name: \"call\", type: \"bytes\" },\n ],\n },\n primaryType: \"DeferredAction\",\n message: {\n nonce: nonce,\n deadline: deadline,\n call: callData,\n },\n },\n };\n };\n\n const buildPreSignatureDeferredActionDigest = ({\n typedData,\n }: BuildPreSignatureDeferredActionDigestParams): Hex => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n const signerEntity = account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n const encodedCallData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call],\n );\n\n const encodedDataLength = size(encodedCallData);\n const encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedCallData,\n ]);\n return encodedData;\n };\n\n const getEntityIdAndNonce = async ({\n entityId = 1,\n nonceKey = 0n,\n isGlobalValidation,\n isDeferredAction = true,\n }: EntityIdAndNonceParams) => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const bytecode = encodeDeployData({\n abi: entityIdAndNonceReaderAbi,\n bytecode: ENTITY_ID_AND_NONCE_READER_BYTECODE,\n args: [\n account.address,\n account.entryPoint.address,\n buildFullNonceKey({\n nonceKey,\n entityId,\n isGlobalValidation,\n isDeferredAction,\n }),\n ],\n });\n\n const action = getAction(client, call, \"call\");\n const { data } = await action({ data: bytecode });\n if (!data) {\n throw new BaseError(\"No data returned from contract call\");\n }\n if (!isHex(data)) {\n throw new BaseError(\"Expected hex data from contract call\");\n }\n\n return {\n nonce: BigInt(data),\n entityId: hexToNumber(`0x${data.slice(40, 48)}`),\n };\n };\n\n return {\n createDeferredActionTypedDataObject,\n buildPreSignatureDeferredActionDigest,\n getEntityIdAndNonce,\n };\n};\n"]}
1
+ {"version":3,"file":"deferralActions.js","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/deferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAKT,YAAY,EACZ,IAAI,EACJ,KAAK,EACL,UAAU,EACV,gBAAgB,EAChB,WAAW,EACX,KAAK,GAEN,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,yBAAyB,EAAE,MAAM,mCAAmC,CAAC;AAC9E,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAC5E,OAAO,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAC5E,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAElE,MAAM,CAAC,MAAM,mCAAmC,GAC9C,s+EAAs+E,CAAC;AA8Cz+E;;;;;GAKG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAK7B,MAA4C,EAC3B,EAAE;IACnB,MAAM,mCAAmC,GAAG,KAAK,EAAE,EACjD,QAAQ,EACR,QAAQ,EACR,KAAK,GAC+B,EAAqC,EAAE;QAC3E,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC/B,IAAI,CAAC,OAAO,IAAI,CAAC,kBAAkB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7C,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED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AAC,IAAI,CAAC,EAAE,CAAC;YACjB,MAAM,IAAI,SAAS,CAAC,sCAAsC,CAAC,CAAC;QAC9D,CAAC;QAED,OAAO;YACL,KAAK,EAAE,MAAM,CAAC,IAAI,CAAC;YACnB,QAAQ,EAAE,WAAW,CAAC,KAAK,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;SACjD,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,mCAAmC;QACnC,sCAAsC;QACtC,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n concatHex,\n type Hex,\n type Client,\n type Chain,\n type Transport,\n encodePacked,\n size,\n toHex,\n maxUint152,\n encodeDeployData,\n hexToNumber,\n isHex,\n type TypedDataDefinition,\n} from \"viem\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { entityIdAndNonceReaderAbi } from \"../abis/entityIdAndNonceReader.js\";\nimport { getAction } from \"viem/utils\";\nimport { call } from \"viem/actions\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { buildFullNonceKey, isModularAccountV2 } from \"../utils/account.js\";\nimport { AccountNotFoundError, BaseError } from \"@alchemy/common\";\n\nexport const ENTITY_ID_AND_NONCE_READER_BYTECODE =\n \"0x608060405234801561001057600080fd5b506040516104f13803806104f183398101604081905261002f916101e5565b60006008826001600160c01b0316901c90506000808263ffffffff1611610057576001610059565b815b90506001600160a01b0385163b15610133575b60006001600160a01b03861663d31b575b6bffffffff0000000000000000604085901b166040516001600160e01b031960e084901b1681526001600160401b03199091166004820152602401600060405180830381865afa1580156100d5573d6000803e3d6000fd5b505050506040513d6000823e601f3d908101601f191682016040526100fd91908101906103c6565b805190915060ff161580156101155750606081015151155b156101205750610133565b8161012a816104a4565b9250505061006c565b604051631aab3f0d60e11b81526001600160a01b03868116600483015264ffffffff01600160c01b038516600884901b64ffffffff0016176024830152600091908616906335567e1a90604401602060405180830381865afa15801561019d573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906101c191906104d7565b90508060005260206000f35b6001600160a01b03811681146101e257600080fd5b50565b6000806000606084860312156101fa57600080fd5b8351610205816101cd565b6020850151909350610216816101cd565b60408501519092506001600160c01b038116811461023357600080fd5b809150509250925092565b634e487b7160e01b600052604160045260246000fd5b604051608081016001600160401b03811182821017156102765761027661023e565b60405290565b604051601f8201601f191681016001600160401b03811182821017156102a4576102a461023e565b604052919050565b60006001600160401b038211156102c5576102c561023e565b5060051b60200190565b600082601f8301126102e057600080fd5b81516102f36102ee826102ac565b61027c565b8082825260208201915060208360051b86010192508583111561031557600080fd5b602085015b8381101561034857805166ffffffffffffff198116811461033a57600080fd5b83526020928301920161031a565b5095945050505050565b600082601f83011261036357600080fd5b81516103716102ee826102ac565b8082825260208201915060208360051b86010192508583111561039357600080fd5b602085015b838110156103485780516001600160e01b0319811681146103b857600080fd5b835260209283019201610398565b6000602082840312156103d857600080fd5b81516001600160401b038111156103ee57600080fd5b82016080818503121561040057600080fd5b610408610254565b815160ff8116811461041957600080fd5b815260208201516001600160401b0381111561043457600080fd5b610440868285016102cf565b60208301525060408201516001600160401b0381111561045f57600080fd5b61046b868285016102cf565b60408301525060608201516001600160401b0381111561048a57600080fd5b61049686828501610352565b606083015250949350505050565b600063ffffffff821663ffffffff81036104ce57634e487b7160e01b600052601160045260246000fd5b60010192915050565b6000602082840312156104e957600080fd5b505191905056fe\";\n\nexport type DeferredActionTypedData = TypedDataDefinition<\n {\n DeferredAction: [\n { name: \"nonce\"; type: \"uint256\" },\n { name: \"deadline\"; type: \"uint48\" },\n { name: \"call\"; type: \"bytes\" },\n ];\n },\n \"DeferredAction\"\n>;\n\nexport type DeferredActionReturnData = {\n typedData: DeferredActionTypedData;\n};\n\nexport type CreateDeferredActionTypedDataParams = {\n callData: Hex;\n deadline: number;\n nonce: bigint;\n};\n\nexport type BuildPreSignatureDeferredActionPayloadParams = {\n typedData: DeferredActionTypedData;\n};\n\nexport type EntityIdAndNonceParams = {\n entityId?: number;\n nonceKey?: bigint;\n isGlobalValidation: boolean;\n isDeferredAction?: boolean;\n};\n\nexport type DeferralActions = {\n createDeferredActionTypedDataObject: (\n args: CreateDeferredActionTypedDataParams,\n ) => Promise<DeferredActionReturnData>;\n buildPreSignatureDeferredActionPayload: (\n args: BuildPreSignatureDeferredActionPayloadParams,\n ) => Hex;\n getEntityIdAndNonce: (\n args: EntityIdAndNonceParams,\n ) => Promise<{ nonce: bigint; entityId: number }>;\n};\n\n/**\n * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildPreSignatureDeferredActionPayload`, and `buildUserOperationWithDeferredAction`.\n */\nexport const deferralActions = <\n TTransport extends Transport = Transport,\n TChain extends Chain = Chain,\n TAccount extends SmartAccount = SmartAccount,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): DeferralActions => {\n const createDeferredActionTypedDataObject = async ({\n callData,\n deadline,\n nonce,\n }: CreateDeferredActionTypedDataParams): Promise<DeferredActionReturnData> => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n return {\n typedData: {\n domain: {\n chainId: client.chain.id,\n verifyingContract: client.account.address,\n },\n types: {\n DeferredAction: [\n { name: \"nonce\", type: \"uint256\" },\n { name: \"deadline\", type: \"uint48\" },\n { name: \"call\", type: \"bytes\" },\n ],\n },\n primaryType: \"DeferredAction\",\n message: {\n nonce: nonce,\n deadline: deadline,\n call: callData,\n },\n },\n };\n };\n\n const buildPreSignatureDeferredActionPayload = ({\n typedData,\n }: BuildPreSignatureDeferredActionPayloadParams): Hex => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n const signerEntity = account.signerEntity;\n const validationLocator =\n (BigInt(signerEntity.entityId) << 8n) |\n (signerEntity.isGlobalValidation ? 1n : 0n);\n\n const encodedCallData = encodePacked(\n [\"uint168\", \"uint48\", \"bytes\"],\n [validationLocator, typedData.message.deadline, typedData.message.call],\n );\n\n const encodedDataLength = size(encodedCallData);\n const encodedData = concatHex([\n toHex(encodedDataLength, { size: 4 }),\n encodedCallData,\n ]);\n return encodedData;\n };\n\n const getEntityIdAndNonce = async ({\n entityId = 1,\n nonceKey = 0n,\n isGlobalValidation,\n isDeferredAction = true,\n }: EntityIdAndNonceParams) => {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const bytecode = encodeDeployData({\n abi: entityIdAndNonceReaderAbi,\n bytecode: ENTITY_ID_AND_NONCE_READER_BYTECODE,\n args: [\n account.address,\n account.entryPoint.address,\n buildFullNonceKey({\n nonceKey,\n entityId,\n isGlobalValidation,\n isDeferredAction,\n }),\n ],\n });\n\n const action = getAction(client, call, \"call\");\n const { data } = await action({ data: bytecode });\n if (!data) {\n throw new BaseError(\"No data returned from contract call\");\n }\n if (!isHex(data)) {\n throw new BaseError(\"Expected hex data from contract call\");\n }\n\n return {\n nonce: BigInt(data),\n entityId: hexToNumber(`0x${data.slice(40, 48)}`),\n };\n };\n\n return {\n createDeferredActionTypedDataObject,\n buildPreSignatureDeferredActionPayload,\n getEntityIdAndNonce,\n };\n};\n"]}
@@ -133,11 +133,11 @@ export declare class PermissionBuilder {
133
133
  /**
134
134
  * Compiles the deferred action typed data to sign.
135
135
  *
136
- * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionDigest: Hex}>} The deferred action typed data and the full pre-signature deferred action digest.
136
+ * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionPayload: Hex}>} The deferred action typed data and the full pre-signature deferred action payload.
137
137
  */
138
138
  compileDeferred(): Promise<{
139
139
  typedData: DeferredActionTypedData;
140
- fullPreSignatureDeferredActionDigest: Hex;
140
+ fullPreSignatureDeferredActionPayload: Hex;
141
141
  }>;
142
142
  /**
143
143
  * Compiles the raw install arguments for the installValidation function.
@@ -15,6 +15,8 @@ const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
15
15
  const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
16
16
  const ACCOUNT_EXECUTE_SELECTOR = "0xb61d27f6";
17
17
  const ACCOUNT_EXECUTEBATCH_SELECTOR = "0x34fcd5be";
18
+ const ACCOUNT_PERFORM_CREATE_SELECTOR = "0x5998db5c";
19
+ const ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR = "0xf2680c0f";
18
20
  /**
19
21
  * A pseudo-enum for permission types.
20
22
  */
@@ -142,6 +144,12 @@ export class PermissionBuilder {
142
144
  * @returns {this} The permission builder instance.
143
145
  */
144
146
  addSelector({ selector }) {
147
+ if (selector === ACCOUNT_PERFORM_CREATE_SELECTOR) {
148
+ throw new SelectorNotAllowed("performCreate");
149
+ }
150
+ if (selector === ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR) {
151
+ throw new SelectorNotAllowed("executeWithRuntimeValidation");
152
+ }
145
153
  this.selectors.push(selector);
146
154
  return this;
147
155
  }
@@ -193,13 +201,19 @@ export class PermissionBuilder {
193
201
  if (permission.data.functions.length === 0) {
194
202
  throw new NoFunctionsProvidedError(permission);
195
203
  }
196
- // Explicitly disallow adding execute & executeBatch
204
+ // Explicitly disallow adding execute, executeBatch, performCreate, and executeWithRuntimeValidation
197
205
  if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {
198
206
  throw new SelectorNotAllowed("execute");
199
207
  }
200
208
  else if (permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)) {
201
209
  throw new SelectorNotAllowed("executeBatch");
202
210
  }
211
+ else if (permission.data.functions.includes(ACCOUNT_PERFORM_CREATE_SELECTOR)) {
212
+ throw new SelectorNotAllowed("performCreate");
213
+ }
214
+ else if (permission.data.functions.includes(ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR)) {
215
+ throw new SelectorNotAllowed("executeWithRuntimeValidation");
216
+ }
203
217
  this.selectors = [...this.selectors, ...permission.data.functions];
204
218
  }
205
219
  this.permissions.push(permission);
@@ -222,7 +236,7 @@ export class PermissionBuilder {
222
236
  /**
223
237
  * Compiles the deferred action typed data to sign.
224
238
  *
225
- * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionDigest: Hex}>} The deferred action typed data and the full pre-signature deferred action digest.
239
+ * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionPayload: Hex}>} The deferred action typed data and the full pre-signature deferred action payload.
226
240
  */
227
241
  async compileDeferred() {
228
242
  // Add time range module hook via expiry
@@ -245,14 +259,14 @@ export class PermissionBuilder {
245
259
  deadline: this.deadline,
246
260
  nonce: this.nonce,
247
261
  });
248
- const preSignatureDigest = deferralActions(this.client).buildPreSignatureDeferredActionDigest({ typedData });
249
- // Encode additional information to build the full pre-signature digest
250
- const fullPreSignatureDeferredActionDigest = `0x0${this.hasAssociatedExecHooks ? "1" : "0"}${toHex(this.nonce, {
262
+ const preSignaturePayload = deferralActions(this.client).buildPreSignatureDeferredActionPayload({ typedData });
263
+ // Encode additional information to build the full pre-signature payload
264
+ const fullPreSignatureDeferredActionPayload = `0x0${this.hasAssociatedExecHooks ? "1" : "0"}${toHex(this.nonce, {
251
265
  size: 32,
252
- }).slice(2)}${preSignatureDigest.slice(2)}`;
266
+ }).slice(2)}${preSignaturePayload.slice(2)}`;
253
267
  return {
254
268
  typedData,
255
- fullPreSignatureDeferredActionDigest,
269
+ fullPreSignatureDeferredActionPayload,
256
270
  };
257
271
  }
258
272
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"permissionBuilder.js","sourceRoot":"","sources":["../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,EACL,WAAW,GAMZ,MAAM,MAAM,CA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AG,EAAE,CAAC;YACR,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,GAAG,CAAC,UAAU;gBAC1B,QAAQ,EAAE,sBAAsB,CAAC,mBAAmB,CAAC,GAAG,CAAC,QAAQ,CAAC;aACnE,CAAC,CAAC;QACL,CAAC;QAED,MAAM,KAAK,GAAG,QAAQ,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC;QAC5D,IAAI,KAAK,EAAE,CAAC;YACV,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,KAAK,CAAC,UAAU;gBAC5B,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAAC,KAAK,CAAC,QAAQ,CAAC;aAC9D,CAAC,CAAC;QACL,CAAC;QAED,MAAM,EAAE,GAAG,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;QAC9C,IAAI,EAAE,EAAE,CAAC;YACP,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,EAAE,CAAC,UAAU;gBACzB,QAAQ,EAAE,sBAAsB,CAAC,mBAAmB,CAAC,EAAE,CAAC,QAAQ,CAAC;aAClE,CAAC,CAAC;QACL,CAAC;QAED,MAAM,SAAS,GAAG,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC;QAC5D,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,SAAS,CAAC,UAAU;gBAChC,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAAC,SAAS,CAAC,QAAQ,CAAC;aAClE,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n maxUint48,\n toHex,\n zeroAddress,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nimport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nimport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nimport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nimport { HookType, type HookConfig, type ValidationConfig } from \"./types.js\";\nimport {\n deferralActions,\n type DeferredActionTypedData,\n} from \"./decorators/deferralActions.js\";\nimport {\n installValidationActions,\n type InstallValidationParams,\n} from \"./decorators/installValidation.js\";\nimport { assertNever, AccountNotFoundError } from \"@alchemy/common\";\nimport {\n AccountAddressAsTargetError,\n DeadlineOverLimitError,\n DuplicateTargetAddressError,\n ExpiredDeadlineError,\n MultipleGasLimitError,\n MultipleNativeTokenTransferError,\n NoFunctionsProvidedError,\n RootPermissionOnlyError,\n SelectorNotAllowed,\n ValidationConfigUnsetError,\n ZeroAddressError,\n} from \"../errors/permissionBuilderErrors.js\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { DefaultModuleAddress, isModularAccountV2 } from \"./utils/account.js\";\n\n// We use this to offset the ERC20 spend limit entityId\nconst HALF_UINT32 = 2147483647;\nconst ERC20_APPROVE_SELECTOR = \"0x095ea7b3\";\nconst ERC20_TRANSFER_SELECTOR = \"0xa9059cbb\";\nconst ACCOUNT_EXECUTE_SELECTOR = \"0xb61d27f6\";\nconst ACCOUNT_EXECUTEBATCH_SELECTOR = \"0x34fcd5be\";\n\n/**\n * A pseudo-enum for permission types.\n */\nexport const PermissionType = {\n NATIVE_TOKEN_TRANSFER: \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER: \"erc20-token-transfer\",\n // ERC721_TOKEN_TRANSFER : \"erc721-token-transfer\", // Unimplemented\n // ERC1155_TOKEN_TRANSFER : \"erc1155-token-transfer\", // Unimplemented\n GAS_LIMIT: \"gas-limit\",\n // CALL_LIMIT : \"call-limit\", //Unimplemented\n // RATE_LIMIT : \"rate-limit\", //Unimplemented\n CONTRACT_ACCESS: \"contract-access\",\n ACCOUNT_FUNCTIONS: \"account-functions\",\n FUNCTIONS_ON_ALL_CONTRACTS: \"functions-on-all-contracts\",\n FUNCTIONS_ON_CONTRACT: \"functions-on-contract\",\n ROOT: \"root\",\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type PermissionType =\n (typeof PermissionType)[keyof typeof PermissionType];\n\n/**\n * A pseudo-enum for hook identifiers.\n */\nexport const HookIdentifier = {\n NATIVE_TOKEN_TRANSFER: \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER: \"erc20-token-transfer\",\n GAS_LIMIT: \"gas-limit\",\n PREVAL_ALLOWLIST: \"preval-allowlist\", // aggregate of CONTRACT_ACCESS, ACCOUNT_FUNCTIONS, FUNCTIONS_ON_ALL_CONTRACTS, FUNCTIONS_ON_CONTRACT\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type HookIdentifier =\n (typeof HookIdentifier)[keyof typeof HookIdentifier];\n\ntype PreExecutionHookConfig = {\n address: Address;\n entityId: number;\n hookType: typeof HookType.EXECUTION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype PreValidationHookConfig = {\n address: Address;\n entityId: number;\n hookType: typeof HookType.VALIDATION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.ERC20_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n [HookIdentifier.GAS_LIMIT]:\n | {\n hookConfig: PreValidationHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.PREVAL_ALLOWLIST]:\n | {\n hookConfig: PreValidationHookConfig;\n\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n};\n\ntype Key = {\n publicKey: Hex;\n type: \"secp256k1\" | \"contract\";\n};\n\nexport type Permission =\n | {\n // this permission allows transfer of native tokens from the account\n type: typeof PermissionType.NATIVE_TOKEN_TRANSFER;\n data: {\n allowance: Hex;\n };\n }\n | {\n // this permission allows transfer or approval of erc20 tokens from the account\n type: typeof PermissionType.ERC20_TOKEN_TRANSFER;\n data: {\n address: Address; // erc20 token contract address\n allowance: Hex;\n };\n }\n | {\n // this permissions allows the key to spend gas for UOs\n type: typeof PermissionType.GAS_LIMIT;\n data: {\n limit: Hex;\n };\n }\n | {\n // this permission grants access to all functions in a contract\n type: typeof PermissionType.CONTRACT_ACCESS;\n data: {\n address: Address;\n };\n }\n | {\n // this permission grants access to functions in the account\n type: typeof PermissionType.ACCOUNT_FUNCTIONS;\n data: {\n functions: Hex[]; // function signatures\n };\n }\n | {\n // this permission grants access to a function selector in any address or contract\n type: typeof PermissionType.FUNCTIONS_ON_ALL_CONTRACTS;\n data: {\n functions: Hex[]; // function signatures\n };\n }\n | {\n // this permission grants access to specified functions on a specific contract\n type: typeof PermissionType.FUNCTIONS_ON_CONTRACT;\n data: {\n address: Address;\n functions: Hex[];\n };\n }\n | {\n // this permission grants full access to everything\n type: typeof PermissionType.ROOT;\n data?: never;\n };\n\ntype Hook = {\n hookConfig: HookConfig;\n initData: Hex;\n};\n\n/**\n * A builder for constructing a Permission object.\n */\nexport class PermissionBuilder {\n private client: Client<Transport, Chain, SmartAccount>;\n private validationConfig: ValidationConfig = {\n moduleAddress: zeroAddress,\n entityId: 0, // uint32\n isGlobal: false,\n isSignatureValidation: false,\n isUserOpValidation: false,\n };\n private selectors: Hex[] = [];\n private installData: Hex = \"0x\";\n private permissions: Permission[] = [];\n private hooks: Hook[] = [];\n private nonce: bigint = 0n;\n private hasAssociatedExecHooks: boolean = false;\n private deadline: number = 0;\n\n /**\n * Creates a PermissionBuilder instance.\n *\n * @param {PermissionBuilderParams} params - The parameters for creating a PermissionBuilder instance.\n */\n constructor({\n client,\n key,\n entityId,\n nonce,\n selectors,\n hooks,\n deadline,\n }: {\n client: Client<Transport, Chain, SmartAccount>;\n key: Key;\n entityId: number;\n nonce: bigint;\n selectors?: Hex[];\n hooks?: Hook[];\n deadline?: number;\n }) {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n this.client = client;\n this.validationConfig = {\n moduleAddress: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n entityId,\n isUserOpValidation: true,\n isGlobal: false,\n isSignatureValidation: false,\n };\n this.installData = SingleSignerValidationModule.encodeOnInstallData({\n entityId: entityId,\n signer: key.publicKey,\n });\n this.nonce = nonce;\n if (selectors) this.selectors = selectors;\n if (hooks) this.hooks = hooks;\n if (deadline) this.deadline = deadline;\n }\n\n /**\n * Adds a selector to the permission builder.\n *\n * @param {Hex} selector - The selector to add.\n * @returns {this} The permission builder instance.\n */\n addSelector({ selector }: { selector: Hex }): this {\n this.selectors.push(selector);\n return this;\n }\n\n /**\n * Adds a permission to the permission builder.\n *\n * @param {Permission} permission - The permission to add.\n * @returns {this} The permission builder instance.\n */\n addPermission({ permission }: { permission: Permission }): this {\n // Check 1: If we're adding root, we can't have any other permissions\n if (permission.type === PermissionType.ROOT) {\n if (this.permissions.length !== 0) {\n throw new RootPermissionOnlyError(permission);\n }\n this.permissions.push(permission);\n // Set isGlobal to true\n this.validationConfig.isGlobal = true;\n return this;\n }\n\n // Check 2: If the permission is NOT ROOT (guaranteed), ensure there is no ROOT permission set\n // Will resolve to undefined if ROOT is not found\n // NOTE: Technically this could be replaced by checking permissions[0] since it should not be possible\n // to have >1 permission with root among them\n if (this.permissions.find((p) => p.type === PermissionType.ROOT)) {\n throw new RootPermissionOnlyError(permission);\n }\n\n // Check 3: If the permission is either CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT, ensure it doesn't collide with another like it.\n if (\n permission.type === PermissionType.CONTRACT_ACCESS ||\n permission.type === PermissionType.FUNCTIONS_ON_CONTRACT\n ) {\n // Check 3.1: address must not be the account address, or the user should use the ACCOUNT_FUNCTIONS permission\n if (permission.data.address === this.client.account.address) {\n throw new AccountAddressAsTargetError(permission);\n }\n\n // Check 3.2: there must not be an existing permission with this address as a target\n const targetAddress = permission.data.address;\n const existingPermissionWithSameAddress = this.permissions.find(\n (p) =>\n (p.type === PermissionType.CONTRACT_ACCESS &&\n \"address\" in p.data &&\n p.data.address === targetAddress) ||\n (p.type === PermissionType.FUNCTIONS_ON_CONTRACT &&\n \"address\" in p.data &&\n p.data.address === targetAddress),\n );\n\n if (existingPermissionWithSameAddress) {\n throw new DuplicateTargetAddressError(permission, targetAddress);\n }\n }\n\n // Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors\n if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n // Explicitly disallow adding execute & executeBatch\n if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {\n throw new SelectorNotAllowed(\"execute\");\n } else if (\n permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)\n ) {\n throw new SelectorNotAllowed(\"executeBatch\");\n }\n this.selectors = [...this.selectors, ...permission.data.functions];\n }\n\n this.permissions.push(permission);\n return this;\n }\n\n /**\n * Adds multiple permissions to the permission builder.\n *\n * @param {Permission[]} permissions - The permissions to add.\n * @returns {this} The permission builder instance.\n */\n addPermissions({ permissions }: { permissions: Permission[] }): this {\n // We could validate each permission here, but for simplicity we'll just add them\n // A better approach would be to call addPermission for each one\n permissions.forEach((permission) => {\n this.addPermission({ permission });\n });\n return this;\n }\n\n /**\n * Compiles the deferred action typed data to sign.\n *\n * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionDigest: Hex}>} The deferred action typed data and the full pre-signature deferred action digest.\n */\n async compileDeferred(): Promise<{\n typedData: DeferredActionTypedData;\n fullPreSignatureDeferredActionDigest: Hex;\n }> {\n // Add time range module hook via expiry\n if (this.deadline !== 0) {\n if (this.deadline < Date.now() / 1000) {\n throw new ExpiredDeadlineError(this.deadline, Date.now() / 1000);\n }\n if (this.deadline > maxUint48) {\n throw new DeadlineOverLimitError(this.deadline);\n }\n\n this.hooks.push(\n TimeRangeModule.buildHook(\n {\n entityId: this.validationConfig.entityId,\n validUntil: this.deadline,\n validAfter: 0,\n },\n DefaultModuleAddress.TIME_RANGE,\n ),\n );\n }\n\n const installValidationCall = await this.compileRaw();\n\n const { typedData } = await deferralActions(\n this.client,\n ).createDeferredActionTypedDataObject({\n callData: installValidationCall,\n deadline: this.deadline,\n nonce: this.nonce,\n });\n\n const preSignatureDigest = deferralActions(\n this.client,\n ).buildPreSignatureDeferredActionDigest({ typedData });\n\n // Encode additional information to build the full pre-signature digest\n const fullPreSignatureDeferredActionDigest: `0x${string}` = `0x0${\n this.hasAssociatedExecHooks ? \"1\" : \"0\"\n }${toHex(this.nonce, {\n size: 32,\n }).slice(2)}${preSignatureDigest.slice(2)}`;\n\n return {\n typedData,\n fullPreSignatureDeferredActionDigest,\n };\n }\n\n /**\n * Compiles the raw install arguments for the installValidation function.\n *\n * @returns {Promise<Hex>} The raw install arguments.\n */\n async compileRaw(): Promise<Hex> {\n const account = this.client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n // Translate all permissions into raw hooks if >0\n if (this.permissions.length > 0) {\n const rawHooks = this.translatePermissions(\n this.validationConfig.entityId,\n );\n // Add the translated permissions as hooks\n this.addHooks(rawHooks);\n }\n this.validateConfiguration();\n\n return await installValidationActions(this.client).encodeInstallValidation({\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account,\n });\n }\n\n /**\n * Compiles the install arguments for the installValidation function.\n *\n * @returns {Promise<InstallValidationParams>} The install arguments.\n */\n async compileInstallArgs(): Promise<InstallValidationParams> {\n const account = this.client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n this.validateConfiguration();\n\n return {\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account,\n };\n }\n\n private validateConfiguration(): void {\n if (\n this.validationConfig.isGlobal === false &&\n this.selectors.length === 0\n ) {\n throw new ValidationConfigUnsetError();\n }\n }\n\n // Used to translate consolidated permissions into raw unencoded hooks\n // Note entityId will be a member object later\n private translatePermissions(entityId: number): RawHooks {\n const rawHooks: RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.ERC20_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.GAS_LIMIT]: undefined,\n [HookIdentifier.PREVAL_ALLOWLIST]: undefined,\n };\n\n this.permissions.forEach((permission) => {\n switch (permission.type) {\n case PermissionType.NATIVE_TOKEN_TRANSFER:\n // Should never be added twice, check is on addPermission(s) too\n if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] !== undefined) {\n throw new MultipleNativeTokenTransferError(permission);\n }\n rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.allowance),\n },\n };\n this.hasAssociatedExecHooks = true;\n break;\n case PermissionType.ERC20_TOKEN_TRANSFER:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId: entityId + HALF_UINT32,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId: entityId + HALF_UINT32,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: true,\n erc20SpendLimit: BigInt(permission.data.allowance),\n selectors: [],\n },\n ],\n },\n };\n this.hasAssociatedExecHooks = true;\n // Also allow `approve` and `transfer` for the erc20\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [ERC20_APPROVE_SELECTOR, ERC20_TRANSFER_SELECTOR], // approve, transfer\n },\n ],\n },\n };\n break;\n case PermissionType.GAS_LIMIT:\n // Should only ever be added once, check is also on addPermission(s)\n if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {\n throw new MultipleGasLimitError(permission);\n }\n rawHooks[HookIdentifier.GAS_LIMIT] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.limit),\n },\n };\n break;\n case PermissionType.CONTRACT_ACCESS:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [],\n },\n ],\n },\n };\n break;\n case PermissionType.ACCOUNT_FUNCTIONS:\n // This is handled in add permissions\n break;\n case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: zeroAddress,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.FUNCTIONS_ON_CONTRACT:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.ROOT:\n // Root permission handled in addPermission\n break;\n default:\n return assertNever(permission, \"Unexpected permission type\");\n }\n\n // isGlobal guaranteed to be false since it's only set with root permissions,\n // we must add access to execute & executeBatch if there's a preVal allowlist hook set.\n if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST] !== undefined) {\n const selectorsToAdd: `0x${string}`[] = [\n ACCOUNT_EXECUTE_SELECTOR,\n ACCOUNT_EXECUTEBATCH_SELECTOR,\n ]; // execute, executeBatch\n\n // Only add the selectors if they aren't already in this.selectors\n const newSelectors = selectorsToAdd.filter(\n (selector) => !this.selectors.includes(selector),\n );\n\n this.selectors = [...this.selectors, ...newSelectors];\n }\n });\n\n return rawHooks;\n }\n\n private addHooks(rawHooks: RawHooks) {\n const ntt = rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER];\n if (ntt) {\n this.hooks.push({\n hookConfig: ntt.hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(ntt.initData),\n });\n }\n\n const erc20 = rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER];\n if (erc20) {\n this.hooks.push({\n hookConfig: erc20.hookConfig,\n initData: AllowlistModule.encodeOnInstallData(erc20.initData),\n });\n }\n\n const gl = rawHooks[HookIdentifier.GAS_LIMIT];\n if (gl) {\n this.hooks.push({\n hookConfig: gl.hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(gl.initData),\n });\n }\n\n const allowlist = rawHooks[HookIdentifier.PREVAL_ALLOWLIST];\n if (allowlist) {\n this.hooks.push({\n hookConfig: allowlist.hookConfig,\n initData: AllowlistModule.encodeOnInstallData(allowlist.initData),\n });\n }\n }\n}\n"]}
1
+ {"version":3,"file":"permissionBuilder.js","sourceRoot":"","sources":["../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,KAAK,EACL,WAAW,GAMZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAA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D,IAAI,SAAS,EAAE,CAAC;YACd,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,SAAS,CAAC,UAAU;gBAChC,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAAC,SAAS,CAAC,QAAQ,CAAC;aAClE,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF","sourcesContent":["import {\n maxUint48,\n toHex,\n zeroAddress,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type Transport,\n} from \"viem\";\nimport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nimport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nimport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nimport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nimport { HookType, type HookConfig, type ValidationConfig } from \"./types.js\";\nimport {\n deferralActions,\n type DeferredActionTypedData,\n} from \"./decorators/deferralActions.js\";\nimport {\n installValidationActions,\n type InstallValidationParams,\n} from \"./decorators/installValidation.js\";\nimport { assertNever, AccountNotFoundError } from \"@alchemy/common\";\nimport {\n AccountAddressAsTargetError,\n DeadlineOverLimitError,\n DuplicateTargetAddressError,\n ExpiredDeadlineError,\n MultipleGasLimitError,\n MultipleNativeTokenTransferError,\n NoFunctionsProvidedError,\n RootPermissionOnlyError,\n SelectorNotAllowed,\n ValidationConfigUnsetError,\n ZeroAddressError,\n} from \"../errors/permissionBuilderErrors.js\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { DefaultModuleAddress, isModularAccountV2 } from \"./utils/account.js\";\n\n// We use this to offset the ERC20 spend limit entityId\nconst HALF_UINT32 = 2147483647;\nconst ERC20_APPROVE_SELECTOR = \"0x095ea7b3\";\nconst ERC20_TRANSFER_SELECTOR = \"0xa9059cbb\";\nconst ACCOUNT_EXECUTE_SELECTOR = \"0xb61d27f6\";\nconst ACCOUNT_EXECUTEBATCH_SELECTOR = \"0x34fcd5be\";\nconst ACCOUNT_PERFORM_CREATE_SELECTOR = \"0x5998db5c\";\nconst ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR = \"0xf2680c0f\";\n\n/**\n * A pseudo-enum for permission types.\n */\nexport const PermissionType = {\n NATIVE_TOKEN_TRANSFER: \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER: \"erc20-token-transfer\",\n // ERC721_TOKEN_TRANSFER : \"erc721-token-transfer\", // Unimplemented\n // ERC1155_TOKEN_TRANSFER : \"erc1155-token-transfer\", // Unimplemented\n GAS_LIMIT: \"gas-limit\",\n // CALL_LIMIT : \"call-limit\", //Unimplemented\n // RATE_LIMIT : \"rate-limit\", //Unimplemented\n CONTRACT_ACCESS: \"contract-access\",\n ACCOUNT_FUNCTIONS: \"account-functions\",\n FUNCTIONS_ON_ALL_CONTRACTS: \"functions-on-all-contracts\",\n FUNCTIONS_ON_CONTRACT: \"functions-on-contract\",\n ROOT: \"root\",\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type PermissionType =\n (typeof PermissionType)[keyof typeof PermissionType];\n\n/**\n * A pseudo-enum for hook identifiers.\n */\nexport const HookIdentifier = {\n NATIVE_TOKEN_TRANSFER: \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER: \"erc20-token-transfer\",\n GAS_LIMIT: \"gas-limit\",\n PREVAL_ALLOWLIST: \"preval-allowlist\", // aggregate of CONTRACT_ACCESS, ACCOUNT_FUNCTIONS, FUNCTIONS_ON_ALL_CONTRACTS, FUNCTIONS_ON_CONTRACT\n} as const;\n\n// eslint-disable-next-line @typescript-eslint/no-redeclare\nexport type HookIdentifier =\n (typeof HookIdentifier)[keyof typeof HookIdentifier];\n\ntype PreExecutionHookConfig = {\n address: Address;\n entityId: number;\n hookType: typeof HookType.EXECUTION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype PreValidationHookConfig = {\n address: Address;\n entityId: number;\n hookType: typeof HookType.VALIDATION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.ERC20_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n [HookIdentifier.GAS_LIMIT]:\n | {\n hookConfig: PreValidationHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.PREVAL_ALLOWLIST]:\n | {\n hookConfig: PreValidationHookConfig;\n\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n};\n\ntype Key = {\n publicKey: Hex;\n type: \"secp256k1\" | \"contract\";\n};\n\nexport type Permission =\n | {\n // this permission allows transfer of native tokens from the account\n type: typeof PermissionType.NATIVE_TOKEN_TRANSFER;\n data: {\n allowance: Hex;\n };\n }\n | {\n // this permission allows transfer or approval of erc20 tokens from the account\n type: typeof PermissionType.ERC20_TOKEN_TRANSFER;\n data: {\n address: Address; // erc20 token contract address\n allowance: Hex;\n };\n }\n | {\n // this permissions allows the key to spend gas for UOs\n type: typeof PermissionType.GAS_LIMIT;\n data: {\n limit: Hex;\n };\n }\n | {\n // this permission grants access to all functions in a contract\n type: typeof PermissionType.CONTRACT_ACCESS;\n data: {\n address: Address;\n };\n }\n | {\n // this permission grants access to functions in the account\n type: typeof PermissionType.ACCOUNT_FUNCTIONS;\n data: {\n functions: Hex[]; // function signatures\n };\n }\n | {\n // this permission grants access to a function selector in any address or contract\n type: typeof PermissionType.FUNCTIONS_ON_ALL_CONTRACTS;\n data: {\n functions: Hex[]; // function signatures\n };\n }\n | {\n // this permission grants access to specified functions on a specific contract\n type: typeof PermissionType.FUNCTIONS_ON_CONTRACT;\n data: {\n address: Address;\n functions: Hex[];\n };\n }\n | {\n // this permission grants full access to everything\n type: typeof PermissionType.ROOT;\n data?: never;\n };\n\ntype Hook = {\n hookConfig: HookConfig;\n initData: Hex;\n};\n\n/**\n * A builder for constructing a Permission object.\n */\nexport class PermissionBuilder {\n private client: Client<Transport, Chain, SmartAccount>;\n private validationConfig: ValidationConfig = {\n moduleAddress: zeroAddress,\n entityId: 0, // uint32\n isGlobal: false,\n isSignatureValidation: false,\n isUserOpValidation: false,\n };\n private selectors: Hex[] = [];\n private installData: Hex = \"0x\";\n private permissions: Permission[] = [];\n private hooks: Hook[] = [];\n private nonce: bigint = 0n;\n private hasAssociatedExecHooks: boolean = false;\n private deadline: number = 0;\n\n /**\n * Creates a PermissionBuilder instance.\n *\n * @param {PermissionBuilderParams} params - The parameters for creating a PermissionBuilder instance.\n */\n constructor({\n client,\n key,\n entityId,\n nonce,\n selectors,\n hooks,\n deadline,\n }: {\n client: Client<Transport, Chain, SmartAccount>;\n key: Key;\n entityId: number;\n nonce: bigint;\n selectors?: Hex[];\n hooks?: Hook[];\n deadline?: number;\n }) {\n const account = client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n this.client = client;\n this.validationConfig = {\n moduleAddress: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n entityId,\n isUserOpValidation: true,\n isGlobal: false,\n isSignatureValidation: false,\n };\n this.installData = SingleSignerValidationModule.encodeOnInstallData({\n entityId: entityId,\n signer: key.publicKey,\n });\n this.nonce = nonce;\n if (selectors) this.selectors = selectors;\n if (hooks) this.hooks = hooks;\n if (deadline) this.deadline = deadline;\n }\n\n /**\n * Adds a selector to the permission builder.\n *\n * @param {Hex} selector - The selector to add.\n * @returns {this} The permission builder instance.\n */\n addSelector({ selector }: { selector: Hex }): this {\n if (selector === ACCOUNT_PERFORM_CREATE_SELECTOR) {\n throw new SelectorNotAllowed(\"performCreate\");\n }\n if (selector === ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR) {\n throw new SelectorNotAllowed(\"executeWithRuntimeValidation\");\n }\n this.selectors.push(selector);\n return this;\n }\n\n /**\n * Adds a permission to the permission builder.\n *\n * @param {Permission} permission - The permission to add.\n * @returns {this} The permission builder instance.\n */\n addPermission({ permission }: { permission: Permission }): this {\n // Check 1: If we're adding root, we can't have any other permissions\n if (permission.type === PermissionType.ROOT) {\n if (this.permissions.length !== 0) {\n throw new RootPermissionOnlyError(permission);\n }\n this.permissions.push(permission);\n // Set isGlobal to true\n this.validationConfig.isGlobal = true;\n return this;\n }\n\n // Check 2: If the permission is NOT ROOT (guaranteed), ensure there is no ROOT permission set\n // Will resolve to undefined if ROOT is not found\n // NOTE: Technically this could be replaced by checking permissions[0] since it should not be possible\n // to have >1 permission with root among them\n if (this.permissions.find((p) => p.type === PermissionType.ROOT)) {\n throw new RootPermissionOnlyError(permission);\n }\n\n // Check 3: If the permission is either CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT, ensure it doesn't collide with another like it.\n if (\n permission.type === PermissionType.CONTRACT_ACCESS ||\n permission.type === PermissionType.FUNCTIONS_ON_CONTRACT\n ) {\n // Check 3.1: address must not be the account address, or the user should use the ACCOUNT_FUNCTIONS permission\n if (permission.data.address === this.client.account.address) {\n throw new AccountAddressAsTargetError(permission);\n }\n\n // Check 3.2: there must not be an existing permission with this address as a target\n const targetAddress = permission.data.address;\n const existingPermissionWithSameAddress = this.permissions.find(\n (p) =>\n (p.type === PermissionType.CONTRACT_ACCESS &&\n \"address\" in p.data &&\n p.data.address === targetAddress) ||\n (p.type === PermissionType.FUNCTIONS_ON_CONTRACT &&\n \"address\" in p.data &&\n p.data.address === targetAddress),\n );\n\n if (existingPermissionWithSameAddress) {\n throw new DuplicateTargetAddressError(permission, targetAddress);\n }\n }\n\n // Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors\n if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n // Explicitly disallow adding execute, executeBatch, performCreate, and executeWithRuntimeValidation\n if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {\n throw new SelectorNotAllowed(\"execute\");\n } else if (\n permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)\n ) {\n throw new SelectorNotAllowed(\"executeBatch\");\n } else if (\n permission.data.functions.includes(ACCOUNT_PERFORM_CREATE_SELECTOR)\n ) {\n throw new SelectorNotAllowed(\"performCreate\");\n } else if (\n permission.data.functions.includes(\n ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR,\n )\n ) {\n throw new SelectorNotAllowed(\"executeWithRuntimeValidation\");\n }\n this.selectors = [...this.selectors, ...permission.data.functions];\n }\n\n this.permissions.push(permission);\n return this;\n }\n\n /**\n * Adds multiple permissions to the permission builder.\n *\n * @param {Permission[]} permissions - The permissions to add.\n * @returns {this} The permission builder instance.\n */\n addPermissions({ permissions }: { permissions: Permission[] }): this {\n // We could validate each permission here, but for simplicity we'll just add them\n // A better approach would be to call addPermission for each one\n permissions.forEach((permission) => {\n this.addPermission({ permission });\n });\n return this;\n }\n\n /**\n * Compiles the deferred action typed data to sign.\n *\n * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionPayload: Hex}>} The deferred action typed data and the full pre-signature deferred action payload.\n */\n async compileDeferred(): Promise<{\n typedData: DeferredActionTypedData;\n fullPreSignatureDeferredActionPayload: Hex;\n }> {\n // Add time range module hook via expiry\n if (this.deadline !== 0) {\n if (this.deadline < Date.now() / 1000) {\n throw new ExpiredDeadlineError(this.deadline, Date.now() / 1000);\n }\n if (this.deadline > maxUint48) {\n throw new DeadlineOverLimitError(this.deadline);\n }\n\n this.hooks.push(\n TimeRangeModule.buildHook(\n {\n entityId: this.validationConfig.entityId,\n validUntil: this.deadline,\n validAfter: 0,\n },\n DefaultModuleAddress.TIME_RANGE,\n ),\n );\n }\n\n const installValidationCall = await this.compileRaw();\n\n const { typedData } = await deferralActions(\n this.client,\n ).createDeferredActionTypedDataObject({\n callData: installValidationCall,\n deadline: this.deadline,\n nonce: this.nonce,\n });\n\n const preSignaturePayload = deferralActions(\n this.client,\n ).buildPreSignatureDeferredActionPayload({ typedData });\n\n // Encode additional information to build the full pre-signature payload\n const fullPreSignatureDeferredActionPayload: `0x${string}` = `0x0${\n this.hasAssociatedExecHooks ? \"1\" : \"0\"\n }${toHex(this.nonce, {\n size: 32,\n }).slice(2)}${preSignaturePayload.slice(2)}`;\n\n return {\n typedData,\n fullPreSignatureDeferredActionPayload,\n };\n }\n\n /**\n * Compiles the raw install arguments for the installValidation function.\n *\n * @returns {Promise<Hex>} The raw install arguments.\n */\n async compileRaw(): Promise<Hex> {\n const account = this.client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n // Translate all permissions into raw hooks if >0\n if (this.permissions.length > 0) {\n const rawHooks = this.translatePermissions(\n this.validationConfig.entityId,\n );\n // Add the translated permissions as hooks\n this.addHooks(rawHooks);\n }\n this.validateConfiguration();\n\n return await installValidationActions(this.client).encodeInstallValidation({\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account,\n });\n }\n\n /**\n * Compiles the install arguments for the installValidation function.\n *\n * @returns {Promise<InstallValidationParams>} The install arguments.\n */\n async compileInstallArgs(): Promise<InstallValidationParams> {\n const account = this.client.account;\n if (!account || !isModularAccountV2(account)) {\n throw new AccountNotFoundError();\n }\n\n this.validateConfiguration();\n\n return {\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account,\n };\n }\n\n private validateConfiguration(): void {\n if (\n this.validationConfig.isGlobal === false &&\n this.selectors.length === 0\n ) {\n throw new ValidationConfigUnsetError();\n }\n }\n\n // Used to translate consolidated permissions into raw unencoded hooks\n // Note entityId will be a member object later\n private translatePermissions(entityId: number): RawHooks {\n const rawHooks: RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.ERC20_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.GAS_LIMIT]: undefined,\n [HookIdentifier.PREVAL_ALLOWLIST]: undefined,\n };\n\n this.permissions.forEach((permission) => {\n switch (permission.type) {\n case PermissionType.NATIVE_TOKEN_TRANSFER:\n // Should never be added twice, check is on addPermission(s) too\n if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] !== undefined) {\n throw new MultipleNativeTokenTransferError(permission);\n }\n rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.allowance),\n },\n };\n this.hasAssociatedExecHooks = true;\n break;\n case PermissionType.ERC20_TOKEN_TRANSFER:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId: entityId + HALF_UINT32,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId: entityId + HALF_UINT32,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: true,\n erc20SpendLimit: BigInt(permission.data.allowance),\n selectors: [],\n },\n ],\n },\n };\n this.hasAssociatedExecHooks = true;\n // Also allow `approve` and `transfer` for the erc20\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [ERC20_APPROVE_SELECTOR, ERC20_TRANSFER_SELECTOR], // approve, transfer\n },\n ],\n },\n };\n break;\n case PermissionType.GAS_LIMIT:\n // Should only ever be added once, check is also on addPermission(s)\n if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {\n throw new MultipleGasLimitError(permission);\n }\n rawHooks[HookIdentifier.GAS_LIMIT] = {\n hookConfig: {\n address: DefaultModuleAddress.NATIVE_TOKEN_LIMIT,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.limit),\n },\n };\n break;\n case PermissionType.CONTRACT_ACCESS:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [],\n },\n ],\n },\n };\n break;\n case PermissionType.ACCOUNT_FUNCTIONS:\n // This is handled in add permissions\n break;\n case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: zeroAddress,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.FUNCTIONS_ON_CONTRACT:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: DefaultModuleAddress.ALLOWLIST,\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.ROOT:\n // Root permission handled in addPermission\n break;\n default:\n return assertNever(permission, \"Unexpected permission type\");\n }\n\n // isGlobal guaranteed to be false since it's only set with root permissions,\n // we must add access to execute & executeBatch if there's a preVal allowlist hook set.\n if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST] !== undefined) {\n const selectorsToAdd: `0x${string}`[] = [\n ACCOUNT_EXECUTE_SELECTOR,\n ACCOUNT_EXECUTEBATCH_SELECTOR,\n ]; // execute, executeBatch\n\n // Only add the selectors if they aren't already in this.selectors\n const newSelectors = selectorsToAdd.filter(\n (selector) => !this.selectors.includes(selector),\n );\n\n this.selectors = [...this.selectors, ...newSelectors];\n }\n });\n\n return rawHooks;\n }\n\n private addHooks(rawHooks: RawHooks) {\n const ntt = rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER];\n if (ntt) {\n this.hooks.push({\n hookConfig: ntt.hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(ntt.initData),\n });\n }\n\n const erc20 = rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER];\n if (erc20) {\n this.hooks.push({\n hookConfig: erc20.hookConfig,\n initData: AllowlistModule.encodeOnInstallData(erc20.initData),\n });\n }\n\n const gl = rawHooks[HookIdentifier.GAS_LIMIT];\n if (gl) {\n this.hooks.push({\n hookConfig: gl.hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(gl.initData),\n });\n }\n\n const allowlist = rawHooks[HookIdentifier.PREVAL_ALLOWLIST];\n if (allowlist) {\n this.hooks.push({\n hookConfig: allowlist.hookConfig,\n initData: AllowlistModule.encodeOnInstallData(allowlist.initData),\n });\n }\n }\n}\n"]}
@@ -13,17 +13,17 @@ export declare const parseDeferredAction: (deferredAction: Hex) => {
13
13
  deferredActionData: Hex;
14
14
  hasAssociatedExecHooks: boolean;
15
15
  };
16
- export type BuildDeferredActionDigestParams = {
17
- fullPreSignatureDeferredActionDigest: Hex;
16
+ export type EncodeDeferredActionWithSignatureParams = {
17
+ fullPreSignatureDeferredActionPayload: Hex;
18
18
  sig: Hex;
19
19
  signaturePrefix?: SignaturePrefix;
20
20
  };
21
21
  /**
22
- * Creates the digest which must be prepended to the userOp signature.
22
+ * Encodes the deferred action with its signature, producing the payload to prepend to the userOp signature.
23
23
  *
24
24
  * Assumption: The client this extends is used to sign the typed data.
25
25
  *
26
- * @param {BuildDeferredActionDigestParams} params - The parameters for building the deferred action digest.
27
- * @returns {Hex} The encoded digest to be prepended to the userOp signature.
26
+ * @param {EncodeDeferredActionWithSignatureParams} params - The parameters for encoding the deferred action with its signature.
27
+ * @returns {Hex} The encoded payload to be prepended to the userOp signature.
28
28
  */
29
- export declare const buildDeferredActionDigest: ({ fullPreSignatureDeferredActionDigest, sig, }: BuildDeferredActionDigestParams) => Hex;
29
+ export declare const encodeDeferredActionWithSignature: ({ fullPreSignatureDeferredActionPayload, sig, }: EncodeDeferredActionWithSignatureParams) => Hex;
@@ -17,19 +17,19 @@ export const parseDeferredAction = (deferredAction) => {
17
17
  };
18
18
  };
19
19
  /**
20
- * Creates the digest which must be prepended to the userOp signature.
20
+ * Encodes the deferred action with its signature, producing the payload to prepend to the userOp signature.
21
21
  *
22
22
  * Assumption: The client this extends is used to sign the typed data.
23
23
  *
24
- * @param {BuildDeferredActionDigestParams} params - The parameters for building the deferred action digest.
25
- * @returns {Hex} The encoded digest to be prepended to the userOp signature.
24
+ * @param {EncodeDeferredActionWithSignatureParams} params - The parameters for encoding the deferred action with its signature.
25
+ * @returns {Hex} The encoded payload to be prepended to the userOp signature.
26
26
  */
27
- export const buildDeferredActionDigest = ({ fullPreSignatureDeferredActionDigest, sig, }) => {
27
+ export const encodeDeferredActionWithSignature = ({ fullPreSignatureDeferredActionPayload, sig, }) => {
28
28
  // 6492 sigs don't work here.
29
29
  const _sig = parseErc6492Signature(sig).signature;
30
30
  const sigLength = size(_sig);
31
31
  const encodedData = concatHex([
32
- fullPreSignatureDeferredActionDigest,
32
+ fullPreSignatureDeferredActionPayload,
33
33
  toHex(sigLength, { size: 4 }),
34
34
  _sig,
35
35
  ]);
@@ -1 +1 @@
1
- {"version":3,"file":"deferredActions.js","sourceRoot":"","sources":["../../../../src/ma-v2/utils/deferredActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,qBAAqB,EACrB,IAAI,EACJ,KAAK,GAEN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,cAAmB,EAOnB,EAAE;IACF,2GAA2G;IAC3G,OAAO;QACL,QAAQ,EAAE,WAAW,CAAC,KAAK,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QAC1D,kBAAkB,EAChB,WAAW,CAAC,KAAK,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;QAC5D,KAAK,EAAE,MAAM,CAAC,KAAK,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;QACjD,kBAAkB,EAAE,KAAK,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,EAAS;QAC1D,sBAAsB,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,GAAG;KAClD,CAAC;AACJ,CAAC,CAAC;AAQF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CAAC,EACxC,oCAAoC,EACpC,GAAG,GAC6B,EAAO,EAAE;IACzC,6BAA6B;IAC7B,MAAM,IAAI,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC;IAElD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7B,MAAM,WAAW,GAAG,SAAS,CAAC;QAC5B,oCAAoC;QACpC,KAAK,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAC7B,IAAI;KACL,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC","sourcesContent":["import {\n concatHex,\n hexToNumber,\n parseErc6492Signature,\n size,\n toHex,\n type Hex,\n} from \"viem\";\nimport { SignaturePrefix } from \"../types.js\";\n\n/**\n * Parses out the 3 components from a deferred action.\n *\n * @param {Hex} deferredAction - The deferred action to parse.\n * @returns {object} The parsed deferred action.\n */\nexport const parseDeferredAction = (\n deferredAction: Hex,\n): {\n entityId: number;\n isGlobalValidation: boolean;\n nonce: bigint;\n deferredActionData: Hex;\n hasAssociatedExecHooks: boolean;\n} => {\n // 2 for 0x, 2 for 00/01, 38 for parallel nonce, 8 for entity id, 2 for options byte, 16 for parallel nonce\n return {\n entityId: hexToNumber(`0x${deferredAction.slice(42, 50)}`),\n isGlobalValidation:\n hexToNumber(`0x${deferredAction.slice(50, 52)}`) % 2 === 1,\n nonce: BigInt(`0x${deferredAction.slice(4, 68)}`),\n deferredActionData: `0x${deferredAction.slice(68)}` as Hex,\n hasAssociatedExecHooks: deferredAction[3] === \"1\",\n };\n};\n\nexport type BuildDeferredActionDigestParams = {\n fullPreSignatureDeferredActionDigest: Hex;\n sig: Hex;\n signaturePrefix?: SignaturePrefix;\n};\n\n/**\n * Creates the digest which must be prepended to the userOp signature.\n *\n * Assumption: The client this extends is used to sign the typed data.\n *\n * @param {BuildDeferredActionDigestParams} params - The parameters for building the deferred action digest.\n * @returns {Hex} The encoded digest to be prepended to the userOp signature.\n */\nexport const buildDeferredActionDigest = ({\n fullPreSignatureDeferredActionDigest,\n sig,\n}: BuildDeferredActionDigestParams): Hex => {\n // 6492 sigs don't work here.\n const _sig = parseErc6492Signature(sig).signature;\n\n const sigLength = size(_sig);\n\n const encodedData = concatHex([\n fullPreSignatureDeferredActionDigest,\n toHex(sigLength, { size: 4 }),\n _sig,\n ]);\n return encodedData;\n};\n"]}
1
+ {"version":3,"file":"deferredActions.js","sourceRoot":"","sources":["../../../../src/ma-v2/utils/deferredActions.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,WAAW,EACX,qBAAqB,EACrB,IAAI,EACJ,KAAK,GAEN,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,cAAmB,EAOnB,EAAE;IACF,2GAA2G;IAC3G,OAAO;QACL,QAAQ,EAAE,WAAW,CAAC,KAAK,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC;QAC1D,kBAAkB,EAChB,WAAW,CAAC,KAAK,cAAc,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC;QAC5D,KAAK,EAAE,MAAM,CAAC,KAAK,cAAc,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC;QACjD,kBAAkB,EAAE,KAAK,cAAc,CAAC,KAAK,CAAC,EAAE,CAAC,EAAS;QAC1D,sBAAsB,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,GAAG;KAClD,CAAC;AACJ,CAAC,CAAC;AAQF;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iCAAiC,GAAG,CAAC,EAChD,qCAAqC,EACrC,GAAG,GACqC,EAAO,EAAE;IACjD,6BAA6B;IAC7B,MAAM,IAAI,GAAG,qBAAqB,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC;IAElD,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,CAAC;IAE7B,MAAM,WAAW,GAAG,SAAS,CAAC;QAC5B,qCAAqC;QACrC,KAAK,CAAC,SAAS,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAC7B,IAAI;KACL,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC","sourcesContent":["import {\n concatHex,\n hexToNumber,\n parseErc6492Signature,\n size,\n toHex,\n type Hex,\n} from \"viem\";\nimport { SignaturePrefix } from \"../types.js\";\n\n/**\n * Parses out the 3 components from a deferred action.\n *\n * @param {Hex} deferredAction - The deferred action to parse.\n * @returns {object} The parsed deferred action.\n */\nexport const parseDeferredAction = (\n deferredAction: Hex,\n): {\n entityId: number;\n isGlobalValidation: boolean;\n nonce: bigint;\n deferredActionData: Hex;\n hasAssociatedExecHooks: boolean;\n} => {\n // 2 for 0x, 2 for 00/01, 38 for parallel nonce, 8 for entity id, 2 for options byte, 16 for parallel nonce\n return {\n entityId: hexToNumber(`0x${deferredAction.slice(42, 50)}`),\n isGlobalValidation:\n hexToNumber(`0x${deferredAction.slice(50, 52)}`) % 2 === 1,\n nonce: BigInt(`0x${deferredAction.slice(4, 68)}`),\n deferredActionData: `0x${deferredAction.slice(68)}` as Hex,\n hasAssociatedExecHooks: deferredAction[3] === \"1\",\n };\n};\n\nexport type EncodeDeferredActionWithSignatureParams = {\n fullPreSignatureDeferredActionPayload: Hex;\n sig: Hex;\n signaturePrefix?: SignaturePrefix;\n};\n\n/**\n * Encodes the deferred action with its signature, producing the payload to prepend to the userOp signature.\n *\n * Assumption: The client this extends is used to sign the typed data.\n *\n * @param {EncodeDeferredActionWithSignatureParams} params - The parameters for encoding the deferred action with its signature.\n * @returns {Hex} The encoded payload to be prepended to the userOp signature.\n */\nexport const encodeDeferredActionWithSignature = ({\n fullPreSignatureDeferredActionPayload,\n sig,\n}: EncodeDeferredActionWithSignatureParams): Hex => {\n // 6492 sigs don't work here.\n const _sig = parseErc6492Signature(sig).signature;\n\n const sigLength = size(_sig);\n\n const encodedData = concatHex([\n fullPreSignatureDeferredActionPayload,\n toHex(sigLength, { size: 4 }),\n _sig,\n ]);\n return encodedData;\n};\n"]}
@@ -1 +1 @@
1
- export declare const VERSION = "5.0.0-beta.21";
1
+ export declare const VERSION = "5.0.0-beta.23";
@@ -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 = "5.0.0-beta.21";
3
+ export const VERSION = "5.0.0-beta.23";
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,eAAe,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"5.0.0-beta.21\";\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,yBAAyB;AACzB,MAAM,CAAC,MAAM,OAAO,GAAG,eAAe,CAAC","sourcesContent":["// This file is autogenerated by inject-version.ts. Any changes will be\n// overwritten on commit!\nexport const VERSION = \"5.0.0-beta.23\";\n"]}
@@ -43,7 +43,7 @@ export type * from "./ma-v2/types.js";
43
43
  export type * from "./ma-v2/utils/account.js";
44
44
  export { DefaultAddress, DefaultModuleAddress, DEFAULT_OWNER_ENTITY_ID, EXECUTE_USER_OP_SELECTOR, getMAV2UpgradeToData, buildFullNonceKey, serializeModuleEntity, isModularAccountV2, } from "./ma-v2/utils/account.js";
45
45
  export type * from "./ma-v2/utils/deferredActions.js";
46
- export { parseDeferredAction, buildDeferredActionDigest, } from "./ma-v2/utils/deferredActions.js";
46
+ export { parseDeferredAction, encodeDeferredActionWithSignature, } from "./ma-v2/utils/deferredActions.js";
47
47
  export type * from "./ma-v2/utils/hooks.js";
48
48
  export { serializeValidationConfig, serializeHookConfig, } from "./ma-v2/utils/hooks.js";
49
49
  export type * from "./ma-v2/utils/signature.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,YAAY,CAAC;AAGhC,mBAAmB,qCAAqC,CAAC;AACzD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAErE,mBAAmB,iDAAiD,CAAC;AACrE,OAAO,EAAE,wBAAwB,EAAE,MAAM,iDAAiD,CAAC;AAE3F,mBAAmB,mCAAmC,CAAC;AACvD,OAAO,EACL,0BAA0B,EAC1B,oCAAoC,GACrC,MAAM,mCAAmC,CAAC;AAE3C,OAAO,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AACrE,mBAAmB,6BAA6B,CAAC;AACjD,OAAO,EACL,0BAA0B,EAC1B,0BAA0B,EAC1B,oCAAoC,EACpC,gCAAgC,GACjC,MAAM,0BAA0B,CAAC;AAElC,OAAO,EACL,aAAa,EACb,aAAa,GACd,MAAM,2CAA2C,CAAC;AAEnD,OAAO,E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,MAAM,wBAAwB,CAAC;AAEhC,mBAAmB,4BAA4B,CAAC;AAChD,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAGpC,OAAO,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAC1E,OAAO,EAAE,+BAA+B,EAAE,MAAM,6CAA6C,CAAC;AAC9F,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,kCAAkC,CAAC;AACxE,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAClE,OAAO,EACL,sBAAsB,EACtB,uBAAuB,EACvB,2BAA2B,EAC3B,2BAA2B,EAC3B,wBAAwB,EACxB,oBAAoB,EACpB,sBAAsB,EACtB,0BAA0B,EAC1B,gCAAgC,EAChC,gBAAgB,EAChB,qBAAqB,EACrB,8BAA8B,EAC9B,kBAAkB,GACnB,MAAM,qCAAqC,CAAC"}
@@ -30,6 +30,45 @@ export type ToModularAccountV2Params<TMode extends Mode | undefined = Mode | und
30
30
  *
31
31
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
32
32
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { createPublicClient } from "viem";
37
+ * import { createBundlerClient, createPaymasterClient } from "viem/account-abstraction";
38
+ * import { sepolia } from "viem/chains";
39
+ * import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
40
+ * import { alchemyTransport } from "@alchemy/common";
41
+ * import { estimateFeesPerGas } from "@alchemy/aa-infra";
42
+ * import { toModularAccountV2 } from "@alchemy/smart-accounts";
43
+ *
44
+ * const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });
45
+ *
46
+ * // 1. Create a MAv2 smart account
47
+ * const account = await toModularAccountV2({
48
+ * client: createPublicClient({ chain: sepolia, transport }),
49
+ * owner: privateKeyToAccount(generatePrivateKey()),
50
+ * });
51
+ *
52
+ * // 2. Create a bundler client with the account
53
+ * const bundlerClient = createBundlerClient({
54
+ * account,
55
+ * chain: sepolia,
56
+ * transport,
57
+ * userOperation: {
58
+ * estimateFeesPerGas,
59
+ * },
60
+ * // Optional: sponsor gas with a paymaster
61
+ * paymaster: createPaymasterClient({ transport }),
62
+ * paymasterContext: { policyId: "YOUR_POLICY_ID" },
63
+ * });
64
+ *
65
+ * // 3. Send a user operation
66
+ * const hash = await bundlerClient.sendUserOperation({
67
+ * calls: [{ to: "0x...", value: 0n, data: "0x" }],
68
+ * });
69
+ *
70
+ * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
71
+ * ```
33
72
  */
34
73
  export declare function toModularAccountV2<TMode extends Mode = Mode>({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt, factory, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }: ToModularAccountV2Params<TMode>): Promise<ModularAccountV2>;
35
74
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"account.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,cAAc,EACnB,KAAK,YAAY,EAEjB,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAKd,OAAO,EAA0B,KAAK,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAC9E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAWhD,KAAK,IAAI,GAAG,SAAS,GAAG,MAAM,CAAC;AAG/B,MAAM,MAAM,gBAAgB,GAAG,oBAAoB,GAAG,EAAE,CAAC;AAEzD,MAAM,MAAM,wBAAwB,CAClC,KAAK,SAAS,IAAI,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,IAC/C;IACF,MAAM,EAAE,MAAM,CAAC,SAAS,EAAE,KAAK,EAAE,cAAc,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,cAAc,EACd,YAAY,EACZ,cAAc,EAAE,eAAe,EAC/B,IAAS,EACT,OAAO,EACP,WAAW,EAAE,YAAY,EACzB,qBAAqB,EAAE,sBAAsB,EAC7C,IAAI,GACL,EAAE,wBAAwB,CAAC,KAAK,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC,CAsH7D"}
@@ -25,7 +25,7 @@ export type CreateDeferredActionTypedDataParams = {
25
25
  deadline: number;
26
26
  nonce: bigint;
27
27
  };
28
- export type BuildPreSignatureDeferredActionDigestParams = {
28
+ export type BuildPreSignatureDeferredActionPayloadParams = {
29
29
  typedData: DeferredActionTypedData;
30
30
  };
31
31
  export type EntityIdAndNonceParams = {
@@ -36,7 +36,7 @@ export type EntityIdAndNonceParams = {
36
36
  };
37
37
  export type DeferralActions = {
38
38
  createDeferredActionTypedDataObject: (args: CreateDeferredActionTypedDataParams) => Promise<DeferredActionReturnData>;
39
- buildPreSignatureDeferredActionDigest: (args: BuildPreSignatureDeferredActionDigestParams) => Hex;
39
+ buildPreSignatureDeferredActionPayload: (args: BuildPreSignatureDeferredActionPayloadParams) => Hex;
40
40
  getEntityIdAndNonce: (args: EntityIdAndNonceParams) => Promise<{
41
41
  nonce: bigint;
42
42
  entityId: number;
@@ -46,7 +46,7 @@ export type DeferralActions = {
46
46
  * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
47
47
  *
48
48
  * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
49
- * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
49
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildPreSignatureDeferredActionPayload`, and `buildUserOperationWithDeferredAction`.
50
50
  */
51
51
  export declare const deferralActions: <TTransport extends Transport = Transport, TChain extends Chain = Chain, TAccount extends SmartAccount = SmartAccount>(client: Client<TTransport, TChain, TAccount>) => DeferralActions;
52
52
  //# sourceMappingURL=deferralActions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deferralActions.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/decorators/deferralActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,GAAG,EACR,KAAK,MAAM,EACX,KAAK,KAAK,EACV,KAAK,SAAS,EAQd,KAAK,mBAAmB,EACzB,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAQ7D,eAAO,MAAM,mCAAmC,y+EACw7E,CAAC;AAEz+E,MAAM,MAAM,uBAAuB,GAAG,mBAAmB,CACvD;IACE,cAAc,EAAE;QACd;YAAE,IAAI,EAAE,OAAO,CAAC;YAAC,IAAI,EAAE,SAAS,CAAA;SAAE;QAClC;YAAE,IAAI,EAAE,UAAU,CAAC;YAAC,IAAI,EAAE,QAAQ,CAAA;SAAE;QACpC;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,IAAI,EAAE,OAAO,CAAA;SAAE;KAChC,CAAC;CACH,EACD,gBAAgB,CACjB,CAAC;AAEF,MAAM,MAAM,wBAAwB,GAAG;IACrC,SAAS,EAAE,uBAAuB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,mCAAmC,GAAG;IAChD,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,2CAA2C,GAAG;IACxD,SAAS,EAAE,uBAAuB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,mCAAmC,EAAE,CACnC,IAAI,EAAE,mCAAmC,KAC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CAAmC,GAAG;IAChD,QAAQ,EAAE,GAAG,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAEF,MAAM,MAAM,4CAA4C,GAAG;IACzD,SAAS,EAAE,uBAAuB,CAAC;CACpC,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,OAAO,CAAC;CAC5B,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,mCAAmC,EAAE,CACnC,IAAI,EAAE,mCAAmC,KACtC,OAAO,CAAC,wBAAwB,CAAC,CAAC;IACvC,sCAAsC,EAAE,CACtC,IAAI,EAAE,4CAA4C,KAC/C,GAAG,CAAC;IACT,mBAAmB,EAAE,CACnB,IAAI,EAAE,sBAAsB,KACzB,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,eAAe,GAC1B,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,MAAM,SAAS,KAAK,GAAG,KAAK,EAC5B,QAAQ,SAAS,YAAY,GAAG,YAAY,EAE5C,QAAQ,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,KAC3C,eA8GF,CAAC"}
@@ -133,11 +133,11 @@ export declare class PermissionBuilder {
133
133
  /**
134
134
  * Compiles the deferred action typed data to sign.
135
135
  *
136
- * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionDigest: Hex}>} The deferred action typed data and the full pre-signature deferred action digest.
136
+ * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionPayload: Hex}>} The deferred action typed data and the full pre-signature deferred action payload.
137
137
  */
138
138
  compileDeferred(): Promise<{
139
139
  typedData: DeferredActionTypedData;
140
- fullPreSignatureDeferredActionDigest: Hex;
140
+ fullPreSignatureDeferredActionPayload: Hex;
141
141
  }>;
142
142
  /**
143
143
  * Compiles the raw install arguments for the installValidation function.
@@ -1 +1 @@
1
- {"version":3,"file":"permissionBuilder.d.ts","sourceRoot":"","sources":["../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AAKd,OAAO,EAAY,KAAK,UAAU,EAAyB,MAAM,YAAY,CAAC;AAC9E,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,iCAAiC,CAAC;AACzC,OAAO,EAEL,KAAK,uBAAuB,EAC7B,MAAM,mCAAmC,CAAC;AAe3C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAU7D;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;;;;;CAajB,CAAC;AAGX,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAEvD;;GAEG;AACH,eAAO,MAAM,cAAc;;;;;CAKjB,CAAC;AAGX,MAAM,MAAM,cAAc,GACxB,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,OAAO,cAAc,CAAC,CAAC;AAsEvD,KAAK,GAAG,GAAG;IACT,SAAS,EAAE,GAAG,CAAC;IACf,IAAI,EAAE,WAAW,GAAG,UAAU,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,UAAU,GAClB;IAEE,IAAI,EAAE,OAAO,cAAc,CAAC,qBAAqB,CAAC;IAClD,IAAI,EAAE;QACJ,SAAS,EAAE,GAAG,CAAC;KAChB,CAAC;CACH,GACD;IAEE,IAAI,EAAE,OAAO,cAAc,CAAC,oBAAoB,CAAC;IAC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AAG,EAAE,CAAC;QAClB,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC;QACf,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB;IAwBD;;;;;OAKG;IACH,WAAW,CAAC,EAAE,QAAQ,EAAE,EAAE;QAAE,QAAQ,EAAE,GAAG,CAAA;KAAE,GAAG,IAAI;IAWlD;;;;;OAKG;IACH,aAAa,CAAC,EAAE,UAAU,EAAE,EAAE;QAAE,UAAU,EAAE,UAAU,CAAA;KAAE,GAAG,IAAI;IA6E/D;;;;;OAKG;IACH,cAAc,CAAC,EAAE,WAAW,EAAE,EAAE;QAAE,WAAW,EAAE,UAAU,EAAE,CAAA;KAAE,GAAG,IAAI;IASpE;;;;OAIG;IACG,eAAe,IAAI,OAAO,CAAC;QAC/B,SAAS,EAAE,uBAAuB,CAAC;QACnC,qCAAqC,EAAE,GAAG,CAAC;KAC5C,CAAC;IAiDF;;;;OAIG;IACG,UAAU,IAAI,OAAO,CAAC,GAAG,CAAC;IAyBhC;;;;OAIG;IACG,kBAAkB,IAAI,OAAO,CAAC,uBAAuB,CAAC;IAiB5D,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,oBAAoB;IAgO5B,OAAO,CAAC,QAAQ;CAiCjB"}
@@ -13,18 +13,18 @@ export declare const parseDeferredAction: (deferredAction: Hex) => {
13
13
  deferredActionData: Hex;
14
14
  hasAssociatedExecHooks: boolean;
15
15
  };
16
- export type BuildDeferredActionDigestParams = {
17
- fullPreSignatureDeferredActionDigest: Hex;
16
+ export type EncodeDeferredActionWithSignatureParams = {
17
+ fullPreSignatureDeferredActionPayload: Hex;
18
18
  sig: Hex;
19
19
  signaturePrefix?: SignaturePrefix;
20
20
  };
21
21
  /**
22
- * Creates the digest which must be prepended to the userOp signature.
22
+ * Encodes the deferred action with its signature, producing the payload to prepend to the userOp signature.
23
23
  *
24
24
  * Assumption: The client this extends is used to sign the typed data.
25
25
  *
26
- * @param {BuildDeferredActionDigestParams} params - The parameters for building the deferred action digest.
27
- * @returns {Hex} The encoded digest to be prepended to the userOp signature.
26
+ * @param {EncodeDeferredActionWithSignatureParams} params - The parameters for encoding the deferred action with its signature.
27
+ * @returns {Hex} The encoded payload to be prepended to the userOp signature.
28
28
  */
29
- export declare const buildDeferredActionDigest: ({ fullPreSignatureDeferredActionDigest, sig, }: BuildDeferredActionDigestParams) => Hex;
29
+ export declare const encodeDeferredActionWithSignature: ({ fullPreSignatureDeferredActionPayload, sig, }: EncodeDeferredActionWithSignatureParams) => Hex;
30
30
  //# sourceMappingURL=deferredActions.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deferredActions.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/utils/deferredActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,GAAG,EACT,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,gBAAgB,GAAG,KAClB;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB,EAAE,GAAG,CAAC;IACxB,sBAAsB,EAAE,OAAO,CAAC;CAWjC,CAAC;AAEF,MAAM,MAAM,+BAA+B,GAAG;IAC5C,oCAAoC,EAAE,GAAG,CAAC;IAC1C,GAAG,EAAE,GAAG,CAAC;IACT,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,yBAAyB,GAAI,gDAGvC,+BAA+B,KAAG,GAYpC,CAAC"}
1
+ {"version":3,"file":"deferredActions.d.ts","sourceRoot":"","sources":["../../../../src/ma-v2/utils/deferredActions.ts"],"names":[],"mappings":"AAAA,OAAO,EAML,KAAK,GAAG,EACT,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,GAC9B,gBAAgB,GAAG,KAClB;IACD,QAAQ,EAAE,MAAM,CAAC;IACjB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,KAAK,EAAE,MAAM,CAAC;IACd,kBAAkB,EAAE,GAAG,CAAC;IACxB,sBAAsB,EAAE,OAAO,CAAC;CAWjC,CAAC;AAEF,MAAM,MAAM,uCAAuC,GAAG;IACpD,qCAAqC,EAAE,GAAG,CAAC;IAC3C,GAAG,EAAE,GAAG,CAAC;IACT,eAAe,CAAC,EAAE,eAAe,CAAC;CACnC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,iCAAiC,GAAI,iDAG/C,uCAAuC,KAAG,GAY5C,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "5.0.0-beta.21";
1
+ export declare const VERSION = "5.0.0-beta.23";
2
2
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alchemy/smart-accounts",
3
- "version": "5.0.0-beta.22",
3
+ "version": "5.0.0-beta.24",
4
4
  "description": "This package contains all of the viem interfaces for Alchemy's Smart Contract Accounts",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -39,12 +39,12 @@
39
39
  "test:run": "vitest run"
40
40
  },
41
41
  "devDependencies": {
42
- "@alchemy/aa-infra": "5.0.0-beta.22",
42
+ "@alchemy/aa-infra": "5.0.0-beta.24",
43
43
  "typescript-template": "workspace:*",
44
44
  "viem": "^2.45.0"
45
45
  },
46
46
  "dependencies": {
47
- "@alchemy/common": "5.0.0-beta.22"
47
+ "@alchemy/common": "5.0.0-beta.24"
48
48
  },
49
49
  "peerDependencies": {
50
50
  "viem": "^2.45.0"
@@ -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": "cd83c2c18bd4de73dfbf56cef2516a4e45ef31ba"
64
+ "gitHead": "f30a06d06c9601f55681307c331b690d51978af9"
65
65
  }
package/src/index.ts CHANGED
@@ -114,7 +114,7 @@ export {
114
114
  export type * from "./ma-v2/utils/deferredActions.js";
115
115
  export {
116
116
  parseDeferredAction,
117
- buildDeferredActionDigest,
117
+ encodeDeferredActionWithSignature,
118
118
  } from "./ma-v2/utils/deferredActions.js";
119
119
 
120
120
  export type * from "./ma-v2/utils/hooks.js";
@@ -65,6 +65,45 @@ export type ToModularAccountV2Params<
65
65
  *
66
66
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
67
67
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
68
+ *
69
+ * @example
70
+ * ```ts
71
+ * import { createPublicClient } from "viem";
72
+ * import { createBundlerClient, createPaymasterClient } from "viem/account-abstraction";
73
+ * import { sepolia } from "viem/chains";
74
+ * import { generatePrivateKey, privateKeyToAccount } from "viem/accounts";
75
+ * import { alchemyTransport } from "@alchemy/common";
76
+ * import { estimateFeesPerGas } from "@alchemy/aa-infra";
77
+ * import { toModularAccountV2 } from "@alchemy/smart-accounts";
78
+ *
79
+ * const transport = alchemyTransport({ apiKey: "YOUR_API_KEY" });
80
+ *
81
+ * // 1. Create a MAv2 smart account
82
+ * const account = await toModularAccountV2({
83
+ * client: createPublicClient({ chain: sepolia, transport }),
84
+ * owner: privateKeyToAccount(generatePrivateKey()),
85
+ * });
86
+ *
87
+ * // 2. Create a bundler client with the account
88
+ * const bundlerClient = createBundlerClient({
89
+ * account,
90
+ * chain: sepolia,
91
+ * transport,
92
+ * userOperation: {
93
+ * estimateFeesPerGas,
94
+ * },
95
+ * // Optional: sponsor gas with a paymaster
96
+ * paymaster: createPaymasterClient({ transport }),
97
+ * paymasterContext: { policyId: "YOUR_POLICY_ID" },
98
+ * });
99
+ *
100
+ * // 3. Send a user operation
101
+ * const hash = await bundlerClient.sendUserOperation({
102
+ * calls: [{ to: "0x...", value: 0n, data: "0x" }],
103
+ * });
104
+ *
105
+ * const receipt = await bundlerClient.waitForUserOperationReceipt({ hash });
106
+ * ```
68
107
  */
69
108
  export async function toModularAccountV2<TMode extends Mode = Mode>({
70
109
  client,
@@ -45,7 +45,7 @@ export type CreateDeferredActionTypedDataParams = {
45
45
  nonce: bigint;
46
46
  };
47
47
 
48
- export type BuildPreSignatureDeferredActionDigestParams = {
48
+ export type BuildPreSignatureDeferredActionPayloadParams = {
49
49
  typedData: DeferredActionTypedData;
50
50
  };
51
51
 
@@ -60,8 +60,8 @@ export type DeferralActions = {
60
60
  createDeferredActionTypedDataObject: (
61
61
  args: CreateDeferredActionTypedDataParams,
62
62
  ) => Promise<DeferredActionReturnData>;
63
- buildPreSignatureDeferredActionDigest: (
64
- args: BuildPreSignatureDeferredActionDigestParams,
63
+ buildPreSignatureDeferredActionPayload: (
64
+ args: BuildPreSignatureDeferredActionPayloadParams,
65
65
  ) => Hex;
66
66
  getEntityIdAndNonce: (
67
67
  args: EntityIdAndNonceParams,
@@ -72,7 +72,7 @@ export type DeferralActions = {
72
72
  * Provides deferred action functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
73
73
  *
74
74
  * @param {ModularAccountV2Client} client - The client instance which provides account and sendUserOperation functionality.
75
- * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildDeferredActionDigest`, and `buildUserOperationWithDeferredAction`.
75
+ * @returns {object} - An object containing three methods: `createDeferredActionTypedDataObject`, `buildPreSignatureDeferredActionPayload`, and `buildUserOperationWithDeferredAction`.
76
76
  */
77
77
  export const deferralActions = <
78
78
  TTransport extends Transport = Transport,
@@ -114,9 +114,9 @@ export const deferralActions = <
114
114
  };
115
115
  };
116
116
 
117
- const buildPreSignatureDeferredActionDigest = ({
117
+ const buildPreSignatureDeferredActionPayload = ({
118
118
  typedData,
119
- }: BuildPreSignatureDeferredActionDigestParams): Hex => {
119
+ }: BuildPreSignatureDeferredActionPayloadParams): Hex => {
120
120
  const account = client.account;
121
121
  if (!account || !isModularAccountV2(account)) {
122
122
  throw new AccountNotFoundError();
@@ -187,7 +187,7 @@ export const deferralActions = <
187
187
 
188
188
  return {
189
189
  createDeferredActionTypedDataObject,
190
- buildPreSignatureDeferredActionDigest,
190
+ buildPreSignatureDeferredActionPayload,
191
191
  getEntityIdAndNonce,
192
192
  };
193
193
  };
@@ -44,6 +44,8 @@ const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
44
44
  const ERC20_TRANSFER_SELECTOR = "0xa9059cbb";
45
45
  const ACCOUNT_EXECUTE_SELECTOR = "0xb61d27f6";
46
46
  const ACCOUNT_EXECUTEBATCH_SELECTOR = "0x34fcd5be";
47
+ const ACCOUNT_PERFORM_CREATE_SELECTOR = "0x5998db5c";
48
+ const ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR = "0xf2680c0f";
47
49
 
48
50
  /**
49
51
  * A pseudo-enum for permission types.
@@ -289,6 +291,12 @@ export class PermissionBuilder {
289
291
  * @returns {this} The permission builder instance.
290
292
  */
291
293
  addSelector({ selector }: { selector: Hex }): this {
294
+ if (selector === ACCOUNT_PERFORM_CREATE_SELECTOR) {
295
+ throw new SelectorNotAllowed("performCreate");
296
+ }
297
+ if (selector === ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR) {
298
+ throw new SelectorNotAllowed("executeWithRuntimeValidation");
299
+ }
292
300
  this.selectors.push(selector);
293
301
  return this;
294
302
  }
@@ -351,13 +359,23 @@ export class PermissionBuilder {
351
359
  if (permission.data.functions.length === 0) {
352
360
  throw new NoFunctionsProvidedError(permission);
353
361
  }
354
- // Explicitly disallow adding execute & executeBatch
362
+ // Explicitly disallow adding execute, executeBatch, performCreate, and executeWithRuntimeValidation
355
363
  if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {
356
364
  throw new SelectorNotAllowed("execute");
357
365
  } else if (
358
366
  permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)
359
367
  ) {
360
368
  throw new SelectorNotAllowed("executeBatch");
369
+ } else if (
370
+ permission.data.functions.includes(ACCOUNT_PERFORM_CREATE_SELECTOR)
371
+ ) {
372
+ throw new SelectorNotAllowed("performCreate");
373
+ } else if (
374
+ permission.data.functions.includes(
375
+ ACCOUNT_EXECUTE_WITH_RUNTIME_VALIDATION_SELECTOR,
376
+ )
377
+ ) {
378
+ throw new SelectorNotAllowed("executeWithRuntimeValidation");
361
379
  }
362
380
  this.selectors = [...this.selectors, ...permission.data.functions];
363
381
  }
@@ -384,11 +402,11 @@ export class PermissionBuilder {
384
402
  /**
385
403
  * Compiles the deferred action typed data to sign.
386
404
  *
387
- * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionDigest: Hex}>} The deferred action typed data and the full pre-signature deferred action digest.
405
+ * @returns {Promise<{typedData: DeferredActionTypedData, fullPreSignatureDeferredActionPayload: Hex}>} The deferred action typed data and the full pre-signature deferred action payload.
388
406
  */
389
407
  async compileDeferred(): Promise<{
390
408
  typedData: DeferredActionTypedData;
391
- fullPreSignatureDeferredActionDigest: Hex;
409
+ fullPreSignatureDeferredActionPayload: Hex;
392
410
  }> {
393
411
  // Add time range module hook via expiry
394
412
  if (this.deadline !== 0) {
@@ -421,20 +439,20 @@ export class PermissionBuilder {
421
439
  nonce: this.nonce,
422
440
  });
423
441
 
424
- const preSignatureDigest = deferralActions(
442
+ const preSignaturePayload = deferralActions(
425
443
  this.client,
426
- ).buildPreSignatureDeferredActionDigest({ typedData });
444
+ ).buildPreSignatureDeferredActionPayload({ typedData });
427
445
 
428
- // Encode additional information to build the full pre-signature digest
429
- const fullPreSignatureDeferredActionDigest: `0x${string}` = `0x0${
446
+ // Encode additional information to build the full pre-signature payload
447
+ const fullPreSignatureDeferredActionPayload: `0x${string}` = `0x0${
430
448
  this.hasAssociatedExecHooks ? "1" : "0"
431
449
  }${toHex(this.nonce, {
432
450
  size: 32,
433
- }).slice(2)}${preSignatureDigest.slice(2)}`;
451
+ }).slice(2)}${preSignaturePayload.slice(2)}`;
434
452
 
435
453
  return {
436
454
  typedData,
437
- fullPreSignatureDeferredActionDigest,
455
+ fullPreSignatureDeferredActionPayload,
438
456
  };
439
457
  }
440
458
 
@@ -34,31 +34,31 @@ export const parseDeferredAction = (
34
34
  };
35
35
  };
36
36
 
37
- export type BuildDeferredActionDigestParams = {
38
- fullPreSignatureDeferredActionDigest: Hex;
37
+ export type EncodeDeferredActionWithSignatureParams = {
38
+ fullPreSignatureDeferredActionPayload: Hex;
39
39
  sig: Hex;
40
40
  signaturePrefix?: SignaturePrefix;
41
41
  };
42
42
 
43
43
  /**
44
- * Creates the digest which must be prepended to the userOp signature.
44
+ * Encodes the deferred action with its signature, producing the payload to prepend to the userOp signature.
45
45
  *
46
46
  * Assumption: The client this extends is used to sign the typed data.
47
47
  *
48
- * @param {BuildDeferredActionDigestParams} params - The parameters for building the deferred action digest.
49
- * @returns {Hex} The encoded digest to be prepended to the userOp signature.
48
+ * @param {EncodeDeferredActionWithSignatureParams} params - The parameters for encoding the deferred action with its signature.
49
+ * @returns {Hex} The encoded payload to be prepended to the userOp signature.
50
50
  */
51
- export const buildDeferredActionDigest = ({
52
- fullPreSignatureDeferredActionDigest,
51
+ export const encodeDeferredActionWithSignature = ({
52
+ fullPreSignatureDeferredActionPayload,
53
53
  sig,
54
- }: BuildDeferredActionDigestParams): Hex => {
54
+ }: EncodeDeferredActionWithSignatureParams): Hex => {
55
55
  // 6492 sigs don't work here.
56
56
  const _sig = parseErc6492Signature(sig).signature;
57
57
 
58
58
  const sigLength = size(_sig);
59
59
 
60
60
  const encodedData = concatHex([
61
- fullPreSignatureDeferredActionDigest,
61
+ fullPreSignatureDeferredActionPayload,
62
62
  toHex(sigLength, { size: 4 }),
63
63
  _sig,
64
64
  ]);
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 = "5.0.0-beta.22";
3
+ export const VERSION = "5.0.0-beta.24";