Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Eip 1271 support #44

Closed
q9f opened this issue Jan 12, 2022 · 4 comments · Fixed by #80
Closed

Eip 1271 support #44

q9f opened this issue Jan 12, 2022 · 4 comments · Fixed by #80
Labels
enhancement New feature or request

Comments

@q9f
Copy link
Owner

q9f commented Jan 12, 2022

https://eips.ethereum.org/EIPS/eip-1271

@q9f q9f mentioned this issue Jan 12, 2022
6 tasks
@q9f
Copy link
Owner Author

q9f commented Mar 29, 2022

Ref spruceid/siwe-ruby#15

@q9f
Copy link
Owner Author

q9f commented Apr 25, 2022

Hi there, checking in on the status of this PR (#68), would be very helpful to implement EIP-1271 for Sign-In with Ethereum spruceid/siwe-ruby#15, let me know if there is anything I can do to help!

@w4ll3 I'm tracking EIP-1271 here, let's briefly discuss this. I'm not very familiar with the mechanics of 1271 but will you require full smart-contract support as in ethereum.rb gem? @kurotaky is working on that but it might take a couple of weeks to release this.

It's quite probable that 1271 does only require a subset of the functionality of that PR #68. Could you describe in a few bullet points what the 1271 authentication workflow looks like, so I can take a look? Maybe we can prioritize this specific feature.

@w4ll3
Copy link

w4ll3 commented Apr 25, 2022 via email

@q9f
Copy link
Owner Author

q9f commented Apr 26, 2022

Gotcha.

// SPDX-License-Identifier: Apache-2.0

pragma solidity ^0.8;

library LibBytes {
  function readBytes32(
    bytes memory b,
    uint256 index
  )
    internal
    pure
    returns (bytes32 result)
  {
    index += 32;
    require(b.length >= index);
    assembly {
      result := mload(add(b, index))
    }
    return result;
  }
}

contract Signer {
  using LibBytes for bytes;
  address constant internal OWNER = 0xCaA29806044A08E533963b2e573C1230A2cd9a2d;
  bytes4 constant internal MAGIC_VALUE = 0x1626ba7e;

  function isValidSignature(
    bytes32 _hash,
    bytes calldata _signature
  )
    external
    pure
    returns (bytes4)
  {
    if (recoverSigner(_hash, _signature) == OWNER) {
      return MAGIC_VALUE;
    } else {
      return 0xffffffff;
    }
  }

  function recoverSigner(
    bytes32 _hash,
    bytes memory _signature
  )
    internal
    pure
    returns (address signer)
  {
    require(_signature.length == 65);
    uint8 v = uint8(_signature[64]);
    bytes32 r = _signature.readBytes32(0);
    bytes32 s = _signature.readBytes32(32);
    signer = ecrecover(keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _hash)), v, r, s);
    return signer;
  }
}

@q9f q9f closed this as completed in #80 May 10, 2022
@q9f q9f added the enhancement New feature or request label May 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants