From f0ed12486ae796cccec3f98abf61b6c77e68abd0 Mon Sep 17 00:00:00 2001 From: Daniel Liu Date: Tue, 14 Jan 2025 10:56:08 +0800 Subject: [PATCH] accounts/usbwallet/trezor: expose protobuf package (#17980) When some of the same messages are redefined anywhere in a Go project, the protobuf package panics (see https://github.com/golang/protobuf/issues/178). Since this package is internal, there is no way to work around it, as one cannot use it directly, but also cannot define the same messages. There is no downside in making the package accessible. --- accounts/usbwallet/trezor.go | 22 +++++++++---------- .../{internal => }/trezor/messages.pb.go | 0 .../{internal => }/trezor/messages.proto | 0 .../usbwallet/{internal => }/trezor/trezor.go | 0 .../{internal => }/trezor/types.pb.go | 0 .../{internal => }/trezor/types.proto | 0 6 files changed, 11 insertions(+), 11 deletions(-) rename accounts/usbwallet/{internal => }/trezor/messages.pb.go (100%) rename accounts/usbwallet/{internal => }/trezor/messages.proto (100%) rename accounts/usbwallet/{internal => }/trezor/trezor.go (100%) rename accounts/usbwallet/{internal => }/trezor/types.pb.go (100%) rename accounts/usbwallet/{internal => }/trezor/types.proto (100%) diff --git a/accounts/usbwallet/trezor.go b/accounts/usbwallet/trezor.go index a58251028d..3b63a9f234 100644 --- a/accounts/usbwallet/trezor.go +++ b/accounts/usbwallet/trezor.go @@ -28,7 +28,7 @@ import ( "math/big" "github.com/XinFinOrg/XDPoSChain/accounts" - "github.com/XinFinOrg/XDPoSChain/accounts/usbwallet/internal/trezor" + "github.com/XinFinOrg/XDPoSChain/accounts/usbwallet/trezor" "github.com/XinFinOrg/XDPoSChain/common" "github.com/XinFinOrg/XDPoSChain/common/hexutil" "github.com/XinFinOrg/XDPoSChain/core/types" @@ -85,15 +85,15 @@ func (w *trezorDriver) Status() (string, error) { // Open implements usbwallet.driver, attempting to initialize the connection to // the Trezor hardware wallet. Initializing the Trezor is a two or three phase operation: -// * The first phase is to initialize the connection and read the wallet's -// features. This phase is invoked is the provided passphrase is empty. The -// device will display the pinpad as a result and will return an appropriate -// error to notify the user that a second open phase is needed. -// * The second phase is to unlock access to the Trezor, which is done by the -// user actually providing a passphrase mapping a keyboard keypad to the pin -// number of the user (shuffled according to the pinpad displayed). -// * If needed the device will ask for passphrase which will require calling -// open again with the actual passphrase (3rd phase) +// - The first phase is to initialize the connection and read the wallet's +// features. This phase is invoked is the provided passphrase is empty. The +// device will display the pinpad as a result and will return an appropriate +// error to notify the user that a second open phase is needed. +// - The second phase is to unlock access to the Trezor, which is done by the +// user actually providing a passphrase mapping a keyboard keypad to the pin +// number of the user (shuffled according to the pinpad displayed). +// - If needed the device will ask for passphrase which will require calling +// open again with the actual passphrase (3rd phase) func (w *trezorDriver) Open(device io.ReadWriter, passphrase string) error { w.device, w.failure = device, nil @@ -249,7 +249,7 @@ func (w *trezorDriver) trezorSign(derivationPath []uint32, tx *types.Transaction } else { // Trezor backend does not support typed transactions yet. signer = types.NewEIP155Signer(chainID) - signature[crypto.RecoveryIDOffset] -= byte(chainID.Uint64()*2+35) + signature[crypto.RecoveryIDOffset] -= byte(chainID.Uint64()*2 + 35) } // Inject the final signature into the transaction and sanity check the sender diff --git a/accounts/usbwallet/internal/trezor/messages.pb.go b/accounts/usbwallet/trezor/messages.pb.go similarity index 100% rename from accounts/usbwallet/internal/trezor/messages.pb.go rename to accounts/usbwallet/trezor/messages.pb.go diff --git a/accounts/usbwallet/internal/trezor/messages.proto b/accounts/usbwallet/trezor/messages.proto similarity index 100% rename from accounts/usbwallet/internal/trezor/messages.proto rename to accounts/usbwallet/trezor/messages.proto diff --git a/accounts/usbwallet/internal/trezor/trezor.go b/accounts/usbwallet/trezor/trezor.go similarity index 100% rename from accounts/usbwallet/internal/trezor/trezor.go rename to accounts/usbwallet/trezor/trezor.go diff --git a/accounts/usbwallet/internal/trezor/types.pb.go b/accounts/usbwallet/trezor/types.pb.go similarity index 100% rename from accounts/usbwallet/internal/trezor/types.pb.go rename to accounts/usbwallet/trezor/types.pb.go diff --git a/accounts/usbwallet/internal/trezor/types.proto b/accounts/usbwallet/trezor/types.proto similarity index 100% rename from accounts/usbwallet/internal/trezor/types.proto rename to accounts/usbwallet/trezor/types.proto