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

Consolidate signTypedData and recoverTypedSignature functions #156

Merged
merged 2 commits into from
Jul 26, 2021

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Jul 15, 2021

The signTypedData and recoverTypedSignature functions each had three different implementations (one for each version of EIP-712). They have each been consolidated into a single function each.

The functions signTypedData and recoverTypedSignature used to be specifically for eth_signTypedData_v3. Instead they now accept an additional version parameter that specifies which version should be used. This replaces signTypedDataLegacy and recoverTypedSignatureLegacy, which were for eth_signTypedData_v1, and it replaces signTypedData_v4 and recoverTypedSignature_v4.

The functions signTypedMessage and recoverTypedMessage used to provide a single interface for using any of EIP-712 types. But now that the base functions serve that purpose instead, they are now obsolete and have been removed.

Additionally a few TypedDataUtils functions were updated to accept a version parameter instead of a useV4 parameter, to bring them in-line with the other functions. The functions changed are hashStruct, eip712Hash, and encodeData.

The README and inline documentation has been updated accordingly. New doc strings were added for signTypedData and recoverTypedSignature, which didn't have any yet before now.

Credit to @aakilfernandes for this idea, who first implemented this in PR #66.

@Gudahtt Gudahtt mentioned this pull request Jul 15, 2021
@Gudahtt Gudahtt force-pushed the consolidate-sign-typed-data-methods branch from 2d85fbf to 99816a7 Compare July 15, 2021 14:17
@Gudahtt Gudahtt marked this pull request as ready for review July 15, 2021 15:34
@Gudahtt Gudahtt requested a review from a team as a code owner July 15, 2021 15:34
The `signTypedData` and `recoverTypedSignature` functions each had
three different implementations (one for each version of EIP-712).
They have each been consolidated into a single function each.

The functions `signTypedData` and `recoverTypedSignature` used to be
specifically for `eth_signTypedData_v3`. Instead they now accept an
additional `version` parameter that specifies which version should be
used. This replaces `signTypedDataLegacy` and
`recoverTypedSignatureLegacy`, which were for `eth_signTypedData_v1`,
and it replaces `signTypedData_v4` and `recoverTypedSignature_v4`.

The functions `signTypedMessage` and `recoverTypedMessage` used to
provide a single interface for using any of EIP-712 types. But now that
the base functions serve that purpose instead, they are now obsolete
and have been removed.

Additionally a few `TypedDataUtils` functions were updated to accept
a `version` parameter instead of a `useV4` parameter, to bring them
in-line with the other functions. The functions changed are
`hashStruct`, `eip712Hash`, and `encodeData`.

The README and inline documentation has been updated accordingly. New
doc strings were added for `signTypedData` and `recoverTypedSignature`,
which didn't have any yet before now.

Credit to @aakilfernandes for this idea, who first implemented this in
PR #66.
@Gudahtt Gudahtt force-pushed the consolidate-sign-typed-data-methods branch from 99816a7 to 4d8324d Compare July 15, 2021 16:25
### signTypedData (privateKeyBuffer, msgParams)
| Version | Description |
| ------- | ------------------------------------------------------------ |
| `V1` | This is based on [an early version of EIP-712](https://github.com/ethereum/EIPs/pull/712/commits/21abe254fe0452d8583d5b132b1d7be87c0439ca) that lacked some later security improvements, and should generally be neglected in favor of `V3`. |

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we add a note about the lack of V2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably, yep! I just didn't know what to say - I have no idea why there isn't a V2

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, actually, I just found more information on this in our docs:

The missing v2 represents an intermediary design that was implemented by the Cipher browser, so that we have room to implement it if there is ever enough developer demand for it.

I'll add this in a follow-up PR.

@Gudahtt Gudahtt merged commit 97caab5 into main Jul 26, 2021
@Gudahtt Gudahtt deleted the consolidate-sign-typed-data-methods branch July 26, 2021 19:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants