-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCredentialVerifier.sol
52 lines (45 loc) · 1.43 KB
/
CredentialVerifier.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.12;
import "@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol";
import "@openzeppelin/contracts/utils/Strings.sol";
contract CredentialVerifier {
modifier requiresCredential(
string memory expectedCredential,
bytes calldata proof,
uint256 validUntil,
uint256 approvedAt,
uint256 maxAge,
string memory fractalId
) {
require(block.timestamp < validUntil, "Credential no longer valid");
require(
maxAge == 0 || block.timestamp < approvedAt + maxAge,
"Approval not recent enough"
);
string memory sender = Strings.toHexString(
uint256(uint160(msg.sender)),
20
);
require(
SignatureChecker.isValidSignatureNow(
0xacD08d6714ADba531beFF582e6FD5DA1AFD6bc65,
ECDSA.toEthSignedMessageHash(
abi.encodePacked(
sender,
";",
fractalId,
";",
Strings.toString(approvedAt),
";",
Strings.toString(validUntil),
";",
expectedCredential
)
),
proof
),
"Signature doesn't match"
);
_;
}
}