Nethereum: EIP712 Signer doesn't work correctly
I get an example of EIP712 Sign from official EIPs example: https://github.com/ethereum/EIPs/blob/b95c19f7118740cb498e0f758803037189b4ca30/assets/eip-712/Example.js I’ve tested it with my private key: https://github.com/vt-btf/EIP712-nodeJs
Then i wrote some code for Metamask with the same data and private key: https://github.com/vt-btf/EIP712-Metamask
I had the same output of Signatures. Then i got your test example(wich has the same data like from EIPs example): https://github.com/Nethereum/Nethereum/blob/master/src/Nethereum.Signer.UnitTests/Eip712TypedDataSignerTest.cs
And created a C# project with this data: https://github.com/vt-btf/EIP712-CSharp
MetaMask and NodeJs examples has same signature. Nethereum Signer has different signature
Expected Behavior
All signatures are the same
Current Behavior
MetaMask and NodeJs examples has same signature. Nethereum Signer has different signature
Steps to Reproduce
- https://github.com/vt-btf/EIP712-nodeJs
- https://github.com/vt-btf/EIP712-Metamask
- https://github.com/vt-btf/EIP712-CSharp
Context (Environment)
Can’t work with GSN v2 example
Possible Implementation
Found out the right signature will be:
var key = new EthECKey(privKey);
var hashedData = Sha3Keccack.Current.CalculateHash(Eip712TypedDataSigner.Current.EncodeTypedData(typedData));
var correctSignature = key.SignAndCalculateV(hashedData);
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 36 (20 by maintainers)
Commits related to this issue
- #634 #361 Add unit tests and recovery implementation / example for V4 — committed to Nethereum/Nethereum by juanfranblanco 2 years ago
- #361 #730 #428 #634 Adding support for Arrays v4 — committed to Nethereum/Nethereum by juanfranblanco 2 years ago
- #361 #634 #730 #428 V4 Array / Tuple support for typed messages Enabling simpler input of typed messages on 712 using complex types and arrays (v4). Typed as in c# types.. The simplest pattern (for u... — committed to Nethereum/Nethereum by juanfranblanco 2 years ago
- #361 #634 #730 #428 Further simplification on type messages, now the description can be extracted from a collection of types. — committed to Nethereum/Nethereum by juanfranblanco 2 years ago
Yeah sure. I’ll add a method
SignTypedDataV4that will be implementation up above from OP@frostiq Initially I tried that & it didn’t work, however, I found out later that I was passing in a string into a field that should have been BigInteger for the uint256 encoding. After fixing that, the signature was valid. Hopefully, this helps someone else.
My use-case is slightly different, I’m not trying to sign using Nethereum, instead I’m trying to recover the signing address from an existing signature. I’ve basically got a REST API and I want to create an auth handler that takes a payload from a client, with a signature of that payload. To verify it, I reconstruct the TypedData at the auth handler, then verify that the recovered address matches the address in the payload. Rough code looks something like:
I’ve got this working totally fine using libraries with node, but I’d really love to have this working with Nethereum. I’ve definitely confirmed that the domain, types and values match - plus I’ve been able to achieve it with 2 different methods in typescript. Any ideas?
I’ve implemented
SignTypedDatain such a way because that was needed for our use case (Gnosis Safe transactions). If you need to make a different signature for another use case (e.g. Metamask compatibility) – feel free to submit a PR with an alternativeSignTypedDatamethod if you are willing to contribute to the library. Looks like such a PR will be relatively easy to do