@@ -36,7 +36,7 @@ const MAX_MESSAGE_SIZE: usize = 1024;
36
36
/// compact format (R and S values), and the last byte is the recoverable id (recid).
37
37
pub async fn process ( request : & pb:: BtcSignMessageRequest ) -> Result < Response , Error > {
38
38
let coin = BtcCoin :: try_from ( request. coin ) ?;
39
- if coin != BtcCoin :: Btc {
39
+ if ! matches ! ( coin, BtcCoin :: Btc | BtcCoin :: Tbtc | BtcCoin :: Rbtc ) {
40
40
return Err ( Error :: InvalidInput ) ;
41
41
}
42
42
let ( keypath, simple_type) = match & request. script_config {
@@ -182,6 +182,52 @@ mod tests {
182
182
) ;
183
183
}
184
184
185
+ #[ test]
186
+ pub fn test_p2wpkh_testnet ( ) {
187
+ let request = pb:: BtcSignMessageRequest {
188
+ coin : BtcCoin :: Tbtc as _ ,
189
+ script_config : Some ( pb:: BtcScriptConfigWithKeypath {
190
+ script_config : Some ( pb:: BtcScriptConfig {
191
+ config : Some ( Config :: SimpleType ( SimpleType :: P2wpkh as _ ) ) ,
192
+ } ) ,
193
+ keypath : vec ! [ 84 + HARDENED , 1 + HARDENED , 0 + HARDENED , 0 , 0 ] ,
194
+ } ) ,
195
+ msg : MESSAGE . to_vec ( ) ,
196
+ host_nonce_commitment : None ,
197
+ } ;
198
+
199
+ static mut CONFIRM_COUNTER : u32 = 0 ;
200
+
201
+ mock ( Data {
202
+ ui_confirm_create : Some ( Box :: new ( |params| {
203
+ match unsafe {
204
+ CONFIRM_COUNTER += 1 ;
205
+ CONFIRM_COUNTER
206
+ } {
207
+ 1 => {
208
+ assert_eq ! ( params. title, "Sign message" ) ;
209
+ assert_eq ! ( params. body, "Coin: BTC Testnet" ) ;
210
+ true
211
+ }
212
+ 2 => {
213
+ assert_eq ! ( params. title, "Address" ) ;
214
+ assert_eq ! ( params. body, "tb1qnlyrq9pshg0v0lsuudjgga4nvmjxhcvketqwdg" ) ;
215
+ true
216
+ }
217
+ 3 => {
218
+ assert_eq ! ( params. title, "Sign message" ) ;
219
+ assert_eq ! ( params. body. as_bytes( ) , MESSAGE ) ;
220
+ true
221
+ }
222
+ _ => panic ! ( "too many user confirmations" ) ,
223
+ }
224
+ } ) ) ,
225
+ ..Default :: default ( )
226
+ } ) ;
227
+ mock_unlocked ( ) ;
228
+ assert ! ( block_on( process( & request) ) . is_ok( ) ) ;
229
+ }
230
+
185
231
#[ test]
186
232
pub fn test_p2wpkh_p2sh ( ) {
187
233
let request = pb:: BtcSignMessageRequest {
@@ -419,5 +465,24 @@ mod tests {
419
465
} ) ) ,
420
466
Err ( Error :: InvalidInput )
421
467
) ;
468
+ // Invalid keypath (mainnet keypath on testnet)
469
+ mock ( Data {
470
+ ..Default :: default ( )
471
+ } ) ;
472
+ mock_unlocked ( ) ;
473
+ assert_eq ! (
474
+ block_on( process( & pb:: BtcSignMessageRequest {
475
+ coin: BtcCoin :: Tbtc as _,
476
+ script_config: Some ( pb:: BtcScriptConfigWithKeypath {
477
+ script_config: Some ( pb:: BtcScriptConfig {
478
+ config: Some ( Config :: SimpleType ( SimpleType :: P2wpkh as _) )
479
+ } ) ,
480
+ keypath: vec![ 84 + HARDENED , 0 + HARDENED , 0 + HARDENED , 0 , 0 ] ,
481
+ } ) ,
482
+ msg: MESSAGE . to_vec( ) ,
483
+ host_nonce_commitment: None ,
484
+ } ) ) ,
485
+ Err ( Error :: InvalidInput )
486
+ ) ;
422
487
}
423
488
}
0 commit comments