@alchemy/smart-accounts 0.0.0-alpha.9 → 5.0.0-beta.2

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 (135) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +36 -0
  3. package/dist/esm/index.d.ts +2 -4
  4. package/dist/esm/index.js +2 -4
  5. package/dist/esm/index.js.map +1 -1
  6. package/dist/esm/light-account/accounts/account.d.ts +7 -3
  7. package/dist/esm/light-account/accounts/account.js +20 -10
  8. package/dist/esm/light-account/accounts/account.js.map +1 -1
  9. package/dist/esm/light-account/accounts/base.js +50 -23
  10. package/dist/esm/light-account/accounts/base.js.map +1 -1
  11. package/dist/esm/light-account/accounts/calldataCodec.js +3 -2
  12. package/dist/esm/light-account/accounts/calldataCodec.js.map +1 -1
  13. package/dist/esm/light-account/accounts/multi-owner-account.d.ts +6 -2
  14. package/dist/esm/light-account/accounts/multi-owner-account.js +14 -6
  15. package/dist/esm/light-account/accounts/multi-owner-account.js.map +1 -1
  16. package/dist/esm/light-account/lightAccountStaticImpl.d.ts +3 -1
  17. package/dist/esm/light-account/lightAccountStaticImpl.js +57 -7
  18. package/dist/esm/light-account/lightAccountStaticImpl.js.map +1 -1
  19. package/dist/esm/light-account/predictAddress.d.ts +40 -2
  20. package/dist/esm/light-account/predictAddress.js +83 -3
  21. package/dist/esm/light-account/predictAddress.js.map +1 -1
  22. package/dist/esm/light-account/registry.d.ts +3410 -0
  23. package/dist/esm/light-account/registry.js +33 -1
  24. package/dist/esm/light-account/registry.js.map +1 -1
  25. package/dist/esm/logger.d.ts +1 -1
  26. package/dist/esm/logger.js +1 -1
  27. package/dist/esm/logger.js.map +1 -1
  28. package/dist/esm/ma-v1/accounts/multi-owner-account.d.ts +6 -2
  29. package/dist/esm/ma-v1/accounts/multi-owner-account.js +18 -7
  30. package/dist/esm/ma-v1/accounts/multi-owner-account.js.map +1 -1
  31. package/dist/esm/ma-v1/predictAddress.d.ts +20 -1
  32. package/dist/esm/ma-v1/predictAddress.js +38 -2
  33. package/dist/esm/ma-v1/predictAddress.js.map +1 -1
  34. package/dist/esm/ma-v2/accounts/account.d.ts +8 -5
  35. package/dist/esm/ma-v2/accounts/account.js +23 -42
  36. package/dist/esm/ma-v2/accounts/account.js.map +1 -1
  37. package/dist/esm/ma-v2/accounts/base.d.ts +2 -2
  38. package/dist/esm/ma-v2/accounts/base.js +12 -59
  39. package/dist/esm/ma-v2/accounts/base.js.map +1 -1
  40. package/dist/esm/ma-v2/mav2StaticImpl.d.ts +1 -15
  41. package/dist/esm/ma-v2/mav2StaticImpl.js +0 -33
  42. package/dist/esm/ma-v2/mav2StaticImpl.js.map +1 -1
  43. package/dist/esm/ma-v2/modules/time-range-module/module.js +3 -2
  44. package/dist/esm/ma-v2/modules/time-range-module/module.js.map +1 -1
  45. package/dist/esm/ma-v2/predictAddress.d.ts +22 -6
  46. package/dist/esm/ma-v2/predictAddress.js +46 -12
  47. package/dist/esm/ma-v2/predictAddress.js.map +1 -1
  48. package/dist/esm/ma-v2/utils/account.d.ts +0 -3
  49. package/dist/esm/ma-v2/utils/account.js +0 -3
  50. package/dist/esm/ma-v2/utils/account.js.map +1 -1
  51. package/dist/esm/ma-v2/utils/signature.d.ts +1 -16
  52. package/dist/esm/ma-v2/utils/signature.js +1 -38
  53. package/dist/esm/ma-v2/utils/signature.js.map +1 -1
  54. package/dist/esm/utils.d.ts +24 -11
  55. package/dist/esm/utils.js +67 -21
  56. package/dist/esm/utils.js.map +1 -1
  57. package/dist/esm/version.d.ts +1 -1
  58. package/dist/esm/version.js +1 -1
  59. package/dist/esm/version.js.map +1 -1
  60. package/dist/types/index.d.ts +2 -4
  61. package/dist/types/index.d.ts.map +1 -1
  62. package/dist/types/light-account/accounts/account.d.ts +7 -3
  63. package/dist/types/light-account/accounts/account.d.ts.map +1 -1
  64. package/dist/types/light-account/accounts/base.d.ts.map +1 -1
  65. package/dist/types/light-account/accounts/calldataCodec.d.ts.map +1 -1
  66. package/dist/types/light-account/accounts/multi-owner-account.d.ts +6 -2
  67. package/dist/types/light-account/accounts/multi-owner-account.d.ts.map +1 -1
  68. package/dist/types/light-account/lightAccountStaticImpl.d.ts +3 -1
  69. package/dist/types/light-account/lightAccountStaticImpl.d.ts.map +1 -1
  70. package/dist/types/light-account/predictAddress.d.ts +40 -2
  71. package/dist/types/light-account/predictAddress.d.ts.map +1 -1
  72. package/dist/types/light-account/registry.d.ts +3410 -0
  73. package/dist/types/light-account/registry.d.ts.map +1 -1
  74. package/dist/types/logger.d.ts +1 -1
  75. package/dist/types/logger.d.ts.map +1 -1
  76. package/dist/types/ma-v1/accounts/multi-owner-account.d.ts +6 -2
  77. package/dist/types/ma-v1/accounts/multi-owner-account.d.ts.map +1 -1
  78. package/dist/types/ma-v1/predictAddress.d.ts +20 -1
  79. package/dist/types/ma-v1/predictAddress.d.ts.map +1 -1
  80. package/dist/types/ma-v2/accounts/account.d.ts +8 -5
  81. package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
  82. package/dist/types/ma-v2/accounts/base.d.ts +2 -2
  83. package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
  84. package/dist/types/ma-v2/mav2StaticImpl.d.ts +1 -15
  85. package/dist/types/ma-v2/mav2StaticImpl.d.ts.map +1 -1
  86. package/dist/types/ma-v2/modules/time-range-module/module.d.ts.map +1 -1
  87. package/dist/types/ma-v2/predictAddress.d.ts +22 -6
  88. package/dist/types/ma-v2/predictAddress.d.ts.map +1 -1
  89. package/dist/types/ma-v2/utils/account.d.ts +0 -3
  90. package/dist/types/ma-v2/utils/account.d.ts.map +1 -1
  91. package/dist/types/ma-v2/utils/signature.d.ts +1 -16
  92. package/dist/types/ma-v2/utils/signature.d.ts.map +1 -1
  93. package/dist/types/utils.d.ts +24 -11
  94. package/dist/types/utils.d.ts.map +1 -1
  95. package/dist/types/version.d.ts +1 -1
  96. package/dist/types/version.d.ts.map +1 -1
  97. package/package.json +9 -8
  98. package/src/index.ts +0 -6
  99. package/src/light-account/accounts/account.ts +30 -16
  100. package/src/light-account/accounts/base.ts +62 -23
  101. package/src/light-account/accounts/calldataCodec.ts +3 -2
  102. package/src/light-account/accounts/multi-owner-account.ts +22 -9
  103. package/src/light-account/lightAccountStaticImpl.ts +84 -11
  104. package/src/light-account/predictAddress.ts +124 -3
  105. package/src/light-account/registry.ts +44 -0
  106. package/src/logger.ts +2 -2
  107. package/src/ma-v1/accounts/multi-owner-account.ts +26 -11
  108. package/src/ma-v1/predictAddress.ts +60 -3
  109. package/src/ma-v2/accounts/account.ts +39 -52
  110. package/src/ma-v2/accounts/base.ts +11 -84
  111. package/src/ma-v2/mav2StaticImpl.ts +1 -52
  112. package/src/ma-v2/modules/time-range-module/module.ts +3 -2
  113. package/src/ma-v2/predictAddress.ts +68 -30
  114. package/src/ma-v2/utils/account.ts +0 -3
  115. package/src/ma-v2/utils/signature.ts +2 -57
  116. package/src/utils.ts +111 -27
  117. package/src/version.ts +1 -1
  118. package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -330
  119. package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js +0 -260
  120. package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js.map +0 -1
  121. package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -287
  122. package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js +0 -374
  123. package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js.map +0 -1
  124. package/dist/esm/ma-v2/modules/webauthn-validation/module.d.ts +0 -11
  125. package/dist/esm/ma-v2/modules/webauthn-validation/module.js +0 -16
  126. package/dist/esm/ma-v2/modules/webauthn-validation/module.js.map +0 -1
  127. package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -331
  128. package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts.map +0 -1
  129. package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -288
  130. package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts.map +0 -1
  131. package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts +0 -12
  132. package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts.map +0 -1
  133. package/src/ma-v2/abis/webAuthnFactoryAbi.ts +0 -259
  134. package/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.ts +0 -373
  135. package/src/ma-v2/modules/webauthn-validation/module.ts +0 -28
@@ -1,4 +1,4 @@
1
- import { lightAccountStaticImplV1_0_1, lightAccountStaticImplV1_0_2, lightAccountStaticImplV1_1_0, lightAccountStaticImplV2_0_0, multiOwnerLightAccountStaticImplV2_0_0, } from "./lightAccountStaticImpl.js";
1
+ import { lightAccountStaticImplV1_0_1, lightAccountStaticImplV1_0_2, lightAccountStaticImplV1_1_0, lightAccountStaticImplV2_0_0, lightAccountStaticImplV2_1_0, lightAccountStaticImplV2_2_0, multiOwnerLightAccountStaticImplV2_0_0, } from "./lightAccountStaticImpl.js";
2
2
  /**
3
3
  * Account version registry interface that defines the light account versions
4
4
  * and the version definition for each light account type
@@ -10,9 +10,41 @@ export const AccountVersionRegistry = {
10
10
  "v1.0.2": lightAccountStaticImplV1_0_2,
11
11
  "v1.1.0": lightAccountStaticImplV1_1_0,
12
12
  "v2.0.0": lightAccountStaticImplV2_0_0,
13
+ "v2.1.0": lightAccountStaticImplV2_1_0,
14
+ "v2.2.0": lightAccountStaticImplV2_2_0,
13
15
  },
14
16
  MultiOwnerLightAccount: {
15
17
  "v2.0.0": multiOwnerLightAccountStaticImplV2_0_0,
16
18
  },
17
19
  };
20
+ /**
21
+ * Light Account v1 versions
22
+ */
23
+ export const LightAccountV1Versions = [
24
+ "v1.0.1",
25
+ "v1.0.2",
26
+ "v1.1.0",
27
+ ];
28
+ /**
29
+ * Light Account v2 versions
30
+ */
31
+ export const LightAccountV2Versions = [
32
+ "v2.0.0",
33
+ "v2.1.0",
34
+ "v2.2.0",
35
+ ];
36
+ /**
37
+ * Type guard to check if a version is a Light Account v1 version
38
+ *
39
+ * @param {LightAccountVersion<"LightAccount">} version - The version to check.
40
+ * @returns {boolean} True if the version is a v1 version.
41
+ */
42
+ export const isLightAccountVersion1 = (version) => LightAccountV1Versions.includes(version);
43
+ /**
44
+ * Type guard to check if a version is a Light Account v2 version
45
+ *
46
+ * @param {LightAccountVersion<"LightAccount">} version - The version to check.
47
+ * @returns {boolean} True if the version is a v2 version.
48
+ */
49
+ export const isLightAccountVersion2 = (version) => LightAccountV2Versions.includes(version);
18
50
  //# sourceMappingURL=registry.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/light-account/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,6BAA6B,CAAC;AAGrC;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,YAAY,EAAE;QACZ,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;KACvC;IACD,sBAAsB,EAAE;QACtB,QAAQ,EAAE,sCAAsC;KACjD;CACyE,CAAC","sourcesContent":["import type { Abi, Address } from \"viem\";\nimport type { LightAccountBase } from \"./accounts/base.js\";\nimport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./lightAccountStaticImpl.js\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\n\n/**\n * Account version registry interface that defines the light account versions\n * and the version definition for each light account type\n *\n */\nexport const AccountVersionRegistry = {\n LightAccount: {\n \"v1.0.1\": lightAccountStaticImplV1_0_1,\n \"v1.0.2\": lightAccountStaticImplV1_0_2,\n \"v1.1.0\": lightAccountStaticImplV1_1_0,\n \"v2.0.0\": lightAccountStaticImplV2_0_0,\n },\n MultiOwnerLightAccount: {\n \"v2.0.0\": multiOwnerLightAccountStaticImplV2_0_0,\n },\n} satisfies Record<string, Record<string, StaticSmartAccountImplementation>>;\n\nexport type LightAccountType = Extract<\n keyof typeof AccountVersionRegistry,\n \"LightAccount\" | \"MultiOwnerLightAccount\"\n>;\n\nexport type LightAccountVersion<TAccountType extends LightAccountType> =\n keyof (typeof AccountVersionRegistry)[TAccountType];\n\nexport type GetLightAccountType<TAccount extends LightAccountBase> =\n TAccount[\"smartAccountType\"] extends LightAccountType\n ? TAccount[\"smartAccountType\"]\n : never;\n\nexport type LightAccountAbi<\n TAccountType extends LightAccountType,\n TAccountVersion extends LightAccountVersion<TAccountType>,\n> = TAccountVersion extends keyof (typeof AccountVersionRegistry)[TAccountType]\n ? (typeof AccountVersionRegistry)[TAccountType][TAccountVersion] extends StaticSmartAccountImplementation\n ? (typeof AccountVersionRegistry)[TAccountType][TAccountVersion][\"accountAbi\"]\n : never\n : never;\n\n/**\n * Infers the EntryPoint details as a type, given the account type and version.\n */\nexport type EntryPointFromAccountRegistry<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> =\n (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion] extends StaticSmartAccountImplementation<\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n infer _7702,\n infer entryPointVersion,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n infer _factoryArgs,\n infer entryPointAbi extends Abi\n >\n ? (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion][\"entryPoint\"] extends {\n readonly version: entryPointVersion;\n readonly address: Address;\n readonly abi: entryPointAbi;\n }\n ? (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion][\"entryPoint\"]\n : never\n : never;\n"]}
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../../src/light-account/registry.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,4BAA4B,EAC5B,sCAAsC,GACvC,MAAM,6BAA6B,CAAC;AAGrC;;;;GAIG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,YAAY,EAAE;QACZ,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;QACtC,QAAQ,EAAE,4BAA4B;KACvC;IACD,sBAAsB,EAAE;QACtB,QAAQ,EAAE,sCAAsC;KACjD;CACyE,CAAC;AAU7E;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,QAAQ;IACR,QAAQ;IACR,QAAQ;CACgD,CAAC;AAE3D;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,QAAQ;IACR,QAAQ;IACR,QAAQ;CACgD,CAAC;AAE3D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAA4C,EACQ,EAAE,CACrD,sBAA4C,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AAElE;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG,CACpC,OAA4C,EACQ,EAAE,CACrD,sBAA4C,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import type { Abi, Address } from \"viem\";\nimport type { LightAccountBase } from \"./accounts/base.js\";\nimport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n lightAccountStaticImplV2_1_0,\n lightAccountStaticImplV2_2_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./lightAccountStaticImpl.js\";\nimport type { StaticSmartAccountImplementation } from \"../types.js\";\n\n/**\n * Account version registry interface that defines the light account versions\n * and the version definition for each light account type\n *\n */\nexport const AccountVersionRegistry = {\n LightAccount: {\n \"v1.0.1\": lightAccountStaticImplV1_0_1,\n \"v1.0.2\": lightAccountStaticImplV1_0_2,\n \"v1.1.0\": lightAccountStaticImplV1_1_0,\n \"v2.0.0\": lightAccountStaticImplV2_0_0,\n \"v2.1.0\": lightAccountStaticImplV2_1_0,\n \"v2.2.0\": lightAccountStaticImplV2_2_0,\n },\n MultiOwnerLightAccount: {\n \"v2.0.0\": multiOwnerLightAccountStaticImplV2_0_0,\n },\n} satisfies Record<string, Record<string, StaticSmartAccountImplementation>>;\n\nexport type LightAccountType = Extract<\n keyof typeof AccountVersionRegistry,\n \"LightAccount\" | \"MultiOwnerLightAccount\"\n>;\n\nexport type LightAccountVersion<TAccountType extends LightAccountType> =\n keyof (typeof AccountVersionRegistry)[TAccountType];\n\n/**\n * Light Account v1 versions\n */\nexport const LightAccountV1Versions = [\n \"v1.0.1\",\n \"v1.0.2\",\n \"v1.1.0\",\n] as const satisfies LightAccountVersion<\"LightAccount\">[];\n\n/**\n * Light Account v2 versions\n */\nexport const LightAccountV2Versions = [\n \"v2.0.0\",\n \"v2.1.0\",\n \"v2.2.0\",\n] as const satisfies LightAccountVersion<\"LightAccount\">[];\n\n/**\n * Type guard to check if a version is a Light Account v1 version\n *\n * @param {LightAccountVersion<\"LightAccount\">} version - The version to check.\n * @returns {boolean} True if the version is a v1 version.\n */\nexport const isLightAccountVersion1 = (\n version: LightAccountVersion<\"LightAccount\">,\n): version is (typeof LightAccountV1Versions)[number] =>\n (LightAccountV1Versions as readonly string[]).includes(version);\n\n/**\n * Type guard to check if a version is a Light Account v2 version\n *\n * @param {LightAccountVersion<\"LightAccount\">} version - The version to check.\n * @returns {boolean} True if the version is a v2 version.\n */\nexport const isLightAccountVersion2 = (\n version: LightAccountVersion<\"LightAccount\">,\n): version is (typeof LightAccountV2Versions)[number] =>\n (LightAccountV2Versions as readonly string[]).includes(version);\n\nexport type GetLightAccountType<TAccount extends LightAccountBase> =\n TAccount[\"smartAccountType\"] extends LightAccountType\n ? TAccount[\"smartAccountType\"]\n : never;\n\nexport type LightAccountAbi<\n TAccountType extends LightAccountType,\n TAccountVersion extends LightAccountVersion<TAccountType>,\n> = TAccountVersion extends keyof (typeof AccountVersionRegistry)[TAccountType]\n ? (typeof AccountVersionRegistry)[TAccountType][TAccountVersion] extends StaticSmartAccountImplementation\n ? (typeof AccountVersionRegistry)[TAccountType][TAccountVersion][\"accountAbi\"]\n : never\n : never;\n\n/**\n * Infers the EntryPoint details as a type, given the account type and version.\n */\nexport type EntryPointFromAccountRegistry<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> =\n (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion] extends StaticSmartAccountImplementation<\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n infer _7702,\n infer entryPointVersion,\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n infer _factoryArgs,\n infer entryPointAbi extends Abi\n >\n ? (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion][\"entryPoint\"] extends {\n readonly version: entryPointVersion;\n readonly address: Address;\n readonly abi: entryPointAbi;\n }\n ? (typeof AccountVersionRegistry)[TLightAccountType][TLightAccountVersion][\"entryPoint\"]\n : never\n : never;\n"]}
@@ -1,2 +1,2 @@
1
- import type { DiagnosticsLogger } from "@alchemy/common";
1
+ import type { DiagnosticsLogger } from "@alchemy/common/internal";
2
2
  export declare const LOGGER: DiagnosticsLogger;
