GSNBouncerSignature.sol 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. pragma solidity ^0.5.0;
  2. import "./GSNBouncerBase.sol";
  3. import "../../cryptography/ECDSA.sol";
  4. contract GSNBouncerSignature is GSNBouncerBase {
  5. using ECDSA for bytes32;
  6. address private _trustedSigner;
  7. enum GSNBouncerSignatureErrorCodes {
  8. INVALID_SIGNER
  9. }
  10. constructor(address trustedSigner) public {
  11. _trustedSigner = trustedSigner;
  12. }
  13. function acceptRelayedCall(
  14. address relay,
  15. address from,
  16. bytes calldata encodedFunction,
  17. uint256 transactionFee,
  18. uint256 gasPrice,
  19. uint256 gasLimit,
  20. uint256 nonce,
  21. bytes calldata approvalData,
  22. uint256
  23. )
  24. external
  25. view
  26. returns (uint256, bytes memory)
  27. {
  28. bytes memory blob = abi.encodePacked(
  29. relay,
  30. from,
  31. encodedFunction,
  32. transactionFee,
  33. gasPrice,
  34. gasLimit,
  35. nonce, // Prevents replays on RelayHub
  36. getHubAddr(), // Prevents replays in multiple RelayHubs
  37. address(this) // Prevents replays in multiple recipients
  38. );
  39. if (keccak256(blob).toEthSignedMessageHash().recover(approvalData) == _trustedSigner) {
  40. return _approveRelayedCall();
  41. } else {
  42. return _rejectRelayedCall(uint256(GSNBouncerSignatureErrorCodes.INVALID_SIGNER));
  43. }
  44. }
  45. }