-
-
Notifications
You must be signed in to change notification settings - Fork 226
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
Simplify function type signatures #198
Conversation
cba08fd
to
87c8fb0
Compare
|
87c8fb0
to
cca8a9e
Compare
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.
In addition to the inline request, I think we should add docstrings to TypedData
and TypedMessage
noting what (i.e. which versions) they're for.
src/index.ts
Outdated
@@ -6,7 +6,7 @@ import { intToHex, isHexString, stripHexPrefix } from 'ethjs-util'; | |||
|
|||
import { padWithZeroes } from './utils'; | |||
|
|||
export type TypedData = string | EIP712TypedData | EIP712TypedData[]; | |||
export type TypedData = EIP712TypedData[]; |
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.
If TypedData
is only used in / for V1, can we change its name to V1TypedData
or something similar?
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.
We could 🤔 I had left it as-is to minimize breaking changes, but I guess we're past that mattering now.
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.
Updated! It's now called TypedDataV1
The type signatures of many public functions were complex and misleading. This was primarily due to the widespread use of the types `TypedData` and `TypedMessage<T>`, which where inappropriate in most of the places they were used. The `TypedMessage<T>` type is used by the `signTypedData` function when the version is 'V3' or 'V4'. All references to this type outside of V3 and V4 of `signTypedData` have been removed. This also resulted in the `T` generic parameter being removed from many functions. The `TypedData` type didn't represent the actual type signature of any function, yet it was used to represent the input data for most functions. In most cases we had no specific expectations for the input type, so `unknown` is now used instead. In the case of `V1` of `signTypedData`, the expected type was always `EIP712TypedData[]`. The `TypedData` type has been reduced to just that one case where it was useful and accurate.
da1bf8a
to
3be88f2
Compare
The `TypedData` type has been renamed to `TypedDataV1` to indicate that this type is only intended to represent the data being signed with `V1` of `signTypedData`. JSDoc documentation has been added for the two message types, `SignTypedDataV1Data` and `TypedMessage`.
3be88f2
to
2bdde6b
Compare
Good idea! The latest commit adds docs for both of those types. |
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!
The type signatures of many public functions were complex and misleading. This was primarily due to the widespread use of the types
TypedData
andTypedMessage<T>
, which where inappropriate in most of the places they were used.The
TypedMessage<T>
type is used by thesignTypedData
function when the version is 'V3' or 'V4'. All references to this type outside of V3 and V4 ofsignTypedData
have been removed. This also resulted in theT
generic parameter being removed from many functions.The
TypedData
type didn't represent the actual type signature of any function, yet it was used to represent the input data for most functions. In most cases we had no specific expectations for the input type, sounknown
is now used instead. In the case ofV1
ofsignTypedData
, the expected type was alwaysEIP712TypedData[]
. TheTypedData
type has been reduced to just that one case where it was useful and accurate.