Skip to content

Commit e78da17

Browse files
committed
eth_sign_tx: integrate address case feature to go library
see : BitBoxSwiss/bitbox02-firmware@055bda6 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 e78da17

14 files changed

+492
-379
lines changed

api/firmware/eth.go

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

144+
// ETHIdentifyCase identifies the case of the recipient address given as hexadecimal string.
145+
// This function exists as a convenience to potentially help clients to determine the case of the
146+
// recipient address. The output of the function goes to ETHSign and ETHSignEIP1559 as the
147+
// recipientAddressCase parameter, which is forwarded to BitBox02 device to reconstruct the address
148+
// in the correct case(the one that the user enters).
149+
func ETHIdentifyCase(recipientAddress string) messages.ETHAddressCase {
150+
switch {
151+
case strings.ToUpper(recipientAddress) == recipientAddress:
152+
return messages.ETHAddressCase_ETH_ADDRESS_CASE_UPPER
153+
case strings.ToLower(recipientAddress) == recipientAddress:
154+
return messages.ETHAddressCase_ETH_ADDRESS_CASE_LOWER
155+
default:
156+
return messages.ETHAddressCase_ETH_ADDRESS_CASE_MIXED
157+
}
158+
}
159+
144160
// ETHSign signs an ethereum transaction. It returns a 65 byte signature (R, S, and 1 byte recID).
145161
func (device *Device) ETHSign(
146162
chainID uint64,
@@ -150,7 +166,8 @@ func (device *Device) ETHSign(
150166
gasLimit uint64,
151167
recipient [20]byte,
152168
value *big.Int,
153-
data []byte) ([]byte, error) {
169+
data []byte,
170+
recipientAddressCase messages.ETHAddressCase) ([]byte, error) {
154171
supportsAntiklepto := device.version.AtLeast(semver.NewSemVer(9, 5, 0))
155172

156173
var hostNonceCommitment *messages.AntiKleptoHostNonceCommitment
@@ -168,6 +185,7 @@ func (device *Device) ETHSign(
168185
if err != nil {
169186
return nil, err
170187
}
188+
171189
request := &messages.ETHRequest{
172190
Request: &messages.ETHRequest_Sign{
173191
Sign: &messages.ETHSignRequest{
@@ -181,6 +199,7 @@ func (device *Device) ETHSign(
181199
Value: value.Bytes(),
182200
Data: data,
183201
HostNonceCommitment: hostNonceCommitment,
202+
AddressCase: recipientAddressCase,
184203
},
185204
},
186205
}
@@ -213,7 +232,8 @@ func (device *Device) ETHSignEIP1559(
213232
gasLimit uint64,
214233
recipient [20]byte,
215234
value *big.Int,
216-
data []byte) ([]byte, error) {
235+
data []byte,
236+
recipientAddressCase messages.ETHAddressCase) ([]byte, error) {
217237

218238
if !device.version.AtLeast(semver.NewSemVer(9, 16, 0)) {
219239
return nil, UnsupportedError("9.16.0")
@@ -237,6 +257,7 @@ func (device *Device) ETHSignEIP1559(
237257
Value: value.Bytes(),
238258
Data: data,
239259
HostNonceCommitment: hostNonceCommitment,
260+
AddressCase: recipientAddressCase,
240261
},
241262
},
242263
}

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)