Skip to content

Commit

Permalink
feat: validate adding keys during init
Browse files Browse the repository at this point in the history
The normal case appears to be no data, so the key is added elsewhere?
  • Loading branch information
cpb8010 committed Dec 5, 2024
1 parent 6d3d6a4 commit 0f083e5
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions src/validators/SessionKeyValidator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,7 @@ contract SessionKeyValidator is IValidationHook, IModuleValidator {
}

function addValidationKey(bytes memory sessionData) external returns (bool) {
if (sessionData.length == 0) {
return false;
}
SessionLib.SessionSpec memory sessionSpec = abi.decode(sessionData, (SessionLib.SessionSpec));
createSession(sessionSpec);
return true;
return _addValidationKey(sessionData);
}

function createSession(SessionLib.SessionSpec memory sessionSpec) public {
Expand All @@ -71,7 +66,21 @@ contract SessionKeyValidator is IValidationHook, IModuleValidator {
emit SessionCreated(msg.sender, sessionHash, sessionSpec);
}

function init(bytes calldata data) external {}
function init(bytes calldata data) external {
// to prevent duplicate inits, since this can be hook plus a validator
if (!_isInitialized(msg.sender) && data.length != 0) {
require(_addValidationKey(data), "init failed");
}
}

function _addValidationKey(bytes memory sessionData) internal returns (bool) {
if (sessionData.length == 0) {
return false;
}
SessionLib.SessionSpec memory sessionSpec = abi.decode(sessionData, (SessionLib.SessionSpec));
createSession(sessionSpec);
return true;
}

function disable() external {
if (_isInitialized(msg.sender)) {
Expand Down

0 comments on commit 0f083e5

Please sign in to comment.