Skip to content
This repository has been archived by the owner on Nov 23, 2023. It is now read-only.

Support domain-only EthereumSignTypedData and other improvements #1033

Merged
merged 4 commits into from
Feb 10, 2022

Conversation

aloisklink
Copy link
Contributor

@aloisklink aloisklink commented Jan 27, 2022

Add documentation on using EthereumSignTypedData on T1 and improved types. These were missing from #1015.

Minor breaking change

EthereumSignTypedData now requires passing Trezor T variables. This seems makes sense from my side, since everybody using this function should pass Trezor T variables anyway, and since this function was only recently released, I doubt this change would affect any users of this library.

Plus, it makes all the code (especially types!) simpler.

Trezor Model 1 parameters are still optional, as blind signing requires using an extra dependency on an external library, and is less secure.

Support for primaryType = EIP712Domain

I tried adding docs/tests/types for trezor/trezor-firmware#2036 in this PR too, but updating the submodules/trezor-common submodule just causes a bunch of other Protobuf type errors to occur, so I'll do that in another separate PR in the future.

I've added support for trezor/trezor-firmware#2036 in this PR too, since they both edit similar files.

I've tested locally using:

src/js/core/methods/EthereumSignTypedData.js Show resolved Hide resolved
Comment on lines 55 to 92
if (payload.message_hash) {
this.params = {
...this.params,
domain_separator_hash: payload.domain_separator_hash,
message_hash: payload.message_hash,
};
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is in a separate if-statement to make Flow-type happy.

src/js/core/methods/EthereumSignTypedData.js Show resolved Hide resolved
@mroz22
Copy link
Contributor

mroz22 commented Jan 31, 2022

Hi, we are switching to master branch of trezor-common here https://github.com/trezor/connect/pull/1036/files and yes. It needs to sort out some types incompabilities. Patience please.

@mroz22
Copy link
Contributor

mroz22 commented Feb 3, 2022

Updated trezor-common is now in develop branch.

@mroz22
Copy link
Contributor

mroz22 commented Feb 4, 2022

Hello @aloisklink
We are generally quite happy for your contributions as they are always really nicely done, so If it suits your needs better this wa I think I am not going to object against that. Just if you could please rebase this on the latest develop so that I can run T1 tests in gitlab CI (we have added better support for this in one of the last commits).

@aloisklink
Copy link
Contributor Author

We are generally quite happy for your contributions as they are always really nicely done, so If it suits your needs better this wa I think I am not going to object against that. Just if you could please rebase this on the latest develop so that I can run T1 tests in gitlab CI (we have added better support for this in one of the last commits).

No worries, this isn't urgent, this PR is currently mainly just documentation/improved-types.

I'm also very close to being done with adding support for trezor/trezor-firmware#2036 (I can push it into this PR, or into a separate one), which fixes any of the failing tests in ethereumSignTypedData due to updating trezor-common.

I did encounter a bug with getFirmwareRange(): it only uses the first matching entry in src/data/config.json, but I believe I've fixed it. I'm just testing it locally, I'll make a PR in a few hours!

@aloisklink
Copy link
Contributor Author

Just if you could please rebase this on the latest develop so that I can run T1 tests in gitlab CI (we have added better support for this in one of the last commits).

Rebased on the latest develop in fee6389

I did it last night before you commented, so GitHub's UI is showing the commit before your comment.

I also added support for trezor/trezor-firmware#2036 in 0bff3e5, so that the T1/TT tests now pass on the updated fixtures. Let me know if you'd prefer me to put this into a separate PR.

I've tested locally using:

  • ./tests/run.sh -D 'podman' -i 'ethereumSignTypedData' Fails, since getFirmwareRange() isn't throwing a wrong firmware error (see Fix getFirmwareRange() for multiple matching firmware ranges #1042)
  • ./tests/run.sh -D 'podman' -i 'ethereumSignTypedData' -f '2-master' Success
  • ./tests/run.sh -D 'podman' -i 'ethereumSignTypedData' -f '1-master' Success

Fixup commits

  • 2fbfc67 Fixes the unit test for getUnavailableCapabilities() (I didn't realise that changing src/data/config.json would affect this test)
  • 7139d79 Renames flow-type EthereumSignTypedHashOrData to EthereumSignTypedHashAndData and adds it to the TypeScript definitions too.

@mroz22
Copy link
Contributor

mroz22 commented Feb 8, 2022

Hi, please rebase and feel free to include everything you need into this PR. I think it looks good so once conflicts are resolved we can merge it.

BREAKING CHANGE: EthereumSignTypedData now requires passing Trezor T
  variables. Trezor Model 1 parameters are still optional, as
  blind signing requires using an extra dependency on an external
  library, and is less secure.
Add support for signing domain-only data in ethereumSignTypedData,
e.g. when primaryType = EIP712Domain.

On Trezor T, this behaviour previously gave incorrect signatures
or threw errors.

On Trezor Model 1, not passing the "message_hash" parameter caused
an error.
Adds support for domain-only EIP-712 hashes to
plugins/ethereum/typedData.js
@aloisklink aloisklink force-pushed the ethereumSignTypedData branch 2 times, most recently from d780e6e to 4e8873a Compare February 9, 2022 03:18
ethereumSignTypedData now passes on tests, so we can add it to CI.
@aloisklink aloisklink force-pushed the ethereumSignTypedData branch from 4e8873a to 5530f40 Compare February 9, 2022 03:30
@aloisklink aloisklink changed the title refactor(ethSignTypedData)!: Improve docs & types Support domain-only EthereumSignTypedData and other improvements Feb 9, 2022
@aloisklink
Copy link
Contributor Author

Thanks for the feedback! I've rebased on develop and --autosquash-ed the !fixup commits.

Since develop included #1042, the ethereumSignTypedData tests now pass on the new/old firmware versions that I tested, so I also added ethereumSignTypedData into the CI in 5530f40

It's ready to merge from my side 😄

Side-note, I didn't add a CI test for src/js/plugins/ethereum, but I can add one in a separate PR if you think it's worth it (I'd say yes on GitHub Actions because it's free, but maybe not worth the extra CI minutes on GitLab). It would be easy to add, just a cd src/js/plugins/ethereum && yarn install && yarn test:unit.

@mroz22
Copy link
Contributor

mroz22 commented Feb 9, 2022

Side-note, I didn't add a CI test for src/js/plugins/ethereum, but I can add one in a separate PR if you think it's worth it (I'd say yes on GitHub Actions because it's free, but maybe not worth the extra CI minutes on GitLab). It would be easy to add, just a cd src/js/plugins/ethereum && yarn install && yarn test:unit.

Running plugins in CI would be great. Github is a good fit for this as it runs for external contributions automatically (gitlab does not) and plugins are mostly developed by external contributors I guess. So I think we would appreciate such effort.

@mroz22 mroz22 merged commit d2e4ad3 into trezor:develop Feb 10, 2022
@aloisklink aloisklink deleted the ethereumSignTypedData branch February 10, 2022 12:06
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants