aboutsummaryrefslogtreecommitdiffstats
path: root/console
diff options
context:
space:
mode:
authorNimrod Gutman <nimrod.gutman@gmail.com>2019-01-24 19:21:38 +0800
committerFelix Lange <fjl@users.noreply.github.com>2019-01-24 19:21:38 +0800
commit6f45fa66d8661036c518a186fb8cc5ede0c0b805 (patch)
tree706462508bad1fa8b8e9bce38028deb0a6afca23 /console
parent769657060e888612e7d585c6b6eae16a64c4ad19 (diff)
downloadgo-tangerine-6f45fa66d8661036c518a186fb8cc5ede0c0b805.tar
go-tangerine-6f45fa66d8661036c518a186fb8cc5ede0c0b805.tar.gz
go-tangerine-6f45fa66d8661036c518a186fb8cc5ede0c0b805.tar.bz2
go-tangerine-6f45fa66d8661036c518a186fb8cc5ede0c0b805.tar.lz
go-tangerine-6f45fa66d8661036c518a186fb8cc5ede0c0b805.tar.xz
go-tangerine-6f45fa66d8661036c518a186fb8cc5ede0c0b805.tar.zst
go-tangerine-6f45fa66d8661036c518a186fb8cc5ede0c0b805.zip
accounts/usbwallet: support trezor passphrases (#16503)
When opening the wallet, ask for passphrase as well as for the PIN and return the relevant error (PIN/passphrase required). Open must then be called again with either PIN or passphrase to advance the process. This also updates the console bridge to support passphrase authentication.
Diffstat (limited to 'console')
-rw-r--r--console/bridge.go35
1 files changed, 30 insertions, 5 deletions
diff --git a/console/bridge.go b/console/bridge.go
index b0b4d3798..33277cf6e 100644
--- a/console/bridge.go
+++ b/console/bridge.go
@@ -105,9 +105,37 @@ func (b *bridge) OpenWallet(call otto.FunctionCall) (response otto.Value) {
return val
}
// Wallet open failed, report error unless it's a PIN entry
- if !strings.HasSuffix(err.Error(), usbwallet.ErrTrezorPINNeeded.Error()) {
+ if strings.HasSuffix(err.Error(), usbwallet.ErrTrezorPINNeeded.Error()) {
+ val, err = b.readPinAndReopenWallet(call)
+ if err == nil {
+ return val
+ }
+ }
+ // Check if the user needs to input a passphrase
+ if !strings.HasSuffix(err.Error(), usbwallet.ErrTrezorPassphraseNeeded.Error()) {
+ throwJSException(err.Error())
+ }
+ val, err = b.readPassphraseAndReopenWallet(call)
+ if err != nil {
throwJSException(err.Error())
}
+ return val
+}
+
+func (b *bridge) readPassphraseAndReopenWallet(call otto.FunctionCall) (otto.Value, error) {
+ var passwd otto.Value
+ wallet := call.Argument(0)
+ if input, err := b.prompter.PromptPassword("Please enter your passphrase: "); err != nil {
+ throwJSException(err.Error())
+ } else {
+ passwd, _ = otto.ToValue(input)
+ }
+ return call.Otto.Call("jeth.openWallet", nil, wallet, passwd)
+}
+
+func (b *bridge) readPinAndReopenWallet(call otto.FunctionCall) (otto.Value, error) {
+ var passwd otto.Value
+ wallet := call.Argument(0)
// Trezor PIN matrix input requested, display the matrix to the user and fetch the data
fmt.Fprintf(b.printer, "Look at the device for number positions\n\n")
fmt.Fprintf(b.printer, "7 | 8 | 9\n")
@@ -121,10 +149,7 @@ func (b *bridge) OpenWallet(call otto.FunctionCall) (response otto.Value) {
} else {
passwd, _ = otto.ToValue(input)
}
- if val, err = call.Otto.Call("jeth.openWallet", nil, wallet, passwd); err != nil {
- throwJSException(err.Error())
- }
- return val
+ return call.Otto.Call("jeth.openWallet", nil, wallet, passwd)
}
// UnlockAccount is a wrapper around the personal.unlockAccount RPC method that