-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Rename to eth_signTypedData_v4
method for accounts provider.
#1346
Rename to eth_signTypedData_v4
method for accounts provider.
#1346
Conversation
Hmm, CI appears to be failing when installing packages:
I don't think this is related to the changes. |
Hey @nlordell, thanks a lot for sending this PR. Unfortunately we don't have enough time to review this right now, but we'll get back to this once Berlin is implemented in the next couple of weeks. |
Good catch! I'm also seeing this blow up my EIP712 signing/hashing when switching providers. Specifically, Optimistic Ethereum tests are currently constrained to using a local testnet. Switching from L1 testing to L2 testing surfaced this mismatch since it changed provider interfaces (HTTP provider instead of local accounts) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, and thanks for including tests!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh wait, there's a failing test that is not a false negative, I'll look into it.
I made two changes:
@alcuadrado what do you think? |
Btw, I think this:
could be stricter. I don't think the |
I imagine these should also be applied to right above to if (address !== undefined) {
// ...
} pattern and doesn't check if a private key is found for the address.
🙈 I didn't look much when I rebased and didn't run the tests locally either. Sorry! I see the failing test is:
Because of |
No, it actually needs to be an object with the following schema: {
type: 'object',
properties: {
types: {
type: 'object',
properties: {
EIP712Domain: {type: 'array'},
},
additionalProperties: {
type: 'array',
items: {
type: 'object',
properties: {
name: {type: 'string'},
type: {type: 'string'}
},
required: ['name', 'type']
}
},
required: ['EIP712Domain']
},
primaryType: {type: 'string'},
domain: {type: 'object'},
message: {type: 'object'}
},
required: ['types', 'primaryType', 'domain', 'message']
} I just imagined that the |
Oh, maybe? We recently made
Yes, that's unrelated to this PR, don't worry. The test that was failing before was one of the new ones, but it's fixed now.
Yep, that's fair. Maybe we can just check that something exists and that it's an object. |
I believe this also needs similar JSON.parse logic to the hardhat-network provider. When working with an up to date version of ethers, the I think we should check if the
EDIT: Here's a PR: |
Hey @nlordell, sorry we've been slow with this PR. We are trying to be extra cautious with this RPC method, as its EIP is not finalized and we already made a few mistakes. Do you have any opinion on @bstchow suggestion? Also, @fvictorio? |
No worries! I also completely missed https://github.com/nlordell/hardhat/pull/1, sorry @bstchow 🙈. |
Add string support for eth_signTypedData_v4
@nlordell no worries! Thanks for the merge and for finding the issue in the first place. You saved me a decent amount of time. |
No worries! And thank you for the awesomeness that is |
This PR bumps Ethers.js to the latest version. Note that it required changing the signing scheme to EIP-712. This is because it appears that Ethers + Hardhat `eth_sign` signatures are currently broken (NomicFoundation/hardhat#1981). This is because they recently changed to always use `personal_sign` for `signMessage` calls (ethers-io/ethers.js@8947fd4), which isn't supported by Hardhat: ``` MethodNotFoundError: Method personal_sign not found ``` Note that we had previously used `eth_sign` signatures because EIP-712 signatures were broken with hardhat, but this should no longer be the case (NomicFoundation/hardhat#1346). ### Test Plan CI still passes.
This PR changes the EIP-712 handler in the accounts provider to use the method name
eth_signTypedData_v4
. This was originally proposed in #1200 and I believe was incorrectly closed.The main motivation for this change is when using
hardhat
andhardhat-ethers
on thehardhat-network
, the following works like a charm (support was added in #1189):However, when using other networks, such as connected to Infura with a private key or mnemonic (for example when implementing a task to interact with a deployed SC on mainnet that requires an EIP-712 signature), the following error occurs:
Since the configuration includes a private key for signing, there is no reason not to be able to generate an ECDSA signature, noting that
eth_sign
works as expected, so it is not an issue with account configuration,I believe this stems from the fact that the
hardhat-network
provider expectseth_signTypedData_v4
(again, added in #1189):https://github.com/nomiclabs/hardhat/blob/f604e23d32ba3a21c3cd4490f67ed7a7fec25fd8/packages/hardhat-core/src/internal/hardhat-network/provider/modules/eth.ts#L251-L264
While, the accounts provider expects
eth_signTypedData
. The proposed change makes these two providers consistent with respect to which method name they are expecting (preferingeth_signTypedData_v4
).Some unit tests were thrown in for fun 🎉.