@@ -1,4 +1,4 @@
1
- import { createLogger } from "@alchemy/common";
1
+ import { createLogger } from "@alchemy/common/internal";
2
2
  import { VERSION } from "./version.js";
3
3
  export const LOGGER = createLogger({
4
4
  package: "@alchemy/smart-accounts",
@@ -1 +1 @@
1
- {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,MAAM,GAAsB,YAAY,CAAC;IACpD,OAAO,EAAE,yBAAyB;IAClC,OAAO,EAAE,OAAO;IAChB,SAAS,EAAE,gBAAgB;CAC5B,CAAC,CAAC","sourcesContent":["import { createLogger } from \"@alchemy/common\";\nimport type { DiagnosticsLogger } from \"@alchemy/common\";\nimport { VERSION } from \"./version.js\";\n\nexport const LOGGER: DiagnosticsLogger = createLogger({\n package: \"@alchemy/smart-accounts\",\n version: VERSION,\n namespace: \"smart-accounts\",\n});\n"]}
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAExD,OAAO,EAAE,OAAO,EAAE,MAAM,cAAc,CAAC;AAEvC,MAAM,CAAC,MAAM,MAAM,GAAsB,YAAY,CAAC;IACpD,OAAO,EAAE,yBAAyB;IAClC,OAAO,EAAE,OAAO;IAChB,SAAS,EAAE,gBAAgB;CAC5B,CAAC,CAAC","sourcesContent":["import { createLogger } from \"@alchemy/common/internal\";\nimport type { DiagnosticsLogger } from \"@alchemy/common/internal\";\nimport { VERSION } from \"./version.js\";\n\nexport const LOGGER: DiagnosticsLogger = createLogger({\n package: \"@alchemy/smart-accounts\",\n version: VERSION,\n namespace: \"smart-accounts\",\n});\n"]}
@@ -9,11 +9,15 @@ export type ToMultiOwnerModularAccountV1Params = {
9
9
  owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{
10
10
  address: Address;
11
11
  }[]];
12
- salt?: bigint;
13
12
  accountAddress?: Address;
14
13
  factory?: Address;
