@@ -122,6 +122,25 @@ pub struct EIP1559Transaction {
122
122
pub data : Vec < u8 > ,
123
123
}
124
124
125
+ /// Identifies the case of the recipient address given as hexadecimal string.
126
+ /// This function exists as a convenience to help clients to determine the case of the
127
+ /// recipient address.
128
+ pub fn eth_identify_case ( recipient_address : & str ) -> pb:: EthAddressCase {
129
+ if recipient_address
130
+ . chars ( )
131
+ . all ( |c| !c. is_ascii_alphabetic ( ) || c. is_ascii_uppercase ( ) )
132
+ {
133
+ pb:: EthAddressCase :: Upper
134
+ } else if recipient_address
135
+ . chars ( )
136
+ . all ( |c| !c. is_ascii_alphabetic ( ) || c. is_ascii_lowercase ( ) )
137
+ {
138
+ pb:: EthAddressCase :: Lower
139
+ } else {
140
+ pb:: EthAddressCase :: Mixed
141
+ }
142
+ }
143
+
125
144
#[ cfg( feature = "rlp" ) ]
126
145
impl TryFrom < & [ u8 ] > for Transaction {
127
146
type Error = ( ) ;
@@ -465,6 +484,7 @@ impl<R: Runtime> PairedBitBox<R> {
465
484
chain_id : u64 ,
466
485
keypath : & Keypath ,
467
486
tx : & Transaction ,
487
+ address_case : Option < pb:: EthAddressCase > ,
468
488
) -> Result < [ u8 ; 65 ] , Error > {
469
489
// passing chainID instead of coin only since v9.10.0
470
490
self . validate_version ( ">=9.10.0" ) ?;
@@ -483,7 +503,7 @@ impl<R: Runtime> PairedBitBox<R> {
483
503
commitment : crate :: antiklepto:: host_commit ( & host_nonce) . to_vec ( ) ,
484
504
} ) ,
485
505
chain_id,
486
- address_case : pb:: EthAddressCase :: Mixed as _ ,
506
+ address_case : address_case . unwrap_or ( pb:: EthAddressCase :: Mixed ) . into ( ) ,
487
507
} ) ;
488
508
let response = self . query_proto_eth ( request) . await ?;
489
509
self . handle_antiklepto ( & response, host_nonce) . await
@@ -496,6 +516,7 @@ impl<R: Runtime> PairedBitBox<R> {
496
516
& self ,
497
517
keypath : & Keypath ,
498
518
tx : & EIP1559Transaction ,
519
+ address_case : Option < pb:: EthAddressCase > ,
499
520
) -> Result < [ u8 ; 65 ] , Error > {
500
521
// EIP1559 is suported from v9.16.0
501
522
self . validate_version ( ">=9.16.0" ) ?;
@@ -516,7 +537,7 @@ impl<R: Runtime> PairedBitBox<R> {
516
537
host_nonce_commitment : Some ( pb:: AntiKleptoHostNonceCommitment {
517
538
commitment : crate :: antiklepto:: host_commit ( & host_nonce) . to_vec ( ) ,
518
539
} ) ,
519
- address_case : pb:: EthAddressCase :: Mixed as _ ,
540
+ address_case : address_case . unwrap_or ( pb:: EthAddressCase :: Mixed ) . into ( ) ,
520
541
} ) ;
521
542
let response = self . query_proto_eth ( request) . await ?;
522
543
self . handle_antiklepto ( & response, host_nonce) . await
@@ -1252,4 +1273,20 @@ mod tests {
1252
1273
)
1253
1274
. is_err( ) ) ;
1254
1275
}
1276
+
1277
+ #[ test]
1278
+ fn test_eth_identify_case ( ) {
1279
+ assert_eq ! (
1280
+ eth_identify_case( "0XF39FD6E51AAD88F6F4CE6AB8827279CFFFB92266" ) ,
1281
+ pb:: EthAddressCase :: Upper
1282
+ ) ;
1283
+ assert_eq ! (
1284
+ eth_identify_case( "0xf39fd6e51aad88f6f4ce6ab8827279cfffb92266" ) ,
1285
+ pb:: EthAddressCase :: Lower
1286
+ ) ;
1287
+ assert_eq ! (
1288
+ eth_identify_case( "0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266" ) ,
1289
+ pb:: EthAddressCase :: Mixed
1290
+ ) ;
1291
+ }
1255
1292
}
0 commit comments