@alchemy/smart-accounts 0.0.0-alpha.2 → 0.0.0-alpha.21

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 (147) hide show
  1. package/dist/esm/index.d.ts +4 -3
  2. package/dist/esm/index.js +3 -3
  3. package/dist/esm/index.js.map +1 -1
  4. package/dist/esm/light-account/accounts/account.d.ts +9 -4
  5. package/dist/esm/light-account/accounts/account.js +29 -18
  6. package/dist/esm/light-account/accounts/account.js.map +1 -1
  7. package/dist/esm/light-account/accounts/base.d.ts +4 -4
  8. package/dist/esm/light-account/accounts/base.js +51 -24
  9. package/dist/esm/light-account/accounts/base.js.map +1 -1
  10. package/dist/esm/light-account/accounts/multi-owner-account.d.ts +9 -4
  11. package/dist/esm/light-account/accounts/multi-owner-account.js +23 -14
  12. package/dist/esm/light-account/accounts/multi-owner-account.js.map +1 -1
  13. package/dist/esm/light-account/decorators/multiOwner.js +2 -1
  14. package/dist/esm/light-account/decorators/multiOwner.js.map +1 -1
  15. package/dist/esm/light-account/decorators/singleOwner.js +1 -1
  16. package/dist/esm/light-account/decorators/singleOwner.js.map +1 -1
  17. package/dist/esm/light-account/lightAccountStaticImpl.d.ts +3 -1
  18. package/dist/esm/light-account/lightAccountStaticImpl.js +57 -7
  19. package/dist/esm/light-account/lightAccountStaticImpl.js.map +1 -1
  20. package/dist/esm/light-account/predictAddress.d.ts +40 -2
  21. package/dist/esm/light-account/predictAddress.js +83 -3
  22. package/dist/esm/light-account/predictAddress.js.map +1 -1
  23. package/dist/esm/light-account/registry.d.ts +3411 -1
  24. package/dist/esm/light-account/registry.js +33 -1
  25. package/dist/esm/light-account/registry.js.map +1 -1
  26. package/dist/esm/light-account/utils.js +1 -1
  27. package/dist/esm/light-account/utils.js.map +1 -1
  28. package/dist/esm/ma-v1/accounts/base.d.ts +4 -4
  29. package/dist/esm/ma-v1/accounts/base.js +1 -1
  30. package/dist/esm/ma-v1/accounts/base.js.map +1 -1
  31. package/dist/esm/ma-v1/accounts/multi-owner-account.d.ts +9 -4
  32. package/dist/esm/ma-v1/accounts/multi-owner-account.js +26 -14
  33. package/dist/esm/ma-v1/accounts/multi-owner-account.js.map +1 -1
  34. package/dist/esm/ma-v1/decorators/multiOwner.js +2 -1
  35. package/dist/esm/ma-v1/decorators/multiOwner.js.map +1 -1
  36. package/dist/esm/ma-v1/predictAddress.d.ts +20 -1
  37. package/dist/esm/ma-v1/predictAddress.js +37 -1
  38. package/dist/esm/ma-v1/predictAddress.js.map +1 -1
  39. package/dist/esm/ma-v2/accounts/account.d.ts +10 -7
  40. package/dist/esm/ma-v2/accounts/account.js +24 -43
  41. package/dist/esm/ma-v2/accounts/account.js.map +1 -1
  42. package/dist/esm/ma-v2/accounts/base.d.ts +5 -5
  43. package/dist/esm/ma-v2/accounts/base.js +18 -60
  44. package/dist/esm/ma-v2/accounts/base.js.map +1 -1
  45. package/dist/esm/ma-v2/mav2StaticImpl.d.ts +1 -15
  46. package/dist/esm/ma-v2/mav2StaticImpl.js +0 -33
  47. package/dist/esm/ma-v2/mav2StaticImpl.js.map +1 -1
  48. package/dist/esm/ma-v2/predictAddress.d.ts +22 -6
  49. package/dist/esm/ma-v2/predictAddress.js +46 -12
  50. package/dist/esm/ma-v2/predictAddress.js.map +1 -1
  51. package/dist/esm/ma-v2/utils/account.d.ts +0 -3
  52. package/dist/esm/ma-v2/utils/account.js +2 -4
  53. package/dist/esm/ma-v2/utils/account.js.map +1 -1
  54. package/dist/esm/ma-v2/utils/signature.d.ts +1 -12
  55. package/dist/esm/ma-v2/utils/signature.js +1 -34
  56. package/dist/esm/ma-v2/utils/signature.js.map +1 -1
  57. package/dist/esm/types.d.ts +8 -1
  58. package/dist/esm/types.js.map +1 -1
  59. package/dist/esm/utils.d.ts +32 -2
  60. package/dist/esm/utils.js +75 -5
  61. package/dist/esm/utils.js.map +1 -1
  62. package/dist/esm/version.d.ts +1 -1
  63. package/dist/esm/version.js +1 -1
  64. package/dist/esm/version.js.map +1 -1
  65. package/dist/types/index.d.ts +4 -3
  66. package/dist/types/index.d.ts.map +1 -1
  67. package/dist/types/light-account/accounts/account.d.ts +9 -4
  68. package/dist/types/light-account/accounts/account.d.ts.map +1 -1
  69. package/dist/types/light-account/accounts/base.d.ts +4 -4
  70. package/dist/types/light-account/accounts/base.d.ts.map +1 -1
  71. package/dist/types/light-account/accounts/multi-owner-account.d.ts +9 -4
  72. package/dist/types/light-account/accounts/multi-owner-account.d.ts.map +1 -1
  73. package/dist/types/light-account/decorators/multiOwner.d.ts.map +1 -1
  74. package/dist/types/light-account/decorators/singleOwner.d.ts.map +1 -1
  75. package/dist/types/light-account/lightAccountStaticImpl.d.ts +3 -1
  76. package/dist/types/light-account/lightAccountStaticImpl.d.ts.map +1 -1
  77. package/dist/types/light-account/predictAddress.d.ts +40 -2
  78. package/dist/types/light-account/predictAddress.d.ts.map +1 -1
  79. package/dist/types/light-account/registry.d.ts +3411 -1
  80. package/dist/types/light-account/registry.d.ts.map +1 -1
  81. package/dist/types/ma-v1/accounts/base.d.ts +4 -4
  82. package/dist/types/ma-v1/accounts/base.d.ts.map +1 -1
  83. package/dist/types/ma-v1/accounts/multi-owner-account.d.ts +9 -4
  84. package/dist/types/ma-v1/accounts/multi-owner-account.d.ts.map +1 -1
  85. package/dist/types/ma-v1/decorators/multiOwner.d.ts.map +1 -1
  86. package/dist/types/ma-v1/predictAddress.d.ts +20 -1
  87. package/dist/types/ma-v1/predictAddress.d.ts.map +1 -1
  88. package/dist/types/ma-v2/accounts/account.d.ts +10 -7
  89. package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
  90. package/dist/types/ma-v2/accounts/base.d.ts +5 -5
  91. package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
  92. package/dist/types/ma-v2/mav2StaticImpl.d.ts +1 -15
  93. package/dist/types/ma-v2/mav2StaticImpl.d.ts.map +1 -1
  94. package/dist/types/ma-v2/predictAddress.d.ts +22 -6
  95. package/dist/types/ma-v2/predictAddress.d.ts.map +1 -1
  96. package/dist/types/ma-v2/utils/account.d.ts +0 -3
  97. package/dist/types/ma-v2/utils/account.d.ts.map +1 -1
  98. package/dist/types/ma-v2/utils/signature.d.ts +1 -12
  99. package/dist/types/ma-v2/utils/signature.d.ts.map +1 -1
  100. package/dist/types/types.d.ts +8 -1
  101. package/dist/types/types.d.ts.map +1 -1
  102. package/dist/types/utils.d.ts +32 -2
  103. package/dist/types/utils.d.ts.map +1 -1
  104. package/dist/types/version.d.ts +1 -1
  105. package/dist/types/version.d.ts.map +1 -1
  106. package/package.json +5 -6
  107. package/src/index.ts +4 -3
  108. package/src/light-account/accounts/account.ts +42 -26
  109. package/src/light-account/accounts/base.ts +66 -27
  110. package/src/light-account/accounts/multi-owner-account.ts +33 -16
  111. package/src/light-account/decorators/multiOwner.ts +4 -1
  112. package/src/light-account/decorators/singleOwner.ts +3 -1
  113. package/src/light-account/lightAccountStaticImpl.ts +84 -11
  114. package/src/light-account/predictAddress.ts +124 -3
  115. package/src/light-account/registry.ts +47 -1
  116. package/src/light-account/utils.ts +1 -1
  117. package/src/ma-v1/accounts/base.ts +8 -5
  118. package/src/ma-v1/accounts/multi-owner-account.ts +37 -18
  119. package/src/ma-v1/decorators/multiOwner.ts +4 -1
  120. package/src/ma-v1/predictAddress.ts +59 -2
  121. package/src/ma-v2/accounts/account.ts +42 -55
  122. package/src/ma-v2/accounts/base.ts +24 -88
  123. package/src/ma-v2/mav2StaticImpl.ts +1 -52
  124. package/src/ma-v2/predictAddress.ts +68 -30
  125. package/src/ma-v2/utils/account.ts +4 -4
  126. package/src/ma-v2/utils/signature.ts +2 -51
  127. package/src/types.ts +15 -1
  128. package/src/utils.ts +119 -6
  129. package/src/version.ts +1 -1
  130. package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -330
  131. package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js +0 -260
  132. package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js.map +0 -1
  133. package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -287
  134. package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js +0 -374
  135. package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js.map +0 -1
  136. package/dist/esm/ma-v2/modules/webauthn-validation/module.d.ts +0 -11
  137. package/dist/esm/ma-v2/modules/webauthn-validation/module.js +0 -16
  138. package/dist/esm/ma-v2/modules/webauthn-validation/module.js.map +0 -1
  139. package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -331
  140. package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts.map +0 -1
  141. package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -288
  142. package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts.map +0 -1
  143. package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts +0 -12
  144. package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts.map +0 -1
  145. package/src/ma-v2/abis/webAuthnFactoryAbi.ts +0 -259
  146. package/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.ts +0 -373
  147. package/src/ma-v2/modules/webauthn-validation/module.ts +0 -28
