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

Simplify function type signatures #198

Merged
merged 2 commits into from
Sep 9, 2021
Merged

Simplify function type signatures #198

merged 2 commits into from
Sep 9, 2021

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Sep 9, 2021

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.

@Gudahtt Gudahtt marked this pull request as ready for review September 9, 2021 04:13
@Gudahtt Gudahtt requested a review from a team as a code owner September 9, 2021 04:13
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 9, 2021

The Node.js v16 failure is unrelated (it also fails on main). It is fixed here: #199 Fixed.

Copy link
Member

@rekmarks rekmarks left a 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[];
Copy link
Member

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?

Copy link
Member Author

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.

Copy link
Member Author

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.
@Gudahtt Gudahtt force-pushed the simplify-types branch 2 times, most recently from da1bf8a to 3be88f2 Compare September 9, 2021 17:28
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`.
@Gudahtt
Copy link
Member Author

Gudahtt commented Sep 9, 2021

Good idea! The latest commit adds docs for both of those types.

Copy link
Member

@rekmarks rekmarks left a comment

Choose a reason for hiding this comment

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

LGTM!

@Gudahtt Gudahtt merged commit 2e158cd into main Sep 9, 2021
@Gudahtt Gudahtt deleted the simplify-types branch September 9, 2021 18:32
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