@account-kit/smart-contracts 4.25.1 → 4.27.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.
Files changed (29) hide show
  1. package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js +29 -17
  2. package/dist/esm/src/ma-v2/account/common/modularAccountV2Base.js.map +1 -1
  3. package/dist/esm/src/ma-v2/account/nativeSMASigner.js +6 -2
  4. package/dist/esm/src/ma-v2/account/nativeSMASigner.js.map +1 -1
  5. package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js +6 -2
  6. package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js.map +1 -1
  7. package/dist/esm/src/ma-v2/permissionBuilder.js +8 -1
  8. package/dist/esm/src/ma-v2/permissionBuilder.js.map +1 -1
  9. package/dist/esm/src/ma-v2/permissionBuilderErrors.d.ts +22 -11
  10. package/dist/esm/src/ma-v2/permissionBuilderErrors.js +29 -11
  11. package/dist/esm/src/ma-v2/permissionBuilderErrors.js.map +1 -1
  12. package/dist/esm/src/ma-v2/utils.d.ts +2 -0
  13. package/dist/esm/src/ma-v2/utils.js +4 -1
  14. package/dist/esm/src/ma-v2/utils.js.map +1 -1
  15. package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -1
  16. package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts.map +1 -1
  17. package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts.map +1 -1
  18. package/dist/types/src/ma-v2/permissionBuilder.d.ts.map +1 -1
  19. package/dist/types/src/ma-v2/permissionBuilderErrors.d.ts +22 -11
  20. package/dist/types/src/ma-v2/permissionBuilderErrors.d.ts.map +1 -1
  21. package/dist/types/src/ma-v2/utils.d.ts +2 -0
  22. package/dist/types/src/ma-v2/utils.d.ts.map +1 -1
  23. package/package.json +5 -5
  24. package/src/ma-v2/account/common/modularAccountV2Base.ts +29 -18
  25. package/src/ma-v2/account/nativeSMASigner.ts +7 -2
  26. package/src/ma-v2/modules/single-signer-validation/signer.ts +7 -2
  27. package/src/ma-v2/permissionBuilder.ts +9 -0
  28. package/src/ma-v2/permissionBuilderErrors.ts +26 -11
  29. package/src/ma-v2/utils.ts +8 -1
@@ -7,7 +7,7 @@ import { nativeSMASigner } from "../nativeSMASigner.js";
7
7
  import { singleSignerMessageSigner } from "../../modules/single-signer-validation/signer.js";
8
8
  export const executeUserOpSelector = "0x8DD7712F";
9
9
  export async function createMAv2Base(config) {
10
- const { transport, chain, signer, entryPoint = getEntryPoint(chain, { version: "0.7.0" }), signerEntity = {
10
+ let { transport, chain, signer, entryPoint = getEntryPoint(chain, { version: "0.7.0" }), signerEntity = {
11
11
  isGlobalValidation: true,
12
12
  entityId: DEFAULT_OWNER_ENTITY_ID,
13
13
  }, signerEntity: { isGlobalValidation = true, entityId = DEFAULT_OWNER_ENTITY_ID, } = {}, accountAddress, deferredAction, ...remainingToSmartContractAccountParams } = config;
@@ -23,23 +23,29 @@ export async function createMAv2Base(config) {
23
23
  abi: entryPoint.abi,
24
24
  client,
25
25
  });
26
- let useDeferredAction = false;
27
- let nonce = 0n;
28
- let deferredActionData = "0x";
26
+ // These default values signal that we should not use the set deferred action nonce
27
+ let nonce;
28
+ let deferredActionData;
29
29
  let hasAssociatedExecHooks = false;
30
30
  if (deferredAction) {
31
- ({ nonce, deferredActionData, hasAssociatedExecHooks } =
32
- parseDeferredAction(deferredAction));
31
+ let deferredActionNonce = 0n;
32
+ // We always update entity id and isGlobalValidation to the deferred action value since the client could be used to send multiple calls
33
+ ({
34
+ entityId,
35
+ isGlobalValidation,
36
+ nonce: deferredActionNonce,
37
+ } = parseDeferredAction(deferredAction));
33
38
  // Set these values if the deferred action has not been consumed. We check this with the EP
34
39
  const nextNonceForDeferredAction = (await entryPointContract.read.getNonce([
35
40
  accountAddress,
36
- nonce >> 64n,
41
+ deferredActionNonce >> 64n,
37
42
  ]));
38
- // we only add the deferred action in if the nonce has not been consumed
39
- if (nonce === nextNonceForDeferredAction) {
40
- useDeferredAction = true;
43
+ if (deferredActionNonce === nextNonceForDeferredAction) {
44
+ ({ nonce, deferredActionData, hasAssociatedExecHooks } =
45
+ parseDeferredAction(deferredAction));
41
46
  }
42
- else if (nonce > nextNonceForDeferredAction) {
47
+ else if (deferredActionNonce > nextNonceForDeferredAction) {
48
+ // if nonce is greater than the next nonce, its invalid, so we throw
43
49
  throw new InvalidDeferredActionNonce();
44
50
  }
45
51
  }
@@ -61,8 +67,10 @@ export async function createMAv2Base(config) {
61
67
  }));
62
68
  const isAccountDeployed = async () => !!(await client.getCode({ address: accountAddress }));
63
69
  const getNonce = async (nonceKey = 0n) => {
64
- if (useDeferredAction) {
65
- return nonce;
70
+ if (nonce) {
71
+ const tempNonce = nonce;
72
+ nonce = undefined; // set to falsy value once used
73
+ return tempNonce;
66
74
  }
67
75
  if (nonceKey > maxUint152) {
68
76
  throw new InvalidNonceKeyError(nonceKey);
@@ -112,10 +120,14 @@ export async function createMAv2Base(config) {
112
120
  const validationData = await getValidationData({
113
121
  entityId: Number(entityId),
114
122
  });
115
- return (useDeferredAction && hasAssociatedExecHooks) ||
116
- validationData.executionHooks.length
117
- ? concatHex([executeUserOpSelector, callData])
118
- : callData;
123
+ if (hasAssociatedExecHooks) {
124
+ hasAssociatedExecHooks = false; // set to falsy value once used
125
+ return concatHex([executeUserOpSelector, callData]);
126
+ }
127
+ if (validationData.executionHooks.length) {
128
+ return concatHex([executeUserOpSelector, callData]);
129
+ }
130
+ return callData;
119
131
  };
120
132
  const baseAccount = await toSmartContractAccount({
121
133
  ...remainingToSmartContractAccountParams,
@@ -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,GAKvB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,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,CACnB,CAAC;KACP,CAAC,CAAC;IAEH,OAAO;QACL,GAAG,WAAW;QACd,SAAS,EAAE,GAAG,EAAE,CAAC,MAAM;QACvB,YAAY;QACZ,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACf,CAAC;AACJ,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} 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\";\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 CreateMAV2BaseParams<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\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> & {\n signer: TSigner;\n signerEntity?: SignerEntity;\n accountAddress: Address;\n deferredAction?: Hex;\n};\n\nexport type CreateMAV2BaseReturnType<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> = Promise<ModularAccountV2<TSigner>>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n>(config: CreateMAV2BaseParams<TSigner>): CreateMAV2BaseReturnType<TSigner> {\n const {\n transport,\n chain,\n signer,\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 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 let useDeferredAction: boolean = false;\n let nonce: bigint = 0n;\n let deferredActionData: Hex = \"0x\";\n let hasAssociatedExecHooks: boolean = false;\n\n if (deferredAction) {\n ({ nonce, deferredActionData, hasAssociatedExecHooks } =\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 nonce >> 64n,\n ])) as bigint;\n\n // we only add the deferred action in if the nonce has not been consumed\n if (nonce === nextNonceForDeferredAction) {\n useDeferredAction = true;\n } else if (nonce > nextNonceForDeferredAction) {\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 (useDeferredAction) {\n return nonce;\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\n return (useDeferredAction && hasAssociatedExecHooks) ||\n validationData.executionHooks.length\n ? concatHex([executeUserOpSelector, callData])\n : 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 ...(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 });\n\n return {\n ...baseAccount,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n };\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,oBAAoB,EACpB,oBAAoB,EACpB,0BAA0B,EAC1B,sBAAsB,GAKvB,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,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,yBAAyB,EAAE,MAAM,kDAAkD,CAAC;AAE7F,MAAM,CAAC,MAAM,qBAAqB,GAAQ,YAAY,CAAC;AAiEvD,MA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Z,gBAAgB;QAChB,iBAAiB;QACjB,cAAc;KACf,CAAC;AACJ,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} 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\";\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 CreateMAV2BaseParams<\n TSigner extends SmartAccountSigner = SmartAccountSigner,\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> & {\n signer: TSigner;\n signerEntity?: SignerEntity;\n accountAddress: Address;\n deferredAction?: Hex;\n};\n\nexport type CreateMAV2BaseReturnType<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n> = Promise<ModularAccountV2<TSigner>>;\n\nexport async function createMAv2Base<\n TSigner extends SmartAccountSigner = SmartAccountSigner\n>(config: CreateMAV2BaseParams<TSigner>): CreateMAV2BaseReturnType<TSigner> {\n let {\n transport,\n chain,\n signer,\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 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 ...(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 });\n\n return {\n ...baseAccount,\n getSigner: () => signer,\n signerEntity,\n getExecutionData,\n getValidationData,\n encodeCallData,\n };\n}\n"]}
@@ -34,13 +34,17 @@ export const nativeSMASigner = (signer, chain, accountAddress, deferredActionDat
34
34
  return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
35
35
  },
36
36
  signUserOperationHash: async (uoHash) => {
37
- const sig = await signer
37
+ let sig = await signer
38
38
  .signMessage({ raw: uoHash })
39
39
  .then((signature) => packUOSignature({
40
40
  // orderedHookData: [],
41
41
  validationSignature: signature,
42
42
  }));
43
- return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
43
+ if (deferredActionData) {
44
+ sig = concatHex([deferredActionData, sig]);
45
+ deferredActionData = undefined;
46
+ }
47
+ return sig;
44
48
  },
45
49
  // we apply the expected 1271 packing here since the account contract will expect it
46
50
  async signMessage({ message }) {
@@ -1 +1 @@
1
- {"version":3,"file":"nativeSMASigner.js","sourceRoot":"","sources":["../../../../../src/ma-v2/account/nativeSMASigner.ts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type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n hashMessage,\n hashTypedData,\n type Hex,\n type SignableMessage,\n type TypedData,\n type TypedDataDefinition,\n type Chain,\n type Address,\n concat,\n concatHex,\n} from \"viem\";\n\nimport {\n packUOSignature,\n pack1271Signature,\n DEFAULT_OWNER_ENTITY_ID,\n} from \"../utils.js\";\nimport { SignatureType } from \"../modules/utils.js\";\n/**\n * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.\n *\n * @example\n * ```ts\n * import { nativeSMASigner } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n *\n * const MNEMONIC = \"...\":\n *\n * const account = createModularAccountV2({ config });\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const messageSigner = nativeSMASigner(signer, chain, account.address);\n * ```\n *\n * @param {SmartAccountSigner} signer Signer to use for signing operations\n * @param {Chain} chain Chain object for the signer\n * @param {Address} accountAddress address of the smart account using this signer\n * @param {Hex} deferredActionData optional deferred action data to prepend to the uo signatures\n * @returns {object} an object with methods for signing operations and managing signatures\n */\nexport const nativeSMASigner = (\n signer: SmartAccountSigner,\n chain: Chain,\n accountAddress: Address,\n deferredActionData?: Hex\n) => {\n return {\n getDummySignature: (): Hex => {\n const sig = packUOSignature({\n // orderedHookData: [],\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n signUserOperationHash: async (uoHash: Hex): Promise<Hex> => {\n const sig = await signer\n .signMessage({ raw: uoHash })\n .then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n // we apply the expected 1271 packing here since the account contract will expect it\n async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {\n const hash = hashMessage(message);\n\n return pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract: accountAddress,\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash,\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId: DEFAULT_OWNER_ENTITY_ID,\n });\n },\n\n // TODO: maybe move \"sign deferred actions\" to a separate function?\n // we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing\n signTypedData: async <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\" = keyof typedData\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>\n ): Promise<Hex> => {\n // the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping\n const isDeferredAction =\n typedDataDefinition?.primaryType === \"DeferredAction\" &&\n typedDataDefinition?.domain?.verifyingContract === accountAddress;\n\n return isDeferredAction\n ? concat([\n SignatureType.EOA,\n await signer.signTypedData(typedDataDefinition),\n ])\n : pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract: accountAddress,\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash: await hashTypedData(typedDataDefinition),\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId: DEFAULT_OWNER_ENTITY_ID,\n });\n },\n };\n};\n"]}
1
+ {"version":3,"file":"nativeSMASigner.js","sourceRoot":"","sources":["../../../../../src/ma-v2/account/nativeSMASigner.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,EAOb,MAAM,EACN,SAAS,GACV,MAAM,MAAM,CAAC;AAEd,OAAO,EACL,eAAe,EACf,iBAAiB,EACjB,uBAAuB,GACxB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAq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,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;qBACpD;oBACD,OAAO,EAAE;wBACP,IAAI;qBACL;oBACD,WAAW,EAAE,gBAAgB;iBAC9B,CAAC;gBACF,QAAQ,EAAE,uBAAuB;aAClC,CAAC,CAAC;QACL,CAAC;QAED,mEAAmE;QACnE,qHAAqH;QACrH,aAAa,EAAE,KAAK,EAIlB,mBAAgE,EAClD,EAAE;YAChB,uIAAuI;YACvI,MAAM,gBAAgB,GACpB,mBAAmB,EAAE,WAAW,KAAK,gBAAgB;gBACrD,mBAAmB,EAAE,MAAM,EAAE,iBAAiB,KAAK,cAAc,CAAC;YAEpE,OAAO,gBAAgB;gBACrB,CAAC,CAAC,MAAM,CAAC;oBACL,aAAa,CAAC,GAAG;oBACjB,MAAM,MAAM,CAAC,aAAa,CAAC,mBAAmB,CAAC;iBAChD,CAAC;gBACJ,CAAC,CAAC,iBAAiB,CAAC;oBAChB,mBAAmB,EAAE,MAAM,MAAM,CAAC,aAAa,CAAC;wBAC9C,MAAM,EAAE;4BACN,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;4BACzB,iBAAiB,EAAE,cAAc;yBAClC;wBACD,KAAK,EAAE;4BACL,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;yBACpD;wBACD,OAAO,EAAE;4BACP,IAAI,EAAE,MAAM,aAAa,CAAC,mBAAmB,CAAC;yBAC/C;wBACD,WAAW,EAAE,gBAAgB;qBAC9B,CAAC;oBACF,QAAQ,EAAE,uBAAuB;iBAClC,CAAC,CAAC;QACT,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n hashMessage,\n hashTypedData,\n type Hex,\n type SignableMessage,\n type TypedData,\n type TypedDataDefinition,\n type Chain,\n type Address,\n concat,\n concatHex,\n} from \"viem\";\n\nimport {\n packUOSignature,\n pack1271Signature,\n DEFAULT_OWNER_ENTITY_ID,\n} from \"../utils.js\";\nimport { SignatureType } from \"../modules/utils.js\";\n/**\n * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.\n *\n * @example\n * ```ts\n * import { nativeSMASigner } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n *\n * const MNEMONIC = \"...\":\n *\n * const account = createModularAccountV2({ config });\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const messageSigner = nativeSMASigner(signer, chain, account.address);\n * ```\n *\n * @param {SmartAccountSigner} signer Signer to use for signing operations\n * @param {Chain} chain Chain object for the signer\n * @param {Address} accountAddress address of the smart account using this signer\n * @param {Hex} deferredActionData optional deferred action data to prepend to the uo signatures\n * @returns {object} an object with methods for signing operations and managing signatures\n */\nexport const nativeSMASigner = (\n signer: SmartAccountSigner,\n chain: Chain,\n accountAddress: Address,\n deferredActionData?: Hex\n) => {\n return {\n getDummySignature: (): Hex => {\n const sig = packUOSignature({\n // orderedHookData: [],\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n signUserOperationHash: async (uoHash: Hex): Promise<Hex> => {\n let sig = await signer\n .signMessage({ raw: uoHash })\n .then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n\n if (deferredActionData) {\n sig = concatHex([deferredActionData, sig]);\n deferredActionData = undefined;\n }\n\n return sig;\n },\n\n // we apply the expected 1271 packing here since the account contract will expect it\n async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {\n const hash = hashMessage(message);\n\n return pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract: accountAddress,\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash,\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId: DEFAULT_OWNER_ENTITY_ID,\n });\n },\n\n // TODO: maybe move \"sign deferred actions\" to a separate function?\n // we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing\n signTypedData: async <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\" = keyof typedData\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>\n ): Promise<Hex> => {\n // the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping\n const isDeferredAction =\n typedDataDefinition?.primaryType === \"DeferredAction\" &&\n typedDataDefinition?.domain?.verifyingContract === accountAddress;\n\n return isDeferredAction\n ? concat([\n SignatureType.EOA,\n await signer.signTypedData(typedDataDefinition),\n ])\n : pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract: accountAddress,\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash: await hashTypedData(typedDataDefinition),\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId: DEFAULT_OWNER_ENTITY_ID,\n });\n },\n };\n};\n"]}
@@ -36,13 +36,17 @@ export const singleSignerMessageSigner = (signer, chain, accountAddress, entityI
36
36
  return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
37
37
  },
38
38
  signUserOperationHash: async (uoHash) => {
39
- const sig = await signer
39
+ let sig = await signer
40
40
  .signMessage({ raw: uoHash })
41
41
  .then((signature) => packUOSignature({
42
42
  // orderedHookData: [],
43
43
  validationSignature: signature,
44
44
  }));
45
- return deferredActionData ? concatHex([deferredActionData, sig]) : sig;
45
+ if (deferredActionData) {
46
+ sig = concatHex([deferredActionData, sig]);
47
+ deferredActionData = undefined;
48
+ }
49
+ return sig;
46
50
  },
47
51
  // we apply the expected 1271 packing here since the account contract will expect it
48
52
  async signMessage({ message }) {
@@ -1 +1 @@
1
- {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/modules/single-signer-validation/signer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EAOT,MAAM,GACP,MAAM,MAAM,CAAC;AACd,OAAO,EACL,6CAA6C,EAC7C,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACpE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,MAA0B,EAC1B,KAAY,EACZ,cAAuB,EACvB,QAAgB,EAChB,kBAAwB,EACxB,EAAE;IACF,OAAO;QACL,iBAAiB,EAAE,GAAQ,EAAE;YAC3B,MAAM,GAAG,GAAG,eAAe,CAAC;gBAC1B,uBAAuB;gBACvB,mBAAmB,EACjB,sIAAsI;aACzI,CAAC,CAAC;YAEH,OAAO,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACzE,CAAC;QAED,qBAAqB,EAAE,KAAK,EAAE,MAAW,EAAgB,EAAE;YACzD,MAAM,GAAG,GAAG,MAAM,MAAM;iBACrB,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;iBAC5B,IAAI,CAAC,CAAC,SAAc,EAAE,EAAE,CACvB,eAAe,CAAC;gBACd,uBAAuB;gBACvB,mBAAmB,EAAE,SAAS;aAC/B,CAAC,CACH,CAAC;YAEJ,OAAO,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACzE,CAAC;QAED,oFAAoF;QACpF,KAAK,CAAC,WAAW,CAAC,EAAE,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iBACpD;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,aAAa,CAAC,mBAAmB,CAAC;iBACzC;gBACD,WAAW,EAAE,gBAAgB;aAC9B,CAAC,CAAC;YAEH,mCAAmC;YACnC,OAAO,gBAAgB;gBACrB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;gBAClD,CAAC,CAAC,iBAAiB,CAAC;oBAChB,mBAAmB;oBACnB,QAAQ;iBACT,CAAC,CAAC;QACT,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n hashMessage,\n hashTypedData,\n concatHex,\n type Hex,\n type SignableMessage,\n type TypedData,\n type TypedDataDefinition,\n type Chain,\n type Address,\n concat,\n} from \"viem\";\nimport {\n getDefaultSingleSignerValidationModuleAddress,\n SignatureType,\n} from \"../utils.js\";\n\nimport { packUOSignature, pack1271Signature } from \"../../utils.js\";\n/**\n * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.\n *\n * @example \n \n * ```ts\n * import { singleSignerMessageSigner } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n *\n * const MNEMONIC = \"...\":\n * \n * const account = createModularAccountV2({ config });\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const messageSigner = singleSignerMessageSigner(signer, chain, account.address, account.signerEntity.entityId);\n * ```\n *\n * @param {SmartAccountSigner} signer Signer to use for signing operations\n * @param {Chain} chain Chain object for the signer\n * @param {Address} accountAddress address of the smart account using this signer\n * @param {number} entityId the entity id of the signing validation\n * @param {Hex} deferredActionData optional deferred action data to prepend to the uo signatures\n * @returns {object} an object with methods for signing operations and managing signatures\n */\nexport const singleSignerMessageSigner = (\n signer: SmartAccountSigner,\n chain: Chain,\n accountAddress: Address,\n entityId: number,\n deferredActionData?: Hex\n) => {\n return {\n getDummySignature: (): Hex => {\n const sig = packUOSignature({\n // orderedHookData: [],\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n signUserOperationHash: async (uoHash: Hex): Promise<Hex> => {\n const sig = await signer\n .signMessage({ raw: uoHash })\n .then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n // we apply the expected 1271 packing here since the account contract will expect it\n async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {\n const hash = await hashMessage(message);\n\n return pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract:\n getDefaultSingleSignerValidationModuleAddress(chain),\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash,\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId,\n });\n },\n\n // TODO: maybe move \"sign deferred actions\" to a separate function?\n // we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing\n signTypedData: async <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\" = keyof typedData\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>\n ): Promise<Hex> => {\n // the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping\n const isDeferredAction =\n typedDataDefinition?.primaryType === \"DeferredAction\" &&\n typedDataDefinition?.domain?.verifyingContract === accountAddress;\n\n const validationSignature = await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract:\n getDefaultSingleSignerValidationModuleAddress(chain),\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash: hashTypedData(typedDataDefinition),\n },\n primaryType: \"ReplaySafeHash\",\n });\n\n // TODO: Handle non-EOA signer case\n return isDeferredAction\n ? concat([SignatureType.EOA, validationSignature])\n : pack1271Signature({\n validationSignature,\n entityId,\n });\n },\n };\n};\n"]}
1
+ {"version":3,"file":"signer.js","sourceRoot":"","sources":["../../../../../../src/ma-v2/modules/single-signer-validation/signer.ts"],"names":[],"mappings":"AACA,OAAO,EACL,WAAW,EACX,aAAa,EACb,SAAS,EAOT,MAAM,GACP,MAAM,MAAM,CAAC;AACd,OAAO,EACL,6CAA6C,EAC7C,aAAa,GACd,MAAM,aAAa,CAAC;AAErB,OAAO,EAAE,eAAe,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACpE;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,MAA0B,EAC1B,KAAY,EACZ,cAAuB,EACvB,QAAgB,EAChB,kBAAwB,EACxB,EAAE;IACF,OAAO;QACL,iBAAiB,EAAE,GAAQ,EAAE;YAC3B,MAAM,GAAG,GAAG,eAAe,CAAC;gBAC1B,uBAAuB;gBACvB,mBAAmB,EACjB,sIAAsI;aACzI,CAAC,CAAC;YAEH,OAAO,kBAAkB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;QACzE,CAAC;QAED,qBAAqB,EAAE,KAAK,EAAE,MAAW,EAAgB,EAAE;YACzD,IAAI,GAAG,GAAG,MAAM,MAAM;iBACnB,WAAW,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC;iBAC5B,IAAI,CAAC,CAAC,SAAc,EAAE,EAAE,CACvB,eAAe,CAAC;gBACd,uBAAuB;gBACvB,mBAAmB,EAAE,SAAS;aAC/B,CAAC,CACH,CAAC;Y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CAAC,KAAK,CAAC;oBACtD,IAAI,EAAE,SAAS,CAAC,CAAC,KAAK,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,EAAE,EAAE,cAAc,CAAC,CAAC;iBAC1D;gBACD,KAAK,EAAE;oBACL,cAAc,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;iBACpD;gBACD,OAAO,EAAE;oBACP,IAAI,EAAE,aAAa,CAAC,mBAAmB,CAAC;iBACzC;gBACD,WAAW,EAAE,gBAAgB;aAC9B,CAAC,CAAC;YAEH,mCAAmC;YACnC,OAAO,gBAAgB;gBACrB,CAAC,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,GAAG,EAAE,mBAAmB,CAAC,CAAC;gBAClD,CAAC,CAAC,iBAAiB,CAAC;oBAChB,mBAAmB;oBACnB,QAAQ;iBACT,CAAC,CAAC;QACT,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { SmartAccountSigner } from \"@aa-sdk/core\";\nimport {\n hashMessage,\n hashTypedData,\n concatHex,\n type Hex,\n type SignableMessage,\n type TypedData,\n type TypedDataDefinition,\n type Chain,\n type Address,\n concat,\n} from \"viem\";\nimport {\n getDefaultSingleSignerValidationModuleAddress,\n SignatureType,\n} from \"../utils.js\";\n\nimport { packUOSignature, pack1271Signature } from \"../../utils.js\";\n/**\n * Creates an object with methods for generating a dummy signature, signing user operation hashes, signing messages, and signing typed data.\n *\n * @example \n \n * ```ts\n * import { singleSignerMessageSigner } from \"@account-kit/smart-contracts\";\n * import { LocalAccountSigner } from \"@aa-sdk/core\";\n *\n * const MNEMONIC = \"...\":\n * \n * const account = createModularAccountV2({ config });\n *\n * const signer = LocalAccountSigner.mnemonicToAccountSigner(MNEMONIC);\n *\n * const messageSigner = singleSignerMessageSigner(signer, chain, account.address, account.signerEntity.entityId);\n * ```\n *\n * @param {SmartAccountSigner} signer Signer to use for signing operations\n * @param {Chain} chain Chain object for the signer\n * @param {Address} accountAddress address of the smart account using this signer\n * @param {number} entityId the entity id of the signing validation\n * @param {Hex} deferredActionData optional deferred action data to prepend to the uo signatures\n * @returns {object} an object with methods for signing operations and managing signatures\n */\nexport const singleSignerMessageSigner = (\n signer: SmartAccountSigner,\n chain: Chain,\n accountAddress: Address,\n entityId: number,\n deferredActionData?: Hex\n) => {\n return {\n getDummySignature: (): Hex => {\n const sig = packUOSignature({\n // orderedHookData: [],\n validationSignature:\n \"0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c\",\n });\n\n return deferredActionData ? concatHex([deferredActionData, sig]) : sig;\n },\n\n signUserOperationHash: async (uoHash: Hex): Promise<Hex> => {\n let sig = await signer\n .signMessage({ raw: uoHash })\n .then((signature: Hex) =>\n packUOSignature({\n // orderedHookData: [],\n validationSignature: signature,\n })\n );\n\n if (deferredActionData) {\n sig = concatHex([deferredActionData, sig]);\n deferredActionData = undefined;\n }\n\n return sig;\n },\n\n // we apply the expected 1271 packing here since the account contract will expect it\n async signMessage({ message }: { message: SignableMessage }): Promise<Hex> {\n const hash = await hashMessage(message);\n\n return pack1271Signature({\n validationSignature: await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract:\n getDefaultSingleSignerValidationModuleAddress(chain),\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash,\n },\n primaryType: \"ReplaySafeHash\",\n }),\n entityId,\n });\n },\n\n // TODO: maybe move \"sign deferred actions\" to a separate function?\n // we don't apply the expected 1271 packing since deferred sigs use typed data sigs and don't expect the 1271 packing\n signTypedData: async <\n const typedData extends TypedData | Record<string, unknown>,\n primaryType extends keyof typedData | \"EIP712Domain\" = keyof typedData\n >(\n typedDataDefinition: TypedDataDefinition<typedData, primaryType>\n ): Promise<Hex> => {\n // the accounts domain already gives replay protection across accounts for deferred actions, so we don't need to apply another wrapping\n const isDeferredAction =\n typedDataDefinition?.primaryType === \"DeferredAction\" &&\n typedDataDefinition?.domain?.verifyingContract === accountAddress;\n\n const validationSignature = await signer.signTypedData({\n domain: {\n chainId: Number(chain.id),\n verifyingContract:\n getDefaultSingleSignerValidationModuleAddress(chain),\n salt: concatHex([`0x${\"00\".repeat(12)}`, accountAddress]),\n },\n types: {\n ReplaySafeHash: [{ name: \"hash\", type: \"bytes32\" }],\n },\n message: {\n hash: hashTypedData(typedDataDefinition),\n },\n primaryType: \"ReplaySafeHash\",\n });\n\n // TODO: Handle non-EOA signer case\n return isDeferredAction\n ? concat([SignatureType.EOA, validationSignature])\n : pack1271Signature({\n validationSignature,\n entityId,\n });\n },\n };\n};\n"]}
@@ -7,7 +7,7 @@ import { getDefaultAllowlistModuleAddress, getDefaultNativeTokenLimitModuleAddre
7
7
  import { SingleSignerValidationModule } from "./modules/single-signer-validation/module.js";
8
8
  import { AllowlistModule } from "./modules/allowlist-module/module.js";
9
9
  import { TimeRangeModule } from "./modules/time-range-module/module.js";
10
- import { AccountAddressAsTargetError, DeadlineOverLimitError, DuplicateTargetAddressError, ExpiredDeadlineError, MultipleGasLimitError, MultipleNativeTokenTransferError, NoFunctionsProvidedError, RootPermissionOnlyError, UnsupportedPermissionTypeError, ValidationConfigUnsetError, ZeroAddressError, } from "./permissionBuilderErrors.js";
10
+ import { AccountAddressAsTargetError, DeadlineOverLimitError, DuplicateTargetAddressError, ExpiredDeadlineError, MultipleGasLimitError, MultipleNativeTokenTransferError, NoFunctionsProvidedError, RootPermissionOnlyError, SelectorNotAllowed, UnsupportedPermissionTypeError, ValidationConfigUnsetError, ZeroAddressError, } from "./permissionBuilderErrors.js";
11
11
  // We use this to offset the ERC20 spend limit entityId
12
12
  const HALF_UINT32 = 2147483647;
13
13
  const ERC20_APPROVE_SELECTOR = "0x095ea7b3";
@@ -164,6 +164,13 @@ export class PermissionBuilder {
164
164
  if (permission.data.functions.length === 0) {
165
165
  throw new NoFunctionsProvidedError(permission);
166
166
  }
167
+ // Explicitly disallow adding execute & executeBatch
168
+ if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {
169
+ throw new SelectorNotAllowed("execute");
170
+ }
171
+ else if (permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)) {
172
+ throw new SelectorNotAllowed("executeBatch");
173
+ }
167
174
  this.selectors = [...this.selectors, ...permission.data.functions];
168
175
  }
169
176
  this.permissions.push(permission);
@@ -1 +1 @@
1
- {"version":3,"file":"permissionBuilder.js","sourceRoot":"","sources":["../../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAA0B,MAAM,MAAM,CAAC;AAC7E,OAAO,EACL,QAAQ,GAGT,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,wBAAwB,GAEzB,MAAM,mDAAmD,CAAC;AAE3D,OAAO,EACL,eAAe,GAEhB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EACL,gCAAgC,EAChC,uCAAuC,EACvC,6CAA6C,EAC7C,gCAAgC,GACjC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,gCAAgC,EAChC,wBAAwB,EACxB,uBAAuB,EACvB,8BAA8B,EAC9B,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AAEtC,uDAAuD;AACvD,MAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,M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;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,QAAQ,CAAC,cAAc,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU;gBACpE,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAC3C,QAAQ,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CACvD;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,UAAU;gBACzD,QAAQ,EAAE,sBAAsB,CAAC,mBAAmB,CAClD,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,QAAQ,CAC5C;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,UAAU;gBAChE,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAC3C,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CACnD;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAC,MAAa;IACvC,MAAM,IAAI,8BAA8B,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import { maxUint48, toHex, zeroAddress, type Address, type Hex } from \"viem\";\nimport {\n HookType,\n type HookConfig,\n type ValidationConfig,\n} from \"./actions/common/types.js\";\nimport {\n installValidationActions,\n type InstallValidationParams,\n} from \"./actions/install-validation/installValidation.js\";\nimport type { ModularAccountV2Client } from \"./client/client.js\";\nimport {\n deferralActions,\n type DeferredActionTypedData,\n} from \"./actions/deferralActions.js\";\nimport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nimport {\n getDefaultAllowlistModuleAddress,\n getDefaultNativeTokenLimitModuleAddress,\n getDefaultSingleSignerValidationModuleAddress,\n getDefaultTimeRangeModuleAddress,\n} from \"./modules/utils.js\";\nimport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nimport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nimport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nimport {\n AccountAddressAsTargetError,\n DeadlineOverLimitError,\n DuplicateTargetAddressError,\n ExpiredDeadlineError,\n MultipleGasLimitError,\n MultipleNativeTokenTransferError,\n NoFunctionsProvidedError,\n RootPermissionOnlyError,\n UnsupportedPermissionTypeError,\n ValidationConfigUnsetError,\n ZeroAddressError,\n} from \"./permissionBuilderErrors.js\";\n\n// We use this to offset the ERC20 spend limit entityId\nconst HALF_UINT32 = 2147483647;\nconst ERC20_APPROVE_SELECTOR = \"0x095ea7b3\";\nconst ERC20_TRANSFER_SELECTOR = \"0xa9059cbb\";\nconst ACCOUNT_EXECUTE_SELECTOR = \"0xb61d27f6\";\nconst ACCOUNT_EXECUTEBATCH_SELECTOR = \"0x34fcd5be\";\n\nexport enum PermissionType {\n NATIVE_TOKEN_TRANSFER = \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER = \"erc20-token-transfer\",\n // ERC721_TOKEN_TRANSFER = \"erc721-token-transfer\", //Unimplemented\n // ERC1155_TOKEN_TRANSFER = \"erc1155-token-transfer\", //Unimplemented\n GAS_LIMIT = \"gas-limit\",\n // CALL_LIMIT = \"call-limit\", //Unimplemented\n // RATE_LIMIT = \"rate-limit\", //Unimplemented\n CONTRACT_ACCESS = \"contract-access\",\n ACCOUNT_FUNCTIONS = \"account-functions\",\n FUNCTIONS_ON_ALL_CONTRACTS = \"functions-on-all-contracts\",\n FUNCTIONS_ON_CONTRACT = \"functions-on-contract\",\n ROOT = \"root\",\n}\n\nenum HookIdentifier {\n NATIVE_TOKEN_TRANSFER,\n ERC20_TOKEN_TRANSFER,\n GAS_LIMIT,\n PREVAL_ALLOWLIST, // aggregate of CONTRACT_ACCESS, ACCOUNT_FUNCTIONS, FUNCTIONS_ON_ALL_CONTRACTS, FUNCTIONS_ON_CONTRACT\n}\n\ntype PreExecutionHookConfig = {\n address: Address;\n entityId: number;\n hookType: HookType.EXECUTION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype PreValidationHookConfig = {\n address: Address;\n entityId: number;\n hookType: HookType.VALIDATION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.ERC20_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n [HookIdentifier.GAS_LIMIT]:\n | {\n hookConfig: PreValidationHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.PREVAL_ALLOWLIST]:\n | {\n hookConfig: PreValidationHookConfig;\n\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n};\n\ntype OneOf<T extends {}[]> = T[number];\n\ntype Key = {\n publicKey: Hex;\n type: \"secp256k1\" | \"contract\";\n};\n\nexport type Permission = OneOf<\n [\n {\n // this permission allows transfer of native tokens from the account\n type: PermissionType.NATIVE_TOKEN_TRANSFER;\n data: {\n allowance: Hex;\n };\n },\n {\n // this permission allows transfer or approval of erc20 tokens from the account\n type: PermissionType.ERC20_TOKEN_TRANSFER;\n data: {\n address: Address; // erc20 token contract address\n allowance: Hex;\n };\n },\n {\n // this permissions allows the key to spend gas for UOs\n type: PermissionType.GAS_LIMIT;\n data: {\n limit: Hex;\n };\n },\n {\n // this permission grants access to all functions in a contract\n type: PermissionType.CONTRACT_ACCESS;\n data: {\n address: Address;\n };\n },\n {\n // this permission grants access to functions in the account\n type: PermissionType.ACCOUNT_FUNCTIONS;\n data: {\n functions: Hex[]; // function signatures\n };\n },\n {\n // this permission grants access to a function selector in any address or contract\n type: PermissionType.FUNCTIONS_ON_ALL_CONTRACTS;\n data: {\n functions: Hex[]; // function signatures\n };\n },\n {\n // this permission grants access to specified functions on a specific contract\n type: PermissionType.FUNCTIONS_ON_CONTRACT;\n data: {\n address: Address;\n functions: Hex[];\n };\n },\n {\n // this permission grants full access to everything\n type: PermissionType.ROOT;\n data?: never;\n }\n ]\n>;\n\ntype Hook = {\n hookConfig: HookConfig;\n initData: Hex;\n};\n\nexport class PermissionBuilder {\n private client: ModularAccountV2Client;\n private validationConfig: ValidationConfig = {\n moduleAddress: zeroAddress,\n entityId: 0, // uint32\n isGlobal: false,\n isSignatureValidation: false,\n isUserOpValidation: false,\n };\n private selectors: Hex[] = [];\n private installData: Hex = \"0x\";\n private permissions: Permission[] = [];\n private hooks: Hook[] = [];\n private nonce: bigint = 0n;\n private hasAssociatedExecHooks: boolean = false;\n private deadline: number = 0;\n\n constructor({\n client,\n key,\n entityId,\n nonce,\n selectors,\n hooks,\n deadline,\n }: {\n client: ModularAccountV2Client;\n key: Key;\n entityId: number;\n nonce: bigint;\n selectors?: Hex[];\n hooks?: Hook[];\n deadline?: number;\n }) {\n this.client = client;\n this.validationConfig = {\n moduleAddress: getDefaultSingleSignerValidationModuleAddress(\n this.client.chain\n ),\n entityId,\n isUserOpValidation: true,\n isGlobal: false,\n isSignatureValidation: false,\n };\n this.installData = SingleSignerValidationModule.encodeOnInstallData({\n entityId: entityId,\n signer: key.publicKey,\n });\n this.nonce = nonce;\n if (selectors) this.selectors = selectors;\n if (hooks) this.hooks = hooks;\n if (deadline) this.deadline = deadline;\n }\n\n addSelector({ selector }: { selector: Hex }): this {\n this.selectors.push(selector);\n return this;\n }\n\n addPermission({ permission }: { permission: Permission }): this {\n // Check 1: If we're adding root, we can't have any other permissions\n if (permission.type === PermissionType.ROOT) {\n if (this.permissions.length !== 0) {\n throw new RootPermissionOnlyError(permission);\n }\n this.permissions.push(permission);\n // Set isGlobal to true\n this.validationConfig.isGlobal = true;\n return this;\n }\n\n // Check 2: If the permission is NOT ROOT (guaranteed), ensure there is no ROOT permission set\n // Will resolve to undefined if ROOT is not found\n // NOTE: Technically this could be replaced by checking permissions[0] since it should not be possible\n // to have >1 permission with root among them\n if (this.permissions.find((p) => p.type === PermissionType.ROOT)) {\n throw new RootPermissionOnlyError(permission);\n }\n\n // Check 3: If the permission is either CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT, ensure it doesn't collide with another like it.\n if (\n permission.type === PermissionType.CONTRACT_ACCESS ||\n permission.type === PermissionType.FUNCTIONS_ON_CONTRACT\n ) {\n // Check 3.1: address must not be the account address, or the user should use the ACCOUNT_FUNCTIONS permission\n if (permission.data.address === this.client.account.address) {\n throw new AccountAddressAsTargetError(permission);\n }\n\n // Check 3.2: there must not be an existing permission with this address as a target\n const targetAddress = permission.data.address;\n const existingPermissionWithSameAddress = this.permissions.find(\n (p) =>\n (p.type === PermissionType.CONTRACT_ACCESS &&\n \"address\" in p.data &&\n p.data.address === targetAddress) ||\n (p.type === PermissionType.FUNCTIONS_ON_CONTRACT &&\n \"address\" in p.data &&\n p.data.address === targetAddress)\n );\n\n if (existingPermissionWithSameAddress) {\n throw new DuplicateTargetAddressError(permission, targetAddress);\n }\n }\n\n // Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors\n if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n this.selectors = [...this.selectors, ...permission.data.functions];\n }\n\n this.permissions.push(permission);\n return this;\n }\n\n addPermissions({ permissions }: { permissions: Permission[] }): this {\n // We could validate each permission here, but for simplicity we'll just add them\n // A better approach would be to call addPermission for each one\n permissions.forEach((permission) => {\n this.addPermission({ permission });\n });\n return this;\n }\n\n // Use for building deferred action typed data to sign\n async compileDeferred(): Promise<{\n typedData: DeferredActionTypedData;\n fullPreSignatureDeferredActionDigest: Hex;\n }> {\n // Add time range module hook via expiry\n if (this.deadline !== 0) {\n if (this.deadline < Date.now() / 1000) {\n throw new ExpiredDeadlineError(this.deadline, Date.now() / 1000);\n }\n if (this.deadline > maxUint48) {\n throw new DeadlineOverLimitError(this.deadline);\n }\n\n this.hooks.push(\n TimeRangeModule.buildHook(\n {\n entityId: this.validationConfig.entityId,\n validUntil: this.deadline,\n validAfter: 0,\n },\n getDefaultTimeRangeModuleAddress(this.client.chain)\n )\n );\n }\n\n const installValidationCall = await this.compileRaw();\n\n const { typedData } = await deferralActions(\n this.client\n ).createDeferredActionTypedDataObject({\n callData: installValidationCall,\n deadline: this.deadline,\n nonce: this.nonce,\n });\n\n const preSignatureDigest = deferralActions(\n this.client\n ).buildPreSignatureDeferredActionDigest({ typedData });\n\n // Encode additional information to build the full pre-signature digest\n const fullPreSignatureDeferredActionDigest: `0x${string}` = `0x0${\n this.hasAssociatedExecHooks ? \"1\" : \"0\"\n }${toHex(this.nonce, {\n size: 32,\n }).slice(2)}${preSignatureDigest.slice(2)}`;\n\n return {\n typedData,\n fullPreSignatureDeferredActionDigest,\n };\n }\n\n // Use for direct `installValidation()` low-level calls (maybe useless)\n async compileRaw(): Promise<Hex> {\n // Translate all permissions into raw hooks if >0\n if (this.permissions.length > 0) {\n const rawHooks = this.translatePermissions(\n this.validationConfig.entityId\n );\n // Add the translated permissions as hooks\n this.addHooks(rawHooks);\n }\n this.validateConfiguration();\n\n return await installValidationActions(this.client).encodeInstallValidation({\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account: this.client.account,\n });\n }\n\n // Use for compiling args to installValidation\n async compileInstallArgs(): Promise<InstallValidationParams> {\n this.validateConfiguration();\n\n return {\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account: this.client.account,\n };\n }\n\n private validateConfiguration(): void {\n if (\n this.validationConfig.isGlobal === false &&\n this.selectors.length === 0\n ) {\n throw new ValidationConfigUnsetError();\n }\n }\n\n // Used to translate consolidated permissions into raw unencoded hooks\n // Note entityId will be a member object later\n private translatePermissions(entityId: number): RawHooks {\n const rawHooks: RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.ERC20_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.GAS_LIMIT]: undefined,\n [HookIdentifier.PREVAL_ALLOWLIST]: undefined,\n };\n\n this.permissions.forEach((permission) => {\n switch (permission.type) {\n case PermissionType.NATIVE_TOKEN_TRANSFER:\n // Should never be added twice, check is on addPermission(s) too\n if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] !== undefined) {\n throw new MultipleNativeTokenTransferError(permission);\n }\n rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] = {\n hookConfig: {\n address: getDefaultNativeTokenLimitModuleAddress(\n this.client.chain\n ),\n entityId,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.allowance),\n },\n };\n this.hasAssociatedExecHooks = true;\n break;\n case PermissionType.ERC20_TOKEN_TRANSFER:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId: entityId + HALF_UINT32,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId: entityId + HALF_UINT32,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: true,\n erc20SpendLimit: BigInt(permission.data.allowance),\n selectors: [],\n },\n ],\n },\n };\n this.hasAssociatedExecHooks = true;\n // Also allow `approve` and `transfer` for the erc20\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [ERC20_APPROVE_SELECTOR, ERC20_TRANSFER_SELECTOR], // approve, transfer\n },\n ],\n },\n };\n break;\n case PermissionType.GAS_LIMIT:\n // Should only ever be added once, check is also on addPermission(s)\n if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {\n throw new MultipleGasLimitError(permission);\n }\n rawHooks[HookIdentifier.GAS_LIMIT] = {\n hookConfig: {\n address: getDefaultNativeTokenLimitModuleAddress(\n this.client.chain\n ),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.limit),\n },\n };\n break;\n case PermissionType.CONTRACT_ACCESS:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [],\n },\n ],\n },\n };\n break;\n case PermissionType.ACCOUNT_FUNCTIONS:\n // This is handled in add permissions\n break;\n case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: zeroAddress,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.FUNCTIONS_ON_CONTRACT:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.ROOT:\n // Root permission handled in addPermission\n break;\n default:\n assertNever(permission);\n }\n\n // isGlobal guaranteed to be false since it's only set with root permissions,\n // we must add access to execute & executeBatch if there's a preVal allowlist hook set.\n if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST] !== undefined) {\n const selectorsToAdd: `0x${string}`[] = [\n ACCOUNT_EXECUTE_SELECTOR,\n ACCOUNT_EXECUTEBATCH_SELECTOR,\n ]; // execute, executeBatch\n\n // Only add the selectors if they aren't already in this.selectors\n const newSelectors = selectorsToAdd.filter(\n (selector) => !this.selectors.includes(selector)\n );\n\n this.selectors = [...this.selectors, ...newSelectors];\n }\n });\n\n return rawHooks;\n }\n\n private addHooks(rawHooks: RawHooks) {\n if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER]) {\n this.hooks.push({\n hookConfig: rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER].hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(\n rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER].initData\n ),\n });\n }\n\n if (rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]) {\n this.hooks.push({\n hookConfig: rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER].hookConfig,\n initData: AllowlistModule.encodeOnInstallData(\n rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER].initData\n ),\n });\n }\n\n if (rawHooks[HookIdentifier.GAS_LIMIT]) {\n this.hooks.push({\n hookConfig: rawHooks[HookIdentifier.GAS_LIMIT].hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(\n rawHooks[HookIdentifier.GAS_LIMIT].initData\n ),\n });\n }\n\n if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST]) {\n this.hooks.push({\n hookConfig: rawHooks[HookIdentifier.PREVAL_ALLOWLIST].hookConfig,\n initData: AllowlistModule.encodeOnInstallData(\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST].initData\n ),\n });\n }\n }\n}\n\nexport function assertNever(_valid: never): never {\n throw new UnsupportedPermissionTypeError();\n}\n"]}
1
+ {"version":3,"file":"permissionBuilder.js","sourceRoot":"","sources":["../../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,WAAW,EAA0B,MAAM,MAAM,CAAC;AAC7E,OAAO,EACL,QAAQ,GAGT,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,wBAAwB,GAEzB,MAAM,mDAAmD,CAAC;AAE3D,OAAO,EACL,eAAe,GAEhB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EACL,gCAAgC,EAChC,uCAAuC,EACvC,6CAA6C,EAC7C,gCAAgC,GACjC,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,4BAA4B,EAAE,MAAM,8CAA8C,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,sCAAsC,CAAC;AACvE,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EACL,2BAA2B,EAC3B,sBAAsB,EACtB,2BAA2B,EAC3B,oBAAoB,EACpB,qBAAqB,EACrB,gCAAgC,EAChC,wBAAwB,EACxB,uBAAuB,EACvB,kBAAkB,EAClB,8BAA8B,EAC9B,0BAA0B,EAC1B,gBAAgB,GACjB,MAAM,8BAA8B,CAAC;AAEtC,uDAAuD;AACvD,MAAM,WAAW,GAAG,UAAU,CAAC;AAC/B,MAAM,sBAAsB,GAAG,YAAY,CAAC;AAC5C,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAC7C,MAAM,wBAAwB,GAAG,YAAY,CAAC;AAC9C,MAAM,6BAA6B,GAAG,YAAY,CAAC;AAEnD,MAAM,CAAN,IAAY,cAaX;AAbD,WAAY,cAAc;IACxB,iEAA+C,CAAA;IAC/C,+DAA6C,CAAA;IAC7C,mEAAmE;IACnE,qEAAqE;IACrE,yCAAuB,CAAA;IACvB,6CAA6C;IAC7C,6C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D;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,QAAQ,CAAC,cAAc,CAAC,oBAAoB,CAAC,EAAE,CAAC;YAClD,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,UAAU;gBACpE,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAC3C,QAAQ,CAAC,cAAc,CAAC,oBAAoB,CAAC,CAAC,QAAQ,CACvD;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,UAAU;gBACzD,QAAQ,EAAE,sBAAsB,CAAC,mBAAmB,CAClD,QAAQ,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC,QAAQ,CAC5C;aACF,CAAC,CAAC;QACL,CAAC;QAED,IAAI,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC9C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;gBACd,UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,UAAU;gBAChE,QAAQ,EAAE,eAAe,CAAC,mBAAmB,CAC3C,QAAQ,CAAC,cAAc,CAAC,gBAAgB,CAAC,CAAC,QAAQ,CACnD;aACF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AAED,MAAM,UAAU,WAAW,CAAC,MAAa;IACvC,MAAM,IAAI,8BAA8B,EAAE,CAAC;AAC7C,CAAC","sourcesContent":["import { maxUint48, toHex, zeroAddress, type Address, type Hex } from \"viem\";\nimport {\n HookType,\n type HookConfig,\n type ValidationConfig,\n} from \"./actions/common/types.js\";\nimport {\n installValidationActions,\n type InstallValidationParams,\n} from \"./actions/install-validation/installValidation.js\";\nimport type { ModularAccountV2Client } from \"./client/client.js\";\nimport {\n deferralActions,\n type DeferredActionTypedData,\n} from \"./actions/deferralActions.js\";\nimport { NativeTokenLimitModule } from \"./modules/native-token-limit-module/module.js\";\nimport {\n getDefaultAllowlistModuleAddress,\n getDefaultNativeTokenLimitModuleAddress,\n getDefaultSingleSignerValidationModuleAddress,\n getDefaultTimeRangeModuleAddress,\n} from \"./modules/utils.js\";\nimport { SingleSignerValidationModule } from \"./modules/single-signer-validation/module.js\";\nimport { AllowlistModule } from \"./modules/allowlist-module/module.js\";\nimport { TimeRangeModule } from \"./modules/time-range-module/module.js\";\nimport {\n AccountAddressAsTargetError,\n DeadlineOverLimitError,\n DuplicateTargetAddressError,\n ExpiredDeadlineError,\n MultipleGasLimitError,\n MultipleNativeTokenTransferError,\n NoFunctionsProvidedError,\n RootPermissionOnlyError,\n SelectorNotAllowed,\n UnsupportedPermissionTypeError,\n ValidationConfigUnsetError,\n ZeroAddressError,\n} from \"./permissionBuilderErrors.js\";\n\n// We use this to offset the ERC20 spend limit entityId\nconst HALF_UINT32 = 2147483647;\nconst ERC20_APPROVE_SELECTOR = \"0x095ea7b3\";\nconst ERC20_TRANSFER_SELECTOR = \"0xa9059cbb\";\nconst ACCOUNT_EXECUTE_SELECTOR = \"0xb61d27f6\";\nconst ACCOUNT_EXECUTEBATCH_SELECTOR = \"0x34fcd5be\";\n\nexport enum PermissionType {\n NATIVE_TOKEN_TRANSFER = \"native-token-transfer\",\n ERC20_TOKEN_TRANSFER = \"erc20-token-transfer\",\n // ERC721_TOKEN_TRANSFER = \"erc721-token-transfer\", //Unimplemented\n // ERC1155_TOKEN_TRANSFER = \"erc1155-token-transfer\", //Unimplemented\n GAS_LIMIT = \"gas-limit\",\n // CALL_LIMIT = \"call-limit\", //Unimplemented\n // RATE_LIMIT = \"rate-limit\", //Unimplemented\n CONTRACT_ACCESS = \"contract-access\",\n ACCOUNT_FUNCTIONS = \"account-functions\",\n FUNCTIONS_ON_ALL_CONTRACTS = \"functions-on-all-contracts\",\n FUNCTIONS_ON_CONTRACT = \"functions-on-contract\",\n ROOT = \"root\",\n}\n\nenum HookIdentifier {\n NATIVE_TOKEN_TRANSFER,\n ERC20_TOKEN_TRANSFER,\n GAS_LIMIT,\n PREVAL_ALLOWLIST, // aggregate of CONTRACT_ACCESS, ACCOUNT_FUNCTIONS, FUNCTIONS_ON_ALL_CONTRACTS, FUNCTIONS_ON_CONTRACT\n}\n\ntype PreExecutionHookConfig = {\n address: Address;\n entityId: number;\n hookType: HookType.EXECUTION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype PreValidationHookConfig = {\n address: Address;\n entityId: number;\n hookType: HookType.VALIDATION;\n hasPreHooks: true;\n hasPostHooks: false;\n};\n\ntype RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.ERC20_TOKEN_TRANSFER]:\n | {\n hookConfig: PreExecutionHookConfig;\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n [HookIdentifier.GAS_LIMIT]:\n | {\n hookConfig: PreValidationHookConfig;\n initData: {\n entityId: number;\n spendLimit: bigint;\n };\n }\n | undefined;\n [HookIdentifier.PREVAL_ALLOWLIST]:\n | {\n hookConfig: PreValidationHookConfig;\n\n initData: {\n entityId: number;\n inputs: Array<{\n target: Address;\n hasSelectorAllowlist: boolean;\n hasERC20SpendLimit: boolean;\n erc20SpendLimit: bigint;\n selectors: Array<Hex>;\n }>;\n };\n }\n | undefined;\n};\n\ntype OneOf<T extends {}[]> = T[number];\n\ntype Key = {\n publicKey: Hex;\n type: \"secp256k1\" | \"contract\";\n};\n\nexport type Permission = OneOf<\n [\n {\n // this permission allows transfer of native tokens from the account\n type: PermissionType.NATIVE_TOKEN_TRANSFER;\n data: {\n allowance: Hex;\n };\n },\n {\n // this permission allows transfer or approval of erc20 tokens from the account\n type: PermissionType.ERC20_TOKEN_TRANSFER;\n data: {\n address: Address; // erc20 token contract address\n allowance: Hex;\n };\n },\n {\n // this permissions allows the key to spend gas for UOs\n type: PermissionType.GAS_LIMIT;\n data: {\n limit: Hex;\n };\n },\n {\n // this permission grants access to all functions in a contract\n type: PermissionType.CONTRACT_ACCESS;\n data: {\n address: Address;\n };\n },\n {\n // this permission grants access to functions in the account\n type: PermissionType.ACCOUNT_FUNCTIONS;\n data: {\n functions: Hex[]; // function signatures\n };\n },\n {\n // this permission grants access to a function selector in any address or contract\n type: PermissionType.FUNCTIONS_ON_ALL_CONTRACTS;\n data: {\n functions: Hex[]; // function signatures\n };\n },\n {\n // this permission grants access to specified functions on a specific contract\n type: PermissionType.FUNCTIONS_ON_CONTRACT;\n data: {\n address: Address;\n functions: Hex[];\n };\n },\n {\n // this permission grants full access to everything\n type: PermissionType.ROOT;\n data?: never;\n }\n ]\n>;\n\ntype Hook = {\n hookConfig: HookConfig;\n initData: Hex;\n};\n\nexport class PermissionBuilder {\n private client: ModularAccountV2Client;\n private validationConfig: ValidationConfig = {\n moduleAddress: zeroAddress,\n entityId: 0, // uint32\n isGlobal: false,\n isSignatureValidation: false,\n isUserOpValidation: false,\n };\n private selectors: Hex[] = [];\n private installData: Hex = \"0x\";\n private permissions: Permission[] = [];\n private hooks: Hook[] = [];\n private nonce: bigint = 0n;\n private hasAssociatedExecHooks: boolean = false;\n private deadline: number = 0;\n\n constructor({\n client,\n key,\n entityId,\n nonce,\n selectors,\n hooks,\n deadline,\n }: {\n client: ModularAccountV2Client;\n key: Key;\n entityId: number;\n nonce: bigint;\n selectors?: Hex[];\n hooks?: Hook[];\n deadline?: number;\n }) {\n this.client = client;\n this.validationConfig = {\n moduleAddress: getDefaultSingleSignerValidationModuleAddress(\n this.client.chain\n ),\n entityId,\n isUserOpValidation: true,\n isGlobal: false,\n isSignatureValidation: false,\n };\n this.installData = SingleSignerValidationModule.encodeOnInstallData({\n entityId: entityId,\n signer: key.publicKey,\n });\n this.nonce = nonce;\n if (selectors) this.selectors = selectors;\n if (hooks) this.hooks = hooks;\n if (deadline) this.deadline = deadline;\n }\n\n addSelector({ selector }: { selector: Hex }): this {\n this.selectors.push(selector);\n return this;\n }\n\n addPermission({ permission }: { permission: Permission }): this {\n // Check 1: If we're adding root, we can't have any other permissions\n if (permission.type === PermissionType.ROOT) {\n if (this.permissions.length !== 0) {\n throw new RootPermissionOnlyError(permission);\n }\n this.permissions.push(permission);\n // Set isGlobal to true\n this.validationConfig.isGlobal = true;\n return this;\n }\n\n // Check 2: If the permission is NOT ROOT (guaranteed), ensure there is no ROOT permission set\n // Will resolve to undefined if ROOT is not found\n // NOTE: Technically this could be replaced by checking permissions[0] since it should not be possible\n // to have >1 permission with root among them\n if (this.permissions.find((p) => p.type === PermissionType.ROOT)) {\n throw new RootPermissionOnlyError(permission);\n }\n\n // Check 3: If the permission is either CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT, ensure it doesn't collide with another like it.\n if (\n permission.type === PermissionType.CONTRACT_ACCESS ||\n permission.type === PermissionType.FUNCTIONS_ON_CONTRACT\n ) {\n // Check 3.1: address must not be the account address, or the user should use the ACCOUNT_FUNCTIONS permission\n if (permission.data.address === this.client.account.address) {\n throw new AccountAddressAsTargetError(permission);\n }\n\n // Check 3.2: there must not be an existing permission with this address as a target\n const targetAddress = permission.data.address;\n const existingPermissionWithSameAddress = this.permissions.find(\n (p) =>\n (p.type === PermissionType.CONTRACT_ACCESS &&\n \"address\" in p.data &&\n p.data.address === targetAddress) ||\n (p.type === PermissionType.FUNCTIONS_ON_CONTRACT &&\n \"address\" in p.data &&\n p.data.address === targetAddress)\n );\n\n if (existingPermissionWithSameAddress) {\n throw new DuplicateTargetAddressError(permission, targetAddress);\n }\n }\n\n // Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors\n if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n // Explicitly disallow adding execute & executeBatch\n if (permission.data.functions.includes(ACCOUNT_EXECUTE_SELECTOR)) {\n throw new SelectorNotAllowed(\"execute\");\n } else if (\n permission.data.functions.includes(ACCOUNT_EXECUTEBATCH_SELECTOR)\n ) {\n throw new SelectorNotAllowed(\"executeBatch\");\n }\n this.selectors = [...this.selectors, ...permission.data.functions];\n }\n\n this.permissions.push(permission);\n return this;\n }\n\n addPermissions({ permissions }: { permissions: Permission[] }): this {\n // We could validate each permission here, but for simplicity we'll just add them\n // A better approach would be to call addPermission for each one\n permissions.forEach((permission) => {\n this.addPermission({ permission });\n });\n return this;\n }\n\n // Use for building deferred action typed data to sign\n async compileDeferred(): Promise<{\n typedData: DeferredActionTypedData;\n fullPreSignatureDeferredActionDigest: Hex;\n }> {\n // Add time range module hook via expiry\n if (this.deadline !== 0) {\n if (this.deadline < Date.now() / 1000) {\n throw new ExpiredDeadlineError(this.deadline, Date.now() / 1000);\n }\n if (this.deadline > maxUint48) {\n throw new DeadlineOverLimitError(this.deadline);\n }\n\n this.hooks.push(\n TimeRangeModule.buildHook(\n {\n entityId: this.validationConfig.entityId,\n validUntil: this.deadline,\n validAfter: 0,\n },\n getDefaultTimeRangeModuleAddress(this.client.chain)\n )\n );\n }\n\n const installValidationCall = await this.compileRaw();\n\n const { typedData } = await deferralActions(\n this.client\n ).createDeferredActionTypedDataObject({\n callData: installValidationCall,\n deadline: this.deadline,\n nonce: this.nonce,\n });\n\n const preSignatureDigest = deferralActions(\n this.client\n ).buildPreSignatureDeferredActionDigest({ typedData });\n\n // Encode additional information to build the full pre-signature digest\n const fullPreSignatureDeferredActionDigest: `0x${string}` = `0x0${\n this.hasAssociatedExecHooks ? \"1\" : \"0\"\n }${toHex(this.nonce, {\n size: 32,\n }).slice(2)}${preSignatureDigest.slice(2)}`;\n\n return {\n typedData,\n fullPreSignatureDeferredActionDigest,\n };\n }\n\n // Use for direct `installValidation()` low-level calls (maybe useless)\n async compileRaw(): Promise<Hex> {\n // Translate all permissions into raw hooks if >0\n if (this.permissions.length > 0) {\n const rawHooks = this.translatePermissions(\n this.validationConfig.entityId\n );\n // Add the translated permissions as hooks\n this.addHooks(rawHooks);\n }\n this.validateConfiguration();\n\n return await installValidationActions(this.client).encodeInstallValidation({\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account: this.client.account,\n });\n }\n\n // Use for compiling args to installValidation\n async compileInstallArgs(): Promise<InstallValidationParams> {\n this.validateConfiguration();\n\n return {\n validationConfig: this.validationConfig,\n selectors: this.selectors,\n installData: this.installData,\n hooks: this.hooks,\n account: this.client.account,\n };\n }\n\n private validateConfiguration(): void {\n if (\n this.validationConfig.isGlobal === false &&\n this.selectors.length === 0\n ) {\n throw new ValidationConfigUnsetError();\n }\n }\n\n // Used to translate consolidated permissions into raw unencoded hooks\n // Note entityId will be a member object later\n private translatePermissions(entityId: number): RawHooks {\n const rawHooks: RawHooks = {\n [HookIdentifier.NATIVE_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.ERC20_TOKEN_TRANSFER]: undefined,\n [HookIdentifier.GAS_LIMIT]: undefined,\n [HookIdentifier.PREVAL_ALLOWLIST]: undefined,\n };\n\n this.permissions.forEach((permission) => {\n switch (permission.type) {\n case PermissionType.NATIVE_TOKEN_TRANSFER:\n // Should never be added twice, check is on addPermission(s) too\n if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] !== undefined) {\n throw new MultipleNativeTokenTransferError(permission);\n }\n rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER] = {\n hookConfig: {\n address: getDefaultNativeTokenLimitModuleAddress(\n this.client.chain\n ),\n entityId,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.allowance),\n },\n };\n this.hasAssociatedExecHooks = true;\n break;\n case PermissionType.ERC20_TOKEN_TRANSFER:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId: entityId + HALF_UINT32,\n hookType: HookType.EXECUTION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId: entityId + HALF_UINT32,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: true,\n erc20SpendLimit: BigInt(permission.data.allowance),\n selectors: [],\n },\n ],\n },\n };\n this.hasAssociatedExecHooks = true;\n // Also allow `approve` and `transfer` for the erc20\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [ERC20_APPROVE_SELECTOR, ERC20_TRANSFER_SELECTOR], // approve, transfer\n },\n ],\n },\n };\n break;\n case PermissionType.GAS_LIMIT:\n // Should only ever be added once, check is also on addPermission(s)\n if (rawHooks[HookIdentifier.GAS_LIMIT] !== undefined) {\n throw new MultipleGasLimitError(permission);\n }\n rawHooks[HookIdentifier.GAS_LIMIT] = {\n hookConfig: {\n address: getDefaultNativeTokenLimitModuleAddress(\n this.client.chain\n ),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n spendLimit: BigInt(permission.data.limit),\n },\n };\n break;\n case PermissionType.CONTRACT_ACCESS:\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: [],\n },\n ],\n },\n };\n break;\n case PermissionType.ACCOUNT_FUNCTIONS:\n // This is handled in add permissions\n break;\n case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: zeroAddress,\n hasSelectorAllowlist: false,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.FUNCTIONS_ON_CONTRACT:\n if (permission.data.functions.length === 0) {\n throw new NoFunctionsProvidedError(permission);\n }\n if (permission.data.address === zeroAddress) {\n throw new ZeroAddressError(permission);\n }\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST] = {\n hookConfig: {\n address: getDefaultAllowlistModuleAddress(this.client.chain),\n entityId,\n hookType: HookType.VALIDATION,\n hasPreHooks: true,\n hasPostHooks: false,\n },\n initData: {\n entityId,\n inputs: [\n // Add previous inputs if they exist\n ...(rawHooks[HookIdentifier.PREVAL_ALLOWLIST]?.initData\n .inputs || []),\n {\n target: permission.data.address,\n hasSelectorAllowlist: true,\n hasERC20SpendLimit: false,\n erc20SpendLimit: 0n,\n selectors: permission.data.functions,\n },\n ],\n },\n };\n break;\n case PermissionType.ROOT:\n // Root permission handled in addPermission\n break;\n default:\n assertNever(permission);\n }\n\n // isGlobal guaranteed to be false since it's only set with root permissions,\n // we must add access to execute & executeBatch if there's a preVal allowlist hook set.\n if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST] !== undefined) {\n const selectorsToAdd: `0x${string}`[] = [\n ACCOUNT_EXECUTE_SELECTOR,\n ACCOUNT_EXECUTEBATCH_SELECTOR,\n ]; // execute, executeBatch\n\n // Only add the selectors if they aren't already in this.selectors\n const newSelectors = selectorsToAdd.filter(\n (selector) => !this.selectors.includes(selector)\n );\n\n this.selectors = [...this.selectors, ...newSelectors];\n }\n });\n\n return rawHooks;\n }\n\n private addHooks(rawHooks: RawHooks) {\n if (rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER]) {\n this.hooks.push({\n hookConfig: rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER].hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(\n rawHooks[HookIdentifier.NATIVE_TOKEN_TRANSFER].initData\n ),\n });\n }\n\n if (rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER]) {\n this.hooks.push({\n hookConfig: rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER].hookConfig,\n initData: AllowlistModule.encodeOnInstallData(\n rawHooks[HookIdentifier.ERC20_TOKEN_TRANSFER].initData\n ),\n });\n }\n\n if (rawHooks[HookIdentifier.GAS_LIMIT]) {\n this.hooks.push({\n hookConfig: rawHooks[HookIdentifier.GAS_LIMIT].hookConfig,\n initData: NativeTokenLimitModule.encodeOnInstallData(\n rawHooks[HookIdentifier.GAS_LIMIT].initData\n ),\n });\n }\n\n if (rawHooks[HookIdentifier.PREVAL_ALLOWLIST]) {\n this.hooks.push({\n hookConfig: rawHooks[HookIdentifier.PREVAL_ALLOWLIST].hookConfig,\n initData: AllowlistModule.encodeOnInstallData(\n rawHooks[HookIdentifier.PREVAL_ALLOWLIST].initData\n ),\n });\n }\n }\n}\n\nexport function assertNever(_valid: never): never {\n throw new UnsupportedPermissionTypeError();\n}\n"]}
@@ -1,6 +1,8 @@
1
1
  import { BaseError, type Address } from "@aa-sdk/core";
2
2
  import type { Permission } from "./permissionBuilder";
3
- export declare class RootPermissionOnlyError extends BaseError {
3
+ export declare abstract class PermissionBuilderError extends BaseError {
4
+ }
5
+ export declare class RootPermissionOnlyError extends PermissionBuilderError {
4
6
  name: string;
5
7
  /**
6
8
  * Constructor for initializing an error message indicating that an account could not be found to execute the specified action.
@@ -9,7 +11,7 @@ export declare class RootPermissionOnlyError extends BaseError {
9
11
  */
10
12
  constructor(permission: Permission);
11
13
  }
12
- export declare class AccountAddressAsTargetError extends BaseError {
14
+ export declare class AccountAddressAsTargetError extends PermissionBuilderError {
13
15
  name: string;
14
16
  /**
15
17
  * Constructor for initializing an error message indicating that account address is used as target.
@@ -18,7 +20,7 @@ export declare class AccountAddressAsTargetError extends BaseError {
18
20
  */
19
21
  constructor(permission: Permission);
20
22
  }
21
- export declare class DuplicateTargetAddressError extends BaseError {
23
+ export declare class DuplicateTargetAddressError extends PermissionBuilderError {
22
24
  name: string;
23
25
  /**
24
26
  * Constructor for initializing an error message indicating duplicate target address in permissions.
@@ -28,7 +30,7 @@ export declare class DuplicateTargetAddressError extends BaseError {
28
30
  */
29
31
  constructor(permission: Permission, targetAddress: Address);
30
32
  }
31
- export declare class NoFunctionsProvidedError extends BaseError {
33
+ export declare class NoFunctionsProvidedError extends PermissionBuilderError {
32
34
  name: string;
33
35
  /**
34
36
  * Constructor for initializing an error message indicating no functions were provided.
@@ -37,7 +39,7 @@ export declare class NoFunctionsProvidedError extends BaseError {
37
39
  */
38
40
  constructor(permission: Permission);
39
41
  }
40
- export declare class ExpiredDeadlineError extends BaseError {
42
+ export declare class ExpiredDeadlineError extends PermissionBuilderError {
41
43
  name: string;
42
44
  /**
43
45
  * Constructor for initializing an error message indicating the deadline has expired.
@@ -47,7 +49,7 @@ export declare class ExpiredDeadlineError extends BaseError {
47
49
  */
48
50
  constructor(deadline: number, currentTime: number);
49
51
  }
50
- export declare class DeadlineOverLimitError extends BaseError {
52
+ export declare class DeadlineOverLimitError extends PermissionBuilderError {
51
53
  name: string;
52
54
  /**
53
55
  * Constructor for initializing an error message indicating the deadline has expired.
@@ -56,14 +58,14 @@ export declare class DeadlineOverLimitError extends BaseError {
56
58
  */
57
59
  constructor(deadline: number);
58
60
  }
59
- export declare class ValidationConfigUnsetError extends BaseError {
61
+ export declare class ValidationConfigUnsetError extends PermissionBuilderError {
60
62
  name: string;
61
63
  /**
62
64
  * Constructor for initializing an error message indicating the validation config is unset.
63
65
  */
64
66
  constructor();
65
67
  }
66
- export declare class MultipleNativeTokenTransferError extends BaseError {
68
+ export declare class MultipleNativeTokenTransferError extends PermissionBuilderError {
67
69
  name: string;
68
70
  /**
69
71
  * Constructor for initializing an error message indicating multiple native token transfer permissions.
@@ -72,7 +74,7 @@ export declare class MultipleNativeTokenTransferError extends BaseError {
72
74
  */
73
75
  constructor(permission: Permission);
74
76
  }
75
- export declare class ZeroAddressError extends BaseError {
77
+ export declare class ZeroAddressError extends PermissionBuilderError {
76
78
  name: string;
77
79
  /**
78
80
  * Constructor for initializing an error message indicating zero address was provided.
@@ -81,7 +83,7 @@ export declare class ZeroAddressError extends BaseError {
81
83
  */
82
84
  constructor(permission: Permission);
83
85
  }
84
- export declare class MultipleGasLimitError extends BaseError {
86
+ export declare class MultipleGasLimitError extends PermissionBuilderError {
85
87
  name: string;
86
88
  /**
87
89
  * Constructor for initializing an error message indicating multiple gas limit permissions.
@@ -90,10 +92,19 @@ export declare class MultipleGasLimitError extends BaseError {
90
92
  */
91
93
  constructor(permission: Permission);
92
94
  }
93
- export declare class UnsupportedPermissionTypeError extends BaseError {
95
+ export declare class UnsupportedPermissionTypeError extends PermissionBuilderError {
94
96
  name: string;
95
97
  /**
96
98
  * Constructor for initializing an error message indicating an unsupported permission type.
97
99
  */
98
100
  constructor();
99
101
  }
102
+ export declare class SelectorNotAllowed extends PermissionBuilderError {
103
+ name: string;
104
+ /**
105
+ * Constructor for initializing an error message indicating that the selector being added is not allowed.
106
+ *
107
+ * @param {string} functionName The function name of the selector that is being added.
108
+ */
109
+ constructor(functionName: string);
110
+ }