@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.
- package/dist/esm/index.d.ts +4 -3
- package/dist/esm/index.js +3 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/light-account/accounts/account.d.ts +9 -4
- package/dist/esm/light-account/accounts/account.js +29 -18
- package/dist/esm/light-account/accounts/account.js.map +1 -1
- package/dist/esm/light-account/accounts/base.d.ts +4 -4
- package/dist/esm/light-account/accounts/base.js +51 -24
- package/dist/esm/light-account/accounts/base.js.map +1 -1
- package/dist/esm/light-account/accounts/multi-owner-account.d.ts +9 -4
- package/dist/esm/light-account/accounts/multi-owner-account.js +23 -14
- package/dist/esm/light-account/accounts/multi-owner-account.js.map +1 -1
- package/dist/esm/light-account/decorators/multiOwner.js +2 -1
- package/dist/esm/light-account/decorators/multiOwner.js.map +1 -1
- package/dist/esm/light-account/decorators/singleOwner.js +1 -1
- package/dist/esm/light-account/decorators/singleOwner.js.map +1 -1
- package/dist/esm/light-account/lightAccountStaticImpl.d.ts +3 -1
- package/dist/esm/light-account/lightAccountStaticImpl.js +57 -7
- package/dist/esm/light-account/lightAccountStaticImpl.js.map +1 -1
- package/dist/esm/light-account/predictAddress.d.ts +40 -2
- package/dist/esm/light-account/predictAddress.js +83 -3
- package/dist/esm/light-account/predictAddress.js.map +1 -1
- package/dist/esm/light-account/registry.d.ts +3411 -1
- package/dist/esm/light-account/registry.js +33 -1
- package/dist/esm/light-account/registry.js.map +1 -1
- package/dist/esm/light-account/utils.js +1 -1
- package/dist/esm/light-account/utils.js.map +1 -1
- package/dist/esm/ma-v1/accounts/base.d.ts +4 -4
- package/dist/esm/ma-v1/accounts/base.js +1 -1
- package/dist/esm/ma-v1/accounts/base.js.map +1 -1
- package/dist/esm/ma-v1/accounts/multi-owner-account.d.ts +9 -4
- package/dist/esm/ma-v1/accounts/multi-owner-account.js +26 -14
- package/dist/esm/ma-v1/accounts/multi-owner-account.js.map +1 -1
- package/dist/esm/ma-v1/decorators/multiOwner.js +2 -1
- package/dist/esm/ma-v1/decorators/multiOwner.js.map +1 -1
- package/dist/esm/ma-v1/predictAddress.d.ts +20 -1
- package/dist/esm/ma-v1/predictAddress.js +37 -1
- package/dist/esm/ma-v1/predictAddress.js.map +1 -1
- package/dist/esm/ma-v2/accounts/account.d.ts +10 -7
- package/dist/esm/ma-v2/accounts/account.js +24 -43
- package/dist/esm/ma-v2/accounts/account.js.map +1 -1
- package/dist/esm/ma-v2/accounts/base.d.ts +5 -5
- package/dist/esm/ma-v2/accounts/base.js +18 -60
- package/dist/esm/ma-v2/accounts/base.js.map +1 -1
- package/dist/esm/ma-v2/mav2StaticImpl.d.ts +1 -15
- package/dist/esm/ma-v2/mav2StaticImpl.js +0 -33
- package/dist/esm/ma-v2/mav2StaticImpl.js.map +1 -1
- package/dist/esm/ma-v2/predictAddress.d.ts +22 -6
- package/dist/esm/ma-v2/predictAddress.js +46 -12
- package/dist/esm/ma-v2/predictAddress.js.map +1 -1
- package/dist/esm/ma-v2/utils/account.d.ts +0 -3
- package/dist/esm/ma-v2/utils/account.js +2 -4
- package/dist/esm/ma-v2/utils/account.js.map +1 -1
- package/dist/esm/ma-v2/utils/signature.d.ts +1 -12
- package/dist/esm/ma-v2/utils/signature.js +1 -34
- package/dist/esm/ma-v2/utils/signature.js.map +1 -1
- package/dist/esm/types.d.ts +8 -1
- package/dist/esm/types.js.map +1 -1
- package/dist/esm/utils.d.ts +32 -2
- package/dist/esm/utils.js +75 -5
- package/dist/esm/utils.js.map +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/esm/version.js.map +1 -1
- package/dist/types/index.d.ts +4 -3
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/light-account/accounts/account.d.ts +9 -4
- package/dist/types/light-account/accounts/account.d.ts.map +1 -1
- package/dist/types/light-account/accounts/base.d.ts +4 -4
- package/dist/types/light-account/accounts/base.d.ts.map +1 -1
- package/dist/types/light-account/accounts/multi-owner-account.d.ts +9 -4
- package/dist/types/light-account/accounts/multi-owner-account.d.ts.map +1 -1
- package/dist/types/light-account/decorators/multiOwner.d.ts.map +1 -1
- package/dist/types/light-account/decorators/singleOwner.d.ts.map +1 -1
- package/dist/types/light-account/lightAccountStaticImpl.d.ts +3 -1
- package/dist/types/light-account/lightAccountStaticImpl.d.ts.map +1 -1
- package/dist/types/light-account/predictAddress.d.ts +40 -2
- package/dist/types/light-account/predictAddress.d.ts.map +1 -1
- package/dist/types/light-account/registry.d.ts +3411 -1
- package/dist/types/light-account/registry.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/base.d.ts +4 -4
- package/dist/types/ma-v1/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v1/accounts/multi-owner-account.d.ts +9 -4
- package/dist/types/ma-v1/accounts/multi-owner-account.d.ts.map +1 -1
- package/dist/types/ma-v1/decorators/multiOwner.d.ts.map +1 -1
- package/dist/types/ma-v1/predictAddress.d.ts +20 -1
- package/dist/types/ma-v1/predictAddress.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/account.d.ts +10 -7
- package/dist/types/ma-v2/accounts/account.d.ts.map +1 -1
- package/dist/types/ma-v2/accounts/base.d.ts +5 -5
- package/dist/types/ma-v2/accounts/base.d.ts.map +1 -1
- package/dist/types/ma-v2/mav2StaticImpl.d.ts +1 -15
- package/dist/types/ma-v2/mav2StaticImpl.d.ts.map +1 -1
- package/dist/types/ma-v2/predictAddress.d.ts +22 -6
- package/dist/types/ma-v2/predictAddress.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/account.d.ts +0 -3
- package/dist/types/ma-v2/utils/account.d.ts.map +1 -1
- package/dist/types/ma-v2/utils/signature.d.ts +1 -12
- package/dist/types/ma-v2/utils/signature.d.ts.map +1 -1
- package/dist/types/types.d.ts +8 -1
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/utils.d.ts +32 -2
- package/dist/types/utils.d.ts.map +1 -1
- package/dist/types/version.d.ts +1 -1
- package/dist/types/version.d.ts.map +1 -1
- package/package.json +5 -6
- package/src/index.ts +4 -3
- package/src/light-account/accounts/account.ts +42 -26
- package/src/light-account/accounts/base.ts +66 -27
- package/src/light-account/accounts/multi-owner-account.ts +33 -16
- package/src/light-account/decorators/multiOwner.ts +4 -1
- package/src/light-account/decorators/singleOwner.ts +3 -1
- package/src/light-account/lightAccountStaticImpl.ts +84 -11
- package/src/light-account/predictAddress.ts +124 -3
- package/src/light-account/registry.ts +47 -1
- package/src/light-account/utils.ts +1 -1
- package/src/ma-v1/accounts/base.ts +8 -5
- package/src/ma-v1/accounts/multi-owner-account.ts +37 -18
- package/src/ma-v1/decorators/multiOwner.ts +4 -1
- package/src/ma-v1/predictAddress.ts +59 -2
- package/src/ma-v2/accounts/account.ts +42 -55
- package/src/ma-v2/accounts/base.ts +24 -88
- package/src/ma-v2/mav2StaticImpl.ts +1 -52
- package/src/ma-v2/predictAddress.ts +68 -30
- package/src/ma-v2/utils/account.ts +4 -4
- package/src/ma-v2/utils/signature.ts +2 -51
- package/src/types.ts +15 -1
- package/src/utils.ts +119 -6
- package/src/version.ts +1 -1
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -330
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js +0 -260
- package/dist/esm/ma-v2/abis/webAuthnFactoryAbi.js.map +0 -1
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -287
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js +0 -374
- package/dist/esm/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.js.map +0 -1
- package/dist/esm/ma-v2/modules/webauthn-validation/module.d.ts +0 -11
- package/dist/esm/ma-v2/modules/webauthn-validation/module.js +0 -16
- package/dist/esm/ma-v2/modules/webauthn-validation/module.js.map +0 -1
- package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts +0 -331
- package/dist/types/ma-v2/abis/webAuthnFactoryAbi.d.ts.map +0 -1
- package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts +0 -288
- package/dist/types/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.d.ts.map +0 -1
- package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts +0 -12
- package/dist/types/ma-v2/modules/webauthn-validation/module.d.ts.map +0 -1
- package/src/ma-v2/abis/webAuthnFactoryAbi.ts +0 -259
- package/src/ma-v2/modules/webauthn-validation/abis/webauthnValidationAbi.ts +0 -373
- package/src/ma-v2/modules/webauthn-validation/module.ts +0 -28
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
export type * from "./types.js";
|
|
2
|
+
export { chainHas7212 } from "./utils.js";
|
|
1
3
|
export type * from "./light-account/accounts/account.js";
|
|
2
4
|
export { toLightAccount } from "./light-account/accounts/account.js";
|
|
3
5
|
export type * from "./light-account/accounts/multi-owner-account.js";
|
|
@@ -30,14 +32,13 @@ export type * from "./ma-v2/decorators/deferralActions.js";
|
|
|
30
32
|
export { deferralActions } from "./ma-v2/decorators/deferralActions.js";
|
|
31
33
|
export type * from "./ma-v2/decorators/installValidation.js";
|
|
32
34
|
export { installValidationActions } from "./ma-v2/decorators/installValidation.js";
|
|
33
|
-
export { semiModularAccountV2StaticImpl, semiModularAccount7702StaticImpl,
|
|
35
|
+
export { semiModularAccountV2StaticImpl, semiModularAccount7702StaticImpl, } from "./ma-v2/mav2StaticImpl.js";
|
|
34
36
|
export type * from "./ma-v2/mav2StaticImpl.js";
|
|
35
37
|
export { AllowlistModule } from "./ma-v2/modules/allowlist-module/module.js";
|
|
36
38
|
export { NativeTokenLimitModule } from "./ma-v2/modules/native-token-limit-module/module.js";
|
|
37
39
|
export { PaymasterGuardModule } from "./ma-v2/modules/paymaster-guard-module/module.js";
|
|
38
40
|
export { SingleSignerValidationModule } from "./ma-v2/modules/single-signer-validation/module.js";
|
|
39
41
|
export { TimeRangeModule } from "./ma-v2/modules/time-range-module/module.js";
|
|
40
|
-
export { WebAuthnValidationModule } from "./ma-v2/modules/webauthn-validation/module.js";
|
|
41
42
|
export type * from "./ma-v2/permissionBuilder.js";
|
|
42
43
|
export { PermissionBuilder, PermissionType, } from "./ma-v2/permissionBuilder.js";
|
|
43
44
|
export type * from "./ma-v2/predictAddress.js";
|
|
@@ -50,7 +51,7 @@ export { parseDeferredAction, buildDeferredActionDigest, } from "./ma-v2/utils/d
|
|
|
50
51
|
export type * from "./ma-v2/utils/hooks.js";
|
|
51
52
|
export { serializeValidationConfig, serializeHookConfig, } from "./ma-v2/utils/hooks.js";
|
|
52
53
|
export type * from "./ma-v2/utils/signature.js";
|
|
53
|
-
export { packUOSignature, pack1271Signature, toReplaySafeTypedData,
|
|
54
|
+
export { packUOSignature, pack1271Signature, toReplaySafeTypedData, } from "./ma-v2/utils/signature.js";
|
|
54
55
|
export { EntityIdOverrideError } from "./errors/EntityIdOverrideError.js";
|
|
55
56
|
export { InvalidDeferredActionNonceError } from "./errors/InvalidDeferredActionNonceError.js";
|
|
56
57
|
export { InvalidEntityIdError } from "./errors/InvalidEntityIdError.js";
|
package/dist/esm/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export { chainHas7212 } from "./utils.js";
|
|
1
2
|
export { toLightAccount } from "./light-account/accounts/account.js";
|
|
2
3
|
export { toMultiOwnerLightAccount } from "./light-account/accounts/multi-owner-account.js";
|
|
3
4
|
export { singleOwnerLightAccountActions } from "./light-account/decorators/singleOwner.js";
|
|
@@ -16,20 +17,19 @@ export { toModularAccountV2 } from "./ma-v2/accounts/account.js";
|
|
|
16
17
|
export { toModularAccountV2Base } from "./ma-v2/accounts/base.js";
|
|
17
18
|
export { deferralActions } from "./ma-v2/decorators/deferralActions.js";
|
|
18
19
|
export { installValidationActions } from "./ma-v2/decorators/installValidation.js";
|
|
19
|
-
export { semiModularAccountV2StaticImpl, semiModularAccount7702StaticImpl,
|
|
20
|
+
export { semiModularAccountV2StaticImpl, semiModularAccount7702StaticImpl, } from "./ma-v2/mav2StaticImpl.js";
|
|
20
21
|
// Modules
|
|
21
22
|
export { AllowlistModule } from "./ma-v2/modules/allowlist-module/module.js";
|
|
22
23
|
export { NativeTokenLimitModule } from "./ma-v2/modules/native-token-limit-module/module.js";
|
|
23
24
|
export { PaymasterGuardModule } from "./ma-v2/modules/paymaster-guard-module/module.js";
|
|
24
25
|
export { SingleSignerValidationModule } from "./ma-v2/modules/single-signer-validation/module.js";
|
|
25
26
|
export { TimeRangeModule } from "./ma-v2/modules/time-range-module/module.js";
|
|
26
|
-
export { WebAuthnValidationModule } from "./ma-v2/modules/webauthn-validation/module.js";
|
|
27
27
|
export { PermissionBuilder, PermissionType, } from "./ma-v2/permissionBuilder.js";
|
|
28
28
|
export { predictModularAccountV2Address } from "./ma-v2/predictAddress.js";
|
|
29
29
|
export { DefaultAddress, DefaultModuleAddress, DEFAULT_OWNER_ENTITY_ID, EXECUTE_USER_OP_SELECTOR, getMAV2UpgradeToData, buildFullNonceKey, serializeModuleEntity, isModularAccountV2, } from "./ma-v2/utils/account.js";
|
|
30
30
|
export { parseDeferredAction, buildDeferredActionDigest, } from "./ma-v2/utils/deferredActions.js";
|
|
31
31
|
export { serializeValidationConfig, serializeHookConfig, } from "./ma-v2/utils/hooks.js";
|
|
32
|
-
export { packUOSignature, pack1271Signature, toReplaySafeTypedData,
|
|
32
|
+
export { packUOSignature, pack1271Signature, toReplaySafeTypedData, } from "./ma-v2/utils/signature.js";
|
|
33
33
|
// Errors
|
|
34
34
|
export { EntityIdOverrideError } from "./errors/EntityIdOverrideError.js";
|
|
35
35
|
export { InvalidDeferredActionNonceError } from "./errors/InvalidDeferredActionNonceError.js";
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO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"./types.js\";\n\nexport { chainHas7212 } from \"./utils.js\";\n\n// LightAccount\nexport type * from \"./light-account/accounts/account.js\";\nexport { toLightAccount } from \"./light-account/accounts/account.js\";\n\nexport type * from \"./light-account/accounts/multi-owner-account.js\";\nexport { toMultiOwnerLightAccount } from \"./light-account/accounts/multi-owner-account.js\";\n\n// TODO(v5): Something to consider for v5 - can we cut the exports for the account-specific actions\n// from the public interface, and just consume these internally with account + rely on the standard\n// bundlerClient actions for performing state writes (i.e. rotating owners)? I'm not sure it's useful\n// to consumers outside of attaching to instances of a client with the right action.\nexport type * from \"./light-account/decorators/singleOwner.js\";\nexport { singleOwnerLightAccountActions } from \"./light-account/decorators/singleOwner.js\";\n\nexport type * from \"./light-account/decorators/multiOwner.js\";\nexport { multiOwnerLightAccountActions } from \"./light-account/decorators/multiOwner.js\";\n\nexport type * from \"./light-account/predictAddress.js\";\nexport {\n predictLightAccountAddress,\n predictMultiOwnerLightAccountAddress,\n} from \"./light-account/predictAddress.js\";\n\nexport { AccountVersionRegistry } from \"./light-account/registry.js\";\nexport type * from \"./light-account/registry.js\";\nexport {\n defaultLightAccountVersion,\n getLightAccountImplAddress,\n LightAccountUnsupported1271Factories,\n LightAccountUnsupported1271Impls,\n} from \"./light-account/utils.js\";\n\nexport {\n lightAccountStaticImplV1_0_1,\n lightAccountStaticImplV1_0_2,\n lightAccountStaticImplV1_1_0,\n lightAccountStaticImplV2_0_0,\n multiOwnerLightAccountStaticImplV2_0_0,\n} from \"./light-account/lightAccountStaticImpl.js\";\n\n// ModularAccountV1\nexport type * from \"./ma-v1/accounts/base.js\";\nexport { toModularAccountV1Base } from \"./ma-v1/accounts/base.js\";\n\nexport type * from \"./ma-v1/accounts/multi-owner-account.js\";\nexport { toMultiOwnerModularAccountV1 } from \"./ma-v1/accounts/multi-owner-account.js\";\n\nexport type * from \"./ma-v1/decorators/multiOwner.js\";\nexport { multiOwnerModularAccountV1Actions } from \"./ma-v1/decorators/multiOwner.js\";\n\nexport type * from \"./ma-v1/predictAddress.js\";\nexport { predictMultiOwnerModularAccountV1Address } from \"./ma-v1/predictAddress.js\";\n\nexport { multiOwnerModularAccountStaticImpl } from \"./ma-v1/mav1StaticImpl.js\";\n\nexport {\n DefaultMaV1Address,\n DefaultMaV1PluginAddress,\n} from \"./ma-v1/account.js\";\n\n// ModularAccountV2\nexport type * from \"./ma-v2/accounts/account.js\";\nexport { toModularAccountV2 } from \"./ma-v2/accounts/account.js\";\n\nexport type * from \"./ma-v2/accounts/base.js\";\nexport { toModularAccountV2Base } from \"./ma-v2/accounts/base.js\";\n\nexport type * from \"./ma-v2/decorators/deferralActions.js\";\nexport { deferralActions } from \"./ma-v2/decorators/deferralActions.js\";\n\nexport type * from \"./ma-v2/decorators/installValidation.js\";\nexport { installValidationActions } from \"./ma-v2/decorators/installValidation.js\";\n\nexport {\n semiModularAccountV2StaticImpl,\n semiModularAccount7702StaticImpl,\n} from \"./ma-v2/mav2StaticImpl.js\";\nexport type * from \"./ma-v2/mav2StaticImpl.js\";\n\n// Modules\nexport { AllowlistModule } from \"./ma-v2/modules/allowlist-module/module.js\";\nexport { NativeTokenLimitModule } from \"./ma-v2/modules/native-token-limit-module/module.js\";\nexport { PaymasterGuardModule } from \"./ma-v2/modules/paymaster-guard-module/module.js\";\nexport { SingleSignerValidationModule } from \"./ma-v2/modules/single-signer-validation/module.js\";\nexport { TimeRangeModule } from \"./ma-v2/modules/time-range-module/module.js\";\n\nexport type * from \"./ma-v2/permissionBuilder.js\";\nexport {\n PermissionBuilder,\n PermissionType,\n} from \"./ma-v2/permissionBuilder.js\";\n\nexport type * from \"./ma-v2/predictAddress.js\";\nexport { predictModularAccountV2Address } from \"./ma-v2/predictAddress.js\";\n\nexport type * from \"./ma-v2/types.js\";\n\nexport type * from \"./ma-v2/utils/account.js\";\nexport {\n DefaultAddress,\n DefaultModuleAddress,\n DEFAULT_OWNER_ENTITY_ID,\n EXECUTE_USER_OP_SELECTOR,\n getMAV2UpgradeToData,\n buildFullNonceKey,\n serializeModuleEntity,\n isModularAccountV2,\n} from \"./ma-v2/utils/account.js\";\n\nexport type * from \"./ma-v2/utils/deferredActions.js\";\nexport {\n parseDeferredAction,\n buildDeferredActionDigest,\n} from \"./ma-v2/utils/deferredActions.js\";\n\nexport type * from \"./ma-v2/utils/hooks.js\";\nexport {\n serializeValidationConfig,\n serializeHookConfig,\n} from \"./ma-v2/utils/hooks.js\";\n\nexport type * from \"./ma-v2/utils/signature.js\";\nexport {\n packUOSignature,\n pack1271Signature,\n toReplaySafeTypedData,\n} from \"./ma-v2/utils/signature.js\";\n\n// Errors\nexport { EntityIdOverrideError } from \"./errors/EntityIdOverrideError.js\";\nexport { InvalidDeferredActionNonceError } from \"./errors/InvalidDeferredActionNonceError.js\";\nexport { InvalidEntityIdError } from \"./errors/InvalidEntityIdError.js\";\nexport { InvalidNonceKeyError } from \"./errors/InvalidNonceKeyError.js\";\nexport { InvalidOwnerError } from \"./errors/InvalidOwnerError.js\";\nexport {\n PermissionBuilderError,\n RootPermissionOnlyError,\n AccountAddressAsTargetError,\n DuplicateTargetAddressError,\n NoFunctionsProvidedError,\n ExpiredDeadlineError,\n DeadlineOverLimitError,\n ValidationConfigUnsetError,\n MultipleNativeTokenTransferError,\n ZeroAddressError,\n MultipleGasLimitError,\n UnsupportedPermissionTypeError,\n SelectorNotAllowed,\n} from \"./errors/permissionBuilderErrors.js\";\n"]}
|
|
@@ -8,15 +8,20 @@ export type LightAccount<TLightAccountVersion extends LightAccountVersion<"Light
|
|
|
8
8
|
export type ToLightAccountParams<TLightAccountVersion extends LightAccountVersion<"LightAccount"> = LightAccountVersion<"LightAccount">> = {
|
|
9
9
|
client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;
|
|
10
10
|
owner: JsonRpcAccount | LocalAccount;
|
|
11
|
-
salt?: bigint;
|
|
12
11
|
accountAddress?: Address;
|
|
13
|
-
|
|
12
|
+
factory?: Address;
|
|
14
13
|
version?: TLightAccountVersion;
|
|
15
|
-
}
|
|
14
|
+
} & ({
|
|
15
|
+
salt?: bigint;
|
|
16
|
+
factoryData?: never;
|
|
17
|
+
} | {
|
|
18
|
+
salt?: never;
|
|
19
|
+
factoryData?: Hex;
|
|
20
|
+
});
|
|
16
21
|
/**
|
|
17
22
|
* Creates a light account.
|
|
18
23
|
*
|
|
19
24
|
* @param {ToLightAccountParams} param0 - The parameters for creating a light account.
|
|
20
25
|
* @returns {Promise<LightAccount<TSigner, TLightAccountVersion>>} A light account.
|
|
21
26
|
*/
|
|
22
|
-
export declare function toLightAccount<TLightAccountVersion extends LightAccountVersion<"LightAccount"> = LightAccountVersion<"LightAccount">>({ client, owner, salt: salt_, accountAddress: accountAddress_, version,
|
|
27
|
+
export declare function toLightAccount<TLightAccountVersion extends LightAccountVersion<"LightAccount"> = LightAccountVersion<"LightAccount">>({ client, owner, salt: salt_, accountAddress: accountAddress_, version, factory, factoryData: factoryData_, }: ToLightAccountParams<TLightAccountVersion>): Promise<LightAccount<TLightAccountVersion>>;
|
|
@@ -4,8 +4,8 @@ import { LightAccountAbi_v1 } from "../abis/LightAccountAbi_v1.js";
|
|
|
4
4
|
import { LightAccountAbi_v2 } from "../abis/LightAccountAbi_v2.js";
|
|
5
5
|
import { LightAccountFactoryAbi_v1 } from "../abis/LightAccountFactoryAbi_v1.js";
|
|
6
6
|
import { LightAccountFactoryAbi_v2 } from "../abis/LightAccountFactoryAbi_v2.js";
|
|
7
|
-
import { predictLightAccountAddress } from "../predictAddress.js";
|
|
8
|
-
import { AccountVersionRegistry, } from "../registry.js";
|
|
7
|
+
import { getLightAccountAddressFromFactoryData, predictLightAccountAddress, } from "../predictAddress.js";
|
|
8
|
+
import { AccountVersionRegistry, isLightAccountVersion2, } from "../registry.js";
|
|
9
9
|
import { LightAccountUnsupported1271Factories, defaultLightAccountVersion, } from "../utils.js";
|
|
10
10
|
import { toLightAccountBase } from "./base.js";
|
|
11
11
|
import { BaseError, lowerAddress } from "@alchemy/common";
|
|
@@ -17,34 +17,45 @@ import { LOGGER } from "../../logger.js";
|
|
|
17
17
|
* @param {ToLightAccountParams} param0 - The parameters for creating a light account.
|
|
18
18
|
* @returns {Promise<LightAccount<TSigner, TLightAccountVersion>>} A light account.
|
|
19
19
|
*/
|
|
20
|
-
export async function toLightAccount({ client, owner, salt: salt_ = 0n, accountAddress: accountAddress_, version = defaultLightAccountVersion(),
|
|
20
|
+
export async function toLightAccount({ client, owner, salt: salt_ = 0n, accountAddress: accountAddress_, version = defaultLightAccountVersion(), factory = AccountVersionRegistry.LightAccount[version].factoryAddress, factoryData: factoryData_, }) {
|
|
21
21
|
LOGGER.debug("toLightAccount:start", {
|
|
22
22
|
version,
|
|
23
23
|
hasAccountAddress: !!accountAddress_,
|
|
24
24
|
});
|
|
25
|
-
const accountAbi = version
|
|
26
|
-
|
|
25
|
+
const accountAbi = isLightAccountVersion2(version)
|
|
26
|
+
? LightAccountAbi_v2
|
|
27
|
+
: LightAccountAbi_v1;
|
|
28
|
+
const factoryAbi = isLightAccountVersion2(version)
|
|
27
29
|
? LightAccountFactoryAbi_v2
|
|
28
30
|
: LightAccountFactoryAbi_v1;
|
|
29
|
-
const salt = LightAccountUnsupported1271Factories.has(lowerAddress(
|
|
31
|
+
const salt = LightAccountUnsupported1271Factories.has(lowerAddress(factory))
|
|
30
32
|
? 0n
|
|
31
33
|
: salt_;
|
|
32
34
|
const accountAddress = accountAddress_ ??
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
(factoryData_
|
|
36
|
+
? await getLightAccountAddressFromFactoryData({
|
|
37
|
+
client,
|
|
38
|
+
factoryAddress: factory,
|
|
39
|
+
factoryData: factoryData_,
|
|
40
|
+
entryPoint: AccountVersionRegistry["LightAccount"][version].entryPoint,
|
|
41
|
+
version,
|
|
42
|
+
})
|
|
43
|
+
: predictLightAccountAddress({
|
|
44
|
+
factoryAddress: factory,
|
|
45
|
+
salt,
|
|
46
|
+
ownerAddress: owner.address,
|
|
47
|
+
version,
|
|
48
|
+
}));
|
|
39
49
|
LOGGER.debug("toLightAccount:address-resolved", { accountAddress });
|
|
40
50
|
const getFactoryArgs = async () => {
|
|
41
|
-
const factoryData =
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
51
|
+
const factoryData = factoryData_ ??
|
|
52
|
+
encodeFunctionData({
|
|
53
|
+
abi: factoryAbi,
|
|
54
|
+
functionName: "createAccount",
|
|
55
|
+
args: [owner.address, salt],
|
|
56
|
+
});
|
|
46
57
|
return {
|
|
47
|
-
factory
|
|
58
|
+
factory,
|
|
48
59
|
factoryData,
|
|
49
60
|
};
|
|
50
61
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAQnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,
|
|
1
|
+
{"version":3,"file":"account.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,GAQnB,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,s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,YAAY,EACZ,cAAc,CACf,CAAC;YACF,MAAM,KAAK,GAAG,MAAM,kBAAkB,CAAC;gBACrC,OAAO,EAAE,cAAc;gBACvB,GAAG,EAAE,UAAU;gBACf,YAAY,EAAE,OAAO;aACtB,CAAC,CAAC;YAEH,IAAI,KAAK,IAAI,IAAI,EAAE,CAAC;gBAClB,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE,EAAE,cAAc,EAAE,CAAC,CAAC;gBAC3D,MAAM,IAAI,SAAS,CAAC,8BAA8B,CAAC,CAAC;YACtD,CAAC;YAED,MAAM,CAAC,KAAK,CAAC,yBAAyB,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC;YACnD,OAAO,KAAK,CAAC;QACf,CAAC;KACF,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 Transport,\n} from \"viem\";\nimport { readContract } from \"viem/actions\";\nimport { LightAccountAbi_v1 } from \"../abis/LightAccountAbi_v1.js\";\nimport { LightAccountAbi_v2 } from \"../abis/LightAccountAbi_v2.js\";\nimport { LightAccountFactoryAbi_v1 } from \"../abis/LightAccountFactoryAbi_v1.js\";\nimport { LightAccountFactoryAbi_v2 } from \"../abis/LightAccountFactoryAbi_v2.js\";\nimport {\n getLightAccountAddressFromFactoryData,\n predictLightAccountAddress,\n} from \"../predictAddress.js\";\nimport {\n type LightAccountVersion,\n AccountVersionRegistry,\n isLightAccountVersion2,\n} from \"../registry.js\";\nimport {\n LightAccountUnsupported1271Factories,\n defaultLightAccountVersion,\n} from \"../utils.js\";\nimport { toLightAccountBase, type LightAccountBase } from \"./base.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport { getAction } from \"viem/utils\";\nimport { LOGGER } from \"../../logger.js\";\n\nexport type LightAccount<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n> = LightAccountBase<\"LightAccount\", TLightAccountVersion> & {\n encodeTransferOwnership: (newOwner: Address) => Hex;\n getOwnerAddress: () => Promise<Address>;\n};\n\nexport type ToLightAccountParams<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n> = {\n client: Client<Transport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n owner: JsonRpcAccount | LocalAccount;\n accountAddress?: Address;\n factory?: Address;\n version?: TLightAccountVersion;\n} & (\n | { salt?: bigint; factoryData?: never }\n | { salt?: never; factoryData?: Hex }\n);\n\n/**\n * Creates a light account.\n *\n * @param {ToLightAccountParams} param0 - The parameters for creating a light account.\n * @returns {Promise<LightAccount<TSigner, TLightAccountVersion>>} A light account.\n */\nexport async function toLightAccount<\n TLightAccountVersion extends\n LightAccountVersion<\"LightAccount\"> = LightAccountVersion<\"LightAccount\">,\n>({\n client,\n owner,\n salt: salt_ = 0n,\n accountAddress: accountAddress_,\n version = defaultLightAccountVersion() as TLightAccountVersion,\n factory = AccountVersionRegistry.LightAccount[version].factoryAddress,\n factoryData: factoryData_,\n}: ToLightAccountParams<TLightAccountVersion>): Promise<\n LightAccount<TLightAccountVersion>\n> {\n LOGGER.debug(\"toLightAccount:start\", {\n version,\n hasAccountAddress: !!accountAddress_,\n });\n\n const accountAbi = isLightAccountVersion2(version)\n ? LightAccountAbi_v2\n : LightAccountAbi_v1;\n const factoryAbi = isLightAccountVersion2(version)\n ? LightAccountFactoryAbi_v2\n : LightAccountFactoryAbi_v1;\n\n const salt = LightAccountUnsupported1271Factories.has(lowerAddress(factory))\n ? 0n\n : salt_;\n\n const accountAddress =\n accountAddress_ ??\n (factoryData_\n ? await getLightAccountAddressFromFactoryData({\n client,\n factoryAddress: factory,\n factoryData: factoryData_,\n entryPoint:\n AccountVersionRegistry[\"LightAccount\"][version].entryPoint,\n version,\n })\n : predictLightAccountAddress({\n factoryAddress: factory,\n salt,\n ownerAddress: owner.address,\n version,\n }));\n\n LOGGER.debug(\"toLightAccount:address-resolved\", { accountAddress });\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: factoryAbi,\n functionName: \"createAccount\",\n args: [owner.address, salt],\n });\n\n return {\n factory,\n factoryData,\n };\n };\n\n const baseAccount = await toLightAccountBase({\n client,\n owner,\n abi: accountAbi,\n accountAddress,\n type: \"LightAccount\",\n version,\n getFactoryArgs,\n });\n\n return {\n ...baseAccount,\n\n encodeTransferOwnership: (newOwner: Address) => {\n return encodeFunctionData({\n abi: accountAbi,\n functionName: \"transferOwnership\",\n args: [newOwner],\n });\n },\n\n async getOwnerAddress(): Promise<Address> {\n LOGGER.debug(\"getOwnerAddress:start\", { accountAddress });\n const readContractAction = getAction(\n client,\n readContract,\n \"readContract\",\n );\n const owner = await readContractAction({\n address: accountAddress,\n abi: accountAbi,\n functionName: \"owner\",\n });\n\n if (owner == null) {\n LOGGER.error(\"getOwnerAddress:failed\", { accountAddress });\n throw new BaseError(\"could not get on-chain owner\");\n }\n\n LOGGER.debug(\"getOwnerAddress:success\", { owner });\n return owner;\n },\n };\n}\n"]}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { type Abi, type Address, type Chain, type Client, type Hex, type JsonRpcAccount, type LocalAccount, type Transport } from "viem";
|
|
2
|
-
import { type
|
|
2
|
+
import { type SmartAccountImplementation } from "viem/account-abstraction";
|
|
3
3
|
import type { EntryPointFromAccountRegistry, LightAccountType, LightAccountVersion } from "../registry.js";
|
|
4
|
-
import type { SignatureRequest } from "../../types.js";
|
|
4
|
+
import type { SignatureRequest, SmartAccountWithDecodeCalls } from "../../types.js";
|
|
5
5
|
export type BaseLightAccountImplementation<TLightAccountType extends LightAccountType = LightAccountType, TLightAccountVersion extends LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>> = SmartAccountImplementation<EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>["abi"], EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>["version"], {
|
|
6
6
|
getLightAccountVersion: () => TLightAccountVersion;
|
|
7
|
-
|
|
7
|
+
smartAccountType: TLightAccountType;
|
|
8
8
|
encodeUpgradeToAndCall: (params: {
|
|
9
9
|
upgradeToAddress: Address;
|
|
10
10
|
upgradeToInitData: Hex;
|
|
@@ -12,7 +12,7 @@ export type BaseLightAccountImplementation<TLightAccountType extends LightAccoun
|
|
|
12
12
|
prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;
|
|
13
13
|
formatSignature: (signature: Hex) => Promise<Hex>;
|
|
14
14
|
}, false>;
|
|
15
|
-
export type LightAccountBase<TLightAccountType extends LightAccountType = LightAccountType, TLightAccountVersion extends LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>> =
|
|
15
|
+
export type LightAccountBase<TLightAccountType extends LightAccountType = LightAccountType, TLightAccountVersion extends LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>> = SmartAccountWithDecodeCalls<BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>>;
|
|
16
16
|
export type ToLightAccountBaseParams<TLightAccountType extends LightAccountType, TLightAccountVersion extends LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>, TTransport extends Transport = Transport> = {
|
|
17
17
|
client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;
|
|
18
18
|
abi: Abi;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { getUserOperationHash, toSmartAccount, } from "viem/account-abstraction";
|
|
1
|
+
import { concatHex, encodeFunctionData, fromHex, hashMessage, hashTypedData, trim, } from "viem";
|
|
2
|
+
import { getUserOperationHash, getUserOperationTypedData, toSmartAccount, } from "viem/account-abstraction";
|
|
3
3
|
import { getStorageAt, signMessage, signTypedData } from "viem/actions";
|
|
4
4
|
import { EIP1967_PROXY_IMPL_STORAGE_SLOT } from "../utils.js";
|
|
5
|
-
import { AccountVersionRegistry } from "../registry.js";
|
|
5
|
+
import { AccountVersionRegistry, isLightAccountVersion2 } from "../registry.js";
|
|
6
6
|
import { encodeCallsLA as encodeCalls, decodeCallsLA as decodeCalls, } from "./calldataCodec.js";
|
|
7
7
|
import { BaseError, lowerAddress } from "@alchemy/common";
|
|
8
8
|
import { getAction } from "viem/utils";
|
|
@@ -68,6 +68,8 @@ export async function toLightAccountBase({ client, abi, accountAddress, owner, t
|
|
|
68
68
|
data: get1271Wrapper(messageHash, "1"),
|
|
69
69
|
};
|
|
70
70
|
case "v2.0.0":
|
|
71
|
+
case "v2.1.0":
|
|
72
|
+
case "v2.2.0":
|
|
71
73
|
return {
|
|
72
74
|
type: "eth_signTypedData_v4",
|
|
73
75
|
data: get1271Wrapper(messageHash, "2"),
|
|
@@ -77,8 +79,8 @@ export async function toLightAccountBase({ client, abi, accountAddress, owner, t
|
|
|
77
79
|
}
|
|
78
80
|
};
|
|
79
81
|
const formatSignature = async (signature) => {
|
|
80
|
-
return version
|
|
81
|
-
?
|
|
82
|
+
return isLightAccountVersion2(version)
|
|
83
|
+
? concatHex([SignaturePrefix.EOA, signature])
|
|
82
84
|
: signature;
|
|
83
85
|
};
|
|
84
86
|
const entryPoint = AccountVersionRegistry[type][version].entryPoint;
|
|
@@ -103,7 +105,9 @@ export async function toLightAccountBase({ client, abi, accountAddress, owner, t
|
|
|
103
105
|
case "v1.1.0":
|
|
104
106
|
return signature;
|
|
105
107
|
case "v2.0.0":
|
|
106
|
-
|
|
108
|
+
case "v2.1.0":
|
|
109
|
+
case "v2.2.0":
|
|
110
|
+
return concatHex([SignaturePrefix.EOA, signature]);
|
|
107
111
|
default:
|
|
108
112
|
throw new BaseError(`Unknown version ${type} of ${String(version)}`);
|
|
109
113
|
}
|
|
@@ -140,26 +144,49 @@ export async function toLightAccountBase({ client, abi, accountAddress, owner, t
|
|
|
140
144
|
},
|
|
141
145
|
async signUserOperation(parameters) {
|
|
142
146
|
const { chainId = client.chain.id, ...userOperation } = parameters;
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
147
|
+
let signature;
|
|
148
|
+
switch (version) {
|
|
149
|
+
case "v1.0.1":
|
|
150
|
+
case "v1.0.2":
|
|
151
|
+
case "v1.1.0":
|
|
152
|
+
case "v2.0.0":
|
|
153
|
+
const userOpHash = getUserOperationHash({
|
|
154
|
+
chainId,
|
|
155
|
+
entryPointAddress: entryPoint.address,
|
|
156
|
+
entryPointVersion: entryPoint.version,
|
|
157
|
+
userOperation: {
|
|
158
|
+
...userOperation,
|
|
159
|
+
sender: accountAddress,
|
|
160
|
+
},
|
|
161
|
+
});
|
|
162
|
+
const signMessageAction = getAction(client, signMessage, "signMessage");
|
|
163
|
+
signature = await signMessageAction({
|
|
164
|
+
account: owner,
|
|
165
|
+
message: { raw: userOpHash },
|
|
166
|
+
});
|
|
167
|
+
break;
|
|
168
|
+
case "v2.1.0":
|
|
169
|
+
case "v2.2.0":
|
|
170
|
+
const signTypedDataAction = getAction(client, signTypedData, "signTypedData");
|
|
171
|
+
signature = await signTypedDataAction({
|
|
172
|
+
account: owner,
|
|
173
|
+
...getUserOperationTypedData({
|
|
174
|
+
chainId,
|
|
175
|
+
entryPointAddress: entryPoint.address,
|
|
176
|
+
userOperation: {
|
|
177
|
+
...userOperation,
|
|
178
|
+
sender: accountAddress,
|
|
179
|
+
},
|
|
180
|
+
}),
|
|
181
|
+
});
|
|
182
|
+
break;
|
|
183
|
+
default:
|
|
184
|
+
throw new BaseError(`Unknown version ${type} of ${String(version)}`);
|
|
185
|
+
}
|
|
186
|
+
return formatSignature(signature);
|
|
160
187
|
},
|
|
161
188
|
extend: {
|
|
162
|
-
|
|
189
|
+
smartAccountType: type,
|
|
163
190
|
getLightAccountVersion: () => version,
|
|
164
191
|
encodeUpgradeToAndCall,
|
|
165
192
|
prepareSignature,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,aAAa,EACb,IAAI,GAUL,MAAM,MAAM,CAAC;AACd,OAAO,EACL,oBAAoB,EACpB,cAAc,GAGf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAMxE,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,EACL,aAAa,IAAI,WAAW,EAC5B,aAAa,IAAI,WAAW,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAK1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,MAAM;IACX,QAAQ,EAAE,MAAM;IAChB,kBAAkB,EAAE,MAAM;CAClB,CAAC;AAmDX,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAKtC,EACA,MAAM,EACN,GAAG,EACH,cAAc,EACd,KAAK,EACL,IAAI,EACJ,OAAO,EACP,cAAc,GAKf;IACC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EACpC,gBAAgB,EAChB,iBAAiB,GAIlB,EAAgB,EAAE;QACjB,MAAM,qBAAqB,GACzB,MAAM,CAAC,MAAM,CACX,sBAAsB,CAAC,IAAI,CAAC,CAE/B,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC;QAEtC,MAAM,kBAAkB,GAAG,SAAS,CAAC,MAAM,EAAE,YAAY,EAAE,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,GAAG,EAAE,SAAS,CAAC,CAAC;gBAC7C,CAAC,CAAC,SAAS,CAAC;QAChB,CAAC;QAED,MAAM,EAAE;YACN,MAAM,EAAE,IAAI;YACZ,sBAAsB,EAAE,GAAG,EAAE,CAAC,OAAO;YACrC,sBAAsB;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n concat,\n concatHex,\n encodeFunctionData,\n fromHex,\n hashMessage,\n hashTypedData,\n trim,\n type Abi,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n getUserOperationHash,\n toSmartAccount,\n type SmartAccount,\n type SmartAccountImplementation,\n} from \"viem/account-abstraction\";\nimport { getStorageAt, signMessage, signTypedData } from \"viem/actions\";\nimport type {\n EntryPointFromAccountRegistry,\n LightAccountType,\n LightAccountVersion,\n} from \"../registry.js\";\nimport { EIP1967_PROXY_IMPL_STORAGE_SLOT } from \"../utils.js\";\nimport { AccountVersionRegistry } from \"../registry.js\";\nimport {\n encodeCallsLA as encodeCalls,\n decodeCallsLA as decodeCalls,\n} from \"./calldataCodec.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport type {\n SignatureRequest,\n StaticSmartAccountImplementation,\n} from \"../../types.js\";\nimport { getAction } from \"viem/utils\";\n\nconst SignaturePrefix = {\n EOA: \"0x00\",\n CONTRACT: \"0x01\",\n CONTRACT_WITH_ADDR: \"0x02\",\n} as const;\n\nexport type BaseLightAccountImplementation<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountImplementation<\n EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>[\"abi\"],\n EntryPointFromAccountRegistry<\n TLightAccountType,\n TLightAccountVersion\n >[\"version\"],\n {\n getLightAccountVersion: () => TLightAccountVersion;\n source: TLightAccountType;\n encodeUpgradeToAndCall: (params: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }) => Promise<Hex>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type LightAccountBase<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccount<\n BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>\n>;\n\nexport type ToLightAccountBaseParams<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n abi: Abi;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n type: TLightAccountType;\n version: TLightAccountVersion;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n};\n\nexport async function toLightAccountBase<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n>({\n client,\n abi,\n accountAddress,\n owner,\n type,\n version,\n getFactoryArgs,\n}: ToLightAccountBaseParams<\n TLightAccountType,\n TLightAccountVersion,\n TTransport\n>): Promise<LightAccountBase<TLightAccountType, TLightAccountVersion>> {\n const encodeUpgradeToAndCall = async ({\n upgradeToAddress,\n upgradeToInitData,\n }: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }): Promise<Hex> => {\n const expectedImplAddresses = (\n Object.values(\n AccountVersionRegistry[type],\n ) as StaticSmartAccountImplementation<false>[]\n ).map((x) => x.accountImplementation);\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n // TODO(v5): This is a super fragile workflow, and we should consider not supporting this on the SmartAccount level in v5.\n const storage = await getStorageAtAction({\n address: accountAddress,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n // Only upgrade undeployed accounts (storage 0) or deployed light accounts, else error.\n if (\n fromHex(storage, \"number\") !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return encodeFunctionData({\n abi,\n functionName: \"upgradeToAndCall\",\n args: [upgradeToAddress, upgradeToInitData],\n });\n };\n\n const get1271Wrapper = (\n hashedMessage: Hex,\n version: string,\n ): TypedDataDefinition => {\n return {\n // EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\n // https://github.com/alchemyplatform/light-account/blob/main/src/LightAccount.sol#L236\n domain: {\n chainId: client.chain.id,\n name: type,\n verifyingContract: accountAddress,\n version,\n },\n types: {\n LightAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: hashedMessage,\n },\n primaryType: \"LightAccountMessage\",\n };\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const messageHash =\n params.type === \"eth_signTypedData_v4\"\n ? hashTypedData(params.data)\n : hashMessage(params.data);\n\n switch (version) {\n case \"v1.0.1\":\n return params;\n case \"v1.0.2\":\n throw new BaseError(\n `Version ${String(version)} of LightAccount doesn't support 1271`,\n );\n case \"v1.1.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"1\"),\n };\n case \"v2.0.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"2\"),\n };\n default:\n throw new BaseError(\n `Unknown version ${String(version)} of LightAccount`,\n );\n }\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return version === \"v2.0.0\"\n ? concat([SignaturePrefix.EOA, signature])\n : signature;\n };\n\n const entryPoint = (\n AccountVersionRegistry[type][version] as StaticSmartAccountImplementation\n ).entryPoint;\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n return encodeCalls(calls);\n },\n\n async decodeCalls(data) {\n return decodeCalls(data, accountAddress);\n },\n\n async getStubSignature() {\n const signature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n return signature;\n case \"v2.0.0\":\n return concat([SignaturePrefix.EOA, signature]);\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\n },\n\n async signMessage({ message }) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signTypedData(params) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n const userOpHash = getUserOperationHash({\n chainId,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n\n const signature = await signMessageAction({\n account: owner,\n message: { raw: userOpHash },\n });\n\n return version === \"v2.0.0\"\n ? concatHex([SignaturePrefix.EOA, signature])\n : signature;\n },\n\n extend: {\n source: type,\n getLightAccountVersion: () => version,\n encodeUpgradeToAndCall,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,OAAO,EACP,WAAW,EACX,aAAa,EACb,IAAI,GAUL,MAAM,MAAM,CAAC;AACd,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,cAAc,GAEf,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAMxE,OAAO,EAAE,+BAA+B,EAAE,MAAM,aAAa,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,gBAAgB,CAAC;AAChF,OAAO,EACL,aAAa,IAAI,WAAW,EAC5B,aAAa,IAAI,WAAW,GAC7B,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM1D,OAAO,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEvC,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE,MAAM;IACX,QAAQ,EAAE,MAAM;IAChB,kBAAkB,EAAE,MAAM;CAClB,CAAC;AAmDX,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAKtC,EACA,MAAM,EACN,GAAG,EACH,cAAc,EACd,KAAK,EACL,IAAI,EACJ,OAAO,EACP,cAAc,GAKf;IACC,MAAM,sBAAsB,GAAG,KAAK,EAAE,EACpC,gBAAgB,EAChB,iBAA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BACX,MAAM,UAAU,GAAG,oBAAoB,CAAC;wBACtC,OAAO;wBACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;wBACrC,iBAAiB,EAAE,UAAU,CAAC,OAAO;wBACrC,aAAa,EAAE;4BACb,GAAG,aAAa;4BAChB,MAAM,EAAE,cAAc;yBACvB;qBACF,CAAC,CAAC;oBAEH,MAAM,iBAAiB,GAAG,SAAS,CACjC,MAAM,EACN,WAAW,EACX,aAAa,CACd,CAAC;oBAEF,SAAS,GAAG,MAAM,iBAAiB,CAAC;wBAClC,OAAO,EAAE,KAAK;wBACd,OAAO,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE;qBAC7B,CAAC,CAAC;oBACH,MAAM;gBACR,KAAK,QAAQ,CAAC;gBACd,KAAK,QAAQ;oBACX,MAAM,mBAAmB,GAAG,SAAS,CACnC,MAAM,EACN,aAAa,EACb,eAAe,CAChB,CAAC;oBAEF,SAAS,GAAG,MAAM,mBAAmB,CAAC;wBACpC,OAAO,EAAE,KAAK;wBACd,GAAG,yBAAyB,CAAC;4BAC3B,OAAO;4BACP,iBAAiB,EAAE,UAAU,CAAC,OAAO;4BACrC,aAAa,EAAE;gCACb,GAAG,aAAa;gCAChB,MAAM,EAAE,cAAc;6BACvB;yBACF,CAAC;qBACH,CAAC,CAAC;oBACH,MAAM;gBACR;oBACE,MAAM,IAAI,SAAS,CAAC,mBAAmB,IAAI,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC;YACzE,CAAC;YAED,OAAO,eAAe,CAAC,SAAS,CAAC,CAAC;QACpC,CAAC;QAED,MAAM,EAAE;YACN,gBAAgB,EAAE,IAAI;YACtB,sBAAsB,EAAE,GAAG,EAAE,CAAC,OAAO;YACrC,sBAAsB;YACtB,gBAAgB;YAChB,eAAe;SAChB;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["import {\n concatHex,\n encodeFunctionData,\n fromHex,\n hashMessage,\n hashTypedData,\n trim,\n type Abi,\n type Address,\n type Chain,\n type Client,\n type Hex,\n type JsonRpcAccount,\n type LocalAccount,\n type Transport,\n type TypedDataDefinition,\n} from \"viem\";\nimport {\n getUserOperationHash,\n getUserOperationTypedData,\n toSmartAccount,\n type SmartAccountImplementation,\n} from \"viem/account-abstraction\";\nimport { getStorageAt, signMessage, signTypedData } from \"viem/actions\";\nimport type {\n EntryPointFromAccountRegistry,\n LightAccountType,\n LightAccountVersion,\n} from \"../registry.js\";\nimport { EIP1967_PROXY_IMPL_STORAGE_SLOT } from \"../utils.js\";\nimport { AccountVersionRegistry, isLightAccountVersion2 } from \"../registry.js\";\nimport {\n encodeCallsLA as encodeCalls,\n decodeCallsLA as decodeCalls,\n} from \"./calldataCodec.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport type {\n SignatureRequest,\n StaticSmartAccountImplementation,\n SmartAccountWithDecodeCalls,\n} from \"../../types.js\";\nimport { getAction } from \"viem/utils\";\n\nconst SignaturePrefix = {\n EOA: \"0x00\",\n CONTRACT: \"0x01\",\n CONTRACT_WITH_ADDR: \"0x02\",\n} as const;\n\nexport type BaseLightAccountImplementation<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountImplementation<\n EntryPointFromAccountRegistry<TLightAccountType, TLightAccountVersion>[\"abi\"],\n EntryPointFromAccountRegistry<\n TLightAccountType,\n TLightAccountVersion\n >[\"version\"],\n {\n getLightAccountVersion: () => TLightAccountVersion;\n smartAccountType: TLightAccountType;\n encodeUpgradeToAndCall: (params: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }) => Promise<Hex>;\n prepareSignature: (request: SignatureRequest) => Promise<SignatureRequest>;\n formatSignature: (signature: Hex) => Promise<Hex>;\n },\n false\n>;\n\nexport type LightAccountBase<\n TLightAccountType extends LightAccountType = LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n> = SmartAccountWithDecodeCalls<\n BaseLightAccountImplementation<TLightAccountType, TLightAccountVersion>\n>;\n\nexport type ToLightAccountBaseParams<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n> = {\n client: Client<TTransport, Chain, JsonRpcAccount | LocalAccount | undefined>;\n abi: Abi;\n accountAddress: Address;\n owner: JsonRpcAccount | LocalAccount;\n type: TLightAccountType;\n version: TLightAccountVersion;\n getFactoryArgs: () => Promise<{\n factory?: Address | undefined;\n factoryData?: Hex | undefined;\n }>;\n};\n\nexport async function toLightAccountBase<\n TLightAccountType extends LightAccountType,\n TLightAccountVersion extends\n LightAccountVersion<TLightAccountType> = LightAccountVersion<TLightAccountType>,\n TTransport extends Transport = Transport,\n>({\n client,\n abi,\n accountAddress,\n owner,\n type,\n version,\n getFactoryArgs,\n}: ToLightAccountBaseParams<\n TLightAccountType,\n TLightAccountVersion,\n TTransport\n>): Promise<LightAccountBase<TLightAccountType, TLightAccountVersion>> {\n const encodeUpgradeToAndCall = async ({\n upgradeToAddress,\n upgradeToInitData,\n }: {\n upgradeToAddress: Address;\n upgradeToInitData: Hex;\n }): Promise<Hex> => {\n const expectedImplAddresses = (\n Object.values(\n AccountVersionRegistry[type],\n ) as StaticSmartAccountImplementation<false>[]\n ).map((x) => x.accountImplementation);\n\n const getStorageAtAction = getAction(client, getStorageAt, \"getStorageAt\");\n // TODO(v5): This is a super fragile workflow, and we should consider not supporting this on the SmartAccount level in v5.\n const storage = await getStorageAtAction({\n address: accountAddress,\n slot: EIP1967_PROXY_IMPL_STORAGE_SLOT,\n });\n\n if (storage == null) {\n throw new BaseError(\n `Failed to get storage slot: ${EIP1967_PROXY_IMPL_STORAGE_SLOT}`,\n );\n }\n\n // Only upgrade undeployed accounts (storage 0) or deployed light accounts, else error.\n if (\n fromHex(storage, \"number\") !== 0 &&\n !expectedImplAddresses.some((x) => x === lowerAddress(trim(storage)))\n ) {\n throw new BaseError(\n `could not determine if smart account implementation is ${type} ${String(\n version,\n )}`,\n );\n }\n\n return encodeFunctionData({\n abi,\n functionName: \"upgradeToAndCall\",\n args: [upgradeToAddress, upgradeToInitData],\n });\n };\n\n const get1271Wrapper = (\n hashedMessage: Hex,\n version: string,\n ): TypedDataDefinition => {\n return {\n // EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)\n // https://github.com/alchemyplatform/light-account/blob/main/src/LightAccount.sol#L236\n domain: {\n chainId: client.chain.id,\n name: type,\n verifyingContract: accountAddress,\n version,\n },\n types: {\n LightAccountMessage: [{ name: \"message\", type: \"bytes\" }],\n },\n message: {\n message: hashedMessage,\n },\n primaryType: \"LightAccountMessage\",\n };\n };\n\n const prepareSignature = async (\n params: SignatureRequest,\n ): Promise<SignatureRequest> => {\n const messageHash =\n params.type === \"eth_signTypedData_v4\"\n ? hashTypedData(params.data)\n : hashMessage(params.data);\n\n switch (version) {\n case \"v1.0.1\":\n return params;\n case \"v1.0.2\":\n throw new BaseError(\n `Version ${String(version)} of LightAccount doesn't support 1271`,\n );\n case \"v1.1.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"1\"),\n };\n case \"v2.0.0\":\n case \"v2.1.0\":\n case \"v2.2.0\":\n return {\n type: \"eth_signTypedData_v4\",\n data: get1271Wrapper(messageHash, \"2\"),\n };\n default:\n throw new BaseError(\n `Unknown version ${String(version)} of LightAccount`,\n );\n }\n };\n\n const formatSignature = async (signature: Hex): Promise<Hex> => {\n return isLightAccountVersion2(\n version as LightAccountVersion<\"LightAccount\">,\n )\n ? concatHex([SignaturePrefix.EOA, signature])\n : signature;\n };\n\n const entryPoint = (\n AccountVersionRegistry[type][version] as StaticSmartAccountImplementation\n ).entryPoint;\n\n return await toSmartAccount({\n getFactoryArgs,\n client,\n entryPoint,\n\n async getAddress() {\n return accountAddress;\n },\n\n async encodeCalls(calls) {\n return encodeCalls(calls);\n },\n\n async decodeCalls(data) {\n return decodeCalls(data, accountAddress);\n },\n\n async getStubSignature() {\n const signature =\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\";\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n return signature;\n case \"v2.0.0\":\n case \"v2.1.0\":\n case \"v2.2.0\":\n return concatHex([SignaturePrefix.EOA, signature]);\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\n },\n\n async signMessage({ message }) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n const { type, data } = await prepareSignature({\n type: \"personal_sign\",\n data: message,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signTypedData(params) {\n const signMessageAction = getAction(client, signMessage, \"signMessage\");\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n const { type, data } = await prepareSignature({\n type: \"eth_signTypedData_v4\",\n data: params as TypedDataDefinition,\n });\n\n const sig =\n type === \"eth_signTypedData_v4\"\n ? await signTypedDataAction({\n ...data,\n account: owner,\n })\n : await signMessageAction({ account: owner, message: data });\n\n return formatSignature(sig);\n },\n\n async signUserOperation(parameters) {\n const { chainId = client.chain.id, ...userOperation } = parameters;\n let signature: Hex;\n\n switch (version) {\n case \"v1.0.1\":\n case \"v1.0.2\":\n case \"v1.1.0\":\n case \"v2.0.0\":\n const userOpHash = getUserOperationHash({\n chainId,\n entryPointAddress: entryPoint.address,\n entryPointVersion: entryPoint.version,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n });\n\n const signMessageAction = getAction(\n client,\n signMessage,\n \"signMessage\",\n );\n\n signature = await signMessageAction({\n account: owner,\n message: { raw: userOpHash },\n });\n break;\n case \"v2.1.0\":\n case \"v2.2.0\":\n const signTypedDataAction = getAction(\n client,\n signTypedData,\n \"signTypedData\",\n );\n\n signature = await signTypedDataAction({\n account: owner,\n ...getUserOperationTypedData({\n chainId,\n entryPointAddress: entryPoint.address,\n userOperation: {\n ...userOperation,\n sender: accountAddress,\n },\n }),\n });\n break;\n default:\n throw new BaseError(`Unknown version ${type} of ${String(version)}`);\n }\n\n return formatSignature(signature);\n },\n\n extend: {\n smartAccountType: type,\n getLightAccountVersion: () => version,\n encodeUpgradeToAndCall,\n prepareSignature,\n formatSignature,\n },\n });\n}\n"]}
|
|
@@ -9,14 +9,19 @@ export type ToMultiOwnerLightAccountParams = {
|
|
|
9
9
|
owners: [OneOf<JsonRpcAccount | LocalAccount>, ...{
|
|
10
10
|
address: Address;
|
|
11
11
|
}[]];
|
|
12
|
-
salt?: bigint;
|
|
13
12
|
accountAddress?: Address;
|
|
14
|
-
|
|
15
|
-
}
|
|
13
|
+
factory?: Address;
|
|
14
|
+
} & ({
|
|
15
|
+
salt?: bigint;
|
|
16
|
+
factoryData?: never;
|
|
17
|
+
} | {
|
|
18
|
+
salt?: never;
|
|
19
|
+
factoryData?: Hex;
|
|
20
|
+
});
|
|
16
21
|
/**
|
|
17
22
|
* Creates a multi-owner light account.
|
|
18
23
|
*
|
|
19
24
|
* @param {ToMultiOwnerLightAccountParams} param0 - The parameters for creating a multi-owner light account.
|
|
20
25
|
* @returns {Promise<MultiOwnerLightAccount<TSigner>>} A multi-owner light account.
|
|
21
26
|
*/
|
|
22
|
-
export declare function toMultiOwnerLightAccount({ client, salt, owners, accountAddress: accountAddress_,
|
|
27
|
+
export declare function toMultiOwnerLightAccount({ client, salt, owners, accountAddress: accountAddress_, factory, factoryData: factoryData_, }: ToMultiOwnerLightAccountParams): Promise<MultiOwnerLightAccount>;
|
|
@@ -2,7 +2,7 @@ import { encodeFunctionData, hexToBigInt, } from "viem";
|
|
|
2
2
|
import { readContract } from "viem/actions";
|
|
3
3
|
import { MultiOwnerLightAccountAbi } from "../abis/MultiOwnerLightAccountAbi.js";
|
|
4
4
|
import { MultiOwnerLightAccountFactoryAbi } from "../abis/MultiOwnerLightAccountFactoryAbi.js";
|
|
5
|
-
import { predictMultiOwnerLightAccountAddress } from "../predictAddress.js";
|
|
5
|
+
import { getMultiOwnerLightAccountAddressFromFactoryData, predictMultiOwnerLightAccountAddress, } from "../predictAddress.js";
|
|
6
6
|
import { toLightAccountBase } from "./base.js";
|
|
7
7
|
import { BaseError, lowerAddress } from "@alchemy/common";
|
|
8
8
|
import { getAction } from "viem/utils";
|
|
@@ -13,8 +13,8 @@ import { AccountVersionRegistry } from "../registry.js";
|
|
|
13
13
|
* @param {ToMultiOwnerLightAccountParams} param0 - The parameters for creating a multi-owner light account.
|
|
14
14
|
* @returns {Promise<MultiOwnerLightAccount<TSigner>>} A multi-owner light account.
|
|
15
15
|
*/
|
|
16
|
-
export async function toMultiOwnerLightAccount({ client, salt = 0n, owners, accountAddress: accountAddress_,
|
|
17
|
-
.factoryAddress, }) {
|
|
16
|
+
export async function toMultiOwnerLightAccount({ client, salt = 0n, owners, accountAddress: accountAddress_, factory = AccountVersionRegistry.MultiOwnerLightAccount["v2.0.0"]
|
|
17
|
+
.factoryAddress, factoryData: factoryData_, }) {
|
|
18
18
|
const signer = owners[0];
|
|
19
19
|
const dedupedOwners = Array.from(new Set(owners.map((it) => lowerAddress(it.address))));
|
|
20
20
|
const sortedOwners = dedupedOwners.sort((a, b) => {
|
|
@@ -23,19 +23,28 @@ export async function toMultiOwnerLightAccount({ client, salt = 0n, owners, acco
|
|
|
23
23
|
return bigintA < bigintB ? -1 : bigintA > bigintB ? 1 : 0;
|
|
24
24
|
});
|
|
25
25
|
const accountAddress = accountAddress_ ??
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
26
|
+
(factoryData_
|
|
27
|
+
? await getMultiOwnerLightAccountAddressFromFactoryData({
|
|
28
|
+
client,
|
|
29
|
+
factoryAddress: factory,
|
|
30
|
+
factoryData: factoryData_,
|
|
31
|
+
entryPoint: AccountVersionRegistry["MultiOwnerLightAccount"]["v2.0.0"]
|
|
32
|
+
.entryPoint,
|
|
33
|
+
})
|
|
34
|
+
: predictMultiOwnerLightAccountAddress({
|
|
35
|
+
factoryAddress: factory,
|
|
36
|
+
salt,
|
|
37
|
+
ownerAddresses: sortedOwners,
|
|
38
|
+
}));
|
|
31
39
|
const getFactoryArgs = async () => {
|
|
32
|
-
const factoryData =
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
40
|
+
const factoryData = factoryData_ ??
|
|
41
|
+
encodeFunctionData({
|
|
42
|
+
abi: MultiOwnerLightAccountFactoryAbi,
|
|
43
|
+
functionName: "createAccount",
|
|
44
|
+
args: [sortedOwners, salt],
|
|
45
|
+
});
|
|
37
46
|
return {
|
|
38
|
-
factory
|
|
47
|
+
factory,
|
|
39
48
|
factoryData,
|
|
40
49
|
};
|
|
41
50
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"multi-owner-account.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/multi-owner-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,GASZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,yBAAyB,EAAE,MAAM,sCAAsC,CAAC;AACjF,OAAO,EAAE,gCAAgC,EAAE,MAAM,6CAA6C,CAAC;AAC/F,OAAO,
|
|
1
|
+
{"version":3,"file":"multi-owner-account.js","sourceRoot":"","sources":["../../../../src/light-account/accounts/multi-owner-account.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,kBAAkB,EAClB,WAAW,GASZ,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,E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,OAAO,EAAE,cAAc;gBACvB,GAAG,EAAE,yBAAyB;gBAC9B,YAAY,EAAE,QAAQ;aACvB,CAAC,CAAC;YAEH,IAAI,aAAa,IAAI,IAAI,EAAE,CAAC;gBAC1B,MAAM,IAAI,SAAS,CAAC,+BAA+B,CAAC,CAAC;YACvD,CAAC;YAED,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 encodeFunctionData,\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} from \"viem\";\nimport { readContract } from \"viem/actions\";\nimport { MultiOwnerLightAccountAbi } from \"../abis/MultiOwnerLightAccountAbi.js\";\nimport { MultiOwnerLightAccountFactoryAbi } from \"../abis/MultiOwnerLightAccountFactoryAbi.js\";\nimport {\n getMultiOwnerLightAccountAddressFromFactoryData,\n predictMultiOwnerLightAccountAddress,\n} from \"../predictAddress.js\";\nimport { toLightAccountBase, type LightAccountBase } from \"./base.js\";\nimport { BaseError, lowerAddress } from \"@alchemy/common\";\nimport { getAction } from \"viem/utils\";\nimport { AccountVersionRegistry } from \"../registry.js\";\n\nexport type MultiOwnerLightAccount = LightAccountBase<\n \"MultiOwnerLightAccount\",\n \"v2.0.0\"\n> & {\n encodeUpdateOwners: (\n ownersToAdd: Address[],\n ownersToRemove: Address[],\n ) => Hex;\n getOwnerAddresses: () => Promise<readonly Address[]>;\n};\n\nexport type ToMultiOwnerLightAccountParams = {\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 light account.\n *\n * @param {ToMultiOwnerLightAccountParams} param0 - The parameters for creating a multi-owner light account.\n * @returns {Promise<MultiOwnerLightAccount<TSigner>>} A multi-owner light account.\n */\nexport async function toMultiOwnerLightAccount({\n client,\n salt = 0n,\n owners,\n accountAddress: accountAddress_,\n factory = AccountVersionRegistry.MultiOwnerLightAccount[\"v2.0.0\"]\n .factoryAddress,\n factoryData: factoryData_,\n}: ToMultiOwnerLightAccountParams): Promise<MultiOwnerLightAccount> {\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 getMultiOwnerLightAccountAddressFromFactoryData({\n client,\n factoryAddress: factory,\n factoryData: factoryData_,\n entryPoint:\n AccountVersionRegistry[\"MultiOwnerLightAccount\"][\"v2.0.0\"]\n .entryPoint,\n })\n : predictMultiOwnerLightAccountAddress({\n factoryAddress: factory,\n salt,\n ownerAddresses: sortedOwners,\n }));\n\n const getFactoryArgs = async () => {\n const factoryData =\n factoryData_ ??\n encodeFunctionData({\n abi: MultiOwnerLightAccountFactoryAbi,\n functionName: \"createAccount\",\n args: [sortedOwners, salt],\n });\n\n return {\n factory,\n factoryData,\n };\n };\n\n const baseAccount = await toLightAccountBase({\n client,\n owner: signer,\n abi: MultiOwnerLightAccountAbi,\n accountAddress,\n type: \"MultiOwnerLightAccount\",\n version: \"v2.0.0\",\n getFactoryArgs,\n });\n\n return {\n ...baseAccount,\n\n encodeUpdateOwners: (ownersToAdd: Address[], ownersToRemove: Address[]) => {\n return encodeFunctionData({\n abi: MultiOwnerLightAccountAbi,\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: accountAddress,\n abi: MultiOwnerLightAccountAbi,\n functionName: \"owners\",\n });\n\n if (ownersOnChain == null) {\n throw new BaseError(\"could not get on-chain owners\");\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"]}
|
|
@@ -2,7 +2,8 @@ import { sendUserOperation } from "viem/account-abstraction";
|
|
|
2
2
|
import { getAction } from "viem/utils";
|
|
3
3
|
import { AccountNotFoundError } from "@alchemy/common";
|
|
4
4
|
function isMultiOwnerLightAccount(account) {
|
|
5
|
-
return "
|
|
5
|
+
return ("smartAccountType" in account &&
|
|
6
|
+
account.smartAccountType === "MultiOwnerLightAccount");
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
9
|
* Generates client actions for a multi-owner light account, including the ability to update owners.
|