Question: How to sign an array of arguments?
otavioschwanck opened this issue · comments
Otávio Schwanck dos Santos commented
I have the following code:
message = [
157560238208251294832227588492080579756,
210000000000000000000,
1658508461,
"0x0063046686E46Dc6F15918b61AE2B121458534a5",
"borrower0272",
]
key = Eth::Key.new priv: 'MY_PRIV_HERE'
key.personal_sign(message, 1337)
The signature that generate its messed up. When i try to verify, it returns another private key.
I am verifying with:
function tokenizeAsset(uint256 _uuid,
uint256 _amount,
uint256 _dueDate,
address _borrowerAddress,
string memory _documentNumber,
bytes memory signature)
public
onlyRole("MINTER")
returns (uint256)
{
validateParametersAuthenticity(keccak256(abi.encodePacked(_uuid, _amount, _dueDate, _borrowerAddress, _documentNumber)),
signature,
owner());
// more code here
}
function validateParametersAuthenticity(bytes32 message, bytes memory signature, address owner) internal {
address signer = recoverSigner(addPrefixToMessage(message), signature);
require(signer == owner,
S.join("The message might be tampered. Expected signer ", S.fromAddress(owner),
", but got ", S.fromAddress(signer)));
}
function recoverSigner(bytes32 message, bytes memory sig) internal pure returns(address) {
uint8 v;
bytes32 r;
bytes32 s;
(v, r, s) = splitSignature(sig);
return ecrecover(message, v, r, s);
}
function addPrefixToMessage(bytes32 message) internal pure returns(bytes32) {
return keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", message));
}
function splitSignature(bytes memory sig)
internal
pure
returns (uint8, bytes32, bytes32) {
require(sig.length == 65);
bytes32 r;
bytes32 s;
uint8 v;
assembly { r := mload(add(sig, 32)) s := mload(add(sig, 64)) v := byte(0, mload(add(sig, 96))) }
return (v, r, s);
}
On python, i can sign with:
def sign(self, types, message):
msg = Web3.soliditySha3(types, message)
full = encode_defunct(hexstr=msg.hex())
result = w3.eth.account.sign_message(full, private_key=self.privateKey())
return result.signature.hex()
Is it possible to sign in this way with this gem?
Afri commented
Please create an issue upstream: https://github.com/q9f/eth.rb/issues
Also, how does bytes32 message
look like? Are these values concatenated? There is no specification how to handle arrays in EIP 191.
Do you require EIP 712? https://github.com/q9f/eth.rb#22-ethereum-signatures-eip-191-eip-712