Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

feat: trezor support #663

Merged
merged 17 commits into from
Dec 13, 2021
Merged

feat: trezor support #663

merged 17 commits into from
Dec 13, 2021

Conversation

joshieDo
Copy link
Contributor

@joshieDo joshieDo commented Dec 9, 2021

Motivation

Ref: #1
Adding trezor signing support, with the end goal of adding it to foundry/cast.

Solution

Forked a year old rust client (https://github.com/romanz/rust-trezor-api -> https://github.com/joshieDo/rust-trezor-api) and added the ethereum interface it lacked, along with updating the libusb (+rusb) to be compatible with ethers-rs. I'm not much experienced in Rust, so an additional pair of eyes in my fork is most welcome.

On the ethers-signers implementation, I tried to follow the existing Ledger structure as much as possible.

  • get_address
  • sign_message
  • sign_tx
  • sign_eip1559
  • sign_eip712

WIP

Fixing: Passphrase is being requested on every request

Missing EIP712

I need to understand EIP712 better from both sides, At first glance, it seems tricky to pass the intended data from ethers-rs to the trezor client. I was hoping that could be done in a future issue/PR. What do you think?

PR Checklist

  • Added Tests
  • Added Documentation
  • Updated the changelog

@joshieDo joshieDo marked this pull request as ready for review December 10, 2021 01:19
Copy link
Collaborator

@mattsse mattsse left a comment

Choose a reason for hiding this comment

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

This is great.
can't speak to the maturity of the trezor client lib, but have some nits:

there are a quite a few unwraps, which may be fine but to be sure I'd rather see a basic helper function like split(&tx) -> Result<(nonce,gasprice,...)> that gets all values in a safe way.

Any plans for publishing the trezor on crates?

@@ -28,6 +28,7 @@ yubihsm = { version = "0.39.0", features = ["secp256k1", "http", "usb"], optiona
futures-util = "0.3.18"
futures-executor = "0.3.18"
semver = "1.0.4"
trezor-client = { package="trezor", git = "https://github.com/joshiedo/rust-trezor-api", rev = "f0c9775", optional = true }
Copy link
Collaborator

Choose a reason for hiding this comment

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

this would prevent us from publishing a new version of ethers,
what's the state of that crate, any chance you can publish this beforehand?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@joshieDo
Copy link
Contributor Author

This is great. can't speak to the maturity of the trezor client lib, but have some nits:

there are a quite a few unwraps, which may be fine but to be sure I'd rather see a basic helper function like split(&tx) -> Result<(nonce,gasprice,...)> that gets all values in a safe way.

cleaned it up (also on the trezor client lib side)

Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

LGTM - but let's maybe try to reduce the deps introduced by the trezor lib?

Cargo.lock Outdated
Comment on lines 224 to 236
[[package]]
name = "bitcoin"
version = "0.18.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd5e7935f613ba170459072926f01dc5ddb8aa22382dc4badf44bbb55e2d243d"
dependencies = [
"bitcoin-bech32",
"bitcoin_hashes",
"byteorder",
"hex 0.3.2",
"rand 0.3.23",
"secp256k1",
]
Copy link
Owner

Choose a reason for hiding this comment

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

It seems like we're pulling in a few dependencies which should not be required? Maybe we can feature gate the Bitcion/Ethereum APIs in the trezor library?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

makes sense, done

Copy link
Owner

@gakonst gakonst left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you.

@gakonst gakonst merged commit 6bf325d into gakonst:master Dec 13, 2021
meetmangukiya pushed a commit to meetmangukiya/ethers-rs that referenced this pull request Mar 21, 2022
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.

3 participants