-
-
Notifications
You must be signed in to change notification settings - Fork 228
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
Conversation
2d85fbf
to
99816a7
Compare
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.
99816a7
to
4d8324d
Compare
### 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`. | |
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.
should we add a note about the lack of V2
?
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.
Probably, yep! I just didn't know what to say - I have no idea why there isn't a V2
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, 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.
The
signTypedData
andrecoverTypedSignature
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
andrecoverTypedSignature
used to be specifically foreth_signTypedData_v3
. Instead they now accept an additionalversion
parameter that specifies which version should be used. This replacessignTypedDataLegacy
andrecoverTypedSignatureLegacy
, which were foreth_signTypedData_v1
, and it replacessignTypedData_v4
andrecoverTypedSignature_v4
.The functions
signTypedMessage
andrecoverTypedMessage
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 aversion
parameter instead of auseV4
parameter, to bring them in-line with the other functions. The functions changed arehashStruct
,eip712Hash
, andencodeData
.The README and inline documentation has been updated accordingly. New doc strings were added for
signTypedData
andrecoverTypedSignature
, which didn't have any yet before now.Credit to @aakilfernandes for this idea, who first implemented this in PR #66.