@account-kit/smart-contracts 4.25.0 → 4.26.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 (43) 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/actions/deferralActions.d.ts +0 -5
  6. package/dist/esm/src/ma-v2/actions/deferralActions.js +0 -20
  7. package/dist/esm/src/ma-v2/actions/deferralActions.js.map +1 -1
  8. package/dist/esm/src/ma-v2/index.d.ts +2 -1
  9. package/dist/esm/src/ma-v2/index.js +2 -1
  10. package/dist/esm/src/ma-v2/index.js.map +1 -1
  11. package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js +6 -2
  12. package/dist/esm/src/ma-v2/modules/single-signer-validation/signer.js.map +1 -1
  13. package/dist/esm/src/ma-v2/permissionBuilder.d.ts +1 -0
  14. package/dist/esm/src/ma-v2/permissionBuilder.js +34 -20
  15. package/dist/esm/src/ma-v2/permissionBuilder.js.map +1 -1
  16. package/dist/esm/src/ma-v2/permissionBuilderErrors.d.ts +108 -0
  17. package/dist/esm/src/ma-v2/permissionBuilderErrors.js +192 -0
  18. package/dist/esm/src/ma-v2/permissionBuilderErrors.js.map +1 -0
  19. package/dist/esm/src/ma-v2/utils.d.ts +17 -0
  20. package/dist/esm/src/ma-v2/utils.js +23 -1
  21. package/dist/esm/src/ma-v2/utils.js.map +1 -1
  22. package/dist/types/src/ma-v2/account/common/modularAccountV2Base.d.ts.map +1 -1
  23. package/dist/types/src/ma-v2/account/nativeSMASigner.d.ts.map +1 -1
  24. package/dist/types/src/ma-v2/actions/deferralActions.d.ts +0 -5
  25. package/dist/types/src/ma-v2/actions/deferralActions.d.ts.map +1 -1
  26. package/dist/types/src/ma-v2/index.d.ts +2 -1
  27. package/dist/types/src/ma-v2/index.d.ts.map +1 -1
  28. package/dist/types/src/ma-v2/modules/single-signer-validation/signer.d.ts.map +1 -1
  29. package/dist/types/src/ma-v2/permissionBuilder.d.ts +1 -0
  30. package/dist/types/src/ma-v2/permissionBuilder.d.ts.map +1 -1
  31. package/dist/types/src/ma-v2/permissionBuilderErrors.d.ts +109 -0
  32. package/dist/types/src/ma-v2/permissionBuilderErrors.d.ts.map +1 -0
  33. package/dist/types/src/ma-v2/utils.d.ts +17 -0
  34. package/dist/types/src/ma-v2/utils.d.ts.map +1 -1
  35. package/package.json +5 -5
  36. package/src/ma-v2/account/common/modularAccountV2Base.ts +29 -18
  37. package/src/ma-v2/account/nativeSMASigner.ts +7 -2
  38. package/src/ma-v2/actions/deferralActions.ts +0 -31
  39. package/src/ma-v2/index.ts +2 -1
  40. package/src/ma-v2/modules/single-signer-validation/signer.ts +7 -2
  41. package/src/ma-v2/permissionBuilder.ts +50 -53
  42. package/src/ma-v2/permissionBuilderErrors.ts +166 -0
  43. package/src/ma-v2/utils.ts +38 -1
