-
Notifications
You must be signed in to change notification settings - Fork 3
/
GameSessionValidationModule.sol
33 lines (31 loc) · 1.45 KB
/
GameSessionValidationModule.sol
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// SPDX-License-Identifier: MIT
pragma solidity 0.8.17;
import {ECDSA} from "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
import "./UserOperation.sol";
contract GameSessionValidationModule {
/**
* @dev validates if the _op (UserOperation) matches the SessionKey permissions
* and that _op has been signed by this SessionKey
* @param _op User Operation to be validated.
* @param _userOpHash Hash of the User Operation to be validated.
* @param _sessionKeyData SessionKey data, that describes sessionKey permissions
* @param _sessionKeySignature Signature over the the _userOpHash.
* @return true if the _op is valid, false otherwise.
*/
function validateSessionUserOp(
UserOperation calldata _op,
bytes32 _userOpHash,
bytes calldata _sessionKeyData,
bytes calldata _sessionKeySignature
) external view returns (bool) {
address sessionKey = address(bytes20(_sessionKeyData[0:20]));
address expectedGameContract = address(bytes20(_sessionKeyData[20:40]));
(address actualGameContract, uint256 callValue,) = abi.decode(
_op.callData[4:], // skip selector
(address, uint256, bytes)
);
require(actualGameContract == expectedGameContract, "Wrong game address");
require(callValue == 0, "Call value must be 0");
return ECDSA.recover(ECDSA.toEthSignedMessageHash(_userOpHash), _sessionKeySignature) == sessionKey;
}
}