-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from morpho-labs/feat/approval-with-sig
Add authorization with signature
- Loading branch information
Showing
4 changed files
with
153 additions
and
42 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
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,36 @@ | ||
// SPDX-License-Identifier: UNLICENSED | ||
pragma solidity ^0.8.0; | ||
|
||
import {AUTHORIZATION_TYPEHASH} from "src/Blue.sol"; | ||
|
||
library SigUtils { | ||
struct Authorization { | ||
address authorizer; | ||
address authorized; | ||
bool isAuthorized; | ||
uint256 nonce; | ||
uint256 deadline; | ||
} | ||
|
||
/// @dev Computes the hash of the EIP-712 encoded data. | ||
function getTypedDataHash(bytes32 domainSeparator, Authorization memory authorization) | ||
public | ||
pure | ||
returns (bytes32) | ||
{ | ||
return keccak256(abi.encodePacked("\x19\x01", domainSeparator, hashStruct(authorization))); | ||
} | ||
|
||
function hashStruct(Authorization memory authorization) internal pure returns (bytes32) { | ||
return keccak256( | ||
abi.encode( | ||
AUTHORIZATION_TYPEHASH, | ||
authorization.authorizer, | ||
authorization.authorized, | ||
authorization.isAuthorized, | ||
authorization.nonce, | ||
authorization.deadline | ||
) | ||
); | ||
} | ||
} |