@@ -1 +1 @@
1
- {"version":3,"file":"permissionBuilder.js","sourceRoot":"","sources":["../../../../src/ma-v2/permissionBuilder.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,WAAW,EAA0B,MAAM,MAAM,CAAC;AAClE,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,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UAAU,EAAE,QAAQ,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC,UAAU;gBACrE,QAAQ,EAAE,sBAAsB,CAAC,mBAAmB,CAClD,QAAQ,CAAC,cAAc,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CACxD;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","sourcesContent":["import { 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\";\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 Error(\n \"PERMISSION: ROOT: Cannot add ROOT permission with other permissions\"\n );\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 Error(\n `PERMISSION: ${permission.type} => Cannot add permissions with ROOT enabled`\n );\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 Error(\n `PERMISSION: ${permission.type} => Account address as target, use ACCOUNT_FUNCTIONS for account address`\n );\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 Error(\n `PERMISSION: ${permission.type} => Address ${targetAddress} already has a permission. Cannot add multiple CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT permissions for the same target address.`\n );\n }\n }\n\n // Check 4: If the permission is ACCOUNT_FUNCTIONS, add selectors\n if (permission.type === PermissionType.ACCOUNT_FUNCTIONS) {\n this.selectors = [...this.selectors, ...permission.data.functions];\n return this;\n }\n\n this.permissions.push(permission);\n\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 Error(\n `PERMISSION: compileDeferred(): deadline ${\n this.deadline\n } cannot be before now (${Date.now() / 1000})`\n );\n }\n this.hooks.push(\n TimeRangeModule.buildHook(\n {\n entityId: this.validationConfig.entityId, // will be timerange 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 Error(\n \"Validation config unset, use permissionBuilder.configure(...)\"\n );\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 Error(\n \"PERMISSION: NATIVE_TOKEN_TRANSFER => Must have at most ONE native token transfer permission\"\n );\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 Error(\n \"PERMISSION: ERC20_TOKEN_TRANSFER => Zero address provided\"\n );\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 Error(\n \"PERMISSION: GAS_LIMIT => Must have at most ONE gas limit permission\"\n );\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 Error(\n \"PERMISSION: CONTRACT_ACCESS => Zero address provided\"\n );\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 if (permission.data.functions.length === 0) {\n throw new Error(\n \"PERMISSION: ACCOUNT_FUNCTION => No functions provided\"\n ); // should be in add perm\n }\n break;\n case PermissionType.FUNCTIONS_ON_ALL_CONTRACTS:\n if (permission.data.functions.length === 0) {\n throw new Error(\n \"PERMISSION: FUNCTIONS_ON_ALL_CONTRACTS => No functions provided\"\n );\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 Error(\n \"PERMISSION: FUNCTIONS_ON_CONTRACT => No functions provided\"\n );\n }\n if (permission.data.address === zeroAddress) {\n throw new Error(\n \"PERMISSION: FUNCTIONS_ON_CONTRACT => Zero address provided\"\n );\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 throw new Error(\n `Unsupported permission type: ${(permission as any).type}`\n );\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"]}
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,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AAQ,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"]}
@@ -0,0 +1,108 @@
1
+ import { BaseError, type Address } from "@aa-sdk/core";
2
+ import type { Permission } from "./permissionBuilder";
3
+ export declare class RootPermissionOnlyError extends BaseError {
4
+ name: string;
5
+ /**
6
+ * Constructor for initializing an error message indicating that an account could not be found to execute the specified action.
7
+ *
8
+ * @param {Permission} permission The permission trying to be added atop the root permission
9
+ */
10
+ constructor(permission: Permission);
11
+ }
12
+ export declare class AccountAddressAsTargetError extends BaseError {
13
+ name: string;
14
+ /**
15
+ * Constructor for initializing an error message indicating that account address is used as target.
16
+ *
17
+ * @param {Permission} permission The permission with account address as target
18
+ */
19
+ constructor(permission: Permission);
20
+ }
21
+ export declare class DuplicateTargetAddressError extends BaseError {
22
+ name: string;
23
+ /**
24
+ * Constructor for initializing an error message indicating duplicate target address in permissions.
25
+ *
26
+ * @param {Permission} permission The permission with duplicate target address
27
+ * @param {Address} targetAddress The duplicate target address
28
+ */
29
+ constructor(permission: Permission, targetAddress: Address);
30
+ }
31
+ export declare class NoFunctionsProvidedError extends BaseError {
32
+ name: string;
33
+ /**
34
+ * Constructor for initializing an error message indicating no functions were provided.
35
+ *
36
+ * @param {Permission} permission The permission missing functions
37
+ */
38
+ constructor(permission: Permission);
39
+ }
40
+ export declare class ExpiredDeadlineError extends BaseError {
41
+ name: string;
42
+ /**
43
+ * Constructor for initializing an error message indicating the deadline has expired.
44
+ *
45
+ * @param {number} deadline The expired deadline timestamp
46
+ * @param {number} currentTime The current timestamp
47
+ */
48
+ constructor(deadline: number, currentTime: number);
49
+ }
50
+ export declare class DeadlineOverLimitError extends BaseError {
51
+ name: string;
52
+ /**
53
+ * Constructor for initializing an error message indicating the deadline has expired.
54
+ *
55
+ * @param {number} deadline The expired deadline timestamp
56
+ */
57
+ constructor(deadline: number);
58
+ }
59
+ export declare class ValidationConfigUnsetError extends BaseError {
60
+ name: string;
61
+ /**
62
+ * Constructor for initializing an error message indicating the validation config is unset.
63
+ */
64
+ constructor();
65
+ }
66
+ export declare class MultipleNativeTokenTransferError extends BaseError {
67
+ name: string;
68
+ /**
69
+ * Constructor for initializing an error message indicating multiple native token transfer permissions.
70
+ *
71
+ * @param {Permission} permission The duplicate native token transfer permission
72
+ */
73
+ constructor(permission: Permission);
74
+ }
75
+ export declare class ZeroAddressError extends BaseError {
76
+ name: string;
77
+ /**
78
+ * Constructor for initializing an error message indicating zero address was provided.
79
+ *
80
+ * @param {Permission} permission The permission with zero address
81
+ */
82
+ constructor(permission: Permission);
83
+ }
84
+ export declare class MultipleGasLimitError extends BaseError {
85
+ name: string;
86
+ /**
87
+ * Constructor for initializing an error message indicating multiple gas limit permissions.
88
+ *
89
+ * @param {Permission} permission The duplicate gas limit permission
90
+ */
91
+ constructor(permission: Permission);
92
+ }
93
+ export declare class UnsupportedPermissionTypeError extends BaseError {
94
+ name: string;
95
+ /**
96
+ * Constructor for initializing an error message indicating an unsupported permission type.
97
+ */
98
+ constructor();
99
+ }
100
+ export declare class SelectorNotAllowed extends BaseError {
101
+ name: string;
102
+ /**
103
+ * Constructor for initializing an error message indicating that the selector being added is not allowed.
104
+ *
105
+ * @param {string} functionName The function name of the selector that is being added.
106
+ */
107
+ constructor(functionName: string);
108
+ }
@@ -0,0 +1,192 @@
1
+ import { BaseError } from "@aa-sdk/core";
2
+ export class RootPermissionOnlyError extends BaseError {
3
+ /**
4
+ * Constructor for initializing an error message indicating that an account could not be found to execute the specified action.
5
+ *
6
+ * @param {Permission} permission The permission trying to be added atop the root permission
7
+ */
8
+ constructor(permission) {
9
+ super(`Adding ${permission}: Cannot add permissions with ROOT permission`);
10
+ Object.defineProperty(this, "name", {
11
+ enumerable: true,
12
+ configurable: true,
13
+ writable: true,
14
+ value: "PermissionBuilder: RootPermissionOnlyError"
15
+ });
16
+ }
17
+ }
18
+ export class AccountAddressAsTargetError extends BaseError {
19
+ /**
20
+ * Constructor for initializing an error message indicating that account address is used as target.
21
+ *
22
+ * @param {Permission} permission The permission with account address as target
23
+ */
24
+ constructor(permission) {
25
+ super(`${permission.type}: Account address as target, use ACCOUNT_FUNCTIONS for account address`);
26
+ Object.defineProperty(this, "name", {
27
+ enumerable: true,
28
+ configurable: true,
29
+ writable: true,
30
+ value: "PermissionBuilder: AccountAddressAsTargetError"
31
+ });
32
+ }
33
+ }
34
+ export class DuplicateTargetAddressError extends BaseError {
35
+ /**
36
+ * Constructor for initializing an error message indicating duplicate target address in permissions.
37
+ *
38
+ * @param {Permission} permission The permission with duplicate target address
39
+ * @param {Address} targetAddress The duplicate target address
40
+ */
41
+ constructor(permission, targetAddress) {
42
+ super(`${permission.type}: Address ${targetAddress} already has a permission. Cannot add multiple CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT permissions for the same target address.`);
43
+ Object.defineProperty(this, "name", {
44
+ enumerable: true,
45
+ configurable: true,
46
+ writable: true,
47
+ value: "PermissionBuilder: DuplicateTargetAddressError"
48
+ });
49
+ }
50
+ }
51
+ export class NoFunctionsProvidedError extends BaseError {
52
+ /**
53
+ * Constructor for initializing an error message indicating no functions were provided.
54
+ *
55
+ * @param {Permission} permission The permission missing functions
56
+ */
57
+ constructor(permission) {
58
+ super(`${permission.type}: No functions provided`);
59
+ Object.defineProperty(this, "name", {
60
+ enumerable: true,
61
+ configurable: true,
62
+ writable: true,
63
+ value: "PermissionBuilder: NoFunctionsProvidedError"
64
+ });
65
+ }
66
+ }
67
+ export class ExpiredDeadlineError extends BaseError {
68
+ /**
69
+ * Constructor for initializing an error message indicating the deadline has expired.
70
+ *
71
+ * @param {number} deadline The expired deadline timestamp
72
+ * @param {number} currentTime The current timestamp
73
+ */
74
+ constructor(deadline, currentTime) {
75
+ super(`compileDeferred(): deadline ${deadline} cannot be before now (${currentTime})`);
76
+ Object.defineProperty(this, "name", {
77
+ enumerable: true,
78
+ configurable: true,
79
+ writable: true,
80
+ value: "PermissionBuilder: ExpiredDeadlineError"
81
+ });
82
+ }
83
+ }
84
+ export class DeadlineOverLimitError extends BaseError {
85
+ /**
86
+ * Constructor for initializing an error message indicating the deadline has expired.
87
+ *
88
+ * @param {number} deadline The expired deadline timestamp
89
+ */
90
+ constructor(deadline) {
91
+ super(`compileDeferred(): deadline ${deadline} cannot be > max uint48 (2^48 - 1)`);
92
+ Object.defineProperty(this, "name", {
93
+ enumerable: true,
94
+ configurable: true,
95
+ writable: true,
96
+ value: "PermissionBuilder: DeadlineOverLimitError"
97
+ });
98
+ }
99
+ }
100
+ export class ValidationConfigUnsetError extends BaseError {
101
+ /**
102
+ * Constructor for initializing an error message indicating the validation config is unset.
103
+ */
104
+ constructor() {
105
+ super("Validation config unset, use permissionBuilder.configure(...)");
106
+ Object.defineProperty(this, "name", {
107
+ enumerable: true,
108
+ configurable: true,
109
+ writable: true,
110
+ value: "PermissionBuilder: ValidationConfigUnsetError"
111
+ });
112
+ }
113
+ }
114
+ export class MultipleNativeTokenTransferError extends BaseError {
115
+ /**
116
+ * Constructor for initializing an error message indicating multiple native token transfer permissions.
117
+ *
118
+ * @param {Permission} permission The duplicate native token transfer permission
119
+ */
120
+ constructor(permission) {
121
+ super(`${permission.type}: Must have at most ONE native token transfer permission`);
122
+ Object.defineProperty(this, "name", {
123
+ enumerable: true,
124
+ configurable: true,
125
+ writable: true,
126
+ value: "PermissionBuilder: MultipleNativeTokenTransferError"
127
+ });
128
+ }
129
+ }
130
+ export class ZeroAddressError extends BaseError {
131
+ /**
132
+ * Constructor for initializing an error message indicating zero address was provided.
133
+ *
134
+ * @param {Permission} permission The permission with zero address
135
+ */
136
+ constructor(permission) {
137
+ super(`${permission.type}: Zero address provided`);
138
+ Object.defineProperty(this, "name", {
139
+ enumerable: true,
140
+ configurable: true,
141
+ writable: true,
142
+ value: "PermissionBuilder: ZeroAddressError"
143
+ });
144
+ }
145
+ }
146
+ export class MultipleGasLimitError extends BaseError {
147
+ /**
148
+ * Constructor for initializing an error message indicating multiple gas limit permissions.
149
+ *
150
+ * @param {Permission} permission The duplicate gas limit permission
151
+ */
152
+ constructor(permission) {
153
+ super(`${permission.type}: Must have at most ONE gas limit permission`);
154
+ Object.defineProperty(this, "name", {
155
+ enumerable: true,
156
+ configurable: true,
157
+ writable: true,
158
+ value: "PermissionBuilder: MultipleGasLimitError"
159
+ });
160
+ }
161
+ }
162
+ export class UnsupportedPermissionTypeError extends BaseError {
163
+ /**
164
+ * Constructor for initializing an error message indicating an unsupported permission type.
165
+ */
166
+ constructor() {
167
+ super(`Unsupported permission type`);
168
+ Object.defineProperty(this, "name", {
169
+ enumerable: true,
170
+ configurable: true,
171
+ writable: true,
172
+ value: "PermissionBuilder: UnsupportedPermissionTypeError"
173
+ });
174
+ }
175
+ }
176
+ export class SelectorNotAllowed extends BaseError {
177
+ /**
178
+ * Constructor for initializing an error message indicating that the selector being added is not allowed.
179
+ *
180
+ * @param {string} functionName The function name of the selector that is being added.
181
+ */
182
+ constructor(functionName) {
183
+ super(`Cannot add ${functionName} on the account`);
184
+ Object.defineProperty(this, "name", {
185
+ enumerable: true,
186
+ configurable: true,
187
+ writable: true,
188
+ value: "SelectorNotAllowed"
189
+ });
190
+ }
191
+ }
192
+ //# sourceMappingURL=permissionBuilderErrors.js.map
@@ -0,0 +1 @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AAC;QAVK;;;;mBAAO,2CAA2C;WAAC;IAW5D,CAAC;CACF;AAED,MAAM,OAAO,0BAA2B,SAAQ,SAAS;IAGvD;;OAEG;IACH;QACE,KAAK,CAAC,+DAA+D,CAAC,CAAC;QANhE;;;;mBAAO,+CAA+C;WAAC;IAOhE,CAAC;CACF;AAED,MAAM,OAAO,gCAAiC,SAAQ,SAAS;IAG7D;;;;OAIG;IACH,YAAY,UAAsB;QAChC,KAAK,CACH,GAAG,UAAU,CAAC,IAAI,0DAA0D,CAC7E,CAAC;QAVK;;;;mBAAO,qDAAqD;WAAC;IAWtE,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,SAAS;IAG7C;;;;OAIG;IACH,YAAY,UAAsB;QAChC,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,yBAAyB,CAAC,CAAC;QAR5C;;;;mBAAO,qCAAqC;WAAC;IAStD,CAAC;CACF;AAED,MAAM,OAAO,qBAAsB,SAAQ,SAAS;IAGlD;;;;OAIG;IACH,YAAY,UAAsB;QAChC,KAAK,CAAC,GAAG,UAAU,CAAC,IAAI,8CAA8C,CAAC,CAAC;QARjE;;;;mBAAO,0CAA0C;WAAC;IAS3D,CAAC;CACF;AAED,MAAM,OAAO,8BAA+B,SAAQ,SAAS;IAG3D;;OAEG;IACH;QACE,KAAK,CAAC,6BAA6B,CAAC,CAAC;QAN9B;;;;mBAAO,mDAAmD;WAAC;IAOpE,CAAC;CACF;AAED,MAAM,OAAO,kBAAmB,SAAQ,SAAS;IAG/C;;;;OAIG;IACH,YAAY,YAAoB;QAC9B,KAAK,CAAC,cAAc,YAAY,iBAAiB,CAAC,CAAC;QAR5C;;;;mBAAO,oBAAoB;WAAC;IASrC,CAAC;CACF","sourcesContent":["import { BaseError, type Address } from \"@aa-sdk/core\";\nimport type { Permission } from \"./permissionBuilder\";\n\nexport class RootPermissionOnlyError extends BaseError {\n override name = \"PermissionBuilder: RootPermissionOnlyError\";\n\n /**\n * Constructor for initializing an error message indicating that an account could not be found to execute the specified action.\n *\n * @param {Permission} permission The permission trying to be added atop the root permission\n */\n constructor(permission: Permission) {\n super(`Adding ${permission}: Cannot add permissions with ROOT permission`);\n }\n}\n\nexport class AccountAddressAsTargetError extends BaseError {\n override name = \"PermissionBuilder: AccountAddressAsTargetError\";\n\n /**\n * Constructor for initializing an error message indicating that account address is used as target.\n *\n * @param {Permission} permission The permission with account address as target\n */\n constructor(permission: Permission) {\n super(\n `${permission.type}: Account address as target, use ACCOUNT_FUNCTIONS for account address`\n );\n }\n}\n\nexport class DuplicateTargetAddressError extends BaseError {\n override name = \"PermissionBuilder: DuplicateTargetAddressError\";\n\n /**\n * Constructor for initializing an error message indicating duplicate target address in permissions.\n *\n * @param {Permission} permission The permission with duplicate target address\n * @param {Address} targetAddress The duplicate target address\n */\n constructor(permission: Permission, targetAddress: Address) {\n super(\n `${permission.type}: Address ${targetAddress} already has a permission. Cannot add multiple CONTRACT_ACCESS or FUNCTIONS_ON_CONTRACT permissions for the same target address.`\n );\n }\n}\n\nexport class NoFunctionsProvidedError extends BaseError {\n override name = \"PermissionBuilder: NoFunctionsProvidedError\";\n\n /**\n * Constructor for initializing an error message indicating no functions were provided.\n *\n * @param {Permission} permission The permission missing functions\n */\n constructor(permission: Permission) {\n super(`${permission.type}: No functions provided`);\n }\n}\n\nexport class ExpiredDeadlineError extends BaseError {\n override name = \"PermissionBuilder: ExpiredDeadlineError\";\n\n /**\n * Constructor for initializing an error message indicating the deadline has expired.\n *\n * @param {number} deadline The expired deadline timestamp\n * @param {number} currentTime The current timestamp\n */\n constructor(deadline: number, currentTime: number) {\n super(\n `compileDeferred(): deadline ${deadline} cannot be before now (${currentTime})`\n );\n }\n}\n\nexport class DeadlineOverLimitError extends BaseError {\n override name = \"PermissionBuilder: DeadlineOverLimitError\";\n\n /**\n * Constructor for initializing an error message indicating the deadline has expired.\n *\n * @param {number} deadline The expired deadline timestamp\n */\n constructor(deadline: number) {\n super(\n `compileDeferred(): deadline ${deadline} cannot be > max uint48 (2^48 - 1)`\n );\n }\n}\n\nexport class ValidationConfigUnsetError extends BaseError {\n override name = \"PermissionBuilder: ValidationConfigUnsetError\";\n\n /**\n * Constructor for initializing an error message indicating the validation config is unset.\n */\n constructor() {\n super(\"Validation config unset, use permissionBuilder.configure(...)\");\n }\n}\n\nexport class MultipleNativeTokenTransferError extends BaseError {\n override name = \"PermissionBuilder: MultipleNativeTokenTransferError\";\n\n /**\n * Constructor for initializing an error message indicating multiple native token transfer permissions.\n *\n * @param {Permission} permission The duplicate native token transfer permission\n */\n constructor(permission: Permission) {\n super(\n `${permission.type}: Must have at most ONE native token transfer permission`\n );\n }\n}\n\nexport class ZeroAddressError extends BaseError {\n override name = \"PermissionBuilder: ZeroAddressError\";\n\n /**\n * Constructor for initializing an error message indicating zero address was provided.\n *\n * @param {Permission} permission The permission with zero address\n */\n constructor(permission: Permission) {\n super(`${permission.type}: Zero address provided`);\n }\n}\n\nexport class MultipleGasLimitError extends BaseError {\n override name = \"PermissionBuilder: MultipleGasLimitError\";\n\n /**\n * Constructor for initializing an error message indicating multiple gas limit permissions.\n *\n * @param {Permission} permission The duplicate gas limit permission\n */\n constructor(permission: Permission) {\n super(`${permission.type}: Must have at most ONE gas limit permission`);\n }\n}\n\nexport class UnsupportedPermissionTypeError extends BaseError {\n override name = \"PermissionBuilder: UnsupportedPermissionTypeError\";\n\n /**\n * Constructor for initializing an error message indicating an unsupported permission type.\n */\n constructor() {\n super(`Unsupported permission type`);\n }\n}\n\nexport class SelectorNotAllowed extends BaseError {\n override name = \"SelectorNotAllowed\";\n\n /**\n * Constructor for initializing an error message indicating that the selector being added is not allowed.\n *\n * @param {string} functionName The function name of the selector that is being added.\n */\n constructor(functionName: string) {\n super(`Cannot add ${functionName} on the account`);\n }\n}\n"]}
@@ -83,7 +83,24 @@ export type BuildNonceParams = {
83
83
  };
84
84
  export declare const buildFullNonceKey: ({ nonceKey, entityId, isGlobalValidation, isDeferredAction, }: BuildNonceParams) => bigint;
85
85
  export declare const parseDeferredAction: (deferredAction: Hex) => {
86
+ entityId: number;
87
+ isGlobalValidation: boolean;
86
88
  nonce: bigint;
87
89
  deferredActionData: Hex;
88
90
  hasAssociatedExecHooks: boolean;
89
91
  };
92
+ export type BuildDeferredActionDigestParams = {
93
+ fullPreSignatureDeferredActionDigest: Hex;
94
+ sig: Hex;
95
+ };
96
+ /**
97
+ * Creates the digest which must be prepended to the userOp signature.
98
+ *
99
+ * Assumption: The client this extends is used to sign the typed data.
100
+ *
101
+ * @param {object} args The argument object containing the following:
102
+ * @param {Hex} args.fullPreSignatureDeferredActionDigest The The data to append the signature and length to
103
+ * @param {Hex} args.sig The signature to include in the digest
104
+ * @returns {Hex} The encoded digest to be prepended to the userOp signature
105
+ */
106
+ export declare const buildDeferredActionDigest: ({ fullPreSignatureDeferredActionDigest, sig, }: BuildDeferredActionDigestParams) => Hex;
@@ -1,4 +1,4 @@
1
- import { concat, toHex, custom, encodeFunctionData, parseAbi, } from "viem";
1
+ import { concat, toHex, custom, encodeFunctionData, parseAbi, size, concatHex, hexToNumber, } from "viem";
2
2
  import { arbitrum, arbitrumSepolia, base, baseSepolia, mainnet, optimism, optimismSepolia, polygon, polygonAmoy, sepolia, } from "@account-kit/infra";
