-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add install/uninstall validation (#1221)
* feat: add install validation, add tests for session key * fix: lint * fix: review fixes * fix: tests * feat: add view functions and user op calldata encodings (#1223)
- Loading branch information
Showing
10 changed files
with
533 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
account-kit/smart-contracts/src/ma-v2/actions/common/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import type { Address, Hex } from "viem"; | ||
|
||
export type ModuleEntity = { | ||
moduleAddress: Address; | ||
entityId: number; | ||
}; | ||
|
||
export type ValidationConfig = { | ||
moduleAddress: Address; | ||
entityId: number; // uint32 | ||
isGlobal: boolean; | ||
isSignatureValidation: boolean; | ||
isUserOpValidation: boolean; | ||
}; | ||
|
||
export enum HookType { | ||
EXECUTION = "0x00", | ||
VALIDATION = "0x01", | ||
} | ||
|
||
export type HookConfig = { | ||
address: Address; | ||
entityId: number; // uint32 | ||
hookType: HookType; | ||
hasPreHooks: boolean; | ||
hasPostHooks: boolean; | ||
}; | ||
|
||
// maps to type ValidationStorage in MAv2 implementation | ||
export type ValidationData = { | ||
isGlobal: boolean; // validation flag | ||
isSignatureValidation: boolean; // validation flag | ||
isUserOpValidation: boolean; | ||
validationHooks: HookConfig[]; | ||
executionHooks: Hex[]; | ||
selectors: Hex[]; | ||
}; |
32 changes: 32 additions & 0 deletions
32
account-kit/smart-contracts/src/ma-v2/actions/common/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { type Hex, toHex, concatHex } from "viem"; | ||
import type { ValidationConfig, HookConfig, ModuleEntity } from "./types"; | ||
import { HookType } from "./types.js"; | ||
|
||
export function serializeValidationConfig(config: ValidationConfig): Hex { | ||
const isUserOpValidationBit = config.isUserOpValidation ? 1 : 0; | ||
const isSignatureValidationBit = config.isSignatureValidation ? 2 : 0; | ||
const isGlobalBit = config.isGlobal ? 4 : 0; | ||
return concatHex([ | ||
serializeModuleEntity(config), | ||
toHex(isUserOpValidationBit + isSignatureValidationBit + isGlobalBit, { | ||
size: 1, | ||
}), | ||
]); | ||
} | ||
|
||
export function serializeHookConfig(config: HookConfig): Hex { | ||
const hookTypeBit = config.hookType === HookType.VALIDATION ? 1 : 0; | ||
const hasPostHooksBit = config.hasPostHooks ? 2 : 0; | ||
const hasPreHooksBit = config.hasPreHooks ? 4 : 0; | ||
return concatHex([ | ||
config.address, | ||
toHex(config.entityId, { size: 4 }), | ||
toHex(hookTypeBit + hasPostHooksBit + hasPreHooksBit, { | ||
size: 1, | ||
}), | ||
]); | ||
} | ||
|
||
export function serializeModuleEntity(config: ModuleEntity): Hex { | ||
return concatHex([config.moduleAddress, toHex(config.entityId, { size: 4 })]); | ||
} |
Oops, something went wrong.