14
+ } & ({
15
+ salt?: bigint;
16
+ factoryData?: never;
17
+ } | {
18
+ salt?: never;
15
19
  factoryData?: Hex;
16
- };
20
+ });
17
21
  /**
18
22
  * Creates a multi-owner MAv1 account.
19
23
  *
@@ -1,13 +1,14 @@
1
- import { hexToBigInt, encodeFunctionData, } from "viem";
1
+ import { encodeFunctionData, hexToBigInt, } from "viem";
2
2
  import { toModularAccountV1Base } from "./base.js";
3
3
  import { lowerAddress, BaseError } from "@alchemy/common";
4
4
  import { DefaultMaV1Address, DefaultMaV1PluginAddress } from "../account.js";
5
5
  import { MultiOwnerModularAccountFactoryAbi } from "../abis/MultiOwnerModularAccountFactory.js";
6
- import { predictMultiOwnerModularAccountV1Address } from "../predictAddress.js";
6
+ import { getMultiOwnerModularAccountV1AddressFromFactoryData, predictMultiOwnerModularAccountV1Address, } from "../predictAddress.js";
7
7
  import { MultiOwnerPluginExecutionFunctionAbi } from "../abis/MultiOwnerPluginExecutionFunction.js";
8
8
  import { readContract } from "viem/actions";
9
9
  import { getAction } from "viem/utils";
10
10
  import { MultiOwnerPluginAbi } from "../abis/MultiOwnerPlugin.js";
11
+ import { entryPoint06Address } from "viem/account-abstraction";
11
12
  /**
12
13
  * Creates a multi-owner MAv1 account.
13
14
  *
@@ -23,11 +24,21 @@ export async function toMultiOwnerModularAccountV1({ client, salt = 0n, owners,
23
24
  return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;
24
25
  });
25
26
  const accountAddress = accountAddress_ ??
26
- predictMultiOwnerModularAccountV1Address({
27
- factoryAddress: factory,
28
- salt,
29
- ownerAddresses: sortedOwners,
30
- });
27
+ (factoryData_
28
+ ? await getMultiOwnerModularAccountV1AddressFromFactoryData({
29
+ client,
30
+ factoryAddress: factory,
31
+ factoryData: factoryData_,
32
+ entryPoint: {
33
+ version: "0.6",
34
+ address: entryPoint06Address,
35
+ },
36
+ })
37
+ : predictMultiOwnerModularAccountV1Address({
38
+ factoryAddress: factory,
39
+ salt,
40
+ ownerAddresses: sortedOwners,
41
+ }));
31
42
  const getFactoryArgs = async () => {
32
43
  const factoryData = factoryData_ ??
33
44
  encodeFunctionData({
@@ -1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AAE,OAAO,EAAE,CAAC;aACnE;YACD,OAAO,EAAE;gBACP,OAAO,EAAE,GAAG;aACb;YACD,WAAW,EAAE,8BAA8B;SAC5C,CAAC;IACJ,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC;QAC/C,MAAM;QACN,KAAK,EAAE,MAAM;QACb,cAAc;QACd,cAAc;QACd,IAAI,EAAE,4BAA4B;QAClC,aAAa;KACd,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,WAAW;QAEd,kBAAkB,EAAE,CAAC,WAAsB,EAAE,cAAyB,EAAE,EAAE;YACxE,OAAO,kBAAkB,CAAC;gBACxB,GAAG,EAAE,oCAAoC;gBACzC,YAAY,EAAE,cAAc;gBAC5B,IAAI,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC;aACpC,CAAC,CAAC;QACL,CAAC;QAED,KAAK,CAAC,iBAAiB;YACrB,MAAM,kBAAkB,GAAG,SAAS,CAClC,MAAM,EACN,YAAY,EACZ,cAAc,CACf,CAAC;YACF,MAAM,aAAa,GAAG,MAAM,kBAAkB,CAAC;gBAC7C,OAAO,EAAE,wBAAwB,CAAC,WAAW;gBAC7C,GAAG,EAAE,mBAAmB;gBACxB,YAAY,EAAE,UAAU;gBACxB,IAAI,EAAE,CAAC,cAAc,CAAC;aACvB,CAAC,CAAC;YAEH,IACE,CAAC,aAAa;iBACX,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;iBAC7B,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EACzC,CAAC;gBACD,MAAM,IAAI,SAAS,CACjB,qDAAqD,CACtD,CAAC;YACJ,CAAC;YAED,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n hexToBigInt,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type OneOf,\n type Transport,\n encodeFunctionData,\n type Hash,\n type TypedDataDefinition,\n} from \"viem\";\nimport { toModularAccountV1Base, type ModularAccountV1Base } from \"./base.js\";\nimport { lowerAddress, BaseError } from \"@alchemy/common\";\nimport { DefaultMaV1Address, DefaultMaV1PluginAddress } from \"../account.js\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"../abis/MultiOwnerModularAccountFactory.js\";\nimport { predictMultiOwnerModularAccountV1Address } from \"../predictAddress.js\";\nimport { MultiOwnerPluginExecutionFunctionAbi } from \"../abis/MultiOwnerPluginExecutionFunction.js\";\nimport { readContract } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\nimport { MultiOwnerPluginAbi } from \"../abis/MultiOwnerPlugin.js\";\n\nexport type MultiOwnerModularAccountV1 = ModularAccountV1Base & {\n encodeUpdateOwners: (\n ownersToAdd: Address[],\n ownersToRemove: Address[],\n ) => Hex;\n getOwnerAddresses: () => Promise<readonly Address[]>;\n};\n\nexport type ToMultiOwnerModularAccountV1Params = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];\n salt?: bigint;\n accountAddress?: Address;\n factory?: Address;\n factoryData?: Hex;\n};\n\n/**\n * Creates a multi-owner MAv1 account.\n *\n * @param {ToMultiOwnerModularAccountV1Params} param0 - The parameters for creating a multi-owner MAv1 account.\n * @returns {Promise<MultiOwnerModularAccountV1<TSigner>>} A multi-owner MAv1 account.\n */\nexport async function toMultiOwnerModularAccountV1({\n client,\n salt = 0n,\n owners,\n accountAddress: accountAddress_,\n factory = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n factoryData: factoryData_,\n}: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1> {\n const signer = owners[0];\n\n const dedupedOwners = Array.from(\n new Set(owners.map((it) => lowerAddress(it.address))),\n );\n\n const sortedOwners = dedupedOwners.sort((a, b) => {\n const bigintA = hexToBigInt(a);\n const bigintB = hexToBigInt(b);\n return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;\n });\n\n const accountAddress =\n accountAddress_ ??\n predictMultiOwnerModularAccountV1Address({\n factoryAddress: factory,\n salt,\n ownerAddresses: sortedOwners,\n });\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [salt, sortedOwners],\n });\n\n return {\n factory,\n factoryData,\n };\n };\n\n const get712Wrapper = async (msg: Hash): Promise<TypedDataDefinition> => {\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n const [, name, version, chainId, verifyingContract, salt] =\n await readContractAction({\n abi: MultiOwnerPluginAbi,\n address: DefaultMaV1PluginAddress.MULTI_OWNER,\n functionName: \"eip712Domain\",\n account: accountAddress,\n });\n\n return {\n domain: {\n chainId: Number(chainId),\n name,\n salt,\n verifyingContract,\n version,\n },\n types: {\n AlchemyModularAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: msg,\n },\n primaryType: \"AlchemyModularAccountMessage\",\n };\n };\n\n const baseAccount = await toModularAccountV1Base({\n client,\n owner: signer,\n accountAddress,\n getFactoryArgs,\n type: \"MultiOwnerModularAccountV1\",\n get712Wrapper,\n });\n\n return {\n ...baseAccount,\n\n encodeUpdateOwners: (ownersToAdd: Address[], ownersToRemove: Address[]) => {\n return encodeFunctionData({\n abi: MultiOwnerPluginExecutionFunctionAbi,\n functionName: \"updateOwners\",\n args: [ownersToAdd, ownersToRemove],\n });\n },\n\n async getOwnerAddresses(): Promise<readonly Address[]> {\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const ownersOnChain = await readContractAction({\n address: DefaultMaV1PluginAddress.MULTI_OWNER,\n abi: MultiOwnerPluginAbi,\n functionName: \"ownersOf\",\n args: [accountAddress],\n });\n\n if (\n !ownersOnChain\n .map((it) => lowerAddress(it))\n .includes(lowerAddress(signer.address))\n ) {\n throw new BaseError(\n \"on-chain owners does not include the current signer\",\n );\n }\n\n return ownersOnChain;\n },\n };\n}\n"]}
1
+ {"version":3,"file":"multi-owner-account.js","sourceRoot":"","sources":["../../../../src/ma-v1/accounts/multi-owner-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,GAWZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,sBAAsB,EAA6B,MAAM,WAAW,CAAC;AAC9E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC1D,OAAO,EAAE,kBAAkB,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,kCAAkC,EAAE,MAAM,4CAA4C,CAAC;AAChG,OAAO,EACL,mDAAmD,EACnD,wCAAwC,GACzC,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,oCAAoC,EAAE,MAAM,8CAA8C,CAAC;AACpG,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AACvC,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAoB/D;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B,CAAC,EACjD,MAAM,EACN,IAAI,GAAG,EAAE,EACT,MAAM,EACN,cAAc,EAAE,eAAe,EAC/B,OAAO,GAAG,kBAAkB,CAAC,wBAAwB,EACrD,WAAW,EAAE,YAAY,GACU;IACnC,MAAM,MAAM,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IAEzB,MAAM,aAAa,GAAG,KAAK,CAAC,IAAI,CAC9B,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC,CACtD,CAAC;IAEF,MAAM,YAAY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EAAE,EAAE,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,CAAC;iBAC7B,QAAQ,CAAC,YAAY,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,EACzC,CAAC;gBACD,MAAM,IAAI,SAAS,CACjB,qDAAqD,CACtD,CAAC;YACJ,CAAC;YAED,OAAO,aAAa,CAAC;QACvB,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n encodeFunctionData,\n hexToBigInt,\n type Address,\n type Chain,\n type Client,\n type Hash,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type OneOf,\n type Transport,\n type TypedDataDefinition,\n} from \"viem\";\nimport { toModularAccountV1Base, type ModularAccountV1Base } from \"./base.js\";\nimport { lowerAddress, BaseError } from \"@alchemy/common\";\nimport { DefaultMaV1Address, DefaultMaV1PluginAddress } from \"../account.js\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"../abis/MultiOwnerModularAccountFactory.js\";\nimport {\n getMultiOwnerModularAccountV1AddressFromFactoryData,\n predictMultiOwnerModularAccountV1Address,\n} from \"../predictAddress.js\";\nimport { MultiOwnerPluginExecutionFunctionAbi } from \"../abis/MultiOwnerPluginExecutionFunction.js\";\nimport { readContract } from \"viem/actions\";\nimport { getAction } from \"viem/utils\";\nimport { MultiOwnerPluginAbi } from \"../abis/MultiOwnerPlugin.js\";\nimport { entryPoint06Address } from \"viem/account-abstraction\";\n\nexport type MultiOwnerModularAccountV1 = ModularAccountV1Base & {\n encodeUpdateOwners: (\n ownersToAdd: Address[],\n ownersToRemove: Address[],\n ) => Hex;\n getOwnerAddresses: () => Promise<readonly Address[]>;\n};\n\nexport type ToMultiOwnerModularAccountV1Params = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{ address: Address }[]];\n accountAddress?: Address;\n factory?: Address;\n} & (\n | { salt?: bigint; factoryData?: never }\n | { salt?: never; factoryData?: Hex }\n);\n\n/**\n * Creates a multi-owner MAv1 account.\n *\n * @param {ToMultiOwnerModularAccountV1Params} param0 - The parameters for creating a multi-owner MAv1 account.\n * @returns {Promise<MultiOwnerModularAccountV1<TSigner>>} A multi-owner MAv1 account.\n */\nexport async function toMultiOwnerModularAccountV1({\n client,\n salt = 0n,\n owners,\n accountAddress: accountAddress_,\n factory = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n factoryData: factoryData_,\n}: ToMultiOwnerModularAccountV1Params): Promise<MultiOwnerModularAccountV1> {\n const signer = owners[0];\n\n const dedupedOwners = Array.from(\n new Set(owners.map((it) => lowerAddress(it.address))),\n );\n\n const sortedOwners = dedupedOwners.sort((a, b) => {\n const bigintA = hexToBigInt(a);\n const bigintB = hexToBigInt(b);\n return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;\n });\n\n const accountAddress =\n accountAddress_ ??\n (factoryData_\n ? await getMultiOwnerModularAccountV1AddressFromFactoryData({\n client,\n factoryAddress: factory,\n factoryData: factoryData_,\n entryPoint: {\n version: \"0.6\",\n address: entryPoint06Address,\n },\n })\n : predictMultiOwnerModularAccountV1Address({\n factoryAddress: factory,\n salt,\n ownerAddresses: sortedOwners,\n }));\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [salt, sortedOwners],\n });\n\n return {\n factory,\n factoryData,\n };\n };\n\n const get712Wrapper = async (msg: Hash): Promise<TypedDataDefinition> => {\n const readContractAction = getAction(client, readContract, \"readContract\");\n\n const [, name, version, chainId, verifyingContract, salt] =\n await readContractAction({\n abi: MultiOwnerPluginAbi,\n address: DefaultMaV1PluginAddress.MULTI_OWNER,\n functionName: \"eip712Domain\",\n account: accountAddress,\n });\n\n return {\n domain: {\n chainId: Number(chainId),\n name,\n salt,\n verifyingContract,\n version,\n },\n types: {\n AlchemyModularAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: msg,\n },\n primaryType: \"AlchemyModularAccountMessage\",\n };\n };\n\n const baseAccount = await toModularAccountV1Base({\n client,\n owner: signer,\n accountAddress,\n getFactoryArgs,\n type: \"MultiOwnerModularAccountV1\",\n get712Wrapper,\n });\n\n return {\n ...baseAccount,\n\n encodeUpdateOwners: (ownersToAdd: Address[], ownersToRemove: Address[]) => {\n return encodeFunctionData({\n abi: MultiOwnerPluginExecutionFunctionAbi,\n functionName: \"updateOwners\",\n args: [ownersToAdd, ownersToRemove],\n });\n },\n\n async getOwnerAddresses(): Promise<readonly Address[]> {\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const ownersOnChain = await readContractAction({\n address: DefaultMaV1PluginAddress.MULTI_OWNER,\n abi: MultiOwnerPluginAbi,\n functionName: \"ownersOf\",\n args: [accountAddress],\n });\n\n if (\n !ownersOnChain\n .map((it) => lowerAddress(it))\n .includes(lowerAddress(signer.address))\n ) {\n throw new BaseError(\n \"on-chain owners does not include the current signer\",\n );\n }\n\n return ownersOnChain;\n },\n };\n}\n"]}
@@ -1,4 +1,5 @@
1
- import { type Address } from "viem";
1
+ import { type Address, type Client, type Hex } from "viem";
2
+ import type { EntryPointVersion } from "viem/account-abstraction";
2
3
  export type PredictMultiOwnerModularAccountV1AddressParams = {
3
4
  salt: bigint;
4
5
  ownerAddresses: Address[];
@@ -26,3 +27,21 @@ export type PredictMultiOwnerModularAccountV1AddressParams = {
26
27
  * ```
27
28
  */
28
29
  export declare const predictMultiOwnerModularAccountV1Address: ({ salt, ownerAddresses, factoryAddress, }: PredictMultiOwnerModularAccountV1AddressParams) => Address;
30
+ export type GetMultiOwnerModularAccountV1AddressFromFactoryDataParams = {
31
+ client: Client;
32
+ factoryAddress: Address;
33
+ factoryData: Hex;
34
+ entryPoint: {
35
+ version: EntryPointVersion;
36
+ address: Address;
37
+ };
38
+ };
39
+ /**
40
+ * Gets the multi-owner modular account v1 address from factory data.
41
+ * If the factory is a known default, decodes the args and predicts without RPC.
42
+ * Otherwise falls back to calling the entry point's getSenderAddress.
43
+ *
44
+ * @param {GetMultiOwnerModularAccountV1AddressFromFactoryDataParams} params - The parameters
45
+ * @returns {Promise<Address>} The account address
46
+ */
47
+ export declare function getMultiOwnerModularAccountV1AddressFromFactoryData({ client, factoryAddress, factoryData, entryPoint, }: GetMultiOwnerModularAccountV1AddressFromFactoryDataParams): Promise<Address>;
@@ -1,6 +1,8 @@
1
- import { getContractAddress, encodeAbiParameters, keccak256, concatHex, } from "viem";
1
+ import { concatHex, decodeFunctionData, encodeAbiParameters, getContractAddress, isAddressEqual, keccak256, } from "viem";
2
2
  import { DefaultMaV1Address } from "./account.js";
3
+ import { MultiOwnerModularAccountFactoryAbi } from "./abis/MultiOwnerModularAccountFactory.js";
3
4
  import { BaseError } from "@alchemy/common";
5
+ import { getSenderFromFactoryData } from "../utils.js";
4
6
  /**
5
7
  * Predicts the address of a MultiOwnerModularAccountV1 smart account before deployment.
6
8
  *
@@ -27,7 +29,7 @@ export const predictMultiOwnerModularAccountV1Address = ({ salt, ownerAddresses,
27
29
  throw new BaseError("Owners array cannot be empty");
28
30
  }
29
31
  if (ownerAddresses.length > 100) {
30
- throw new Error("Maximum 100 owners on creation");
32
+ throw new BaseError("Maximum 100 owners on creation");
31
33
  }
32
34
  const combinedSalt = getCombinedSalt(salt, ownerAddresses);
33
35
  const initCodeHash = getERC1967ProxyInitCodeHash(DefaultMaV1Address.IMPLEMENTATION_ADDRESS);
@@ -48,4 +50,38 @@ function getERC1967ProxyInitCodeHash(implementationAddress) {
48
50
  const constructorArgs = encodeAbiParameters([{ type: "address" }, { type: "bytes" }], [implementationAddress, "0x"]);
49
51
  return keccak256(concatHex([ERC1967_PROXY_BYTECODE, constructorArgs]));
50
52
  }
53
+ /**
54
+ * Gets the multi-owner modular account v1 address from factory data.
55
+ * If the factory is a known default, decodes the args and predicts without RPC.
56
+ * Otherwise falls back to calling the entry point's getSenderAddress.
57
+ *
58
+ * @param {GetMultiOwnerModularAccountV1AddressFromFactoryDataParams} params - The parameters
59
+ * @returns {Promise<Address>} The account address
60
+ */
61
+ export async function getMultiOwnerModularAccountV1AddressFromFactoryData({ client, factoryAddress, factoryData, entryPoint, }) {
62
+ if (isAddressEqual(factoryAddress, DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY)) {
63
+ try {
64
+ const decoded = decodeFunctionData({
65
+ abi: MultiOwnerModularAccountFactoryAbi,
66
+ data: factoryData,
67
+ });
68
+ if (decoded.functionName === "createAccount") {
69
+ const [decodedSalt, decodedOwners] = decoded.args;
70
+ return predictMultiOwnerModularAccountV1Address({
71
+ factoryAddress,
72
+ salt: decodedSalt,
73
+ ownerAddresses: [...decodedOwners],
74
+ });
75
+ }
76
+ }
77
+ catch {
78
+ // Decode failed, fall through to RPC
79
+ }
80
+ }
81
+ return getSenderFromFactoryData(client, {
82
+ factory: factoryAddress,
83
+ factoryData,
84
+ entryPoint,
85
+ });
86
+ }
51
87
  //# sourceMappingURL=predictAddress.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"predictAddress.js","sourceRoot":"","sources":["../../../src/ma-v1/predictAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,kBAAkB,EAClB,mBAAmB,EACnB,SAAS,EACT,SAAS,GAEV,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAS5C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,EACvD,IAAI,EACJ,cAAc,EACd,cAAc,GAAG,kBAAkB,CAAC,wBAAwB,GACb,EAAW,EAAE;IAC5D,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,cAAc,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QAChC,MAAM,IAAI,KAAK,CAAC,gCAAgC,CAAC,CAAC;IACpD,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAE3D,MAAM,YAAY,GAAG,2BAA2B,CAC9C,kBAAkB,CAAC,sBAAsB,CAC1C,CAAC;IAEF,OAAO,kBAAkB,CAAC;QACxB,IAAI,EAAE,cAAc;QACpB,MAAM,EAAE,SAAS;QACjB,IAAI,EAAE,YAAY;QAClB,YAAY,EAAE,YAAY;KAC3B,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,SAAS,eAAe,CAAC,IAAY,EAAE,MAAiB;IACtD,MAAM,aAAa,GAAG,mBAAmB,CAAC,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC;IAC7E,MAAM,aAAa,GAAG,mBAAmB,CACvC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EACxC,CAAC,IAAI,EAAE,aAAa,CAAC,CACtB,CAAC;IACF,OAAO,SAAS,CAAC,aAAa,CAAC,CAAC;AAClC,CAAC;AAED,SAAS,2BAA2B,CAAC,qBAA8B;IACjE,MAAM,sBAAsB,GAC1B,4lEAAqmE,CAAC;IAExmE,MAAM,eAAe,GAAG,mBAAmB,CACzC,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,EACxC,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAC9B,CAAC;IAEF,OAAO,SAAS,CAAC,SAAS,CAAC,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;AACzE,CAAC","sourcesContent":["import {\n type Address,\n getContractAddress,\n encodeAbiParameters,\n keccak256,\n concatHex,\n type Hex,\n} from \"viem\";\nimport { DefaultMaV1Address } from \"./account.js\";\nimport { BaseError } from \"@alchemy/common\";\n\nexport type PredictMultiOwnerModularAccountV1AddressParams = {\n salt: bigint;\n /* Owner addresses must be already deduped, sorted in ascending order, and have the signer address included. */\n ownerAddresses: Address[];\n factoryAddress?: Address;\n};\n\n/**\n * Predicts the address of a MultiOwnerModularAccountV1 smart account before deployment.\n *\n * This function uses CREATE2 to deterministically compute the account address based on the factory address,\n * salt, and owner addresses. The predicted address will match the actual deployed address if the same\n * parameters are used during deployment.\n *\n * @param {PredictMultiOwnerModularAccountV1AddressParams} params The parameters for predicting the account address\n * @param {bigint} params.salt A unique value used to generate different account addresses for the same set of owners\n * @param {Address[]} params.ownerAddresses Array of owner addresses that will control the account. Must be deduplicated, sorted in ascending order, and include the signer address. Cannot be empty and must contain at most 100 addresses.\n * @param {Address} [params.factoryAddress] The factory contract address that will deploy the account. Defaults to the standard MultiOwnerModularAccountV1 factory address.\n * @returns {Address} The predicted address where the account will be deployed\n *\n * @example\n * ```ts\n * const predictedAddress = predictMultiOwnerModularAccountV1Address({\n * salt: 0n,\n * ownerAddresses: [\"0x1234...\", \"0x5678...\"]\n * });\n * ```\n */\nexport const predictMultiOwnerModularAccountV1Address = ({\n salt,\n ownerAddresses,\n factoryAddress = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n}: PredictMultiOwnerModularAccountV1AddressParams): Address => {\n if (ownerAddresses.length === 0) {\n throw new BaseError(\"Owners array cannot be empty\");\n }\n if (ownerAddresses.length > 100) {\n throw new Error(\"Maximum 100 owners on creation\");\n }\n\n const combinedSalt = getCombinedSalt(salt, ownerAddresses);\n\n const initCodeHash = getERC1967ProxyInitCodeHash(\n DefaultMaV1Address.IMPLEMENTATION_ADDRESS,\n );\n\n return getContractAddress({\n from: factoryAddress,\n opcode: \"CREATE2\",\n salt: combinedSalt,\n bytecodeHash: initCodeHash,\n });\n};\n\nfunction getCombinedSalt(salt: bigint, owners: Address[]): Hex {\n const encodedOwners = encodeAbiParameters([{ type: \"address[]\" }], [owners]);\n const saltAndOwners = encodeAbiParameters(\n [{ type: \"uint256\" }, { type: \"bytes\" }],\n [salt, encodedOwners],\n );\n return keccak256(saltAndOwners);\n}\n\nfunction getERC1967ProxyInitCodeHash(implementationAddress: Address): Hex {\n const ERC1967_PROXY_BYTECODE =\n \"0x60406080815261042c908138038061001681610218565b93843982019181818403126102135780516001600160a01b038116808203610213576020838101516001600160401b0394919391858211610213570186601f820112156102135780519061007161006c83610253565b610218565b918083528583019886828401011161021357888661008f930161026e565b813b156101b9577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b031916841790556000927fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a28051158015906101b2575b61010b575b855160e790816103458239f35b855194606086019081118682101761019e578697849283926101889952602788527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c87890152660819985a5b195960ca1b8a8901525190845af4913d15610194573d9061017a61006c83610253565b91825281943d92013e610291565b508038808080806100fe565b5060609250610291565b634e487b7160e01b84526041600452602484fd5b50826100f9565b855162461bcd60e51b815260048101859052602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761023d57604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161023d57601f01601f191660200190565b60005b8381106102815750506000910152565b8181015183820152602001610271565b919290156102f357508151156102a5575090565b3b156102ae5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156103065750805190602001fd5b6044604051809262461bcd60e51b825260206004830152610336815180928160248601526020868601910161026e565b601f01601f19168101030190fdfe60806040523615605f5773ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f35b3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f3fea26469706673582212208f3104255ee3c201238ea03e118ee6ec0a2cff51cbfbdc3af1727982a5a959a564736f6c63430008160033\" as const;\n\n const constructorArgs = encodeAbiParameters(\n [{ type: \"address\" }, { type: \"bytes\" }],\n [implementationAddress, \"0x\"],\n );\n\n return keccak256(concatHex([ERC1967_PROXY_BYTECODE, constructorArgs]));\n}\n"]}
1
+ {"version":3,"file":"predictAddress.js","sourceRoot":"","sources":["../../../src/ma-v1/predictAddress.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,SAAS,EACT,kBAAkB,EAClB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,SAAS,GAEV,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,kCAAkC,EAAE,MAAM,2CAA2C,CAAC;AAC/F,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,wBAAwB,EAAE,MAAM,aAAa,CAAC;AASvD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,MAAM,CAAC,MAAM,wCAAwC,GAAG,CAAC,EACvD,IAAI,EACJ,cAAc,EACd,cAAc,GAAG,kBAAkB,CAAC,wBAAwB,GACb,EAAW,EAAE;IAC5D,IAAI,cAAc,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;IACtD,CAAC;IACD,IAAI,cAAc,CAAC,MAAM,GAAG,GAAG,EAAE,CAAC;QAChC,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAC;IACxD,CAAC;IAED,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,EAAE,cAAc,CAAC,CAAC;IAE3D,MAAM,YAAY,GAAG,2BAA2B,CAC9C,kBAAkB,CAAC,sBAAsB,CAC1C,CAAC;IAEF,OAAO,kBAAkB,CAAC;QACxB,IAAI,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AC,WAAW,EAAE,aAAa,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;gBAClD,OAAO,wCAAwC,CAAC;oBAC9C,cAAc;oBACd,IAAI,EAAE,WAAW;oBACjB,cAAc,EAAE,CAAC,GAAG,aAAa,CAAC;iBACnC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,qCAAqC;QACvC,CAAC;IACH,CAAC;IACD,OAAO,wBAAwB,CAAC,MAAM,EAAE;QACtC,OAAO,EAAE,cAAc;QACvB,WAAW;QACX,UAAU;KACX,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n type Address,\n type Client,\n concatHex,\n decodeFunctionData,\n encodeAbiParameters,\n getContractAddress,\n isAddressEqual,\n keccak256,\n type Hex,\n} from \"viem\";\nimport type { EntryPointVersion } from \"viem/account-abstraction\";\nimport { DefaultMaV1Address } from \"./account.js\";\nimport { MultiOwnerModularAccountFactoryAbi } from \"./abis/MultiOwnerModularAccountFactory.js\";\nimport { BaseError } from \"@alchemy/common\";\nimport { getSenderFromFactoryData } from \"../utils.js\";\n\nexport type PredictMultiOwnerModularAccountV1AddressParams = {\n salt: bigint;\n /* Owner addresses must be already deduped, sorted in ascending order, and have the signer address included. */\n ownerAddresses: Address[];\n factoryAddress?: Address;\n};\n\n/**\n * Predicts the address of a MultiOwnerModularAccountV1 smart account before deployment.\n *\n * This function uses CREATE2 to deterministically compute the account address based on the factory address,\n * salt, and owner addresses. The predicted address will match the actual deployed address if the same\n * parameters are used during deployment.\n *\n * @param {PredictMultiOwnerModularAccountV1AddressParams} params The parameters for predicting the account address\n * @param {bigint} params.salt A unique value used to generate different account addresses for the same set of owners\n * @param {Address[]} params.ownerAddresses Array of owner addresses that will control the account. Must be deduplicated, sorted in ascending order, and include the signer address. Cannot be empty and must contain at most 100 addresses.\n * @param {Address} [params.factoryAddress] The factory contract address that will deploy the account. Defaults to the standard MultiOwnerModularAccountV1 factory address.\n * @returns {Address} The predicted address where the account will be deployed\n *\n * @example\n * ```ts\n * const predictedAddress = predictMultiOwnerModularAccountV1Address({\n * salt: 0n,\n * ownerAddresses: [\"0x1234...\", \"0x5678...\"]\n * });\n * ```\n */\nexport const predictMultiOwnerModularAccountV1Address = ({\n salt,\n ownerAddresses,\n factoryAddress = DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY,\n}: PredictMultiOwnerModularAccountV1AddressParams): Address => {\n if (ownerAddresses.length === 0) {\n throw new BaseError(\"Owners array cannot be empty\");\n }\n if (ownerAddresses.length > 100) {\n throw new BaseError(\"Maximum 100 owners on creation\");\n }\n\n const combinedSalt = getCombinedSalt(salt, ownerAddresses);\n\n const initCodeHash = getERC1967ProxyInitCodeHash(\n DefaultMaV1Address.IMPLEMENTATION_ADDRESS,\n );\n\n return getContractAddress({\n from: factoryAddress,\n opcode: \"CREATE2\",\n salt: combinedSalt,\n bytecodeHash: initCodeHash,\n });\n};\n\nfunction getCombinedSalt(salt: bigint, owners: Address[]): Hex {\n const encodedOwners = encodeAbiParameters([{ type: \"address[]\" }], [owners]);\n const saltAndOwners = encodeAbiParameters(\n [{ type: \"uint256\" }, { type: \"bytes\" }],\n [salt, encodedOwners],\n );\n return keccak256(saltAndOwners);\n}\n\nfunction getERC1967ProxyInitCodeHash(implementationAddress: Address): Hex {\n const ERC1967_PROXY_BYTECODE =\n \"0x60406080815261042c908138038061001681610218565b93843982019181818403126102135780516001600160a01b038116808203610213576020838101516001600160401b0394919391858211610213570186601f820112156102135780519061007161006c83610253565b610218565b918083528583019886828401011161021357888661008f930161026e565b813b156101b9577f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc80546001600160a01b031916841790556000927fbc7cd75a20ee27fd9adebab32041f755214dbc6bffa90cc0225b39da2e5c2d3b8480a28051158015906101b2575b61010b575b855160e790816103458239f35b855194606086019081118682101761019e578697849283926101889952602788527f416464726573733a206c6f772d6c6576656c2064656c65676174652063616c6c87890152660819985a5b195960ca1b8a8901525190845af4913d15610194573d9061017a61006c83610253565b91825281943d92013e610291565b508038808080806100fe565b5060609250610291565b634e487b7160e01b84526041600452602484fd5b50826100f9565b855162461bcd60e51b815260048101859052602d60248201527f455243313936373a206e657720696d706c656d656e746174696f6e206973206e60448201526c1bdd08184818dbdb9d1c9858dd609a1b6064820152608490fd5b600080fd5b6040519190601f01601f191682016001600160401b0381118382101761023d57604052565b634e487b7160e01b600052604160045260246000fd5b6001600160401b03811161023d57601f01601f191660200190565b60005b8381106102815750506000910152565b8181015183820152602001610271565b919290156102f357508151156102a5575090565b3b156102ae5790565b60405162461bcd60e51b815260206004820152601d60248201527f416464726573733a2063616c6c20746f206e6f6e2d636f6e74726163740000006044820152606490fd5b8251909150156103065750805190602001fd5b6044604051809262461bcd60e51b825260206004830152610336815180928160248601526020868601910161026e565b601f01601f19168101030190fdfe60806040523615605f5773ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f35b3d90fd5b73ffffffffffffffffffffffffffffffffffffffff7f360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc54166000808092368280378136915af43d82803e15605b573d90f3fea26469706673582212208f3104255ee3c201238ea03e118ee6ec0a2cff51cbfbdc3af1727982a5a959a564736f6c63430008160033\" as const;\n\n const constructorArgs = encodeAbiParameters(\n [{ type: \"address\" }, { type: \"bytes\" }],\n [implementationAddress, \"0x\"],\n );\n\n return keccak256(concatHex([ERC1967_PROXY_BYTECODE, constructorArgs]));\n}\n\nexport type GetMultiOwnerModularAccountV1AddressFromFactoryDataParams = {\n client: Client;\n factoryAddress: Address;\n factoryData: Hex;\n entryPoint: {\n version: EntryPointVersion;\n address: Address;\n };\n};\n\n/**\n * Gets the multi-owner modular account v1 address from factory data.\n * If the factory is a known default, decodes the args and predicts without RPC.\n * Otherwise falls back to calling the entry point's getSenderAddress.\n *\n * @param {GetMultiOwnerModularAccountV1AddressFromFactoryDataParams} params - The parameters\n * @returns {Promise<Address>} The account address\n */\nexport async function getMultiOwnerModularAccountV1AddressFromFactoryData({\n client,\n factoryAddress,\n factoryData,\n entryPoint,\n}: GetMultiOwnerModularAccountV1AddressFromFactoryDataParams): Promise<Address> {\n if (\n isAddressEqual(factoryAddress, DefaultMaV1Address.MULTI_OWNER_MAV1_FACTORY)\n ) {\n try {\n const decoded = decodeFunctionData({\n abi: MultiOwnerModularAccountFactoryAbi,\n data: factoryData,\n });\n if (decoded.functionName === \"createAccount\") {\n const [decodedSalt, decodedOwners] = decoded.args;\n return predictMultiOwnerModularAccountV1Address({\n factoryAddress,\n salt: decodedSalt,\n ownerAddresses: [...decodedOwners],\n });\n }\n } catch {\n // Decode failed, fall through to RPC\n }\n }\n return getSenderFromFactoryData(client, {\n factory: factoryAddress,\n factoryData,\n entryPoint,\n });\n}\n"]}
@@ -1,12 +1,11 @@
1
1
  import { type Address, type Chain, type Client, type Hex, type JsonRpcAccount, type LocalAccount, type Transport } from "viem";
2
- import type { WebAuthnAccount } from "viem/account-abstraction";
3
2
  import { type ModularAccountV2Base } from "./base.js";
4
3
  import type { SignerEntity } from "../types.js";
5
4
  type Mode = "default" | "7702";
6
5
  export type ModularAccountV2 = ModularAccountV2Base & {};
7
6
  export type ToModularAccountV2Params<TMode extends Mode | undefined = Mode | undefined> = {
8
7
  client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;
9
- owner: JsonRpcAccount | LocalAccount | WebAuthnAccount;
8
+ owner: JsonRpcAccount | LocalAccount;
10
9
  deferredAction?: Hex;
11
10
  signerEntity?: SignerEntity;
12
11
  accountAddress?: Address;
@@ -17,11 +16,15 @@ export type ToModularAccountV2Params<TMode extends Mode | undefined = Mode | und
17
16
  factoryData?: never;
18
17
  implementationAddress?: never;
19
18
  } : {
20
- salt?: bigint;
21
19
  factory?: Address;
22
- factoryData?: Hex;
23
20
  implementationAddress?: Address;
24
- });
21
+ } & ({
22
+ salt?: bigint;
23
+ factoryData?: never;
24
+ } | {
25
+ salt?: never;
26
+ factoryData?: Hex;
27
+ }));
25
28
  /**
26
29
  * Creates a MAv2 account.
27
30
  *
@@ -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";
@@ -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 = factory ??
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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,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 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 factory?: never;\n factoryData?: never;\n implementationAddress?: never;\n }\n : {\n salt?: bigint;\n factory?: 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 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 =\n factory ??\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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;aACtB,CAAC,CAAC;YACH,MAAM,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,5 +1,5 @@
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 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
4
  import type { SignatureRequest, SmartAccountWithDecodeCalls } from "../../types.js";
5
5
  export type ValidationDataParams = {
@@ -21,7 +21,7 @@ export type BaseModularAccountV2Implementation = SmartAccountImplementation<type
21
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;