3
3
  import { createModularAccountV2 } from "./account/modularAccountV2.js";
4
4
  import {} from "./account/common/modularAccountV2Base.js";
@@ -163,10 +163,32 @@ export const buildFullNonceKey = ({ nonceKey = 0n, entityId = 0, isGlobalValidat
163
163
  };
164
164
  // Parses out the 3 components from a deferred action
165
165
  export const parseDeferredAction = (deferredAction) => {
166
+ // 2 for 0x, 2 for 00/01, 38 for parallel nonce, 8 for entity id, 2 for options byte, 16 for parallel nonce
166
167
  return {
168
+ entityId: hexToNumber(`0x${deferredAction.slice(42, 50)}`),
169
+ isGlobalValidation: hexToNumber(`0x${deferredAction.slice(50, 52)}`) % 2 === 1,
167
170
  nonce: BigInt(`0x${deferredAction.slice(4, 68)}`),
168
171
  deferredActionData: `0x${deferredAction.slice(68)}`,
169
172
  hasAssociatedExecHooks: deferredAction[3] === "1",
170
173
  };
171
174
  };
175
+ /**
176
+ * Creates the digest which must be prepended to the userOp signature.
177
+ *
178
+ * Assumption: The client this extends is used to sign the typed data.
179
+ *
180
+ * @param {object} args The argument object containing the following:
181
+ * @param {Hex} args.fullPreSignatureDeferredActionDigest The The data to append the signature and length to
182
+ * @param {Hex} args.sig The signature to include in the digest
183
+ * @returns {Hex} The encoded digest to be prepended to the userOp signature
184
+ */
185
+ export const buildDeferredActionDigest = ({ fullPreSignatureDeferredActionDigest, sig, }) => {
186
+ const sigLength = size(sig);
187
+ const encodedData = concatHex([
188
+ fullPreSignatureDeferredActionDigest,
189
+ toHex(sigLength, { size: 4 }),
190
+ sig,
191
+ ]);
192
+ return encodedData;
193
+ };
172
194
  //# sourceMappingURL=utils.js.map