-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathSignatureValidator.sol
More file actions
27 lines (25 loc) · 966 Bytes
/
SignatureValidator.sol
File metadata and controls
27 lines (25 loc) · 966 Bytes
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
// SPDX-License-Identifier: MIT
pragma solidity 0.8.25;
library SignatureValidator {
/**
@dev Verfies signature against address
@param addr The signing address
@param quoteHash The hash of the signed data
@param signature The signature containing v, r and s
@return True if the signature is valid, false otherwise.
*/
function verify(address addr, bytes32 quoteHash, bytes memory signature) public pure returns (bool) {
bytes32 r;
bytes32 s;
uint8 v;
assembly {
r := mload(add(signature, 0x20))
s := mload(add(signature, 0x40))
v := byte(0, mload(add(signature, 0x60)))
}
// TODO use EIP712 compatible format instead
bytes memory prefix = "\x19Ethereum Signed Message:\n32";
bytes32 prefixedHash = keccak256(abi.encodePacked(prefix, quoteHash));
return ecrecover(prefixedHash, v, r, s) == addr;
}
}