@@ -1,9 +1,8 @@
1
1
  import { encodeFunctionData, } from "viem";
2
+ import { entryPoint07Address, } from "viem/account-abstraction";
2
3
  import { toModularAccountV2Base } from "./base.js";
3
- import { predictModularAccountV2Address } from "../predictAddress.js";
4
- import { parsePublicKey } from "webauthn-p256";
4
+ import { getModularAccountV2AddressFromFactoryData, predictModularAccountV2Address, } from "../predictAddress.js";
5
5
  import { accountFactoryAbi } from "../abis/accountFactoryAbi.js";
6
- import { webAuthnFactoryAbi } from "../abis/webAuthnFactoryAbi.js";
7
6
  import { EntityIdOverrideError } from "../../errors/EntityIdOverrideError.js";
8
7
  import { InvalidOwnerError } from "../../errors/InvalidOwnerError.js";
9
8
  import { DEFAULT_OWNER_ENTITY_ID, DefaultAddress } from "../utils/account.js";
@@ -14,7 +13,7 @@ import { LOGGER } from "../../logger.js";
14
13
  * @param {ToModularAccountV2Params} param0 - The parameters for creating a MAv2 account.
15
14
  * @returns {Promise<ModularAccountV2>} A MAv2 account.
16
15
  */
17
- export async function toModularAccountV2({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt = 0n, factoryAddress: factoryAddress_, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }) {
16
+ export async function toModularAccountV2({ client, owner, deferredAction, signerEntity, accountAddress: accountAddress_, salt = 0n, factory, factoryData: factoryData_, implementationAddress: implementationAddress_, mode, }) {
18
17
  const is7702 = mode === "7702";
19
18
  LOGGER.debug("toModularAccountV2:start", {
20
19
  ownerType: owner.type,
@@ -23,16 +22,9 @@ export async function toModularAccountV2({ client, owner, deferredAction, signer
23
22
  hasAccountAddress: !!accountAddress_,
24
23
  });
25
24
  const entityId = signerEntity?.entityId ?? DEFAULT_OWNER_ENTITY_ID;
26
- const factoryAddress = factoryAddress_ ??
27
- (owner.type === "webAuthn"
28
- ? DefaultAddress.MAV2_FACTORY_WEBAUTHN
29
- : DefaultAddress.MAV2_FACTORY);
25
+ const factoryAddress = factory ?? DefaultAddress.MAV2_FACTORY;
30
26
  const implementationAddress = implementationAddress_ ??
31
- (is7702
32
- ? DefaultAddress.SMAV2_7702
33
- : owner.type === "webAuthn"
34
- ? DefaultAddress.MAV2
35
- : DefaultAddress.SMAV2_BYTECODE);
27
+ (is7702 ? DefaultAddress.SMAV2_7702 : DefaultAddress.SMAV2_BYTECODE);
36
28
  const getFactoryArgs = async () => {
37
29
  if (is7702) {
38
30
  // This is only for EP 0.8.0.
@@ -45,18 +37,6 @@ export async function toModularAccountV2({ client, owner, deferredAction, signer
45
37
  factoryData: undefined,
46
38
  };
47
39
  }
48
- if (owner.type === "webAuthn") {
49
- const { x, y } = parsePublicKey(owner.publicKey);
50
- return {
51
- factory: factoryAddress,
52
- factoryData: factoryData_ ??
53
- encodeFunctionData({
54
- abi: webAuthnFactoryAbi,
55
- functionName: "createWebAuthnAccount",
56
- args: [x, y, salt, entityId],
57
- }),
58
- };
59
- }
60
40
  return {
61
41
  factory: factoryAddress,
62
42
  factoryData: factoryData_ ??
@@ -68,24 +48,26 @@ export async function toModularAccountV2({ client, owner, deferredAction, signer
68
48
  };
69
49
  };
70
50
  const accountAddress = accountAddress_ ??
71
- (mode === "7702" && owner.type === "local"
51
+ (is7702
72
52
  ? owner.address
73
- : predictModularAccountV2Address({
74
- factoryAddress,
75
- implementationAddress,
76
- salt,
77
- ...(owner.type === "webAuthn"
78
- ? {
79
- type: "WebAuthn",
80
- ownerPublicKey: owner.publicKey,
81
- entityId,
82
- }
83
- : {
84
- type: "SMA", // `MA` is never used here since we only support deploying SMA & WebAuthn accounts.
85
- ownerAddress: owner.address,
86
- entityId,
87
- }),
88
- }));
53
+ : factoryData_
54
+ ? await getModularAccountV2AddressFromFactoryData({
55
+ client,
56
+ factoryAddress,
57
+ factoryData: factoryData_,
58
+ implementationAddress,
59
+ entryPoint: {
60
+ version: "0.7",
61
+ address: entryPoint07Address,
62
+ },
63
+ })
64
+ : predictModularAccountV2Address({
65
+ factoryAddress,
66
+ implementationAddress,
67
+ salt,
68
+ type: "SMA",
69
+ ownerAddress: owner.address,
70
+ }));
89
71
  LOGGER.debug("toModularAccountV2:address-resolved", {
90
72
  accountAddress,
91
73
  is7702,
@@ -93,7 +75,6 @@ export async function toModularAccountV2({ client, owner, deferredAction, signer
93
75
  let authorization;
94
76
  if (is7702) {
95
77
  LOGGER.debug("toModularAccountV2:7702-mode");
96
- // TODO(v5): Ensure this works w/ our signer types.
97
78
  if (owner.type !== "local") {
98
79
  LOGGER.error("toModularAccountV2:invalid-owner-type", {
99
80
  ownerType: owner.type,
@@ -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,CAA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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,sFAAsF;KACvF,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 type {\n WebAuthnAccount,\n ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport { toModularAccountV2Base, type ModularAccountV2Base } from \"./base.js\";\nimport type { SignerEntity } from \"../types.js\";\nimport { predictModularAccountV2Address } from \"../predictAddress.js\";\nimport { parsePublicKey } from \"webauthn-p256\";\nimport { accountFactoryAbi } from \"../abis/accountFactoryAbi.js\";\nimport { webAuthnFactoryAbi } from \"../abis/webAuthnFactoryAbi.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// TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\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 | WebAuthnAccount;\n deferredAction?: Hex;\n signerEntity?: SignerEntity;\n accountAddress?: Address;\n mode?: TMode;\n} & (TMode extends \"7702\"\n ? {\n salt?: never;\n factoryAddress?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n salt?: bigint;\n factoryAddress?: Address;\n factoryData?: Hex;\n implementationAddress?: Address;\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 factoryAddress: factoryAddress_,\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 =\n factoryAddress_ ??\n (owner.type === \"webAuthn\"\n ? DefaultAddress.MAV2_FACTORY_WEBAUTHN\n : DefaultAddress.MAV2_FACTORY);\n\n const implementationAddress =\n implementationAddress_ ??\n (is7702\n ? DefaultAddress.SMAV2_7702\n : owner.type === \"webAuthn\"\n ? DefaultAddress.MAV2\n : 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 if (owner.type === \"webAuthn\") {\n const { x, y } = parsePublicKey(owner.publicKey);\n return {\n factory: factoryAddress,\n factoryData:\n factoryData_ ??\n encodeFunctionData({\n abi: webAuthnFactoryAbi,\n functionName: \"createWebAuthnAccount\",\n args: [x, y, salt, entityId],\n }),\n };\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 (mode === \"7702\" && owner.type === \"local\"\n ? owner.address\n : predictModularAccountV2Address({\n factoryAddress,\n implementationAddress,\n salt,\n ...(owner.type === \"webAuthn\"\n ? {\n type: \"WebAuthn\",\n ownerPublicKey: owner.publicKey,\n entityId,\n }\n : {\n type: \"SMA\", // `MA` is never used here since we only support deploying SMA & WebAuthn accounts.\n ownerAddress: owner.address,\n entityId,\n }),\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 // TODO(v5): Ensure this works w/ our signer types.\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 // TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\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,OAA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M,IAAI,iBAAiB,CACzB,iBAAiB,KAAK,CAAC,IAAI,gCAAgC,CAC5D,CAAC;QACJ,CAAC;QACD,IAAI,KAAK,CAAC,iBAAiB,IAAI,IAAI,EAAE,CAAC;YACpC,MAAM,CAAC,KAAK,CAAC,8CAA8C,CAAC,CAAC;YAC7D,MAAM,IAAI,iBAAiB,CACzB,qEAAqE,CACtE,CAAC;QACJ,CAAC;QACD,IACE,QAAQ,KAAK,uBAAuB;YACpC,KAAK,CAAC,OAAO,KAAK,cAAc,EAChC,CAAC;YACD,MAAM,CAAC,KAAK,CAAC,uCAAuC,CAAC,CAAC;YACtD,MAAM,IAAI,qBAAqB,EAAE,CAAC;QACpC,CAAC;QACD,aAAa,GAAG;YACd,iEAAiE;YACjE,+DAA+D;YAC/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,sFAAsF;KACvF,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// TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\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 // TODO(v5): does this need to be extended w/ any more methods like LightAccount does?\n };\n}\n"]}
@@ -1,7 +1,7 @@
1
1
  import { type Address, type Hex, type Chain, type Client, type JsonRpcAccount, type LocalAccount, type Transport } from "viem";
2
- import { entryPoint07Abi, type SmartAccountImplementation, type SmartAccount, type WebAuthnAccount, type ToSmartAccountParameters } from "viem/account-abstraction";
2
+ import { entryPoint07Abi, type SmartAccountImplementation, type ToSmartAccountParameters } from "viem/account-abstraction";
3
3
  import { type ExecutionDataView, type SignerEntity, type ValidationDataView } from "../types.js";
4
- import type { SignatureRequest } from "../../types.js";
4
+ import type { SignatureRequest, SmartAccountWithDecodeCalls } from "../../types.js";
5
5
  export type ValidationDataParams = {
6
6
  validationModuleAddress: Address;
7
7
  entityId?: never;
@@ -10,7 +10,7 @@ export type ValidationDataParams = {
10
10
  entityId: number;
11
11
  };
12
12
  export type BaseModularAccountV2Implementation = SmartAccountImplementation<typeof entryPoint07Abi, "0.7", {
13
- source: "ModularAccountV2";
13
+ smartAccountType: "ModularAccountV2";
14
14
  signerEntity: SignerEntity;
15
15
  encodeCallData: (callData: Hex) => Promise<Hex>;
16
16
  getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;
@@ -18,10 +18,10 @@ export type BaseModularAccountV2Implementation = SmartAccountImplementation<type
18
18
  prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;
19
19
  formatSignature: (signature: Hex) => Promise<Hex>;
20
20
  }, boolean>;
21
- export type ModularAccountV2Base = SmartAccount<BaseModularAccountV2Implementation>;
21
+ export type ModularAccountV2Base = SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;
22
22
  export type ToModularAccountV2BaseParams<TTransport extends Transport = Transport> = {
23
23
  client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;
24
- owner: JsonRpcAccount | LocalAccount | WebAuthnAccount;
24
+ owner: JsonRpcAccount | LocalAccount;
25
25
  accountAddress: Address;
26
26
  getFactoryArgs: () => Promise<{
27
27
  factory?: Address | undefined;
@@ -1,5 +1,5 @@
1
1
  import { concat, concatHex, encodeFunctionData, hashMessage, hashTypedData, maxUint32, maxUint152, zeroAddress, } from "viem";
2
- import { entryPoint07Abi, entryPoint07Address, getUserOperationHash, toSmartAccount, estimateUserOperationGas, } from "viem/account-abstraction";
2
+ import { entryPoint07Abi, entryPoint07Address, getUserOperationHash, toSmartAccount, } from "viem/account-abstraction";
3
3
  import { getCode, readContract, signMessage, signTypedData, } from "viem/actions";
4
4
  import { assertNever, BaseError } from "@alchemy/common";
5
5
  import { SignaturePrefix, } from "../types.js";
@@ -7,11 +7,11 @@ import { modularAccountAbi } from "../abis/modularAccountAbi.js";
7
7
  import { decodeFunctionData, getAction, isAddressEqual, sliceHex, } from "viem/utils";
8
8
  import { DEFAULT_OWNER_ENTITY_ID, DefaultModuleAddress, EXECUTE_USER_OP_SELECTOR, serializeModuleEntity, } from "../utils/account.js";
9
9
  import { parseDeferredAction } from "../utils/deferredActions.js";
10
- import { pack1271Signature, toWebAuthnSignature, toReplaySafeTypedData, packUOSignature, } from "../utils/signature.js";
11
- import { chainHas7212 } from "../../utils.js";
10
+ import { pack1271Signature, toReplaySafeTypedData, packUOSignature, } from "../utils/signature.js";
12
11
  import { InvalidDeferredActionNonceError } from "../../errors/InvalidDeferredActionNonceError.js";
13
12
  import { InvalidNonceKeyError } from "../../errors/InvalidNonceKeyError.js";
14
13
  import { InvalidEntityIdError } from "../../errors/InvalidEntityIdError.js";
14
+ import { is7702Delegated } from "../../utils.js";
15
15
  /**
16
16
  * Creates a ModularAccountV2Base instance.
17
17
  *
@@ -31,10 +31,17 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
31
31
  if (entityId > Number(maxUint32)) {
32
32
  throw new InvalidEntityIdError(entityId);
33
33
  }
34
+ let isDeployed = false;
34
35
  const isAccountDeployed = async () => {
36
+ if (isDeployed) {
37
+ return true;
38
+ }
35
39
  const action = getAction(client, getCode, "getCode");
36
40
  const code = await action({ address: accountAddress });
37
- return code != null && code !== "0x";
41
+ isDeployed = authorization
42
+ ? is7702Delegated(authorization.address, code)
43
+ : !!code;
44
+ return isDeployed;
38
45
  };
39
46
  // These default values signal that we should not use the set deferred action nonce
40
47
  let nonce;
@@ -154,24 +161,19 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
154
161
  data: toReplaySafeTypedData({
155
162
  chainId: client.chain.id,
156
163
  hash,
157
- ...(owner.type === "webAuthn"
158
- ? {
159
- address: DefaultModuleAddress.WEBAUTHN_VALIDATION,
164
+ ...(entityId === DEFAULT_OWNER_ENTITY_ID
165
+ ? { address: accountAddress }
166
+ : {
167
+ address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,
160
168
  salt: concatHex([`0x${"00".repeat(12)}`, accountAddress]),
161
- }
162
- : entityId === DEFAULT_OWNER_ENTITY_ID
163
- ? { address: accountAddress }
164
- : {
165
- address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,
166
- salt: concatHex([`0x${"00".repeat(12)}`, accountAddress]),
167
- }),
169
+ }),
168
170
  }),
169
171
  };
170
172
  };
171
173
  const formatSignature = async (signature) => {
172
174
  return pack1271Signature({
173
175
  entityId,
174
- validationSignaturePrefix: owner.type === "webAuthn" ? null : SignaturePrefix.EOA,
176
+ validationSignaturePrefix: SignaturePrefix.EOA,
175
177
  validationSignature: signature,
176
178
  });
177
179
  };
@@ -249,9 +251,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
249
251
  ];
250
252
  },
251
253
  async getStubSignature() {
252
- if (owner.type === "webAuthn") {
253
- return "0xff000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000001949fc7c88032b9fcb5f6efc7a7b8c63668eae9871b765e23123bb473ff57aa831a7c0d9276168ebcc29f2875a0239cffdf2a9cd1c2007c5c77c071db9264df1d000000000000000000000000000000000000000000000000000000000000002549960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008a7b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2273496a396e6164474850596759334b7156384f7a4a666c726275504b474f716d59576f4d57516869467773222c226f726967696e223a2268747470733a2f2f7369676e2e636f696e626173652e636f6d222c2263726f73734f726967696e223a66616c73657d00000000000000000000000000000000000000000000";
254
- }
255
254
  const sig = packUOSignature({
256
255
  validationSignature: "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c",
257
256
  });
@@ -262,10 +261,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
262
261
  type: "personal_sign",
263
262
  data: message,
264
263
  });
265
- if (owner.type === "webAuthn") {
266
- const validationSignature = toWebAuthnSignature(await owner.sign({ hash: hashTypedData(data) }));
267
- return formatSignature(validationSignature);
268
- }
269
264
  const action = getAction(client, signTypedData, "signTypedData");
270
265
  const signature = await action({
271
266
  ...data,
@@ -283,12 +278,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
283
278
  type: "eth_signTypedData_v4",
284
279
  data: td, // TODO(v5): Try harder to satisfy this w/o casting.
285
280
  });
286
- if (owner.type === "webAuthn") {
287
- const validationSignature = toWebAuthnSignature(await owner.sign({ hash: hashTypedData(data) }));
288
- return isDeferredAction
289
- ? validationSignature
290
- : formatSignature(validationSignature);
291
- }
292
281
  const action = getAction(client, signTypedData, "signTypedData");
293
282
  const signature = await action({
294
283
  ...data,
@@ -308,17 +297,6 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
308
297
  sender: accountAddress,
309
298
  },
310
299
  });
311
- if (owner.type === "webAuthn") {
312
- const validationSignature = toWebAuthnSignature(await owner.sign({
313
- hash: hashMessage({ raw: hash }),
314
- }));
315
- const signature = deferredActionData
316
- ? concatHex([deferredActionData, validationSignature])
317
- : validationSignature;
318
- deferredActionData = undefined; // clear once used
319
- hasAssociatedExecHooks = false; // set to falsy value once used
320
- return concatHex(["0xff", signature]);
321
- }
322
300
  const signMessageAction = getAction(client, signMessage, "signMessage");
323
301
  const validationSignature = await signMessageAction({
324
302
  account: owner,
@@ -334,28 +312,8 @@ export async function toModularAccountV2Base({ client, owner, accountAddress, ge
334
312
  hasAssociatedExecHooks = false; // set to falsy value once used
335
313
  return signature;
336
314
  },
337
- userOperation: {
338
- estimateGas: async (uo) => {
339
- if (owner.type !== "webAuthn") {
340
- // Uses the default gas estimator.
341
- // Note that we get 7702 support automatically from Viem.
342
- return undefined;
343
- }
344
- const estimateGasAction = getAction(client, estimateUserOperationGas, "estimateUserOperationGas");
345
- const estimate = await estimateGasAction({
346
- ...uo,
347
- entryPointAddress: entryPoint.address,
348
- });
349
- const buffer = (await chainHas7212(client)) ? 10000n : 300000n;
350
- // TODO(v4): iterate numbers. Aim to have ~1000 gas buffer to account for longer authenticatorDatas and clientDataJSONs.
351
- return {
352
- ...estimate,
353
- verificationGasLimit: estimate.verificationGasLimit + buffer,
354
- };
355
- },
356
- },
357
315
  extend: {
358
- source: "ModularAccountV2",
316
+ smartAccountType: "ModularAccountV2",
359
317
  signerEntity: {
360
318
  entityId,
361
319
  isGlobalValidation,
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,aAAa,EAEb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EAGf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,EAGd,wBAAwB,GAEzB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,i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A+C;oBACnD,iBAAiB,EAAE,UAAU,CAAC,OAAO;iBACtC,CAAC,CAAC;gBAEH,MAAM,MAAM,GAAG,CAAC,MAAM,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC;gBAE/D,wHAAwH;gBACxH,OAAO;oBACL,GAAG,QAAQ;oBACX,oBAAoB,EAAE,QAAQ,CAAC,oBAAoB,GAAG,MAAM;iBAC7D,CAAC;YACJ,CAAC;SACF;QAED,MAAM,EAAE;YACN,MAAM,EAAE,kBAA2B;YACnC,YAAY,EAAE;gBACZ,QAAQ;gBACR,kBAAkB;aACnB;YACD,cAAc;YACd,gBAAgB;YAChB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Chain,\n type Client,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n concat,\n concatHex,\n encodeFunctionData,\n hashMessage,\n hashTypedData,\n type TypedDataDefinition,\n maxUint32,\n maxUint152,\n zeroAddress,\n} from \"viem\";\nimport {\n entryPoint07Abi,\n type SmartAccountImplementation,\n type SmartAccount,\n entryPoint07Address,\n getUserOperationHash,\n toSmartAccount,\n type WebAuthnAccount,\n type ToSmartAccountParameters,\n estimateUserOperationGas,\n type UserOperation,\n} from \"viem/account-abstraction\";\nimport {\n getCode,\n readContract,\n signMessage,\n signTypedData,\n} from \"viem/actions\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport {\n SignaturePrefix,\n type ExecutionDataView,\n type SignerEntity,\n type ValidationDataView,\n} from \"../types.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport type { SignatureRequest } from \"../../types.js\";\nimport {\n decodeFunctionData,\n getAction,\n isAddressEqual,\n sliceHex,\n} from \"viem/utils\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n DefaultModuleAddress,\n EXECUTE_USER_OP_SELECTOR,\n serializeModuleEntity,\n} from \"../utils/account.js\";\nimport { parseDeferredAction } from \"../utils/deferredActions.js\";\nimport {\n pack1271Signature,\n toWebAuthnSignature,\n toReplaySafeTypedData,\n packUOSignature,\n} from \"../utils/signature.js\";\nimport { chainHas7212 } from \"../../utils.js\";\nimport { InvalidDeferredActionNonceError } from \"../../errors/InvalidDeferredActionNonceError.js\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { InvalidEntityIdError } from \"../../errors/InvalidEntityIdError.js\";\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type BaseModularAccountV2Implementation = SmartAccountImplementation<\n typeof entryPoint07Abi,\n \"0.7\",\n {\n source: \"ModularAccountV2\";\n signerEntity: SignerEntity;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n boolean\n>;\n\nexport type ModularAccountV2Base =\n SmartAccount<BaseModularAccountV2Implementation>;\n\nexport type ToModularAccountV2BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount | WebAuthnAccount;\n accountAddress: Address;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n signerEntity?: SignerEntity;\n deferredAction?: Hex;\n authorization?: ToSmartAccountParameters[\"authorization\"];\n};\n\n/**\n * Creates a ModularAccountV2Base instance.\n *\n * @param {ToModularAccountV2BaseParams<TTransport>} params - The parameters for creating a ModularAccountV2Base instance.\n * @returns {Promise<ModularAccountV2Base>} A promise that resolves to a ModularAccountV2Base instance.\n */\nexport async function toModularAccountV2Base<\n TTransport extends Transport = Transport,\n>({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n deferredAction,\n authorization,\n}: ToModularAccountV2BaseParams<TTransport>): Promise<ModularAccountV2Base> {\n let { isGlobalValidation, entityId } = signerEntity;\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address as Address,\n version: \"0.7\" as const,\n };\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n const isAccountDeployed: () => Promise<boolean> = async () => {\n const action = getAction(client, getCode, \"getCode\");\n const code = await action({ address: accountAddress });\n return code != null && code !== \"0x\";\n };\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n // Set these values if the deferred action has not been consumed. We check this with the EP.\n const nextNonceForDeferredAction: bigint = await readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, deferredActionNonce >> 64n],\n });\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonceError();\n }\n }\n\n const getNonce = async (\n params?: { key?: bigint | undefined } | undefined,\n ): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n const nonceKey = params?.key ?? 0n;\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n return readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, fullNonceKey],\n });\n };\n\n const accountContract = {\n address: accountAddress,\n abi: modularAccountAbi,\n };\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return readContract(client, {\n ...accountContract,\n functionName: \"getExecutionData\",\n args: [selector],\n });\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n const readContractAction = getAction(client, readContract, \"readContract\");\n return readContractAction({\n ...accountContract,\n functionName: \"getValidationData\",\n args: [\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ],\n });\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n return callData;\n };\n\n const prepareSignature = async (\n request: SignatureRequest,\n ): Promise<Extract<SignatureRequest, { type: \"eth_signTypedData_v4\" }>> => {\n const isDeferredAction =\n request.type === \"eth_signTypedData_v4\" &&\n request.data?.primaryType === \"DeferredAction\" &&\n request.data?.domain?.verifyingContract === accountAddress;\n\n if (isDeferredAction && entityId === DEFAULT_OWNER_ENTITY_ID) {\n return request;\n }\n\n const hash =\n request.type === \"personal_sign\"\n ? hashMessage(request.data)\n : request.type === \"eth_signTypedData_v4\"\n ? hashTypedData(request.data)\n : assertNever(request, \"Unexpected signature request type\");\n\n return {\n type: \"eth_signTypedData_v4\",\n data: toReplaySafeTypedData({\n chainId: client.chain.id,\n hash,\n ...(owner.type === \"webAuthn\"\n ? {\n address: DefaultModuleAddress.WEBAUTHN_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }\n : entityId === DEFAULT_OWNER_ENTITY_ID\n ? { address: accountAddress }\n : {\n address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }),\n }),\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return pack1271Signature({\n entityId,\n validationSignaturePrefix:\n owner.type === \"webAuthn\" ? null : SignaturePrefix.EOA,\n validationSignature: signature,\n });\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n getNonce,\n authorization,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length === 1) {\n const call = calls[0];\n\n if (isAddressEqual(call.to, accountAddress)) {\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n\n if (call.data === undefined) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n }),\n );\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n data: call.data ?? \"0x\",\n value: call.value ?? 0n,\n })),\n ],\n }),\n );\n },\n\n async decodeCalls(data) {\n // Inverse of `encodeCalls`.\n // Trim the EXECUTE_USER_OP_SELECTOR if it is present.\n const trimmedData = data\n .toLowerCase()\n .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())\n ? sliceHex(data, 4)\n : data;\n\n const decoded = decodeFunctionData({\n abi: modularAccountAbi,\n data: trimmedData,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n },\n\n async getStubSignature() {\n if (owner.type === \"webAuthn\") {\n return \"0xff000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000c0000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000000170000000000000000000000000000000000000000000000000000000000000001949fc7c88032b9fcb5f6efc7a7b8c63668eae9871b765e23123bb473ff57aa831a7c0d9276168ebcc29f2875a0239cffdf2a9cd1c2007c5c77c071db9264df1d000000000000000000000000000000000000000000000000000000000000002549960de5880e8c687434170f6476605b8fe4aeb9a28632c7995cf3ba831d97630500000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008a7b2274797065223a22776562617574686e2e676574222c226368616c6c656e6765223a2273496a396e6164474850596759334b7156384f7a4a666c726275504b474f716d59576f4d57516869467773222c226f726967696e223a2268747470733a2f2f7369676e2e636f696e626173652e636f6d222c2263726f73734f726967696e223a66616c73657d00000000000000000000000000000000000000000000\";\n }\n\n const sig = packUOSignature({\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n async signMessage({ message }) {\n const { data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n if (owner.type === \"webAuthn\") {\n const validationSignature = toWebAuthnSignature(\n await owner.sign({ hash: hashTypedData(data) }),\n );\n return formatSignature(validationSignature);\n }\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return formatSignature(signature);\n },\n\n async signTypedData(td) {\n const isDeferredAction =\n td.primaryType === \"DeferredAction\" &&\n td.domain &&\n typeof td.domain === \"object\" &&\n \"verifyingContract\" in td.domain &&\n td.domain.verifyingContract === accountAddress;\n\n const { data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: td as TypedDataDefinition, // TODO(v5): Try harder to satisfy this w/o casting.\n });\n\n if (owner.type === \"webAuthn\") {\n const validationSignature = toWebAuthnSignature(\n await owner.sign({ hash: hashTypedData(data) }),\n );\n return isDeferredAction\n ? validationSignature\n : formatSignature(validationSignature);\n }\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return isDeferredAction\n ? concat([SignaturePrefix.EOA, signature])\n : formatSignature(signature);\n },\n\n async signUserOperation(uo) {\n const hash = getUserOperationHash({\n chainId: uo.chainId ?? client.chain.id,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...uo,\n sender: accountAddress,\n },\n });\n\n if (owner.type === \"webAuthn\") {\n const validationSignature = toWebAuthnSignature(\n await owner.sign({\n hash: hashMessage({ raw: hash }),\n }),\n );\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, validationSignature])\n : validationSignature;\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n return concatHex([\"0xff\", signature]);\n }\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const validationSignature = await signMessageAction({\n account: owner,\n message: { raw: hash },\n });\n\n const packedSignature = packUOSignature({\n validationSignature,\n });\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, packedSignature])\n : packedSignature;\n\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n\n return signature;\n },\n\n userOperation: {\n estimateGas: async (uo) => {\n if (owner.type !== \"webAuthn\") {\n // Uses the default gas estimator.\n // Note that we get 7702 support automatically from Viem.\n return undefined;\n }\n\n const estimateGasAction = getAction(\n client,\n estimateUserOperationGas,\n \"estimateUserOperationGas\",\n );\n\n const estimate = await estimateGasAction({\n ...(uo as UserOperation<typeof entryPoint.version>),\n entryPointAddress: entryPoint.address,\n });\n\n const buffer = (await chainHas7212(client)) ? 10000n : 300000n;\n\n // TODO(v4): iterate numbers. Aim to have ~1000 gas buffer to account for longer authenticatorDatas and clientDataJSONs.\n return {\n ...estimate,\n verificationGasLimit: estimate.verificationGasLimit + buffer,\n };\n },\n },\n\n extend: {\n source: \"ModularAccountV2\" as const,\n signerEntity: {\n entityId,\n isGlobalValidation,\n },\n encodeCallData,\n getExecutionData,\n getValidationData,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/ma-v2/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,aAAa,EAEb,SAAS,EACT,UAAU,EACV,WAAW,GACZ,MAAM,MAAM,CAAC;AACd,OAAO,EACL,eAAe,EAEf,mBAAmB,EACnB,oBAAoB,EACpB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EACL,OAAO,EACP,YAAY,EACZ,WAAW,EACX,aAAa,GACd,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EACL,eAAe,GAIhB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AAKjE,OAAO,EACL,kBAAkB,EAClB,SAAS,EACT,cAAc,EACd,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,uBAAuB,EACvB,oBAAoB,EACpB,wBAAwB,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CAAC,CAAC;YAEH,MAAM,iBAAiB,GAAG,SAAS,CAAC,MAAM,EAAE,WAAW,EAAE,aAAa,CAAC,CAAC;YAExE,MAAM,mBAAmB,GAAG,MAAM,iBAAiB,CAAC;gBAClD,OAAO,EAAE,KAAK;gBACd,OAAO,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE;aACvB,CAAC,CAAC;YAEH,MAAM,eAAe,GAAG,eAAe,CAAC;gBACtC,mBAAmB;aACpB,CAAC,CAAC;YAEH,MAAM,SAAS,GAAG,kBAAkB;gBAClC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,eAAe,CAAC,CAAC;gBAClD,CAAC,CAAC,eAAe,CAAC;YAEpB,kBAAkB,GAAG,SAAS,CAAC,CAAC,kBAAkB;YAClD,sBAAsB,GAAG,KAAK,CAAC,CAAC,+BAA+B;YAE/D,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,kBAA2B;YAC7C,YAAY,EAAE;gBACZ,QAAQ;gBACR,kBAAkB;aACnB;YACD,cAAc;YACd,gBAAgB;YAChB,iBAAiB;YACjB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Hex,\n type Chain,\n type Client,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n concat,\n concatHex,\n encodeFunctionData,\n hashMessage,\n hashTypedData,\n type TypedDataDefinition,\n maxUint32,\n maxUint152,\n zeroAddress,\n} from \"viem\";\nimport {\n entryPoint07Abi,\n type SmartAccountImplementation,\n entryPoint07Address,\n getUserOperationHash,\n toSmartAccount,\n type ToSmartAccountParameters,\n} from \"viem/account-abstraction\";\nimport {\n getCode,\n readContract,\n signMessage,\n signTypedData,\n} from \"viem/actions\";\nimport { assertNever, BaseError } from \"@alchemy/common\";\nimport {\n SignaturePrefix,\n type ExecutionDataView,\n type SignerEntity,\n type ValidationDataView,\n} from \"../types.js\";\nimport { modularAccountAbi } from \"../abis/modularAccountAbi.js\";\nimport type {\n SignatureRequest,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport {\n decodeFunctionData,\n getAction,\n isAddressEqual,\n sliceHex,\n} from \"viem/utils\";\nimport {\n DEFAULT_OWNER_ENTITY_ID,\n DefaultModuleAddress,\n EXECUTE_USER_OP_SELECTOR,\n serializeModuleEntity,\n} from \"../utils/account.js\";\nimport { parseDeferredAction } from \"../utils/deferredActions.js\";\nimport {\n pack1271Signature,\n toReplaySafeTypedData,\n packUOSignature,\n} from \"../utils/signature.js\";\nimport { InvalidDeferredActionNonceError } from \"../../errors/InvalidDeferredActionNonceError.js\";\nimport { InvalidNonceKeyError } from \"../../errors/InvalidNonceKeyError.js\";\nimport { InvalidEntityIdError } from \"../../errors/InvalidEntityIdError.js\";\nimport { is7702Delegated } from \"../../utils.js\";\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type BaseModularAccountV2Implementation = SmartAccountImplementation<\n typeof entryPoint07Abi,\n \"0.7\",\n {\n smartAccountType: \"ModularAccountV2\";\n signerEntity: SignerEntity;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n boolean\n>;\n\nexport type ModularAccountV2Base =\n SmartAccountWithDecodeCalls<BaseModularAccountV2Implementation>;\n\nexport type ToModularAccountV2BaseParams<\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n accountAddress: Address;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n signerEntity?: SignerEntity;\n deferredAction?: Hex;\n authorization?: ToSmartAccountParameters[\"authorization\"];\n};\n\n/**\n * Creates a ModularAccountV2Base instance.\n *\n * @param {ToModularAccountV2BaseParams<TTransport>} params - The parameters for creating a ModularAccountV2Base instance.\n * @returns {Promise<ModularAccountV2Base>} A promise that resolves to a ModularAccountV2Base instance.\n */\nexport async function toModularAccountV2Base<\n TTransport extends Transport = Transport,\n>({\n client,\n owner,\n accountAddress,\n getFactoryArgs,\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n deferredAction,\n authorization,\n}: ToModularAccountV2BaseParams<TTransport>): Promise<ModularAccountV2Base> {\n let { isGlobalValidation, entityId } = signerEntity;\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address as Address,\n version: \"0.7\" as const,\n };\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n let isDeployed = false;\n\n const isAccountDeployed: () => Promise<boolean> = async () => {\n if (isDeployed) {\n return true;\n }\n const action = getAction(client, getCode, \"getCode\");\n const code = await action({ address: accountAddress });\n isDeployed = authorization\n ? is7702Delegated(authorization.address, code)\n : !!code;\n return isDeployed;\n };\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n // Set these values if the deferred action has not been consumed. We check this with the EP.\n const nextNonceForDeferredAction: bigint = await readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, deferredActionNonce >> 64n],\n });\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonceError();\n }\n }\n\n const getNonce = async (\n params?: { key?: bigint | undefined } | undefined,\n ): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n const nonceKey = params?.key ?? 0n;\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n return readContractAction({\n ...entryPoint,\n functionName: \"getNonce\",\n args: [accountAddress, fullNonceKey],\n });\n };\n\n const accountContract = {\n address: accountAddress,\n abi: modularAccountAbi,\n };\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return readContract(client, {\n ...accountContract,\n functionName: \"getExecutionData\",\n args: [selector],\n });\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n const readContractAction = getAction(client, readContract, \"readContract\");\n return readContractAction({\n ...accountContract,\n functionName: \"getValidationData\",\n args: [\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ],\n });\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([EXECUTE_USER_OP_SELECTOR, callData]);\n }\n return callData;\n };\n\n const prepareSignature = async (\n request: SignatureRequest,\n ): Promise<Extract<SignatureRequest, { type: \"eth_signTypedData_v4\" }>> => {\n const isDeferredAction =\n request.type === \"eth_signTypedData_v4\" &&\n request.data?.primaryType === \"DeferredAction\" &&\n request.data?.domain?.verifyingContract === accountAddress;\n\n if (isDeferredAction && entityId === DEFAULT_OWNER_ENTITY_ID) {\n return request;\n }\n\n const hash =\n request.type === \"personal_sign\"\n ? hashMessage(request.data)\n : request.type === \"eth_signTypedData_v4\"\n ? hashTypedData(request.data)\n : assertNever(request, \"Unexpected signature request type\");\n\n return {\n type: \"eth_signTypedData_v4\",\n data: toReplaySafeTypedData({\n chainId: client.chain.id,\n hash,\n ...(entityId === DEFAULT_OWNER_ENTITY_ID\n ? { address: accountAddress }\n : {\n address: DefaultModuleAddress.SINGLE_SIGNER_VALIDATION,\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n }),\n }),\n };\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return pack1271Signature({\n entityId,\n validationSignaturePrefix: SignaturePrefix.EOA,\n validationSignature: signature,\n });\n };\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n getNonce,\n authorization,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length === 1) {\n const call = calls[0];\n\n if (isAddressEqual(call.to, accountAddress)) {\n // If the call is to the account itself, we need to avoid wrapping it in an `execute` call.\n\n if (call.data === undefined) {\n throw new BaseError(\"Data is required for an account self-call.\");\n }\n\n return encodeCallData(call.data);\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [call.to, call.value ?? 0n, call.data ?? \"0x\"],\n }),\n );\n }\n\n return encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n calls.map((call) => ({\n target: call.to,\n data: call.data ?? \"0x\",\n value: call.value ?? 0n,\n })),\n ],\n }),\n );\n },\n\n async decodeCalls(data) {\n // Inverse of `encodeCalls`.\n // Trim the EXECUTE_USER_OP_SELECTOR if it is present.\n const trimmedData = data\n .toLowerCase()\n .startsWith(EXECUTE_USER_OP_SELECTOR.toLowerCase())\n ? sliceHex(data, 4)\n : data;\n\n const decoded = decodeFunctionData({\n abi: modularAccountAbi,\n data: trimmedData,\n });\n\n if (decoded.functionName === \"execute\") {\n return [\n {\n to: decoded.args[0],\n value: decoded.args[1],\n data: decoded.args[2],\n },\n ];\n }\n\n if (decoded.functionName === \"executeBatch\") {\n return decoded.args[0].map((call) => ({\n to: call.target,\n value: call.value,\n data: call.data,\n }));\n }\n\n // If the data is not for an `execute` or `executeBatch` call, we treat it as a single call to the account itself.\n return [\n {\n to: accountAddress,\n data,\n },\n ];\n },\n\n async getStubSignature() {\n const sig = packUOSignature({\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n async signMessage({ message }) {\n const { data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return formatSignature(signature);\n },\n\n async signTypedData(td) {\n const isDeferredAction =\n td.primaryType === \"DeferredAction\" &&\n td.domain &&\n typeof td.domain === \"object\" &&\n \"verifyingContract\" in td.domain &&\n td.domain.verifyingContract === accountAddress;\n\n const { data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: td as TypedDataDefinition, // TODO(v5): Try harder to satisfy this w/o casting.\n });\n\n const action = getAction(client, signTypedData, \"signTypedData\");\n\n const signature = await action({\n ...data,\n account: owner,\n });\n\n return isDeferredAction\n ? concat([SignaturePrefix.EOA, signature])\n : formatSignature(signature);\n },\n\n async signUserOperation(uo) {\n const hash = getUserOperationHash({\n chainId: uo.chainId ?? client.chain.id,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...uo,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const validationSignature = await signMessageAction({\n account: owner,\n message: { raw: hash },\n });\n\n const packedSignature = packUOSignature({\n validationSignature,\n });\n\n const signature = deferredActionData\n ? concatHex([deferredActionData, packedSignature])\n : packedSignature;\n\n deferredActionData = undefined; // clear once used\n hasAssociatedExecHooks = false; // set to falsy value once used\n\n return signature;\n },\n\n extend: {\n smartAccountType: \"ModularAccountV2\" as const,\n signerEntity: {\n entityId,\n isGlobalValidation,\n },\n encodeCallData,\n getExecutionData,\n getValidationData,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
@@ -1,10 +1,8 @@
1
- import { type Address, type Hex } from "viem";
1
+ import { type Address } from "viem";
2
2
  import { entryPoint07Abi } from "viem/account-abstraction";
3
3
  import type { StaticSmartAccountImplementation } from "../types.js";
4
4
  import { semiModularAccountBytecodeAbi } from "./abis/semiModularAccountBytecodeAbi.js";
5
5
  import { accountFactoryAbi } from "./abis/accountFactoryAbi.js";
6
- import { webAuthnFactoryAbi } from "./abis/webAuthnFactoryAbi.js";
7
- import { modularAccountAbi } from "./abis/modularAccountAbi.js";
8
6
  export type SemiModularAccountV2FactoryArgs = {
9
7
  owner: Address;
10
8
  salt: bigint;
@@ -23,15 +21,3 @@ export type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<
23
21
  * TODO(v5): update JSDoc format when doc-gen supports structs or records.
24
22
  */
25
23
  export declare const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl;
26
- export type WebAuthnModularAccountV2FactoryArgs = {
27
- ownerPublicKey: Hex;
28
- salt: bigint;
29
- entityId: number;
30
- };
31
- export type WebAuthnModularAccountV2StaticImpl = StaticSmartAccountImplementation<false, "0.7", WebAuthnModularAccountV2FactoryArgs, typeof entryPoint07Abi, typeof modularAccountAbi, typeof webAuthnFactoryAbi>;
32
- /**
33
- * Static implementation logic for WebAuthnModularAccountV2.
34
- *
35
- * TODO(v5): update JSDoc format when doc-gen supports structs or records.
36
- */
37
- export declare const webAuthnModularAccountV2StaticImpl: WebAuthnModularAccountV2StaticImpl;
@@ -3,11 +3,8 @@ import { entryPoint07Abi, entryPoint07Address } from "viem/account-abstraction";
3
3
  import { lowerAddress } from "@alchemy/common";
4
4
  import { semiModularAccountBytecodeAbi } from "./abis/semiModularAccountBytecodeAbi.js";
5
5
  import { accountFactoryAbi } from "./abis/accountFactoryAbi.js";
6
- import { webAuthnFactoryAbi } from "./abis/webAuthnFactoryAbi.js";
7
6
  import { DefaultAddress as DefaultMAV2Address } from "./utils/account.js";
8
7
  import { predictModularAccountV2Address } from "./predictAddress.js";
9
- import { modularAccountAbi } from "./abis/modularAccountAbi.js";
10
- import { parsePublicKey } from "webauthn-p256";
11
8
  // Shared entryPoint configuration across all modular account v2 implementations
12
9
  const entryPoint = {
13
10
  abi: entryPoint07Abi,
@@ -55,34 +52,4 @@ export const semiModularAccount7702StaticImpl = {
55
52
  ...semiModularAccountBase,
56
53
  delegationAddress: lowerAddress(DefaultMAV2Address.SMAV2_7702),
57
54
  };
58
- /**
59
- * Static implementation logic for WebAuthnModularAccountV2.
60
- *
61
- * TODO(v5): update JSDoc format when doc-gen supports structs or records.
62
- */
63
- export const webAuthnModularAccountV2StaticImpl = {
64
- entryPoint,
65
- accountAbi: modularAccountAbi,
66
- accountImplementation: lowerAddress(DefaultMAV2Address.MAV2),
67
- factoryAddress: lowerAddress(DefaultMAV2Address.MAV2_FACTORY_WEBAUTHN),
68
- factoryAbi: webAuthnFactoryAbi,
69
- getFactoryData: (args) => {
70
- const { x, y } = parsePublicKey(args.ownerPublicKey);
71
- return encodeFunctionData({
72
- abi: webAuthnFactoryAbi,
73
- functionName: "createWebAuthnAccount",
74
- args: [x, y, args.salt, args.entityId],
75
- });
76
- },
77
- predictAccountAddress: (args) => {
78
- return predictModularAccountV2Address({
79
- factoryAddress: DefaultMAV2Address.MAV2_FACTORY_WEBAUTHN,
80
- implementationAddress: DefaultMAV2Address.MAV2,
81
- type: "WebAuthn",
82
- salt: args.salt,
83
- ownerPublicKey: args.ownerPublicKey,
84
- entityId: args.entityId,
85
- });
86
- },
87
- };
88
55
  //# sourceMappingURL=mav2StaticImpl.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mav2StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v2/mav2StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAA0B,MAAM,MAAM,CAAC;AAClE,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AAgB/C,gFAAgF;AAChF,MAAM,UAAU,GAAG;IACjB,GAAG,EAAE,eAAe;IACpB,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,sEAAsE;AACtE,MAAM,sBAAsB,GAAG;IAC7B,UAAU;IACV,UAAU,EAAE,6BAA6B;CACQ,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAmC;IAC5E,GAAG,sBAAsB;IACzB,qBAAqB,EAAE,YAAY,CAAC,kBAAkB,CAAC,cAAc,CA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AAE,CAAC,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,QAAQ,CAAC;SACvC,CAAC,CAAC;IACL,CAAC;IACD,qBAAqB,EAAE,CAAC,IAAyC,EAAE,EAAE;QACnE,OAAO,8BAA8B,CAAC;YACpC,cAAc,EAAE,kBAAkB,CAAC,qBAAqB;YACxD,qBAAqB,EAAE,kBAAkB,CAAC,IAAI;YAC9C,IAAI,EAAE,UAAU;YAChB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,cAAc,EAAE,IAAI,CAAC,cAAc;YACnC,QAAQ,EAAE,IAAI,CAAC,QAAQ;SACxB,CAAC,CAAC;IACL,CAAC;CACF,CAAC","sourcesContent":["import { encodeFunctionData, type Address, type Hex } from \"viem\";\nimport { entryPoint07Abi, entryPoint07Address } from \"viem/account-abstraction\";\nimport { lowerAddress } from \"@alchemy/common\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"./abis/semiModularAccountBytecodeAbi.js\";\nimport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nimport { webAuthnFactoryAbi } from \"./abis/webAuthnFactoryAbi.js\";\nimport { DefaultAddress as DefaultMAV2Address } from \"./utils/account.js\";\nimport { predictModularAccountV2Address } from \"./predictAddress.js\";\nimport { modularAccountAbi } from \"./abis/modularAccountAbi.js\";\nimport { parsePublicKey } from \"webauthn-p256\";\n\nexport type SemiModularAccountV2FactoryArgs = {\n owner: Address;\n salt: bigint;\n};\n\nexport type SemiModularAccountV2StaticImpl = StaticSmartAccountImplementation<\n false,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n// Shared entryPoint configuration across all modular account v2 implementations\nconst entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address,\n version: \"0.7\",\n} as const;\n\n// Shared base for semi-modular account implementations (SMA and 7702)\nconst semiModularAccountBase = {\n entryPoint,\n accountAbi: semiModularAccountBytecodeAbi,\n} satisfies Partial<SemiModularAccountV2StaticImpl>;\n\n/**\n * Static implementation logic for SemiModularAccountV2.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const semiModularAccountV2StaticImpl: SemiModularAccountV2StaticImpl = {\n ...semiModularAccountBase,\n accountImplementation: lowerAddress(DefaultMAV2Address.SMAV2_BYTECODE),\n factoryAddress: lowerAddress(DefaultMAV2Address.MAV2_FACTORY),\n factoryAbi: accountFactoryAbi,\n getFactoryData: (args: SemiModularAccountV2FactoryArgs) => {\n return encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [args.owner, args.salt],\n });\n },\n predictAccountAddress: (args: SemiModularAccountV2FactoryArgs) => {\n return predictModularAccountV2Address({\n factoryAddress: DefaultMAV2Address.MAV2_FACTORY,\n implementationAddress: DefaultMAV2Address.SMAV2_BYTECODE,\n type: \"SMA\",\n salt: args.salt,\n ownerAddress: args.owner,\n });\n },\n};\n\nexport type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<\n true,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n/**\n * Static implementation logic for SemiModularAccount7702.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl =\n {\n ...semiModularAccountBase,\n delegationAddress: lowerAddress(DefaultMAV2Address.SMAV2_7702),\n };\n\nexport type WebAuthnModularAccountV2FactoryArgs = {\n ownerPublicKey: Hex;\n salt: bigint;\n entityId: number;\n};\n\nexport type WebAuthnModularAccountV2StaticImpl =\n StaticSmartAccountImplementation<\n false,\n \"0.7\",\n WebAuthnModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof modularAccountAbi,\n typeof webAuthnFactoryAbi\n >;\n\n/**\n * Static implementation logic for WebAuthnModularAccountV2.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const webAuthnModularAccountV2StaticImpl: WebAuthnModularAccountV2StaticImpl =\n {\n entryPoint,\n accountAbi: modularAccountAbi,\n accountImplementation: lowerAddress(DefaultMAV2Address.MAV2),\n factoryAddress: lowerAddress(DefaultMAV2Address.MAV2_FACTORY_WEBAUTHN),\n factoryAbi: webAuthnFactoryAbi,\n getFactoryData: (args: WebAuthnModularAccountV2FactoryArgs) => {\n const { x, y } = parsePublicKey(args.ownerPublicKey);\n return encodeFunctionData({\n abi: webAuthnFactoryAbi,\n functionName: \"createWebAuthnAccount\",\n args: [x, y, args.salt, args.entityId],\n });\n },\n predictAccountAddress: (args: WebAuthnModularAccountV2FactoryArgs) => {\n return predictModularAccountV2Address({\n factoryAddress: DefaultMAV2Address.MAV2_FACTORY_WEBAUTHN,\n implementationAddress: DefaultMAV2Address.MAV2,\n type: \"WebAuthn\",\n salt: args.salt,\n ownerPublicKey: args.ownerPublicKey,\n entityId: args.entityId,\n });\n },\n };\n"]}
1
+ {"version":3,"file":"mav2StaticImpl.js","sourceRoot":"","sources":["../../../src/ma-v2/mav2StaticImpl.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,MAAM,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAChF,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAC;AACxF,OAAO,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAChE,OAAO,EAAE,cAAc,IAAI,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC1E,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAC;AAgBrE,gFAAgF;AAChF,MAAM,UAAU,GAAG;IACjB,GAAG,EAAE,eAAe;IACpB,OAAO,EAAE,mBAAmB;IAC5B,OAAO,EAAE,KAAK;CACN,CAAC;AAEX,sEAAsE;AACtE,MAAM,sBAAsB,GAAG;IAC7B,UAAU;IACV,UAAU,EAAE,6BAA6B;CACQ,CAAC;AAEpD;;;;GAIG;AACH,MAAM,CAAC,MAAM,8BAA8B,GAAmC;IAC5E,GAAG,sBAAsB;IACzB,qBAAqB,EAAE,YAAY,CAAC,kBAAkB,CAAC,cAAc,CAAC;IACtE,cAAc,EAAE,YAAY,CAAC,kBAAkB,CAAC,YAAY,CAAC;IAC7D,UAAU,EAAE,iBAAiB;IAC7B,cAAc,EAAE,CAAC,IAAqC,EAAE,EAAE;QACxD,OAAO,kBAAkB,CAAC;YACxB,GAAG,EAAE,iBAAiB;YACtB,YAAY,EAAE,0BAA0B;YACxC,IAAI,EAAE,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,CAAC;SAC9B,CAAC,CAAC;IACL,CAAC;IACD,qBAAqB,EAAE,CAAC,IAAqC,EAAE,EAAE;QAC/D,OAAO,8BAA8B,CAAC;YACpC,cAAc,EAAE,kBAAkB,CAAC,YAAY;YAC/C,qBAAqB,EAAE,kBAAkB,CAAC,cAAc;YACxD,IAAI,EAAE,KAAK;YACX,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,KAAK;SACzB,CAAC,CAAC;IACL,CAAC;CACF,CAAC;AAWF;;;;GAIG;AACH,MAAM,CAAC,MAAM,gCAAgC,GAC3C;IACE,GAAG,sBAAsB;IACzB,iBAAiB,EAAE,YAAY,CAAC,kBAAkB,CAAC,UAAU,CAAC;CAC/D,CAAC","sourcesContent":["import { encodeFunctionData, type Address } from \"viem\";\nimport { entryPoint07Abi, entryPoint07Address } from \"viem/account-abstraction\";\nimport { lowerAddress } from \"@alchemy/common\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\nimport { semiModularAccountBytecodeAbi } from \"./abis/semiModularAccountBytecodeAbi.js\";\nimport { accountFactoryAbi } from \"./abis/accountFactoryAbi.js\";\nimport { DefaultAddress as DefaultMAV2Address } from \"./utils/account.js\";\nimport { predictModularAccountV2Address } from \"./predictAddress.js\";\n\nexport type SemiModularAccountV2FactoryArgs = {\n owner: Address;\n salt: bigint;\n};\n\nexport type SemiModularAccountV2StaticImpl = StaticSmartAccountImplementation<\n false,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n// Shared entryPoint configuration across all modular account v2 implementations\nconst entryPoint = {\n abi: entryPoint07Abi,\n address: entryPoint07Address,\n version: \"0.7\",\n} as const;\n\n// Shared base for semi-modular account implementations (SMA and 7702)\nconst semiModularAccountBase = {\n entryPoint,\n accountAbi: semiModularAccountBytecodeAbi,\n} satisfies Partial<SemiModularAccountV2StaticImpl>;\n\n/**\n * Static implementation logic for SemiModularAccountV2.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const semiModularAccountV2StaticImpl: SemiModularAccountV2StaticImpl = {\n ...semiModularAccountBase,\n accountImplementation: lowerAddress(DefaultMAV2Address.SMAV2_BYTECODE),\n factoryAddress: lowerAddress(DefaultMAV2Address.MAV2_FACTORY),\n factoryAbi: accountFactoryAbi,\n getFactoryData: (args: SemiModularAccountV2FactoryArgs) => {\n return encodeFunctionData({\n abi: accountFactoryAbi,\n functionName: \"createSemiModularAccount\",\n args: [args.owner, args.salt],\n });\n },\n predictAccountAddress: (args: SemiModularAccountV2FactoryArgs) => {\n return predictModularAccountV2Address({\n factoryAddress: DefaultMAV2Address.MAV2_FACTORY,\n implementationAddress: DefaultMAV2Address.SMAV2_BYTECODE,\n type: \"SMA\",\n salt: args.salt,\n ownerAddress: args.owner,\n });\n },\n};\n\nexport type SemiModularAccount7702StaticImpl = StaticSmartAccountImplementation<\n true,\n \"0.7\",\n SemiModularAccountV2FactoryArgs,\n typeof entryPoint07Abi,\n typeof semiModularAccountBytecodeAbi,\n typeof accountFactoryAbi\n>;\n\n/**\n * Static implementation logic for SemiModularAccount7702.\n *\n * TODO(v5): update JSDoc format when doc-gen supports structs or records.\n */\nexport const semiModularAccount7702StaticImpl: SemiModularAccount7702StaticImpl =\n {\n ...semiModularAccountBase,\n delegationAddress: lowerAddress(DefaultMAV2Address.SMAV2_7702),\n };\n"]}
@@ -1,4 +1,5 @@
1
- import { type Address, type Hex } from "viem";
1
+ import { type Address, type Client, type Hex } from "viem";
2
+ import { type EntryPointVersion } from "viem/account-abstraction";
2
3
  export type PredictModularAccountV2AddressParams = {
3
4
  factoryAddress: Address;
4
5
  implementationAddress: Address;
@@ -10,13 +11,9 @@ export type PredictModularAccountV2AddressParams = {
10
11
  } | {
11
12
  type: "SMA";
12
13
  ownerAddress: Address;
13
- } | {
14
- type: "WebAuthn";
15
- ownerPublicKey: Hex;
16
- entityId: number;
17
14
  });
18
15
  /**
19
- * Predicts the address of a modular account V2 based on the provided parameters, which include factory address, salt, and implementation address. This function supports different types of accounts including "SMA", "MA", and "WebAuthn".
16
+ * Predicts the address of a modular account V2 based on the provided parameters, which include factory address, salt, and implementation address. This function supports different types of accounts including "SMA" and "MA".
20
17
  *
21
18
  * @example
22
19
  * ```ts
@@ -35,3 +32,22 @@ export type PredictModularAccountV2AddressParams = {
35
32
  * @returns {Address} The predicted address for the modular account V2.
36
33
  */
37
34
  export declare function predictModularAccountV2Address(params: PredictModularAccountV2AddressParams): Address;
35
+ export type GetModularAccountV2AddressFromFactoryDataParams = {
36
+ client: Client;
37
+ factoryAddress: Address;
38
+ factoryData: Hex;
39
+ implementationAddress: Address;
40
+ entryPoint?: {
41
+ version: EntryPointVersion;
42
+ address: Address;
43
+ };
44
+ };
45
+ /**
46
+ * Gets the modular account v2 address from factory data.
47
+ * If the factory is a known default (SMA), decodes the args and predicts without RPC.
48
+ * Otherwise falls back to calling the entry point's getSenderAddress.
49
+ *
50
+ * @param {GetModularAccountV2AddressFromFactoryDataParams} params - The parameters
51
+ * @returns {Promise<Address>} The account address
52
+ */
53
+ export declare function getModularAccountV2AddressFromFactoryData({ client, factoryAddress, factoryData, implementationAddress, entryPoint, }: GetModularAccountV2AddressFromFactoryDataParams): Promise<Address>;