Skip to content

Commit 6612064

Browse files
committed
eth_sign_tx: integrate address case feature to go library
see : BitBoxSwiss/bitbox02-firmware@055bda6#diff-3c37126459943046256cdb0d98c78832b5630e54b1d56aff57a8fac56d2964bc For ETH signing legacy and EIP1559 transactions, the BitBox02 device shows confirmation screens for recipient and amount. For recipient, the device was previously showing the address in mixed case according to EIP-55, no matter the case user has entered. This created confusions among the users. That is why not the go library detects the case of the recipient address useer inputted and sends this case information to BitBox02 device, which will in turn show the recipient address in the same case that it got from the library. Signed-off-by: asi345 <inanata15@gmail.com>
1 parent a8c8337 commit 6612064

14 files changed

+487
-379
lines changed

api/firmware/eth.go

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,17 @@ func (device *Device) handleSignerNonceCommitment(response *messages.ETHResponse
141141
return signature, nil
142142
}
143143

144+
func ETHIdentifyCase(recipientAddress string) messages.ETHAddressCase {
145+
switch {
146+
case strings.ToUpper(recipientAddress) == recipientAddress:
147+
return messages.ETHAddressCase_ETH_ADDRESS_CASE_UPPER
148+
case strings.ToLower(recipientAddress) == recipientAddress:
149+
return messages.ETHAddressCase_ETH_ADDRESS_CASE_LOWER
150+
default:
151+
return messages.ETHAddressCase_ETH_ADDRESS_CASE_MIXED
152+
}
153+
}
154+
144155
// ETHSign signs an ethereum transaction. It returns a 65 byte signature (R, S, and 1 byte recID).
145156
func (device *Device) ETHSign(
146157
chainID uint64,
@@ -150,7 +161,8 @@ func (device *Device) ETHSign(
150161
gasLimit uint64,
151162
recipient [20]byte,
152163
value *big.Int,
153-
data []byte) ([]byte, error) {
164+
data []byte,
165+
recipientAddressCase messages.ETHAddressCase) ([]byte, error) {
154166
supportsAntiklepto := device.version.AtLeast(semver.NewSemVer(9, 5, 0))
155167

156168
var hostNonceCommitment *messages.AntiKleptoHostNonceCommitment
@@ -168,6 +180,7 @@ func (device *Device) ETHSign(
168180
if err != nil {
169181
return nil, err
170182
}
183+
171184
request := &messages.ETHRequest{
172185
Request: &messages.ETHRequest_Sign{
173186
Sign: &messages.ETHSignRequest{
@@ -181,6 +194,7 @@ func (device *Device) ETHSign(
181194
Value: value.Bytes(),
182195
Data: data,
183196
HostNonceCommitment: hostNonceCommitment,
197+
AddressCase: recipientAddressCase,
184198
},
185199
},
186200
}
@@ -213,7 +227,8 @@ func (device *Device) ETHSignEIP1559(
213227
gasLimit uint64,
214228
recipient [20]byte,
215229
value *big.Int,
216-
data []byte) ([]byte, error) {
230+
data []byte,
231+
recipientAddressCase messages.ETHAddressCase) ([]byte, error) {
217232

218233
if !device.version.AtLeast(semver.NewSemVer(9, 16, 0)) {
219234
return nil, UnsupportedError("9.16.0")
@@ -237,6 +252,7 @@ func (device *Device) ETHSignEIP1559(
237252
Value: value.Bytes(),
238253
Data: data,
239254
HostNonceCommitment: hostNonceCommitment,
255+
AddressCase: recipientAddressCase,
240256
},
241257
},
242258
}

api/firmware/messages/antiklepto.pb.go

Lines changed: 6 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/firmware/messages/backup_commands.pb.go

Lines changed: 10 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

api/firmware/messages/bitbox02_system.pb.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)