Implement 0x00 version of EIP-191 in ECDSA Library (#4063)

This commit is contained in:
Yamen Merhi
2023-02-22 16:22:50 +02:00
committed by GitHub
parent adb861fb3b
commit 53235263a3
4 changed files with 41 additions and 1 deletions

View File

@ -4,6 +4,21 @@ function toEthSignedMessageHash(messageHex) {
return web3.utils.sha3(Buffer.concat([prefix, messageBuffer]));
}
/**
* Create a signed data with intended validator according to the version 0 of EIP-191
* @param validatorAddress The address of the validator
* @param dataHex The data to be concatenated with the prefix and signed
*/
function toDataWithIntendedValidatorHash(validatorAddress, dataHex) {
const validatorBuffer = Buffer.from(web3.utils.hexToBytes(validatorAddress));
const dataBuffer = Buffer.from(web3.utils.hexToBytes(dataHex));
const preambleBuffer = Buffer.from('\x19');
const versionBuffer = Buffer.from('\x00');
const ethMessage = Buffer.concat([preambleBuffer, versionBuffer, validatorBuffer, dataBuffer]);
return web3.utils.sha3(ethMessage);
}
/**
* Create a signer between a contract and a signer for a voucher of method, args, and redeemer
* Note that `method` is the web3 method, not the truffle-contract method
@ -43,5 +58,6 @@ const getSignFor =
module.exports = {
toEthSignedMessageHash,
toDataWithIntendedValidatorHash,
getSignFor,
};