Skip to content

Commit

Permalink
Allow TypedDataUtils to be called unbound
Browse files Browse the repository at this point in the history
Previously the functions exposed as `TypedDataUtils` could only be
called from the `TypedDataUtils` object. If they were called unbound,
they would throw errors because of the use of `this`.

They have all been updated to no longer rely upon `this`, so they now
work the same way regardless how they are bound when called.

They are still exported as the `TypedDataUtils` object, so this should
not change the API. This was done to simplify the code, specifically to
make it easier for functions outside of `TypedDataUtils` to reuse code
inside of `TypedDataUtils`.

Some types required adjustments, as type mistakes were brought to light
that TypeScript for some reason wasn't aware of when these were
declared as properties of the `TypedDataUtils` object. These were fixed
by adding two type assertions, making the `types` parameter to
`hashStruct` and `hashType` more strict, and by making the `typedData`
parameter to `eip712Hash` more strict. The type assertions (warranted
or not) preserve the types used previously. We can replace them later
with validation.
  • Loading branch information
Gudahtt committed Jul 26, 2021
1 parent 97caab5 commit c8ee6a8
Show file tree
Hide file tree
Showing 2 changed files with 362 additions and 222 deletions.
Loading

0 comments on commit c8ee6a8

Please sign in to comment.