forked from Blockstream/Jade
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest_jade.py
3846 lines (3323 loc) · 189 KB
/
test_jade.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import os
import time
import glob
import cbor2 as cbor
import copy
import json
import base64
import random
import logging
import argparse
import subprocess
import threading
import _thread
from pinserver.server import PINServerECDHv2
from pinserver.pindb import PINDb
import wallycore as wally
from jadepy.jade import JadeAPI, JadeError
# Enable jade logging
jadehandler = logging.StreamHandler()
logger = logging.getLogger('jadepy.jade')
logger.setLevel(logging.DEBUG)
logger.addHandler(jadehandler)
device_logger = logging.getLogger('jadepy.jade-device')
device_logger.setLevel(logging.DEBUG)
device_logger.addHandler(jadehandler)
def h2b(hexdata):
if hexdata is None:
return None
elif isinstance(hexdata, list):
return list(map(h2b, hexdata))
elif isinstance(hexdata, dict):
return {k: h2b(v) for k, v in hexdata.items()}
else:
return bytes.fromhex(hexdata)
def _h2b_test_case(testcase):
# Convert fields from hex to binary
if 'txn' in testcase['input']:
# sign-tx data
testcase['input']['txn'] = h2b(testcase['input']['txn'])
for input in testcase['input']['inputs']:
if input:
for k, v in input.items():
if k not in ['is_witness', 'path', 'sighash', 'satoshi', 'value']:
input[k] = h2b(v)
if 'trusted_commitments' in testcase['input']:
for commitment in testcase['input']['trusted_commitments']:
if commitment:
for k, v in commitment.items():
commitment[k] = v if k == 'value' else h2b(v)
if 'additional_info' in testcase['input']:
additional_info = testcase['input']['additional_info']
for summary_item in additional_info['wallet_input_summary']:
summary_item['asset_id'] = h2b(summary_item['asset_id'])
for summary_item in additional_info['wallet_output_summary']:
summary_item['asset_id'] = h2b(summary_item['asset_id'])
if 'expected_output' in testcase:
testcase['expected_output'] = h2b(testcase['expected_output'])
elif 'psbt' in testcase['input']:
testcase['input']['psbt'] = base64.b64decode(testcase['input']['psbt'])
if 'expected_output' in testcase:
expected_output = testcase['expected_output']
expected_output['psbt'] = base64.b64decode(expected_output['psbt'])
if 'txn' in expected_output:
expected_output['txn'] = h2b(expected_output['txn'])
elif 'message' in testcase['input']:
# sign-msg test data
if 'ae_host_commitment' in testcase['input']:
testcase['input']['ae_host_commitment'] = h2b(testcase['input']['ae_host_commitment'])
if 'ae_host_entropy' in testcase['input']:
testcase['input']['ae_host_entropy'] = h2b(testcase['input']['ae_host_entropy'])
if 'expected_output' in testcase and len(testcase['expected_output']) == 2:
testcase['expected_output'][0] = h2b(testcase['expected_output'][0])
elif 'identity' in testcase['input']:
# sign-identity test data
testcase['input']['challenge'] = h2b(testcase['input']['challenge'])
expected_output = testcase['expected_output']
expected_output['slip-0013'] = h2b(expected_output['slip-0013'])
expected_output['signature'] = h2b(expected_output['signature'])
expected_output['slip-0017'] = h2b(expected_output['slip-0017'])
expected_output['ecdh_with_trezor'] = h2b(expected_output['ecdh_with_trezor'])
elif 'multisig_name' in testcase['input']:
# multisig data
descriptor = testcase['input']['descriptor']
if 'master_blinding_key' in descriptor:
descriptor['master_blinding_key'] = h2b(descriptor['master_blinding_key'])
for signer in testcase['input']['descriptor']['signers']:
signer['fingerprint'] = h2b(signer['fingerprint'])
if 'blinding_key_tests' in testcase:
for blinding_test in testcase['blinding_key_tests']:
blinding_test['script'] = h2b(blinding_test['script'])
blinding_test['their_pubkey'] = h2b(blinding_test['their_pubkey'])
blinding_test['expected_blinding_key'] = h2b(blinding_test['expected_blinding_key'])
blinding_test['expected_shared_nonce'] = h2b(blinding_test['expected_shared_nonce'])
if 'commitments_tests' in testcase:
for blinding_test in testcase['commitments_tests']:
blinding_test['hash_prevouts'] = h2b(blinding_test['hash_prevouts'])
blinding_test['asset_id'] = h2b(blinding_test['asset_id'])
blinding_test['abf'] = h2b(blinding_test['abf'])
blinding_test['vbf'] = h2b(blinding_test['vbf'])
blinding_test['asset_generator'] = h2b(blinding_test['asset_generator'])
blinding_test['value_commitment'] = h2b(blinding_test['value_commitment'])
elif 'multisig_file' in testcase['input']:
expected_result = testcase.get('expected_result')
if expected_result and 'master_blinding_key' in expected_result:
expected_result['master_blinding_key'] = h2b(expected_result['master_blinding_key'])
elif 'descriptor_name' in testcase['input']:
# descriptor data
if 'multisig_equivalent' in testcase['input']:
for signer in testcase['input']['multisig_equivalent']['descriptor']['signers']:
signer['fingerprint'] = h2b(signer['fingerprint'])
return testcase
# Helper to read a json file into a dict
def _read_json_file(filename):
logger.info('Reading json file: {}'.format(filename))
with open(filename, 'r') as json_file:
return json.load(json_file)
# Helper to read json test files into a list
def _get_test_cases(pattern):
return (_h2b_test_case(_read_json_file(f)) for f in glob.glob("./test_data/" + pattern))
BLE_TEST_PASSKEYFILE = "ble_test_passkey.txt"
BLE_TEST_BADKEYFILE = "ble_test_badkey.txt"
# The default serial read timeout
DEFAULT_SERIAL_TIMEOUT = 120
# The pubkey for the test (in-proc) pinserver
PINSERVER_TEST_PUBKEY_FILE = "server_public_key.pub"
# Pinserver prod defaults
PINSERVER_DEFAULT_URL = "https://j8d.io"
PINSERVER_DEFAULT_ONION = "http://mrrxtq6tjpbnbm7vh5jt6mpjctn7ggyfy5wegvbeff3x7jrznqawlmid.onion"
# The number of values expected back in version info
NUM_VALUES_VERINFO = 20
TEST_MNEMONIC = 'fish inner face ginger orchard permit useful method fence \
kidney chuckle party favorite sunset draw limb science crane oval letter \
slot invite sadness banana'
TEST_MNEMONIC_PREFIXES = 'fish inne face gin orc perm usef meth fen kidn chuc \
part fav suns draw limb scie cran ova let slot invi sadn bana'
# 'can' and 'net' are ambiguous prefixes, but are an exact match to words in
# the bip39-wordlist, so should be recognised/allowed.
TEST_MNEMONIC_PREFIXES_EXACT_MATCH = 'recy wear club hurr indu floa cust gua \
ae plan scan carr elec reco acco stoc insp net ups can opt brie guid priv'
# One word (met) prefix is not unambiguous: met => metal, method
TEST_MNEMONIC_PREFIXES_AMBIGUOUS = 'fish inne face gin orc perm usef met fen \
kidn chuc part fav suns draw limb scie cran ova let slot invi sadn bana'
# Seedsigner styles for our test mnemonic
TEST_MNEMONIC_SEEDSIGNER = '0701093106520784124813051919112106800979032412840\
67217400531103815430402126110281632094415190145'
TEST_MNEMONIC_SEEDSIGNER_COMPACT = b'W\xae\x8dF1\t\xc1F{\xfcaU\x0fL\xa2PEA\xb3\
\x10\x9c\x0e\xc0\xe6Jv\xc0L\xc0\xec/x'
# bcur bip39 style for our test mnemonic
TEST_MNEMONIC_BCUR_BIP39_LOWER = 'ur:crypto-bip39/oeadlkiyjkisinihjzieihiojpjl\
kpjoihihjpjlieihihhskthsjeihiejzjliajeiojkhskpjkhsioihieiahsjkisihiojzhsjpihie\
kthskoihieiajpihktihiyjzhsjnihihiojzjlkoihaoidihjtrkkndede'
TEST_MNEMONIC_BCUR_BIP39_UPPER = 'UR:CRYPTO-BIP39/OEADLKIYJKISINIHJZIEIHIOJPJL\
KPJOIHIHJPJLIEIHIHHSKTHSJEIHIEJZJLIAJEIOJKHSKPJKHSIOIHIEIAHSJKISIHIOJZHSJPIHIE\
KTHSKOIHIEIAJPIHKTIHIYJZHSJNIHIHIOJZJLKOIHAOIDIHJTRKKNDEDE'
TEST_MNEMONIC_BCUR_BIP39_STRING = 'shield group erode awake lock sausage \
cash glare wave crew flame glove'
TEST_MNEMONIC_12 = 'retire verb human ecology best member fiction measure \
demand stereo wedding olive'
TEST_MNEMONIC_12_IDENTITY = 'alcohol woman abuse must during monitor noble \
actual mixed trade anger aisle'
# Seedsigner's own test vectors
# See: https://github.com/SeedSigner/seedsigner/blob/dev/docs/seed_qr/README.md
SEEDSIGNER_MNEMONIC_TEST_VECTORS = [
# 24-word
('attack pizza motion avocado network gather crop fresh patrol unusual wild holiday candy pony \
ranch winter theme error hybrid van cereal salon goddess expire',
'0115132511540127119007710415074212891906200808700266134314202016179206140896192903001524080\
10643',
b'\x0et\xb6A\x07\xf9L\xc0\xcc\xfa\xe6\xa1=\xcb\xec6b\x15O\xecg\xe0\xe0\t\x99\xc0x\x92Y}\x19\n'),
('atom solve joy ugly ankle message setup typical bean era cactus various odor refuse element \
afraid meadow quick medal plate wisdom swap noble shallow',
'0114165509641888007311191572188701560610025619321225144305730036110114051106132920181754119\
71576',
b"\x0eY\xdd\xe2v\x00\x93\x17\xf1'_\x13\x89\x88\x80x\xc9\x93h\xd1\xe8$\x89\xb5\xf6)S\x1f\xc5\
\xb6\xa5n"),
('sound federal bonus bleak light raise false engage round stock update render quote truck \
quality fringe palace foot recipe labor glow tortoise potato still',
'1662067502030188103614170658059415071712190814561408186514010744127307271437099407981836135\
01710',
b'\xcf\xca\x8ce\x8b\xc8\x19bT\x92R\xbcz\xc3\xba[\x0b\x01\xd2k\xca\xe8\x9f+^\xce\xbe&=\xcb*6'),
# 12-word
('forum undo fragile fade shy sign arrest garment culture tube off merit',
'073318950739065415961602009907670428187212261116',
b'[\xbd\x9dq\xa8\xecy\x90\x83\x1a\xff5\x9dBeE'),
('good battle boil exact add seed angle hurry success glad carbon whisper',
'080301540200062600251559007008931730078802752004',
b"dbhd' 3\x85\xc23}\xd8LP\x89\xfd"),
('approve fruit lens brass ring actual stool coin doll boss strong rate',
'008607501025021714880023171503630517020917211425',
b'\n\xcb\xba\x00\x8d\x9b\xa0\x05\xf5\x99k@\xa3G\\\xd9'),
# Potentially Problematic
('dignity utility vacant shiver thought canoe feel multiply item youth actor coyote',
'049619221923158517990268067811630950204300210397',
b'>\x1e\x0b\xc1\xe3\x1e\x0eC\x154\x8bv\xdf\xec\n\x98'),
('corn voice scrap arrow original diamond trial property benefit choose junk lock',
'038719631547010112530489185713790169032209701051',
b'0~\xaf\x05\x86Y\xcazz\rc\x15%\t\xe5A'),
('vocal tray giggle tool duck letter category pattern train magnet excite swamp',
'196218530783182905421028028912901848107106301753',
b'\xf5\\\xf5\x87\xf2T=\x01\t\r\n\xe7\x10\xbd;m'),
]
# Test cases generated with: https://github.com/ethankosakovsky/bip85
GET_BIP85_BIP39_DATA = [
(12, 0, "elephant this puppy lucky fatigue skate aerobic emotion peanut outer clinic casino"),
(12, 12, "prevent marriage menu outside total tone prison few sword coffee print salad"),
(12, 100, "lottery divert goat drink tackle picture youth text stem marriage call tip"),
(12, 65535, "curtain angle fatigue siren involve bleak detail frame name spare size cycle"),
(24, 0,
"certain act palace ball plug they divide fold climb hand tuition inside choose sponsor grass "
"scheme choose split top twenty always vendor fit thank"),
(24, 24,
"flip meat face wood hammer crack fat topple admit canvas bid capital leopard angry fan gate "
"domain exile patient recipe nut honey resist inner"),
(24, 1024,
"phone goat wheel unique local maximum sand reflect scissors one have spin weasel dignity "
"antenna acid pulp increase fitness typical bacon strike spy festival"),
(24, 65535,
"humble museum grab fitness wrap window front job quarter update rich grape gap daring blame "
"cricket traffic sad trade easily genius boost lumber rhythm")
]
# NOTE: the best way to generate test cases is directly in core.
# You need to poke the seed below into the wallet as a base58 wif, as below:
# bitcoin-cli sethdseed true "92zRAmYnWVRrWJ6cQb8yrzEz9r3aXj4oEUiPAZEbiPKHpCnxkKz"
#
# NOTE: if using liquid you also need to import the master-blindingkey (which
# green/wally derives from the seed using slip77, but elements-core does not)
# elements-cli importmasterblindingkey
# "946549f3bb3fc7449a6e86908b3bf1cc19f50cbdd9c1c459632b7624b397aec1"
#
# To generate txns it'll need some funds!
# Get an address and mine over 100 blocks to that address to get some money
# in the wallet. eg:
# bitcoin-cli generatetoaddress 120 2N8Yn3oXF7Pg38yBpuvoheDS7981vW4vy5b (for p2wsh-p2sh),
# mwJDHFp93fuHZysBwU7RTiFXrJZXXcPuUc (p2pkh legacy) or
# bcrt1qkrkcltr7kx5s5alsvnpvkcfunlrjtwx942zmn4 (p2wsh native)
#
TEST_SEED_SINGLE_SIG = 'b90e532426d0dc20fffe01037048c018e940300038b165c211915c672e07762c'
# NOTE: for get-xpub the root (empty path array) can be accessed (to allow
# external creation of watch-only public key tree)
# NOTE: networks 'liquid' and 'mainnet' result in 'xpub' prefix, else 'tpub'
GET_XPUB_DATA = [([], 'testnet', 'tpubD6NzVbkrYhZ4Y6YYLhPsm1vVhs7CDSvoxfTTohcN\
PigN2RkeMJL3gTWav9fCicJsC7eSyARLKi8Q3UU825cz65meRQFFfqTYfBBy3MHC6Vn'),
([], 'mainnet', 'xpub661MyMwAqRbcGJMgtWQnZ6b8Nk1YE4RkR2sAT9ZE\
3ovUH95wH5UxY1qkg7aRC7MdQD7YMauTncJMMHyWdDmkCeKMMoVwzJoK5DbZHHhinUQ'),
([], 'liquid', 'xpub661MyMwAqRbcGJMgtWQnZ6b8Nk1YE4RkR2sAT9ZE3\
ovUH95wH5UxY1qkg7aRC7MdQD7YMauTncJMMHyWdDmkCeKMMoVwzJoK5DbZHHhinUQ'),
([0], 'localtest', 'tpubD9wHvxq4yutRJBbRis4guqLvvAZqppKmMJmqD\
i4HVtVRTRKKTMzomHx77PqcprGZf6UuzwiWn8QWbUx3ECSUStzMHFPJM2e16VUoqEGnkk7'),
([6], 'localtest', 'tpubD9wHvxq4yutRaYSLLTxkMuSGafH6NyQMJeGhq\
sug25o2p9KMNqZAcSV1eYcX31eVXf5vS8MYUPp5Cr2HHAkmpgAHQHa7iG4bqW6ajLq6WVk'),
([12, 123], 'localtest-liquid', 'tpubDBdwuiH7nSNmLs5ffMyv3jXv\
ZrqFgimAbxXvxhWgXWATBTYPjiBbEDRzanF6YBHCaPoMF8XJNJdsUeXZHBuy3tkUSbEYh3o1M6fEfM\
fdBV5'),
([18, 986], 'mainnet', 'xpub6BYx1MizD2XPpY6EuF5Pso8cG5fVHJEWn\
iziGqXcrrcqH96MUiPcuNQkfKSnGx9tCvBJBZx35fiZE3zBbVkZqH89TU4W6HkyE9fSUx9QHNX'),
([2147483651, 2147483648], 'mainnet', 'xpub69w5Svpcz1iNw383Q4\
dcKTH7DVwPinVYL8Ka7S61gskwY8SW4YeeCny4xdxhR9yFhPxGDJ9Yne8PNQFoqkVdUK2whQ9bJiZu\
MarKPtCixrX'),
([2147483651, 2147483651], 'liquid', 'xpub69w5Svpcz1iP4ocLTZ9\
3HDnRkFwKRUomwEZwFuafNnDhTWirvUFxbtou6KQMT83gnyjZAKmsD8oTST6FTj5dgAZn5EP6KMPZw\
QGEQu1tqez'),
([2147483692, 0, 1, 2], 'testnet-liquid', 'tpubDFHUCdwiKzeyST\
BkMyPec9y9VSwwVgn1AftmefpKLYTPrChSCTbHAnbXtSQTB8qEvR8H6nt3sBwNAUeYZK5oc75dWDiY\
WBrYcMRYW2DGU1Z')]
GET_GREENADDRESS_DATA = [('localtest', 0, 1, 345, None, 0, None,
'2MyMy6Ey7a5dmWJW1D9M7RFwjmXD1ECrgy4'),
('testnet', 0, 1, 568, None, 51840, None,
'2MxbBuvnRvgL3uTDtTkufPTdzuwuXE9HCNj'),
('mainnet', 3, 1, 88, '', 0, None,
'36kTtrBFR5NQmzBxAuNWcmLk22WsuhRq2S'),
('mainnet', 0, 1, 568, 'xpub6BYx1MizD2XPpY6EuF5Pso8cG\
5fVHJEWniziGqXcrrcqH96MUiPcuNQkfKSnGx9tCvBJBZx35fiZE3zBbVkZqH89TU4W6HkyE9fSUx9\
QHNX', 0, None, '338M4PG24m1gZggrzQV1s9vr3dZZ31kLsU'),
('localtest-liquid', 6, 1, 345, None, 65535, None,
'Azpx2UGRpzEQ6pt6yCbPYGnjqNaTtxN2ZdLmMMjWMVvJdzd5uD9\
cysaRc4Es5auve68RAwijQqReG3AT'),
('testnet-liquid', 3, 1, 244, None, 65535, None,
'vjU6NdME2viTa8BzBA6qNG5jQKLfGfLvC93f4fRwZ9SR4pE7KBW\
QNbGUi2bodfxiMACFDombViiC5Vej'),
('liquid', 10, 1, 122, None, 65535, None,
'VJLGotGqjthW3NY7JFZ7EaJZo8rnuRi23waPVY7FwJTYxtFNrNL\
y6CC4VEQoKRmd5VkL2mmuo64LfZNy'),
# Jade can generate non-confidential addresses also
('testnet-liquid', 0, 1, 9, None, 65535, None,
'vjTzk5t4D8J3j73rt2QWsD9UMSs28KcNnYSGovgGBKcpfHpihSz\
5bsMmUNAkdohYRHXPztnqgZqaLgEk'),
('testnet-liquid', 0, 1, 9, None, 65535, True,
'vjTzk5t4D8J3j73rt2QWsD9UMSs28KcNnYSGovgGBKcpfHpihSz\
5bsMmUNAkdohYRHXPztnqgZqaLgEk'),
('testnet-liquid', 0, 1, 9, None, 65535, False,
'8z6YuTaMWRf4UeqAGKmQ64Bi4wPWtw7pqm')]
GET_SINGLE_SIG_ADDR_DATA = [ # The below were generated on core
('localtest', 'sh(wpkh(k))', None,
[2147483648, 2147483648, 2147483657],
'2N8Yn3oXF7Pg38yBpuvoheDS7981vW4vy5b'),
('localtest', 'wpkh(k)', None,
[2147483648, 2147483648, 2147483658],
'bcrt1qkrkcltr7kx5s5alsvnpvkcfunlrjtwx942zmn4'),
('localtest', 'pkh(k)', None,
[2147483648, 2147483648, 2147483659],
'mwJDHFp93fuHZysBwU7RTiFXrJZXXcPuUc'),
# And these on elements ...
('localtest-liquid', 'sh(wpkh(k))', None,
[2147483648, 2147483648, 2147483649],
'AzpnFQq17AnWm4gvL2oHLRucFawmq8VWFyaxfPX3EgrihEdw\
DXWmb1QmA7QrRu5RCy3wDtSe8h9WxKbQ'),
('localtest-liquid', 'wpkh(k)', None,
[2147483648, 2147483648, 2147483650],
'el1qqwud2rtjxwgfxc9wrey504mtjqujrmzsc442zway65gk\
uj2f0mm4xfv8h3sqfz223jxjrj307zyqln2dywxmsvpvs9x2tvufj'),
('localtest-liquid', 'pkh(k)', None,
[2147483648, 2147483648, 2147483651],
'CTEuAWMSL94hM2PbTzoe8TGLjyVkkSgdPFas7eUMouiGk5Q2\
SfzadGnGduPwvoVK1ZpthykJup8A8Eh2'),
# The below are 'speculative' ...
('mainnet', 'sh(wpkh(k))', None,
[2147483648, 2147483648, 2147483657],
'3GzZz4bDVwAgwBZHEoBq2GSqvmokj9e4Jx'),
('mainnet', 'wpkh(k)', None,
[2147483648, 2147483648, 2147483657],
'bc1qpky3r9yuz5gguvuqkrf2dfqtqgutr9evgnjmq6'),
('mainnet', 'pkh(k)', None,
[2147483648, 2147483648, 2147483657],
'12EZzC9ck31rxaFYKbGwVj1gYXsUwfHuWj'),
('testnet', 'sh(wpkh(k))', None,
[2147483648, 2147483648, 2147483657],
'2N8Yn3oXF7Pg38yBpuvoheDS7981vW4vy5b'),
('testnet', 'wpkh(k)', None,
[2147483648, 2147483648, 2147483657],
'tb1qpky3r9yuz5gguvuqkrf2dfqtqgutr9evz4fgmf'),
('testnet', 'pkh(k)', None,
[2147483648, 2147483648, 2147483657],
'mgkXHFEbZ4T7jgjA3AFKKeE1QXUBrX7qQC'),
('liquid', 'sh(wpkh(k))', None,
[2147483648, 2147483648, 2147483657],
'VJLGcUjN2q6HHuNUAQJ2LEASQnr5LkD2DgDwT2vcyQjKhA3B\
5a2VAgp94Gj5rSXYiD6eHmGJmVSHY5xG'),
('testnet-liquid', 'wpkh(k)', None,
[2147483648, 2147483648, 2147483657],
'tlq1qq28n8pj790vsyd6t5lr6n0puhrp7hd8wvcgrlm8knxm\
684lxq6pzjrvfzx2fc9gs3cecpvxj56jqkq3ckxtjc88gqxa6j2cv7'),
# Jade can generate non-confidential addresses also
('localtest-liquid', 'pkh(k)', None,
[2147483648, 2147483648, 2147483657],
'CTEjtdpkvj7mrGtgMTrmDfSnH9DdN9Rzi2tzsxsFNujSU8qh\
YzNnQaWx24j5hX8iWcaZgTZJ6Y3sedLi'),
('localtest-liquid', 'pkh(k)', True,
[2147483648, 2147483648, 2147483657],
'CTEjtdpkvj7mrGtgMTrmDfSnH9DdN9Rzi2tzsxsFNujSU8qh\
YzNnQaWx24j5hX8iWcaZgTZJ6Y3sedLi'),
('localtest-liquid', 'pkh(k)', False,
[2147483648, 2147483648, 2147483657],
'2dafKNiCKbRum9S1u5BYqTByZT5R9zSqcWy')]
# Hold test data in separate files as can be large
QR_QVGA_SCAN_TESTS = "qr_qvga_*.json"
QR_VGA_SCAN_TESTS = "qr_vga_*.json"
MULTI_REG_TESTS = "multisig_reg_*.json"
MULTI_REG_SS_TESTS = "multisig_reg_ss_*.json"
MULTI_REG_FILE_TESTS = "multisig_file_*.json"
MULTI_REG_BAD_FILE_TESTS = "multisig_bad_file_*.json"
DESCRIPTOR_REG_SS_TESTS = "descriptor_ss_*.json"
SIGN_MSG_TESTS = "msg_*.json"
SIGN_MSG_FILE_TESTS = "msgfile_*.json"
SIGN_IDENTITY_TESTS = "identity_*.json"
SIGN_TXN_TESTS = "txn_*.json"
SIGN_TXN_FAIL_CASES = "badtxn_*.json"
SIGN_LIQUID_TXN_TESTS = "liquid_txn_*.json"
SIGN_TXN_SINGLE_SIG_TESTS = "singlesig_txn*.json"
SIGN_LIQUID_TXN_SINGLE_SIG_TESTS = "singlesig_liquid_txn*.json"
SIGN_PSBT_TESTS = "psbt_tm_*.json"
SIGN_PSBT_SS_TESTS = "psbt_ss_*.json"
TEST_SCRIPT = h2b('76a9145f4fcd4a757c2abf6a0691f59dffae18852bbd7388ac')
EXPECTED_MASTER_BLINDING_KEY = h2b('afacc503637e85da661ca1706c4ea147f1407868c4\
8d8f92dd339ac272293cdc')
EXPECTED_BLINDING_KEY = h2b('023454c233497be73ed98c07d5e9069e21519e94d0663375c\
a57c982037546e352')
TEST_THEIR_PK = h2b('03e7cd9230b30bf53753a43add0e88931bac3be21baa4c6465d9f8da9\
251f2904c')
EXPECTED_SHARED_SECRET = h2b('35801ebd1e62e8698490440861cff2e5bd10cf4aec19b51f\
8ccc7dc910a7e488')
TEST_HASH_PREVOUTS_HEX = '95f17695f6329dbcce2aa0b7f1eaff823b19d64d8737d642d6e6\
147f5ec88342'
TEST_HASH_PREVOUTS = h2b(TEST_HASH_PREVOUTS_HEX)
TEST_REGTEST_BITCOIN = h2b('5ac9f65c0efcc4775e0baec4ec03abdde22473cd3cf33c0419\
ca290e0751b225')
EXPECTED_LIQ_COMMITMENT_1 = {'abf': h2b('42bc9c7025f3df490a208cb362ff220547910\
da1d3e81c63a6e7c28c3a33a993'),
'vbf': h2b('7a6693fde7b88efb8375db618670fb5ccb9b2\
f7e8743b7d772924f0426c5efe6'),
'asset_generator': h2b('0a5cf0a43ad404163946c28b8\
a36d0e5cb4895b0ee386da4cd1008ffc8cb464501'),
'value_commitment': h2b('082d8de9b7f66994abf789b2\
591738331f88a7ddbef4e553bbf123e47677d60099'),
'asset_id': h2b('5ac9f65c0efcc4775e0baec4ec03abdd\
e22473cd3cf33c0419ca290e0751b225'),
'value': 9000000}
EXPECTED_LIQ_COMMITMENT_2 = {'abf': h2b('a3510210bbab6ed67429af9beaf42f09382e1\
2146a3db466971b58a45516bba0'),
'vbf': h2b('6ec064a68075a278bfca4a10f777c730116e9\
ba02fbb343a237c847e4d2fbf53'),
'asset_generator': h2b('0abd23178d9ff73cf848d8d88\
a7c7e269a464f53017cab0f9f53ed9d64b2849713'),
'value_commitment': h2b('094d9a00f1661a2a805a8afe\
c9c188310d4c43353cc319886ee4d9f439389d8f43'),
'asset_id': h2b('5ac9f65c0efcc4775e0baec4ec03abdd\
e22473cd3cf33c0419ca290e0751b225'),
'value': 9000000}
SIGN_IDENTITY_DATA = [
# challenge, identity, index, curve, slip13 pubkey, signature prefixed 0x00, slip17 pubkey
# First test case copied from:
# https://github.com/trezor/trezor-firmware/blob/a3c79bf4f7393386d23fe92210c7bce4d1049280
# /tests/device_tests/misc/test_msg_signidentity.py#L75
# NOTE: slight differnece as we return the *uncompressed* pubkey
# THIS IS THE ONE TRUE TEST (except the ecdh pubkey, which is unverified)
('cd8552569d6e4509266ef137584d1e62c7579b5b8ed69bbafa4b864c6521e7c2',
'ssh://[email protected]', 47, 'nist256p1',
'0473f21a3da3d0e96fc2189f81dd826658c3d76b2d55bd1da349bc6c3573b13ae4d56471\
0ca0bf84b81c6850e916cb94ae9c397b550589da476ace7aee39ebcb37',
'005122cebabb852cdd32103b602662afa88e54c0c0c1b38d7099c64dcd49efe908288114\
e66ed2d8c82f23a70b769a4db723173ec53840c08aafb840d3f09a18d3',
'04248befa95e9dbcf0a2ef7cf6957651ee25a168355590c4c84a6a8601758ca230d397bc\
ba67b4676c3f2711b59083fff9157c16899da6d4ed76f8eaf57a100fa8'
),
# These are 'speculative', just to cover a few more cases for regressions
# ssh
('c16e1456df150491c50722a9d02fa04c74ef065a94f1936f7db029f71138c239',
'ssh://[email protected]', 112, 'nist256p1',
'04a88f160249fd794bdb12fc56896e8dac6bf5e72e33960e2a7d11252f6a93ef28fa183f\
3eca7ac84aa0d2e1488f281dbe4af394fcbeda3ab368e7fe98fc25f16f',
'00d0472ffa6a6b0075b71a60c7abd3faf9f6d49b7bb86bace344e23c68b888ebc273d48b\
62b4af70f2ad1ca213f6886e26d74d31cfbbd7f4ac917af4d243939813',
'04ae7218d72039060c69cf50a17698cfe157905e859d7570663c57099e6cf2946be4f6a3\
11f4c3f349b70edea7a8e18b2c2d354811bc5836c713784f72d4d4c201'
),
('ff732d6499071333f13170d2184054b6dffc1296ca43cb1599a68cea65071e6f',
'ssh://[email protected]', 3754, 'nist256p1',
'0434e451e9bc1bdba24654822277f5960f42cf6d0375629813d41476c499d62f7d971174\
0406834034958b7782ef743b295530e580bd68a1a1ad3de8b6a141c4c0',
'00ce030c73249ac7b53184c7987917f00c290ad3b5617c1c0f0465ff150035a46b288766\
c8594e7f574778402c4df5085bfc0642240200ddbe01c0ec9cd2b46a55',
'04d0ea80cef5fc83d7ac73ae7f33deff8d3b46641d021145cd0d51acf535daa212541315\
630d9e3f99f3adbb652f2178ed7b8190503a3df57dac03c0f9c0ad1d88'
),
# gpg
('bcfc224438bd07742c4a3ad6db530e3f071f93645728e9f69eaee21c2f4ed54a',
'gpg://GreenAddress <[email protected]>', 0, 'nist256p1',
'04741f65f95543b6de0ccfcdc13016e573df52fca14b2b15fd3142930bc4d871cc6375a5\
5e402911d873332b8610f73a4020676462c498268a94434a00bca9691e',
'00010f560db262ee2d82b0032a858d72bb5d927563743af55b3c8514f4c3e353e233e363\
7c172b60b40a48f0c19117ddbd6fc15dcb936430087a86c4db139caa97',
'0425d63b5f4c41af1d8bee7f6419c28e3d39ec637aef1d5694b008cbc03509c8349f290b\
5937e53105f1aaf613bcf6c72b486015546ee08e7d83412f51f94a6e2a'
),
('fa94545d4f18e4cc4655c87869fc8a790a07eb58a3e5b599ab9f7da6d8ab5061',
'gpg://Jade <[email protected]>', 0, 'nist256p1',
'041127ef35e4690ff035e13ebab340ab3fa2327c0409bbed3dbf03b8932777d929bd8ade\
43e3ebceb9fc74c23a32cd0e380d9b529a70ee0e83763e0c7af5f0bb1f',
'000118565f7363337ad72a1c497a1e1de5d336a99b09af8c49b36518e925a0ca517dafff\
b2e95dc777c4d7df504ced12fd668f81a11d14d30033831df1434b59d7',
'043ede5aad3f3171b495b68da5c36d35eb724e4cb3beafa08b529830bf7679b955730684\
7b8f392c6288ce45565c3133301811f5dcfa6e216e4ae2397e22603e52'
)
]
# The tests
def test_bad_message(jade):
bad_requests = [{'method': 'get_version_info'}, # no-id
{'id': '2'}, # no method
{'id': 123}, # bad id type
{'id': '12345'*8}, # id too long
{'method': 'x'*40, 'id': '4'}] # method
for request in bad_requests:
msgbytes = cbor.dumps(request)
jade.write(msgbytes)
# Expect one reject message for the bad (but well formed) input
reply = jade.read_response()
# Returned id should match sent and valid, or '00' if not
assert 'id' in reply
if 'id' in request and \
isinstance(request['id'], str) and \
len(request['id']) < 32:
assert reply['id'] == request['id'] # matches
else:
assert reply['id'] == '00' # default error id
# Assert bad message response
assert 'result' not in reply
error = reply['error']
assert error['code'] == JadeError.INVALID_REQUEST
assert error['message'] == 'Invalid RPC Request message'
assert int(error['data']) == len(msgbytes)
assert 'result' not in reply
def test_very_bad_message(jade):
empty = cbor.dumps(b"")
text = cbor.dumps("This is not a good cbor message")
truncated = cbor.dumps("{'id': '1', method: 'msgwillbecut'}")[1:]
goodmsg = jade.build_request('ent', 'add_entropy', {'entropy': 'noise'.encode()})
for badmsg in [empty, text, truncated]:
# Send the bad message, and after a pause a good message
jade.write(badmsg)
time.sleep(3)
jade.write_request(goodmsg)
# We should receive a bag of errors
# NOTE: we cannot be sure how many messages will be returned exactly,
# but we do know that Jade should reject a total of 'len(badmsg)' bytes.
bad_bytes = 0
while bad_bytes < len(badmsg):
reply = jade.read_response()
# Returned id should be '00'
assert reply['id'] == '00'
assert 'result' not in reply
# Assert bad message response
error = reply['error']
assert error['code'] == JadeError.INVALID_REQUEST
assert error['message'] == 'Invalid RPC Request message'
bad_bytes += int(error['data'])
assert bad_bytes == len(badmsg)
# After the bad bytes have been rejected, we expect to see the reply to the good message
reply = jade.read_response()
assert reply['id'] == 'ent'
assert 'error' not in reply
assert 'result' in reply
assert reply['result'] is True
def test_random_bytes(jade):
# Stream up 1k of random bytes, then a good message after a short pause
# NOTE: use fixed pseudo-random here, so test run is reproducible
random.seed(12345678, 2)
nsent = 0
for _ in range(8):
noise = random.getrandbits(128*8).to_bytes(128, 'little')
jade.write(noise)
nsent += len(noise)
time.sleep(5)
goodmsg = jade.build_request('goodmsg', 'add_entropy', {'entropy': 'somebytes'.encode()})
jade.write_request(goodmsg)
# We should receive a bag of errors
# NOTE: we cannot be sure how many messages will be returned exactly,
# but we do know that Jade should reject a total of 'nsent' bytes.
nreceived = 0
while nreceived < nsent:
# Expect error - count rejected bytes
reply = jade.read_response()
error = reply['error']
assert error['code'] == JadeError.INVALID_REQUEST
assert error['message'] == 'Invalid RPC Request message'
nreceived += int(error['data'])
assert nreceived == nsent
# After the bad bytes have been rejected, we expect to see the reply to the good message
reply = jade.read_response()
assert reply['id'] == 'goodmsg'
assert 'error' not in reply
assert 'result' in reply
assert reply['result'] is True
def test_too_much_input(jade, has_psram):
noise = 'long'.encode() # 4b
cacophony = noise * 4096 # 16k
# NOTE: if the hw has PSRAM it will have a 401k buffer.
# If not, it will have a 17k buffer. Want only 1k left.
# Send the appropriate amount of noise. (400k or 16k)
if has_psram:
cacophony = cacophony * 25 # 25x16 is 400k
# Input buffer would now only have 1k space remaining.
# Add another 1k to fill the buffer
cacophony += noise * 256 # 1k
expected_buffer_size = len(cacophony)
# Then add another 64b to overflow
extra = noise * 16 # 64b
cacophony += extra
# Format as a cbor message, otherwise it gets rejected early, as soon
# as the parser decides the bytes it has are not a valid message.
# See: test_very_bad_message() above.
# Adjust the expected_overflow_len for the cbor overhead
big_msg = cbor.dumps({'method': 'toobig', 'id': 'tohandle', 'params': cacophony})
# Send the message up with 4k writes
# (as if trying to write too much can hit the timeout)
total_len = len(big_msg)
expected_overflow_len = total_len - expected_buffer_size
remaining = total_len
while remaining:
tosend = min(remaining, 4096)
jade.write(big_msg[total_len - remaining: (total_len - remaining) + tosend])
remaining -= tosend
# First we expect to get a response about the buffer-overflow bytes
# ie. one (initial) reject message with a big number in!
reply = jade.read_response()
error = reply['error']
assert error['code'] == JadeError.INVALID_REQUEST
assert error['message'] == 'Invalid RPC Request message'
assert int(error['data']) == expected_buffer_size
# After a short pause send a good message
time.sleep(5)
goodmsg = jade.build_request('trailer', 'add_entropy', {'entropy': 'random'.encode()})
jade.write_request(goodmsg)
# We should then receive a bag of errors
# NOTE: we cannot be sure how many messages will be returned exactly,
# but we do know that Jade should reject a total of 'expected_overflow_len' bytes.
bad_bytes = 0
while bad_bytes < expected_overflow_len:
# Expect error - collect bad bytes
reply = jade.read_response()
error = reply['error']
assert error['code'] == JadeError.INVALID_REQUEST
assert error['message'] == 'Invalid RPC Request message'
bad_bytes += int(error['data'])
assert bad_bytes == expected_overflow_len
# After the bad bytes have been rejected, we expect to see the reply to the good message
reply = jade.read_response()
assert reply['id'] == 'trailer'
assert 'error' not in reply
assert 'result' in reply
assert reply['result'] is True
def test_split_message(jade):
# Simulate transport stream being v.slow
msg = cbor.dumps({'method': 'get_version_info', 'id': '24680'})
for msgpart in [msg[:5], msg[5:10], msg[10:]]:
jade.write(msgpart)
time.sleep(0.25)
reply = jade.read_response()
# Returned id should match sent
assert reply['id'] == "24680"
assert 'error' not in reply
assert 'result' in reply and len(reply['result']) == NUM_VALUES_VERINFO
def test_concatenated_messages(jade):
# Simulate a 'bad' client sending two messages without waiting for a reply
msg1 = {'method': 'get_version_info', 'id': '123456'}
msg2 = {'method': 'get_version_info', 'id': '456789'}
concat_cbor = cbor.dumps(msg1) + cbor.dumps(msg2)
jade.write(concat_cbor)
reply1 = jade.read_response()
reply2 = jade.read_response()
# Returned ids should match sent
for msg, reply in [(msg1, reply1), (msg2, reply2)]:
assert reply['id'] == msg['id']
assert 'error' not in reply
assert 'result' in reply and len(reply['result']) == NUM_VALUES_VERINFO
def test_unknown_method(jade):
# Includes tests of method prefixes 'get...' and 'sign...'
for msgid, method in [('unk0', 'dostuff'), ('unk1', 'get'), ('unk2', 'sign'),
('unk3', 'handshake_init')]:
request = jade.build_request(msgid, method,
{'path': (0, 1, 2, 3, 4),
'message': 'Jade is cool'})
reply = jade.make_rpc_call(request)
# Returned id should match sent
assert reply['id'] == msgid
# Assert unknown method response
error = reply['error']
assert error['code'] == JadeError.UNKNOWN_METHOD
assert error['message'] == 'Unknown method'
assert 'result' not in reply
def test_unexpected_method(jade):
# These messages are only expected as a subsequent message
# in a multi-message protocol.
unexpected = [('protocol2', 'pin',
{'payload': 'abcdef', 'hmac': '1234'}),
('protocol3', 'ota_data', h2b('abcdef')),
('protocol4', 'ota_complete'),
('protocol5', 'tx_input'),
('protocol6', 'get_signature'),
('protocol7', 'get_extended_data')]
for args in unexpected:
request = jade.build_request(*args)
reply = jade.make_rpc_call(request)
# Assert protocol-error/unexpected-method response
error = reply['error']
assert error['code'] == JadeError.PROTOCOL_ERROR
assert error['message'] == 'Unexpected method'
assert 'result' not in reply
def _test_good_params(jade, args):
request = jade.build_request(*args)
reply = jade.make_rpc_call(request)
# Assert all-good response
assert reply['id'] == request['id']
assert 'error' not in reply
assert 'result' in reply
return reply['result']
def _test_bad_params(jade, args, expected_error):
request = jade.build_request(*args)
reply = jade.make_rpc_call(request)
# Assert bad-parameters response
assert reply['id'] == request['id']
assert 'result' not in reply
assert 'error' in reply
error = reply['error']
assert error['code'] == JadeError.BAD_PARAMETERS
assert 'message' in error
assert expected_error in error['message']
return error['message']
def test_bad_params(jade):
GOODTX = h2b(
'02000000010f757ae0b5714cb36e017dfffafe5f3ba8c89ddb969a0ae60d99ee\
7b5892a2740000000000ffffffff01203f0f00000000001600145f4fcd4a757c2abf6a0691f59d\
ffae18852bbd7300000000')
MULTI_COSIGNERS = [
{
"fingerprint": h2b("1273da33"),
"derivation": [44, 2147483648, 2147483648],
"xpub": "tpubDDCNstnPhbdd4vwbw5UWK3vRQSF1WXQkvBHpNXpKJAkwFYjwu735EH3\
GVf53qwbWimzewDUv68MUmRDgYtQ1AU8FRCPkazfuaBp7LaEaohG",
"path": [3, 1]
},
{
"fingerprint": h2b("e3ebcc79"),
"derivation": [2147483651, 2147483649, 1],
"xpub": "tpubDDExQpZg2tziZ7ACSBCYsY3rYxAZtTRBgWwioRLYqgNBguH6rMHN1D8\
epTxUQUB5kM5nxkEtr2SNic6PJLPubcGMR6S2fmDZTzL9dHpU7ka",
"path": [1]
}
]
# Default test user is cosigners[1]
bad_multi_cosigners1 = copy.deepcopy(MULTI_COSIGNERS)
bad_multi_cosigners1[1]['fingerprint'] = h2b("abcdef")
bad_multi_cosigners2 = copy.deepcopy(MULTI_COSIGNERS)
bad_multi_cosigners2[1]['fingerprint'] = bad_multi_cosigners2[0]['fingerprint']
bad_multi_cosigners3 = copy.deepcopy(MULTI_COSIGNERS)
bad_multi_cosigners3[1]['derivation'] = [1, 2, 3, 4]
bad_multi_cosigners4 = copy.deepcopy(MULTI_COSIGNERS)
bad_multi_cosigners4[1]['path'] = [2147483648]
bad_multi_cosigners5 = copy.deepcopy(MULTI_COSIGNERS)
bad_multi_cosigners5[1]['xpub'] = bad_multi_cosigners2[0]['xpub']
bad_multi_cosigners6 = copy.deepcopy(MULTI_COSIGNERS)
bad_multi_cosigners6[0]['xpub'] = bad_multi_cosigners6[0]['xpub'].replace('D', 'E', 1)
DESCRIPTOR = 'wsh(pkh(@0/<0;1>/*))'
DESCR_SIGNER = "[e3ebcc79/48'/1'/0'/2']tpubDDvj9CrVJ9kWXSL2kjtA8v53rZvTmL3\
HmWPvgD3hiTnD5KZuMkxSUsgGraZ9vavB5JSA3F9s5E4cXuCte5rvBs5N4DjfxYssQk1L82Bq4FE"
bad_descr_signer1 = '[abcdef' + DESCR_SIGNER[DESCR_SIGNER.find('/'):]
bad_descr_signer2 = '[1273da33' + DESCR_SIGNER[DESCR_SIGNER.find('/'):]
bad_descr_signer3 = '[e3ebcc79/1/2/3/4' + DESCR_SIGNER[DESCR_SIGNER.find(']'):]
trezor_id_test = list(_get_test_cases('identity_ssh_nist_matches_trezor.json'))
assert len(trezor_id_test) == 1
GOOD_ECDH_PUBKEY = trezor_id_test[0]['expected_output']['slip-0017']
bad_params = [(('badauth1', 'auth_user'), 'Expecting parameters map'),
(('badauth2', 'auth_user', {'network': None}), 'extract valid network'),
(('badauth3', 'auth_user', {'network': 1234512345}), 'extract valid network'),
(('badauth4', 'auth_user', {'network': ''}), 'extract valid network'),
(('badauth5', 'auth_user', {'network': 'notanetwork'}), 'extract valid network'),
(('badauth6', 'auth_user', {'network': 'testnet', 'epoch': 'notanumber'}),
'valid epoch value'),
(('badauth7', 'auth_user', {'network': 'testnet', 'epoch': 12345.6789}),
'valid epoch value'),
(('badpin1', 'update_pinserver'), 'Expecting parameters map'),
(('badpin2', 'update_pinserver',
{'urlA': ''}), 'invalid first URL'),
(('badpin3', 'update_pinserver',
{'urlA': '192.168.1.123'}), 'invalid first URL'),
(('badpin4', 'update_pinserver',
{'urlA': 'ftp://192.168.1.123'}), 'invalid first URL'),
(('badpin5', 'update_pinserver',
{'urlA': 'http://192.168.1.123', 'urlB': 'testurl.com:8080'}),
'Invalid second URL'),
(('badpin6', 'update_pinserver',
{'urlA': 'http://192.168.1.123', 'urlB': 'madeup://testurl.com:8080'}),
'Invalid second URL'),
(('badpin7', 'update_pinserver',
{'urlB': 'https://192.168.1.124'}), 'set only second URL'),
(('badpin8', 'update_pinserver',
{'urlA': 'http://192.168.1.123', 'urlB': 'https://192.168.1.124',
'reset_details': True}), 'set and reset details'),
(('badpin9', 'update_pinserver',
{'pubkey': h2b('abc123'), 'reset_details': True}), 'set and reset details'),
(('badpin10', 'update_pinserver',
{'pubkey': h2b('abcdef')}), 'set pubkey without URL'),
(('badpin11', 'update_pinserver',
{'urlA': 'http://192.168.1.123', 'urlB': 'https://192.168.1.124',
'pubkey': h2b('abcdef1234')}), 'Invalid Oracle pubkey'),
(('badpin12', 'update_pinserver',
{'certificate': 'testcert', 'reset_certificate': True}),
'set and reset certificate'),
(('badent1', 'add_entropy'), 'Expecting parameters map'),
(('badent2', 'add_entropy', {'entropy': None}), 'valid entropy bytes'),
(('badent3', 'add_entropy', {'entropy': 1234512345}), 'valid entropy bytes'),
(('badent4', 'add_entropy', {'entropy': b''}), 'valid entropy bytes'),
(('badent5', 'add_entropy', {'entropy': 'notbinary'}), 'valid entropy bytes'),
(('badepoch1', 'set_epoch'), 'Expecting parameters map'),
(('badepoch2', 'set_epoch', {'epoch': None}), 'valid epoch value'),
(('badepoch3', 'set_epoch', {'epoch': ''}), 'valid epoch value'),
(('badepoch4', 'set_epoch', {'epoch': 'notinteger'}), 'valid epoch value'),
(('badepoch5', 'set_epoch', {'epoch': 12345.6789}), 'valid epoch value'),
(('badota1', 'ota'), ''),
(('badota2', 'ota', {'fwsize': 12345}), 'Bad filesize parameters'),
(('badota3', 'ota',
{'fwsize': '1234', 'cmpsize': '123'}), 'Bad filesize parameters'),
(('badota4', 'ota',
{'fwsize': 'X', 'cmpsize': 'Y'}), 'Bad filesize parameters'),
(('badota5', 'ota', # compsize >= fwsize rejected
{'fwsize': 1234, 'cmpsize': 1234}), 'Bad filesize parameters'),
(('badota6', 'ota', # hash unexpected size
{'fwsize': 1234, 'cmpsize': 1111, 'cmphash': b'123'}), 'extract valid fw hash'),
(('badota_delta1', 'ota_delta'), ''),
(('badota_delta2', 'ota_delta', {'fwsize': 12345}), 'Bad filesize parameters'),
(('badota_delta3', 'ota_delta',
{'fwsize': '1234', 'cmpsize': '123'}), 'Bad filesize parameters'),
(('badota_delta4', 'ota_delta',
{'fwsize': 'X', 'cmpsize': 'Y'}), 'Bad filesize parameters'),
(('badota_delta5', 'ota_delta', # compsize >= fwsize rejected
{'fwsize': 1234, 'cmpsize': 1234}), 'Bad filesize parameters'),
(('badota_delta6', 'ota_delta', # hash unexpected size
{'fwsize': 1234, 'cmpsize': 1111,
'patchsize': 1200, 'cmphash': b'123'}), 'extract valid fw hash'),
(('badxpub1', 'get_xpub'), 'Expecting parameters map'),
(('badxpub2', 'get_xpub',
{'notpath': 'X', 'network': 'testnet'}), 'extract valid path'),
(('badxpub3', 'get_xpub',
{'path': 'X', 'network': 'testnet'}), 'extract valid path'),
(('badxpub4', 'get_xpub',
{'path': None, 'network': 'testnet'}), 'extract valid path'),
(('badxpub5', 'get_xpub',
{'path': '', 'network': 'testnet'}), 'extract valid path'),
(('badxpub6', 'get_xpub',
{'path': [None], 'network': 'testnet'}), 'extract valid path'),
(('badxpub7', 'get_xpub',
{'path': ['123', '456'], 'network': 'testnet'}), 'extract valid path'),
(('badxpub8', 'get_xpub',
{'path': ['X', 'Y', 'Z'], 'network': 'testnet'}), 'extract valid path'),
(('badxpub9', 'get_xpub', # path too long
{'path': [0, 1, 2] * 6, 'network': 'testnet'}), 'extract valid path'),
(('badxpub10', 'get_xpub', # path value too large
{'path': [0xFFFFFFFF + 1], 'network': 'testnet'}), 'extract valid path'),
(('badxpub11', 'get_xpub', {'path': [1, 2, 3]}), 'valid network'),
(('badxpub12', 'get_xpub', # network missing or invalid
{'path': [], 'network': 'invalid'}), 'valid network'),
(('badxpub13', 'get_xpub', # network missing or invalid
{'path': [1, 2, 3], 'network': 'invalid'}), 'valid network'),
(('badgetmulti1', 'get_registered_multisig'), 'Expecting parameters map'),
(('badgetmulti2', 'get_registered_multisig',
{'multisig_name': 'notsobad', 'as_file': 'not bool'}),
'Failed to extract valid as_file parameter'),
(('badgetmulti3', 'get_registered_multisig', {'multisig_name': None}),
'invalid multisig name'),
(('badgetmulti4', 'get_registered_multisig', {'multisig_name': 'space is bad'}),
'invalid multisig name'),
(('badgetmulti5', 'get_registered_multisig',
{'multisig_name': 'excessivelylong1'}), 'invalid multisig name'),
(('badgetmulti6', 'get_registered_multisig', {'multisig_name': 'noexist'}),
'does not exist for this signer'),
(('badmulti1', 'register_multisig'), 'Expecting parameters map'),
(('badmulti2', 'register_multisig',
{'network': 'testnet', 'multisig_name': None}), 'invalid multisig name'),
(('badmulti3', 'register_multisig',
{'network': 'testnet', 'multisig_name': 'space is bad'}),
'invalid multisig name'),
(('badmulti4', 'register_multisig',
{'network': 'testnet',
'multisig_name': 'excessivelylong1'}), 'invalid multisig name'),
(('badmulti5', 'register_multisig',
{'network': 'testnet',
'multisig_name': 'test'}), 'extract multisig descriptor'),
(('badmulti6', 'register_multisig',
{'network': 'testnet', 'multisig_name': 'test', 'descriptor': {
'threshold': 2, 'signers': []}}), 'Invalid script variant'),
(('badmulti7', 'register_multisig',
{'network': 'testnet', 'multisig_name': 'test', 'descriptor': {
'variant': 'pkh(k)', 'threshold': 2, 'signers': []}}),
'Invalid script variant'),
(('badmulti8', 'register_multisig',
{'network': 'testnet', 'multisig_name': 'test', 'descriptor': {
'variant': 'wsh(multi(k))', 'sorted': 'Yes', 'threshold': 2, 'signers': []}}),
'Invalid sorted flag value'),
(('badmulti9', 'register_multisig',
{'network': 'testnet', 'multisig_name': 'test', 'descriptor': {
'variant': 'wsh(multi(k))', 'signers': []}}), 'Invalid multisig threshold'),
(('badmulti10', 'register_multisig',