-
Notifications
You must be signed in to change notification settings - Fork 20.8k
accounts/usbwallet: trezor signed message support #19831
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
Conversation
3e2094c
to
9c9734e
Compare
accounts/usbwallet/ledger.go
Outdated
@@ -168,6 +168,12 @@ func (w *ledgerDriver) SignTx(path accounts.DerivationPath, tx *types.Transactio | |||
return w.ledgerSign(path, tx, chainID) | |||
} | |||
|
|||
// SignData sends a blob of data to the USB device and waits for the user to confirm | |||
// or deny the transaction. |
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.
transaction
-> signing request
.
accounts/usbwallet/trezor.go
Outdated
@@ -185,6 +185,29 @@ func (w *trezorDriver) SignTx(path accounts.DerivationPath, tx *types.Transactio | |||
return w.trezorSign(path, tx, chainID) | |||
} | |||
|
|||
// SignData sends a blob of data to the xUSB device and waits for the user to confirm | |||
// or deny the transaction. |
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.
transaction
-> signing request
.
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.
xUSB
-> USB
?
accounts/usbwallet/wallet.go
Outdated
@@ -67,6 +67,10 @@ type driver interface { | |||
// SignTx sends the transaction to the USB device and waits for the user to confirm | |||
// or deny the transaction. | |||
SignTx(path accounts.DerivationPath, tx *types.Transaction, chainID *big.Int) (common.Address, *types.Transaction, error) | |||
|
|||
// SignData sends a blob of data to the USB device and waits for the user to confirm | |||
// or deny the transaction. |
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.
transaction
-> signing request
.
|
||
// SignData sends a blob of data to the USB device and waits for the user to confirm | ||
// or deny the transaction. | ||
SignData(path accounts.DerivationPath, hash []byte) (common.Address, []byte, error) |
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.
I'm unsure about passing a hash
vs. the data itself. Won't some hardware wallet or Clef itself need the entire data?
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.
actually the message itself is passed, I'm going to change the variable name.
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.
Please do :)
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.
Parameter name is still hash
signer/core/signed_data.go
Outdated
@@ -144,7 +144,7 @@ func (api *SignerAPI) sign(addr common.MixedcaseAddress, req *SignDataRequest, l | |||
} | |||
pw, err := api.lookupOrQueryPassword(account.Address, | |||
"Password for signing", | |||
fmt.Sprintf("Please enter password for signing data with account %s", account.Address.Hex())) | |||
fmt.Sprintf("Please enter password for signing data with account %s, or just press 'RETURN'", account.Address.Hex())) |
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.
This is a bit ugly :P. A cleaner solution perhaps would be to look at the account.URL
and if it's a keystore, ask for password, for everything else just blindly forward?
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.
Quoting you (from memory) when you asked me to look into the Trezor stuff: "I would like a quick and ugly solution". Boom, delivered.
@@ -514,7 +518,44 @@ func (w *wallet) SelfDerive(bases []accounts.DerivationPath, chain ethereum.Chai | |||
// signHash implements accounts.Wallet, however signing arbitrary data is not | |||
// supported for hardware wallets, so this method will always return an error. | |||
func (w *wallet) signHash(account accounts.Account, hash []byte) ([]byte, error) { | |||
return nil, accounts.ErrNotSupported | |||
w.stateLock.RLock() // Comms have their own mutex |
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.
I guess this method should be renamed signData? Also please rename the hash variables everywhere to data.
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.
Please read the comment and update it too accordingly :P
7bcd24e
to
407128b
Compare
accounts/usbwallet/wallet.go
Outdated
@@ -518,7 +517,7 @@ func (w *wallet) SelfDerive(bases []accounts.DerivationPath, chain ethereum.Chai | |||
|
|||
// signHash implements accounts.Wallet, however signing arbitrary data is not |
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.
:P
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.
grmbl
accounts/usbwallet/ledger.go
Outdated
@@ -168,6 +168,12 @@ func (w *ledgerDriver) SignTx(path accounts.DerivationPath, tx *types.Transactio | |||
return w.ledgerSign(path, tx, chainID) | |||
} | |||
|
|||
// SignData sends a blob of data to the USB device and waits for the user to confirm | |||
// or deny the signing request. | |||
func (w *ledgerDriver) SignData(path accounts.DerivationPath, hash []byte) (common.Address, []byte, error) { |
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.
Parameter name is still hash
if addr := response.GetAddressHex(); len(addr) > 0 { // Newer firmwares use hexadecimal fomats | ||
address = common.HexToAddress(addr) | ||
} | ||
|
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.
Pls drop empty line.
@@ -531,7 +571,7 @@ func (w *wallet) SignDataWithPassphrase(account accounts.Account, passphrase, mi | |||
} | |||
|
|||
func (w *wallet) SignText(account accounts.Account, text []byte) ([]byte, error) { | |||
return w.signHash(account, accounts.TextHash(text)) | |||
return w.signData(account, accounts.TextHash(text)) |
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.
This should be wrong now. If we changed the signature to sign data, then we can't hash the text here now. What does sign text even do? It's not my method. Ping @holiman ?
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.
There's an extra catch here that I've spotted yesterday during a debug session: the Trezor actually adds the prefix no matter what, so right now the prefix is added twice. So the whole prefix management has to be changed, I'm still untangling some bits, and it would be interesting to discuss it.
signer/core/signed_data.go
Outdated
return nil, err | ||
// Only ask for the passphrase if the account is keystore based | ||
pw := "" | ||
if strings.Compare(wallet.URL().Scheme, "keystore") == 0 { |
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.
wallet.URL().Scheme == "keystore"
Putting this into the 1.9.x backlog. We need Trezor firmware support before we can continue (trezor/trezor-firmware#148). |
1 |
Closing this as it's not supported by Trezor. We can only pick it up if they implement it upstream. Closing until then. |
reference: trezor/trezor-firmware#148 |
Implements
signData
for trezor. This has been tested with both the pre-1.8 version of the firmware and the latest. Fixes #19812To work, this PR needs #19827