Skip to content

Commit c2c3419

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 c2c3419

14 files changed

+489
-377
lines changed

api/firmware/eth.go

Lines changed: 20 additions & 0 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 identifyCase(hexString string) messages.ETHAddressCase {
145+
switch {
146+
case strings.ToUpper(hexString) == hexString:
147+
return messages.ETHAddressCase_ETH_ADDRESS_CASE_UPPER
148+
case strings.ToLower(hexString) == hexString:
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,
@@ -168,6 +179,10 @@ func (device *Device) ETHSign(
168179
if err != nil {
169180
return nil, err
170181
}
182+
183+
recipient_hex := hex.EncodeToString(recipient[:])
184+
address_case := identifyCase(recipient_hex)
185+
171186
request := &messages.ETHRequest{
172187
Request: &messages.ETHRequest_Sign{
173188
Sign: &messages.ETHSignRequest{
@@ -181,6 +196,7 @@ func (device *Device) ETHSign(
181196
Value: value.Bytes(),
182197
Data: data,
183198
HostNonceCommitment: hostNonceCommitment,
199+
AddressCase: address_case,
184200
},
185201
},
186202
}
@@ -224,6 +240,9 @@ func (device *Device) ETHSignEIP1559(
224240
return nil, err
225241
}
226242

243+
recipient_hex := hex.EncodeToString(recipient[:])
244+
address_case := identifyCase(recipient_hex)
245+
227246
request := &messages.ETHRequest{
228247
Request: &messages.ETHRequest_SignEip1559{
229248
SignEip1559: &messages.ETHSignEIP1559Request{
@@ -237,6 +256,7 @@ func (device *Device) ETHSignEIP1559(
237256
Value: value.Bytes(),
238257
Data: data,
239258
HostNonceCommitment: hostNonceCommitment,
259+
AddressCase: address_case,
240260
},
241261
},
242262
}

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)