generated from BreadchainCoop/solidity-foundry-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: introducing abstracted EIP712 messaging formating to comply wi…
…th offchain formatting"
- Loading branch information
1 parent
ee548c4
commit 8c31b97
Showing
2 changed files
with
29 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,26 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {LayerSDK} from 'contracts/LayerSDK.sol'; | ||
import {ILayerSDK, LayerSDK} from 'contracts/LayerSDK.sol'; | ||
|
||
contract OffchainMessageConsumer is LayerSDK { | ||
/// @notice The expected hash of the offchain message | ||
bytes32 private constant _MESSAGE_HASH = keccak256(abi.encode('Hello, World!')); | ||
/// @notice The expected content of the offchain message | ||
string private constant _MESSAGE = 'Hello, World!'; | ||
|
||
/// @notice Initializer | ||
constructor(address _stakeRegistry) LayerSDK(_stakeRegistry) {} | ||
|
||
/** | ||
* @notice Validates a layer task from off-chain AVS operator | ||
* @param _offchainData The off-chain data to verify | ||
* @param _task The off-chain data to verify | ||
* @return _isValid Whether the task is valid | ||
*/ | ||
function validateOffchainMessage(string calldata _offchainData) external view returns (bool _isValid) { | ||
Task memory _task = Task({dataHash: bytes32(bytes(_offchainData[0:32])), signatureData: bytes(_offchainData[32:])}); | ||
_isValid = _validateLayerTask(_task) && _task.dataHash == _MESSAGE_HASH; | ||
function validateOffchainMessage(ILayerSDK.Task calldata _task) | ||
external | ||
view | ||
onlyValidLayerTask(_task) | ||
returns (bool _isValid) | ||
{ | ||
_isValid = _validateEthSignedMessage(_task.dataHash, _MESSAGE); | ||
} | ||
} |