@account-kit/smart-contracts 4.44.0 → 4.46.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,8 @@
1
- import { type SmartAccountSigner, type SmartContractAccountWithSigner, type ToSmartContractAccountParams, type SmartContractAccount } from "@aa-sdk/core";
2
- import { type Hex, type Address, type Chain, type Transport } from "viem";
1
+ import { type SmartAccountSigner, type SmartContractAccount, type SmartContractAccountWithSigner, type ToSmartContractAccountParams } from "@aa-sdk/core";
2
+ import { type Address, type Chain, type Hex, type Transport } from "viem";
3
3
  import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
4
4
  export declare const executeUserOpSelector: Hex;
5
+ export type ModularAccountsV2 = ModularAccountV2 | WebauthnModularAccountV2;
5
6
  export type SignerEntity = {
6
7
  isGlobalValidation: boolean;
7
8
  entityId: number;
@@ -52,3 +53,4 @@ export type CreateWebauthnMAV2BaseParams = Omit<CreateMAV2BaseParams, "signer">
52
53
  export type CreateMAV2BaseReturnType<TSigner extends SmartAccountSigner = SmartAccountSigner> = Promise<ModularAccountV2<TSigner>>;
53
54
  export declare function createMAv2Base(config: CreateWebauthnMAV2BaseParams): Promise<WebauthnModularAccountV2>;
54
55
  export declare function createMAv2Base<TSigner extends SmartAccountSigner = SmartAccountSigner>(config: CreateMAV2BaseParams): CreateMAV2BaseReturnType<TSigner>;
56
+ export declare function isModularAccountV2(account: SmartContractAccount): account is ModularAccountV2 | WebauthnModularAccountV2;
@@ -1,11 +1,11 @@
1
- import { createBundlerClient, getEntryPoint, InvalidEntityIdError, InvalidNonceKeyError, InvalidDeferredActionNonce, toSmartContractAccount, } from "@aa-sdk/core";
2
- import { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from "../../utils.js";
3
- import { encodeFunctionData, maxUint32, zeroAddress, getContract, concatHex, maxUint152, } from "viem";
1
+ import { createBundlerClient, getEntryPoint, InvalidDeferredActionNonce, InvalidEntityIdError, InvalidNonceKeyError, toSmartContractAccount, } from "@aa-sdk/core";
2
+ import { concatHex, encodeFunctionData, getContract, maxUint152, maxUint32, zeroAddress, } from "viem";
4
3
  import { modularAccountAbi } from "../../abis/modularAccountAbi.js";
5
4
  import { serializeModuleEntity } from "../../actions/common/utils.js";
6
- import { nativeSMASigner } from "../nativeSMASigner.js";
7
5
  import { singleSignerMessageSigner } from "../../modules/single-signer-validation/signer.js";
8
6
  import { webauthnSigningFunctions } from "../../modules/webauthn-validation/signingMethods.js";
7
+ import { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from "../../utils.js";
8
+ import { nativeSMASigner } from "../nativeSMASigner.js";
9
9
  export const executeUserOpSelector = "0x8DD7712F";
10
10
  export async function createMAv2Base(config) {
11
11
  let { transport, chain, entryPoint = getEntryPoint(chain, { version: "0.7.0" }), signerEntity = {
@@ -169,4 +169,7 @@ export async function createMAv2Base(config) {
169
169
  encodeCallData,
170
170
  }; // TO DO: figure out when this breaks! we shouldn't have to cast
171
171
  }
172
+ export function isModularAccountV2(account) {
173
+ return account.source === "ModularAccountV2";
174
+ }
172
175
  //# sourceMappingURL=modularAccountV2Base.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modularAccountV2Base.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,GAMvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAKL,kBAAkB,EAClB,SAAS,EACT,WAAW,EACX,WAAW,EACX,SAAS,EACT,UAAU,GACX,MAAM,MAAM,CAAC;AACd,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,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,IAAI,cAAc,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC;YACzC,OAAO,SAAS,CAAC,CAAC,qBAAqB,EAAE,QAAQ,CAAC,CAAC,CAAC;QACtD,CAAC;QACD,OAAO,QAAQ,CAAC;IAClB,CAAC,CAAC;IAEF,MAAM,WAAW,GAAG,MAAM,sBAAsB,CAAC;QAC/C,GAAG,qCAAqC;QACxC,SAAS;QACT,KAAK;QACL,UAAU;QACV,cAAc;QACd,aAAa;QACb,kBAAkB;QAClB,QAAQ;QACR,GAAG,CAAC,MAAM;YACR,CAAC,CAAC,QAAQ,KAAK,uBAAuB;gBACpC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,kBAAkB,CAAC;gBACpE,CAAC,CAAC,yBAAyB,CACvB,MAAM,EACN,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB;YACL,CAAC,CAAC,wBAAwB;YACtB,sFAAsF;YACtF,UAAW,EACX,KAAK,EACL,IAAI,EACJ,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB,CAAC;KACP,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,GAAG,WAAW;YACd,YAAY;YACZ,gBAAgB;YAChB,iBAAiB;YACjB,cAAc;SACa,CAAC,CAAC,gEAAgE;IACjG,CAAC;IAED,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACc,CAAC,CAAC,gEAAgE;AAClG,CAAC","sourcesContent":["import {\n createBundlerClient,\n getEntryPoint,\n InvalidEntityIdError,\n InvalidNonceKeyError,\n InvalidDeferredActionNonce,\n toSmartContractAccount,\n type AccountOp,\n type SmartAccountSigner,\n type SmartContractAccountWithSigner,\n type ToSmartContractAccountParams,\n type SmartContractAccount,\n} from \"@aa-sdk/core\";\nimport { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from \"../../utils.js\";\nimport {\n type Hex,\n type Address,\n type Chain,\n type Transport,\n encodeFunctionData,\n maxUint32,\n zeroAddress,\n getContract,\n concatHex,\n maxUint152,\n} from \"viem\";\nimport { modularAccountAbi } from \"../../abis/modularAccountAbi.js\";\nimport { serializeModuleEntity } from \"../../actions/common/utils.js\";\nimport { nativeSMASigner } from \"../nativeSMASigner.js\";\nimport { singleSignerMessageSigner } from \"../../modules/single-signer-validation/signer.js\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\nimport { webauthnSigningFunctions } from \"../../modules/webauthn-validation/signingMethods.js\";\n\nexport const executeUserOpSelector: Hex = \"0x8DD7712F\";\n\nexport type SignerEntity = {\n isGlobalValidation: boolean;\n entityId: number;\n};\n\nexport type ExecutionDataView = {\n module: Address;\n skipRuntimeValidation: boolean;\n allowGlobalValidation: boolean;\n executionHooks: readonly Hex[];\n};\n\nexport type ValidationDataView = {\n validationHooks: readonly Hex[];\n executionHooks: readonly Hex[];\n selectors: readonly Hex[];\n validationFlags: number;\n};\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type ModularAccountV2<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = SmartContractAccountWithSigner<\"ModularAccountV2\", TSigner, \"0.7.0\"> & {\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type WebauthnModularAccountV2 = SmartContractAccount<\n \"ModularAccountV2\",\n \"0.7.0\"\n> & {\n params: ToWebAuthnAccountParameters;\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type CreateMAV2BaseParams<\n TSigner extends SmartAccountSigner | undefined =\n | SmartAccountSigner\n | undefined,\n TTransport extends Transport = Transport,\n> = Omit<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n // Implements the following methods required by `toSmartContractAccount`, and passes through any other parameters.\n | \"encodeExecute\"\n | \"encodeBatchExecute\"\n | \"getNonce\"\n | \"signMessage\"\n | \"signTypedData\"\n | \"getDummySignature\"\n | \"prepareSign\"\n | \"formatSign\"\n> & {\n signer: TSigner;\n signerEntity?: SignerEntity;\n accountAddress: Address;\n deferredAction?: Hex;\n};\n\nexport type CreateWebauthnMAV2BaseParams = Omit<\n CreateMAV2BaseParams,\n \"signer\"\n> & {\n credential: ToWebAuthnAccountParameters[\"credential\"];\n getFn?: ToWebAuthnAccountParameters[\"getFn\"] | undefined;\n rpId?: ToWebAuthnAccountParameters[\"rpId\"] | undefined;\n};\n\nexport type CreateMAV2BaseReturnType<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = Promise<ModularAccountV2<TSigner>>;\n\n// function overload\nexport async function createMAv2Base(\n config: CreateWebauthnMAV2BaseParams,\n): Promise<WebauthnModularAccountV2>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(config: CreateMAV2BaseParams): CreateMAV2BaseReturnType<TSigner>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n config: CreateMAV2BaseParams<TSigner> | CreateWebauthnMAV2BaseParams,\n): Promise<WebauthnModularAccountV2 | ModularAccountV2<TSigner>> {\n let {\n transport,\n chain,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: {\n isGlobalValidation = true,\n entityId = DEFAULT_OWNER_ENTITY_ID,\n } = {},\n accountAddress,\n deferredAction,\n ...remainingToSmartContractAccountParams\n } = config;\n\n const signer = \"signer\" in config ? config.signer : undefined;\n const credential = \"credential\" in config ? config.credential : undefined;\n const getFn = \"getFn\" in config ? config.getFn : undefined;\n const rpId = \"rpId\" in config ? config.rpId : undefined;\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client,\n });\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce: bigint = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n // Set these values if the deferred action has not been consumed. We check this with the EP\n const nextNonceForDeferredAction: bigint =\n (await entryPointContract.read.getNonce([\n accountAddress,\n deferredActionNonce >> 64n,\n ])) as bigint;\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonce();\n }\n }\n\n const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({\n target,\n data,\n value,\n }) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [target, value ?? 0n, data],\n }),\n );\n\n const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n txs.map((tx) => ({\n target: tx.target,\n data: tx.data,\n value: tx.value ?? 0n,\n })),\n ],\n }),\n );\n\n const isAccountDeployed: () => Promise<boolean> = async () =>\n !!(await client.getCode({ address: accountAddress }));\n\n const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey: bigint =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n return entryPointContract.read.getNonce([\n accountAddress,\n fullNonceKey,\n ]) as Promise<bigint>;\n };\n\n const accountContract = getContract({\n address: accountAddress,\n abi: modularAccountAbi,\n client,\n });\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return await accountContract.read.getExecutionData([selector]);\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n return await accountContract.read.getValidationData([\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ]);\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n hasAssociatedExecHooks = false; // set to falsy value once used\n return concatHex([executeUserOpSelector, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([executeUserOpSelector, callData]);\n }\n return callData;\n };\n\n const baseAccount = await toSmartContractAccount({\n ...remainingToSmartContractAccountParams,\n transport,\n chain,\n entryPoint,\n accountAddress,\n encodeExecute,\n encodeBatchExecute,\n getNonce,\n ...(signer\n ? entityId === DEFAULT_OWNER_ENTITY_ID\n ? nativeSMASigner(signer, chain, accountAddress, deferredActionData)\n : singleSignerMessageSigner(\n signer,\n chain,\n accountAddress,\n entityId,\n deferredActionData,\n )\n : webauthnSigningFunctions(\n // credential required for webauthn mode is checked at modularAccountV2 creation level\n credential!,\n getFn,\n rpId,\n chain,\n accountAddress,\n entityId,\n deferredActionData,\n )),\n });\n\n if (!signer) {\n return {\n ...baseAccount,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n } as WebauthnModularAccountV2; // TO DO: figure out when this breaks! we shouldn't have to cast\n }\n\n return {\n ...baseAccount,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n } as ModularAccountV2<TSigner>; // TO DO: figure out when this breaks! we shouldn't have to cast\n}\n"]}
1
+ {"version":3,"file":"modularAccountV2Base.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,0BAA0B,EAC1B,oBAAoB,EACpB,oBAAoB,EACpB,sBAAsB,GAMvB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,SAAS,EACT,kBAAkB,EAClB,WAAW,EACX,UAAU,EACV,SAAS,EACT,WAAW,GAKZ,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAC7F,OAAO,EAAE,wBAAwB,EAAE,MAAM,qDAAqD,CAAC;AAC/F,OAAO,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAC9E,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,MAAM,CAAC,MAAM,qBAAqB,GAAQ,YAAY,CAAC;AAsGvD,MAAM,CAAC,KAAK,UAAU,cAAc,CAGlC,MAAoE;IAEpE,IAAI,EACF,SAAS,EACT,KAAK,EACL,UAAU,GAAG,aAAa,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AClB,QAAQ;QACR,GAAG,CAAC,MAAM;YACR,CAAC,CAAC,QAAQ,KAAK,uBAAuB;gBACpC,CAAC,CAAC,eAAe,CAAC,MAAM,EAAE,KAAK,EAAE,cAAc,EAAE,kBAAkB,CAAC;gBACpE,CAAC,CAAC,yBAAyB,CACvB,MAAM,EACN,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB;YACL,CAAC,CAAC,wBAAwB;YACtB,sFAAsF;YACtF,UAAW,EACX,KAAK,EACL,IAAI,EACJ,KAAK,EACL,cAAc,EACd,QAAQ,EACR,kBAAkB,CACnB,CAAC;KACP,CAAC,CAAC;IAEH,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO;YACL,GAAG,WAAW;YACd,YAAY;YACZ,gBAAgB;YAChB,iBAAiB;YACjB,cAAc;SACa,CAAC,CAAC,gEAAgE;IACjG,CAAC;IAED,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACc,CAAC,CAAC,gEAAgE;AAClG,CAAC;AAED,MAAM,UAAU,kBAAkB,CAChC,OAA6B;IAE7B,OAAO,OAAO,CAAC,MAAM,KAAK,kBAAkB,CAAC;AAC/C,CAAC","sourcesContent":["import {\n createBundlerClient,\n getEntryPoint,\n InvalidDeferredActionNonce,\n InvalidEntityIdError,\n InvalidNonceKeyError,\n toSmartContractAccount,\n type AccountOp,\n type SmartAccountSigner,\n type SmartContractAccount,\n type SmartContractAccountWithSigner,\n type ToSmartContractAccountParams,\n} from \"@aa-sdk/core\";\nimport {\n concatHex,\n encodeFunctionData,\n getContract,\n maxUint152,\n maxUint32,\n zeroAddress,\n type Address,\n type Chain,\n type Hex,\n type Transport,\n} from \"viem\";\nimport type { ToWebAuthnAccountParameters } from \"viem/account-abstraction\";\nimport { modularAccountAbi } from \"../../abis/modularAccountAbi.js\";\nimport { serializeModuleEntity } from \"../../actions/common/utils.js\";\nimport { singleSignerMessageSigner } from \"../../modules/single-signer-validation/signer.js\";\nimport { webauthnSigningFunctions } from \"../../modules/webauthn-validation/signingMethods.js\";\nimport { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from \"../../utils.js\";\nimport { nativeSMASigner } from \"../nativeSMASigner.js\";\n\nexport const executeUserOpSelector: Hex = \"0x8DD7712F\";\n\nexport type ModularAccountsV2 = ModularAccountV2 | WebauthnModularAccountV2;\n\nexport type SignerEntity = {\n isGlobalValidation: boolean;\n entityId: number;\n};\n\nexport type ExecutionDataView = {\n module: Address;\n skipRuntimeValidation: boolean;\n allowGlobalValidation: boolean;\n executionHooks: readonly Hex[];\n};\n\nexport type ValidationDataView = {\n validationHooks: readonly Hex[];\n executionHooks: readonly Hex[];\n selectors: readonly Hex[];\n validationFlags: number;\n};\n\nexport type ValidationDataParams =\n | {\n validationModuleAddress: Address;\n entityId?: never;\n }\n | {\n validationModuleAddress?: never;\n entityId: number;\n };\n\nexport type ModularAccountV2<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = SmartContractAccountWithSigner<\"ModularAccountV2\", TSigner, \"0.7.0\"> & {\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type WebauthnModularAccountV2 = SmartContractAccount<\n \"ModularAccountV2\",\n \"0.7.0\"\n> & {\n params: ToWebAuthnAccountParameters;\n signerEntity: SignerEntity;\n getExecutionData: (selector: Hex) => Promise<ExecutionDataView>;\n getValidationData: (\n args: ValidationDataParams,\n ) => Promise<ValidationDataView>;\n encodeCallData: (callData: Hex) => Promise<Hex>;\n};\n\nexport type CreateMAV2BaseParams<\n TSigner extends SmartAccountSigner | undefined =\n | SmartAccountSigner\n | undefined,\n TTransport extends Transport = Transport,\n> = Omit<\n ToSmartContractAccountParams<\"ModularAccountV2\", TTransport, Chain, \"0.7.0\">,\n // Implements the following methods required by `toSmartContractAccount`, and passes through any other parameters.\n | \"encodeExecute\"\n | \"encodeBatchExecute\"\n | \"getNonce\"\n | \"signMessage\"\n | \"signTypedData\"\n | \"getDummySignature\"\n | \"prepareSign\"\n | \"formatSign\"\n> & {\n signer: TSigner;\n signerEntity?: SignerEntity;\n accountAddress: Address;\n deferredAction?: Hex;\n};\n\nexport type CreateWebauthnMAV2BaseParams = Omit<\n CreateMAV2BaseParams,\n \"signer\"\n> & {\n credential: ToWebAuthnAccountParameters[\"credential\"];\n getFn?: ToWebAuthnAccountParameters[\"getFn\"] | undefined;\n rpId?: ToWebAuthnAccountParameters[\"rpId\"] | undefined;\n};\n\nexport type CreateMAV2BaseReturnType<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = Promise<ModularAccountV2<TSigner>>;\n\n// function overload\nexport async function createMAv2Base(\n config: CreateWebauthnMAV2BaseParams,\n): Promise<WebauthnModularAccountV2>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(config: CreateMAV2BaseParams): CreateMAV2BaseReturnType<TSigner>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n config: CreateMAV2BaseParams<TSigner> | CreateWebauthnMAV2BaseParams,\n): Promise<WebauthnModularAccountV2 | ModularAccountV2<TSigner>> {\n let {\n transport,\n chain,\n entryPoint = getEntryPoint(chain, { version: \"0.7.0\" }),\n signerEntity = {\n isGlobalValidation: true,\n entityId: DEFAULT_OWNER_ENTITY_ID,\n },\n signerEntity: {\n isGlobalValidation = true,\n entityId = DEFAULT_OWNER_ENTITY_ID,\n } = {},\n accountAddress,\n deferredAction,\n ...remainingToSmartContractAccountParams\n } = config;\n\n const signer = \"signer\" in config ? config.signer : undefined;\n const credential = \"credential\" in config ? config.credential : undefined;\n const getFn = \"getFn\" in config ? config.getFn : undefined;\n const rpId = \"rpId\" in config ? config.rpId : undefined;\n\n if (entityId > Number(maxUint32)) {\n throw new InvalidEntityIdError(entityId);\n }\n\n const client = createBundlerClient({\n transport,\n chain,\n });\n\n const entryPointContract = getContract({\n address: entryPoint.address,\n abi: entryPoint.abi,\n client,\n });\n\n // These default values signal that we should not use the set deferred action nonce\n let nonce: bigint | undefined;\n let deferredActionData: Hex | undefined;\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n let deferredActionNonce: bigint = 0n;\n // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls\n ({\n entityId,\n isGlobalValidation,\n nonce: deferredActionNonce,\n } = parseDeferredAction(deferredAction));\n\n // Set these values if the deferred action has not been consumed. We check this with the EP\n const nextNonceForDeferredAction: bigint =\n (await entryPointContract.read.getNonce([\n accountAddress,\n deferredActionNonce >> 64n,\n ])) as bigint;\n\n if (deferredActionNonce === nextNonceForDeferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\n parseDeferredAction(deferredAction));\n } else if (deferredActionNonce > nextNonceForDeferredAction) {\n // if nonce is greater than the next nonce, its invalid, so we throw\n throw new InvalidDeferredActionNonce();\n }\n }\n\n const encodeExecute: (tx: AccountOp) => Promise<Hex> = async ({\n target,\n data,\n value,\n }) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"execute\",\n args: [target, value ?? 0n, data],\n }),\n );\n\n const encodeBatchExecute: (txs: AccountOp[]) => Promise<Hex> = async (txs) =>\n await encodeCallData(\n encodeFunctionData({\n abi: modularAccountAbi,\n functionName: \"executeBatch\",\n args: [\n txs.map((tx) => ({\n target: tx.target,\n data: tx.data,\n value: tx.value ?? 0n,\n })),\n ],\n }),\n );\n\n const isAccountDeployed: () => Promise<boolean> = async () =>\n !!(await client.getCode({ address: accountAddress }));\n\n const getNonce = async (nonceKey: bigint = 0n): Promise<bigint> => {\n if (nonce) {\n const tempNonce = nonce;\n nonce = undefined; // set to falsy value once used\n return tempNonce;\n }\n\n if (nonceKey > maxUint152) {\n throw new InvalidNonceKeyError(nonceKey);\n }\n\n const fullNonceKey: bigint =\n (nonceKey << 40n) +\n (BigInt(entityId) << 8n) +\n (isGlobalValidation ? 1n : 0n);\n\n return entryPointContract.read.getNonce([\n accountAddress,\n fullNonceKey,\n ]) as Promise<bigint>;\n };\n\n const accountContract = getContract({\n address: accountAddress,\n abi: modularAccountAbi,\n client,\n });\n\n const getExecutionData = async (selector: Hex) => {\n if (!(await isAccountDeployed())) {\n return {\n module: zeroAddress,\n skipRuntimeValidation: false,\n allowGlobalValidation: false,\n executionHooks: [],\n };\n }\n\n return await accountContract.read.getExecutionData([selector]);\n };\n\n const getValidationData = async (args: ValidationDataParams) => {\n if (!(await isAccountDeployed())) {\n return {\n validationHooks: [],\n executionHooks: [],\n selectors: [],\n validationFlags: 0,\n };\n }\n\n const { validationModuleAddress, entityId } = args;\n return await accountContract.read.getValidationData([\n serializeModuleEntity({\n moduleAddress: validationModuleAddress ?? zeroAddress,\n entityId: entityId ?? Number(maxUint32),\n }),\n ]);\n };\n\n const encodeCallData = async (callData: Hex): Promise<Hex> => {\n const validationData = await getValidationData({\n entityId: Number(entityId),\n });\n if (hasAssociatedExecHooks) {\n hasAssociatedExecHooks = false; // set to falsy value once used\n return concatHex([executeUserOpSelector, callData]);\n }\n if (validationData.executionHooks.length) {\n return concatHex([executeUserOpSelector, callData]);\n }\n return callData;\n };\n\n const baseAccount = await toSmartContractAccount({\n ...remainingToSmartContractAccountParams,\n transport,\n chain,\n entryPoint,\n accountAddress,\n encodeExecute,\n encodeBatchExecute,\n getNonce,\n ...(signer\n ? entityId === DEFAULT_OWNER_ENTITY_ID\n ? nativeSMASigner(signer, chain, accountAddress, deferredActionData)\n : singleSignerMessageSigner(\n signer,\n chain,\n accountAddress,\n entityId,\n deferredActionData,\n )\n : webauthnSigningFunctions(\n // credential required for webauthn mode is checked at modularAccountV2 creation level\n credential!,\n getFn,\n rpId,\n chain,\n accountAddress,\n entityId,\n deferredActionData,\n )),\n });\n\n if (!signer) {\n return {\n ...baseAccount,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n } as WebauthnModularAccountV2; // TO DO: figure out when this breaks! we shouldn't have to cast\n }\n\n return {\n ...baseAccount,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n } as ModularAccountV2<TSigner>; // TO DO: figure out when this breaks! we shouldn't have to cast\n}\n\nexport function isModularAccountV2(\n account: SmartContractAccount,\n): account is ModularAccountV2 | WebauthnModularAccountV2 {\n return account.source === \"ModularAccountV2\";\n}\n"]}
@@ -1,9 +1,8 @@
1
- import { type GetEntryPointFromAccount, type SendUserOperationResult, type UserOperationOverridesParameter, type SmartAccountSigner } from "@aa-sdk/core";
2
- import { type Address, type Hex } from "viem";
1
+ import { type GetAccountParameter, type GetEntryPointFromAccount, type SendUserOperationResult, type UserOperationOverridesParameter } from "@aa-sdk/core";
2
+ import { type Address, type Chain, type Client, type Hex, type Transport } from "viem";
3
3
  import type { HookConfig, ValidationConfig } from "../common/types.js";
4
- import { type ModularAccountV2Client } from "../../client/client.js";
5
- import { type ModularAccountV2 } from "../../account/common/modularAccountV2Base.js";
6
- export type InstallValidationParams<TSigner extends SmartAccountSigner = SmartAccountSigner> = {
4
+ import { type ModularAccountsV2 } from "../../account/common/modularAccountV2Base.js";
5
+ export type InstallValidationParams<TAccount extends ModularAccountsV2 | undefined = ModularAccountsV2 | undefined> = {
7
6
  validationConfig: ValidationConfig;
8
7
  selectors: Hex[];
9
8
  installData: Hex;
@@ -11,20 +10,18 @@ export type InstallValidationParams<TSigner extends SmartAccountSigner = SmartAc
11
10
  hookConfig: HookConfig;
12
11
  initData: Hex;
13
12
  }[];
14
- account?: ModularAccountV2<TSigner> | undefined;
15
- } & UserOperationOverridesParameter<GetEntryPointFromAccount<ModularAccountV2<TSigner>>>;
16
- export type UninstallValidationParams<TSigner extends SmartAccountSigner = SmartAccountSigner> = {
13
+ } & UserOperationOverridesParameter<GetEntryPointFromAccount<TAccount>> & GetAccountParameter<TAccount>;
14
+ export type UninstallValidationParams<TAccount extends ModularAccountsV2 | undefined = ModularAccountsV2 | undefined> = {
17
15
  moduleAddress: Address;
18
16
  entityId: number;
19
17
  uninstallData: Hex;
20
18
  hookUninstallDatas: Hex[];
21
- account?: ModularAccountV2<TSigner> | undefined;
22
- } & UserOperationOverridesParameter<GetEntryPointFromAccount<ModularAccountV2<TSigner>>>;
23
- export type InstallValidationActions<TSigner extends SmartAccountSigner = SmartAccountSigner> = {
24
- installValidation: (args: InstallValidationParams<TSigner>) => Promise<SendUserOperationResult>;
25
- encodeInstallValidation: (args: InstallValidationParams<TSigner>) => Promise<Hex>;
26
- uninstallValidation: (args: UninstallValidationParams<TSigner>) => Promise<SendUserOperationResult>;
27
- encodeUninstallValidation: (args: UninstallValidationParams<TSigner>) => Promise<Hex>;
19
+ } & UserOperationOverridesParameter<GetEntryPointFromAccount<TAccount>> & GetAccountParameter<TAccount>;
20
+ export type InstallValidationActions<TAccount extends ModularAccountsV2 | undefined = ModularAccountsV2 | undefined> = {
21
+ installValidation: (args: InstallValidationParams<TAccount>) => Promise<SendUserOperationResult>;
22
+ encodeInstallValidation: (args: InstallValidationParams<TAccount>) => Promise<Hex>;
23
+ uninstallValidation: (args: UninstallValidationParams<TAccount>) => Promise<SendUserOperationResult>;
24
+ encodeUninstallValidation: (args: UninstallValidationParams<TAccount>) => Promise<Hex>;
28
25
  };
29
26
  /**
30
27
  * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
@@ -70,4 +67,4 @@ export type InstallValidationActions<TSigner extends SmartAccountSigner = SmartA
70
67
  * @param {object} client - The client instance which provides account and sendUserOperation functionality.
71
68
  * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.
72
69
  */
73
- export declare const installValidationActions: <TSigner extends SmartAccountSigner = SmartAccountSigner>(client: ModularAccountV2Client<TSigner>) => InstallValidationActions<TSigner>;
70
+ export declare function installValidationActions<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ModularAccountsV2 | undefined = ModularAccountsV2 | undefined>(client: Client<TTransport, TChain, TAccount>): InstallValidationActions<TAccount>;
@@ -1,9 +1,8 @@
1
- import { AccountNotFoundError, IncompatibleClientError, isSmartAccountClient, EntityIdOverrideError, } from "@aa-sdk/core";
2
- import { encodeFunctionData, concatHex, zeroAddress, } from "viem";
1
+ import { AccountNotFoundError, NotAModularAccountV2Error, EntityIdOverrideError, IncompatibleClientError, isSmartAccountClient, isSmartAccountWithSigner, } from "@aa-sdk/core";
2
+ import { concatHex, encodeFunctionData, zeroAddress, } from "viem";
3
3
  import { semiModularAccountBytecodeAbi } from "../../abis/semiModularAccountBytecodeAbi.js";
4
- import { serializeValidationConfig, serializeHookConfig, serializeModuleEntity, } from "../common/utils.js";
5
- import {} from "../../client/client.js";
6
- import {} from "../../account/common/modularAccountV2Base.js";
4
+ import { serializeHookConfig, serializeModuleEntity, serializeValidationConfig, } from "../common/utils.js";
5
+ import { isModularAccountV2, } from "../../account/common/modularAccountV2Base.js";
7
6
  import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js";
8
7
  /**
9
8
  * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
@@ -49,12 +48,16 @@ import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js";
49
48
  * @param {object} client - The client instance which provides account and sendUserOperation functionality.
50
49
  * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.
51
50
  */
52
- export const installValidationActions = (client) => {
51
+ export function installValidationActions(client) {
53
52
  const encodeInstallValidation = async ({ validationConfig, selectors, installData, hooks, account = client.account, }) => {
54
53
  if (!account) {
55
54
  throw new AccountNotFoundError();
56
55
  }
57
- if (!isSmartAccountClient(client)) {
56
+ if (!isModularAccountV2(account)) {
57
+ throw new NotAModularAccountV2Error();
58
+ }
59
+ if (isSmartAccountWithSigner(account) && !isSmartAccountClient(client)) {
60
+ // if we don't differentiate between WebauthnModularAccountV2Client and ModularAccountV2Client, passing client to isSmartAccountClient complains
58
61
  throw new IncompatibleClientError("SmartAccountClient", "installValidation", client);
59
62
  }
60
63
  // an entityId of zero is only allowed if we're installing or uninstalling hooks on the fallback validation
@@ -77,7 +80,11 @@ export const installValidationActions = (client) => {
77
80
  if (!account) {
78
81
  throw new AccountNotFoundError();
79
82
  }
80
- if (!isSmartAccountClient(client)) {
83
+ if (!isModularAccountV2(account)) {
84
+ throw new NotAModularAccountV2Error();
85
+ }
86
+ if (isSmartAccountWithSigner(account) && !isSmartAccountClient(client)) {
87
+ // if we don't differentiate between WebauthnModularAccountV2Client and ModularAccountV2Client, passing client to isSmartAccountClient complains
81
88
  throw new IncompatibleClientError("SmartAccountClient", "uninstallValidation", client);
82
89
  }
83
90
  return account.encodeCallData(encodeFunctionData({
@@ -97,6 +104,12 @@ export const installValidationActions = (client) => {
97
104
  encodeInstallValidation,
98
105
  encodeUninstallValidation,
99
106
  installValidation: async ({ validationConfig, selectors, installData, hooks, account = client.account, overrides, }) => {
107
+ if (!isSmartAccountClient(client)) {
108
+ throw new IncompatibleClientError("SmartAccountClient", "installValidation", client);
109
+ }
110
+ if (!account) {
111
+ throw new AccountNotFoundError();
112
+ }
100
113
  const callData = await encodeInstallValidation({
101
114
  validationConfig,
102
115
  selectors,
@@ -111,6 +124,12 @@ export const installValidationActions = (client) => {
111
124
  });
112
125
  },
113
126
  uninstallValidation: async ({ moduleAddress, entityId, uninstallData, hookUninstallDatas, account = client.account, overrides, }) => {
127
+ if (!account) {
128
+ throw new AccountNotFoundError();
129
+ }
130
+ if (!isSmartAccountClient(client)) {
131
+ throw new IncompatibleClientError("SmartAccountClient", "uninstallValidation", client);
132
+ }
114
133
  const callData = await encodeUninstallValidation({
115
134
  moduleAddress,
116
135
  entityId,
@@ -125,5 +144,5 @@ export const installValidationActions = (client) => {
125
144
  });
126
145
  },
127
146
  };
128
- };
147
+ }
129
148
  //# sourceMappingURL=installValidation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"installValidation.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/actions/install-validation/installValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,uBAAuB,EACvB,oBAAoB,EACpB,qBAAqB,GAKtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAGL,kBAAkB,EAClB,SAAS,EACT,WAAW,GACZ,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAC;AAE5F,OAAO,EACL,yBAAyB,EACzB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAA+B,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAyB,MAAM,8CAA8C,CAAC;AACrF,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AA+CzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAII,CAAC,MAAM,EAAE,EAAE;IAClD,MAAM,uBAAuB,GAAG,KAAK,EAAE,EACrC,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,KAAK,EACL,OAAO,GAAG,MAAM,CAAC,OAAO,GACA,EAAE,EAAE;QAC5B,IAAI,CAAC,OAAO,EAAE,CAAC;YACb,MAAM,IAAI,oBAAoB,EAAE,CAAC;QACnC,CAAC;QAED,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;YAClC,MAAM,IAAI,uBAAuB,CAC/B,oBAAoB,EACpB,mBAAmB,EACnB,MAAM,CACP,CAAC;QACJ,CAAC;QAED,2GAA2G;QAC3G,IACE,gBAAgB,CAAC,QAAQ,KAAK,uBAAuB;YACrD,gBAAgB,CAAC,aAAa,KAAK,WAAW,EAC9C,CAAC;YACD,MAAM,IAAI,qBAAqB,EAAE,CAAC;QACpC,CAAC;QAED,OAAO,OAAO,CAAC,cAAc,CAC3B,kBAAkB,CA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ACT,WAAW;gBACX,KAAK;gBACL,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC,iBAAiB,CAAC;gBAC9B,EAAE,EAAE,QAAQ;gBACZ,OAAO;gBACP,SAAS;aACV,CAAC,CAAC;QACL,CAAC;QAED,mBAAmB,EAAE,KAAK,EAAE,EAC1B,aAAa,EACb,QAAQ,EACR,aAAa,EACb,kBAAkB,EAClB,OAAO,GAAG,MAAM,CAAC,OAAO,EACxB,SAAS,GACV,EAAE,EAAE;YACH,MAAM,QAAQ,GAAG,MAAM,yBAAyB,CAAC;gBAC/C,aAAa;gBACb,QAAQ;gBACR,aAAa;gBACb,kBAAkB;gBAClB,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC,iBAAiB,CAAC;gBAC9B,EAAE,EAAE,QAAQ;gBACZ,OAAO;gBACP,SAAS;aACV,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n AccountNotFoundError,\n IncompatibleClientError,\n isSmartAccountClient,\n EntityIdOverrideError,\n type GetEntryPointFromAccount,\n type SendUserOperationResult,\n type UserOperationOverridesParameter,\n type SmartAccountSigner,\n} from \"@aa-sdk/core\";\nimport {\n type Address,\n type Hex,\n encodeFunctionData,\n concatHex,\n zeroAddress,\n} from \"viem\";\n\nimport { semiModularAccountBytecodeAbi } from \"../../abis/semiModularAccountBytecodeAbi.js\";\nimport type { HookConfig, ValidationConfig } from \"../common/types.js\";\nimport {\n serializeValidationConfig,\n serializeHookConfig,\n serializeModuleEntity,\n} from \"../common/utils.js\";\n\nimport { type ModularAccountV2Client } from \"../../client/client.js\";\nimport { type ModularAccountV2 } from \"../../account/common/modularAccountV2Base.js\";\nimport { DEFAULT_OWNER_ENTITY_ID } from \"../../utils.js\";\n\nexport type InstallValidationParams<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = {\n validationConfig: ValidationConfig;\n selectors: Hex[];\n installData: Hex;\n hooks: {\n hookConfig: HookConfig;\n initData: Hex;\n }[];\n account?: ModularAccountV2<TSigner> | undefined;\n} & UserOperationOverridesParameter<\n GetEntryPointFromAccount<ModularAccountV2<TSigner>>\n>;\n\nexport type UninstallValidationParams<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = {\n moduleAddress: Address;\n entityId: number;\n uninstallData: Hex;\n hookUninstallDatas: Hex[];\n account?: ModularAccountV2<TSigner> | undefined;\n} & UserOperationOverridesParameter<\n GetEntryPointFromAccount<ModularAccountV2<TSigner>>\n>;\n\nexport type InstallValidationActions<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n> = {\n installValidation: (\n args: InstallValidationParams<TSigner>,\n ) => Promise<SendUserOperationResult>;\n encodeInstallValidation: (\n // TODO: omit the user op sending related parameters from this type\n args: InstallValidationParams<TSigner>,\n ) => Promise<Hex>;\n uninstallValidation: (\n args: UninstallValidationParams<TSigner>,\n ) => Promise<SendUserOperationResult>;\n encodeUninstallValidation: (\n args: UninstallValidationParams<TSigner>,\n ) => Promise<Hex>;\n};\n\n/**\n * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @example\n * ```ts\n * import { createModularAccountV2Client, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from \"@account-kit/smart-contracts\";\n * import { Address } from \"viem\";\n *\n * const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);\n * const sessionKeyAddress: Address = \"0x1234\";\n * const sessionKeyEntityId: number = 1;\n *\n * await client.installValidation({\n * validationConfig: {\n * moduleAddress: getDefaultSingleSignerValidationModuleAddress(\n * client.chain\n * ),\n * entityId: sessionKeyEntityId,\n * isGlobal: true,\n * isSignatureValidation: false,\n * isUserOpValidation: true,\n * },\n * selectors: [],\n * installData: SingleSignerValidationModule.encodeOnInstallData({\n * entityId: sessionKeyEntityId,\n * signer: sessionKeyAddress,\n * }),\n * hooks: [],\n * });\n *\n * await client.uninstallValidation({\n * moduleAddress: sessionKeyAddress,\n * entityId: sessionKeyEntityId,\n * uninstallData: SingleSignerValidationModule.encodeOnUninstallData({\n * entityId: sessionKeyEntityId,\n * }),\n * hookUninstallDatas: [],\n * });\n *\n * ```\n *\n * @param {object} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.\n */\nexport const installValidationActions: <\n TSigner extends SmartAccountSigner = SmartAccountSigner,\n>(\n client: ModularAccountV2Client<TSigner>,\n) => InstallValidationActions<TSigner> = (client) => {\n const encodeInstallValidation = async ({\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n }: InstallValidationParams) => {\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!isSmartAccountClient(client)) {\n throw new IncompatibleClientError(\n \"SmartAccountClient\",\n \"installValidation\",\n client,\n );\n }\n\n // an entityId of zero is only allowed if we're installing or uninstalling hooks on the fallback validation\n if (\n validationConfig.entityId === DEFAULT_OWNER_ENTITY_ID &&\n validationConfig.moduleAddress !== zeroAddress\n ) {\n throw new EntityIdOverrideError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"installValidation\",\n args: [\n serializeValidationConfig(validationConfig),\n selectors,\n installData,\n hooks.map((hook: { hookConfig: HookConfig; initData: Hex }) =>\n concatHex([serializeHookConfig(hook.hookConfig), hook.initData]),\n ),\n ],\n }),\n );\n };\n\n const encodeUninstallValidation = async ({\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n }: UninstallValidationParams) => {\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!isSmartAccountClient(client)) {\n throw new IncompatibleClientError(\n \"SmartAccountClient\",\n \"uninstallValidation\",\n client,\n );\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"uninstallValidation\",\n args: [\n serializeModuleEntity({\n moduleAddress,\n entityId,\n }),\n uninstallData,\n hookUninstallDatas,\n ],\n }),\n );\n };\n\n return {\n encodeInstallValidation,\n encodeUninstallValidation,\n installValidation: async ({\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n overrides,\n }) => {\n const callData = await encodeInstallValidation({\n validationConfig,\n selectors,\n installData,\n hooks,\n account,\n });\n\n return client.sendUserOperation({\n uo: callData,\n account,\n overrides,\n });\n },\n\n uninstallValidation: async ({\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n overrides,\n }) => {\n const callData = await encodeUninstallValidation({\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account,\n });\n\n return client.sendUserOperation({\n uo: callData,\n account,\n overrides,\n });\n },\n };\n};\n"]}
1
+ {"version":3,"file":"installValidation.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/actions/install-validation/installValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,oBAAoB,EACpB,yBAAyB,EACzB,qBAAqB,EAGrB,uBAAuB,EAGvB,oBAAoB,EACpB,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAML,SAAS,EACT,kBAAkB,EAClB,WAAW,GACZ,MAAM,MAAM,CAAC;AAEd,OAAO,EAAE,6BAA6B,EAAE,MAAM,6CAA6C,CAAC;AAE5F,OAAO,EACL,mBAAmB,EACnB,qBAAqB,EACrB,yBAAyB,GAC1B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EAEL,kBAAkB,GACnB,MAAM,8CAA8C,CAAC;AACtD,OAAO,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AAiDzD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,MAAM,UAAU,wBAAwB,CAOtC,MAA4C;IAE5C,MAAM,uBAAuB,GAAG,KAAK,EAAE,EACrC,gBAAgB,EAChB,SAAS,EACT,WAAW,EACX,KAAK,EACL,OAAO,GAAG,MAAM,CAAC,OAAO,GACU,EAAE,EAAE;QACtC,IAAI,CAAC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GAAG,MAAM,CAAC,OAAO,EACxB,SAAS,GAC2B,EAAE,EAAE;YACxC,IAAI,CAAC,OAAO,EAAE,CAAC;gBACb,MAAM,IAAI,oBAAoB,EAAE,CAAC;YACnC,CAAC;YAED,IAAI,CAAC,oBAAoB,CAAC,MAAM,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,uBAAuB,CAC/B,oBAAoB,EACpB,qBAAqB,EACrB,MAAM,CACP,CAAC;YACJ,CAAC;YAED,MAAM,QAAQ,GAAQ,MAAM,yBAAyB,CAAC;gBACpD,aAAa;gBACb,QAAQ;gBACR,aAAa;gBACb,kBAAkB;gBAClB,OAAO;aACR,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC,iBAAiB,CAAC;gBAC9B,EAAE,EAAE,QAAQ;gBACZ,OAAO;gBACP,SAAS;aACV,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC","sourcesContent":["import {\n AccountNotFoundError,\n NotAModularAccountV2Error,\n EntityIdOverrideError,\n type GetAccountParameter,\n type GetEntryPointFromAccount,\n IncompatibleClientError,\n type SendUserOperationResult,\n type UserOperationOverridesParameter,\n isSmartAccountClient,\n isSmartAccountWithSigner,\n} from \"@aa-sdk/core\";\nimport {\n type Address,\n type Chain,\n type Client,\n type Hex,\n type Transport,\n concatHex,\n encodeFunctionData,\n zeroAddress,\n} from \"viem\";\n\nimport { semiModularAccountBytecodeAbi } from \"../../abis/semiModularAccountBytecodeAbi.js\";\nimport type { HookConfig, ValidationConfig } from \"../common/types.js\";\nimport {\n serializeHookConfig,\n serializeModuleEntity,\n serializeValidationConfig,\n} from \"../common/utils.js\";\n\nimport {\n type ModularAccountsV2,\n isModularAccountV2,\n} from \"../../account/common/modularAccountV2Base.js\";\nimport { DEFAULT_OWNER_ENTITY_ID } from \"../../utils.js\";\n\nexport type InstallValidationParams<\n TAccount extends ModularAccountsV2 | undefined =\n | ModularAccountsV2\n | undefined,\n> = {\n validationConfig: ValidationConfig;\n selectors: Hex[];\n installData: Hex;\n hooks: {\n hookConfig: HookConfig;\n initData: Hex;\n }[];\n} & UserOperationOverridesParameter<GetEntryPointFromAccount<TAccount>> &\n GetAccountParameter<TAccount>;\n\nexport type UninstallValidationParams<\n TAccount extends ModularAccountsV2 | undefined =\n | ModularAccountsV2\n | undefined,\n> = {\n moduleAddress: Address;\n entityId: number;\n uninstallData: Hex;\n hookUninstallDatas: Hex[];\n} & UserOperationOverridesParameter<GetEntryPointFromAccount<TAccount>> &\n GetAccountParameter<TAccount>;\n\nexport type InstallValidationActions<\n TAccount extends ModularAccountsV2 | undefined =\n | ModularAccountsV2\n | undefined,\n> = {\n installValidation: (\n args: InstallValidationParams<TAccount>,\n ) => Promise<SendUserOperationResult>;\n encodeInstallValidation: (\n // TODO: omit the user op sending related parameters from this type\n args: InstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n uninstallValidation: (\n args: UninstallValidationParams<TAccount>,\n ) => Promise<SendUserOperationResult>;\n encodeUninstallValidation: (\n args: UninstallValidationParams<TAccount>,\n ) => Promise<Hex>;\n};\n\n/**\n * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.\n *\n * @example\n * ```ts\n * import { createModularAccountV2Client, installValidationActions, getDefaultSingleSignerValidationModuleAddress, SingleSignerValidationModule } from \"@account-kit/smart-contracts\";\n * import { Address } from \"viem\";\n *\n * const client = (await createModularAccountV2Client({ ... })).extend(installValidationActions);\n * const sessionKeyAddress: Address = \"0x1234\";\n * const sessionKeyEntityId: number = 1;\n *\n * await client.installValidation({\n * validationConfig: {\n * moduleAddress: getDefaultSingleSignerValidationModuleAddress(\n * client.chain\n * ),\n * entityId: sessionKeyEntityId,\n * isGlobal: true,\n * isSignatureValidation: false,\n * isUserOpValidation: true,\n * },\n * selectors: [],\n * installData: SingleSignerValidationModule.encodeOnInstallData({\n * entityId: sessionKeyEntityId,\n * signer: sessionKeyAddress,\n * }),\n * hooks: [],\n * });\n *\n * await client.uninstallValidation({\n * moduleAddress: sessionKeyAddress,\n * entityId: sessionKeyEntityId,\n * uninstallData: SingleSignerValidationModule.encodeOnUninstallData({\n * entityId: sessionKeyEntityId,\n * }),\n * hookUninstallDatas: [],\n * });\n *\n * ```\n *\n * @param {object} client - The client instance which provides account and sendUserOperation functionality.\n * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.\n */\nexport function installValidationActions<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends ModularAccountsV2 | undefined =\n | ModularAccountsV2\n | undefined,\n>(\n client: Client<TTransport, TChain, TAccount>,\n): InstallValidationActions<TAccount> {\n const encodeInstallValidation = async ({\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n }: InstallValidationParams<TAccount>) => {\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!isModularAccountV2(account)) {\n throw new NotAModularAccountV2Error();\n }\n\n if (isSmartAccountWithSigner(account) && !isSmartAccountClient(client)) {\n // if we don't differentiate between WebauthnModularAccountV2Client and ModularAccountV2Client, passing client to isSmartAccountClient complains\n throw new IncompatibleClientError(\n \"SmartAccountClient\",\n \"installValidation\",\n client,\n );\n }\n\n // an entityId of zero is only allowed if we're installing or uninstalling hooks on the fallback validation\n if (\n validationConfig.entityId === DEFAULT_OWNER_ENTITY_ID &&\n validationConfig.moduleAddress !== zeroAddress\n ) {\n throw new EntityIdOverrideError();\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"installValidation\",\n args: [\n serializeValidationConfig(validationConfig),\n selectors,\n installData,\n hooks.map((hook: { hookConfig: HookConfig; initData: Hex }) =>\n concatHex([serializeHookConfig(hook.hookConfig), hook.initData]),\n ),\n ],\n }),\n );\n };\n\n const encodeUninstallValidation = async ({\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n }: UninstallValidationParams<TAccount>) => {\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!isModularAccountV2(account)) {\n throw new NotAModularAccountV2Error();\n }\n\n if (isSmartAccountWithSigner(account) && !isSmartAccountClient(client)) {\n // if we don't differentiate between WebauthnModularAccountV2Client and ModularAccountV2Client, passing client to isSmartAccountClient complains\n throw new IncompatibleClientError(\n \"SmartAccountClient\",\n \"uninstallValidation\",\n client,\n );\n }\n\n return account.encodeCallData(\n encodeFunctionData({\n abi: semiModularAccountBytecodeAbi,\n functionName: \"uninstallValidation\",\n args: [\n serializeModuleEntity({\n moduleAddress,\n entityId,\n }),\n uninstallData,\n hookUninstallDatas,\n ],\n }),\n );\n };\n\n return {\n encodeInstallValidation,\n encodeUninstallValidation,\n installValidation: async ({\n validationConfig,\n selectors,\n installData,\n hooks,\n account = client.account,\n overrides,\n }: InstallValidationParams<TAccount>) => {\n if (!isSmartAccountClient(client)) {\n throw new IncompatibleClientError(\n \"SmartAccountClient\",\n \"installValidation\",\n client,\n );\n }\n\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n const callData = await encodeInstallValidation({\n validationConfig,\n selectors,\n installData,\n hooks,\n account,\n });\n\n return client.sendUserOperation({\n uo: callData,\n account,\n overrides,\n });\n },\n\n uninstallValidation: async ({\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account = client.account,\n overrides,\n }: UninstallValidationParams<TAccount>) => {\n if (!account) {\n throw new AccountNotFoundError();\n }\n\n if (!isSmartAccountClient(client)) {\n throw new IncompatibleClientError(\n \"SmartAccountClient\",\n \"uninstallValidation\",\n client,\n );\n }\n\n const callData: Hex = await encodeUninstallValidation({\n moduleAddress,\n entityId,\n uninstallData,\n hookUninstallDatas,\n account,\n });\n\n return client.sendUserOperation({\n uo: callData,\n account,\n overrides,\n });\n },\n };\n}\n"]}
@@ -1,7 +1,8 @@
1
- import { type SmartAccountSigner, type SmartContractAccountWithSigner, type ToSmartContractAccountParams, type SmartContractAccount } from "@aa-sdk/core";
2
- import { type Hex, type Address, type Chain, type Transport } from "viem";
1
+ import { type SmartAccountSigner, type SmartContractAccount, type SmartContractAccountWithSigner, type ToSmartContractAccountParams } from "@aa-sdk/core";
2
+ import { type Address, type Chain, type Hex, type Transport } from "viem";
3
3
  import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
4
4
  export declare const executeUserOpSelector: Hex;
5
+ export type ModularAccountsV2 = ModularAccountV2 | WebauthnModularAccountV2;
5
6
  export type SignerEntity = {
6
7
  isGlobalValidation: boolean;
7
8
  entityId: number;
@@ -52,4 +53,5 @@ export type CreateWebauthnMAV2BaseParams = Omit<CreateMAV2BaseParams, "signer">
52
53
  export type CreateMAV2BaseReturnType<TSigner extends SmartAccountSigner = SmartAccountSigner> = Promise<ModularAccountV2<TSigner>>;
53
54
  export declare function createMAv2Base(config: CreateWebauthnMAV2BaseParams): Promise<WebauthnModularAccountV2>;
54
55
  export declare function createMAv2Base<TSigner extends SmartAccountSigner = SmartAccountSigner>(config: CreateMAV2BaseParams): CreateMAV2BaseReturnType<TSigner>;
56
+ export declare function isModularAccountV2(account: SmartContractAccount): account is ModularAccountV2 | WebauthnModularAccountV2;
55
57
  //# sourceMappingURL=modularAccountV2Base.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"modularAccountV2Base.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,EACjC,KAAK,oBAAoB,EAC1B,MAAM,cAAc,CAAC;AAEtB,OAAO,EACL,KAAK,GAAG,EACR,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,SAAS,EAOf,MAAM,MAAM,CAAC;AAKd,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAG5E,eAAO,MAAM,qBAAqB,EAAE,GAAkB,CAAC;AAEvD,MAAM,MAAM,YAAY,GAAG;IACzB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,QAAQ,EAAE,MAAM,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B,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC"}
1
+ {"version":3,"file":"modularAccountV2Base.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/account/common/modularAccountV2Base.ts"],"names":[],"mappings":"AAAA,OAAO,EAQL,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EACzB,KAAK,8BAA8B,EACnC,KAAK,4BAA4B,EAClC,MAAM,cAAc,CAAC;AACtB,OAAO,EAOL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,GAAG,EACR,KAAK,SAAS,EACf,MAAM,MAAM,CAAC;AACd,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,0BAA0B,CAAC;AAQ5E,eAAO,MAAM,qBAAqB,EAAE,GAAkB,CAAC;AAEvD,MAAM,MAAM,iBAAiB,GAAG,gBAAgB,GAAG,wBAAwB,CAAC;AAE5E,MAAM,MAAM,YAAY,GAAG;IACzB,kBAAkB,EAAE,OAAO,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,MAAM,EAAE,OAAO,CAAC;IAChB,qBAAqB,EAAE,OAAO,CAAC;IAC/B,qBAAqB,EAAE,OAAO,CAAC;IAC/B,cAAc,EAAE,SAAS,GAAG,EAAE,CAAC;CAChC,CAAC;AAEF,MAAM,MAAM,kBAAkB,GAAG;IAC/B,eAAe,EAAE,SAAS,GAAG,EAAE,CAAC;IAChC,cAAc,EAAE,SAAS,GAAG,EAAE,CAAC;IAC/B,SAAS,EAAE,SAAS,GAAG,EAAE,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAC5B;IACE,uBAAuB,EAAE,OAAO,CAAC;IACjC,QAAQ,CAAC,EAAE,KAAK,CAAC;CAClB,GACD;IACE,uBAAuB,CAAC,EAAE,KAAK,CAAC;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAE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CAAC;IACxB,cAAc,CAAC,EAAE,GAAG,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG,IAAI,CAC7C,oBAAoB,EACpB,QAAQ,CACT,GAAG;IACF,UAAU,EAAE,2BAA2B,CAAC,YAAY,CAAC,CAAC;IACtD,KAAK,CAAC,EAAE,2BAA2B,CAAC,OAAO,CAAC,GAAG,SAAS,CAAC;IACzD,IAAI,CAAC,EAAE,2BAA2B,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC;CACxD,CAAC;AAEF,MAAM,MAAM,wBAAwB,CAClC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,IACrD,OAAO,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC;AAGvC,wBAAsB,cAAc,CAClC,MAAM,EAAE,4BAA4B,GACnC,OAAO,CAAC,wBAAwB,CAAC,CAAC;AAErC,wBAAsB,cAAc,CAClC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,EACvD,MAAM,EAAE,oBAAoB,GAAG,wBAAwB,CAAC,OAAO,CAAC,CAAC;AAsOnE,wBAAgB,kBAAkB,CAChC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,IAAI,gBAAgB,GAAG,wBAAwB,CAExD"}
@@ -1,9 +1,8 @@
1
- import { type GetEntryPointFromAccount, type SendUserOperationResult, type UserOperationOverridesParameter, type SmartAccountSigner } from "@aa-sdk/core";
2
- import { type Address, type Hex } from "viem";
1
+ import { type GetAccountParameter, type GetEntryPointFromAccount, type SendUserOperationResult, type UserOperationOverridesParameter } from "@aa-sdk/core";
2
+ import { type Address, type Chain, type Client, type Hex, type Transport } from "viem";
3
3
  import type { HookConfig, ValidationConfig } from "../common/types.js";
4
- import { type ModularAccountV2Client } from "../../client/client.js";
5
- import { type ModularAccountV2 } from "../../account/common/modularAccountV2Base.js";
6
- export type InstallValidationParams<TSigner extends SmartAccountSigner = SmartAccountSigner> = {
4
+ import { type ModularAccountsV2 } from "../../account/common/modularAccountV2Base.js";
5
+ export type InstallValidationParams<TAccount extends ModularAccountsV2 | undefined = ModularAccountsV2 | undefined> = {
7
6
  validationConfig: ValidationConfig;
8
7
  selectors: Hex[];
9
8
  installData: Hex;
@@ -11,20 +10,18 @@ export type InstallValidationParams<TSigner extends SmartAccountSigner = SmartAc
11
10
  hookConfig: HookConfig;
12
11
  initData: Hex;
13
12
  }[];
14
- account?: ModularAccountV2<TSigner> | undefined;
15
- } & UserOperationOverridesParameter<GetEntryPointFromAccount<ModularAccountV2<TSigner>>>;
16
- export type UninstallValidationParams<TSigner extends SmartAccountSigner = SmartAccountSigner> = {
13
+ } & UserOperationOverridesParameter<GetEntryPointFromAccount<TAccount>> & GetAccountParameter<TAccount>;
14
+ export type UninstallValidationParams<TAccount extends ModularAccountsV2 | undefined = ModularAccountsV2 | undefined> = {
17
15
  moduleAddress: Address;
18
16
  entityId: number;
19
17
  uninstallData: Hex;
20
18
  hookUninstallDatas: Hex[];
21
- account?: ModularAccountV2<TSigner> | undefined;
22
- } & UserOperationOverridesParameter<GetEntryPointFromAccount<ModularAccountV2<TSigner>>>;
23
- export type InstallValidationActions<TSigner extends SmartAccountSigner = SmartAccountSigner> = {
24
- installValidation: (args: InstallValidationParams<TSigner>) => Promise<SendUserOperationResult>;
25
- encodeInstallValidation: (args: InstallValidationParams<TSigner>) => Promise<Hex>;
26
- uninstallValidation: (args: UninstallValidationParams<TSigner>) => Promise<SendUserOperationResult>;
27
- encodeUninstallValidation: (args: UninstallValidationParams<TSigner>) => Promise<Hex>;
19
+ } & UserOperationOverridesParameter<GetEntryPointFromAccount<TAccount>> & GetAccountParameter<TAccount>;
20
+ export type InstallValidationActions<TAccount extends ModularAccountsV2 | undefined = ModularAccountsV2 | undefined> = {
21
+ installValidation: (args: InstallValidationParams<TAccount>) => Promise<SendUserOperationResult>;
22
+ encodeInstallValidation: (args: InstallValidationParams<TAccount>) => Promise<Hex>;
23
+ uninstallValidation: (args: UninstallValidationParams<TAccount>) => Promise<SendUserOperationResult>;
24
+ encodeUninstallValidation: (args: UninstallValidationParams<TAccount>) => Promise<Hex>;
28
25
  };
29
26
  /**
30
27
  * Provides validation installation and uninstallation functionalities for a MA v2 client, ensuring compatibility with `SmartAccountClient`.
@@ -70,5 +67,5 @@ export type InstallValidationActions<TSigner extends SmartAccountSigner = SmartA
70
67
  * @param {object} client - The client instance which provides account and sendUserOperation functionality.
71
68
  * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.
72
69
  */
73
- export declare const installValidationActions: <TSigner extends SmartAccountSigner = SmartAccountSigner>(client: ModularAccountV2Client<TSigner>) => InstallValidationActions<TSigner>;
70
+ export declare function installValidationActions<TTransport extends Transport = Transport, TChain extends Chain | undefined = Chain | undefined, TAccount extends ModularAccountsV2 | undefined = ModularAccountsV2 | undefined>(client: Client<TTransport, TChain, TAccount>): InstallValidationActions<TAccount>;
74
71
  //# sourceMappingURL=installValidation.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"installValidation.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/actions/install-validation/installValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAC5B,KAAK,+BAA+B,EACpC,KAAK,kBAAkB,EACxB,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,GAAG,EAIT,MAAM,MAAM,CAAC;AAGd,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAOvE,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,wBAAwB,CAAC;AACrE,OAAO,EAAE,KAAK,gBAAgB,EAAE,MAAM,8CAA8C,CAAC;AAGrF,MAAM,MAAM,uBAAuB,CACjC,OAAO,SAAS,kBAAkB,GAAG,kBAAkB,IACrD;IACF,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,WAAW,EAAE,GAAG,CAAC;I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kB,EAEvD,MAAM,EAAE,sBAAsB,CAAC,OAAO,CAAC,KACpC,wBAAwB,CAAC,OAAO,CAgIpC,CAAC"}
1
+ {"version":3,"file":"installValidation.d.ts","sourceRoot":"","sources":["../../../../../../src/ma-v2/actions/install-validation/installValidation.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,mBAAmB,EACxB,KAAK,wBAAwB,EAE7B,KAAK,uBAAuB,EAC5B,KAAK,+BAA+B,EAGrC,MAAM,cAAc,CAAC;AACtB,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,KAAK,EACV,KAAK,MAAM,EACX,KAAK,GAAG,EACR,KAAK,SAAS,EAIf,MAAM,MAAM,CAAC;AAGd,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AAOvE,OAAO,EACL,KAAK,iBAAiB,EAEvB,MAAM,8CAA8C,CAAC;AAGtD,MAAM,MAAM,uBAAuB,CACjC,QAAQ,SAAS,iBAAiB,GAAG,SAAS,GAC1C,iBAAiB,GACjB,SAAS,IACX;IACF,gBAAgB,EAAE,gBAAgB,CAAC;IACnC,SAAS,EAAE,GAAG,EAAE,CAAC;IACjB,WAAW,EAAE,GAAG,CAAC;IACjB,KAAK,EAAE;QACL,UAAU,EAAE,UAAU,CAAC;QACvB,QAAQ,EAAE,GAAG,CAAC;KACf,EAAE,CAAC;CACL,GAAG,+BAA+B,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,GACrE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAEhC,MAAM,MAAM,yBAAyB,CACnC,QAAQ,SAAS,iBAAiB,GAAG,SAAS,GAC1C,iBAAiB,GACjB,SAAS,IACX;IACF,aAAa,EAAE,OAAO,CAAC;IACvB,QAAQ,EAAE,MAAM,CAAC;IACjB,aAAa,EAAE,GAAG,CAAC;IACnB,kBAAkB,EAAE,GAAG,EAAE,CAAC;CAC3B,GAAG,+BAA+B,CAAC,wBAAwB,CAAC,QAAQ,CAAC,CAAC,GACrE,mBAAmB,CAAC,QAAQ,CAAC,CAAC;AAEhC,MAAM,MAAM,wBAAwB,CAClC,QAAQ,SAAS,iBAAiB,GAAG,SAAS,GAC1C,iBAAiB,GACjB,SAAS,IACX;IACF,iBAAiB,EAAE,CACjB,IAAI,EAAE,uBAAuB,CAAC,QAAQ,CAAC,KACpC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,uBAAuB,EAAE,CAEvB,IAAI,EAAE,uBAAuB,CAAC,QAAQ,CAAC,KACpC,OAAO,CAAC,GAAG,CAAC,CAAC;IAClB,mBAAmB,EAAE,CACnB,IAAI,EAAE,yBAAyB,CAAC,QAAQ,CAAC,KACtC,OAAO,CAAC,uBAAuB,CAAC,CAAC;IACtC,yBAAyB,EAAE,CACzB,IAAI,EAAE,yBAAyB,CAAC,QAAQ,CAAC,KACtC,OAAO,CAAC,GAAG,CAAC,CAAC;CACnB,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,wBAAwB,CACtC,UAAU,SAAS,SAAS,GAAG,SAAS,EACxC,MAAM,SAAS,KAAK,GAAG,SAAS,GAAG,KAAK,GAAG,SAAS,EACpD,QAAQ,SAAS,iBAAiB,GAAG,SAAS,GAC1C,iBAAiB,GACjB,SAAS,EAEb,MAAM,EAAE,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,QAAQ,CAAC,GAC3C,wBAAwB,CAAC,QAAQ,CAAC,CAkKpC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@account-kit/smart-contracts",
3
- "version": "4.44.0",
3
+ "version": "4.46.0",
4
4
  "description": "aa-sdk compatible interfaces for Alchemy Smart Accounts",
5
5
  "author": "Alchemy",
6
6
  "license": "MIT",
@@ -52,7 +52,7 @@
52
52
  "test:run": "vitest run"
53
53
  },
54
54
  "devDependencies": {
55
- "@account-kit/plugingen": "^4.44.0",
55
+ "@account-kit/plugingen": "^4.46.0",
56
56
  "change-case": "^5.1.2",
57
57
  "dedent": "^1.5.1",
58
58
  "dotenv": "^16.3.1",
@@ -70,10 +70,10 @@
70
70
  "url": "https://github.com/alchemyplatform/aa-sdk/issues"
71
71
  },
72
72
  "homepage": "https://github.com/alchemyplatform/aa-sdk#readme",
73
- "gitHead": "29c87d1385f13cffcb55e6286bfaeb26637d5fe9",
73
+ "gitHead": "fb516cc1ba7059a257fb329fb8663c7cc90947bb",
74
74
  "dependencies": {
75
- "@aa-sdk/core": "^4.44.0",
76
- "@account-kit/infra": "^4.44.0",
75
+ "@aa-sdk/core": "^4.46.0",
76
+ "@account-kit/infra": "^4.46.0",
77
77
  "webauthn-p256": "^0.0.10"
78
78
  },
79
79
  "peerDependencies": {
@@ -1,38 +1,40 @@
1
1
  import {
2
2
  createBundlerClient,
3
3
  getEntryPoint,
4
+ InvalidDeferredActionNonce,
4
5
  InvalidEntityIdError,
5
6
  InvalidNonceKeyError,
6
- InvalidDeferredActionNonce,
7
7
  toSmartContractAccount,
8
8
  type AccountOp,
9
9
  type SmartAccountSigner,
10
+ type SmartContractAccount,
10
11
  type SmartContractAccountWithSigner,
11
12
  type ToSmartContractAccountParams,
12
- type SmartContractAccount,
13
13
  } from "@aa-sdk/core";
14
- import { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from "../../utils.js";
15
14
  import {
16
- type Hex,
17
- type Address,
18
- type Chain,
19
- type Transport,
15
+ concatHex,
20
16
  encodeFunctionData,
21
- maxUint32,
22
- zeroAddress,
23
17
  getContract,
24
- concatHex,
25
18
  maxUint152,
19
+ maxUint32,
20
+ zeroAddress,
21
+ type Address,
22
+ type Chain,
23
+ type Hex,
24
+ type Transport,
26
25
  } from "viem";
26
+ import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
27
27
  import { modularAccountAbi } from "../../abis/modularAccountAbi.js";
28
28
  import { serializeModuleEntity } from "../../actions/common/utils.js";
29
- import { nativeSMASigner } from "../nativeSMASigner.js";
30
29
  import { singleSignerMessageSigner } from "../../modules/single-signer-validation/signer.js";
31
- import type { ToWebAuthnAccountParameters } from "viem/account-abstraction";
32
30
  import { webauthnSigningFunctions } from "../../modules/webauthn-validation/signingMethods.js";
31
+ import { DEFAULT_OWNER_ENTITY_ID, parseDeferredAction } from "../../utils.js";
32
+ import { nativeSMASigner } from "../nativeSMASigner.js";
33
33
 
34
34
  export const executeUserOpSelector: Hex = "0x8DD7712F";
35
35
 
36
+ export type ModularAccountsV2 = ModularAccountV2 | WebauthnModularAccountV2;
37
+
36
38
  export type SignerEntity = {
37
39
  isGlobalValidation: boolean;
38
40
  entityId: number;
@@ -358,3 +360,9 @@ export async function createMAv2Base<
358
360
  encodeCallData,
359
361
  } as ModularAccountV2<TSigner>; // TO DO: figure out when this breaks! we shouldn't have to cast
360
362
  }
363
+
364
+ export function isModularAccountV2(
365
+ account: SmartContractAccount,
366
+ ): account is ModularAccountV2 | WebauthnModularAccountV2 {
367
+ return account.source === "ModularAccountV2";
368
+ }
@@ -1,35 +1,44 @@
1
1
  import {
2
2
  AccountNotFoundError,
3
- IncompatibleClientError,
4
- isSmartAccountClient,
3
+ NotAModularAccountV2Error,
5
4
  EntityIdOverrideError,
5
+ type GetAccountParameter,
6
6
  type GetEntryPointFromAccount,
7
+ IncompatibleClientError,
7
8
  type SendUserOperationResult,
8
9
  type UserOperationOverridesParameter,
9
- type SmartAccountSigner,
10
+ isSmartAccountClient,
11
+ isSmartAccountWithSigner,
10
12
  } from "@aa-sdk/core";
11
13
  import {
12
14
  type Address,
15
+ type Chain,
16
+ type Client,
13
17
  type Hex,
14
- encodeFunctionData,
18
+ type Transport,
15
19
  concatHex,
20
+ encodeFunctionData,
16
21
  zeroAddress,
17
22
  } from "viem";
18
23
 
19
24
  import { semiModularAccountBytecodeAbi } from "../../abis/semiModularAccountBytecodeAbi.js";
20
25
  import type { HookConfig, ValidationConfig } from "../common/types.js";
21
26
  import {
22
- serializeValidationConfig,
23
27
  serializeHookConfig,
24
28
  serializeModuleEntity,
29
+ serializeValidationConfig,
25
30
  } from "../common/utils.js";
26
31
 
27
- import { type ModularAccountV2Client } from "../../client/client.js";
28
- import { type ModularAccountV2 } from "../../account/common/modularAccountV2Base.js";
32
+ import {
33
+ type ModularAccountsV2,
34
+ isModularAccountV2,
35
+ } from "../../account/common/modularAccountV2Base.js";
29
36
  import { DEFAULT_OWNER_ENTITY_ID } from "../../utils.js";
30
37
 
31
38
  export type InstallValidationParams<
32
- TSigner extends SmartAccountSigner = SmartAccountSigner,
39
+ TAccount extends ModularAccountsV2 | undefined =
40
+ | ModularAccountsV2
41
+ | undefined,
33
42
  > = {
34
43
  validationConfig: ValidationConfig;
35
44
  selectors: Hex[];
@@ -38,38 +47,38 @@ export type InstallValidationParams<
38
47
  hookConfig: HookConfig;
39
48
  initData: Hex;
40
49
  }[];
41
- account?: ModularAccountV2<TSigner> | undefined;
42
- } & UserOperationOverridesParameter<
43
- GetEntryPointFromAccount<ModularAccountV2<TSigner>>
44
- >;
50
+ } & UserOperationOverridesParameter<GetEntryPointFromAccount<TAccount>> &
51
+ GetAccountParameter<TAccount>;
45
52
 
46
53
  export type UninstallValidationParams<
47
- TSigner extends SmartAccountSigner = SmartAccountSigner,
54
+ TAccount extends ModularAccountsV2 | undefined =
55
+ | ModularAccountsV2
56
+ | undefined,
48
57
  > = {
49
58
  moduleAddress: Address;
50
59
  entityId: number;
51
60
  uninstallData: Hex;
52
61
  hookUninstallDatas: Hex[];
53
- account?: ModularAccountV2<TSigner> | undefined;
54
- } & UserOperationOverridesParameter<
55
- GetEntryPointFromAccount<ModularAccountV2<TSigner>>
56
- >;
62
+ } & UserOperationOverridesParameter<GetEntryPointFromAccount<TAccount>> &
63
+ GetAccountParameter<TAccount>;
57
64
 
58
65
  export type InstallValidationActions<
59
- TSigner extends SmartAccountSigner = SmartAccountSigner,
66
+ TAccount extends ModularAccountsV2 | undefined =
67
+ | ModularAccountsV2
68
+ | undefined,
60
69
  > = {
61
70
  installValidation: (
62
- args: InstallValidationParams<TSigner>,
71
+ args: InstallValidationParams<TAccount>,
63
72
  ) => Promise<SendUserOperationResult>;
64
73
  encodeInstallValidation: (
65
74
  // TODO: omit the user op sending related parameters from this type
66
- args: InstallValidationParams<TSigner>,
75
+ args: InstallValidationParams<TAccount>,
67
76
  ) => Promise<Hex>;
68
77
  uninstallValidation: (
69
- args: UninstallValidationParams<TSigner>,
78
+ args: UninstallValidationParams<TAccount>,
70
79
  ) => Promise<SendUserOperationResult>;
71
80
  encodeUninstallValidation: (
72
- args: UninstallValidationParams<TSigner>,
81
+ args: UninstallValidationParams<TAccount>,
73
82
  ) => Promise<Hex>;
74
83
  };
75
84
 
@@ -117,23 +126,32 @@ export type InstallValidationActions<
117
126
  * @param {object} client - The client instance which provides account and sendUserOperation functionality.
118
127
  * @returns {object} - An object containing two methods, `installValidation` and `uninstallValidation`.
119
128
  */
120
- export const installValidationActions: <
121
- TSigner extends SmartAccountSigner = SmartAccountSigner,
129
+ export function installValidationActions<
130
+ TTransport extends Transport = Transport,
131
+ TChain extends Chain | undefined = Chain | undefined,
132
+ TAccount extends ModularAccountsV2 | undefined =
133
+ | ModularAccountsV2
134
+ | undefined,
122
135
  >(
123
- client: ModularAccountV2Client<TSigner>,
124
- ) => InstallValidationActions<TSigner> = (client) => {
136
+ client: Client<TTransport, TChain, TAccount>,
137
+ ): InstallValidationActions<TAccount> {
125
138
  const encodeInstallValidation = async ({
126
139
  validationConfig,
127
140
  selectors,
128
141
  installData,
129
142
  hooks,
130
143
  account = client.account,
131
- }: InstallValidationParams) => {
144
+ }: InstallValidationParams<TAccount>) => {
132
145
  if (!account) {
133
146
  throw new AccountNotFoundError();
134
147
  }
135
148
 
136
- if (!isSmartAccountClient(client)) {
149
+ if (!isModularAccountV2(account)) {
150
+ throw new NotAModularAccountV2Error();
151
+ }
152
+
153
+ if (isSmartAccountWithSigner(account) && !isSmartAccountClient(client)) {
154
+ // if we don't differentiate between WebauthnModularAccountV2Client and ModularAccountV2Client, passing client to isSmartAccountClient complains
137
155
  throw new IncompatibleClientError(
138
156
  "SmartAccountClient",
139
157
  "installValidation",
@@ -171,12 +189,17 @@ export const installValidationActions: <
171
189
  uninstallData,
172
190
  hookUninstallDatas,
173
191
  account = client.account,
174
- }: UninstallValidationParams) => {
192
+ }: UninstallValidationParams<TAccount>) => {
175
193
  if (!account) {
176
194
  throw new AccountNotFoundError();
177
195
  }
178
196
 
179
- if (!isSmartAccountClient(client)) {
197
+ if (!isModularAccountV2(account)) {
198
+ throw new NotAModularAccountV2Error();
199
+ }
200
+
201
+ if (isSmartAccountWithSigner(account) && !isSmartAccountClient(client)) {
202
+ // if we don't differentiate between WebauthnModularAccountV2Client and ModularAccountV2Client, passing client to isSmartAccountClient complains
180
203
  throw new IncompatibleClientError(
181
204
  "SmartAccountClient",
182
205
  "uninstallValidation",
@@ -210,7 +233,19 @@ export const installValidationActions: <
210
233
  hooks,
211
234
  account = client.account,
212
235
  overrides,
213
- }) => {
236
+ }: InstallValidationParams<TAccount>) => {
237
+ if (!isSmartAccountClient(client)) {
238
+ throw new IncompatibleClientError(
239
+ "SmartAccountClient",
240
+ "installValidation",
241
+ client,
242
+ );
243
+ }
244
+
245
+ if (!account) {
246
+ throw new AccountNotFoundError();
247
+ }
248
+
214
249
  const callData = await encodeInstallValidation({
215
250
  validationConfig,
216
251
  selectors,
@@ -233,8 +268,20 @@ export const installValidationActions: <
233
268
  hookUninstallDatas,
234
269
  account = client.account,
235
270
  overrides,
236
- }) => {
237
- const callData = await encodeUninstallValidation({
271
+ }: UninstallValidationParams<TAccount>) => {
272
+ if (!account) {
273
+ throw new AccountNotFoundError();
274
+ }
275
+
276
+ if (!isSmartAccountClient(client)) {
277
+ throw new IncompatibleClientError(
278
+ "SmartAccountClient",
279
+ "uninstallValidation",
280
+ client,
281
+ );
282
+ }
283
+
284
+ const callData: Hex = await encodeUninstallValidation({
238
285
  moduleAddress,
239
286
  entityId,
240
287
  uninstallData,
@@ -249,4 +296,4 @@ export const installValidationActions: <
249
296
  });
250
297
  },
251
298
  };
252
- };
299
+ }