The Wayback Machine - https://web.archive.org/web/20201126141516/https://github.com/OpenZeppelin/openzeppelin-contracts/issues/890
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ECDSA#toEthSignedMessageHash for bytes type #890

Open
shrugs opened this issue Apr 12, 2018 · 7 comments
Open

Add ECDSA#toEthSignedMessageHash for bytes type #890

shrugs opened this issue Apr 12, 2018 · 7 comments

Comments

@shrugs
Copy link
Contributor

@shrugs shrugs commented Apr 12, 2018

馃帀 Description

The ECDSA contract has a function toEthSignedMessage(bytes32), but we should have a function that works for any length of a bytes array:

function toEthSignedMessage(bytes s) pure internal returns (bytes32) {
  return keccak256(
    "\x19Ethereum Signed Message:\n",
    uintToBytes(s.length),
    s);
}

Where uintToBytes is implemented from an ideally MIT-licensed project with appropriate attribution.

@frangio
Copy link
Member

@frangio frangio commented Apr 12, 2018

For uintToBytes we could use pipermerriam/ethereum-string-utils.

@k06a
Copy link
Contributor

@k06a k06a commented Apr 24, 2018

@shrugs usually s is of length 32, because it is hash of the original message. This kind of method will be still very useful:

function ethSignedMessage(bytes32 hash) pure internal returns (bytes32) {
  return keccak256(
    "\x19Ethereum Signed Message:\n32",
    hash);
}
@k06a
Copy link
Contributor

@k06a k06a commented Apr 24, 2018

@frangio awesome 馃槑

@k06a
Copy link
Contributor

@k06a k06a commented Apr 25, 2018

@frangio this code is not yet included in the latest release. I am waiting for it to use in https://github.com/bitclave/Feeless

@frangio frangio changed the title Add ECRecovery#ethSignedMessage for bytes type Add ECDSA#ethSignedMessage for bytes type Jul 13, 2019
@frangio frangio changed the title Add ECDSA#ethSignedMessage for bytes type Add ECDSA#toEthSignedMessageHash for bytes type Jul 13, 2019
@frangio
Copy link
Member

@frangio frangio commented Jul 13, 2019

Update: we already have Strings.fromUint256 for converting numbers to strings.

@frangio frangio removed the help wanted label Jul 13, 2019
@nventuro
Copy link
Contributor

@nventuro nventuro commented Jul 17, 2019

Note that signed data should always be a hash, since signatures can be faked for arbitrary data. This helper would still be safe in that sense because, even if the underlying bytes are not a hash, the whole signed message is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
4 participants
You can鈥檛 perform that action at this time.