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

Personal signatures differ from metamask signatures #231

Closed
yelodia opened this issue Apr 5, 2023 · 1 comment
Closed

Personal signatures differ from metamask signatures #231

yelodia opened this issue Apr 5, 2023 · 1 comment
Labels
question Further information is requested

Comments

@yelodia
Copy link

yelodia commented Apr 5, 2023

Hi. Is it possible to make a personal signature with multiple parameters like in web3 library (not typed_data sign)

hash1 = Web3.utils.soliditySha3({t: 'string', v: 'test'}, {t: 'uint256', v: 60});
const signature = await ethereum.request({ method: 'personal_sign', params: [ message, account ] });
@q9f
Copy link
Owner

q9f commented Apr 11, 2023

Web3.utils.solditySha3 implements packed ABI encoding which is not supported by the ruby gem, see #103

You can use normal ABI encoding though:

encoded = Eth::Abi.encode(["string", "uint256"], ["test", 60])
# => "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000@\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000<\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0004test\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000"
hashed = Eth::Util.keccak256 encoded
# => "\xF0[\x8D,|f\xF3\x93}\xDF\xDAp\x16=\xF3oPn\xC9I*\xD8\xC6\x99\xF1\x14\xC5\xF2Jp#\xB0"
account = Eth::Key.new
# => #<Eth::Key:0x0000556e3e147d08
 @private_key=#<Secp256k1::PrivateKey:0x0000556e3e147ad8>,
 @public_key=#<Secp256k1::PublicKey:0x0000556e3e147ab0>>
signed = account.personal_sign hashed
# => "d0cafb1f024fe513bfc1f24dc087f09f9a1a8be5275ed54361b4b1217d78fca86fee3ed8a7cc40bb8158d6c84dc3f55f73a8d9a75129e77c5f45a6d70bfab4bb1c"

@q9f q9f added the question Further information is requested label Apr 11, 2023
@q9f q9f closed this as completed May 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants