diff --git a/core/tests/common.py b/core/tests/common.py index 539f625cfb..349f65f8dd 100644 --- a/core/tests/common.py +++ b/core/tests/common.py @@ -10,6 +10,7 @@ from typing import Any, Awaitable from trezor import utils # noqa: F401 from apps.common.paths import HARDENED + def H_(x: int) -> int: """ Shortcut function that "hardens" a number in a BIP44 path. diff --git a/core/tests/mock_storage.py b/core/tests/mock_storage.py index 29eef8715b..0b8cb31f77 100644 --- a/core/tests/mock_storage.py +++ b/core/tests/mock_storage.py @@ -2,6 +2,7 @@ from mock import patch import storage.common + class MockStorage: PATCH_METHODS = ("get", "set", "delete") diff --git a/core/tests/production_tests/main.py b/core/tests/production_tests/main.py index 90f106e74d..bec08bb2f0 100644 --- a/core/tests/production_tests/main.py +++ b/core/tests/production_tests/main.py @@ -34,17 +34,17 @@ sbu = io.SBU() def test_display(colors): d.clear() m = { - 'R': 0xF800, - 'G': 0x07E0, - 'B': 0x001F, - 'W': 0xFFFF, + "R": 0xF800, + "G": 0x07E0, + "B": 0x001F, + "W": 0xFFFF, } w = 240 // len(colors) for i, c in enumerate(colors): c = m.get(c, 0x0000) d.bar(i * w, 0, i * w + w, 240, c) d.refresh() - print('OK') + print("OK") def test_touch(v): @@ -68,14 +68,22 @@ def test_touch(v): touch = False while True: if not touch: - if io.poll([io.TOUCH], r, 10000) and r[0] == io.TOUCH and r[1][0] == io.TOUCH_START: + if ( + io.poll([io.TOUCH], r, 10000) + and r[0] == io.TOUCH + and r[1][0] == io.TOUCH_START + ): touch = True else: - if io.poll([io.TOUCH], r, 10000) and r[0] == io.TOUCH and r[1][0] == io.TOUCH_END: - print(f'OK {r[1][1]} {r[1][2]}') + if ( + io.poll([io.TOUCH], r, 10000) + and r[0] == io.TOUCH + and r[1][0] == io.TOUCH_END + ): + print(f"OK {r[1][1]} {r[1][2]}") break if utime.ticks_us() > deadline: - print('ERROR TIMEOUT') + print("ERROR TIMEOUT") break # flush all events while io.poll([io.TOUCH], r, 10000): @@ -87,7 +95,7 @@ def test_touch(v): def test_pwm(v): d.backlight(int(v)) d.refresh() - print('OK') + print("OK") def test_sd(): @@ -97,52 +105,52 @@ def test_sd(): try: sd.read(0, buf1) except OSError: - print('ERROR READING DATA') + print("ERROR READING DATA") sd.power(False) return try: sd.write(0, buf1) except OSError: - print('ERROR WRITING DATA') + print("ERROR WRITING DATA") sd.power(False) return buf2 = bytearray(8 * 1024) try: sd.read(0, buf2) except OSError: - print('ERROR READING DATA') + print("ERROR READING DATA") sd.power(False) return if buf1 == buf2: - print('OK') + print("OK") else: - print('ERROR DATA MISMATCH') + print("ERROR DATA MISMATCH") sd.power(False) else: - print('ERROR NOCARD') + print("ERROR NOCARD") def test_sbu(v): - sbu1 = (v[0] == '1') - sbu2 = (v[1] == '1') + sbu1 = v[0] == "1" + sbu2 = v[1] == "1" sbu.set(sbu1, sbu2) - print('OK') + print("OK") def test_otp_read(): data = bytearray(32) otp.read(0, 0, data) - data = bytes(data).rstrip(b'\x00\xff').decode() - print('OK', data) + data = bytes(data).rstrip(b"\x00\xff").decode() + print("OK", data) def test_otp_write(v): if len(v) < 32: - v = v + '\x00' * (32 - len(v)) + v = v + "\x00" * (32 - len(v)) data = v[:32].encode() otp.write(0, 0, data) otp.lock(0) - print('OK') + print("OK") d.clear() @@ -152,32 +160,32 @@ while True: try: line = input() - if line == 'PING': - print('OK') + if line == "PING": + print("OK") - elif line.startswith('DISP '): + elif line.startswith("DISP "): test_display(line[5:]) - elif line.startswith('TOUCH '): + elif line.startswith("TOUCH "): test_touch(line[6:]) - elif line.startswith('PWM '): + elif line.startswith("PWM "): test_pwm(line[4:]) - elif line == 'SD': + elif line == "SD": test_sd() - elif line.startswith('SBU '): + elif line.startswith("SBU "): test_sbu(line[4:]) - elif line.startswith('OTP READ'): + elif line.startswith("OTP READ"): test_otp_read() - elif line.startswith('OTP WRITE '): + elif line.startswith("OTP WRITE "): test_otp_write(line[10:]) else: - print('UNKNOWN') + print("UNKNOWN") except Exception as ex: - print('ERROR', ex) + print("ERROR", ex) diff --git a/core/tests/slip39_vectors.py b/core/tests/slip39_vectors.py index 1900900769..b92a5be3ec 100644 --- a/core/tests/slip39_vectors.py +++ b/core/tests/slip39_vectors.py @@ -1,282 +1,282 @@ vectors = [ - [ [ - "duckling enlarge academic academic agency result length solution fridge kidney coal piece deal husband erode duke ajar critical decision keyboard" + [ + "duckling enlarge academic academic agency result length solution fridge kidney coal piece deal husband erode duke ajar critical decision keyboard" + ], + "bb54aac4b89dc868ba37d9cc21b2cece", ], - "bb54aac4b89dc868ba37d9cc21b2cece" - ], - [ [ - "duckling enlarge academic academic agency result length solution fridge kidney coal piece deal husband erode duke ajar critical decision kidney" + [ + "duckling enlarge academic academic agency result length solution fridge kidney coal piece deal husband erode duke ajar critical decision kidney" + ], + "", ], - "" - ], - [ [ - "duckling enlarge academic academic email result length solution fridge kidney coal piece deal husband erode duke ajar music cargo fitness" + [ + "duckling enlarge academic academic email result length solution fridge kidney coal piece deal husband erode duke ajar music cargo fitness" + ], + "", ], - "" - ], - [ [ - "shadow pistol academic always adequate wildlife fancy gross oasis cylinder mustang wrist rescue view short owner flip making coding armed", - "shadow pistol academic acid actress prayer class unknown daughter sweater depict flip twice unkind craft early superior advocate guest smoking" + [ + "shadow pistol academic always adequate wildlife fancy gross oasis cylinder mustang wrist rescue view short owner flip making coding armed", + "shadow pistol academic acid actress prayer class unknown daughter sweater depict flip twice unkind craft early superior advocate guest smoking", + ], + "b43ceb7e57a0ea8766221624d01b0864", ], - "b43ceb7e57a0ea8766221624d01b0864" - ], - [ [ - "shadow pistol academic always adequate wildlife fancy gross oasis cylinder mustang wrist rescue view short owner flip making coding armed" + [ + "shadow pistol academic always adequate wildlife fancy gross oasis cylinder mustang wrist rescue view short owner flip making coding armed" + ], + "", ], - "" - ], - [ [ - "adequate smoking academic acid debut wine petition glen cluster slow rhyme slow simple epidemic rumor junk tracks treat olympic tolerate", - "adequate stay academic agency agency formal party ting frequent learn upstairs remember smear leaf damage anatomy ladle market hush corner" + [ + "adequate smoking academic acid debut wine petition glen cluster slow rhyme slow simple epidemic rumor junk tracks treat olympic tolerate", + "adequate stay academic agency agency formal party ting frequent learn upstairs remember smear leaf damage anatomy ladle market hush corner", + ], + "", ], - "" - ], - [ [ - "peasant leaves academic acid desert exact olympic math alive axle trial tackle drug deny decent smear dominant desert bucket remind", - "peasant leader academic agency cultural blessing percent network envelope medal junk primary human pumps jacket fragment payroll ticket evoke voice" + [ + "peasant leaves academic acid desert exact olympic math alive axle trial tackle drug deny decent smear dominant desert bucket remind", + "peasant leader academic agency cultural blessing percent network envelope medal junk primary human pumps jacket fragment payroll ticket evoke voice", + ], + "", ], - "" - ], - [ [ - "liberty category beard echo animal fawn temple briefing math username various wolf aviation fancy visual holy thunder yelp helpful payment", - "liberty category beard email beyond should fancy romp founder easel pink holy hairy romp loyalty material victim owner toxic custody", - "liberty category academic easy being hazard crush diminish oral lizard reaction cluster force dilemma deploy force club veteran expect photo" + [ + "liberty category beard echo animal fawn temple briefing math username various wolf aviation fancy visual holy thunder yelp helpful payment", + "liberty category beard email beyond should fancy romp founder easel pink holy hairy romp loyalty material victim owner toxic custody", + "liberty category academic easy being hazard crush diminish oral lizard reaction cluster force dilemma deploy force club veteran expect photo", + ], + "", ], - "" - ], - [ [ - "average senior academic leaf broken teacher expect surface hour capture obesity desire negative dynamic dominant pistol mineral mailman iris aide", - "average senior academic agency curious pants blimp spew clothes slice script dress wrap firm shaft regular slavery negative theater roster" + [ + "average senior academic leaf broken teacher expect surface hour capture obesity desire negative dynamic dominant pistol mineral mailman iris aide", + "average senior academic agency curious pants blimp spew clothes slice script dress wrap firm shaft regular slavery negative theater roster", + ], + "", ], - "" - ], - [ [ - "music husband acrobat acid artist finance center either graduate swimming object bike medical clothes station aspect spider maiden bulb welcome", - "music husband acrobat agency advance hunting bike corner density careful material civil evil tactics remind hawk discuss hobo voice rainbow", - "music husband beard academic black tricycle clock mayor estimate level photo episode exclude ecology papa source amazing salt verify divorce" + [ + "music husband acrobat acid artist finance center either graduate swimming object bike medical clothes station aspect spider maiden bulb welcome", + "music husband acrobat agency advance hunting bike corner density careful material civil evil tactics remind hawk discuss hobo voice rainbow", + "music husband beard academic black tricycle clock mayor estimate level photo episode exclude ecology papa source amazing salt verify divorce", + ], + "", ], - "" - ], - [ [ - "device stay academic always dive coal antenna adult black exceed stadium herald advance soldier busy dryer daughter evaluate minister laser", - "device stay academic always dwarf afraid robin gravity crunch adjust soul branch walnut coastal dream costume scholar mortgage mountain pumps" + [ + "device stay academic always dive coal antenna adult black exceed stadium herald advance soldier busy dryer daughter evaluate minister laser", + "device stay academic always dwarf afraid robin gravity crunch adjust soul branch walnut coastal dream costume scholar mortgage mountain pumps", + ], + "", ], - "" - ], - [ [ - "hour painting academic academic device formal evoke guitar random modern justice filter withdraw trouble identify mailman insect general cover oven", - "hour painting academic agency artist again daisy capital beaver fiber much enjoy suitable symbolic identify photo editor romp float echo" + [ + "hour painting academic academic device formal evoke guitar random modern justice filter withdraw trouble identify mailman insect general cover oven", + "hour painting academic agency artist again daisy capital beaver fiber much enjoy suitable symbolic identify photo editor romp float echo", + ], + "", ], - "" - ], - [ [ - "guilt walnut academic acid deliver remove equip listen vampire tactics nylon rhythm failure husband fatigue alive blind enemy teaspoon rebound", - "guilt walnut academic agency brave hamster hobo declare herd taste alpha slim criminal mild arcade formal romp branch pink ambition" + [ + "guilt walnut academic acid deliver remove equip listen vampire tactics nylon rhythm failure husband fatigue alive blind enemy teaspoon rebound", + "guilt walnut academic agency brave hamster hobo declare herd taste alpha slim criminal mild arcade formal romp branch pink ambition", + ], + "", ], - "" - ], - [ [ - "eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice" + [ + "eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice" + ], + "", ], - "" - ], - [ [ - "eraser senior decision scared cargo theory device idea deliver modify curly include pancake both news skin realize vitamins away join", - "eraser senior decision roster beard treat identify grumpy salt index fake aviation theater cubic bike cause research dragon emphasis counter" + [ + "eraser senior decision scared cargo theory device idea deliver modify curly include pancake both news skin realize vitamins away join", + "eraser senior decision roster beard treat identify grumpy salt index fake aviation theater cubic bike cause research dragon emphasis counter", + ], + "", ], - "" - ], - [ [ - "eraser senior decision shadow artist work morning estate greatest pipeline plan ting petition forget hormone flexible general goat admit surface", - "eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice" + [ + "eraser senior decision shadow artist work morning estate greatest pipeline plan ting petition forget hormone flexible general goat admit surface", + "eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice", + ], + "", ], - "" - ], - [ [ - "eraser senior decision roster beard treat identify grumpy salt index fake aviation theater cubic bike cause research dragon emphasis counter", - "eraser senior ceramic snake clay various huge numb argue hesitate auction category timber browser greatest hanger petition script leaf pickup", - "eraser senior ceramic shaft dynamic become junior wrist silver peasant force math alto coal amazing segment yelp velvet image paces", - "eraser senior ceramic round column hawk trust auction smug shame alive greatest sheriff living perfect corner chest sled fumes adequate", - "eraser senior decision smug corner ruin rescue cubic angel tackle skin skunk program roster trash rumor slush angel flea amazing" + [ + "eraser senior decision roster beard treat identify grumpy salt index fake aviation theater cubic bike cause research dragon emphasis counter", + "eraser senior ceramic snake clay various huge numb argue hesitate auction category timber browser greatest hanger petition script leaf pickup", + "eraser senior ceramic shaft dynamic become junior wrist silver peasant force math alto coal amazing segment yelp velvet image paces", + "eraser senior ceramic round column hawk trust auction smug shame alive greatest sheriff living perfect corner chest sled fumes adequate", + "eraser senior decision smug corner ruin rescue cubic angel tackle skin skunk program roster trash rumor slush angel flea amazing", + ], + "7c3397a292a5941682d7a4ae2d898d11", ], - "7c3397a292a5941682d7a4ae2d898d11" - ], - [ [ - "eraser senior decision smug corner ruin rescue cubic angel tackle skin skunk program roster trash rumor slush angel flea amazing", - "eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice", - "eraser senior decision scared cargo theory device idea deliver modify curly include pancake both news skin realize vitamins away join" + [ + "eraser senior decision smug corner ruin rescue cubic angel tackle skin skunk program roster trash rumor slush angel flea amazing", + "eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice", + "eraser senior decision scared cargo theory device idea deliver modify curly include pancake both news skin realize vitamins away join", + ], + "7c3397a292a5941682d7a4ae2d898d11", ], - "7c3397a292a5941682d7a4ae2d898d11" - ], - [ [ - "eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice", - "eraser senior acrobat romp bishop medical gesture pumps secret alive ultimate quarter priest subject class dictate spew material endless market" + [ + "eraser senior beard romp adorn nuclear spill corner cradle style ancient family general leader ambition exchange unusual garlic promise voice", + "eraser senior acrobat romp bishop medical gesture pumps secret alive ultimate quarter priest subject class dictate spew material endless market", + ], + "7c3397a292a5941682d7a4ae2d898d11", ], - "7c3397a292a5941682d7a4ae2d898d11" - ], - [ [ - "theory painting academic academic armed sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips brave detect luck" + [ + "theory painting academic academic armed sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips brave detect luck" + ], + "989baf9dcaad5b10ca33dfd8cc75e42477025dce88ae83e75a230086a0e00e92", ], - "989baf9dcaad5b10ca33dfd8cc75e42477025dce88ae83e75a230086a0e00e92" - ], - [ [ - "theory painting academic academic armed sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips brave detect lunar" + [ + "theory painting academic academic armed sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips brave detect lunar" + ], + "", ], - "" - ], - [ [ - "theory painting academic academic campus sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips facility obtain sister" + [ + "theory painting academic academic campus sweater year military elder discuss acne wildlife boring employer fused large satoshi bundle carbon diagnose anatomy hamster leaves tracks paces beyond phantom capital marvel lips facility obtain sister" + ], + "", ], - "" - ], - [ [ - "humidity disease academic always aluminum jewelry energy woman receiver strategy amuse duckling lying evidence network walnut tactics forget hairy rebound impulse brother survive clothes stadium mailman rival ocean reward venture always armed unwrap", - "humidity disease academic agency actress jacket gross physics cylinder solution fake mortgage benefit public busy prepare sharp friar change work slow purchase ruler again tricycle involve viral wireless mixture anatomy desert cargo upgrade" + [ + "humidity disease academic always aluminum jewelry energy woman receiver strategy amuse duckling lying evidence network walnut tactics forget hairy rebound impulse brother survive clothes stadium mailman rival ocean reward venture always armed unwrap", + "humidity disease academic agency actress jacket gross physics cylinder solution fake mortgage benefit public busy prepare sharp friar change work slow purchase ruler again tricycle involve viral wireless mixture anatomy desert cargo upgrade", + ], + "c938b319067687e990e05e0da0ecce1278f75ff58d9853f19dcaeed5de104aae", ], - "c938b319067687e990e05e0da0ecce1278f75ff58d9853f19dcaeed5de104aae" - ], - [ [ - "humidity disease academic always aluminum jewelry energy woman receiver strategy amuse duckling lying evidence network walnut tactics forget hairy rebound impulse brother survive clothes stadium mailman rival ocean reward venture always armed unwrap" + [ + "humidity disease academic always aluminum jewelry energy woman receiver strategy amuse duckling lying evidence network walnut tactics forget hairy rebound impulse brother survive clothes stadium mailman rival ocean reward venture always armed unwrap" + ], + "", ], - "" - ], - [ [ - "smear husband academic acid deadline scene venture distance dive overall parking bracelet elevator justice echo burning oven chest duke nylon", - "smear isolate academic agency alpha mandate decorate burden recover guard exercise fatal force syndrome fumes thank guest drift dramatic mule" + [ + "smear husband academic acid deadline scene venture distance dive overall parking bracelet elevator justice echo burning oven chest duke nylon", + "smear isolate academic agency alpha mandate decorate burden recover guard exercise fatal force syndrome fumes thank guest drift dramatic mule", + ], + "", ], - "" - ], - [ [ - "finger trash academic acid average priority dish revenue academic hospital spirit western ocean fact calcium syndrome greatest plan losing dictate", - "finger traffic academic agency building lilac deny paces subject threaten diploma eclipse window unknown health slim piece dragon focus smirk" + [ + "finger trash academic acid average priority dish revenue academic hospital spirit western ocean fact calcium syndrome greatest plan losing dictate", + "finger traffic academic agency building lilac deny paces subject threaten diploma eclipse window unknown health slim piece dragon focus smirk", + ], + "", ], - "" - ], - [ [ - "flavor pink beard echo depart forbid retreat become frost helpful juice unwrap reunion credit math burning spine black capital lair", - "flavor pink beard email diet teaspoon freshman identify document rebound cricket prune headset loyalty smell emission skin often square rebound", - "flavor pink academic easy credit cage raisin crazy closet lobe mobile become drink human tactics valuable hand capture sympathy finger" + [ + "flavor pink beard echo depart forbid retreat become frost helpful juice unwrap reunion credit math burning spine black capital lair", + "flavor pink beard email diet teaspoon freshman identify document rebound cricket prune headset loyalty smell emission skin often square rebound", + "flavor pink academic easy credit cage raisin crazy closet lobe mobile become drink human tactics valuable hand capture sympathy finger", + ], + "", ], - "" - ], - [ [ - "column flea academic leaf debut extra surface slow timber husky lawsuit game behavior husky swimming already paper episode tricycle scroll", - "column flea academic agency blessing garbage party software stadium verify silent umbrella therapy decorate chemical erode dramatic eclipse replace apart" + [ + "column flea academic leaf debut extra surface slow timber husky lawsuit game behavior husky swimming already paper episode tricycle scroll", + "column flea academic agency blessing garbage party software stadium verify silent umbrella therapy decorate chemical erode dramatic eclipse replace apart", + ], + "", ], - "" - ], - [ [ - "smirk pink acrobat acid auction wireless impulse spine sprinkle fortune clogs elbow guest hush loyalty crush dictate tracks airport talent", - "smirk pink acrobat agency dwarf emperor ajar organize legs slice harvest plastic dynamic style mobile float bulb health coding credit", - "smirk pink beard academic alto strategy carve shame language rapids ruin smart location spray training acquire eraser endorse submit peaceful" + [ + "smirk pink acrobat acid auction wireless impulse spine sprinkle fortune clogs elbow guest hush loyalty crush dictate tracks airport talent", + "smirk pink acrobat agency dwarf emperor ajar organize legs slice harvest plastic dynamic style mobile float bulb health coding credit", + "smirk pink beard academic alto strategy carve shame language rapids ruin smart location spray training acquire eraser endorse submit peaceful", + ], + "", ], - "" - ], - [ [ - "fishing recover academic always device craft trend snapshot gums skin downtown watch device sniff hour clock public maximum garlic born", - "fishing recover academic always aircraft view software cradle fangs amazing package plastic evaluate intend penalty epidemic anatomy quarter cage apart" + [ + "fishing recover academic always device craft trend snapshot gums skin downtown watch device sniff hour clock public maximum garlic born", + "fishing recover academic always aircraft view software cradle fangs amazing package plastic evaluate intend penalty epidemic anatomy quarter cage apart", + ], + "", ], - "" - ], - [ [ - "evoke garden academic academic answer wolf scandal modern warmth station devote emerald market physics surface formal amazing aquatic gesture medical", - "evoke garden academic agency deal revenue knit reunion decrease magazine flexible company goat repair alarm military facility clogs aide mandate" + [ + "evoke garden academic academic answer wolf scandal modern warmth station devote emerald market physics surface formal amazing aquatic gesture medical", + "evoke garden academic agency deal revenue knit reunion decrease magazine flexible company goat repair alarm military facility clogs aide mandate", + ], + "", ], - "" - ], - [ [ - "river deal academic acid average forbid pistol peanut custody bike class aunt hairy merit valid flexible learn ajar very easel", - "river deal academic agency camera amuse lungs numb isolate display smear piece traffic worthy year patrol crush fact fancy emission" + [ + "river deal academic acid average forbid pistol peanut custody bike class aunt hairy merit valid flexible learn ajar very easel", + "river deal academic agency camera amuse lungs numb isolate display smear piece traffic worthy year patrol crush fact fancy emission", + ], + "", ], - "" - ], - [ [ - "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium" + [ + "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium" + ], + "", ], - "" - ], - [ [ - "wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen", - "wildlife deal decision smug ancestor genuine move huge cubic strategy smell game costume extend swimming false desire fake traffic vegan senior twice timber submit leader payroll fraction apart exact forward pulse tidy install" + [ + "wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen", + "wildlife deal decision smug ancestor genuine move huge cubic strategy smell game costume extend swimming false desire fake traffic vegan senior twice timber submit leader payroll fraction apart exact forward pulse tidy install", + ], + "", ], - "" - ], - [ [ - "wildlife deal decision shadow analysis adjust bulb skunk muscle mandate obesity total guitar coal gravity carve slim jacket ruin rebuild ancestor numerous hour mortgage require herd maiden public ceiling pecan pickup shadow club", - "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium" + [ + "wildlife deal decision shadow analysis adjust bulb skunk muscle mandate obesity total guitar coal gravity carve slim jacket ruin rebuild ancestor numerous hour mortgage require herd maiden public ceiling pecan pickup shadow club", + "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium", + ], + "", ], - "" - ], - [ [ - "wildlife deal ceramic round aluminum pitch goat racism employer miracle percent math decision episode dramatic editor lily prospect program scene rebuild display sympathy have single mustang junction relate often chemical society wits estate", - "wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen", - "wildlife deal ceramic scatter argue equip vampire together ruin reject literary rival distance aquatic agency teammate rebound false argue miracle stay again blessing peaceful unknown cover beard acid island language debris industry idle", - "wildlife deal ceramic snake agree voter main lecture axis kitchen physics arcade velvet spine idea scroll promise platform firm sharp patrol divorce ancestor fantasy forbid goat ajar believe swimming cowboy symbolic plastic spelling", - "wildlife deal decision shadow analysis adjust bulb skunk muscle mandate obesity total guitar coal gravity carve slim jacket ruin rebuild ancestor numerous hour mortgage require herd maiden public ceiling pecan pickup shadow club" + [ + "wildlife deal ceramic round aluminum pitch goat racism employer miracle percent math decision episode dramatic editor lily prospect program scene rebuild display sympathy have single mustang junction relate often chemical society wits estate", + "wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen", + "wildlife deal ceramic scatter argue equip vampire together ruin reject literary rival distance aquatic agency teammate rebound false argue miracle stay again blessing peaceful unknown cover beard acid island language debris industry idle", + "wildlife deal ceramic snake agree voter main lecture axis kitchen physics arcade velvet spine idea scroll promise platform firm sharp patrol divorce ancestor fantasy forbid goat ajar believe swimming cowboy symbolic plastic spelling", + "wildlife deal decision shadow analysis adjust bulb skunk muscle mandate obesity total guitar coal gravity carve slim jacket ruin rebuild ancestor numerous hour mortgage require herd maiden public ceiling pecan pickup shadow club", + ], + "5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b", ], - "5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b" - ], - [ [ - "wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen", - "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium", - "wildlife deal decision smug ancestor genuine move huge cubic strategy smell game costume extend swimming false desire fake traffic vegan senior twice timber submit leader payroll fraction apart exact forward pulse tidy install" + [ + "wildlife deal decision scared acne fatal snake paces obtain election dryer dominant romp tactics railroad marvel trust helpful flip peanut theory theater photo luck install entrance taxi step oven network dictate intimate listen", + "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium", + "wildlife deal decision smug ancestor genuine move huge cubic strategy smell game costume extend swimming false desire fake traffic vegan senior twice timber submit leader payroll fraction apart exact forward pulse tidy install", + ], + "5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b", ], - "5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b" - ], - [ [ - "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium", - "wildlife deal acrobat romp anxiety axis starting require metric flexible geology game drove editor edge screw helpful have huge holy making pitch unknown carve holiday numb glasses survive already tenant adapt goat fangs" + [ + "wildlife deal beard romp alcohol space mild usual clothes union nuclear testify course research heat listen task location thank hospital slice smell failure fawn helpful priest ambition average recover lecture process dough stadium", + "wildlife deal acrobat romp anxiety axis starting require metric flexible geology game drove editor edge screw helpful have huge holy making pitch unknown carve holiday numb glasses survive already tenant adapt goat fangs", + ], + "5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b", ], - "5385577c8cfc6c1a8aa0f7f10ecde0a3318493262591e78b8c14c6686167123b" - ], - [ [ - "junk necklace academic academic acne isolate join hesitate lunar roster dough calcium chemical ladybug amount mobile glasses verify cylinder" + [ + "junk necklace academic academic acne isolate join hesitate lunar roster dough calcium chemical ladybug amount mobile glasses verify cylinder" + ], + "", ], - "" - ], - [ [ - "fraction necklace academic academic award teammate mouse regular testify coding building member verdict purchase blind camera duration email prepare spirit quarter" + [ + "fraction necklace academic academic award teammate mouse regular testify coding building member verdict purchase blind camera duration email prepare spirit quarter" + ], + "", ], - "" - ] ] diff --git a/core/tests/test_apps.binance.address.py b/core/tests/test_apps.binance.address.py index 381deb6e17..ea6da68305 100644 --- a/core/tests/test_apps.binance.address.py +++ b/core/tests/test_apps.binance.address.py @@ -10,7 +10,7 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestBinanceAddress(unittest.TestCase): def test_privkey_to_address(self): - #source of test data - binance javascript SDK + # source of test data - binance javascript SDK privkey = "90335b9d2153ad1a9799a3ccc070bd64b4164e9642ee1dd48053c33f9a3a05e9" expected_address = "tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd" @@ -20,5 +20,5 @@ class TestBinanceAddress(unittest.TestCase): self.assertEqual(address, expected_address) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.binance.sign_tx.py b/core/tests/test_apps.binance.sign_tx.py index 3db0d3ad1a..6e897504b9 100644 --- a/core/tests/test_apps.binance.sign_tx.py +++ b/core/tests/test_apps.binance.sign_tx.py @@ -26,19 +26,30 @@ class TestBinanceSign(unittest.TestCase): # https://github.com/binance-chain/javascript-sdk/blob/master/__tests__/fixtures/placeOrder.json json_msg = '{"account_number":"34","chain_id":"Binance-Chain-Nile","data":null,"memo":"","msgs":[{"id":"BA36F0FAD74D8F41045463E4774F328F4AF779E5-33","ordertype":2,"price":100000000,"quantity":100000000,"sender":"tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd","side":1,"symbol":"ADA.B-B63_BNB","timeinforce":1}],"sequence":"32","source":"1"}' expected_signature = "851fc9542342321af63ecbba7d3ece545f2a42bad01ba32cff5535b18e54b6d3106e10b6a4525993d185a1443d9a125186960e028eabfdd8d76cf70a3a7e3100" - public_key = "029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e" + public_key = ( + "029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e" + ) private_key = "90335b9d2153ad1a9799a3ccc070bd64b4164e9642ee1dd48053c33f9a3a05e9" # Testing data for object creation is decoded from json_msg - envelope = BinanceSignTx(msg_count=1, account_number=34, chain_id="Binance-Chain-Nile", memo="", sequence=32, source=1) - msg = BinanceOrderMsg(id="BA36F0FAD74D8F41045463E4774F328F4AF779E5-33", - ordertype=2, - price=100000000, - quantity=100000000, - sender="tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd", - side=1, - symbol="ADA.B-B63_BNB", - timeinforce=1) + envelope = BinanceSignTx( + msg_count=1, + account_number=34, + chain_id="Binance-Chain-Nile", + memo="", + sequence=32, + source=1, + ) + msg = BinanceOrderMsg( + id="BA36F0FAD74D8F41045463E4774F328F4AF779E5-33", + ordertype=2, + price=100000000, + quantity=100000000, + sender="tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd", + side=1, + symbol="ADA.B-B63_BNB", + timeinforce=1, + ) msg_json = produce_json_for_signing(envelope, msg) @@ -46,8 +57,12 @@ class TestBinanceSign(unittest.TestCase): self.assertEqual(msg_json, json_msg) # verify signature against public key - signature = generate_content_signature(msg_json.encode(), unhexlify(private_key)) - self.assertTrue(verify_content_signature(unhexlify(public_key), signature, json_msg)) + signature = generate_content_signature( + msg_json.encode(), unhexlify(private_key) + ) + self.assertTrue( + verify_content_signature(unhexlify(public_key), signature, json_msg) + ) # check if the signed data is the same as test vector self.assertEqual(signature, unhexlify(expected_signature)) @@ -57,14 +72,25 @@ class TestBinanceSign(unittest.TestCase): # https://github.com/binance-chain/javascript-sdk/blob/master/__tests__/fixtures/cancelOrder.json json_msg = '{"account_number":"34","chain_id":"Binance-Chain-Nile","data":null,"memo":"","msgs":[{"refid":"BA36F0FAD74D8F41045463E4774F328F4AF779E5-29","sender":"tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd","symbol":"BCHSV.B-10F_BNB"}],"sequence":"33","source":"1"}' expected_signature = "d93fb0402b2b30e7ea08e123bb139ad68bf0a1577f38592eb22d11e127f09bbd3380f29b4bf15bdfa973454c5c8ed444f2e256e956fe98cfd21e886a946e21e5" - public_key = "029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e" + public_key = ( + "029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e" + ) private_key = "90335b9d2153ad1a9799a3ccc070bd64b4164e9642ee1dd48053c33f9a3a05e9" # Testing data for object creation is decoded from json_msg - envelope = BinanceSignTx(msg_count=1, account_number=34, chain_id="Binance-Chain-Nile", memo="", sequence=33, source=1) - msg = BinanceCancelMsg(refid="BA36F0FAD74D8F41045463E4774F328F4AF779E5-29", - sender="tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd", - symbol="BCHSV.B-10F_BNB") + envelope = BinanceSignTx( + msg_count=1, + account_number=34, + chain_id="Binance-Chain-Nile", + memo="", + sequence=33, + source=1, + ) + msg = BinanceCancelMsg( + refid="BA36F0FAD74D8F41045463E4774F328F4AF779E5-29", + sender="tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd", + symbol="BCHSV.B-10F_BNB", + ) msg_json = produce_json_for_signing(envelope, msg) @@ -72,10 +98,14 @@ class TestBinanceSign(unittest.TestCase): self.assertEqual(msg_json, json_msg) # verify signature against public key - signature = generate_content_signature(msg_json.encode(), unhexlify(private_key)) - self.assertTrue(verify_content_signature(unhexlify(public_key), signature, json_msg)) + signature = generate_content_signature( + msg_json.encode(), unhexlify(private_key) + ) + self.assertTrue( + verify_content_signature(unhexlify(public_key), signature, json_msg) + ) - #check if the signed data is the same as test vector + # check if the signed data is the same as test vector self.assertEqual(signature, unhexlify(expected_signature)) def test_transfer_signature(self): @@ -83,14 +113,27 @@ class TestBinanceSign(unittest.TestCase): # https://github.com/binance-chain/javascript-sdk/blob/master/__tests__/fixtures/transfer.json json_msg = '{"account_number":"34","chain_id":"Binance-Chain-Nile","data":null,"memo":"test","msgs":[{"inputs":[{"address":"tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd","coins":[{"amount":1000000000,"denom":"BNB"}]}],"outputs":[{"address":"tbnb1ss57e8sa7xnwq030k2ctr775uac9gjzglqhvpy","coins":[{"amount":1000000000,"denom":"BNB"}]}]}],"sequence":"31","source":"1"}' expected_signature = "faf5b908d6c4ec0c7e2e7d8f7e1b9ca56ac8b1a22b01655813c62ce89bf84a4c7b14f58ce51e85d64c13f47e67d6a9187b8f79f09e0a9b82019f47ae190a4db3" - public_key = "029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e" + public_key = ( + "029729a52e4e3c2b4a4e52aa74033eedaf8ba1df5ab6d1f518fd69e67bbd309b0e" + ) private_key = "90335b9d2153ad1a9799a3ccc070bd64b4164e9642ee1dd48053c33f9a3a05e9" # Testing data for object creation is decoded from json_msg - envelope = BinanceSignTx(msg_count=1, account_number=34, chain_id="Binance-Chain-Nile", memo="test", sequence=31, source=1) + envelope = BinanceSignTx( + msg_count=1, + account_number=34, + chain_id="Binance-Chain-Nile", + memo="test", + sequence=31, + source=1, + ) coin = BinanceCoin(denom="BNB", amount=1000000000) - first_input = BinanceInputOutput(address="tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd", coins=[coin]) - first_output = BinanceInputOutput(address="tbnb1ss57e8sa7xnwq030k2ctr775uac9gjzglqhvpy", coins=[coin]) + first_input = BinanceInputOutput( + address="tbnb1hgm0p7khfk85zpz5v0j8wnej3a90w709zzlffd", coins=[coin] + ) + first_output = BinanceInputOutput( + address="tbnb1ss57e8sa7xnwq030k2ctr775uac9gjzglqhvpy", coins=[coin] + ) msg = BinanceTransferMsg(inputs=[first_input], outputs=[first_output]) msg_json = produce_json_for_signing(envelope, msg) @@ -99,17 +142,23 @@ class TestBinanceSign(unittest.TestCase): self.assertEqual(msg_json, json_msg) # verify signature against public key - signature = generate_content_signature(msg_json.encode(), unhexlify(private_key)) - self.assertTrue(verify_content_signature(unhexlify(public_key), signature, json_msg)) + signature = generate_content_signature( + msg_json.encode(), unhexlify(private_key) + ) + self.assertTrue( + verify_content_signature(unhexlify(public_key), signature, json_msg) + ) # check if the signed data is the same as test vector self.assertEqual(signature, unhexlify(expected_signature)) + def verify_content_signature( public_key: bytes, signature: bytes, unsigned_data: bytes ) -> bool: msghash = sha256(unsigned_data).digest() return secp256k1.verify(public_key, signature, msghash) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.address.py b/core/tests/test_apps.bitcoin.address.py index dc9fd9c5d5..4f35af87b0 100644 --- a/core/tests/test_apps.bitcoin.address.py +++ b/core/tests/test_apps.bitcoin.address.py @@ -8,8 +8,10 @@ from trezor.utils import HashWriter from apps.common import coins from apps.bitcoin.addresses import * from apps.bitcoin.addresses import ( - _address_p2wsh, _address_p2wsh_in_p2sh, - _address_multisig_p2wsh_in_p2sh, _address_multisig_p2sh + _address_p2wsh, + _address_p2wsh_in_p2sh, + _address_multisig_p2wsh_in_p2sh, + _address_multisig_p2sh, ) from apps.bitcoin.keychain import validate_path_against_script_type from apps.bitcoin.writers import * @@ -25,74 +27,80 @@ class TestAddress(unittest.TestCase): # pylint: disable=C0301 def test_p2wpkh_in_p2sh_address(self): - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") address = address_p2wpkh_in_p2sh( - unhexlify('03a1af804ac108a8a51782198c2d034b28bf90c8803f5a53f76276fa69a4eae77f'), - coin + unhexlify( + "03a1af804ac108a8a51782198c2d034b28bf90c8803f5a53f76276fa69a4eae77f" + ), + coin, ) - self.assertEqual(address, '2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2') + self.assertEqual(address, "2Mww8dCYPUpKHofjgcXcBCEGmniw9CoaiD2") def test_p2wpkh_in_p2sh_node_derive_address(self): - coin = coins.by_name('Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') - root = bip32.from_seed(seed, 'secp256k1') + coin = coins.by_name("Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") + root = bip32.from_seed(seed, "secp256k1") node = node_derive(root, [H_(49), H_(1), H_(0), 1, 0]) address = address_p2wpkh_in_p2sh(node.public_key(), coin) - self.assertEqual(address, '2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX') + self.assertEqual(address, "2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX") node = node_derive(root, [H_(49), H_(1), H_(0), 1, 1]) address = address_p2wpkh_in_p2sh(node.public_key(), coin) - self.assertEqual(address, '2NFWLCJQBSpz1oUJwwLpX8ECifFWGznBVqs') + self.assertEqual(address, "2NFWLCJQBSpz1oUJwwLpX8ECifFWGznBVqs") node = node_derive(root, [H_(49), H_(1), H_(0), 0, 0]) address = address_p2wpkh_in_p2sh(node.public_key(), coin) - self.assertEqual(address, '2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp') + self.assertEqual(address, "2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp") def test_p2wpkh_address(self): # test data from https://bc-2.jp/tools/bech32demo/index.html - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") address = address_p2wpkh( - unhexlify('0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798'), - coin + unhexlify( + "0279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798" + ), + coin, ) - self.assertEqual(address, 'tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx') + self.assertEqual(address, "tb1qw508d6qejxtdg4y5r3zarvary0c5xw7kxpjzsx") def test_p2sh_address(self): - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") address = address_p2sh( - unhexlify('7a55d61848e77ca266e79a39bfc85c580a6426c9'), - coin + unhexlify("7a55d61848e77ca266e79a39bfc85c580a6426c9"), coin ) - self.assertEqual(address, '2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp') + self.assertEqual(address, "2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp") def test_p2wsh_address(self): - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") # pubkey OP_CHECKSIG - script = unhexlify('210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac') + script = unhexlify( + "210279be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798ac" + ) h = HashWriter(sha256()) write_bytes_unchecked(h, script) - address = _address_p2wsh( - h.get_digest(), - coin.bech32_prefix + address = _address_p2wsh(h.get_digest(), coin.bech32_prefix) + self.assertEqual( + address, "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7" ) - self.assertEqual(address, 'tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7') def test_p2wsh_in_p2sh_address(self): - coin = coins.by_name('Bitcoin') + coin = coins.by_name("Bitcoin") # test data from Mastering Bitcoin address = _address_p2wsh_in_p2sh( - unhexlify('9592d601848d04b172905e0ddb0adde59f1590f1e553ffc81ddc4b0ed927dd73'), - coin + unhexlify( + "9592d601848d04b172905e0ddb0adde59f1590f1e553ffc81ddc4b0ed927dd73" + ), + coin, ) - self.assertEqual(address, '3Dwz1MXhM6EfFoJChHCxh1jWHb8GQqRenG') + self.assertEqual(address, "3Dwz1MXhM6EfFoJChHCxh1jWHb8GQqRenG") def test_multisig_address_p2sh(self): # # test data from @@ -107,13 +115,17 @@ class TestAddress(unittest.TestCase): # address = _address_multisig_p2sh(pubkeys, 2, coin.address_type_p2sh) # self.assertEqual(address, '347N1Thc213QqfYCz3PZkjoJpNv5b14kBd') - coin = coins.by_name('Bitcoin') + coin = coins.by_name("Bitcoin") pubkeys = [ - unhexlify('02fe6f0a5a297eb38c391581c4413e084773ea23954d93f7753db7dc0adc188b2f'), - unhexlify('02ff12471208c14bd580709cb2358d98975247d8765f92bc25eab3b2763ed605f8'), + unhexlify( + "02fe6f0a5a297eb38c391581c4413e084773ea23954d93f7753db7dc0adc188b2f" + ), + unhexlify( + "02ff12471208c14bd580709cb2358d98975247d8765f92bc25eab3b2763ed605f8" + ), ] address = _address_multisig_p2sh(pubkeys, 2, coin) - self.assertEqual(address, '39bgKC7RFbpoCRbtD5KEdkYKtNyhpsNa3Z') + self.assertEqual(address, "39bgKC7RFbpoCRbtD5KEdkYKtNyhpsNa3Z") for invalid_m in (-1, 0, len(pubkeys) + 1, 16): with self.assertRaises(wire.DataError): @@ -122,14 +134,18 @@ class TestAddress(unittest.TestCase): def test_multisig_address_p2wsh_in_p2sh(self): # test data from # https://bitcoin.stackexchange.com/questions/62656/generate-a-p2sh-p2wsh-address-and-spend-output-sent-to-it - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") pubkeys = [ - unhexlify('020b020e27e49f049eac10010506499a84e1d59a500cd3680e9ded580df9a107b0'), - unhexlify('0320ce424c6d61f352ccfea60d209651672cfb03b2dc77d1d64d3ba519aec756ae'), + unhexlify( + "020b020e27e49f049eac10010506499a84e1d59a500cd3680e9ded580df9a107b0" + ), + unhexlify( + "0320ce424c6d61f352ccfea60d209651672cfb03b2dc77d1d64d3ba519aec756ae" + ), ] address = _address_multisig_p2wsh_in_p2sh(pubkeys, 2, coin) - self.assertEqual(address, '2MsZ2fpGKUydzY62v6trPHR8eCx5JTy1Dpa') + self.assertEqual(address, "2MsZ2fpGKUydzY62v6trPHR8eCx5JTy1Dpa") # def test_multisig_address_p2wsh(self): # todo couldn't find test data @@ -143,20 +159,53 @@ class TestAddress(unittest.TestCase): def test_paths_btc(self): incorrect_derivation_paths = [ ([H_(49)], InputScriptType.SPENDP2SHWITNESS), # invalid length - ([H_(49), H_(0), H_(0), H_(0), H_(0)], InputScriptType.SPENDP2SHWITNESS), # too many HARDENED + ( + [H_(49), H_(0), H_(0), H_(0), H_(0)], + InputScriptType.SPENDP2SHWITNESS, + ), # too many HARDENED ([H_(49), H_(0)], InputScriptType.SPENDP2SHWITNESS), # invalid length - ([H_(49), H_(0), H_(0), 0, 0, 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid length - ([H_(49), H_(123), H_(0), 0, 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid slip44 - ([H_(49), H_(0), H_(1000), 0, 0], InputScriptType.SPENDP2SHWITNESS), # account too high - ([H_(49), H_(0), H_(1), 2, 0], InputScriptType.SPENDP2SHWITNESS), # invalid y - ([H_(49), H_(0), H_(1), 0, 10000000], InputScriptType.SPENDP2SHWITNESS), # address index too high - ([H_(84), H_(0), H_(1), 0, 10000000], InputScriptType.SPENDWITNESS), # address index too high - ([H_(49), H_(0), H_(1), 0, 0], InputScriptType.SPENDWITNESS), # invalid input type - ([H_(84), H_(0), H_(1), 0, 0], InputScriptType.SPENDP2SHWITNESS), # invalid input type - ([H_(49), H_(0), H_(5), 0, 10], InputScriptType.SPENDMULTISIG), # invalid input type + ( + [H_(49), H_(0), H_(0), 0, 0, 0, 0], + InputScriptType.SPENDP2SHWITNESS, + ), # invalid length + ( + [H_(49), H_(123), H_(0), 0, 0, 0], + InputScriptType.SPENDP2SHWITNESS, + ), # invalid slip44 + ( + [H_(49), H_(0), H_(1000), 0, 0], + InputScriptType.SPENDP2SHWITNESS, + ), # account too high + ( + [H_(49), H_(0), H_(1), 2, 0], + InputScriptType.SPENDP2SHWITNESS, + ), # invalid y + ( + [H_(49), H_(0), H_(1), 0, 10000000], + InputScriptType.SPENDP2SHWITNESS, + ), # address index too high + ( + [H_(84), H_(0), H_(1), 0, 10000000], + InputScriptType.SPENDWITNESS, + ), # address index too high + ( + [H_(49), H_(0), H_(1), 0, 0], + InputScriptType.SPENDWITNESS, + ), # invalid input type + ( + [H_(84), H_(0), H_(1), 0, 0], + InputScriptType.SPENDP2SHWITNESS, + ), # invalid input type + ( + [H_(49), H_(0), H_(5), 0, 10], + InputScriptType.SPENDMULTISIG, + ), # invalid input type ] correct_derivation_paths = [ - ([H_(44), H_(0), H_(0), 0, 0], InputScriptType.SPENDADDRESS), # btc is segwit coin, but non-segwit paths are allowed as well + ( + [H_(44), H_(0), H_(0), 0, 0], + InputScriptType.SPENDADDRESS, + ), # btc is segwit coin, but non-segwit paths are allowed as well ([H_(44), H_(0), H_(0), 0, 1], InputScriptType.SPENDADDRESS), ([H_(44), H_(0), H_(0), 1, 0], InputScriptType.SPENDADDRESS), ([H_(49), H_(0), H_(0), 0, 0], InputScriptType.SPENDP2SHWITNESS), @@ -169,7 +218,7 @@ class TestAddress(unittest.TestCase): ([H_(84), H_(0), H_(5), 0, 10], InputScriptType.SPENDWITNESS), ([H_(48), H_(0), H_(5), H_(0), 0, 10], InputScriptType.SPENDMULTISIG), ] - coin = coins.by_name('Bitcoin') + coin = coins.by_name("Bitcoin") for path, input_type in incorrect_derivation_paths: self.assertFalse(self.validate(path, coin, input_type)) @@ -177,24 +226,59 @@ class TestAddress(unittest.TestCase): for path, input_type in correct_derivation_paths: self.assertTrue(self.validate(path, coin, input_type)) - self.assertTrue(self.validate([H_(44), H_(0), H_(0), 0, 0], coin, InputScriptType.SPENDADDRESS)) - self.assertFalse(self.validate([H_(44), H_(0), H_(0), 0, 0], coin, InputScriptType.SPENDWITNESS)) + self.assertTrue( + self.validate( + [H_(44), H_(0), H_(0), 0, 0], coin, InputScriptType.SPENDADDRESS + ) + ) + self.assertFalse( + self.validate( + [H_(44), H_(0), H_(0), 0, 0], coin, InputScriptType.SPENDWITNESS + ) + ) @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") def test_paths_bch(self): incorrect_derivation_paths = [ ([H_(44)], InputScriptType.SPENDADDRESS), # invalid length - ([H_(44), H_(145), H_(0), H_(0), H_(0)], InputScriptType.SPENDADDRESS), # too many HARDENED - ([H_(49), H_(145), H_(0), 0, 0], InputScriptType.SPENDP2SHWITNESS), # bch is not segwit coin so 49' is not allowed - ([H_(84), H_(145), H_(1), 0, 1], InputScriptType.SPENDWITNESS), # and neither is 84' + ( + [H_(44), H_(145), H_(0), H_(0), H_(0)], + InputScriptType.SPENDADDRESS, + ), # too many HARDENED + ( + [H_(49), H_(145), H_(0), 0, 0], + InputScriptType.SPENDP2SHWITNESS, + ), # bch is not segwit coin so 49' is not allowed + ( + [H_(84), H_(145), H_(1), 0, 1], + InputScriptType.SPENDWITNESS, + ), # and neither is 84' ([H_(44), H_(145)], InputScriptType.SPENDADDRESS), # invalid length - ([H_(44), H_(145), H_(0), 0, 0, 0, 0], InputScriptType.SPENDADDRESS), # invalid length - ([H_(44), H_(123), H_(0), 0, 0, 0], InputScriptType.SPENDADDRESS), # invalid slip44 - ([H_(44), H_(145), H_(1000), 0, 0], InputScriptType.SPENDADDRESS), # account too high + ( + [H_(44), H_(145), H_(0), 0, 0, 0, 0], + InputScriptType.SPENDADDRESS, + ), # invalid length + ( + [H_(44), H_(123), H_(0), 0, 0, 0], + InputScriptType.SPENDADDRESS, + ), # invalid slip44 + ( + [H_(44), H_(145), H_(1000), 0, 0], + InputScriptType.SPENDADDRESS, + ), # account too high ([H_(44), H_(145), H_(1), 2, 0], InputScriptType.SPENDADDRESS), # invalid y - ([H_(44), H_(145), H_(1), 0, 10000000], InputScriptType.SPENDADDRESS), # address index too high - ([H_(84), H_(145), H_(1), 0, 10000000], InputScriptType.SPENDWITNESS), # address index too high - ([H_(44), H_(145), H_(0), 0, 0], InputScriptType.SPENDWITNESS), # input type mismatch + ( + [H_(44), H_(145), H_(1), 0, 10000000], + InputScriptType.SPENDADDRESS, + ), # address index too high + ( + [H_(84), H_(145), H_(1), 0, 10000000], + InputScriptType.SPENDWITNESS, + ), # address index too high + ( + [H_(44), H_(145), H_(0), 0, 0], + InputScriptType.SPENDWITNESS, + ), # input type mismatch ] correct_derivation_paths = [ ([H_(44), H_(145), H_(0), 0, 0], InputScriptType.SPENDADDRESS), @@ -206,7 +290,7 @@ class TestAddress(unittest.TestCase): ([H_(48), H_(145), H_(5), H_(0), 0, 0], InputScriptType.SPENDMULTISIG), ([H_(48), H_(145), H_(5), H_(0), 0, 10], InputScriptType.SPENDMULTISIG), ] - coin = coins.by_name('Bcash') # segwit is disabled + coin = coins.by_name("Bcash") # segwit is disabled for path, input_type in incorrect_derivation_paths: self.assertFalse(self.validate(path, coin, input_type)) @@ -216,7 +300,10 @@ class TestAddress(unittest.TestCase): @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") def test_paths_other(self): incorrect_derivation_paths = [ - ([H_(44), H_(3), H_(0), 0, 0], InputScriptType.SPENDMULTISIG), # input type mismatch + ( + [H_(44), H_(3), H_(0), 0, 0], + InputScriptType.SPENDMULTISIG, + ), # input type mismatch ] correct_derivation_paths = [ ([H_(44), H_(3), H_(0), 0, 0], InputScriptType.SPENDADDRESS), @@ -224,7 +311,7 @@ class TestAddress(unittest.TestCase): ([H_(44), H_(3), H_(0), 0, 1123], InputScriptType.SPENDADDRESS), ([H_(44), H_(3), H_(0), 1, 44444], InputScriptType.SPENDADDRESS), ] - coin = coins.by_name('Dogecoin') # segwit is disabled + coin = coins.by_name("Dogecoin") # segwit is disabled for path, input_type in correct_derivation_paths: self.assertTrue(self.validate(path, coin, input_type)) @@ -237,21 +324,34 @@ class TestAddress(unittest.TestCase): from apps.common.paths import AlwaysMatchingSchema VECTORS = ( - ('Bitcoin', '1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE', '9cf7c230041d6ed95b8273bd32e023d3f227ec8c44257f6463c743a4b4add028'), - ('Testnet', 'mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ', '4375089e50423505dc3480e6e85b0ba37a52bd1e009db5d260b6329f22c950d9') + ( + "Bitcoin", + "1DyHzbQUoQEsLxJn6M7fMD8Xdt1XvNiwNE", + "9cf7c230041d6ed95b8273bd32e023d3f227ec8c44257f6463c743a4b4add028", + ), + ( + "Testnet", + "mm6kLYbGEL1tGe4ZA8xacfgRPdW1NLjCbZ", + "4375089e50423505dc3480e6e85b0ba37a52bd1e009db5d260b6329f22c950d9", + ), ) - seed = bip39.seed(' '.join(['all'] * 12), '') + seed = bip39.seed(" ".join(["all"] * 12), "") for coin_name, address, mac in VECTORS: coin = coins.by_name(coin_name) mac = unhexlify(mac) - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0024"]]) + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0024"]], + ) self.assertEqual(get_address_mac(address, coin.slip44, keychain), mac) check_address_mac(address, mac, coin.slip44, keychain) with self.assertRaises(wire.DataError): - mac = bytes([mac[0]^1]) + mac[1:] + mac = bytes([mac[0] ^ 1]) + mac[1:] check_address_mac(address, mac, coin.slip44, keychain) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.address_grs.py b/core/tests/test_apps.bitcoin.address_grs.py index 35a1e94f70..fe6afb4ce5 100644 --- a/core/tests/test_apps.bitcoin.address_grs.py +++ b/core/tests/test_apps.bitcoin.address_grs.py @@ -17,68 +17,88 @@ class TestAddressGRS(unittest.TestCase): # pylint: disable=C0301 def test_p2pkh_node_derive_address(self): - coin = coins.by_name('Groestlcoin') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Groestlcoin") + seed = bip39.seed(" ".join(["all"] * 12), "") root = bip32.from_seed(seed, coin.curve_name) - node = node_derive(root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 0]) - address = node.address(coin.address_type) # generate in trezor-crypto - self.assertEqual(address, 'FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN') - address = address_pkh(node.public_key(), coin) # generate in trezor-core - self.assertEqual(address, 'FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN') + node = node_derive( + root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 0] + ) + address = node.address(coin.address_type) # generate in trezor-crypto + self.assertEqual(address, "FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN") + address = address_pkh(node.public_key(), coin) # generate in trezor-core + self.assertEqual(address, "FmRaqvVBRrAp2Umfqx9V1ectZy8gw54QDN") - node = node_derive(root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 1]) + node = node_derive( + root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 1] + ) address = node.address(coin.address_type) - self.assertEqual(address, 'Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di') + self.assertEqual(address, "Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di") address = address_pkh(node.public_key(), coin) - self.assertEqual(address, 'Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di') + self.assertEqual(address, "Fmhtxeh7YdCBkyQF7AQG4QnY8y3rJg89di") - node = node_derive(root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 0]) + node = node_derive( + root, [44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 0] + ) address = node.address(coin.address_type) - self.assertEqual(address, 'Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM') + self.assertEqual(address, "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM") address = address_pkh(node.public_key(), coin) - self.assertEqual(address, 'Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM') + self.assertEqual(address, "Fj62rBJi8LvbmWu2jzkaUX1NFXLEqDLoZM") def test_p2wpkh_in_p2sh_node_derive_address(self): - coin = coins.by_name('Groestlcoin Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Groestlcoin Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") root = bip32.from_seed(seed, coin.curve_name) - node = node_derive(root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0]) + node = node_derive( + root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0] + ) address = address_p2wpkh_in_p2sh(node.public_key(), coin) - self.assertEqual(address, '2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7') + self.assertEqual(address, "2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7") - node = node_derive(root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 1]) + node = node_derive( + root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 1] + ) address = address_p2wpkh_in_p2sh(node.public_key(), coin) - self.assertEqual(address, '2NFWLCJQBSpz1oUJwwLpX8ECifFWGxQyzGu') + self.assertEqual(address, "2NFWLCJQBSpz1oUJwwLpX8ECifFWGxQyzGu") - node = node_derive(root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0]) + node = node_derive( + root, [49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0] + ) address = address_p2wpkh_in_p2sh(node.public_key(), coin) - self.assertEqual(address, '2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e') + self.assertEqual(address, "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e") def test_p2sh_address(self): - coin = coins.by_name('Groestlcoin Testnet') + coin = coins.by_name("Groestlcoin Testnet") - address = address_p2sh(unhexlify('7a55d61848e77ca266e79a39bfc85c580a6426c9'), coin) - self.assertEqual(address, '2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e') + address = address_p2sh( + unhexlify("7a55d61848e77ca266e79a39bfc85c580a6426c9"), coin + ) + self.assertEqual(address, "2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e") def test_p2wpkh_node_derive_address(self): - coin = coins.by_name('Groestlcoin') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Groestlcoin") + seed = bip39.seed(" ".join(["all"] * 12), "") root = bip32.from_seed(seed, coin.curve_name) - node = node_derive(root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 0]) + node = node_derive( + root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 0] + ) address = address_p2wpkh(node.public_key(), coin) - self.assertEqual(address, 'grs1qzfpwn55tvkxcw0xwfa0g8k2gtlzlgkcq3z000e') + self.assertEqual(address, "grs1qzfpwn55tvkxcw0xwfa0g8k2gtlzlgkcq3z000e") - node = node_derive(root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 1]) + node = node_derive( + root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 1, 1] + ) address = address_p2wpkh(node.public_key(), coin) - self.assertEqual(address, 'grs1qxsgwl66tx7tsuwfm4kk5c5dh6tlfpr4qjqg6gg') + self.assertEqual(address, "grs1qxsgwl66tx7tsuwfm4kk5c5dh6tlfpr4qjqg6gg") - node = node_derive(root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 0]) + node = node_derive( + root, [84 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 0] + ) address = address_p2wpkh(node.public_key(), coin) - self.assertEqual(address, 'grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne') + self.assertEqual(address, "grs1qw4teyraux2s77nhjdwh9ar8rl9dt7zww8r6lne") -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.approver.py b/core/tests/test_apps.bitcoin.approver.py index 3645216f47..dd9152b716 100644 --- a/core/tests/test_apps.bitcoin.approver.py +++ b/core/tests/test_apps.bitcoin.approver.py @@ -22,17 +22,16 @@ from apps.bitcoin import writers class TestApprover(unittest.TestCase): - def setUp(self): - self.coin = coins.by_name('Bitcoin') + self.coin = coins.by_name("Bitcoin") self.fee_rate_percent = 0.3 - self.no_fee_threshold=1000000 - self.min_registrable_amount=5000 + self.no_fee_threshold = 1000000 + self.min_registrable_amount = 5000 self.coordinator_name = "www.example.com" # Private key for signing and masking CoinJoin requests. # m/0h for "all all ... all" seed. - self.private_key = b'?S\ti\x8b\xc5o{,\xab\x03\x194\xea\xa8[_:\xeb\xdf\xce\xef\xe50\xf17D\x98`\xb9dj' + self.private_key = b"?S\ti\x8b\xc5o{,\xab\x03\x194\xea\xa8[_:\xeb\xdf\xce\xef\xe50\xf17D\x98`\xb9dj" self.node = bip32.HDNode( depth=0, @@ -42,12 +41,16 @@ class TestApprover(unittest.TestCase): private_key=b"\x01" * 32, curve_name="secp256k1", ) - self.tweaked_node_pubkey = b"\x02" + bip340.tweak_public_key(self.node.public_key()[1:]) + self.tweaked_node_pubkey = b"\x02" + bip340.tweak_public_key( + self.node.public_key()[1:] + ) self.msg_auth = AuthorizeCoinJoin( coordinator=self.coordinator_name, max_rounds=10, - max_coordinator_fee_rate=int(self.fee_rate_percent * 10**FEE_RATE_DECIMALS), + max_coordinator_fee_rate=int( + self.fee_rate_percent * 10**FEE_RATE_DECIMALS + ), max_fee_per_kvbyte=7000, address_n=[H_(10025), H_(0), H_(0), H_(1)], coin_name=self.coin.coin_name, @@ -59,7 +62,9 @@ class TestApprover(unittest.TestCase): mask_public_key = secp256k1.publickey(self.private_key) coinjoin_flags = bytearray() for txi in inputs: - shared_secret = secp256k1.multiply(self.private_key, self.tweaked_node_pubkey)[1:33] + shared_secret = secp256k1.multiply( + self.private_key, self.tweaked_node_pubkey + )[1:33] h_mask = HashWriter(sha256()) writers.write_bytes_fixed(h_mask, shared_secret, 32) writers.write_bytes_reversed(h_mask, txi.prev_hash, writers.TX_HASH_SIZE) @@ -71,11 +76,11 @@ class TestApprover(unittest.TestCase): # Compute CoinJoin request signature. h_request = HashWriter(sha256(b"CJR1")) - writers.write_bytes_prefixed( - h_request, self.coordinator_name.encode() - ) + writers.write_bytes_prefixed(h_request, self.coordinator_name.encode()) writers.write_uint32(h_request, self.coin.slip44) - writers.write_uint32(h_request, int(self.fee_rate_percent * 10**FEE_RATE_DECIMALS)) + writers.write_uint32( + h_request, int(self.fee_rate_percent * 10**FEE_RATE_DECIMALS) + ) writers.write_uint64(h_request, self.no_fee_threshold) writers.write_uint64(h_request, self.min_registrable_amount) writers.write_bytes_fixed(h_request, mask_public_key, 33) @@ -105,31 +110,34 @@ class TestApprover(unittest.TestCase): amount=denomination, script_pubkey=bytes(22), script_type=InputScriptType.EXTERNAL, - sequence=0xffffffff, + sequence=0xFFFFFFFF, witness="", - ) for i in range(99) + ) + for i in range(99) ] # Our input. - inputs.insert(30, + inputs.insert( + 30, TxInput( prev_hash=bytes(32), prev_index=0, address_n=[H_(10025), H_(0), H_(0), H_(1), 0, 1], amount=denomination, script_type=InputScriptType.SPENDTAPROOT, - sequence=0xffffffff, - ) + sequence=0xFFFFFFFF, + ), ) # Other's CoinJoined outputs. outputs = [ TxOutput( address="", - amount=denomination-fees, + amount=denomination - fees, script_type=OutputScriptType.PAYTOTAPROOT, payment_req_index=0, - ) for i in range(99) + ) + for i in range(99) ] # Our CoinJoined output. @@ -138,10 +146,10 @@ class TestApprover(unittest.TestCase): TxOutput( address="", address_n=[H_(10025), H_(0), H_(0), H_(1), 0, 2], - amount=denomination-fees, + amount=denomination - fees, script_type=OutputScriptType.PAYTOTAPROOT, payment_req_index=0, - ) + ), ) # Coordinator's output. @@ -155,7 +163,13 @@ class TestApprover(unittest.TestCase): ) coinjoin_req = self.make_coinjoin_request(inputs) - tx = SignTx(outputs_count=len(outputs), inputs_count=len(inputs), coin_name=self.coin.coin_name, lock_time=0, coinjoin_request=coinjoin_req) + tx = SignTx( + outputs_count=len(outputs), + inputs_count=len(inputs), + coin_name=self.coin.coin_name, + lock_time=0, + coinjoin_request=coinjoin_req, + ) authorization = CoinJoinAuthorization(self.msg_auth) approver = CoinJoinApprover(tx, self.coin, authorization) signer = Bitcoin(tx, None, self.coin, approver) @@ -180,11 +194,17 @@ class TestApprover(unittest.TestCase): prev_index=0, address_n=[H_(10025), H_(0), H_(0), H_(1), 0], amount=10000000, - script_type=InputScriptType.SPENDTAPROOT + script_type=InputScriptType.SPENDTAPROOT, ) coinjoin_req = self.make_coinjoin_request([txi]) - tx = SignTx(outputs_count=201, inputs_count=100, coin_name=self.coin.coin_name, lock_time=0, coinjoin_request=coinjoin_req) + tx = SignTx( + outputs_count=201, + inputs_count=100, + coin_name=self.coin.coin_name, + lock_time=0, + coinjoin_request=coinjoin_req, + ) authorization = CoinJoinAuthorization(self.msg_auth) approver = CoinJoinApprover(tx, self.coin, authorization) @@ -197,11 +217,17 @@ class TestApprover(unittest.TestCase): prev_index=0, address_n=[H_(10025), H_(0), H_(1), H_(1), 0, 0], amount=10000000, - script_type=InputScriptType.SPENDTAPROOT + script_type=InputScriptType.SPENDTAPROOT, ) coinjoin_req = self.make_coinjoin_request([txi]) - tx = SignTx(outputs_count=201, inputs_count=100, coin_name=self.coin.coin_name, lock_time=0, coinjoin_request=coinjoin_req) + tx = SignTx( + outputs_count=201, + inputs_count=100, + coin_name=self.coin.coin_name, + lock_time=0, + coinjoin_request=coinjoin_req, + ) authorization = CoinJoinAuthorization(self.msg_auth) approver = CoinJoinApprover(tx, self.coin, authorization) @@ -209,5 +235,5 @@ class TestApprover(unittest.TestCase): await_result(approver.add_internal_input(txi, self.node)) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.authorization.py b/core/tests/test_apps.bitcoin.authorization.py index 3678821423..7cca018713 100644 --- a/core/tests/test_apps.bitcoin.authorization.py +++ b/core/tests/test_apps.bitcoin.authorization.py @@ -14,7 +14,7 @@ _ROUND_ID_LEN = 32 class TestAuthorization(unittest.TestCase): - coin = coins.by_name('Bitcoin') + coin = coins.by_name("Bitcoin") def setUp(self): self.msg_auth = AuthorizeCoinJoin( @@ -37,7 +37,8 @@ class TestAuthorization(unittest.TestCase): coin_name=self.coin.coin_name, script_type=InputScriptType.SPENDWITNESS, user_confirmation=True, - commitment_data=b"\x0fwww.example.com" + int.to_bytes(1, _ROUND_ID_LEN, "big"), + commitment_data=b"\x0fwww.example.com" + + int.to_bytes(1, _ROUND_ID_LEN, "big"), ) self.assertFalse(self.authorization.check_get_ownership_proof(msg)) @@ -49,7 +50,8 @@ class TestAuthorization(unittest.TestCase): coin_name=self.coin.coin_name, script_type=InputScriptType.SPENDWITNESS, user_confirmation=True, - commitment_data=b"\x0fwww.example.com" + int.to_bytes(1, _ROUND_ID_LEN, "big"), + commitment_data=b"\x0fwww.example.com" + + int.to_bytes(1, _ROUND_ID_LEN, "big"), ) self.assertFalse(self.authorization.check_get_ownership_proof(msg)) @@ -61,7 +63,8 @@ class TestAuthorization(unittest.TestCase): coin_name=self.coin.coin_name, script_type=InputScriptType.SPENDWITNESS, user_confirmation=True, - commitment_data=b"\x0fwww.example.org" + int.to_bytes(1, _ROUND_ID_LEN, "big"), + commitment_data=b"\x0fwww.example.org" + + int.to_bytes(1, _ROUND_ID_LEN, "big"), ) self.assertFalse(self.authorization.check_get_ownership_proof(msg)) @@ -72,7 +75,8 @@ class TestAuthorization(unittest.TestCase): coin_name=self.coin.coin_name, script_type=InputScriptType.SPENDWITNESS, user_confirmation=True, - commitment_data=b"\x0ewww.example.com" + int.to_bytes(1, _ROUND_ID_LEN - 1, "big"), + commitment_data=b"\x0ewww.example.com" + + int.to_bytes(1, _ROUND_ID_LEN - 1, "big"), ) self.assertFalse(self.authorization.check_get_ownership_proof(msg)) @@ -82,7 +86,8 @@ class TestAuthorization(unittest.TestCase): coin_name=self.coin.coin_name, script_type=InputScriptType.SPENDWITNESS, user_confirmation=True, - commitment_data=b"\x10www.example.com" + int.to_bytes(1, _ROUND_ID_LEN + 1, "big"), + commitment_data=b"\x10www.example.com" + + int.to_bytes(1, _ROUND_ID_LEN + 1, "big"), ) self.assertFalse(self.authorization.check_get_ownership_proof(msg)) @@ -94,14 +99,20 @@ class TestAuthorization(unittest.TestCase): coin_name=self.coin.coin_name, script_type=InputScriptType.SPENDWITNESS, user_confirmation=True, - commitment_data=b"\x0fwww.example.com" + int.to_bytes(1, _ROUND_ID_LEN, "big"), + commitment_data=b"\x0fwww.example.com" + + int.to_bytes(1, _ROUND_ID_LEN, "big"), ) self.assertTrue(self.authorization.check_get_ownership_proof(msg)) def test_approve_sign_tx(self): - msg = SignTx(outputs_count=10, inputs_count=21, coin_name=self.coin.coin_name, lock_time=0) + msg = SignTx( + outputs_count=10, + inputs_count=21, + coin_name=self.coin.coin_name, + lock_time=0, + ) self.assertTrue(self.authorization.approve_sign_tx(msg)) self.assertTrue(self.authorization.approve_sign_tx(msg)) @@ -109,5 +120,5 @@ class TestAuthorization(unittest.TestCase): self.assertFalse(self.authorization.approve_sign_tx(msg)) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.keychain.py b/core/tests/test_apps.bitcoin.keychain.py index b78caefcb3..b51bcb92a4 100644 --- a/core/tests/test_apps.bitcoin.keychain.py +++ b/core/tests/test_apps.bitcoin.keychain.py @@ -149,7 +149,6 @@ class TestAltcoinKeychains(unittest.TestCase): [H_(45), 99, 1, 1000], [H_(49), H_(0), H_(0), 0, 0], [H_(84), H_(0), H_(0), 0, 0], - [44, 2, 0, 0, 0], [H_(44), H_(2), H_(0)], [H_(44), H_(2), H_(0), 0, 0, 0], diff --git a/core/tests/test_apps.bitcoin.ownership_proof.py b/core/tests/test_apps.bitcoin.ownership_proof.py index 2a4bfd1d96..1d9710443e 100644 --- a/core/tests/test_apps.bitcoin.ownership_proof.py +++ b/core/tests/test_apps.bitcoin.ownership_proof.py @@ -8,24 +8,40 @@ from apps.common import coins from apps.common.keychain import Keychain from apps.common.paths import HARDENED, AlwaysMatchingSchema from apps.bitcoin import ownership, scripts -from apps.bitcoin.addresses import _address_p2tr, address_p2wpkh, address_p2wpkh_in_p2sh, _address_multisig_p2wsh, _address_multisig_p2wsh_in_p2sh, _address_multisig_p2sh +from apps.bitcoin.addresses import ( + _address_p2tr, + address_p2wpkh, + address_p2wpkh_in_p2sh, + _address_multisig_p2wsh, + _address_multisig_p2wsh_in_p2sh, + _address_multisig_p2sh, +) from apps.bitcoin.multisig import multisig_get_pubkeys class TestOwnershipProof(unittest.TestCase): - def test_p2wpkh_gen_proof(self): # SLIP-0019 test vector 1 - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "") + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) commitment_data = b"" node = keychain.derive([84 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0]) address = address_p2wpkh(node.public_key(), coin) script_pubkey = scripts.output_derive_script(address, coin) ownership_id = ownership.get_identifier(script_pubkey, keychain) - self.assertEqual(ownership_id, unhexlify("a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad5707")) + self.assertEqual( + ownership_id, + unhexlify( + "a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad5707" + ), + ) proof, signature = ownership.generate_proof( node=node, @@ -37,15 +53,34 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("3045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac5")) - self.assertEqual(proof, unhexlify("534c00190001a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad57070002483045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac50121032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b")) - self.assertFalse(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + self.assertEqual( + signature, + unhexlify( + "3045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac5" + ), + ) + self.assertEqual( + proof, + unhexlify( + "534c00190001a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad57070002483045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac50121032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b" + ), + ) + self.assertFalse( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) def test_p2wpkh_in_p2sh_gen_proof(self): # SLIP-0019 test vector 2 - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "") + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) commitment_data = b"TREZOR" node = keychain.derive([49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0]) @@ -53,7 +88,12 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey = scripts.output_derive_script(address, coin) ownership_id = ownership.get_identifier(script_pubkey, keychain) - self.assertEqual(ownership_id, unhexlify("92caf0b8daf78f1d388dbbceaec34bd2dabc31b217e32343663667f6694a3f46")) + self.assertEqual( + ownership_id, + unhexlify( + "92caf0b8daf78f1d388dbbceaec34bd2dabc31b217e32343663667f6694a3f46" + ), + ) proof, signature = ownership.generate_proof( node=node, @@ -65,22 +105,46 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("304402207f1003c59661ddf564af2e10d19ad8d6a1a47ad30e7052197d95fd65d186a67802205f0a804509980fec1b063554aadd8fb871d7c9fe934087cba2da09cbeff8531c")) - self.assertEqual(proof, unhexlify("534c0019010192caf0b8daf78f1d388dbbceaec34bd2dabc31b217e32343663667f6694a3f4617160014e0cffbee1925a411844f44c3b8d81365ab51d0360247304402207f1003c59661ddf564af2e10d19ad8d6a1a47ad30e7052197d95fd65d186a67802205f0a804509980fec1b063554aadd8fb871d7c9fe934087cba2da09cbeff8531c012103a961687895a78da9aef98eed8e1f2a3e91cfb69d2f3cf11cbd0bb1773d951928")) - self.assertFalse(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + self.assertEqual( + signature, + unhexlify( + "304402207f1003c59661ddf564af2e10d19ad8d6a1a47ad30e7052197d95fd65d186a67802205f0a804509980fec1b063554aadd8fb871d7c9fe934087cba2da09cbeff8531c" + ), + ) + self.assertEqual( + proof, + unhexlify( + "534c0019010192caf0b8daf78f1d388dbbceaec34bd2dabc31b217e32343663667f6694a3f4617160014e0cffbee1925a411844f44c3b8d81365ab51d0360247304402207f1003c59661ddf564af2e10d19ad8d6a1a47ad30e7052197d95fd65d186a67802205f0a804509980fec1b063554aadd8fb871d7c9fe934087cba2da09cbeff8531c012103a961687895a78da9aef98eed8e1f2a3e91cfb69d2f3cf11cbd0bb1773d951928" + ), + ) + self.assertFalse( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) def test_p2tr_gen_proof(self): # SLIP-0019 test vector 5 - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "") + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) commitment_data = b"" node = keychain.derive([86 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0]) address = _address_p2tr(node.public_key(), coin) script_pubkey = scripts.output_derive_script(address, coin) ownership_id = ownership.get_identifier(script_pubkey, keychain) - self.assertEqual(ownership_id, unhexlify("dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec")) + self.assertEqual( + ownership_id, + unhexlify( + "dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec" + ), + ) proof, signature = ownership.generate_proof( node=node, @@ -92,22 +156,46 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("647d6af883107a870417e808abe424882bd28ee04a28ba85a7e99400e1b9485075733695964c2a0fa02d4439ab80830e9566ccbd10f2597f5513eff9f03a0497")) - self.assertEqual(proof, unhexlify("534c00190001dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec000140647d6af883107a870417e808abe424882bd28ee04a28ba85a7e99400e1b9485075733695964c2a0fa02d4439ab80830e9566ccbd10f2597f5513eff9f03a0497")) - self.assertFalse(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + self.assertEqual( + signature, + unhexlify( + "647d6af883107a870417e808abe424882bd28ee04a28ba85a7e99400e1b9485075733695964c2a0fa02d4439ab80830e9566ccbd10f2597f5513eff9f03a0497" + ), + ) + self.assertEqual( + proof, + unhexlify( + "534c00190001dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec000140647d6af883107a870417e808abe424882bd28ee04a28ba85a7e99400e1b9485075733695964c2a0fa02d4439ab80830e9566ccbd10f2597f5513eff9f03a0497" + ), + ) + self.assertFalse( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) def test_p2pkh_gen_proof(self): # SLIP-0019 test vector 3 - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), 'TREZOR') - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "TREZOR") + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) commitment_data = b"" node = keychain.derive([44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0]) address = node.address(coin.address_type) script_pubkey = scripts.output_derive_script(address, coin) ownership_id = ownership.get_identifier(script_pubkey, keychain) - self.assertEqual(ownership_id, unhexlify("ccc49ac5fede0efc80725fbda8b763d4e62a221c51cc5425076cffa7722c0bda")) + self.assertEqual( + ownership_id, + unhexlify( + "ccc49ac5fede0efc80725fbda8b763d4e62a221c51cc5425076cffa7722c0bda" + ), + ) proof, signature = ownership.generate_proof( node=node, @@ -119,55 +207,103 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("3045022100e818002d0a85438a7f2140503a6aa0a6af6002fa956d0101fd3db24e776e546f0220430fd59dc1498bc96ab6e71a4829b60224828cf1fc35edc98e0973db203ca3f0")) - self.assertEqual(proof, unhexlify("534c00190001ccc49ac5fede0efc80725fbda8b763d4e62a221c51cc5425076cffa7722c0bda6b483045022100e818002d0a85438a7f2140503a6aa0a6af6002fa956d0101fd3db24e776e546f0220430fd59dc1498bc96ab6e71a4829b60224828cf1fc35edc98e0973db203ca3f0012102f63159e21fbcb54221ec993def967ad2183a9c243c8bff6e7d60f4d5ed3b386500")) - self.assertFalse(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + self.assertEqual( + signature, + unhexlify( + "3045022100e818002d0a85438a7f2140503a6aa0a6af6002fa956d0101fd3db24e776e546f0220430fd59dc1498bc96ab6e71a4829b60224828cf1fc35edc98e0973db203ca3f0" + ), + ) + self.assertEqual( + proof, + unhexlify( + "534c00190001ccc49ac5fede0efc80725fbda8b763d4e62a221c51cc5425076cffa7722c0bda6b483045022100e818002d0a85438a7f2140503a6aa0a6af6002fa956d0101fd3db24e776e546f0220430fd59dc1498bc96ab6e71a4829b60224828cf1fc35edc98e0973db203ca3f0012102f63159e21fbcb54221ec993def967ad2183a9c243c8bff6e7d60f4d5ed3b386500" + ), + ) + self.assertFalse( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) def test_p2wpkh_verify_proof(self): # SLIP-0019 test vector 1 - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), 'TREZOR') - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "TREZOR") + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) commitment_data = b"" # Proof for "all all ... all" seed without passphrase. script_pubkey = unhexlify("0014b2f771c370ccf219cd3059cda92bdf7f00cf2103") - proof = unhexlify("534c00190001a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad57070002483045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac50121032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b") - self.assertTrue(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + proof = unhexlify( + "534c00190001a122407efc198211c81af4450f40b235d54775efd934d16b9e31c6ce9bad57070002483045022100c0dc28bb563fc5fea76cacff75dba9cb4122412faae01937cdebccfb065f9a7002202e980bfbd8a434a7fc4cd2ca49da476ce98ca097437f8159b1a386b41fcdfac50121032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b" + ) + self.assertTrue( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) def test_p2tr_verify_proof(self): # SLIP-0019 test vector 5 - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), 'TREZOR') - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "TREZOR") + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) commitment_data = b"" # Proof for "all all ... all" seed without passphrase. - script_pubkey = unhexlify("51204102897557de0cafea0a8401ea5b59668eccb753e4b100aebe6a19609f3cc79f") - proof = unhexlify("534c00190001dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec0001401b553e5b9cc787b531bbc78417aea901272b4ea905136a2babc4d6ca471549743b5e0e39ddc14e620b254e42faa7f6d5bd953e97aa231d764d21bc5a58e8b7d9") - self.assertTrue(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + script_pubkey = unhexlify( + "51204102897557de0cafea0a8401ea5b59668eccb753e4b100aebe6a19609f3cc79f" + ) + proof = unhexlify( + "534c00190001dc18066224b9e30e306303436dc18ab881c7266c13790350a3fe415e438135ec0001401b553e5b9cc787b531bbc78417aea901272b4ea905136a2babc4d6ca471549743b5e0e39ddc14e620b254e42faa7f6d5bd953e97aa231d764d21bc5a58e8b7d9" + ) + self.assertTrue( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) def test_p2wsh_gen_proof(self): # SLIP-0019 test vector 4 - coin = coins.by_name('Bitcoin') - seed1 = bip39.seed(' '.join(['all'] * 12), '') - seed2 = bip39.seed('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', '') - seed3 = bip39.seed('zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong', '') + coin = coins.by_name("Bitcoin") + seed1 = bip39.seed(" ".join(["all"] * 12), "") + seed2 = bip39.seed( + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + "", + ) + seed3 = bip39.seed("zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong", "") commitment_data = b"TREZOR" nodes = [] keychains = [] for seed in [seed1, seed2, seed3]: - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) keychains.append(keychain) node = keychain.derive([84 | HARDENED, 0 | HARDENED, 0 | HARDENED]) - nodes.append(HDNodeType( - depth=node.depth(), - child_num=node.child_num(), - fingerprint=node.fingerprint(), - chain_code=node.chain_code(), - public_key=node.public_key(), - )) + nodes.append( + HDNodeType( + depth=node.depth(), + child_num=node.child_num(), + fingerprint=node.fingerprint(), + chain_code=node.chain_code(), + public_key=node.public_key(), + ) + ) multisig = MultisigRedeemScriptType( nodes=nodes, @@ -179,10 +315,27 @@ class TestOwnershipProof(unittest.TestCase): pubkeys = multisig_get_pubkeys(multisig) address = _address_multisig_p2wsh(pubkeys, multisig.m, coin.bech32_prefix) script_pubkey = scripts.output_derive_script(address, coin) - ownership_ids = [ownership.get_identifier(script_pubkey, keychain) for keychain in keychains] - self.assertEqual(ownership_ids[0], unhexlify("309c4ffec5c228cc836b51d572c0a730dbabd39df9f01862502ac9eabcdeb94a")) - self.assertEqual(ownership_ids[1], unhexlify("46307177b959c48bf2eb516e0463bb651aad388c7f8f597320df7854212fa344")) - self.assertEqual(ownership_ids[2], unhexlify("3892f9573e08cedff9160b243759520733a980fed45b131a8bba171317ae5d94")) + ownership_ids = [ + ownership.get_identifier(script_pubkey, keychain) for keychain in keychains + ] + self.assertEqual( + ownership_ids[0], + unhexlify( + "309c4ffec5c228cc836b51d572c0a730dbabd39df9f01862502ac9eabcdeb94a" + ), + ) + self.assertEqual( + ownership_ids[1], + unhexlify( + "46307177b959c48bf2eb516e0463bb651aad388c7f8f597320df7854212fa344" + ), + ) + self.assertEqual( + ownership_ids[2], + unhexlify( + "3892f9573e08cedff9160b243759520733a980fed45b131a8bba171317ae5d94" + ), + ) # Sign with the first key. _, signature = ownership.generate_proof( @@ -195,7 +348,12 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("30450221009d8cd2d792633732b3a406ea86072e94c72c0d1ffb5ddde466993ee2142eeef502206fa9c6273ab35400ebf689028ebcf8d2031edb3326106339e92d499652dc4303")) + self.assertEqual( + signature, + unhexlify( + "30450221009d8cd2d792633732b3a406ea86072e94c72c0d1ffb5ddde466993ee2142eeef502206fa9c6273ab35400ebf689028ebcf8d2031edb3326106339e92d499652dc4303" + ), + ) multisig.signatures[0] = signature # Sign with the third key. @@ -209,26 +367,47 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("304402205fae1218bc4600ad6c28b6093e8f3757603681b024e60f1d92fca579bfce210b022011d6f1c6ef1c7f7601f635ed237dafc774386dd9f4be0aef85e3af3f095d8a92")) - self.assertEqual(proof, unhexlify("534c00190003309c4ffec5c228cc836b51d572c0a730dbabd39df9f01862502ac9eabcdeb94a46307177b959c48bf2eb516e0463bb651aad388c7f8f597320df7854212fa3443892f9573e08cedff9160b243759520733a980fed45b131a8bba171317ae5d940004004830450221009d8cd2d792633732b3a406ea86072e94c72c0d1ffb5ddde466993ee2142eeef502206fa9c6273ab35400ebf689028ebcf8d2031edb3326106339e92d499652dc43030147304402205fae1218bc4600ad6c28b6093e8f3757603681b024e60f1d92fca579bfce210b022011d6f1c6ef1c7f7601f635ed237dafc774386dd9f4be0aef85e3af3f095d8a9201695221032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b2103025324888e429ab8e3dbaf1f7802648b9cd01e9b418485c5fa4c1b9b5700e1a621033057150eb57e2b21d69866747f3d377e928f864fa88ecc5ddb1c0e501cce3f8153ae")) - self.assertFalse(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + self.assertEqual( + signature, + unhexlify( + "304402205fae1218bc4600ad6c28b6093e8f3757603681b024e60f1d92fca579bfce210b022011d6f1c6ef1c7f7601f635ed237dafc774386dd9f4be0aef85e3af3f095d8a92" + ), + ) + self.assertEqual( + proof, + unhexlify( + "534c00190003309c4ffec5c228cc836b51d572c0a730dbabd39df9f01862502ac9eabcdeb94a46307177b959c48bf2eb516e0463bb651aad388c7f8f597320df7854212fa3443892f9573e08cedff9160b243759520733a980fed45b131a8bba171317ae5d940004004830450221009d8cd2d792633732b3a406ea86072e94c72c0d1ffb5ddde466993ee2142eeef502206fa9c6273ab35400ebf689028ebcf8d2031edb3326106339e92d499652dc43030147304402205fae1218bc4600ad6c28b6093e8f3757603681b024e60f1d92fca579bfce210b022011d6f1c6ef1c7f7601f635ed237dafc774386dd9f4be0aef85e3af3f095d8a9201695221032ef68318c8f6aaa0adec0199c69901f0db7d3485eb38d9ad235221dc3d61154b2103025324888e429ab8e3dbaf1f7802648b9cd01e9b418485c5fa4c1b9b5700e1a621033057150eb57e2b21d69866747f3d377e928f864fa88ecc5ddb1c0e501cce3f8153ae" + ), + ) + self.assertFalse( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) def test_p2wsh_in_p2sh_gen_proof(self): - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "") + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) commitment_data = b"" nodes = [] for index in range(1, 6): node = keychain.derive([49 | HARDENED, 0 | HARDENED, index | HARDENED]) - nodes.append(HDNodeType( - depth=node.depth(), - child_num=node.child_num(), - fingerprint=node.fingerprint(), - chain_code=node.chain_code(), - public_key=node.public_key(), - )) + nodes.append( + HDNodeType( + depth=node.depth(), + child_num=node.child_num(), + fingerprint=node.fingerprint(), + chain_code=node.chain_code(), + public_key=node.public_key(), + ) + ) multisig = MultisigRedeemScriptType( nodes=nodes, @@ -241,8 +420,13 @@ class TestOwnershipProof(unittest.TestCase): address = _address_multisig_p2wsh_in_p2sh(pubkeys, multisig.m, coin) script_pubkey = scripts.output_derive_script(address, coin) ownership_id = ownership.get_identifier(script_pubkey, keychain) - ownership_ids = [b'\x00' * 32, b'\x01' * 32, b'\x02' * 32, ownership_id] - self.assertEqual(ownership_id, unhexlify("66f99db388dfa7ae137f7bdb5f0004b4d6968014921cfaff1fec042e3bb83ae0")) + ownership_ids = [b"\x00" * 32, b"\x01" * 32, b"\x02" * 32, ownership_id] + self.assertEqual( + ownership_id, + unhexlify( + "66f99db388dfa7ae137f7bdb5f0004b4d6968014921cfaff1fec042e3bb83ae0" + ), + ) # Sign with the second key. _, signature = ownership.generate_proof( @@ -255,7 +439,12 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("30450221008c2c61ac2b50fd5f644baf5e8815b41caaf41d3b085d6e79c1ab38ab9ff4ef0702206742f837eddd4484ebf642e0bcb9621fe39165d3c9d62706bb01b2a8d854fb39")) + self.assertEqual( + signature, + unhexlify( + "30450221008c2c61ac2b50fd5f644baf5e8815b41caaf41d3b085d6e79c1ab38ab9ff4ef0702206742f837eddd4484ebf642e0bcb9621fe39165d3c9d62706bb01b2a8d854fb39" + ), + ) multisig.signatures[1] = signature # Sign with the fourth key. @@ -269,7 +458,12 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("304402200f5ec86b369f6a980a237944a1a06e6615afb147c6d84baf28cd1b8a58faf52702205614240e1582adeaa84685398a24d3678d0781371678b402b290ae3de3e058ee")) + self.assertEqual( + signature, + unhexlify( + "304402200f5ec86b369f6a980a237944a1a06e6615afb147c6d84baf28cd1b8a58faf52702205614240e1582adeaa84685398a24d3678d0781371678b402b290ae3de3e058ee" + ), + ) multisig.signatures[3] = signature # Sign with the fifth key. @@ -283,26 +477,47 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("304402201ce53fcd797b6f5ceefa839817d6285551ff420457503ae2dab3f90ca1f6f2330220522f030423c22d5582c4f8fe243839031f584642ba5c085af712145d1e8146b7")) - self.assertEqual(proof, unhexlify("534c0019000400000000000000000000000000000000000000000000000000000000000000000101010101010101010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202020202020202020266f99db388dfa7ae137f7bdb5f0004b4d6968014921cfaff1fec042e3bb83ae0232200208c256ed80a97a421656daa1468f6d4d43f475cb52ed79532d8bcb3155182981205004830450221008c2c61ac2b50fd5f644baf5e8815b41caaf41d3b085d6e79c1ab38ab9ff4ef0702206742f837eddd4484ebf642e0bcb9621fe39165d3c9d62706bb01b2a8d854fb390147304402200f5ec86b369f6a980a237944a1a06e6615afb147c6d84baf28cd1b8a58faf52702205614240e1582adeaa84685398a24d3678d0781371678b402b290ae3de3e058ee0147304402201ce53fcd797b6f5ceefa839817d6285551ff420457503ae2dab3f90ca1f6f2330220522f030423c22d5582c4f8fe243839031f584642ba5c085af712145d1e8146b701ad5321032922ce9b0b71ae2d2d8a7f239610ae8226e0fb8c0f445ec4c88cf9aa4787f44b21028373a1cdb9a1afbc67e57f75eeea1f53e7210ae8ec4b3441a5f2bc4a250b663c21028ab4c06e3ad19053b370eff097697d4cb6d3738712ebcdcdc27c58a5639ac3aa2103e3247fab300aeba459257e4605245f85378ecbfe092ca3bc55ec1259baa456f521023b0d8d97398d97c4dba10f788344abd4bd1058ad3959724d32079ad04bdbde8a55ae")) - self.assertFalse(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + self.assertEqual( + signature, + unhexlify( + "304402201ce53fcd797b6f5ceefa839817d6285551ff420457503ae2dab3f90ca1f6f2330220522f030423c22d5582c4f8fe243839031f584642ba5c085af712145d1e8146b7" + ), + ) + self.assertEqual( + proof, + unhexlify( + "534c0019000400000000000000000000000000000000000000000000000000000000000000000101010101010101010101010101010101010101010101010101010101010101020202020202020202020202020202020202020202020202020202020202020266f99db388dfa7ae137f7bdb5f0004b4d6968014921cfaff1fec042e3bb83ae0232200208c256ed80a97a421656daa1468f6d4d43f475cb52ed79532d8bcb3155182981205004830450221008c2c61ac2b50fd5f644baf5e8815b41caaf41d3b085d6e79c1ab38ab9ff4ef0702206742f837eddd4484ebf642e0bcb9621fe39165d3c9d62706bb01b2a8d854fb390147304402200f5ec86b369f6a980a237944a1a06e6615afb147c6d84baf28cd1b8a58faf52702205614240e1582adeaa84685398a24d3678d0781371678b402b290ae3de3e058ee0147304402201ce53fcd797b6f5ceefa839817d6285551ff420457503ae2dab3f90ca1f6f2330220522f030423c22d5582c4f8fe243839031f584642ba5c085af712145d1e8146b701ad5321032922ce9b0b71ae2d2d8a7f239610ae8226e0fb8c0f445ec4c88cf9aa4787f44b21028373a1cdb9a1afbc67e57f75eeea1f53e7210ae8ec4b3441a5f2bc4a250b663c21028ab4c06e3ad19053b370eff097697d4cb6d3738712ebcdcdc27c58a5639ac3aa2103e3247fab300aeba459257e4605245f85378ecbfe092ca3bc55ec1259baa456f521023b0d8d97398d97c4dba10f788344abd4bd1058ad3959724d32079ad04bdbde8a55ae" + ), + ) + self.assertFalse( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) def test_p2sh_gen_proof(self): - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), '') - keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema], slip21_namespaces=[[b"SLIP-0019"]]) + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "") + keychain = Keychain( + seed, + coin.curve_name, + [AlwaysMatchingSchema], + slip21_namespaces=[[b"SLIP-0019"]], + ) commitment_data = b"TREZOR" nodes = [] for index in range(1, 3): node = keychain.derive([48 | HARDENED, 0 | HARDENED, index | HARDENED]) - nodes.append(HDNodeType( - depth=node.depth(), - child_num=node.child_num(), - fingerprint=node.fingerprint(), - chain_code=node.chain_code(), - public_key=node.public_key(), - )) + nodes.append( + HDNodeType( + depth=node.depth(), + child_num=node.child_num(), + fingerprint=node.fingerprint(), + chain_code=node.chain_code(), + public_key=node.public_key(), + ) + ) multisig = MultisigRedeemScriptType( nodes=nodes, @@ -315,8 +530,13 @@ class TestOwnershipProof(unittest.TestCase): address = _address_multisig_p2sh(pubkeys, multisig.m, coin) script_pubkey = scripts.output_derive_script(address, coin) ownership_id = ownership.get_identifier(script_pubkey, keychain) - ownership_ids = [b'\x00' * 32, ownership_id] - self.assertEqual(ownership_id, unhexlify("ce4ee8298ad105c3495a1d2b620343133521ab34de2450deeb32eec39475fef4")) + ownership_ids = [b"\x00" * 32, ownership_id] + self.assertEqual( + ownership_id, + unhexlify( + "ce4ee8298ad105c3495a1d2b620343133521ab34de2450deeb32eec39475fef4" + ), + ) # Sign with the first key. _, signature = ownership.generate_proof( @@ -329,7 +549,12 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("3044022058091b367ab67281963029435046abcb51057d143077a36737780a7cbcd6c1af02202f54147645b970c60b5b631b233ed93c15304294a4214b2c44b57db84815ca14")) + self.assertEqual( + signature, + unhexlify( + "3044022058091b367ab67281963029435046abcb51057d143077a36737780a7cbcd6c1af02202f54147645b970c60b5b631b233ed93c15304294a4214b2c44b57db84815ca14" + ), + ) multisig.signatures[0] = signature # Sign with the third key. @@ -343,10 +568,24 @@ class TestOwnershipProof(unittest.TestCase): script_pubkey=script_pubkey, commitment_data=commitment_data, ) - self.assertEqual(signature, unhexlify("304402200d8f270ea9a80678f266b3fbe6e4aa59aab46b440d8066dcf46fb46a4beaf58202201198d73e355158ebf532ca6527e28ea97b79594e016a65c7a0c68813c26271ff")) - self.assertEqual(proof, unhexlify("534c001900020000000000000000000000000000000000000000000000000000000000000000ce4ee8298ad105c3495a1d2b620343133521ab34de2450deeb32eec39475fef4d900473044022058091b367ab67281963029435046abcb51057d143077a36737780a7cbcd6c1af02202f54147645b970c60b5b631b233ed93c15304294a4214b2c44b57db84815ca140147304402200d8f270ea9a80678f266b3fbe6e4aa59aab46b440d8066dcf46fb46a4beaf58202201198d73e355158ebf532ca6527e28ea97b79594e016a65c7a0c68813c26271ff014752210203ed6187880ae932660086e55d4561a57952dd200aa3ed2aa66b73e5723a0ce7210360e7f32fd3c8dee27a166f6614c598929699ee66acdcbda5fb24571bf2ae1ca052ae00")) - self.assertFalse(ownership.verify_nonownership(proof, script_pubkey, commitment_data, keychain, coin)) + self.assertEqual( + signature, + unhexlify( + "304402200d8f270ea9a80678f266b3fbe6e4aa59aab46b440d8066dcf46fb46a4beaf58202201198d73e355158ebf532ca6527e28ea97b79594e016a65c7a0c68813c26271ff" + ), + ) + self.assertEqual( + proof, + unhexlify( + "534c001900020000000000000000000000000000000000000000000000000000000000000000ce4ee8298ad105c3495a1d2b620343133521ab34de2450deeb32eec39475fef4d900473044022058091b367ab67281963029435046abcb51057d143077a36737780a7cbcd6c1af02202f54147645b970c60b5b631b233ed93c15304294a4214b2c44b57db84815ca140147304402200d8f270ea9a80678f266b3fbe6e4aa59aab46b440d8066dcf46fb46a4beaf58202201198d73e355158ebf532ca6527e28ea97b79594e016a65c7a0c68813c26271ff014752210203ed6187880ae932660086e55d4561a57952dd200aa3ed2aa66b73e5723a0ce7210360e7f32fd3c8dee27a166f6614c598929699ee66acdcbda5fb24571bf2ae1ca052ae00" + ), + ) + self.assertFalse( + ownership.verify_nonownership( + proof, script_pubkey, commitment_data, keychain, coin + ) + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py b/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py index fcf4d54f44..77ae98c7d6 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.bip143.native_p2wpkh.py @@ -19,33 +19,51 @@ from trezor.crypto import bip39 class TestSegwitBip143NativeP2WPKH(unittest.TestCase): # pylint: disable=C0301 - tx = SignTx(coin_name='Bitcoin', version=1, lock_time=0x00000011, inputs_count=2, outputs_count=2) - inp1 = TxInput(address_n=[0], - # Trezor expects hash in reversed format - prev_hash=unhexlify('9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff'), - prev_index=0, - amount=625000000, # 6.25 btc - script_type=InputScriptType.SPENDWITNESS, - multisig=None, - sequence=0xffffffee) - inp2 = TxInput(address_n=[1], - # Trezor expects hash in reversed format - prev_hash=unhexlify('8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef'), - prev_index=1, - multisig=None, - amount=600000000, # 6 btc - script_type=InputScriptType.SPENDWITNESS, - sequence=0xffffffff) - out1 = TxOutput(address='1Cu32FVupVCgHkMMRJdYJugxwo2Aprgk7H', # derived - amount=0x0000000006b22c20, - script_type=OutputScriptType.PAYTOADDRESS, - multisig=None, - address_n=[]) - out2 = TxOutput(address='16TZ8J6Q5iZKBWizWzFAYnrsaox5Z5aBRV', # derived - amount=0x000000000d519390, - script_type=OutputScriptType.PAYTOADDRESS, - multisig=None, - address_n=[]) + tx = SignTx( + coin_name="Bitcoin", + version=1, + lock_time=0x00000011, + inputs_count=2, + outputs_count=2, + ) + inp1 = TxInput( + address_n=[0], + # Trezor expects hash in reversed format + prev_hash=unhexlify( + "9f96ade4b41d5433f4eda31e1738ec2b36f6e7d1420d94a6af99801a88f7f7ff" + ), + prev_index=0, + amount=625000000, # 6.25 btc + script_type=InputScriptType.SPENDWITNESS, + multisig=None, + sequence=0xFFFFFFEE, + ) + inp2 = TxInput( + address_n=[1], + # Trezor expects hash in reversed format + prev_hash=unhexlify( + "8ac60eb9575db5b2d987e29f301b5b819ea83a5c6579d282d189cc04b8e151ef" + ), + prev_index=1, + multisig=None, + amount=600000000, # 6 btc + script_type=InputScriptType.SPENDWITNESS, + sequence=0xFFFFFFFF, + ) + out1 = TxOutput( + address="1Cu32FVupVCgHkMMRJdYJugxwo2Aprgk7H", # derived + amount=0x0000000006B22C20, + script_type=OutputScriptType.PAYTOADDRESS, + multisig=None, + address_n=[], + ) + out2 = TxOutput( + address="16TZ8J6Q5iZKBWizWzFAYnrsaox5Z5aBRV", # derived + amount=0x000000000D519390, + script_type=OutputScriptType.PAYTOADDRESS, + multisig=None, + address_n=[], + ) def test_prevouts(self): coin = coins.by_name(self.tx.coin_name) @@ -53,19 +71,30 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase): sig_hasher.add_input(self.inp1, b"") sig_hasher.add_input(self.inp2, b"") prevouts_hash = get_tx_hash(sig_hasher.h_prevouts, double=coin.sign_hash_double) - self.assertEqual(hexlify(prevouts_hash), b'96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37') + self.assertEqual( + hexlify(prevouts_hash), + b"96b827c8483d4e9b96712b6713a7b68d6e8003a781feba36c31143470b4efd37", + ) def test_sequence(self): coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() sig_hasher.add_input(self.inp1, b"") sig_hasher.add_input(self.inp2, b"") - sequence_hash = get_tx_hash(sig_hasher.h_sequences, double=coin.sign_hash_double) - self.assertEqual(hexlify(sequence_hash), b'52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b') + sequence_hash = get_tx_hash( + sig_hasher.h_sequences, double=coin.sign_hash_double + ) + self.assertEqual( + hexlify(sequence_hash), + b"52b0a642eea2fb7ae638c36f6252b6750293dbe574a806984b8e4d8548339a3b", + ) def test_outputs(self): - seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '') + seed = bip39.seed( + "alcohol woman abuse must during monitor noble actual mixed trade anger aisle", + "", + ) coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() @@ -75,11 +104,17 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase): sig_hasher.add_output(txo_bin, script_pubkey) outputs_hash = get_tx_hash(sig_hasher.h_outputs, double=coin.sign_hash_double) - self.assertEqual(hexlify(outputs_hash), b'863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5') + self.assertEqual( + hexlify(outputs_hash), + b"863ef3e1a92afbfdb97f31ad0fc7683ee943e9abcf2501590ff8f6551f47e5e5", + ) def test_preimage_testdata(self): - seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '') + seed = bip39.seed( + "alcohol woman abuse must during monitor noble actual mixed trade anger aisle", + "", + ) coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() sig_hasher.add_input(self.inp1, b"") @@ -95,9 +130,14 @@ class TestSegwitBip143NativeP2WPKH(unittest.TestCase): # test data public key hash # only for input 2 - input 1 is not segwit - result = sig_hasher.hash143(self.inp2, [node.public_key()], 1, self.tx, coin, SigHashType.SIGHASH_ALL) - self.assertEqual(hexlify(result), b'2fa3f1351618b2532228d7182d3221d95c21fd3d496e7e22e9ded873cf022a8b') + result = sig_hasher.hash143( + self.inp2, [node.public_key()], 1, self.tx, coin, SigHashType.SIGHASH_ALL + ) + self.assertEqual( + hexlify(result), + b"2fa3f1351618b2532228d7182d3221d95c21fd3d496e7e22e9ded873cf022a8b", + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py b/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py index 024fdcd296..60d7e15809 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py +++ b/core/tests/test_apps.bitcoin.segwit.bip143.p2wpkh_in_p2sh.py @@ -19,42 +19,67 @@ from trezor.crypto import bip39 class TestSegwitBip143(unittest.TestCase): # pylint: disable=C0301 - tx = SignTx(coin_name='Bitcoin', version=1, lock_time=0x00000492, inputs_count=1, outputs_count=2) - inp1 = TxInput(address_n=[0], - # Trezor expects hash in reversed format - prev_hash=unhexlify('77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb'), - prev_index=1, - multisig=None, - amount=1000000000, # 10 btc - script_type=InputScriptType.SPENDP2SHWITNESS, # TODO: is this correct? - sequence=0xfffffffe) - out1 = TxOutput(address='1Fyxts6r24DpEieygQiNnWxUdb18ANa5p7', - amount=0x000000000bebb4b8, - script_type=OutputScriptType.PAYTOADDRESS, - multisig=None, - address_n=[]) - out2 = TxOutput(address='1Q5YjKVj5yQWHBBsyEBamkfph3cA6G9KK8', - amount=0x000000002faf0800, - script_type=OutputScriptType.PAYTOADDRESS, - multisig=None, - address_n=[]) + tx = SignTx( + coin_name="Bitcoin", + version=1, + lock_time=0x00000492, + inputs_count=1, + outputs_count=2, + ) + inp1 = TxInput( + address_n=[0], + # Trezor expects hash in reversed format + prev_hash=unhexlify( + "77541aeb3c4dac9260b68f74f44c973081a9d4cb2ebe8038b2d70faa201b6bdb" + ), + prev_index=1, + multisig=None, + amount=1000000000, # 10 btc + script_type=InputScriptType.SPENDP2SHWITNESS, # TODO: is this correct? + sequence=0xFFFFFFFE, + ) + out1 = TxOutput( + address="1Fyxts6r24DpEieygQiNnWxUdb18ANa5p7", + amount=0x000000000BEBB4B8, + script_type=OutputScriptType.PAYTOADDRESS, + multisig=None, + address_n=[], + ) + out2 = TxOutput( + address="1Q5YjKVj5yQWHBBsyEBamkfph3cA6G9KK8", + amount=0x000000002FAF0800, + script_type=OutputScriptType.PAYTOADDRESS, + multisig=None, + address_n=[], + ) def test_bip143_prevouts(self): coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() sig_hasher.add_input(self.inp1, b"") prevouts_hash = get_tx_hash(sig_hasher.h_prevouts, double=coin.sign_hash_double) - self.assertEqual(hexlify(prevouts_hash), b'b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a') + self.assertEqual( + hexlify(prevouts_hash), + b"b0287b4a252ac05af83d2dcef00ba313af78a3e9c329afa216eb3aa2a7b4613a", + ) def test_bip143_sequence(self): coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() sig_hasher.add_input(self.inp1, b"") - sequence_hash = get_tx_hash(sig_hasher.h_sequences, double=coin.sign_hash_double) - self.assertEqual(hexlify(sequence_hash), b'18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198') + sequence_hash = get_tx_hash( + sig_hasher.h_sequences, double=coin.sign_hash_double + ) + self.assertEqual( + hexlify(sequence_hash), + b"18606b350cd8bf565266bc352f0caddcf01e8fa789dd8a15386327cf8cabe198", + ) def test_bip143_outputs(self): - seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '') + seed = bip39.seed( + "alcohol woman abuse must during monitor noble actual mixed trade anger aisle", + "", + ) coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() @@ -64,10 +89,16 @@ class TestSegwitBip143(unittest.TestCase): sig_hasher.add_output(txo_bin, script_pubkey) outputs_hash = get_tx_hash(sig_hasher.h_outputs, double=coin.sign_hash_double) - self.assertEqual(hexlify(outputs_hash), b'de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83') + self.assertEqual( + hexlify(outputs_hash), + b"de984f44532e2173ca0d64314fcefe6d30da6f8cf27bafa706da61df8a226c83", + ) def test_bip143_preimage_testdata(self): - seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '') + seed = bip39.seed( + "alcohol woman abuse must during monitor noble actual mixed trade anger aisle", + "", + ) coin = coins.by_name(self.tx.coin_name) sig_hasher = BitcoinSigHasher() sig_hasher.add_input(self.inp1, b"") @@ -80,9 +111,14 @@ class TestSegwitBip143(unittest.TestCase): node = keychain.derive(self.inp1.address_n) # test data public key hash - result = sig_hasher.hash143(self.inp1, [node.public_key()], 1, self.tx, coin, SigHashType.SIGHASH_ALL) - self.assertEqual(hexlify(result), b'6e28aca7041720995d4acf59bbda64eef5d6f23723d23f2e994757546674bbd9') + result = sig_hasher.hash143( + self.inp1, [node.public_key()], 1, self.tx, coin, SigHashType.SIGHASH_ALL + ) + self.assertEqual( + hexlify(result), + b"6e28aca7041720995d4acf59bbda64eef5d6f23723d23f2e994757546674bbd9", + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.segwit.bip341.p2tr.py b/core/tests/test_apps.bitcoin.segwit.bip341.p2tr.py index 14352bcef3..b86eec1e9d 100644 --- a/core/tests/test_apps.bitcoin.segwit.bip341.p2tr.py +++ b/core/tests/test_apps.bitcoin.segwit.bip341.p2tr.py @@ -11,115 +11,180 @@ from trezor.enums import InputScriptType VECTORS = [ { # https://github.com/bitcoin/bips/pull/1225/commits/f7af1f73b287c14cf2f63afcb8d199feaf6ab5e1 - "sign_tx": SignTx(coin_name='Bitcoin', version=2, lock_time=0x1dcd6500, inputs_count=9, outputs_count=2), + "sign_tx": SignTx( + coin_name="Bitcoin", + version=2, + lock_time=0x1DCD6500, + inputs_count=9, + outputs_count=2, + ), "inputs": [ TxInput( amount=420000000, - prev_hash=unhexlify('9c4e333b5f116359b5f5578fe4a74c6f58b3bab9d28149a583da86f6bf0ce27d'), + prev_hash=unhexlify( + "9c4e333b5f116359b5f5578fe4a74c6f58b3bab9d28149a583da86f6bf0ce27d" + ), prev_index=1, - script_pubkey=unhexlify('512053a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343'), + script_pubkey=unhexlify( + "512053a1f6e454df1aa2776a2814a721372d6258050de330b3c6d10ee8f4e0dda343" + ), script_type=InputScriptType.SPENDTAPROOT, sequence=0x00000000, ), TxInput( amount=462000000, - prev_hash=unhexlify('99ddaf6d9b75447d5127e17312f6def68acba2d4f464d0e2ac93137bb5cab7d7'), + prev_hash=unhexlify( + "99ddaf6d9b75447d5127e17312f6def68acba2d4f464d0e2ac93137bb5cab7d7" + ), prev_index=0, - script_pubkey=unhexlify('5120147c9c57132f6e7ecddba9800bb0c4449251c92a1e60371ee77557b6620f3ea3'), + script_pubkey=unhexlify( + "5120147c9c57132f6e7ecddba9800bb0c4449251c92a1e60371ee77557b6620f3ea3" + ), script_type=InputScriptType.SPENDTAPROOT, - sequence=0xffffffff, + sequence=0xFFFFFFFF, ), TxInput( amount=294000000, - prev_hash=unhexlify('4218a419542757d960174457dc82e06b3613ac8ed2c528926833433883f5e1f8'), + prev_hash=unhexlify( + "4218a419542757d960174457dc82e06b3613ac8ed2c528926833433883f5e1f8" + ), prev_index=0, - script_pubkey=unhexlify('76a914751e76e8199196d454941c45d1b3a323f1433bd688ac'), + script_pubkey=unhexlify( + "76a914751e76e8199196d454941c45d1b3a323f1433bd688ac" + ), script_type=InputScriptType.SPENDADDRESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, ), TxInput( amount=504000000, - prev_hash=unhexlify('3b8504d63a84a0fd1043e7ec832adaeeb7382a6d3ca762b10cb363aa809168f0'), + prev_hash=unhexlify( + "3b8504d63a84a0fd1043e7ec832adaeeb7382a6d3ca762b10cb363aa809168f0" + ), prev_index=1, - script_pubkey=unhexlify('5120e4d810fd50586274face62b8a807eb9719cef49c04177cc6b76a9a4251d5450e'), + script_pubkey=unhexlify( + "5120e4d810fd50586274face62b8a807eb9719cef49c04177cc6b76a9a4251d5450e" + ), script_type=InputScriptType.SPENDTAPROOT, - sequence=0xfffffffe, + sequence=0xFFFFFFFE, ), TxInput( amount=630000000, - prev_hash=unhexlify('7a488f58881cecb2523690afcf22eb8892372bae018a125e1f006283a38c630c'), + prev_hash=unhexlify( + "7a488f58881cecb2523690afcf22eb8892372bae018a125e1f006283a38c630c" + ), prev_index=0, - script_pubkey=unhexlify('512091b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605'), + script_pubkey=unhexlify( + "512091b64d5324723a985170e4dc5a0f84c041804f2cd12660fa5dec09fc21783605" + ), script_type=InputScriptType.SPENDTAPROOT, - sequence=0xfffffffe, + sequence=0xFFFFFFFE, ), TxInput( amount=378000000, - prev_hash=unhexlify('50d0ac326d44a3a29358214139fecb8a7129aa2f2dbeb28e96aa6fc6bd496195'), + prev_hash=unhexlify( + "50d0ac326d44a3a29358214139fecb8a7129aa2f2dbeb28e96aa6fc6bd496195" + ), prev_index=0, - script_pubkey=unhexlify('00147dd65592d0ab2fe0d0257d571abf032cd9db93dc'), + script_pubkey=unhexlify("00147dd65592d0ab2fe0d0257d571abf032cd9db93dc"), script_type=InputScriptType.SPENDWITNESS, sequence=0x00000000, ), TxInput( amount=672000000, - prev_hash=unhexlify('3a013eb5a6a664585ddbc210e02147847cde7317c0ce4e056ee4f0f167a2ef81'), + prev_hash=unhexlify( + "3a013eb5a6a664585ddbc210e02147847cde7317c0ce4e056ee4f0f167a2ef81" + ), prev_index=1, - script_pubkey=unhexlify('512075169f4001aa68f15bbed28b218df1d0a62cbbcf1188c6665110c293c907b831'), + script_pubkey=unhexlify( + "512075169f4001aa68f15bbed28b218df1d0a62cbbcf1188c6665110c293c907b831" + ), script_type=InputScriptType.SPENDTAPROOT, sequence=0x00000000, ), TxInput( amount=546000000, - prev_hash=unhexlify('eebd075c693d6823dd39fe11e3a6d1993fdec6109860937d50624a3c9c6690a6'), + prev_hash=unhexlify( + "eebd075c693d6823dd39fe11e3a6d1993fdec6109860937d50624a3c9c6690a6" + ), prev_index=0, - script_pubkey=unhexlify('51200f63ca2c7639b9bb4be0465cc0aa3ee78a0761ba5f5f7d6ff8eab340f09da561'), + script_pubkey=unhexlify( + "51200f63ca2c7639b9bb4be0465cc0aa3ee78a0761ba5f5f7d6ff8eab340f09da561" + ), script_type=InputScriptType.SPENDTAPROOT, - sequence=0xffffffff, + sequence=0xFFFFFFFF, ), TxInput( amount=588000000, - prev_hash=unhexlify('9e667967d1eb839b9b0a1fd17b2f29e838ff0240a83c61f896844377f8b57a72'), + prev_hash=unhexlify( + "9e667967d1eb839b9b0a1fd17b2f29e838ff0240a83c61f896844377f8b57a72" + ), prev_index=1, - script_pubkey=unhexlify('5120053690babeabbb7850c32eead0acf8df990ced79f7a31e358fabf2658b4bc587'), + script_pubkey=unhexlify( + "5120053690babeabbb7850c32eead0acf8df990ced79f7a31e358fabf2658b4bc587" + ), script_type=InputScriptType.SPENDTAPROOT, - sequence=0xffffffff, + sequence=0xFFFFFFFF, ), ], "outputs": [ PrevOutput( amount=1000000000, - script_pubkey=unhexlify('76a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac'), # 1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP + script_pubkey=unhexlify( + "76a91406afd46bcdfd22ef94ac122aa11f241244a37ecc88ac" + ), # 1cMh228HTCiwS8ZsaakH8A8wze1JR5ZsP ), PrevOutput( amount=3410000000, - script_pubkey=unhexlify('ac9a87f5594be208f8532db38cff670c450ed2fea8fcdefcc9a663f78bab962b'), - ) + script_pubkey=unhexlify( + "ac9a87f5594be208f8532db38cff670c450ed2fea8fcdefcc9a663f78bab962b" + ), + ), ], - "sha_amounts": unhexlify('58a6964a4f5f8f0b642ded0a8a553be7622a719da71d1f5befcefcdee8e0fde6'), - "sha_outputs": unhexlify('a2e6dab7c1f0dcd297c8d61647fd17d821541ea69c3cc37dcbad7f90d4eb4bc5'), - "sha_prevouts": unhexlify('2bd4d5a417902673919b2c209d14f8efaa285ede022a88d6a45edf4bdd43db11'), - "sha_scriptpubkeys": unhexlify('26003c31f2f1786d22fcb3e1f690ddcdff53627a59f9219d5a2c77985a8930c0'), - "sha_sequences": unhexlify('18959c7221ab5ce9e26c3cd67b22c24f8baa54bac281d8e6b05e400e6c3a957e'), - "signature_hashes": - [ + "sha_amounts": unhexlify( + "58a6964a4f5f8f0b642ded0a8a553be7622a719da71d1f5befcefcdee8e0fde6" + ), + "sha_outputs": unhexlify( + "a2e6dab7c1f0dcd297c8d61647fd17d821541ea69c3cc37dcbad7f90d4eb4bc5" + ), + "sha_prevouts": unhexlify( + "2bd4d5a417902673919b2c209d14f8efaa285ede022a88d6a45edf4bdd43db11" + ), + "sha_scriptpubkeys": unhexlify( + "26003c31f2f1786d22fcb3e1f690ddcdff53627a59f9219d5a2c77985a8930c0" + ), + "sha_sequences": unhexlify( + "18959c7221ab5ce9e26c3cd67b22c24f8baa54bac281d8e6b05e400e6c3a957e" + ), + "signature_hashes": [ { "index": 3, "hash_type": SigHashType.SIGHASH_ALL, - "result": unhexlify('6ffd256e108685b41831385f57eebf2fca041bc6b5e607ea11b3e03d4cf9d9ba'), + "result": unhexlify( + "6ffd256e108685b41831385f57eebf2fca041bc6b5e607ea11b3e03d4cf9d9ba" + ), }, { "index": 4, "hash_type": SigHashType.SIGHASH_ALL_TAPROOT, - "result": unhexlify('9f90136737540ccc18707e1fd398ad222a1a7e4dd65cbfd22dbe4660191efa58'), + "result": unhexlify( + "9f90136737540ccc18707e1fd398ad222a1a7e4dd65cbfd22dbe4660191efa58" + ), }, - ] + ], }, { # https://github.com/bitcoin/bips/pull/1191/commits/fa40b5ae3544c1ed1615ead93a688d72be963e08 - "sign_tx": SignTx(coin_name='Bitcoin', version=2, lock_time=0x00000000, inputs_count=2, outputs_count=1), + "sign_tx": SignTx( + coin_name="Bitcoin", + version=2, + lock_time=0x00000000, + inputs_count=2, + outputs_count=1, + ), "inputs": [ TxInput( - prev_hash=unhexlify('8dcb562f365cfeb249be74e7865135cf035add604234fc0d8330b49bec92605f'), + prev_hash=unhexlify( + "8dcb562f365cfeb249be74e7865135cf035add604234fc0d8330b49bec92605f" + ), prev_index=0, amount=500000000, # 5 btc script_type=InputScriptType.SPENDWITNESS, @@ -128,35 +193,52 @@ VECTORS = [ script_pubkey=unhexlify("0014196a5bea745288a7f947993c28e3a0f2108d2e0a"), ), TxInput( - prev_hash=unhexlify('e1323b577ed0d216f4e52bf2b4c490710dfa0088dae3d15e8ba26ad792184361'), + prev_hash=unhexlify( + "e1323b577ed0d216f4e52bf2b4c490710dfa0088dae3d15e8ba26ad792184361" + ), prev_index=1, multisig=None, amount=600000000, # 6 btc script_type=InputScriptType.SPENDTAPROOT, sequence=0, - script_pubkey=unhexlify("512029d942d0408906b359397b6f87c5145814a9aefc8c396dd05efa8b5b73576bf2"), + script_pubkey=unhexlify( + "512029d942d0408906b359397b6f87c5145814a9aefc8c396dd05efa8b5b73576bf2" + ), ), ], "outputs": [ PrevOutput( amount=1000000000, - script_pubkey=unhexlify('76a914682dfdbc97ab5c31300f36d3c12c6fd854b1b35a88ac'), # 1AVrNUPAytZZbisNduCacWcEVJS6eGRvaa + script_pubkey=unhexlify( + "76a914682dfdbc97ab5c31300f36d3c12c6fd854b1b35a88ac" + ), # 1AVrNUPAytZZbisNduCacWcEVJS6eGRvaa ), ], - "sha_amounts": unhexlify('5733468db74734c00efa0b466bca091d8f1aab074af2538f36bd0a734a5940c5'), - "sha_outputs": unhexlify('8cdee56004a241f9c79cc55b7d79eaed04909d84660502a2d4e9c357c2047cf5'), - "sha_prevouts": unhexlify('32553b113292dfa8216546e721388a6c19c76626ca65dc187e0348d6ed445f81'), - "sha_scriptpubkeys": unhexlify('423cd73484fc5e3e0a623442846c279c2216f25a2f32d161fea6c5821a1adde7'), - "sha_sequences": unhexlify('af5570f5a1810b7af78caf4bc70a660f0df51e42baf91d4de5b2328de0e83dfc'), - "signature_hashes": - [ + "sha_amounts": unhexlify( + "5733468db74734c00efa0b466bca091d8f1aab074af2538f36bd0a734a5940c5" + ), + "sha_outputs": unhexlify( + "8cdee56004a241f9c79cc55b7d79eaed04909d84660502a2d4e9c357c2047cf5" + ), + "sha_prevouts": unhexlify( + "32553b113292dfa8216546e721388a6c19c76626ca65dc187e0348d6ed445f81" + ), + "sha_scriptpubkeys": unhexlify( + "423cd73484fc5e3e0a623442846c279c2216f25a2f32d161fea6c5821a1adde7" + ), + "sha_sequences": unhexlify( + "af5570f5a1810b7af78caf4bc70a660f0df51e42baf91d4de5b2328de0e83dfc" + ), + "signature_hashes": [ { "index": 1, "hash_type": SigHashType.SIGHASH_ALL_TAPROOT, - "result": unhexlify('07333acfe6dce8196f1ad62b2e039a3d9f0b6627bf955be767c519c0f8789ff4'), + "result": unhexlify( + "07333acfe6dce8196f1ad62b2e039a3d9f0b6627bf955be767c519c0f8789ff4" + ), }, - ] - } + ], + }, ] @@ -170,21 +252,39 @@ class TestSegwitBip341P2TR(unittest.TestCase): for txi in tx["inputs"]: hasher.add_input(txi, txi.script_pubkey) - self.assertEqual(get_tx_hash(hasher.h_amounts), tx["sha_amounts"], f"sha_amounts tx {i}") - self.assertEqual(get_tx_hash(hasher.h_prevouts), tx["sha_prevouts"], f"sha_prevouts tx {i}") - self.assertEqual(get_tx_hash(hasher.h_scriptpubkeys), tx["sha_scriptpubkeys"], f"sha_scriptpubkeys tx {i}") - self.assertEqual(get_tx_hash(hasher.h_sequences), tx["sha_sequences"], f"sha_sequences tx {i}") + self.assertEqual( + get_tx_hash(hasher.h_amounts), tx["sha_amounts"], f"sha_amounts tx {i}" + ) + self.assertEqual( + get_tx_hash(hasher.h_prevouts), + tx["sha_prevouts"], + f"sha_prevouts tx {i}", + ) + self.assertEqual( + get_tx_hash(hasher.h_scriptpubkeys), + tx["sha_scriptpubkeys"], + f"sha_scriptpubkeys tx {i}", + ) + self.assertEqual( + get_tx_hash(hasher.h_sequences), + tx["sha_sequences"], + f"sha_sequences tx {i}", + ) for txo in tx["outputs"]: hasher.add_output(txo, txo.script_pubkey) - self.assertEqual(get_tx_hash(hasher.h_outputs), tx["sha_outputs"], f"sha_outputs tx {i}") + self.assertEqual( + get_tx_hash(hasher.h_outputs), tx["sha_outputs"], f"sha_outputs tx {i}" + ) for sh in tx["signature_hashes"]: txi = tx["inputs"][sh["index"]] result = hasher.hash341(sh["index"], tx["sign_tx"], sh["hash_type"]) - self.assertEqual(result, sh["result"], f"signature_hash tx {i} input {sh['index']}") + self.assertEqual( + result, sh["result"], f"signature_hash tx {i} input {sh['index']}" + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py index bcce720cd8..dbcca0f478 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh.py @@ -40,124 +40,189 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): def test_send_native_p2wpkh(self): - coin = coins.by_name('Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'), + prev_hash=unhexlify( + "09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a" + ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'), - prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), - prev_index=0, - sequence=4294967295) - pout1 = PrevOutput(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'), - amount=12300000) - pout2 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - amount=111145789) + ptx1 = PrevTx( + version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 + ) + pinp1 = PrevInput( + script_sig=unhexlify("160014d16b8c0680c61fc6ed2e407455715055e41052f5"), + prev_hash=unhexlify( + "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" + ), + prev_index=0, + sequence=4294967295, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c"), + amount=12300000, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + amount=111145789, + ) out1 = TxOutput( - address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp', + address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp", amount=5000000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], multisig=None, ) out2 = TxOutput( - address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu', + address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu", script_type=OutputScriptType.PAYTOADDRESS, amount=12300000 - 11000 - 5000000, address_n=[], multisig=None, ) - tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Testnet", version=1, lock_time=0, inputs_count=1, outputs_count=2 + ) # precomputed tx weight is 142 = ceil(566 / 4) fee_rate = 11000 / 142 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - helpers.UiConfirmForeignAddress(address_n=inp1.address_n), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False), True, - - helpers.UiConfirmTotal(12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3] + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify('01000000000101'), - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized inp1 - serialized_tx=unhexlify('8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02'), - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized inp1 + serialized_tx=unhexlify( + "8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02" + ), + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out1 - serialized_tx=unhexlify('404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out1 + serialized_tx=unhexlify( + "404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987" + ), + signature_index=None, + signature=None, + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - # segwit - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out2 - serialized_tx=unhexlify('a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f5'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out2 + serialized_tx=unhexlify( + "a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f5" + ), + signature_index=None, + signature=None, + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify('02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000'), - signature_index=0, - signature=unhexlify('3045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b95'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify( + "02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000" + ), + signature_index=0, + signature=unhexlify( + "3045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b95" + ), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -173,31 +238,43 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): def test_send_native_p2wpkh_change(self): - coin = coins.by_name('Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'), + prev_hash=unhexlify( + "09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a" + ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'), - prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), - prev_index=0, - sequence=4294967295) - pout1 = PrevOutput(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'), - amount=12300000) - pout2 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - amount=111145789) + ptx1 = PrevTx( + version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 + ) + pinp1 = PrevInput( + script_sig=unhexlify("160014d16b8c0680c61fc6ed2e407455715055e41052f5"), + prev_hash=unhexlify( + "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" + ), + prev_index=0, + sequence=4294967295, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c"), + amount=12300000, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + amount=111145789, + ) out1 = TxOutput( - address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp', + address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp", amount=5000000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], @@ -211,88 +288,145 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): amount=12300000 - 11000 - 5000000, multisig=None, ) - tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Testnet", version=1, lock_time=0, inputs_count=1, outputs_count=2 + ) # precomputed tx weight is 142 = ceil(566 / 4) fee_rate = 11000 / 142 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - helpers.UiConfirmForeignAddress(address_n=inp1.address_n), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - helpers.UiConfirmForeignAddress(address_n=out2.address_n), True, - - helpers.UiConfirmTotal(5000000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 5000000 + 11000, + 11000, + fee_rate, + coin, + AmountUnit.BITCOIN, + inp1.address_n[:3], + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify('01000000000101'), - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized inp1 - serialized_tx=unhexlify('8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02'), - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized inp1 + serialized_tx=unhexlify( + "8a44999c07bba32df1cacdc50987944e68e3205b4429438fdde35c76024614090000000000ffffffff02" + ), + ), + ), # the out has to be cloned not to send the same object which was modified TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out1.__dict__))), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out1 - serialized_tx=unhexlify('404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out1 + serialized_tx=unhexlify( + "404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987" + ), + signature_index=None, + signature=None, + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out2.__dict__))), - # segwit - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out2 - serialized_tx=unhexlify('a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f5'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out2 + serialized_tx=unhexlify( + "a8386f0000000000160014d16b8c0680c61fc6ed2e407455715055e41052f5" + ), + signature_index=None, + signature=None, + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify('02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000'), - signature_index=0, - signature=unhexlify('3045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b95'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify( + "02483045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b950121033add1f0e8e3c3136f7428dd4a4de1057380bd311f5b0856e2269170b4ffa65bf00000000" + ), + signature_index=0, + signature=unhexlify( + "3045022100a7ca8f097525f9044e64376dc0a0f5d4aeb8d15d66808ba97979a0475b06b66502200597c8ebcef63e047f9aeef1a8001d3560470cf896c12f6990eec4faec599b95" + ), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -308,51 +442,70 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): def test_send_native_invalid_address(self): - coin = coins.by_name('Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'), + prev_hash=unhexlify( + "09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a" + ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('160014d16b8c0680c61fc6ed2e407455715055e41052f5'), - prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), - prev_index=0, - sequence=4294967295) - pout1 = PrevOutput(script_pubkey=unhexlify('00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c'), - amount=12300000) - pout2 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - amount=111145789) + ptx1 = PrevTx( + version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 + ) + pinp1 = PrevInput( + script_sig=unhexlify("160014d16b8c0680c61fc6ed2e407455715055e41052f5"), + prev_hash=unhexlify( + "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" + ), + prev_index=0, + sequence=4294967295, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("00140099a7ecbd938ed1839f5f6bf6d50933c6db9d5c"), + amount=12300000, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + amount=111145789, + ) out1 = TxOutput( - address='TB1Q694CCP5QCC0UDMFWGP692U2S2HJPQ5H407URTU', # Error: should be lower case + address="TB1Q694CCP5QCC0UDMFWGP692U2S2HJPQ5H407URTU", # Error: should be lower case script_type=OutputScriptType.PAYTOADDRESS, amount=12300000 - 11000 - 5000000, address_n=[], multisig=None, ) - tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=1) + tx = SignTx( + coin_name="Testnet", version=1, lock_time=0, inputs_count=1, outputs_count=1 + ) messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - helpers.UiConfirmForeignAddress(address_n=inp1.address_n), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - None + None, ] ns = _get_schemas_for_coin(coin) @@ -369,5 +522,5 @@ class TestSignSegwitTxNativeP2WPKH(unittest.TestCase): self.assertEqual(response, expected_response) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py index 9765132cfd..d5ef49c13f 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.native_p2wpkh_grs.py @@ -41,124 +41,201 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): def test_send_native_p2wpkh(self): - coin = coins.by_name('Groestlcoin Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Groestlcoin Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 84'/1'/0'/0/0" - tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify('4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1'), + prev_hash=unhexlify( + "4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1" + ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, - sequence=0xfffffffe, + sequence=0xFFFFFFFE, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=650645, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4'), - prev_hash=unhexlify('1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160'), - prev_index=1, - sequence=4294967293) - pout1 = PrevOutput(script_pubkey=unhexlify('0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1'), - amount=12300000) - pout2 = PrevOutput(script_pubkey=unhexlify('76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac'), - amount=9887699777) + ptx1 = PrevTx( + version=1, + lock_time=650645, + inputs_count=1, + outputs_count=2, + extra_data_len=0, + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4" + ), + prev_hash=unhexlify( + "1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160" + ), + prev_index=1, + sequence=4294967293, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1"), + amount=12300000, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify( + "76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac" + ), + amount=9887699777, + ) out1 = TxOutput( - address='2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e', + address="2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e", amount=5000000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], multisig=None, ) out2 = TxOutput( - address='tgrs1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt9lkd57', + address="tgrs1qejqxwzfld7zr6mf7ygqy5s5se5xq7vmt9lkd57", script_type=OutputScriptType.PAYTOADDRESS, amount=12300000 - 11000 - 5000000, address_n=[], multisig=None, ) - tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650713, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Groestlcoin Testnet", + version=1, + lock_time=650713, + inputs_count=1, + outputs_count=2, + ) # precomputed tx weight is 142 = ceil(566 / 4) fee_rate = 11000 / 142 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False), True, - helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), True, - - helpers.UiConfirmTotal(12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 12300000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3] + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify('01000000000101'), - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized inp1 - serialized_tx=unhexlify('d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02'), - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized inp1 + serialized_tx=unhexlify( + "d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02" + ), + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out1 - serialized_tx=unhexlify('404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out1 + serialized_tx=unhexlify( + "404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987" + ), + signature_index=None, + signature=None, + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - # segwit - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out2 - serialized_tx=unhexlify('a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out2 + serialized_tx=unhexlify( + "a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b" + ), + signature_index=None, + signature=None, + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify('02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900'), - signature_index=0, - signature=unhexlify('3045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify( + "02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900" + ), + signature_index=0, + signature=unhexlify( + "3045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3" + ), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -174,31 +251,51 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): def test_send_native_p2wpkh_change(self): - coin = coins.by_name('Groestlcoin Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Groestlcoin Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 84'/1'/0'/0/0" - tgrs1qkvwu9g3k2pdxewfqr7syz89r3gj557l3ued7ja address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify('4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1'), + prev_hash=unhexlify( + "4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1" + ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, - sequence=0xfffffffe, + sequence=0xFFFFFFFE, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=650645, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4'), - prev_hash=unhexlify('1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160'), - prev_index=1, - sequence=4294967293) - pout1 = PrevOutput(script_pubkey=unhexlify('0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1'), - amount=12300000) - pout2 = PrevOutput(script_pubkey=unhexlify('76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac'), - amount=9887699777) + ptx1 = PrevTx( + version=1, + lock_time=650645, + inputs_count=1, + outputs_count=2, + extra_data_len=0, + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "483045022100d9615361c044e91f6dd7bb4455f3ad686cd5a663d7800bb74c448b2706500ccb022026bed24b81a501e8398411c5a9a793741d9bfe39617d51c363dde0a84f44f4f9012102659a6eefcc72d6f2eff92e57095388b17db0b06034946ecd44120e5e7a830ff4" + ), + prev_hash=unhexlify( + "1c92508b38239e5c10b23fb46dcf765ee2f3a95b835edbf0943ec21b21711160" + ), + prev_index=1, + sequence=4294967293, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("0014b31dc2a236505a6cb9201fa0411ca38a254a7bf1"), + amount=12300000, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify( + "76a91438cc090e4a4b2e458c33fe35af1c5c0094699ac288ac" + ), + amount=9887699777, + ) out1 = TxOutput( - address='2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e', + address="2N4Q5FhU2497BryFfUgbqkAJE87aKDv3V3e", amount=5000000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], @@ -212,85 +309,147 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): amount=12300000 - 11000 - 5000000, multisig=None, ) - tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650713, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Groestlcoin Testnet", + version=1, + lock_time=650713, + inputs_count=1, + outputs_count=2, + ) # precomputed tx weight is 142 = ceil(566 / 4) fee_rate = 11000 / 142 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), True, - - helpers.UiConfirmTotal(5000000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 5000000 + 11000, + 11000, + fee_rate, + coin, + AmountUnit.BITCOIN, + inp1.address_n[:3], + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify('01000000000101'), - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized inp1 - serialized_tx=unhexlify('d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02'), - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized inp1 + serialized_tx=unhexlify( + "d1613f483f2086d076c82fe34674385a86beb08f052d5405fe1aed397f852f4f0000000000feffffff02" + ), + ), + ), # the out has to be cloned not to send the same object which was modified TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out1.__dict__))), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out1 - serialized_tx=unhexlify('404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out1 + serialized_tx=unhexlify( + "404b4c000000000017a9147a55d61848e77ca266e79a39bfc85c580a6426c987" + ), + signature_index=None, + signature=None, + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out2.__dict__))), - # segwit - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out2 - serialized_tx=unhexlify('a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out2 + serialized_tx=unhexlify( + "a8386f0000000000160014cc8067093f6f843d6d3e22004a4290cd0c0f336b" + ), + signature_index=None, + signature=None, + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify('02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900'), - signature_index=0, - signature=unhexlify('3045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify( + "02483045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3012103adc58245cf28406af0ef5cc24b8afba7f1be6c72f279b642d85c48798685f862d9ed0900" + ), + signature_index=0, + signature=unhexlify( + "3045022100ea8780bc1e60e14e945a80654a41748bbf1aa7d6f2e40a88d91dfc2de1f34bd10220181a474a3420444bd188501d8d270736e1e9fe379da9970de992ff445b0972e3" + ), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -305,5 +464,5 @@ class TestSignSegwitTxNativeP2WPKH_GRS(unittest.TestCase): signer.send(None) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py index 934e643085..8e0ecf3292 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh.py @@ -40,121 +40,196 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): def test_send_p2wpkh_in_p2sh(self): - coin = coins.by_name('Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), + prev_hash=unhexlify( + "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" + ), prev_index=0, script_type=InputScriptType.SPENDP2SHWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'), - prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'), - prev_index=0, - sequence=4294967295) - pout1 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - amount=123456789) - pout2 = PrevOutput(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'), - amount=865519308) + ptx1 = PrevTx( + version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c" + ), + prev_hash=unhexlify( + "802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a" + ), + prev_index=0, + sequence=4294967295, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + amount=123456789, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify( + "76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac" + ), + amount=865519308, + ) out1 = TxOutput( - address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC', + address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC", amount=12300000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], multisig=None, ) out2 = TxOutput( - address='2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX', + address="2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX", script_type=OutputScriptType.PAYTOADDRESS, amount=123456789 - 11000 - 12300000, address_n=[], multisig=None, ) - tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Testnet", version=1, lock_time=0, inputs_count=1, outputs_count=2 + ) # precomputed tx weight is 168 = ceil(670 / 4) fee_rate = 11000 / 168 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False), True, - - helpers.UiConfirmTotal(123445789 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 123445789 + 11000, + 11000, + fee_rate, + coin, + AmountUnit.BITCOIN, + inp1.address_n[:3], + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify('01000000000101'), - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized inp1 - serialized_tx=unhexlify('37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02'), - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized inp1 + serialized_tx=unhexlify( + "37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02" + ), + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out1 - serialized_tx=unhexlify('e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out1 + serialized_tx=unhexlify( + "e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac" + ), + signature_index=None, + signature=None, + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - # segwit - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out2 - serialized_tx=unhexlify('3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out2 + serialized_tx=unhexlify( + "3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), + signature_index=None, + signature=None, + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify('02483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000'), - signature_index=0, - signature=unhexlify('3045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify( + "02483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" + ), + signature_index=0, + signature=unhexlify( + "3045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b" + ), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -170,31 +245,47 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): def test_send_p2wpkh_in_p2sh_change(self): - coin = coins.by_name('Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), + prev_hash=unhexlify( + "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" + ), prev_index=0, script_type=InputScriptType.SPENDP2SHWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'), - prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'), - prev_index=0, - sequence=4294967295) - pout1 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - amount=123456789) - pout2 = PrevOutput(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'), - amount=865519308) + ptx1 = PrevTx( + version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c" + ), + prev_hash=unhexlify( + "802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a" + ), + prev_index=0, + sequence=4294967295, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + amount=123456789, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify( + "76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac" + ), + amount=865519308, + ) out1 = TxOutput( - address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC', + address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC", amount=12300000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], @@ -207,93 +298,141 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): address=None, multisig=None, ) - tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Testnet", version=1, lock_time=0, inputs_count=1, outputs_count=2 + ) # precomputed tx weight is 168 = ceil(670 / 4) fee_rate = 11000 / 168 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), - + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - - helpers.UiConfirmTotal(12300000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 12300000 + 11000, + 11000, + fee_rate, + coin, + AmountUnit.BITCOIN, + inp1.address_n[:3], + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify( - '01000000000101'), - )), - + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized inp1 - serialized_tx=unhexlify( - '37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02'), - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized inp1 + serialized_tx=unhexlify( + "37c361fb8f2d9056ba8c98c5611930fcb48cacfdd0fe2e0449d83eea982f91200000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5ffffffff02" + ), + ), + ), # the out has to be cloned not to send the same object which was modified TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out1.__dict__))), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized out1 - serialized_tx=unhexlify( - 'e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out1 + serialized_tx=unhexlify( + "e0aebb00000000001976a91414fdede0ddc3be652a0ce1afbc1b509a55b6b94888ac" + ), + signature_index=None, + signature=None, + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out2.__dict__))), - # segwit - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized out2 - serialized_tx=unhexlify( - '3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out2 + serialized_tx=unhexlify( + "3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), + signature_index=None, + signature=None, + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify( - '02483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000'), - signature_index=0, - signature=unhexlify('3045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify( + "02483045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7900000000" + ), + signature_index=0, + signature=unhexlify( + "3045022100ccd253bfdf8a5593cd7b6701370c531199f0f05a418cd547dfc7da3f21515f0f02203fa08a0753688871c220648f9edadbdb98af42e5d8269364a326572cf703895b" + ), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -309,41 +448,59 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): def test_send_p2wpkh_in_p2sh_attack_amount(self): - coin = coins.by_name('Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=10, - prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), + prev_hash=unhexlify( + "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" + ), prev_index=0, script_type=InputScriptType.SPENDP2SHWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c'), - prev_hash=unhexlify('802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a'), - prev_index=0, - sequence=4294967295) - pout1 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - amount=123456789) - pout2 = PrevOutput(script_pubkey=unhexlify('76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac'), - amount=865519308) + ptx1 = PrevTx( + version=1, lock_time=0, inputs_count=1, outputs_count=2, extra_data_len=0 + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "4730440220548e087d0426b20b8a571b03b9e05829f7558b80c53c12143e342f56ab29e51d02205b68cb7fb223981d4c999725ac1485a982c4259c4f50b8280f137878c232998a012102794a25b254a268e59a5869da57fbae2fadc6727cb3309321dab409b12b2fa17c" + ), + prev_hash=unhexlify( + "802cabf0843b945eabe136d7fc7c89f41021658abf56cba000acbce88c41143a" + ), + prev_index=0, + sequence=4294967295, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + amount=123456789, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify( + "76a914b84bacdcd8f4cc59274a5bfb73f804ca10f7fd1488ac" + ), + amount=865519308, + ) inpattack = TxInput( # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=9, # modified! - prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), + prev_hash=unhexlify( + "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" + ), prev_index=0, script_type=InputScriptType.SPENDP2SHWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) out1 = TxOutput( - address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC', + address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC", amount=8, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], @@ -356,53 +513,83 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): address=None, multisig=None, ) - tx = SignTx(coin_name='Testnet', version=1, lock_time=0, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Testnet", version=1, lock_time=0, inputs_count=1, outputs_count=2 + ) # precomputed tx weight is 168 = ceil(670 / 4) fee_rate = (9 - 8 - 1) / 168 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inpattack)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - - helpers.UiConfirmTotal(9 - 1, 9 - 8 - 1, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 9 - 1, 9 - 8 - 1, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3] + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify( - '01000000000101'), - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -423,5 +610,5 @@ class TestSignSegwitTxP2WPKHInP2SH(unittest.TestCase): signer.send(None) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py index cae18a4470..a7c4434802 100644 --- a/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py +++ b/core/tests/test_apps.bitcoin.segwit.signtx.p2wpkh_in_p2sh_grs.py @@ -41,124 +41,206 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): def test_send_p2wpkh_in_p2sh(self): - coin = coins.by_name('Groestlcoin Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Groestlcoin Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7 address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify('09a48bce2f9d5c6e4f0cb9ea1b32d0891855e8acfe5334f9ebd72b9ad2de60cf'), + prev_hash=unhexlify( + "09a48bce2f9d5c6e4f0cb9ea1b32d0891855e8acfe5334f9ebd72b9ad2de60cf" + ), prev_index=0, script_type=InputScriptType.SPENDP2SHWITNESS, - sequence=0xfffffffe, + sequence=0xFFFFFFFE, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=650749, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4'), - prev_hash=unhexlify('4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1'), - prev_index=1, - sequence=4294967294) - pout1 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - amount=123456789) - pout2 = PrevOutput(script_pubkey=unhexlify('76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac'), - amount=9764242764) + ptx1 = PrevTx( + version=1, + lock_time=650749, + inputs_count=1, + outputs_count=2, + extra_data_len=0, + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4" + ), + prev_hash=unhexlify( + "4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1" + ), + prev_index=1, + sequence=4294967294, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + amount=123456789, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify( + "76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac" + ), + amount=9764242764, + ) out1 = TxOutput( - address='mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y', + address="mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y", amount=12300000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], multisig=None, ) out2 = TxOutput( - address='2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7', + address="2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7", script_type=OutputScriptType.PAYTOADDRESS, amount=123456789 - 11000 - 12300000, address_n=[], multisig=None, ) - tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650756, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Groestlcoin Testnet", + version=1, + lock_time=650756, + inputs_count=1, + outputs_count=2, + ) # precomputed tx weight is 168 = ceil(670 / 4) fee_rate = 11000 / 168 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), helpers.UiConfirmOutput(out2, coin, AmountUnit.BITCOIN, 1, False), True, - helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), True, - - helpers.UiConfirmTotal(123445789 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 123445789 + 11000, + 11000, + fee_rate, + coin, + AmountUnit.BITCOIN, + inp1.address_n[:3], + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify('01000000000101'), - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized inp1 - serialized_tx=unhexlify('cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02'), - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized inp1 + serialized_tx=unhexlify( + "cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02" + ), + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out1 - serialized_tx=unhexlify('e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out1 + serialized_tx=unhexlify( + "e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac" + ), + signature_index=None, + signature=None, + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - # segwit - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - # returned serialized out2 - serialized_tx=unhexlify('3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out2 + serialized_tx=unhexlify( + "3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), + signature_index=None, + signature=None, + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify('02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900'), - signature_index=0, - signature=unhexlify('3045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify( + "02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900" + ), + signature_index=0, + signature=unhexlify( + "3045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80" + ), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -174,31 +256,51 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): def test_send_p2wpkh_in_p2sh_change(self): - coin = coins.by_name('Groestlcoin Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Groestlcoin Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") inp1 = TxInput( # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZYBtBZ7 address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify('09a48bce2f9d5c6e4f0cb9ea1b32d0891855e8acfe5334f9ebd72b9ad2de60cf'), + prev_hash=unhexlify( + "09a48bce2f9d5c6e4f0cb9ea1b32d0891855e8acfe5334f9ebd72b9ad2de60cf" + ), prev_index=0, script_type=InputScriptType.SPENDP2SHWITNESS, - sequence=0xfffffffe, + sequence=0xFFFFFFFE, multisig=None, ) - ptx1 = PrevTx(version=1, lock_time=650749, inputs_count=1, outputs_count=2, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4'), - prev_hash=unhexlify('4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1'), - prev_index=1, - sequence=4294967294) - pout1 = PrevOutput(script_pubkey=unhexlify('a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - amount=123456789) - pout2 = PrevOutput(script_pubkey=unhexlify('76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac'), - amount=9764242764) + ptx1 = PrevTx( + version=1, + lock_time=650749, + inputs_count=1, + outputs_count=2, + extra_data_len=0, + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "47304402201f8f57f708144c3a11da322546cb37bd385aa825d940c37e8016f0efd6ec3e9402202a41bc02c29e4f3f13efd4bededbcd4308a6393279111d614ee1f7635cf3e65701210371546a36bdf6bc82087301b3f6e759736dc8790150673d2e7e2715d2ad72f3a4" + ), + prev_hash=unhexlify( + "4f2f857f39ed1afe05542d058fb0be865a387446e32fc876d086203f483f61d1" + ), + prev_index=1, + sequence=4294967294, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify("a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87"), + amount=123456789, + ) + pout2 = PrevOutput( + script_pubkey=unhexlify( + "76a91435528b20e9a793cf2c3a1cf9cff1f2127ad377da88ac" + ), + amount=9764242764, + ) out1 = TxOutput( - address='mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y', + address="mvbu1Gdy8SUjTenqerxUaZyYjmvedc787y", amount=12300000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], @@ -211,93 +313,147 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): address=None, multisig=None, ) - tx = SignTx(coin_name='Groestlcoin Testnet', version=1, lock_time=650756, inputs_count=1, outputs_count=2) + tx = SignTx( + coin_name="Groestlcoin Testnet", + version=1, + lock_time=650756, + inputs_count=1, + outputs_count=2, + ) # precomputed tx weight is 168 = ceil(670 / 4) fee_rate = 11000 / 168 messages = [ None, - # check fee - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out2)), - helpers.UiConfirmNonDefaultLocktime(tx.lock_time, lock_time_disabled=False), True, - - helpers.UiConfirmTotal(12300000 + 11000, 11000, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 12300000 + 11000, + 11000, + fee_rate, + coin, + AmountUnit.BITCOIN, + inp1.address_n[:3], + ), True, - # check prev tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, tx_hash=inp1.prev_hash + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=inp1.prev_hash), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout2)), - # sign tx - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized header - serialized_tx=unhexlify( - '01000000000101'), - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized header + serialized_tx=unhexlify("01000000000101"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized inp1 - serialized_tx=unhexlify( - 'cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02'), - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized inp1 + serialized_tx=unhexlify( + "cf60ded29a2bd7ebf93453feace8551889d0321beab90c4f6e5c9d2fce8ba4090000000017160014d16b8c0680c61fc6ed2e407455715055e41052f5feffffff02" + ), + ), + ), # the out has to be cloned not to send the same object which was modified TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out1.__dict__))), - - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=1, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized out1 - serialized_tx=unhexlify( - 'e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=1, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out1 + serialized_tx=unhexlify( + "e0aebb00000000001976a914a579388225827d9f2fe9014add644487808c695d88ac" + ), + signature_index=None, + signature=None, + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=TxOutput(**out2.__dict__))), - # segwit - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), - serialized=TxRequestSerializedType( - # returned serialized out2 - serialized_tx=unhexlify( - '3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87'), - signature_index=None, - signature=None, - )), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + # returned serialized out2 + serialized_tx=unhexlify( + "3df39f060000000017a91458b53ea7f832e8f096e896b8713a8c6df0e892ca87" + ), + signature_index=None, + signature=None, + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - serialized_tx=unhexlify('02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900'), - signature_index=0, - signature=unhexlify('3045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify( + "02483045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80012103e7bfe10708f715e8538c92d46ca50db6f657bbc455b7494e6a0303ccdb868b7904ee0900" + ), + signature_index=0, + signature=unhexlify( + "3045022100b7ce2972bcbc3a661fe320ba901e680913b2753fcb47055c9c6ba632fc4acf81022001c3cfd6c2fe92eb60f5176ce0f43707114dd7223da19c56f2df89c13c2fef80" + ), + ), + ), ] ns = _get_schemas_for_coin(coin) @@ -312,5 +468,5 @@ class TestSignSegwitTxP2WPKHInP2SH_GRS(unittest.TestCase): signer.send(None) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.sign_tx.writers.py b/core/tests/test_apps.bitcoin.sign_tx.writers.py index 0dd6949b82..6ce2d989f8 100644 --- a/core/tests/test_apps.bitcoin.sign_tx.writers.py +++ b/core/tests/test_apps.bitcoin.sign_tx.writers.py @@ -15,7 +15,7 @@ class TestWriters(unittest.TestCase): "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" ), prev_index=0, - sequence=0xffffffff, + sequence=0xFFFFFFFF, script_sig=b"0123456789", ) @@ -25,7 +25,9 @@ class TestWriters(unittest.TestCase): for bad_prevhash in (b"", b"x", b"hello", b"x" * 33): inp.prev_hash = bad_prevhash - self.assertRaises(AssertionError, writers.write_tx_input, b, inp, inp.script_sig) + self.assertRaises( + AssertionError, writers.write_tx_input, b, inp, inp.script_sig + ) def test_tx_input_check(self): inp = TxInput( @@ -36,18 +38,23 @@ class TestWriters(unittest.TestCase): ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, - sequence=0xffffffff, - script_pubkey=unhexlify("76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac"), + sequence=0xFFFFFFFF, + script_pubkey=unhexlify( + "76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac" + ), script_sig=b"0123456789", ) b = bytearray() writers.write_tx_input_check(b, inp) - self.assertEqual(len(b), 4 + 4 + 32 + 4 + 11 + 4 + 4 + 1 + 8 + 1 + 1 + 1 + 4 + 26) + self.assertEqual( + len(b), 4 + 4 + 32 + 4 + 11 + 4 + 4 + 1 + 8 + 1 + 1 + 1 + 4 + 26 + ) for bad_prevhash in (b"", b"x", b"hello", b"x" * 33): inp.prev_hash = bad_prevhash self.assertRaises(AssertionError, writers.write_tx_input_check, b, inp) + if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py index 893aef17c9..bcadb66185 100644 --- a/core/tests/test_apps.bitcoin.signtx.fee_threshold.py +++ b/core/tests/test_apps.bitcoin.signtx.fee_threshold.py @@ -107,65 +107,150 @@ class TestSignTxFeeThreshold(unittest.TestCase): """ def test_under_threshold(self): - coin_bitcoin = coins.by_name('Bitcoin') + coin_bitcoin = coins.by_name("Bitcoin") - ptx1 = PrevTx(version=1, lock_time=0, inputs_count=2, outputs_count=1, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503'), - prev_hash=unhexlify('c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf'), - prev_index=1, - sequence=0xffff_ffff) - pinp2 = PrevInput(script_sig=unhexlify('48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214'), - prev_hash=unhexlify('1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf'), - prev_index=1, - sequence=0xffff_ffff) - pout1 = PrevOutput(script_pubkey=unhexlify('76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac'), - amount=390000) + ptx1 = PrevTx( + version=1, lock_time=0, inputs_count=2, outputs_count=1, extra_data_len=0 + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "483045022072ba61305fe7cb542d142b8f3299a7b10f9ea61f6ffaab5dca8142601869d53c0221009a8027ed79eb3b9bc13577ac2853269323434558528c6b6a7e542be46e7e9a820141047a2d177c0f3626fc68c53610b0270fa6156181f46586c679ba6a88b34c6f4874686390b4d92e5769fbb89c8050b984f4ec0b257a0e5c4ff8bd3b035a51709503" + ), + prev_hash=unhexlify( + "c16a03f1cf8f99f6b5297ab614586cacec784c2d259af245909dedb0e39eddcf" + ), + prev_index=1, + sequence=0xFFFF_FFFF, + ) + pinp2 = PrevInput( + script_sig=unhexlify( + "48304502200fd63adc8f6cb34359dc6cca9e5458d7ea50376cbd0a74514880735e6d1b8a4c0221008b6ead7fe5fbdab7319d6dfede3a0bc8e2a7c5b5a9301636d1de4aa31a3ee9b101410486ad608470d796236b003635718dfc07c0cac0cfc3bfc3079e4f491b0426f0676e6643a39198e8e7bdaffb94f4b49ea21baa107ec2e237368872836073668214" + ), + prev_hash=unhexlify( + "1ae39a2f8d59670c8fc61179148a8e61e039d0d9e8ab08610cb69b4a19453eaf" + ), + prev_index=1, + sequence=0xFFFF_FFFF, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify( + "76a91424a56db43cf6f2b02e838ea493f95d8d6047423188ac" + ), + amount=390000, + ) - inp1 = TxInput(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e - amount=390000, - prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), - prev_index=0, - multisig=None, - sequence=0xffff_ffff) - out1 = TxOutput(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1', - amount=390000 - 90000, # fee increased to 90000, slightly less than the threshold - script_type=OutputScriptType.PAYTOADDRESS, - multisig=None, - address_n=[]) - tx = SignTx(coin_name=None, version=1, lock_time=0, inputs_count=1, outputs_count=1) + inp1 = TxInput( + address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e + amount=390000, + prev_hash=unhexlify( + "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" + ), + prev_index=0, + multisig=None, + sequence=0xFFFF_FFFF, + ) + out1 = TxOutput( + address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", + amount=390000 + - 90000, # fee increased to 90000, slightly less than the threshold + script_type=OutputScriptType.PAYTOADDRESS, + multisig=None, + address_n=[], + ) + tx = SignTx( + coin_name=None, version=1, lock_time=0, inputs_count=1, outputs_count=1 + ) # precomputed tx weight is 768 fee_rate = 90000 / (768 / 4) messages = [ None, - - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), helpers.UiConfirmForeignAddress(address_n=inp1.address_n), True, - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False), True, helpers.UiConfirmMultipleAccounts(), True, - helpers.UiConfirmTotal(300000 + 90000, 90000, fee_rate, coin_bitcoin, AmountUnit.BITCOIN, None), + helpers.UiConfirmTotal( + 300000 + 90000, 90000, fee_rate, coin_bitcoin, AmountUnit.BITCOIN, None + ), True, - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, + tx_hash=unhexlify( + "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" + ), + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType( + request_index=0, + tx_hash=unhexlify( + "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" + ), + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=1, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType( + request_index=1, + tx_hash=unhexlify( + "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" + ), + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp2)), - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882')), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType( + request_index=0, + tx_hash=unhexlify( + "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" + ), + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType(serialized_tx=unhexlify('0100000001'))), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + serialized_tx=unhexlify("0100000001") + ), + ), ] - seed = bip39.seed('alcohol woman abuse must during monitor noble actual mixed trade anger aisle', '') + seed = bip39.seed( + "alcohol woman abuse must during monitor noble actual mixed trade anger aisle", + "", + ) keychain = Keychain(seed, coin_bitcoin.curve_name, [AlwaysMatchingSchema]) signer = bitcoin.Bitcoin(tx, keychain, coin_bitcoin, None).signer() @@ -176,5 +261,5 @@ class TestSignTxFeeThreshold(unittest.TestCase): self.assertEqual(res, response) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.signtx.omni.py b/core/tests/test_apps.bitcoin.signtx.omni.py index e566c408da..395b7699c8 100644 --- a/core/tests/test_apps.bitcoin.signtx.omni.py +++ b/core/tests/test_apps.bitcoin.signtx.omni.py @@ -2,17 +2,17 @@ from common import * from apps.bitcoin.sign_tx.omni import is_valid, parse -class TestSignTxOmni(unittest.TestCase): +class TestSignTxOmni(unittest.TestCase): def test_is_valid(self): VECTORS = { - "6f6d6e69": False, - "6f6d6e69000000": False, - "6f6d6e6900000000": True, - "6f6d6e69000000000000001f0000000020c85580": True, - "0f6d6e69000000000000001f0000000020c85580": False, - "6f6d6e69000000000000001f0000000020c8558000": True, - "6f6d6e69000000000000001f0000000020c855": True, + "6f6d6e69": False, + "6f6d6e69000000": False, + "6f6d6e6900000000": True, + "6f6d6e69000000000000001f0000000020c85580": True, + "0f6d6e69000000000000001f0000000020c85580": False, + "6f6d6e69000000000000001f0000000020c8558000": True, + "6f6d6e69000000000000001f0000000020c855": True, } for k, v in VECTORS.items(): k = unhexlify(k) @@ -20,15 +20,16 @@ class TestSignTxOmni(unittest.TestCase): def test_parse(self): VECTORS = { - "6f6d6e69000000000000001f000000002b752ee0": "Simple send of 7.291 USDT", - "6f6d6e69000000000000001f0000000020c85580": "Simple send of 5.5 USDT", - "6f6d6e690000000000000003000000002b752ee0": "Simple send of 729,100,000 MAID", - "6f6d6e690000000000000000000000002b752ee0": "Simple send of 729,100,000 UNKN", - "6f6d6e6901000000": "Unknown transaction", + "6f6d6e69000000000000001f000000002b752ee0": "Simple send of 7.291 USDT", + "6f6d6e69000000000000001f0000000020c85580": "Simple send of 5.5 USDT", + "6f6d6e690000000000000003000000002b752ee0": "Simple send of 729,100,000 MAID", + "6f6d6e690000000000000000000000002b752ee0": "Simple send of 729,100,000 UNKN", + "6f6d6e6901000000": "Unknown transaction", } for k, v in VECTORS.items(): k = unhexlify(k) self.assertEqual(parse(k), v) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.signtx.py b/core/tests/test_apps.bitcoin.signtx.py index 6d0ee620fd..297a21c3ab 100644 --- a/core/tests/test_apps.bitcoin.signtx.py +++ b/core/tests/test_apps.bitcoin.signtx.py @@ -113,7 +113,14 @@ class TestSignTx(unittest.TestCase): TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin_bitcoin, AmountUnit.BITCOIN, 0, False), True, - helpers.UiConfirmTotal(3_801_747, 50_000, fee_rate, coin_bitcoin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 3_801_747, + 50_000, + fee_rate, + coin_bitcoin, + AmountUnit.BITCOIN, + inp1.address_n[:3], + ), True, # ButtonRequest(code=ButtonRequest_ConfirmOutput), # ButtonRequest(code=ButtonRequest_SignTx), diff --git a/core/tests/test_apps.bitcoin.signtx_decred.py b/core/tests/test_apps.bitcoin.signtx_decred.py index ef615a5670..a2bfba91e0 100644 --- a/core/tests/test_apps.bitcoin.signtx_decred.py +++ b/core/tests/test_apps.bitcoin.signtx_decred.py @@ -112,7 +112,12 @@ class TestSignTxDecred(unittest.TestCase): helpers.UiConfirmOutput(out1, coin_decred, AmountUnit.BITCOIN, 0, False), True, helpers.UiConfirmTotal( - 200_000_000, 100_000, fee_rate, coin_decred, AmountUnit.BITCOIN, inp1.address_n[:3] + 200_000_000, + 100_000, + fee_rate, + coin_decred, + AmountUnit.BITCOIN, + inp1.address_n[:3], ), True, TxRequest( @@ -294,7 +299,12 @@ class TestSignTxDecred(unittest.TestCase): ), TxAckOutput(tx=TxAckOutputWrapper(output=out3)), helpers.UiConfirmTotal( - 200_000_000, 100_000, fee_rate, coin_decred, AmountUnit.BITCOIN, inp1.address_n[:3] + 200_000_000, + 100_000, + fee_rate, + coin_decred, + AmountUnit.BITCOIN, + inp1.address_n[:3], ), True, TxRequest( diff --git a/core/tests/test_apps.bitcoin.signtx_grs.py b/core/tests/test_apps.bitcoin.signtx_grs.py index 55abd95516..3c98b60899 100644 --- a/core/tests/test_apps.bitcoin.signtx_grs.py +++ b/core/tests/test_apps.bitcoin.signtx_grs.py @@ -41,69 +41,168 @@ class TestSignTx_GRS(unittest.TestCase): # http://groestlsight.groestlcoin.org/tx/f56521b17b828897f72b30dd21b0192fd942342e89acbb06abf1d446282c30f5 # ptx1: http://groestlsight.groestlcoin.org/api/tx/cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a - coin = coins.by_name('Groestlcoin') + coin = coins.by_name("Groestlcoin") - ptx1 = PrevTx(version=1, lock_time=2160993, inputs_count=1, outputs_count=1, extra_data_len=0) - pinp1 = PrevInput(script_sig=unhexlify('48304502210096a287593b1212a188e778596eb8ecd4cc169b93a4d115226460d8e3deae431c02206c78ec09b3df977f04a6df5eb53181165c4ea5a0b35f826551349130f879d6b8012102cf5126ff54e38a80a919579d7091cafe24840eab1d30fe2b4d59bdd9d267cad8'), - prev_hash=unhexlify('7dc74a738c50c2ae1228ce9890841e5355fd6d7f2c1367e0a74403ab60db3224'), - prev_index=0, - sequence=4294967294) - pout1 = PrevOutput(script_pubkey=unhexlify('76a914172b4e06e9b7881a48d2ee8062b495d0b2517fe888ac'), - amount=210016) + ptx1 = PrevTx( + version=1, + lock_time=2160993, + inputs_count=1, + outputs_count=1, + extra_data_len=0, + ) + pinp1 = PrevInput( + script_sig=unhexlify( + "48304502210096a287593b1212a188e778596eb8ecd4cc169b93a4d115226460d8e3deae431c02206c78ec09b3df977f04a6df5eb53181165c4ea5a0b35f826551349130f879d6b8012102cf5126ff54e38a80a919579d7091cafe24840eab1d30fe2b4d59bdd9d267cad8" + ), + prev_hash=unhexlify( + "7dc74a738c50c2ae1228ce9890841e5355fd6d7f2c1367e0a74403ab60db3224" + ), + prev_index=0, + sequence=4294967294, + ) + pout1 = PrevOutput( + script_pubkey=unhexlify( + "76a914172b4e06e9b7881a48d2ee8062b495d0b2517fe888ac" + ), + amount=210016, + ) - inp1 = TxInput(address_n=[44 | 0x80000000, 17 | 0x80000000, 0 | 0x80000000, 0, 2], # FXHDsC5ZqWQHkDmShzgRVZ1MatpWhwxTAA - prev_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a'), - prev_index=0, - amount=210016) - out1 = TxOutput(address='FtM4zAn9aVYgHgxmamWBgWPyZsb6RhvkA9', - amount=210016 - 192, - script_type=OutputScriptType.PAYTOADDRESS, - address_n=[]) - tx = SignTx(coin_name='Groestlcoin', version=1, lock_time=0, inputs_count=1, outputs_count=1) + inp1 = TxInput( + address_n=[ + 44 | 0x80000000, + 17 | 0x80000000, + 0 | 0x80000000, + 0, + 2, + ], # FXHDsC5ZqWQHkDmShzgRVZ1MatpWhwxTAA + prev_hash=unhexlify( + "cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a" + ), + prev_index=0, + amount=210016, + ) + out1 = TxOutput( + address="FtM4zAn9aVYgHgxmamWBgWPyZsb6RhvkA9", + amount=210016 - 192, + script_type=OutputScriptType.PAYTOADDRESS, + address_n=[], + ) + tx = SignTx( + coin_name="Groestlcoin", + version=1, + lock_time=0, + inputs_count=1, + outputs_count=1, + ) # precomputed tx weight is 768 fee_rate = 192 / (768 / 4) messages = [ None, - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), helpers.UiConfirmOutput(out1, coin, AmountUnit.BITCOIN, 0, False), True, - helpers.UiConfirmTotal(210016, 192, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3]), + helpers.UiConfirmTotal( + 210016, 192, fee_rate, coin, AmountUnit.BITCOIN, inp1.address_n[:3] + ), True, - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - TxRequest(request_type=TXMETA, details=TxRequestDetailsType(request_index=None, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXMETA, + details=TxRequestDetailsType( + request_index=None, + tx_hash=unhexlify( + "cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a" + ), + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevMeta(tx=ptx1), - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType( + request_index=0, + tx_hash=unhexlify( + "cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a" + ), + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevInput(tx=TxAckPrevInputWrapper(input=pinp1)), - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=unhexlify('cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a')), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType( + request_index=0, + tx_hash=unhexlify( + "cb74c8478c5814742c87cffdb4a21231869888f8042fb07a90e015a9db1f9d4a" + ), + ), + serialized=EMPTY_SERIALIZED, + ), TxAckPrevOutput(tx=TxAckPrevOutputWrapper(output=pout1)), # ButtonRequest(code=ButtonRequest_ConfirmOutput), # ButtonRequest(code=ButtonRequest_SignTx), - TxRequest(request_type=TXINPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - signature_index=None, - signature=None, - serialized_tx=unhexlify('0100000001'))), + TxRequest( + request_type=TXINPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + signature_index=None, + signature=None, + serialized_tx=unhexlify("0100000001"), + ), + ), TxAckInput(tx=TxAckInputWrapper(input=inp1)), - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=EMPTY_SERIALIZED), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=EMPTY_SERIALIZED, + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - TxRequest(request_type=TXOUTPUT, details=TxRequestDetailsType(request_index=0, tx_hash=None), serialized=TxRequestSerializedType( - signature_index=0, - signature=unhexlify('304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a74302368761'), - serialized_tx=unhexlify('4a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01'))), + TxRequest( + request_type=TXOUTPUT, + details=TxRequestDetailsType(request_index=0, tx_hash=None), + serialized=TxRequestSerializedType( + signature_index=0, + signature=unhexlify( + "304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a74302368761" + ), + serialized_tx=unhexlify( + "4a9d1fdba915e0907ab02f04f88898863112a2b4fdcf872c7414588c47c874cb000000006a47304402201fb96d20d0778f54520ab59afe70d5fb20e500ecc9f02281cf57934e8029e8e10220383d5a3e80f2e1eb92765b6da0f23d454aecbd8236f083d483e9a7430236876101210331693756f749180aeed0a65a0fab0625a2250bd9abca502282a4cf0723152e67ffffffff01" + ), + ), + ), TxAckOutput(tx=TxAckOutputWrapper(output=out1)), - TxRequest(request_type=TXFINISHED, details=TxRequestDetailsType(), serialized=TxRequestSerializedType( - signature_index=None, - signature=None, - serialized_tx=unhexlify('a0330300000000001976a914fe40329c95c5598ac60752a5310b320cb52d18e688ac00000000'), - )), + TxRequest( + request_type=TXFINISHED, + details=TxRequestDetailsType(), + serialized=TxRequestSerializedType( + signature_index=None, + signature=None, + serialized_tx=unhexlify( + "a0330300000000001976a914fe40329c95c5598ac60752a5310b320cb52d18e688ac00000000" + ), + ), + ), ] - seed = bip39.seed(' '.join(['all'] * 12), '') + seed = bip39.seed(" ".join(["all"] * 12), "") ns = _get_schemas_for_coin(coin) keychain = Keychain(seed, coin.curve_name, ns) signer = bitcoinlike.Bitcoinlike(tx, keychain, coin, None).signer() @@ -116,5 +215,5 @@ class TestSignTx_GRS(unittest.TestCase): signer.send(None) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.txweight.py b/core/tests/test_apps.bitcoin.txweight.py index 6bb76f3449..3fba834e06 100644 --- a/core/tests/test_apps.bitcoin.txweight.py +++ b/core/tests/test_apps.bitcoin.txweight.py @@ -19,54 +19,64 @@ class TestCalculateTxWeight(unittest.TestCase): def test_p2pkh_txweight(self): - coin = coins.by_name('Bitcoin') + coin = coins.by_name("Bitcoin") - inp1 = TxInput(address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e - # amount=390000, - prev_hash=unhexlify('d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882'), - prev_index=0, - amount=None, - script_type=InputScriptType.SPENDADDRESS, - sequence=0xffff_ffff, - multisig=None) - out1 = TxOutput(address='1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1', - amount=390000 - 10000, - script_type=OutputScriptType.PAYTOADDRESS, - address_n=[], - multisig=None) + inp1 = TxInput( + address_n=[0], # 14LmW5k4ssUrtbAB4255zdqv3b4w1TuX9e + # amount=390000, + prev_hash=unhexlify( + "d5f65ee80147b4bcc70b75e4bbf2d7382021b871bd8867ef8fa525ef50864882" + ), + prev_index=0, + amount=None, + script_type=InputScriptType.SPENDADDRESS, + sequence=0xFFFF_FFFF, + multisig=None, + ) + out1 = TxOutput( + address="1MJ2tj2ThBE62zXbBYA5ZaN3fdve5CPAz1", + amount=390000 - 10000, + script_type=OutputScriptType.PAYTOADDRESS, + address_n=[], + multisig=None, + ) calculator = TxWeightCalculator() calculator.add_input(inp1) calculator.add_output(output_derive_script(out1.address, coin)) - serialized_tx = '010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000' - tx_weight = len(serialized_tx) / 2 * 4 # non-segwit tx's weight is simple length*4 + serialized_tx = "010000000182488650ef25a58fef6788bd71b8212038d7f2bbe4750bc7bcb44701e85ef6d5000000006b4830450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede7810121023230848585885f63803a0a8aecdd6538792d5c539215c91698e315bf0253b43dffffffff0160cc0500000000001976a914de9b2a8da088824e8fe51debea566617d851537888ac00000000" + tx_weight = ( + len(serialized_tx) / 2 * 4 + ) # non-segwit tx's weight is simple length*4 self.assertEqual(calculator.get_weight(), tx_weight) def test_p2wpkh_in_p2sh_txweight(self): - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") inp1 = TxInput( # 49'/1'/0'/1/0" - 2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=123456789, - prev_hash=unhexlify('20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337'), + prev_hash=unhexlify( + "20912f98ea3ed849042efed0fdac8cb4fc301961c5988cba56902d8ffb61c337" + ), prev_index=0, script_type=InputScriptType.SPENDP2SHWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) out1 = TxOutput( - address='mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC', + address="mhRx1CeVfaayqRwq5zgRQmD7W5aWBfD5mC", amount=12300000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], multisig=None, ) out2 = TxOutput( - address='2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX', + address="2N1LGaGg836mqSQqiuUBLfcyGBhyZbremDX", script_type=OutputScriptType.PAYTOADDRESS, amount=123456789 - 11000 - 12300000, address_n=[], @@ -85,27 +95,29 @@ class TestCalculateTxWeight(unittest.TestCase): def test_native_p2wpkh_txweight(self): - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") inp1 = TxInput( # 49'/1'/0'/0/0" - tb1qqzv60m9ajw8drqulta4ld4gfx0rdh82un5s65s address_n=[49 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], amount=12300000, - prev_hash=unhexlify('09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a'), + prev_hash=unhexlify( + "09144602765ce3dd8f4329445b20e3684e948709c5cdcaf12da3bb079c99448a" + ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, - sequence=0xffffffff, + sequence=0xFFFFFFFF, multisig=None, ) out1 = TxOutput( - address='2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp', + address="2N4Q5FhU2497BryFfUgbqkAJE87aKHUhXMp", amount=5000000, script_type=OutputScriptType.PAYTOADDRESS, address_n=[], multisig=None, ) out2 = TxOutput( - address='tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu', + address="tb1q694ccp5qcc0udmfwgp692u2s2hjpq5h407urtu", script_type=OutputScriptType.PAYTOADDRESS, amount=12300000 - 11000 - 5000000, address_n=[], @@ -123,12 +135,14 @@ class TestCalculateTxWeight(unittest.TestCase): # total 566 def test_taproot_txweight(self): - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") inp1 = TxInput( address_n=[86 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 1, 0], amount=4600, - prev_hash=unhexlify('7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b'), + prev_hash=unhexlify( + "7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b" + ), prev_index=1, script_type=InputScriptType.SPENDTAPROOT, ) @@ -144,23 +158,27 @@ class TestCalculateTxWeight(unittest.TestCase): calculator.add_output(output_derive_script(out1.address, coin)) # 010000000001017b350e3faca092f39883d7086cdd502c82b6f0314ab61541b062733edef156790100000000ffffffff016211000000000000225120e9af2fc69e20b0be2629cd0e9c34da9f3ef56af7beac4fb4298262bc5a45ec5d0140493145b992dacbd7ea579a415efc2cba20c3bf0f7827d1bcf999109c0d11783fe96f91ddb04a889faa17ad21ecc5c81a578009744e95c7e721aff2a5c442916600000000 - self.assertEqual(calculator.get_weight(), 4*94 + 68) + self.assertEqual(calculator.get_weight(), 4 * 94 + 68) def test_legacy_multisig_txweight(self): - coin = coins.by_name('Bitcoin') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Bitcoin") + seed = bip39.seed(" ".join(["all"] * 12), "") keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema]) nodes = [] for index in range(1, 4): - node = keychain.derive([48 | 0x80000000, 0 | 0x80000000, index | 0x80000000, 0 | 0x80000000]) - nodes.append(HDNodeType( - depth=node.depth(), - child_num=node.child_num(), - fingerprint=node.fingerprint(), - chain_code=node.chain_code(), - public_key=node.public_key(), - )) + node = keychain.derive( + [48 | 0x80000000, 0 | 0x80000000, index | 0x80000000, 0 | 0x80000000] + ) + nodes.append( + HDNodeType( + depth=node.depth(), + child_num=node.child_num(), + fingerprint=node.fingerprint(), + chain_code=node.chain_code(), + public_key=node.public_key(), + ) + ) multisig = MultisigRedeemScriptType( nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 @@ -169,7 +187,9 @@ class TestCalculateTxWeight(unittest.TestCase): inp1 = TxInput( address_n=[48 | 0x80000000, 0 | 0x80000000, 1 | 0x80000000, 0, 0], amount=100000, - prev_hash=unhexlify('c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52'), + prev_hash=unhexlify( + "c6091adf4c0c23982a35899a6e58ae11e703eacd7954f588ed4b9cdefc4dba52" + ), prev_index=1, script_type=InputScriptType.SPENDMULTISIG, multisig=multisig, @@ -186,23 +206,27 @@ class TestCalculateTxWeight(unittest.TestCase): calculator.add_output(output_derive_script(out1.address, coin)) # 010000000152ba4dfcde9c4bed88f55479cdea03e711ae586e9a89352a98230c4cdf1a09c601000000fdfe00004830450221009276eea820aa54a24bd9f1a056cb09a15f50c0816570a7c7878bd1c5ee7248540220677d200aec5e2f25bcf4000bdfab3faa9e1746d7f80c4ae4bfa1f5892eb5dcbf01483045022100c2a9fbfbff1be87036d8a6a22745512b158154f7f3d8f4cad4ba7ed130b37b83022058f5299b4c26222588dcc669399bd88b6f2bc6e04b48276373683853187a4fd6014c69522103dc0ff15b9c85c0d2c87099758bf47d36229c2514aeefcf8dea123f0f93c679762102bfe426e8671601ad46d54d09ee15aa035610d36d411961c87474908d403fbc122102a5d57129c6c96df663ad29492aa18605dad97231e043be8a92f9406073815c5d53aeffffffff01a0860100000000001976a91412e8391ad256dcdc023365978418d658dfecba1c88ac00000000 - self.assertEqual(calculator.get_weight(), 4*341) + self.assertEqual(calculator.get_weight(), 4 * 341) def test_segwit_multisig_txweight(self): - coin = coins.by_name('Testnet') - seed = bip39.seed(' '.join(['all'] * 12), '') + coin = coins.by_name("Testnet") + seed = bip39.seed(" ".join(["all"] * 12), "") keychain = Keychain(seed, coin.curve_name, [AlwaysMatchingSchema]) nodes = [] for index in range(1, 4): - node = keychain.derive([49 | 0x80000000, 1 | 0x80000000, index | 0x80000000]) - nodes.append(HDNodeType( - depth=node.depth(), - child_num=node.child_num(), - fingerprint=node.fingerprint(), - chain_code=node.chain_code(), - public_key=node.public_key(), - )) + node = keychain.derive( + [49 | 0x80000000, 1 | 0x80000000, index | 0x80000000] + ) + nodes.append( + HDNodeType( + depth=node.depth(), + child_num=node.child_num(), + fingerprint=node.fingerprint(), + chain_code=node.chain_code(), + public_key=node.public_key(), + ) + ) multisig = MultisigRedeemScriptType( nodes=nodes, address_n=[0, 0], signatures=[b"", b"", b""], m=2 @@ -210,7 +234,9 @@ class TestCalculateTxWeight(unittest.TestCase): inp1 = TxInput( address_n=[49 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], - prev_hash=unhexlify('c9348040bbc2024e12dcb4a0b4806b0398646b91acf314da028c3f03dd0179fc'), + prev_hash=unhexlify( + "c9348040bbc2024e12dcb4a0b4806b0398646b91acf314da028c3f03dd0179fc" + ), prev_index=1, script_type=InputScriptType.SPENDP2SHWITNESS, multisig=multisig, @@ -228,36 +254,44 @@ class TestCalculateTxWeight(unittest.TestCase): calculator.add_output(output_derive_script(out1.address, coin)) # 01000000000101be0210025c5be68a473f6a38bf53b53bc88d5c46567616026dc056e72b92319c01000000232200208d398cfb58a1d9cdb59ccbce81559c095e8c6f4a3e64966ca385078d9879f95effffffff01887d180000000000220020c5f4a0a4ea7c0392efe0a9670a73264cffa90b19107cd8a8e9750ff93c77fdfb0400483045022100dd6342c65197af27d7894d8b8b88b16b568ee3b5ebfdc55fdfb7caa9650e3b4c02200c7074a5bcb0068f63d9014c7cd2b0490aba75822d315d41aad444e9b86adf5201483045022100e7e6c2d21109512ba0609e93903e84bfb7731ac3962ee2c1cad54a7a30ff99a20220421497930226c39fc3834e8d6da3fc876516239518b0e82e2dc1e3c46271a17c01695221021630971f20fa349ba940a6ba3706884c41579cd760c89901374358db5dd545b92102f2ff4b353702d2bb03d4c494be19d77d0ab53d16161b53fbcaf1afeef4ad0cb52103e9b6b1c691a12ce448f1aedbbd588e064869c79fbd760eae3b8cd8a5f1a224db53ae00000000 - self.assertEqual(calculator.get_weight(), 4*129 + 256) + self.assertEqual(calculator.get_weight(), 4 * 129 + 256) def test_mixed_txweight(self): - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") inp1 = TxInput( address_n=[49 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], amount=20000, - prev_hash=unhexlify('8c3ea7a10ab6d289119b722ec8c27b70c17c722334ced31a0370d782e4b6775d'), + prev_hash=unhexlify( + "8c3ea7a10ab6d289119b722ec8c27b70c17c722334ced31a0370d782e4b6775d" + ), prev_index=0, script_type=InputScriptType.SPENDP2SHWITNESS, ) inp2 = TxInput( address_n=[84 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], amount=15000, - prev_hash=unhexlify('7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b'), + prev_hash=unhexlify( + "7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b" + ), prev_index=0, script_type=InputScriptType.SPENDWITNESS, ) inp3 = TxInput( address_n=[86 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], amount=4450, - prev_hash=unhexlify('7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b'), + prev_hash=unhexlify( + "7956f1de3e7362b04115b64a31f0b6822c50dd6c08d78398f392a0ac3f0e357b" + ), prev_index=0, script_type=InputScriptType.SPENDTAPROOT, ) inp4 = TxInput( address_n=[44 | 0x80000000, 1 | 0x80000000, 1 | 0x80000000, 0, 0], amount=10000, - prev_hash=unhexlify('3ac32e90831d79385eee49d6030a2123cd9d009fe8ffc3d470af9a6a777a119b'), + prev_hash=unhexlify( + "3ac32e90831d79385eee49d6030a2123cd9d009fe8ffc3d470af9a6a777a119b" + ), prev_index=2, script_type=InputScriptType.SPENDADDRESS, ) @@ -302,25 +336,29 @@ class TestCalculateTxWeight(unittest.TestCase): # 010000000001045d77b6e482d770031ad3ce3423727cc1707bc2c82e729b1189d2b60aa1a73e8c0000000017160014a33c6e24c99e108b97bc411e7e9ef31e9d5d6164ffffffff7b350e3faca092f39883d7086cdd502c82b6f0314ab61541b062733edef156790000000000ffffffff852e125137abca2dd7a42837dccfc34edc358c72eefd62978d6747d3be9315900000000000ffffffff9b117a776a9aaf70d4c3ffe89f009dcd23210a03d649ee5e38791d83902ec33a020000006b483045022100f6bd64136839b49822cf7e2050bc5c91346fc18b5cf97a945d4fd6c502f712d002207d1859e66d218f705b704f3cfca0c75410349bb1f50623f4fc2d09d5d8df0a3f012103bae960983f83e28fcb8f0e5f3dc1f1297b9f9636612fd0835b768e1b7275fb9dffffffff05a861000000000000160014d1a739f628f7eca55e8b99e7f32b22dcdbf672d4581b0000000000001976a91402e9b094fd98e2a26e805894eb78f7ff3fef199b88acf41a00000000000017a9141ff816cbeb74817050de585ceb2c772ebf71147a870000000000000000186a1674657374206f66206f705f72657475726e206461746110270000000000002251205a02573f7b39770ac53f73d161dc86f5104c6812bac297cb6ba418f6f1219c070247304402205fae7fa2b5141548593d5623ce5bd82ee18dfc751c243526039c91848efd603702200febfbe3467a68c599245ff89055514f26e146c79b58d932ced2325e6dad1b1a0121021630971f20fa349ba940a6ba3706884c41579cd760c89901374358db5dd545b90247304402201b21212100c84207697cebb852374669c382ed97cbd08afbbdfe1b302802161602206b32b2140d094cf5b7e758135961c95478c8e82fea0df30f56ccee284b79eaea012103f6b2377d52960a6094ec158cf19dcf9e33b3da4798c2302aa5806483ed4187ae01404a81e4b7f55d6d4a26923c5e2daf3cc86ed6030f83ea6e7bb16d7b81b988b34585be21a64ab45ddcc2fb9f17be2dfeff6b22cf943bc3fc8f125a7f463af428ed0000000000 # The witness data is 283 bytes, but two of the DER signatures are one byte below the # average length, so the caculator should estimate 285 bytes of witness data. - self.assertEqual(calculator.get_weight(), 4*477 + 285) + self.assertEqual(calculator.get_weight(), 4 * 477 + 285) def test_external_txweight(self): - coin = coins.by_name('Testnet') + coin = coins.by_name("Testnet") inp1 = TxInput( amount=100000, - prev_hash=unhexlify('e5b7e21b5ba720e81efd6bfa9f854ababdcddc75a43bfa60bf0fe069cfd1bb8a'), + prev_hash=unhexlify( + "e5b7e21b5ba720e81efd6bfa9f854ababdcddc75a43bfa60bf0fe069cfd1bb8a" + ), prev_index=0, script_type=InputScriptType.EXTERNAL, - script_pubkey=unhexlify('00149c02608d469160a92f40fdf8c6ccced029493088'), + script_pubkey=unhexlify("00149c02608d469160a92f40fdf8c6ccced029493088"), ownership_proof=unhexlify( - '534c001900016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c40002483045022100d4ad0374c922848c71d913fba59c81b9075e0d33e884d953f0c4b4806b8ffd0c022024740e6717a2b6a5aa03148c3a28b02c713b4e30fc8aeae67fa69eb20e8ddcd9012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d' + "534c001900016b2055d8190244b2ed2d46513c40658a574d3bc2deb6969c0535bb818b44d2c40002483045022100d4ad0374c922848c71d913fba59c81b9075e0d33e884d953f0c4b4806b8ffd0c022024740e6717a2b6a5aa03148c3a28b02c713b4e30fc8aeae67fa69eb20e8ddcd9012103505f0d82bbdd251511591b34f36ad5eea37d3220c2b81a1189084431ddb3aa3d" ), ) inp2 = TxInput( address_n=[84 | 0x80000000, 1 | 0x80000000, 0 | 0x80000000, 0, 0], - prev_hash=unhexlify('70f9871eb03a38405cfd7a01e0e1448678132d815e2c9f552ad83ae23969509e'), + prev_hash=unhexlify( + "70f9871eb03a38405cfd7a01e0e1448678132d815e2c9f552ad83ae23969509e" + ), prev_index=0, amount=100000, script_type=InputScriptType.SPENDWITNESS, @@ -329,14 +367,16 @@ class TestCalculateTxWeight(unittest.TestCase): inp3 = TxInput( # tb1qldlynaqp0hy4zc2aag3pkenzvxy65saesxw3wd # address_n=parse_path("m/84h/1h/0h/0/1"), - prev_hash=unhexlify('65b768dacccfb209eebd95a1fb80a04f1dd6a3abc6d7b41d5e9d9f91605b37d9'), + prev_hash=unhexlify( + "65b768dacccfb209eebd95a1fb80a04f1dd6a3abc6d7b41d5e9d9f91605b37d9" + ), prev_index=0, amount=10000, script_type=InputScriptType.EXTERNAL, - script_pubkey=unhexlify('0014fb7e49f4017dc951615dea221b66626189aa43b9'), + script_pubkey=unhexlify("0014fb7e49f4017dc951615dea221b66626189aa43b9"), script_sig=bytes(0), witness=unhexlify( - '024730440220432ac60461de52713ad543cbb1484f7eca1a72c615d539b3f42f5668da4501d2022063786a6d6940a5c1ed9c2d2fd02cef90b6c01ddd84829c946561e15be6c0aae1012103dcf3bc936ecb2ec57b8f468050abce8c8756e75fd74273c9977744b1a0be7d03' + "024730440220432ac60461de52713ad543cbb1484f7eca1a72c615d539b3f42f5668da4501d2022063786a6d6940a5c1ed9c2d2fd02cef90b6c01ddd84829c946561e15be6c0aae1012103dcf3bc936ecb2ec57b8f468050abce8c8756e75fd74273c9977744b1a0be7d03" ), ) @@ -352,11 +392,11 @@ class TestCalculateTxWeight(unittest.TestCase): calculator.add_input(inp3) calculator.add_output(output_derive_script(out1.address, coin)) - self.assertEqual(calculator.get_weight(), 4*164 + 325) + self.assertEqual(calculator.get_weight(), 4 * 164 + 325) # non-segwit: header, inputs, outputs, locktime 4*(4+1+3*41+1+31+4) = 4*164 # segwit: segwit header, 2x estimated witness (including stack item count) # and 1x exact witness (including stack item count) 1*(2+108+108+107) = 325 -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.bitcoin.zcash.zip243.py b/core/tests/test_apps.bitcoin.zcash.zip243.py index c1f419b0d9..6bd3d16cd5 100644 --- a/core/tests/test_apps.bitcoin.zcash.zip243.py +++ b/core/tests/test_apps.bitcoin.zcash.zip243.py @@ -142,32 +142,32 @@ class TestZcashZip243(unittest.TestCase): }, # "Test vector 3" from https://github.com/zcash/zips/blob/master/zip-0243.rst { - "expiry": 0x0004b048, + "expiry": 0x0004B048, "inputs": [ { - "amount": 0x02faf080, + "amount": 0x02FAF080, "prevout": [ "d9042195d9a1b65b2f1f79d68ceb1a5ea6459c9651a6ad4dc1f465824785c6a8", 1, ], "script_type": InputScriptType.SPENDADDRESS, "pubkey": "03c6d9cc725bb7e19c026df03bf693ee1171371a8eaf25f04b7a58f6befabcd38c", - "sequence": 0xfffffffe, + "sequence": 0xFFFFFFFE, } ], - "lock_time": 0x0004b029, + "lock_time": 0x0004B029, "outputs": [ { "script_pubkey": "76a9148132712c3ff19f3a151234616777420a6d7ef22688ac", - "amount": 0x02625a00, + "amount": 0x02625A00, }, { "script_pubkey": "76a9145453e4698f02a38abdaa521cd1ff2dee6fac187188ac", - "amount": 0x0098958b, + "amount": 0x0098958B, }, ], "version": 4, - "version_group_id": 0x892f2085, + "version_group_id": 0x892F2085, "branch_id": 0x76B809BB, "prevouts_hash": b"fae31b8dec7b0b77e2c8d6b6eb0e7e4e55abc6574c26dd44464d9408a8e33f11", "sequence_hash": b"6c80d37f12d89b6f17ff198723e7db1247c4811d1a695d74d930f99e98418790", @@ -195,25 +195,41 @@ class TestZcashZip243(unittest.TestCase): for i in v["inputs"]: txi = TxInput( - amount = i["amount"], - prev_hash = unhexlify(i["prevout"][0]), - prev_index = i["prevout"][1], - script_type = i["script_type"], - sequence = i["sequence"], + amount=i["amount"], + prev_hash=unhexlify(i["prevout"][0]), + prev_index=i["prevout"][1], + script_type=i["script_type"], + sequence=i["sequence"], ) zip243.add_input(txi, b"") for o in v["outputs"]: txo = PrevOutput( - amount = o["amount"], - script_pubkey = unhexlify(o["script_pubkey"]), + amount=o["amount"], + script_pubkey=unhexlify(o["script_pubkey"]), ) zip243.add_output(txo, txo.script_pubkey) - self.assertEqual(hexlify(get_tx_hash(zip243.h_prevouts)), v["prevouts_hash"]) - self.assertEqual(hexlify(get_tx_hash(zip243.h_sequence)), v["sequence_hash"]) + self.assertEqual( + hexlify(get_tx_hash(zip243.h_prevouts)), v["prevouts_hash"] + ) + self.assertEqual( + hexlify(get_tx_hash(zip243.h_sequence)), v["sequence_hash"] + ) self.assertEqual(hexlify(get_tx_hash(zip243.h_outputs)), v["outputs_hash"]) - self.assertEqual(hexlify(zip243.hash143(txi, [unhexlify(i["pubkey"])], 1, tx, coin, SigHashType.SIGHASH_ALL)), v["preimage_hash"]) + self.assertEqual( + hexlify( + zip243.hash143( + txi, + [unhexlify(i["pubkey"])], + 1, + tx, + coin, + SigHashType.SIGHASH_ALL, + ) + ), + v["preimage_hash"], + ) if __name__ == "__main__": diff --git a/core/tests/test_apps.cardano.address.py b/core/tests/test_apps.cardano.address.py index 61be57b659..662fc42ed0 100644 --- a/core/tests/test_apps.cardano.address.py +++ b/core/tests/test_apps.cardano.address.py @@ -9,7 +9,10 @@ from apps.common import seed from apps.common.paths import HARDENED if not utils.BITCOIN_ONLY: - from apps.cardano.addresses import derive_human_readable, validate_address_parameters + from apps.cardano.addresses import ( + derive_human_readable, + validate_address_parameters, + ) from apps.cardano.byron_addresses import _address_hash from apps.cardano.helpers import network_ids, protocol_magics from apps.cardano.seed import Keychain @@ -35,9 +38,20 @@ class TestCardanoAddress(unittest.TestCase): # 44'/1815'/0'/0/i' address_parameters = CardanoAddressParametersType( address_type=CardanoAddressType.BYRON, - address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0x80000000 + i], + address_n=[ + 0x80000000 | 44, + 0x80000000 | 1815, + 0x80000000, + 0, + 0x80000000 + i, + ], + ) + address = derive_human_readable( + self.keychain, + address_parameters, + protocol_magics.MAINNET, + network_ids.MAINNET, ) - address = derive_human_readable(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET) self.assertEqual(expected, address) nodes = [ @@ -45,24 +59,26 @@ class TestCardanoAddress(unittest.TestCase): b"3881a8de77d069001010d7f7d5211552e7d539b0e253add710367f95e528ed51", b"9b77608b38e0a0c7861aa234557c81482f42aae2d17993a8ddaec1868fb04d60", b"a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408", - b"cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0" + b"cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0", ), ( b"3003aca659846540b9ed04f2b844f2d8ea964856ca38a7dffedef4f6e528ed51", b"8844ccc81d633e1c7126f30c2524c1652617cf58da755014070215bf5070ba38", b"be28c00ed6cb9b70310f78028f8e3a2db935baf482d84afa590b0b5b864571cc", - b"584b4631d752023a249e980779517280e6c0b3ac7a7f27c6e9456bfd228ca60b" + b"584b4631d752023a249e980779517280e6c0b3ac7a7f27c6e9456bfd228ca60b", ), ( b"68e4482add0a741e14c8f2306bf83206a623e3729dd24175915eedece428ed51", b"3165a80c5efe846224d46a0427cdb2be4f31ea3585c51f4131faefc4328ad95a", b"9a32499976ffb582daa9988dfc42a303de5ed00c320c929f496be3c6eb1cf405", - b"da07ca30a3d1c5fe3c34ce5fa197722446a646624a10bdf8889a4b9c347b2ef2" + b"da07ca30a3d1c5fe3c34ce5fa197722446a646624a10bdf8889a4b9c347b2ef2", ), ] for i, (priv, ext, pub, chain) in enumerate(nodes): - n = self.keychain.derive([0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0x80000000 + i]) + n = self.keychain.derive( + [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0x80000000 + i] + ) self.assertEqual(hexlify(n.private_key()), priv) self.assertEqual(hexlify(n.private_key_ext()), ext) self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())), pub) @@ -81,7 +97,12 @@ class TestCardanoAddress(unittest.TestCase): address_type=CardanoAddressType.BYRON, address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i], ) - address = derive_human_readable(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET) + address = derive_human_readable( + self.keychain, + address_parameters, + protocol_magics.MAINNET, + network_ids.MAINNET, + ) self.assertEqual(address, expected) nodes = [ @@ -89,44 +110,52 @@ class TestCardanoAddress(unittest.TestCase): b"d03ba81163fd55af97bd132bf651a0da5b5e6201b15b1caca60b0be8e028ed51", b"493f44aa8d25fe0d3fe2935c76ea6b3e9e41c79e9dbcbe7131357c5aa1b6cac5", b"b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5", - b"fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7" + b"fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7", ), ( b"08b6438c8dd49d34b71c8e914d6ac3184e5ab3dcc8af023d08503a7edf28ed51", b"3fee605fdfaddc1ee2ea0b246b02c9abc54ad741054bc83943e8b21487b5a053", b"89053545a6c254b0d9b1464e48d2b5fcf91d4e25c128afb1fcfc61d0843338ea", - b"26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a635" + b"26308151516f3b0e02bb1638142747863c520273ce9bd3e5cd91e1d46fe2a635", ), ( b"088f0275bf4a1bd18f08d7ef06c6ddb6ce7e3dc415fb4e89fe21bf39e628ed51", b"4c44563c7df519ea9b4d1801c1ab98b449db28b87f1c3837759c20f68c4c1e65", b"52548cb98e6f46a592bdf7f3598a9abc0126c78dfa3f46d1894ee52a5213e833", - b"91af0668ee449e613e61bbb2482e5ddee1d9b15785727ec3e362c36861bff923" + b"91af0668ee449e613e61bbb2482e5ddee1d9b15785727ec3e362c36861bff923", ), ] for i, (priv, ext, pub, chain) in enumerate(nodes): - n = self.keychain.derive([0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i]) + n = self.keychain.derive( + [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i] + ) self.assertEqual(hexlify(n.private_key()), priv) self.assertEqual(hexlify(n.private_key_ext()), ext) self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())), pub) self.assertEqual(hexlify(n.chain_code()), chain) - def test_root_address_derivation_scheme(self): # 44'/1815' address_parameters = CardanoAddressParametersType( address_type=CardanoAddressType.BYRON, address_n=[0x80000000 | 44, 0x80000000 | 1815], ) - address = derive_human_readable(self.keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET) - self.assertEqual(address, "Ae2tdPwUPEZ2FGHX3yCKPSbSgyuuTYgMxNq652zKopxT4TuWvEd8Utd92w3") + address = derive_human_readable( + self.keychain, + address_parameters, + protocol_magics.MAINNET, + network_ids.MAINNET, + ) + self.assertEqual( + address, "Ae2tdPwUPEZ2FGHX3yCKPSbSgyuuTYgMxNq652zKopxT4TuWvEd8Utd92w3" + ) priv, ext, pub, chain = ( b"204ec79cbb6502a141de60d274962010c7f1c94a2987b26506433184d228ed51", b"975cdd1c8610b44701567f05934c45c8716064263ccfe72ed2167ccb705c09b6", b"8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce", - b"02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a" + b"02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a", ) n = self.keychain.derive([0x80000000 | 44, 0x80000000 | 1815]) @@ -135,22 +164,30 @@ class TestCardanoAddress(unittest.TestCase): self.assertEqual(hexlify(seed.remove_ed25519_prefix(n.public_key())), pub) self.assertEqual(hexlify(n.chain_code()), chain) - def test_address_hash(self): - data = [0, [0, b"}\x1d\xe3\xf2/S\x90M\x00\x7f\xf83\xfa\xdd|\xd6H.\xa1\xe89\x18\xb9\x85\xb4\xea3\xe6<\x16\xd1\x83z\x04\xa6\xaa\xb0\xed\x12\xafV*&\xdbM\x104DT'M\x0b\xfan5\x81\xdf\x1d\xc0/\x13\xc5\xfb\xe5"], {}] + data = [ + 0, + [ + 0, + b"}\x1d\xe3\xf2/S\x90M\x00\x7f\xf83\xfa\xdd|\xd6H.\xa1\xe89\x18\xb9\x85\xb4\xea3\xe6<\x16\xd1\x83z\x04\xa6\xaa\xb0\xed\x12\xafV*&\xdbM\x104DT'M\x0b\xfan5\x81\xdf\x1d\xc0/\x13\xc5\xfb\xe5", + ], + {}, + ] result = _address_hash(data) - self.assertEqual(result, b'\x1c\xca\xee\xc9\x80\xaf}\xb0\x9a\xa8\x96E\xd6\xa4\xd1\xb4\x13\x85\xb9\xc2q\x1d5/{\x12"\xca') - + self.assertEqual( + result, + b'\x1c\xca\xee\xc9\x80\xaf}\xb0\x9a\xa8\x96E\xd6\xa4\xd1\xb4\x13\x85\xb9\xc2q\x1d5/{\x12"\xca', + ) def test_slip39_128(self): mnemonics = [ "extra extend academic bishop cricket bundle tofu goat apart victim " - "enlarge program behavior permit course armed jerky faint language modern", + "enlarge program behavior permit course armed jerky faint language modern", "extra extend academic acne away best indicate impact square oasis " - "prospect painting voting guest either argue username racism enemy eclipse", + "prospect painting voting guest either argue username racism enemy eclipse", "extra extend academic arcade born dive legal hush gross briefing " - "talent drug much home firefly toxic analysis idea umbrella slice" + "talent drug much home firefly toxic analysis idea umbrella slice", ] passphrase = b"TREZOR" identifier, exponent, ems = slip39.recover_ems(mnemonics) @@ -166,7 +203,9 @@ class TestCardanoAddress(unittest.TestCase): self.assertEqual(hexlify(node.private_key()), root_priv) self.assertEqual(hexlify(node.private_key_ext()), root_ext) - self.assertEqual(hexlify(seed.remove_ed25519_prefix(node.public_key())), root_pub) + self.assertEqual( + hexlify(seed.remove_ed25519_prefix(node.public_key())), root_pub + ) self.assertEqual(hexlify(node.chain_code()), root_chain) # Check derived nodes and addresses. @@ -192,8 +231,8 @@ class TestCardanoAddress(unittest.TestCase): b"e8320644cce22a6e9fc33865fc5a598b1cda061c47a548aead3af4ed1cd13954", b"9e2ece5d7fe8119cb76090009be926a84fc5d3b95855b5962ffe2f880836cf09", b"831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de", - b"672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb" - ) + b"672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb", + ), ] for i, (address, priv, ext, pub, chain) in enumerate(nodes): @@ -202,7 +241,12 @@ class TestCardanoAddress(unittest.TestCase): address_type=CardanoAddressType.BYRON, address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i], ) - a = derive_human_readable(keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET) + a = derive_human_readable( + keychain, + address_parameters, + protocol_magics.MAINNET, + network_ids.MAINNET, + ) n = keychain.derive([0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i]) self.assertEqual(a, address) self.assertEqual(hexlify(n.private_key()), priv) @@ -213,11 +257,11 @@ class TestCardanoAddress(unittest.TestCase): def test_slip39_256(self): mnemonics = [ "hobo romp academic axis august founder knife legal recover alien expect " - "emphasis loan kitchen involve teacher capture rebuild trial numb spider forward " - "ladle lying voter typical security quantity hawk legs idle leaves gasoline", + "emphasis loan kitchen involve teacher capture rebuild trial numb spider forward " + "ladle lying voter typical security quantity hawk legs idle leaves gasoline", "hobo romp academic agency ancestor industry argue sister scene midst graduate " - "profile numb paid headset airport daisy flame express scene usual welcome " - "quick silent downtown oral critical step remove says rhythm venture aunt" + "profile numb paid headset airport daisy flame express scene usual welcome " + "quick silent downtown oral critical step remove says rhythm venture aunt", ] passphrase = b"TREZOR" identifier, exponent, ems = slip39.recover_ems(mnemonics) @@ -233,7 +277,9 @@ class TestCardanoAddress(unittest.TestCase): self.assertEqual(hexlify(node.private_key()), root_priv) self.assertEqual(hexlify(node.private_key_ext()), root_ext) - self.assertEqual(hexlify(seed.remove_ed25519_prefix(node.public_key())), root_pub) + self.assertEqual( + hexlify(seed.remove_ed25519_prefix(node.public_key())), root_pub + ) self.assertEqual(hexlify(node.chain_code()), root_chain) # Check derived nodes and addresses. @@ -260,7 +306,7 @@ class TestCardanoAddress(unittest.TestCase): b"ddfe7f27e2894b983df773d8ac2a07973fc37ff36e93a2f2d71fb7327d4e18f4", b"7f145b50ef07fb9accc40ee07a01fe93ceb6fa07d5a9f20fc3c8a48246dd4d02", b"e67d2864614ada5eec8fb8ee1225a94a6fb0a1b3c347c854ec3037351c6a0fc7", - ) + ), ] for i, (address, priv, ext, pub, chain) in enumerate(nodes): @@ -269,7 +315,12 @@ class TestCardanoAddress(unittest.TestCase): address_type=CardanoAddressType.BYRON, address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i], ) - a = derive_human_readable(keychain, address_parameters, protocol_magics.MAINNET, network_ids.MAINNET) + a = derive_human_readable( + keychain, + address_parameters, + protocol_magics.MAINNET, + network_ids.MAINNET, + ) n = keychain.derive([0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i]) self.assertEqual(a, address) self.assertEqual(hexlify(n.private_key()), priv) @@ -290,7 +341,9 @@ class TestCardanoAddress(unittest.TestCase): address_type=CardanoAddressType.BYRON, address_n=[0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, i], ) - address = derive_human_readable(self.keychain, address_parameters, protocol_magics.TESTNET_LEGACY, 0) + address = derive_human_readable( + self.keychain, address_parameters, protocol_magics.TESTNET_LEGACY, 0 + ) self.assertEqual(expected, address) def test_derive_address(self): @@ -298,59 +351,95 @@ class TestCardanoAddress(unittest.TestCase): "BASE": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 4 | HARDENED, 0, 0], - address_n_staking=[1852 | HARDENED, 1815 | HARDENED, 4 | HARDENED, 2, 0] + address_n_staking=[ + 1852 | HARDENED, + 1815 | HARDENED, + 4 | HARDENED, + 2, + 0, + ], ), "BASE_OWN_STAKING_KEY_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 4 | HARDENED, 0, 0], - staking_key_hash=unhexlify("1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff") + staking_key_hash=unhexlify( + "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" + ), ), "BASE_OWN_STAKING_KEY_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 4 | HARDENED, 0, 0], - staking_key_hash=unhexlify("1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff") + staking_key_hash=unhexlify( + "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" + ), ), # staking key hash not owned - derived with "all all..." mnenomnic "BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_4": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 4 | HARDENED, 0, 0], - staking_key_hash=unhexlify("122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277") + staking_key_hash=unhexlify( + "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277" + ), ), # staking key hash not owned - derived with "all all..." mnenomnic "BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_0": CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - staking_key_hash=unhexlify("122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277") + staking_key_hash=unhexlify( + "122a946b9ad3d2ddf029d3a828f0468aece76895f15c9efbd69b4277" + ), ), - "BASE_SCRIPT_KEY_SCRIPT_HASH":CardanoAddressParametersType( + "BASE_SCRIPT_KEY_SCRIPT_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_KEY, - address_n_staking=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - script_payment_hash=unhexlify("0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe"), + address_n_staking=[ + 1852 | HARDENED, + 1815 | HARDENED, + 0 | HARDENED, + 2, + 0, + ], + script_payment_hash=unhexlify( + "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" + ), ), - "BASE_KEY_SCRIPT_HASH":CardanoAddressParametersType( + "BASE_KEY_SCRIPT_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.BASE_KEY_SCRIPT, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - script_staking_hash=unhexlify("8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9"), + script_staking_hash=unhexlify( + "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" + ), ), "BASE_SCRIPT_SCRIPT_HASHES": CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_SCRIPT, - script_payment_hash=unhexlify("0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe"), - script_staking_hash=unhexlify("8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9"), + script_payment_hash=unhexlify( + "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" + ), + script_staking_hash=unhexlify( + "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" + ), ), "POINTER1": CardanoAddressParametersType( address_type=CardanoAddressType.POINTER, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - certificate_pointer=CardanoBlockchainPointerType(block_index=1, tx_index=2, certificate_index=3), + certificate_pointer=CardanoBlockchainPointerType( + block_index=1, tx_index=2, certificate_index=3 + ), ), "POINTER2": CardanoAddressParametersType( address_type=CardanoAddressType.POINTER, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - certificate_pointer=CardanoBlockchainPointerType(block_index=24157, tx_index=177, certificate_index=42), + certificate_pointer=CardanoBlockchainPointerType( + block_index=24157, tx_index=177, certificate_index=42 + ), ), "POINTER_SCRIPT_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.POINTER_SCRIPT, - certificate_pointer=CardanoBlockchainPointerType(block_index=24157, tx_index=177, certificate_index=42), - script_payment_hash=unhexlify("0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe"), + certificate_pointer=CardanoBlockchainPointerType( + block_index=24157, tx_index=177, certificate_index=42 + ), + script_payment_hash=unhexlify( + "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" + ), ), "ENTERPRISE": CardanoAddressParametersType( address_type=CardanoAddressType.ENTERPRISE, @@ -358,60 +447,201 @@ class TestCardanoAddress(unittest.TestCase): ), "ENTERPRISE_SCRIPT_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.ENTERPRISE_SCRIPT, - script_payment_hash=unhexlify("0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe"), + script_payment_hash=unhexlify( + "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" + ), ), "REWARD": CardanoAddressParametersType( address_type=CardanoAddressType.REWARD, - address_n_staking=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], + address_n_staking=[ + 1852 | HARDENED, + 1815 | HARDENED, + 0 | HARDENED, + 2, + 0, + ], ), "REWARD_SCRIPT_HASH": CardanoAddressParametersType( address_type=CardanoAddressType.REWARD_SCRIPT, - script_staking_hash=unhexlify("8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9"), + script_staking_hash=unhexlify( + "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" + ), ), } test_vectors = [ # base address - (network_ids.MAINNET, CardanoAddressType.BASE, address_parameters["BASE"], "addr1q8v42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wnrqua2vw243tmjfjt0h5wsru6appuz8c0pfd75ur7myyeqsx9990"), - (network_ids.TESTNET, CardanoAddressType.BASE, address_parameters["BASE"], "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wnrqua2vw243tmjfjt0h5wsru6appuz8c0pfd75ur7myyeqnsc9fs"), + ( + network_ids.MAINNET, + CardanoAddressType.BASE, + address_parameters["BASE"], + "addr1q8v42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wnrqua2vw243tmjfjt0h5wsru6appuz8c0pfd75ur7myyeqsx9990", + ), + ( + network_ids.TESTNET, + CardanoAddressType.BASE, + address_parameters["BASE"], + "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wnrqua2vw243tmjfjt0h5wsru6appuz8c0pfd75ur7myyeqnsc9fs", + ), # base address with staking key hash - (network_ids.MAINNET, CardanoAddressType.BASE, address_parameters["BASE_OWN_STAKING_KEY_HASH"], "addr1q8v42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsmcs5wgus8qt4atk45lvt4xfxpjtwfhdmvchdf2m3u3hlsydc62k"), - (network_ids.TESTNET, CardanoAddressType.BASE, address_parameters["BASE_OWN_STAKING_KEY_HASH"], "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsmcs5wgus8qt4atk45lvt4xfxpjtwfhdmvchdf2m3u3hls8m96xf"), - (network_ids.MAINNET, CardanoAddressType.BASE, address_parameters["BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_4"], "addr1q8v42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfms06skxl"), - (network_ids.MAINNET, CardanoAddressType.BASE, address_parameters["BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_0"], "addr1qxq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsl3s9zt"), - (network_ids.TESTNET, CardanoAddressType.BASE, address_parameters["BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_4"], "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsvvdk2q"), + ( + network_ids.MAINNET, + CardanoAddressType.BASE, + address_parameters["BASE_OWN_STAKING_KEY_HASH"], + "addr1q8v42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsmcs5wgus8qt4atk45lvt4xfxpjtwfhdmvchdf2m3u3hlsydc62k", + ), + ( + network_ids.TESTNET, + CardanoAddressType.BASE, + address_parameters["BASE_OWN_STAKING_KEY_HASH"], + "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsmcs5wgus8qt4atk45lvt4xfxpjtwfhdmvchdf2m3u3hls8m96xf", + ), + ( + network_ids.MAINNET, + CardanoAddressType.BASE, + address_parameters["BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_4"], + "addr1q8v42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfms06skxl", + ), + ( + network_ids.MAINNET, + CardanoAddressType.BASE, + address_parameters["BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_0"], + "addr1qxq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsl3s9zt", + ), + ( + network_ids.TESTNET, + CardanoAddressType.BASE, + address_parameters["BASE_FOREIGN_STAKING_KEY_HASH_ACCOUNT_4"], + "addr_test1qrv42wjda8r6mpfj40d36znlgfdcqp7jtj03ah8skh6u8wsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsvvdk2q", + ), # base_script_key address - (network_ids.MAINNET, CardanoAddressType.BASE_SCRIPT_KEY, address_parameters["BASE_SCRIPT_KEY_SCRIPT_HASH"], "addr1zyx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3lsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsf42dkl"), - (network_ids.TESTNET, CardanoAddressType.BASE_SCRIPT_KEY, address_parameters["BASE_SCRIPT_KEY_SCRIPT_HASH"], "addr_test1zqx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3lsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfms2rhd6q"), + ( + network_ids.MAINNET, + CardanoAddressType.BASE_SCRIPT_KEY, + address_parameters["BASE_SCRIPT_KEY_SCRIPT_HASH"], + "addr1zyx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3lsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsf42dkl", + ), + ( + network_ids.TESTNET, + CardanoAddressType.BASE_SCRIPT_KEY, + address_parameters["BASE_SCRIPT_KEY_SCRIPT_HASH"], + "addr_test1zqx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3lsj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfms2rhd6q", + ), # base_key_script address - (network_ids.MAINNET, CardanoAddressType.BASE_KEY_SCRIPT, address_parameters["BASE_KEY_SCRIPT_HASH"], "addr1yxq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z925d004u0fv0r3a4ld7f8yg8rmxnk5dsxf542ghcc42ngw5s8vnrtt"), - (network_ids.TESTNET, CardanoAddressType.BASE_KEY_SCRIPT, address_parameters["BASE_KEY_SCRIPT_HASH"], "addr_test1yzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z925d004u0fv0r3a4ld7f8yg8rmxnk5dsxf542ghcc42ngw5sy6wr85"), + ( + network_ids.MAINNET, + CardanoAddressType.BASE_KEY_SCRIPT, + address_parameters["BASE_KEY_SCRIPT_HASH"], + "addr1yxq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z925d004u0fv0r3a4ld7f8yg8rmxnk5dsxf542ghcc42ngw5s8vnrtt", + ), + ( + network_ids.TESTNET, + CardanoAddressType.BASE_KEY_SCRIPT, + address_parameters["BASE_KEY_SCRIPT_HASH"], + "addr_test1yzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z925d004u0fv0r3a4ld7f8yg8rmxnk5dsxf542ghcc42ngw5sy6wr85", + ), # base_script_script address - (network_ids.MAINNET, CardanoAddressType.BASE_SCRIPT_SCRIPT, address_parameters["BASE_SCRIPT_SCRIPT_HASHES"], "addr1xyx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3l5d004u0fv0r3a4ld7f8yg8rmxnk5dsxf542ghcc42ngw5s3gftll"), - (network_ids.TESTNET, CardanoAddressType.BASE_SCRIPT_SCRIPT, address_parameters["BASE_SCRIPT_SCRIPT_HASHES"], "addr_test1xqx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3l5d004u0fv0r3a4ld7f8yg8rmxnk5dsxf542ghcc42ngw5sj75tnq"), + ( + network_ids.MAINNET, + CardanoAddressType.BASE_SCRIPT_SCRIPT, + address_parameters["BASE_SCRIPT_SCRIPT_HASHES"], + "addr1xyx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3l5d004u0fv0r3a4ld7f8yg8rmxnk5dsxf542ghcc42ngw5s3gftll", + ), + ( + network_ids.TESTNET, + CardanoAddressType.BASE_SCRIPT_SCRIPT, + address_parameters["BASE_SCRIPT_SCRIPT_HASHES"], + "addr_test1xqx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3l5d004u0fv0r3a4ld7f8yg8rmxnk5dsxf542ghcc42ngw5sj75tnq", + ), # pointer address - (network_ids.MAINNET, CardanoAddressType.POINTER, address_parameters["POINTER1"], "addr1gxq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92spqgpsl97q83"), - (network_ids.TESTNET, CardanoAddressType.POINTER, address_parameters["POINTER2"], "addr_test1gzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z925ph3wczvf2ag2x9t"), + ( + network_ids.MAINNET, + CardanoAddressType.POINTER, + address_parameters["POINTER1"], + "addr1gxq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92spqgpsl97q83", + ), + ( + network_ids.TESTNET, + CardanoAddressType.POINTER, + address_parameters["POINTER2"], + "addr_test1gzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z925ph3wczvf2ag2x9t", + ), # pointer_script address - (network_ids.MAINNET, CardanoAddressType.POINTER_SCRIPT, address_parameters["POINTER_SCRIPT_HASH"], "addr12yx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3l5ph3wczvf2zmd4yp"), - (network_ids.TESTNET, CardanoAddressType.POINTER_SCRIPT, address_parameters["POINTER_SCRIPT_HASH"], "addr_test12qx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3l5ph3wczvf2d4sugn"), + ( + network_ids.MAINNET, + CardanoAddressType.POINTER_SCRIPT, + address_parameters["POINTER_SCRIPT_HASH"], + "addr12yx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3l5ph3wczvf2zmd4yp", + ), + ( + network_ids.TESTNET, + CardanoAddressType.POINTER_SCRIPT, + address_parameters["POINTER_SCRIPT_HASH"], + "addr_test12qx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3l5ph3wczvf2d4sugn", + ), # enterprise address - (network_ids.MAINNET, CardanoAddressType.ENTERPRISE, address_parameters["ENTERPRISE"], "addr1vxq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92su77c6m"), - (network_ids.TESTNET, CardanoAddressType.ENTERPRISE, address_parameters["ENTERPRISE"], "addr_test1vzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92s8k2y47"), + ( + network_ids.MAINNET, + CardanoAddressType.ENTERPRISE, + address_parameters["ENTERPRISE"], + "addr1vxq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92su77c6m", + ), + ( + network_ids.TESTNET, + CardanoAddressType.ENTERPRISE, + address_parameters["ENTERPRISE"], + "addr_test1vzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92s8k2y47", + ), # enterprise_script address - (network_ids.MAINNET, CardanoAddressType.ENTERPRISE_SCRIPT, address_parameters["ENTERPRISE_SCRIPT_HASH"], "addr1wyx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3lsqee7sp"), - (network_ids.TESTNET, CardanoAddressType.ENTERPRISE_SCRIPT, address_parameters["ENTERPRISE_SCRIPT_HASH"], "addr_test1wqx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3lsm3dzly"), + ( + network_ids.MAINNET, + CardanoAddressType.ENTERPRISE_SCRIPT, + address_parameters["ENTERPRISE_SCRIPT_HASH"], + "addr1wyx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3lsqee7sp", + ), + ( + network_ids.TESTNET, + CardanoAddressType.ENTERPRISE_SCRIPT, + address_parameters["ENTERPRISE_SCRIPT_HASH"], + "addr_test1wqx44jlk580mpjrjfesd7v2fsuc4ejlh3wmvp7dk702k3lsm3dzly", + ), # reward address - (network_ids.MAINNET, CardanoAddressType.REWARD, address_parameters["REWARD"], "stake1uyfz49rtntfa9h0s98f6s28sg69weemgjhc4e8hm66d5yacalmqha"), - (network_ids.TESTNET, CardanoAddressType.REWARD, address_parameters["REWARD"], "stake_test1uqfz49rtntfa9h0s98f6s28sg69weemgjhc4e8hm66d5yac643znq"), + ( + network_ids.MAINNET, + CardanoAddressType.REWARD, + address_parameters["REWARD"], + "stake1uyfz49rtntfa9h0s98f6s28sg69weemgjhc4e8hm66d5yacalmqha", + ), + ( + network_ids.TESTNET, + CardanoAddressType.REWARD, + address_parameters["REWARD"], + "stake_test1uqfz49rtntfa9h0s98f6s28sg69weemgjhc4e8hm66d5yac643znq", + ), # reward_script address - (network_ids.MAINNET, CardanoAddressType.REWARD_SCRIPT, address_parameters["REWARD_SCRIPT_HASH"], "stake17xxhh6785k83c76lklynjyr3anfm2xcry624ytuv24f582gt5mad4"), - (network_ids.TESTNET, CardanoAddressType.REWARD_SCRIPT, address_parameters["REWARD_SCRIPT_HASH"], "stake_test17zxhh6785k83c76lklynjyr3anfm2xcry624ytuv24f582gv73lfg"), + ( + network_ids.MAINNET, + CardanoAddressType.REWARD_SCRIPT, + address_parameters["REWARD_SCRIPT_HASH"], + "stake17xxhh6785k83c76lklynjyr3anfm2xcry624ytuv24f582gt5mad4", + ), + ( + network_ids.TESTNET, + CardanoAddressType.REWARD_SCRIPT, + address_parameters["REWARD_SCRIPT_HASH"], + "stake_test17zxhh6785k83c76lklynjyr3anfm2xcry624ytuv24f582gv73lfg", + ), ] - - for network_id, address_type, address_parameters, expected_address in test_vectors: + for ( + network_id, + address_type, + address_parameters, + expected_address, + ) in test_vectors: validate_address_parameters(address_parameters) - actual_address = derive_human_readable(self.keychain, address_parameters, protocol_magics.MAINNET, network_id) + actual_address = derive_human_readable( + self.keychain, address_parameters, protocol_magics.MAINNET, network_id + ) self.assertEqual(actual_address, expected_address) @@ -428,34 +658,60 @@ class TestCardanoAddress(unittest.TestCase): CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - address_n_staking=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 2, 0], - staking_key_hash=unhexlify("1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff"), + address_n_staking=[ + 1852 | HARDENED, + 1815 | HARDENED, + 0 | HARDENED, + 2, + 0, + ], + staking_key_hash=unhexlify( + "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" + ), ), # base address - staking_key_hash is too short CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], address_n_staking=None, - staking_key_hash=unhexlify("1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8d"), + staking_key_hash=unhexlify( + "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8d" + ), ), # base address - address_n_staking is not a staking path CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - address_n_staking=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], + address_n_staking=[ + 1852 | HARDENED, + 1815 | HARDENED, + 0 | HARDENED, + 0, + 0, + ], staking_key_hash=None, ), # base_script_key address - script_payment_hash is None CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_KEY, script_payment_hash=None, - staking_key_hash=unhexlify("1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8d"), + staking_key_hash=unhexlify( + "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8d" + ), ), # base_script_key address - address_n_staking is not a staking path CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_KEY, - script_payment_hash=unhexlify("0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe"), - address_n_staking=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], + script_payment_hash=unhexlify( + "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" + ), + address_n_staking=[ + 1852 | HARDENED, + 1815 | HARDENED, + 0 | HARDENED, + 0, + 0, + ], ), # base_key_script address - script_staking_hash is None CardanoAddressParametersType( @@ -467,12 +723,16 @@ class TestCardanoAddress(unittest.TestCase): CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_SCRIPT, script_payment_hash=None, - script_staking_hash=unhexlify("8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9"), + script_staking_hash=unhexlify( + "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" + ), ), # base_script_script address - script_staking and script_staking_hash are None CardanoAddressParametersType( address_type=CardanoAddressType.BASE_SCRIPT_SCRIPT, - script_payment_hash=unhexlify("0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe"), + script_payment_hash=unhexlify( + "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" + ), script_staking_hash=None, ), # pointer address - pointer is None @@ -484,14 +744,18 @@ class TestCardanoAddress(unittest.TestCase): # pointer_script address - pointer is None CardanoAddressParametersType( address_type=CardanoAddressType.POINTER_SCRIPT, - script_payment_hash=unhexlify("0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe"), + script_payment_hash=unhexlify( + "0d5acbf6a1dfb0c8724e60df314987315ccbf78bb6c0f9b6f3d568fe" + ), certificate_pointer=None, ), # pointer_script address - script_payment_script is None CardanoAddressParametersType( address_type=CardanoAddressType.POINTER_SCRIPT, script_payment_hash=None, - certificate_pointer=CardanoBlockchainPointerType(block_index=24157, tx_index=177, certificate_index=42), + certificate_pointer=CardanoBlockchainPointerType( + block_index=24157, tx_index=177, certificate_index=42 + ), ), # enterprise_script address - script_payment_hash is None CardanoAddressParametersType( @@ -501,29 +765,34 @@ class TestCardanoAddress(unittest.TestCase): # reward address - non staking path CardanoAddressParametersType( address_type=CardanoAddressType.REWARD, - address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0] + address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], ), # reward_script address - script_staking_hash is None CardanoAddressParametersType( address_type=CardanoAddressType.REWARD_SCRIPT, script_staking_hash=None, ), - # Shelley addresses with Byron namespace CardanoAddressParametersType( address_type=CardanoAddressType.BASE, address_n=[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - staking_key_hash=unhexlify("1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff"), + staking_key_hash=unhexlify( + "1bc428e4720702ebd5dab4fb175324c192dc9bb76cc5da956e3c8dff" + ), ), CardanoAddressParametersType( address_type=CardanoAddressType.BASE_KEY_SCRIPT, address_n=[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - script_staking_hash=unhexlify("8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9"), + script_staking_hash=unhexlify( + "8d7bebc7a58f1c7b5fb7c9391071ecd3b51b032695522f8c555343a9" + ), ), CardanoAddressParametersType( address_type=CardanoAddressType.POINTER, address_n=[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - certificate_pointer=CardanoBlockchainPointerType(block_index=0, tx_index=0, certificate_index=0) + certificate_pointer=CardanoBlockchainPointerType( + block_index=0, tx_index=0, certificate_index=0 + ), ), CardanoAddressParametersType( address_type=CardanoAddressType.ENTERPRISE, @@ -533,12 +802,11 @@ class TestCardanoAddress(unittest.TestCase): address_type=CardanoAddressType.REWARD, address_n=[44 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], ), - # Byron address with Shelley namespace CardanoAddressParametersType( address_type=CardanoAddressType.BYRON, address_n=[1852 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], - ) + ), ] for address_parameters in test_vectors: @@ -546,5 +814,5 @@ class TestCardanoAddress(unittest.TestCase): validate_address_parameters(address_parameters) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.cardano.bech32.py b/core/tests/test_apps.cardano.bech32.py index 92bf0e8e93..9b6867623f 100644 --- a/core/tests/test_apps.cardano.bech32.py +++ b/core/tests/test_apps.cardano.bech32.py @@ -2,19 +2,31 @@ from common import * from apps.cardano.helpers import bech32 + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestCardanoBech32(unittest.TestCase): def test_decode_and_encode(self): expected_bechs = [ # human readable part, bech32 ("a", "a12uel5l"), - ("an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio", - "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs"), + ( + "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio", + "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs", + ), ("abcdef", "abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw"), - ("1", "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j"), + ( + "1", + "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", + ), ("split", "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w"), - ("addr", "addr1qzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsw8ezsk"), - ("addr_test", "addr_test1qzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsu8d9w5") + ( + "addr", + "addr1qzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsw8ezsk", + ), + ( + "addr_test", + "addr_test1qzq0nckg3ekgzuqg7w5p9mvgnd9ym28qh5grlph8xd2z92sj922xhxkn6twlq2wn4q50q352annk3903tj00h45mgfmsu8d9w5", + ), ] for expected_human_readable_part, expected_bech in expected_bechs: diff --git a/core/tests/test_apps.cardano.get_public_key.py b/core/tests/test_apps.cardano.get_public_key.py index 4b1b17ea90..a235d619e4 100644 --- a/core/tests/test_apps.cardano.get_public_key.py +++ b/core/tests/test_apps.cardano.get_public_key.py @@ -23,7 +23,6 @@ class TestCardanoGetPublicKey(unittest.TestCase): [0x80000000 | 44, 0x80000000 | 1815], [0x80000000 | 44, 0x80000000 | 1815, 0, 0, 0], [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0], - [0x80000000 | 1852, 0x80000000 | 1815, 0x80000000, 0, 0x80000000], [0x80000000 | 1852, 0x80000000 | 1815], [0x80000000 | 1852, 0x80000000 | 1815, 0, 0, 0], @@ -31,39 +30,36 @@ class TestCardanoGetPublicKey(unittest.TestCase): ] public_keys = [ - b'a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408', - b'8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce', - b'17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791', - b'b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5', - - b'f698a764b23aa6667b1157fc4247c6a1b58c21a3865ac6a47a3590167a9e0211', - b'e9c46841be76e3be0289694fd5c7503c04f40e5b036abac200b98a9006cf6647', - b'6d225f078ca611f00d86cbfd8ba6c6ac7826721434eae6525686efb878b72370', - b'5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1', + b"a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408", + b"8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce", + b"17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791", + b"b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5", + b"f698a764b23aa6667b1157fc4247c6a1b58c21a3865ac6a47a3590167a9e0211", + b"e9c46841be76e3be0289694fd5c7503c04f40e5b036abac200b98a9006cf6647", + b"6d225f078ca611f00d86cbfd8ba6c6ac7826721434eae6525686efb878b72370", + b"5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1", ] chain_codes = [ - b'cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0', - b'02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a', - b'646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d', - b'fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7', - - b'13cfb6de37a568aae56cadac907e6469b121464fe1b70a10c213eaea2cbb6636', - b'58f3f46f4a93e7a4431e75b10af7497b747c3053cb7466ed53f4277e78a63c52', - b'f72b3c361381db2d88289440268c94c5e7467c9414375e6b63d03026750f3c66', - b'f123474e140a2c360b01f0fa66f2f22e2e965a5b07a80358cf75f77abbd66088', + b"cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0", + b"02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a", + b"646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d", + b"fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7", + b"13cfb6de37a568aae56cadac907e6469b121464fe1b70a10c213eaea2cbb6636", + b"58f3f46f4a93e7a4431e75b10af7497b747c3053cb7466ed53f4277e78a63c52", + b"f72b3c361381db2d88289440268c94c5e7467c9414375e6b63d03026750f3c66", + b"f123474e140a2c360b01f0fa66f2f22e2e965a5b07a80358cf75f77abbd66088", ] xpub_keys = [ - 'a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0', - '8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a', - '17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d', - 'b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7', - - 'f698a764b23aa6667b1157fc4247c6a1b58c21a3865ac6a47a3590167a9e021113cfb6de37a568aae56cadac907e6469b121464fe1b70a10c213eaea2cbb6636', - 'e9c46841be76e3be0289694fd5c7503c04f40e5b036abac200b98a9006cf664758f3f46f4a93e7a4431e75b10af7497b747c3053cb7466ed53f4277e78a63c52', - '6d225f078ca611f00d86cbfd8ba6c6ac7826721434eae6525686efb878b72370f72b3c361381db2d88289440268c94c5e7467c9414375e6b63d03026750f3c66', - '5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1f123474e140a2c360b01f0fa66f2f22e2e965a5b07a80358cf75f77abbd66088', + "a938c8554ae04616cfaae7cd0eb557475082c4e910242ce774967e0bd7492408cbf6ab47c8eb1a0477fc40b25dbb6c4a99454edb97d6fe5acedd3e238ef46fe0", + "8c47ebce34234d04fd3dfbac33feaba6133e4e3d77c4b5ab18120ec6878ad4ce02ac67c59a8b0264724a635774ca2c242afa10d7ab70e2bf0a8f7d4bb10f1f7a", + "17cc0bf978756d0d5c76f931629036a810c61801b78beecb44555773d13e3791646ac4a6295326bae6831be05921edfbcb362de48dfd37b12e74c227dfad768d", + "b90fb812a2268e9569ff1172e8daed1da3dc7e72c7bded7c5bcb7282039f90d5fd8e71c1543de2cdc7f7623130c5f2cceb53549055fa1f5bc88199989e08cce7", + "f698a764b23aa6667b1157fc4247c6a1b58c21a3865ac6a47a3590167a9e021113cfb6de37a568aae56cadac907e6469b121464fe1b70a10c213eaea2cbb6636", + "e9c46841be76e3be0289694fd5c7503c04f40e5b036abac200b98a9006cf664758f3f46f4a93e7a4431e75b10af7497b747c3053cb7466ed53f4277e78a63c52", + "6d225f078ca611f00d86cbfd8ba6c6ac7826721434eae6525686efb878b72370f72b3c361381db2d88289440268c94c5e7467c9414375e6b63d03026750f3c66", + "5d010cf16fdeff40955633d6c565f3844a288a24967cf6b76acbeb271b4f13c1f123474e140a2c360b01f0fa66f2f22e2e965a5b07a80358cf75f77abbd66088", ] for index, derivation_path in enumerate(derivation_paths): @@ -84,19 +80,19 @@ class TestCardanoGetPublicKey(unittest.TestCase): ] public_keys = [ - b'82f12f1916c0c35a412291e72204f17f033b0b7edf148dfd7d75acd3975c9ac0', - b'd92d0590e76bbf0300112a9f283fba2f7f8af5cf1054d634b610d1e4f541df90', + b"82f12f1916c0c35a412291e72204f17f033b0b7edf148dfd7d75acd3975c9ac0", + b"d92d0590e76bbf0300112a9f283fba2f7f8af5cf1054d634b610d1e4f541df90", ] chain_codes = [ - b'974f9cd4336e23b976f934752026a2d4c32d2e23f0532f4f87152b45fa5ca81f', - b'352499ed19b47f2bc8c164b47df0d55f428cc8c12f96b7e65d7563114ddfd75b', + b"974f9cd4336e23b976f934752026a2d4c32d2e23f0532f4f87152b45fa5ca81f", + b"352499ed19b47f2bc8c164b47df0d55f428cc8c12f96b7e65d7563114ddfd75b", ] xpub_keys = [ - '82f12f1916c0c35a412291e72204f17f033b0b7edf148dfd7d75acd3975c9ac0974f9cd4336e23b976f934752026a2d4c32d2e23f0532f4f87152b45fa5ca81f', - 'd92d0590e76bbf0300112a9f283fba2f7f8af5cf1054d634b610d1e4f541df90352499ed19b47f2bc8c164b47df0d55f428cc8c12f96b7e65d7563114ddfd75b', - ] + "82f12f1916c0c35a412291e72204f17f033b0b7edf148dfd7d75acd3975c9ac0974f9cd4336e23b976f934752026a2d4c32d2e23f0532f4f87152b45fa5ca81f", + "d92d0590e76bbf0300112a9f283fba2f7f8af5cf1054d634b610d1e4f541df90352499ed19b47f2bc8c164b47df0d55f428cc8c12f96b7e65d7563114ddfd75b", + ] for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(keychain, derivation_path) @@ -105,7 +101,6 @@ class TestCardanoGetPublicKey(unittest.TestCase): self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) - def test_get_public_key_scheme_24_words(self): mnemonic = "balance exotic ranch knife glory slow tape favorite yard gym awake ill exist useless parent aim pig stay effort into square gasp credit butter" passphrase = "" @@ -117,19 +112,19 @@ class TestCardanoGetPublicKey(unittest.TestCase): ] public_keys = [ - b'9d45d1e979bd0b942adb1896019c85d08fbc562f012775a1f72fc7be8fe9e4b6', - b'a85a339897354931d584f828f6d79d4227ed16f3468990687ab42f13a87c9ea8', + b"9d45d1e979bd0b942adb1896019c85d08fbc562f012775a1f72fc7be8fe9e4b6", + b"a85a339897354931d584f828f6d79d4227ed16f3468990687ab42f13a87c9ea8", ] chain_codes = [ - b'aad67fd6d620f7af88ad816a229de09cfacff3e28008a528759b2e2cf28d859a', - b'e6f844931e7e2ec724e6e62efde662ae2669355322dc3eb9b307bc1c8e75e219', + b"aad67fd6d620f7af88ad816a229de09cfacff3e28008a528759b2e2cf28d859a", + b"e6f844931e7e2ec724e6e62efde662ae2669355322dc3eb9b307bc1c8e75e219", ] xpub_keys = [ - '9d45d1e979bd0b942adb1896019c85d08fbc562f012775a1f72fc7be8fe9e4b6aad67fd6d620f7af88ad816a229de09cfacff3e28008a528759b2e2cf28d859a', - 'a85a339897354931d584f828f6d79d4227ed16f3468990687ab42f13a87c9ea8e6f844931e7e2ec724e6e62efde662ae2669355322dc3eb9b307bc1c8e75e219', - ] + "9d45d1e979bd0b942adb1896019c85d08fbc562f012775a1f72fc7be8fe9e4b6aad67fd6d620f7af88ad816a229de09cfacff3e28008a528759b2e2cf28d859a", + "a85a339897354931d584f828f6d79d4227ed16f3468990687ab42f13a87c9ea8e6f844931e7e2ec724e6e62efde662ae2669355322dc3eb9b307bc1c8e75e219", + ] for index, derivation_path in enumerate(derivation_paths): key = _get_public_key(keychain, derivation_path) @@ -138,15 +133,14 @@ class TestCardanoGetPublicKey(unittest.TestCase): self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) - def test_slip39_128(self): mnemonics = [ "extra extend academic bishop cricket bundle tofu goat apart victim " - "enlarge program behavior permit course armed jerky faint language modern", + "enlarge program behavior permit course armed jerky faint language modern", "extra extend academic acne away best indicate impact square oasis " - "prospect painting voting guest either argue username racism enemy eclipse", + "prospect painting voting guest either argue username racism enemy eclipse", "extra extend academic arcade born dive legal hush gross briefing " - "talent drug much home firefly toxic analysis idea umbrella slice" + "talent drug much home firefly toxic analysis idea umbrella slice", ] passphrase = b"TREZOR" identifier, exponent, ems = slip39.recover_ems(mnemonics) @@ -160,25 +154,25 @@ class TestCardanoGetPublicKey(unittest.TestCase): derivation_paths = [ [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0], [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 1], - [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 2] + [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 2], ] public_keys = [ - b'bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579', - b'24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c', - b'831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de' + b"bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579", + b"24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c", + b"831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de", ] chain_codes = [ b"dc3f0d2b5cccb822335ef6213fd133f4ca934151ec44a6000aee43b8a101078c", b"6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b", - b"672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb" + b"672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb", ] xpub_keys = [ "bc043d84b8b891d49890edb6aced6f2d78395f255c5b6aea8878b913f83e8579dc3f0d2b5cccb822335ef6213fd133f4ca934151ec44a6000aee43b8a101078c", "24c4fe188a39103db88818bc191fd8571eae7b284ebcbdf2462bde97b058a95c6f7a744035f4b3ddb8f861c18446169643cc3ae85e271b4b4f0eda05cf84c65b", - "831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb" + "831a63d381a8dab1e6e1ee991a4300fc70687aae5f97f4fcf92ed1b6c2bd99de672d6af4707aba201b7940231e83dd357f92f8851b3dfdc224ef311e1b64cdeb", ] for index, derivation_path in enumerate(derivation_paths): @@ -191,11 +185,11 @@ class TestCardanoGetPublicKey(unittest.TestCase): def test_slip39_256(self): mnemonics = [ "hobo romp academic axis august founder knife legal recover alien expect " - "emphasis loan kitchen involve teacher capture rebuild trial numb spider forward " - "ladle lying voter typical security quantity hawk legs idle leaves gasoline", + "emphasis loan kitchen involve teacher capture rebuild trial numb spider forward " + "ladle lying voter typical security quantity hawk legs idle leaves gasoline", "hobo romp academic agency ancestor industry argue sister scene midst graduate " - "profile numb paid headset airport daisy flame express scene usual welcome " - "quick silent downtown oral critical step remove says rhythm venture aunt" + "profile numb paid headset airport daisy flame express scene usual welcome " + "quick silent downtown oral critical step remove says rhythm venture aunt", ] passphrase = b"TREZOR" identifier, exponent, ems = slip39.recover_ems(mnemonics) @@ -209,7 +203,7 @@ class TestCardanoGetPublicKey(unittest.TestCase): derivation_paths = [ [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 0], [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 1], - [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 2] + [0x80000000 | 44, 0x80000000 | 1815, 0x80000000, 0, 2], ] public_keys = [ @@ -237,5 +231,6 @@ class TestCardanoGetPublicKey(unittest.TestCase): self.assertEqual(hexlify(key.node.chain_code), chain_codes[index]) self.assertEqual(key.xpub, xpub_keys[index]) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.cardano.native_script.py b/core/tests/test_apps.cardano.native_script.py index ccad1c6aa7..e05eb222f3 100644 --- a/core/tests/test_apps.cardano.native_script.py +++ b/core/tests/test_apps.cardano.native_script.py @@ -6,7 +6,10 @@ from trezor.messages import CardanoNativeScript if not utils.BITCOIN_ONLY: from apps.cardano.seed import Keychain - from apps.cardano.native_script import get_native_script_hash, validate_native_script + from apps.cardano.native_script import ( + get_native_script_hash, + validate_native_script, + ) VALID_NATIVE_SCRIPTS = [ # PUB_KEY @@ -68,7 +71,7 @@ VALID_NATIVE_SCRIPTS = [ # ALL scripts are empty [ CardanoNativeScript(type=CardanoNativeScriptType.ALL, scripts=[]), - b"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf" + b"d441227553a0f1a965fee7d60a0f724b368dd1bddbc208730fccebcf", ], # ANY [ @@ -92,7 +95,7 @@ VALID_NATIVE_SCRIPTS = [ # ANY scripts are empty [ CardanoNativeScript(type=CardanoNativeScriptType.ANY, scripts=[]), - b"52dc3d43b6d2465e96109ce75ab61abe5e9c1d8a3c9ce6ff8a3af528" + b"52dc3d43b6d2465e96109ce75ab61abe5e9c1d8a3c9ce6ff8a3af528", ], # N OF K [ @@ -122,8 +125,10 @@ VALID_NATIVE_SCRIPTS = [ ], # N_OF_K scripts are empty [ - CardanoNativeScript(type=CardanoNativeScriptType.N_OF_K, required_signatures_count=0, scripts=[]), - b"3530cc9ae7f2895111a99b7a02184dd7c0cea7424f1632d73951b1d7" + CardanoNativeScript( + type=CardanoNativeScriptType.N_OF_K, required_signatures_count=0, scripts=[] + ), + b"3530cc9ae7f2895111a99b7a02184dd7c0cea7424f1632d73951b1d7", ], # INVALID BEFORE [ @@ -182,7 +187,13 @@ VALID_NATIVE_SCRIPTS = [ scripts=[ CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_path=[1854 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], + key_path=[ + 1854 | HARDENED, + 1815 | HARDENED, + 0 | HARDENED, + 0, + 0, + ], ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, @@ -198,7 +209,13 @@ VALID_NATIVE_SCRIPTS = [ scripts=[ CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, - key_path=[1854 | HARDENED, 1815 | HARDENED, 0 | HARDENED, 0, 0], + key_path=[ + 1854 | HARDENED, + 1815 | HARDENED, + 0 | HARDENED, + 0, + 0, + ], ), CardanoNativeScript( type=CardanoNativeScriptType.PUB_KEY, diff --git a/core/tests/test_apps.cardano.utils.py b/core/tests/test_apps.cardano.utils.py index 434fd70cfa..5939f68b53 100644 --- a/core/tests/test_apps.cardano.utils.py +++ b/core/tests/test_apps.cardano.utils.py @@ -1,7 +1,10 @@ from common import * if not utils.BITCOIN_ONLY: - from apps.cardano.helpers.utils import variable_length_encode, format_asset_fingerprint + from apps.cardano.helpers.utils import ( + variable_length_encode, + format_asset_fingerprint, + ) @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") @@ -23,7 +26,6 @@ class TestCardanoUtils(unittest.TestCase): actual = variable_length_encode(number) self.assertEqual(actual, expected) - def test_variable_length_encode_negative_number(self): with self.assertRaises(ValueError): variable_length_encode(-1) @@ -31,15 +33,32 @@ class TestCardanoUtils(unittest.TestCase): def test_format_asset_fingerprint(self): # source: https://github.com/cardano-foundation/CIPs/pull/64 test_vectors = [ - (("7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", ""), "asset1rjklcrnsdzqp65wjgrg55sy9723kw09mlgvlc3"), - (("7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", "504154415445"), "asset13n25uv0yaf5kus35fm2k86cqy60z58d9xmde92"), - (("1e349c9bdea19fd6c147626a5260bc44b71635f398b67c59881df209", "7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373"), "asset1aqrdypg669jgazruv5ah07nuyqe0wxjhe2el6f"), + ( + ("7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", ""), + "asset1rjklcrnsdzqp65wjgrg55sy9723kw09mlgvlc3", + ), + ( + ( + "7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", + "504154415445", + ), + "asset13n25uv0yaf5kus35fm2k86cqy60z58d9xmde92", + ), + ( + ( + "1e349c9bdea19fd6c147626a5260bc44b71635f398b67c59881df209", + "7eae28af2208be856f7a119668ae52a49b73725e326dc16579dcc373", + ), + "asset1aqrdypg669jgazruv5ah07nuyqe0wxjhe2el6f", + ), ] for params, expected in test_vectors: - actual = format_asset_fingerprint(policy_id=unhexlify(params[0]), asset_name_bytes=unhexlify(params[1])) + actual = format_asset_fingerprint( + policy_id=unhexlify(params[0]), asset_name_bytes=unhexlify(params[1]) + ) self.assertEqual(actual, expected) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.common.cbor.py b/core/tests/test_apps.common.cbor.py index 2a53edd155..aa2950b3e8 100644 --- a/core/tests/test_apps.common.cbor.py +++ b/core/tests/test_apps.common.cbor.py @@ -16,113 +16,112 @@ from apps.common.cbor import ( class TestCardanoCbor(unittest.TestCase): def test_create_array_header(self): test_vectors = [ - (0, '80'), - (23, '97'), - ((2 ** 8) - 1, '98ff'), - ((2 ** 16) - 1, '99ffff'), - ((2 ** 32) - 1, '9affffffff'), - ((2 ** 64) - 1, '9bffffffffffffffff'), + (0, "80"), + (23, "97"), + ((2**8) - 1, "98ff"), + ((2**16) - 1, "99ffff"), + ((2**32) - 1, "9affffffff"), + ((2**64) - 1, "9bffffffffffffffff"), ] for val, header_hex in test_vectors: header = unhexlify(header_hex) self.assertEqual(create_array_header(val), header) with self.assertRaises(NotImplementedError): - create_array_header(2 ** 64) + create_array_header(2**64) def test_create_map_header(self): test_vectors = [ - (0, 'a0'), - (23, 'b7'), - ((2 ** 8) - 1, 'b8ff'), - ((2 ** 16) - 1, 'b9ffff'), - ((2 ** 32) - 1, 'baffffffff'), - ((2 ** 64) - 1, 'bbffffffffffffffff'), + (0, "a0"), + (23, "b7"), + ((2**8) - 1, "b8ff"), + ((2**16) - 1, "b9ffff"), + ((2**32) - 1, "baffffffff"), + ((2**64) - 1, "bbffffffffffffffff"), ] for val, header_hex in test_vectors: header = unhexlify(header_hex) self.assertEqual(create_map_header(val), header) with self.assertRaises(NotImplementedError): - create_map_header(2 ** 64) + create_map_header(2**64) def test_create_embedded_cbor_bytes_header(self): test_vectors = [ - (0, 'd81840'), - (23, 'd81857'), - ((2 ** 8) - 1, 'd81858ff'), - ((2 ** 16) - 1, 'd81859ffff'), - ((2 ** 32) - 1, 'd8185affffffff'), - ((2 ** 64) - 1, 'd8185bffffffffffffffff'), + (0, "d81840"), + (23, "d81857"), + ((2**8) - 1, "d81858ff"), + ((2**16) - 1, "d81859ffff"), + ((2**32) - 1, "d8185affffffff"), + ((2**64) - 1, "d8185bffffffffffffffff"), ] for val, header_hex in test_vectors: header = unhexlify(header_hex) self.assertEqual(create_embedded_cbor_bytes_header(val), header) with self.assertRaises(NotImplementedError): - create_embedded_cbor_bytes_header(2 ** 64) + create_embedded_cbor_bytes_header(2**64) def test_cbor_encoding(self): test_vectors = [ # unsigned integers - (0, '00'), - (1, '01'), - (10, '0a'), - (23, '17'), - (24, '1818'), - (25, '1819'), - (100, '1864'), - (1000, '1903e8'), - (1000000, '1a000f4240'), - (1000000000000, '1b000000e8d4a51000'), - + (0, "00"), + (1, "01"), + (10, "0a"), + (23, "17"), + (24, "1818"), + (25, "1819"), + (100, "1864"), + (1000, "1903e8"), + (1000000, "1a000f4240"), + (1000000000000, "1b000000e8d4a51000"), # negative integers - (-1, '20'), - (-10, '29'), - (-24, '37'), - (-25, '3818'), - (-26, '3819'), - (-100, '3863'), - (-1000, '3903E7'), - (-1000000, '3A000F423F'), - (-1000000000000, '3B000000E8D4A50FFF'), - + (-1, "20"), + (-10, "29"), + (-24, "37"), + (-25, "3818"), + (-26, "3819"), + (-100, "3863"), + (-1000, "3903E7"), + (-1000000, "3A000F423F"), + (-1000000000000, "3B000000E8D4A50FFF"), # binary strings - (b'', '40'), - (unhexlify('01020304'), '4401020304'), - + (b"", "40"), + (unhexlify("01020304"), "4401020304"), # text strings - ('', '60'), - ('Fun', '6346756e'), - (u'P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f', '786550c599c3adc5a165726ec49b20c5be6c75c5a56f75c48d6bc3bd206bc5afc58820c3ba70c49b6c20c48fc3a162656c736bc3a920c3b36479207ac3a16b65c5996ec3bd2075c48d65c5882062c49bc5bec3ad20706f64c3a96c207ac3b36e7920c3ba6cc5af'), - + ("", "60"), + ("Fun", "6346756e"), + ( + "P\u0159\xed\u0161ern\u011b \u017elu\u0165ou\u010dk\xfd k\u016f\u0148 \xfap\u011bl \u010f\xe1belsk\xe9 \xf3dy z\xe1ke\u0159n\xfd u\u010de\u0148 b\u011b\u017e\xed pod\xe9l z\xf3ny \xfal\u016f", + "786550c599c3adc5a165726ec49b20c5be6c75c5a56f75c48d6bc3bd206bc5afc58820c3ba70c49b6c20c48fc3a162656c736bc3a920c3b36479207ac3a16b65c5996ec3bd2075c48d65c5882062c49bc5bec3ad20706f64c3a96c207ac3b36e7920c3ba6cc5af", + ), # tags - (Tagged(1, 1363896240), 'c11a514b67b0'), - (Tagged(23, unhexlify('01020304')), 'd74401020304'), - + (Tagged(1, 1363896240), "c11a514b67b0"), + (Tagged(23, unhexlify("01020304")), "d74401020304"), # arrays - ([], '80'), - ([1, 2, 3], '83010203'), - ([1, [2, 3], [4, 5]], '8301820203820405'), - (list(range(1, 26)), '98190102030405060708090a0b0c0d0e0f101112131415161718181819'), - + ([], "80"), + ([1, 2, 3], "83010203"), + ([1, [2, 3], [4, 5]], "8301820203820405"), + ( + list(range(1, 26)), + "98190102030405060708090a0b0c0d0e0f101112131415161718181819", + ), # maps - ({}, 'a0'), - ({1: 2, 3: 4}, 'a201020304'), - ({3: 4, 1: 2}, 'a201020304'), - + ({}, "a0"), + ({1: 2, 3: 4}, "a201020304"), + ({3: 4, 1: 2}, "a201020304"), # indefinite - (IndefiniteLengthArray([]), '9fff'), - (IndefiniteLengthArray([1, [2, 3], [4, 5]]), '9f01820203820405ff'), - (IndefiniteLengthArray([1, [2, 3], IndefiniteLengthArray([4, 5])]), - '9f018202039f0405ffff'), - + (IndefiniteLengthArray([]), "9fff"), + (IndefiniteLengthArray([1, [2, 3], [4, 5]]), "9f01820203820405ff"), + ( + IndefiniteLengthArray([1, [2, 3], IndefiniteLengthArray([4, 5])]), + "9f018202039f0405ffff", + ), # boolean - (True, 'f5'), - (False, 'f4'), - + (True, "f5"), + (False, "f4"), # null - (None, 'f6'), + (None, "f6"), ] for val, encoded_hex in test_vectors: encoded = unhexlify(encoded_hex) @@ -134,10 +133,13 @@ class TestCardanoCbor(unittest.TestCase): Tuples should be encoded as arrays and decoded back as lists. """ test_vectors = [ - ([], '80'), - ([1, 2, 3], '83010203'), - ([1, [2, 3], [4, 5]], '8301820203820405'), - (list(range(1, 26)), '98190102030405060708090a0b0c0d0e0f101112131415161718181819'), + ([], "80"), + ([1, 2, 3], "83010203"), + ([1, [2, 3], [4, 5]], "8301820203820405"), + ( + list(range(1, 26)), + "98190102030405060708090a0b0c0d0e0f101112131415161718181819", + ), ] for val, encoded_hex in test_vectors: value_tuple = tuple(val) @@ -150,9 +152,9 @@ class TestCardanoCbor(unittest.TestCase): OrderedMaps should be encoded as maps without any ordering and decoded back as dicts. """ test_vectors = [ - ({}, 'a0'), - ([[1, 2], [3, 4]], 'a201020304'), - ([[3, 4], [1, 2]], 'a203040102'), + ({}, "a0"), + ([[1, 2], [3, 4]], "a201020304"), + ([[3, 4], [1, 2]], "a203040102"), ] for val, encoded_hex in test_vectors: @@ -168,12 +170,10 @@ class TestCardanoCbor(unittest.TestCase): large_dict = {i: i for i in range(100)} encoded = encode(large_dict) - encoded_streamed = [ - bytes(item) for item in encode_streamed(large_dict) - ] + encoded_streamed = [bytes(item) for item in encode_streamed(large_dict)] - self.assertEqual(b''.join(encoded_streamed), encoded) + self.assertEqual(b"".join(encoded_streamed), encoded) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.common.coins.py b/core/tests/test_apps.common.coins.py index 55471822df..0af26ba47e 100644 --- a/core/tests/test_apps.common.coins.py +++ b/core/tests/test_apps.common.coins.py @@ -4,12 +4,11 @@ from apps.common import coins class TestCoins(unittest.TestCase): - def test_bitcoin(self): ref = [ - ('BTC', 'Bitcoin', 0), - ('TEST', 'Testnet', 111), - ('REGTEST', 'Regtest', 111), + ("BTC", "Bitcoin", 0), + ("TEST", "Testnet", 111), + ("REGTEST", "Regtest", 111), ] for s, n, a in ref: c = coins.by_name(n) @@ -19,11 +18,11 @@ class TestCoins(unittest.TestCase): @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") def test_altcoins(self): ref = [ - ('NMC', 'Namecoin', 52), - ('LTC', 'Litecoin', 48), - ('DASH', 'Dash', 76), - ('ZEC', 'Zcash', 7352), - ('TAZ', 'Zcash Testnet', 7461), + ("NMC", "Namecoin", 52), + ("LTC", "Litecoin", 48), + ("DASH", "Dash", 76), + ("ZEC", "Zcash", 7352), + ("TAZ", "Zcash Testnet", 7461), ] for s, n, a in ref: c = coins.by_name(n) @@ -32,8 +31,8 @@ class TestCoins(unittest.TestCase): def test_failure(self): with self.assertRaises(ValueError): - coins.by_name('XXXXX') + coins.by_name("XXXXX") -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.common.paths.py b/core/tests/test_apps.common.paths.py index d47b40f1e0..ce1a2a1891 100644 --- a/core/tests/test_apps.common.paths.py +++ b/core/tests/test_apps.common.paths.py @@ -51,7 +51,7 @@ class TestPathSchemas(unittest.TestCase): ensure( all(is_equal(a, b) for a, b in zip(schema_a.schema, schema_b.schema)) and is_equal(schema_a.trailing_components, schema_b.trailing_components), - f"Schemas differ:\nA = {repr(schema_a)}\nB = {repr(schema_b)}" + f"Schemas differ:\nA = {repr(schema_a)}\nB = {repr(schema_b)}", ) def test_always_never_matching(self): diff --git a/core/tests/test_apps.common.seed.py b/core/tests/test_apps.common.seed.py index a1190ebc7c..77abdef5aa 100644 --- a/core/tests/test_apps.common.seed.py +++ b/core/tests/test_apps.common.seed.py @@ -5,34 +5,49 @@ from apps.common.seed import Slip21Node from trezor import wire from trezor.crypto import bip39 + class TestSeed(unittest.TestCase): def test_slip21(self): - seed = bip39.seed(' '.join(['all'] * 12), '') + seed = bip39.seed(" ".join(["all"] * 12), "") node1 = Slip21Node(seed) node2 = node1.clone() keychain = Keychain(seed, "", [], slip21_namespaces=[[b"SLIP-0021"]]) # Key(m) - KEY_M = unhexlify(b"dbf12b44133eaab506a740f6565cc117228cbf1dd70635cfa8ddfdc9af734756") + KEY_M = unhexlify( + b"dbf12b44133eaab506a740f6565cc117228cbf1dd70635cfa8ddfdc9af734756" + ) self.assertEqual(node1.key(), KEY_M) # Key(m/"SLIP-0021") - KEY_M_SLIP0021 = unhexlify(b"1d065e3ac1bbe5c7fad32cf2305f7d709dc070d672044a19e610c77cdf33de0d") + KEY_M_SLIP0021 = unhexlify( + b"1d065e3ac1bbe5c7fad32cf2305f7d709dc070d672044a19e610c77cdf33de0d" + ) node1.derive_path([b"SLIP-0021"]) self.assertEqual(node1.key(), KEY_M_SLIP0021) self.assertEqual(keychain.derive_slip21([b"SLIP-0021"]).key(), KEY_M_SLIP0021) # Key(m/"SLIP-0021"/"Master encryption key") - KEY_M_SLIP0021_MEK = unhexlify(b"ea163130e35bbafdf5ddee97a17b39cef2be4b4f390180d65b54cf05c6a82fde") + KEY_M_SLIP0021_MEK = unhexlify( + b"ea163130e35bbafdf5ddee97a17b39cef2be4b4f390180d65b54cf05c6a82fde" + ) node1.derive_path([b"Master encryption key"]) self.assertEqual(node1.key(), KEY_M_SLIP0021_MEK) - self.assertEqual(keychain.derive_slip21([b"SLIP-0021", b"Master encryption key"]).key(), KEY_M_SLIP0021_MEK) + self.assertEqual( + keychain.derive_slip21([b"SLIP-0021", b"Master encryption key"]).key(), + KEY_M_SLIP0021_MEK, + ) # Key(m/"SLIP-0021"/"Authentication key") - KEY_M_SLIP0021_AK = unhexlify(b"47194e938ab24cc82bfa25f6486ed54bebe79c40ae2a5a32ea6db294d81861a6") + KEY_M_SLIP0021_AK = unhexlify( + b"47194e938ab24cc82bfa25f6486ed54bebe79c40ae2a5a32ea6db294d81861a6" + ) node2.derive_path([b"SLIP-0021", b"Authentication key"]) self.assertEqual(node2.key(), KEY_M_SLIP0021_AK) - self.assertEqual(keychain.derive_slip21([b"SLIP-0021", b"Authentication key"]).key(), KEY_M_SLIP0021_AK) + self.assertEqual( + keychain.derive_slip21([b"SLIP-0021", b"Authentication key"]).key(), + KEY_M_SLIP0021_AK, + ) # Forbidden paths. with self.assertRaises(wire.DataError): @@ -41,5 +56,5 @@ class TestSeed(unittest.TestCase): keychain.derive_slip21([b"SLIP-9999", b"Authentication key"]) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.common.writers.py b/core/tests/test_apps.common.writers.py index 39b023088e..4b837efb3e 100644 --- a/core/tests/test_apps.common.writers.py +++ b/core/tests/test_apps.common.writers.py @@ -26,7 +26,7 @@ class TestSeed(unittest.TestCase): def test_write_uint64_le(self): buf = bytearray() - writers.write_uint64_le(buf, 0x1234567890abcdef) + writers.write_uint64_le(buf, 0x1234567890ABCDEF) self.assertEqual(buf, b"\xef\xcd\xab\x90\x78\x56\x34\x12") def test_write_uint32_be(self): @@ -36,7 +36,7 @@ class TestSeed(unittest.TestCase): def test_write_uint64_be(self): buf = bytearray() - writers.write_uint64_be(buf, 0x1234567890abcdef) + writers.write_uint64_be(buf, 0x1234567890ABCDEF) self.assertEqual(buf, b"\x12\x34\x56\x78\x90\xab\xcd\xef") diff --git a/core/tests/test_apps.eos.check_action.py b/core/tests/test_apps.eos.check_action.py index 436dc107bb..5a23e70144 100644 --- a/core/tests/test_apps.eos.check_action.py +++ b/core/tests/test_apps.eos.check_action.py @@ -9,44 +9,246 @@ if not utils.BITCOIN_ONLY: class TestEosActions(unittest.TestCase): def test_check_action(self): # return True - self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram=object()), 'buyram', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram_bytes=object()), 'buyrambytes', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), sell_ram=object()), 'sellram', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), delegate=object()), 'delegatebw', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), undelegate=object()), 'undelegatebw', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), refund=object()), 'refund', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), vote_producer=object()), 'voteproducer', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), update_auth=object()), 'updateauth', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), delete_auth=object()), 'deleteauth', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), link_auth=object()), 'linkauth', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), unlink_auth=object()), 'unlinkauth', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), new_account=object()), 'newaccount', 'eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), transfer=object()), 'transfer', 'not_eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), unknown=[]), 'unknown', 'not_eosio'), True) - self.assertEqual(_check_action(EosTxActionAck(common=object(), unknown=[]), 'buyram', 'buygoods'), True) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), buy_ram=object()), "buyram", "eosio" + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), buy_ram_bytes=object()), + "buyrambytes", + "eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), sell_ram=object()), "sellram", "eosio" + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), delegate=object()), + "delegatebw", + "eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), undelegate=object()), + "undelegatebw", + "eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), refund=object()), "refund", "eosio" + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), vote_producer=object()), + "voteproducer", + "eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), update_auth=object()), + "updateauth", + "eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), delete_auth=object()), + "deleteauth", + "eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), link_auth=object()), "linkauth", "eosio" + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), unlink_auth=object()), + "unlinkauth", + "eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), new_account=object()), + "newaccount", + "eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), transfer=object()), + "transfer", + "not_eosio", + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), unknown=[]), "unknown", "not_eosio" + ), + True, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), unknown=[]), "buyram", "buygoods" + ), + True, + ) # returns False - self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram=object()), 'buyram', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object()), 'buyram', 'eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram_bytes=object()), 'buyrambytes', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), sell_ram=object()), 'sellram', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), delegate=object()), 'delegatebw', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), undelegate=object()), 'undelegatebw', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), refund=object()), 'refund', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object()), 'refund', 'eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), vote_producer=object()), 'voteproducer', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), update_auth=object()), 'updateauth', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), delete_auth=object()), 'deleteauth', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), link_auth=object()), 'linkauth', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), unlink_auth=object()), 'unlinkauth', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object()), 'unlinkauth', 'eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), new_account=object()), 'newaccount', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), transfer=object()), 'transfer', 'eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object()), 'unknown', 'not_eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), buy_ram=object()), 'test', 'eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), unknown=[]), 'buyram', 'eosio'), False) - self.assertEqual(_check_action(EosTxActionAck(common=object(), unknown=[]), 'transfer', 'loveme'), False) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), buy_ram=object()), "buyram", "not_eosio" + ), + False, + ) + self.assertEqual( + _check_action(EosTxActionAck(common=object()), "buyram", "eosio"), False + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), buy_ram_bytes=object()), + "buyrambytes", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), sell_ram=object()), + "sellram", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), delegate=object()), + "delegatebw", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), undelegate=object()), + "undelegatebw", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), refund=object()), "refund", "not_eosio" + ), + False, + ) + self.assertEqual( + _check_action(EosTxActionAck(common=object()), "refund", "eosio"), False + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), vote_producer=object()), + "voteproducer", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), update_auth=object()), + "updateauth", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), delete_auth=object()), + "deleteauth", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), link_auth=object()), + "linkauth", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), unlink_auth=object()), + "unlinkauth", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action(EosTxActionAck(common=object()), "unlinkauth", "eosio"), False + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), new_account=object()), + "newaccount", + "not_eosio", + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), transfer=object()), "transfer", "eosio" + ), + False, + ) + self.assertEqual( + _check_action(EosTxActionAck(common=object()), "unknown", "not_eosio"), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), buy_ram=object()), "test", "eosio" + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), unknown=[]), "buyram", "eosio" + ), + False, + ) + self.assertEqual( + _check_action( + EosTxActionAck(common=object(), unknown=[]), "transfer", "loveme" + ), + False, + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.eos.conversions.py b/core/tests/test_apps.eos.conversions.py index 83779099e9..2569f6f57e 100644 --- a/core/tests/test_apps.eos.conversions.py +++ b/core/tests/test_apps.eos.conversions.py @@ -17,12 +17,12 @@ class TestEosConversions(unittest.TestCase): 595056260442243600, ] names_out = [ - 'miniminimini', - '12345abcdefg', - '123451234512', - 'hijklmnopqrs', - 'tuvwxyz12345', - '111111111111', + "miniminimini", + "12345abcdefg", + "123451234512", + "hijklmnopqrs", + "tuvwxyz12345", + "111111111111", ] for i, o in zip(names_in, names_out): self.assertEqual(helpers.eos_name_to_string(i), o) @@ -30,40 +30,41 @@ class TestEosConversions(unittest.TestCase): def test_eos_asset_to_string(self): asset_in = [ EosAsset( - amount=10000, - symbol=1397703940, + amount=10000, + symbol=1397703940, ), EosAsset( - amount=200000, - symbol=1397703940, + amount=200000, + symbol=1397703940, ), EosAsset( - amount=255000, - symbol=1397703940, + amount=255000, + symbol=1397703940, ), EosAsset( - amount=999999, - symbol=1397703939, + amount=999999, + symbol=1397703939, ), EosAsset( - amount=1, - symbol=1397703940, + amount=1, + symbol=1397703940, ), EosAsset( - amount=999, - symbol=1397703939, + amount=999, + symbol=1397703939, ), ] asset_out = [ - '1.0000 EOS', - '20.0000 EOS', - '25.5000 EOS', - '999.999 EOS', - '0.0001 EOS', - '0.999 EOS', + "1.0000 EOS", + "20.0000 EOS", + "25.5000 EOS", + "999.999 EOS", + "0.0001 EOS", + "0.999 EOS", ] for i, o in zip(asset_in, asset_out): self.assertEqual(helpers.eos_asset_to_string(i), o) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.eos.get_public_key.py b/core/tests/test_apps.eos.get_public_key.py index 9e206c476d..3db18f16b1 100644 --- a/core/tests/test_apps.eos.get_public_key.py +++ b/core/tests/test_apps.eos.get_public_key.py @@ -19,7 +19,7 @@ def _get_public_key(node: bip32.HDNode) -> tuple[str, bytes]: class TestEosGetPublicKey(unittest.TestCase): def test_get_public_key_scheme(self): mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about" - seed = bip39.seed(mnemonic, '') + seed = bip39.seed(mnemonic, "") derivation_paths = [ [0x80000000 | 44, 0x80000000 | 194, 0x80000000, 0, 0], @@ -29,21 +29,21 @@ class TestEosGetPublicKey(unittest.TestCase): ] public_keys = [ - b'0315c358024ce46767102578947584c4342a6982b922d454f63588effa34597197', - b'029622eff7248c4d298fe28f2df19ee0d5f7674f678844e05c31d1a5632412869e', - b'02625f33c10399703e95e41bd5054beef3ab893dcc7df2bb9bdcee48359b29069d', - b'037c9b7d24d42589941cca3f4debc75b37c0e7b881e6eb00d2e674958debe3bbc3', + b"0315c358024ce46767102578947584c4342a6982b922d454f63588effa34597197", + b"029622eff7248c4d298fe28f2df19ee0d5f7674f678844e05c31d1a5632412869e", + b"02625f33c10399703e95e41bd5054beef3ab893dcc7df2bb9bdcee48359b29069d", + b"037c9b7d24d42589941cca3f4debc75b37c0e7b881e6eb00d2e674958debe3bbc3", ] wif_keys = [ - 'EOS6zpSNY1YoLxNt2VsvJjoDfBueU6xC1M1ERJw1UoekL1NHn8KNA', - 'EOS62cPUiWnLqbUjiBMxbEU4pm4Hp5X3RGk4KMTadvZNygjX72yHW', - 'EOS5dp8aCFoFwrKo6KuUfos1hwMfZGkiZUbaF2CyuD4chyBEN2wQK', - 'EOS7n7TXwR4Y3DtPt2ji6akhQi5uw4SruuPArvoNJso84vhwPQt1G', + "EOS6zpSNY1YoLxNt2VsvJjoDfBueU6xC1M1ERJw1UoekL1NHn8KNA", + "EOS62cPUiWnLqbUjiBMxbEU4pm4Hp5X3RGk4KMTadvZNygjX72yHW", + "EOS5dp8aCFoFwrKo6KuUfos1hwMfZGkiZUbaF2CyuD4chyBEN2wQK", + "EOS7n7TXwR4Y3DtPt2ji6akhQi5uw4SruuPArvoNJso84vhwPQt1G", ] for index, path in enumerate(derivation_paths): - node = bip32.from_seed(seed, 'secp256k1') + node = bip32.from_seed(seed, "secp256k1") node.derive_path(path) wif, public_key = _get_public_key(node) @@ -52,5 +52,5 @@ class TestEosGetPublicKey(unittest.TestCase): self.assertEqual(public_key_to_wif(public_key), wif_keys[index]) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.ethereum.tokens.py b/core/tests/test_apps.ethereum.tokens.py index 464cc14163..1a2a799265 100644 --- a/core/tests/test_apps.ethereum.tokens.py +++ b/core/tests/test_apps.ethereum.tokens.py @@ -8,16 +8,19 @@ if not utils.BITCOIN_ONLY: class TestEthereumTokens(unittest.TestCase): def test_token_by_chain_address(self): - token = tokens.token_by_chain_address(1, b"\x7f\xc6\x65\x00\xc8\x4a\x76\xad\x7e\x9c\x93\x43\x7b\xfc\x5a\xc3\x3e\x2d\xda\xe9") - self.assertEqual(token.symbol, 'AAVE') + token = tokens.token_by_chain_address( + 1, + b"\x7f\xc6\x65\x00\xc8\x4a\x76\xad\x7e\x9c\x93\x43\x7b\xfc\x5a\xc3\x3e\x2d\xda\xe9", + ) + self.assertEqual(token.symbol, "AAVE") # invalid adress, invalid chain - token = tokens.token_by_chain_address(999, b'\x00\xFF') + token = tokens.token_by_chain_address(999, b"\x00\xFF") self.assertIs(token, None) - self.assertEqual(tokens.UNKNOWN_TOKEN.symbol, 'Wei UNKN') + self.assertEqual(tokens.UNKNOWN_TOKEN.symbol, "Wei UNKN") self.assertEqual(tokens.UNKNOWN_TOKEN.decimals, 0) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.management.recovery_device.py b/core/tests/test_apps.management.recovery_device.py index 67124b3d34..d3dc5ef1e1 100644 --- a/core/tests/test_apps.management.recovery_device.py +++ b/core/tests/test_apps.management.recovery_device.py @@ -5,7 +5,12 @@ import storage import storage.recovery from apps.management.recovery_device.recover import process_slip39 from trezor.enums import BackupType -from apps.management.recovery_device.word_validity import check, IdentifierMismatch, AlreadyAdded, ThresholdReached +from apps.management.recovery_device.word_validity import ( + check, + IdentifierMismatch, + AlreadyAdded, + ThresholdReached, +) MNEMONIC_SLIP39_BASIC_20_3of6 = [ "extra extend academic bishop cricket bundle tofu goat apart victim enlarge program behavior permit course armed jerky faint language modern", @@ -27,7 +32,6 @@ MNEMONIC_SLIP39_ADVANCED_33 = [ class TestSlip39(unittest.TestCase): - @mock_storage def test_process_slip39_basic(self): storage.recovery.set_in_progress(True) @@ -37,26 +41,39 @@ class TestSlip39(unittest.TestCase): secret, share = process_slip39(first) self.assertIsNone(secret) self.assertEqual(share.group_count, storage.recovery.get_slip39_group_count()) - self.assertEqual(share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent()) + self.assertEqual( + share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent() + ) self.assertEqual(share.identifier, storage.recovery.get_slip39_identifier()) self.assertEqual(storage.recovery.get_slip39_remaining_shares(0), 2) - self.assertEqual(storage.recovery_shares.get(share.index, share.group_index), first) + self.assertEqual( + storage.recovery_shares.get(share.index, share.group_index), first + ) # second share (member index 0) second = MNEMONIC_SLIP39_BASIC_20_3of6[1] secret, share = process_slip39(second) self.assertIsNone(secret) self.assertEqual(storage.recovery.get_slip39_remaining_shares(0), 1) - self.assertEqual(storage.recovery_shares.get(share.index, share.group_index), second) - self.assertEqual(storage.recovery_shares.fetch_group(share.group_index), [second, first]) # ordered by index + self.assertEqual( + storage.recovery_shares.get(share.index, share.group_index), second + ) + self.assertEqual( + storage.recovery_shares.fetch_group(share.group_index), [second, first] + ) # ordered by index # third share (member index 3) third = MNEMONIC_SLIP39_BASIC_20_3of6[2] secret, share = process_slip39(third) - self.assertEqual(secret, b'I\x1by[\x80\xfc!\xcc\xdfFl\x0f\xbc\x98\xc8\xfc') + self.assertEqual(secret, b"I\x1by[\x80\xfc!\xcc\xdfFl\x0f\xbc\x98\xc8\xfc") self.assertEqual(storage.recovery.get_slip39_remaining_shares(0), 0) - self.assertEqual(storage.recovery_shares.get(share.index, share.group_index), third) - self.assertEqual(storage.recovery_shares.fetch_group(share.group_index), [second, third, first]) # ordered by index + self.assertEqual( + storage.recovery_shares.get(share.index, share.group_index), third + ) + self.assertEqual( + storage.recovery_shares.fetch_group(share.group_index), + [second, third, first], + ) # ordered by index @mock_storage def test_process_slip39_advanced(self): @@ -67,47 +84,89 @@ class TestSlip39(unittest.TestCase): secret, share = process_slip39(words) self.assertIsNone(secret) self.assertEqual(share.group_count, storage.recovery.get_slip39_group_count()) - self.assertEqual(share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent()) + self.assertEqual( + share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent() + ) self.assertEqual(share.identifier, storage.recovery.get_slip39_identifier()) - self.assertEqual(storage.recovery.fetch_slip39_remaining_shares(), [16, 0, 16, 16]) - self.assertEqual(storage.recovery_shares.get(share.index, share.group_index), words) + self.assertEqual( + storage.recovery.fetch_slip39_remaining_shares(), [16, 0, 16, 16] + ) + self.assertEqual( + storage.recovery_shares.get(share.index, share.group_index), words + ) # member index 4 from group 2 (3of5) words = MNEMONIC_SLIP39_ADVANCED_20[1] secret, share = process_slip39(words) self.assertIsNone(secret) self.assertEqual(share.group_count, storage.recovery.get_slip39_group_count()) - self.assertEqual(share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent()) + self.assertEqual( + share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent() + ) self.assertEqual(share.identifier, storage.recovery.get_slip39_identifier()) - self.assertEqual(storage.recovery_shares.get(share.index, share.group_index), words) - self.assertEqual(storage.recovery_shares.fetch_group(1), [MNEMONIC_SLIP39_ADVANCED_20[0]]) - self.assertEqual(storage.recovery_shares.fetch_group(2), [MNEMONIC_SLIP39_ADVANCED_20[1]]) - self.assertEqual(storage.recovery.fetch_slip39_remaining_shares(), [16, 0, 2, 16]) + self.assertEqual( + storage.recovery_shares.get(share.index, share.group_index), words + ) + self.assertEqual( + storage.recovery_shares.fetch_group(1), [MNEMONIC_SLIP39_ADVANCED_20[0]] + ) + self.assertEqual( + storage.recovery_shares.fetch_group(2), [MNEMONIC_SLIP39_ADVANCED_20[1]] + ) + self.assertEqual( + storage.recovery.fetch_slip39_remaining_shares(), [16, 0, 2, 16] + ) # member index 2 from group 2 words = MNEMONIC_SLIP39_ADVANCED_20[2] secret, share = process_slip39(words) self.assertIsNone(secret) self.assertEqual(share.group_count, storage.recovery.get_slip39_group_count()) - self.assertEqual(share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent()) + self.assertEqual( + share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent() + ) self.assertEqual(share.identifier, storage.recovery.get_slip39_identifier()) - self.assertEqual(storage.recovery_shares.get(share.index, share.group_index), words) - self.assertEqual(storage.recovery_shares.fetch_group(1), [MNEMONIC_SLIP39_ADVANCED_20[0]]) - self.assertEqual(storage.recovery_shares.fetch_group(2), [MNEMONIC_SLIP39_ADVANCED_20[2], MNEMONIC_SLIP39_ADVANCED_20[1]]) - self.assertEqual(storage.recovery.fetch_slip39_remaining_shares(), [16, 0, 1, 16]) + self.assertEqual( + storage.recovery_shares.get(share.index, share.group_index), words + ) + self.assertEqual( + storage.recovery_shares.fetch_group(1), [MNEMONIC_SLIP39_ADVANCED_20[0]] + ) + self.assertEqual( + storage.recovery_shares.fetch_group(2), + [MNEMONIC_SLIP39_ADVANCED_20[2], MNEMONIC_SLIP39_ADVANCED_20[1]], + ) + self.assertEqual( + storage.recovery.fetch_slip39_remaining_shares(), [16, 0, 1, 16] + ) # last member index 0 from group 2 # now group 2 is complete => the whole Shamir recovery is completed words = MNEMONIC_SLIP39_ADVANCED_20[3] secret, share = process_slip39(words) - self.assertEqual(secret, b'\xc2\xd2\xe2j\xd0`#\xc6\x01E\xf1P\xab\xe2\xdd+') + self.assertEqual(secret, b"\xc2\xd2\xe2j\xd0`#\xc6\x01E\xf1P\xab\xe2\xdd+") self.assertEqual(share.group_count, storage.recovery.get_slip39_group_count()) - self.assertEqual(share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent()) + self.assertEqual( + share.iteration_exponent, storage.recovery.get_slip39_iteration_exponent() + ) self.assertEqual(share.identifier, storage.recovery.get_slip39_identifier()) - self.assertEqual(storage.recovery_shares.get(share.index, share.group_index), words) - self.assertEqual(storage.recovery_shares.fetch_group(1), [MNEMONIC_SLIP39_ADVANCED_20[0]]) - self.assertEqual(storage.recovery_shares.fetch_group(2), [MNEMONIC_SLIP39_ADVANCED_20[3], MNEMONIC_SLIP39_ADVANCED_20[2], MNEMONIC_SLIP39_ADVANCED_20[1]]) - self.assertEqual(storage.recovery.fetch_slip39_remaining_shares(), [16, 0, 0, 16]) + self.assertEqual( + storage.recovery_shares.get(share.index, share.group_index), words + ) + self.assertEqual( + storage.recovery_shares.fetch_group(1), [MNEMONIC_SLIP39_ADVANCED_20[0]] + ) + self.assertEqual( + storage.recovery_shares.fetch_group(2), + [ + MNEMONIC_SLIP39_ADVANCED_20[3], + MNEMONIC_SLIP39_ADVANCED_20[2], + MNEMONIC_SLIP39_ADVANCED_20[1], + ], + ) + self.assertEqual( + storage.recovery.fetch_slip39_remaining_shares(), [16, 0, 0, 16] + ) @mock_storage def test_exceptions(self): @@ -157,9 +216,13 @@ class TestSlip39(unittest.TestCase): check(BackupType.Bip39, ["ocean"]) # let's store two shares in the storage - secret, share = process_slip39("trash smug adjust ambition criminal prisoner security math cover pecan response pharmacy center criminal salary elbow bracelet lunar briefing dragon") + secret, share = process_slip39( + "trash smug adjust ambition criminal prisoner security math cover pecan response pharmacy center criminal salary elbow bracelet lunar briefing dragon" + ) self.assertIsNone(secret) - secret, share = process_slip39("trash smug adjust aide benefit temple round clogs devote prevent type cards clogs plastic aspect paper behavior lunar custody intimate") + secret, share = process_slip39( + "trash smug adjust aide benefit temple round clogs devote prevent type cards clogs plastic aspect paper behavior lunar custody intimate" + ) self.assertIsNone(secret) # different identifier @@ -179,9 +242,13 @@ class TestSlip39(unittest.TestCase): check(BackupType.Slip39_Advanced, ["trash", "smug", "adjust", "ambition"]) # Let's store two more. The group is 4/6 so this group is now complete. - secret, share = process_slip39("trash smug adjust arena beard quick language program true hush amount round geology should training practice language diet order ruin") + secret, share = process_slip39( + "trash smug adjust arena beard quick language program true hush amount round geology should training practice language diet order ruin" + ) self.assertIsNone(secret) - secret, share = process_slip39("trash smug adjust beam brave sack magazine radar toxic emission domestic cradle vocal petition mule toxic acid hobo welcome downtown") + secret, share = process_slip39( + "trash smug adjust beam brave sack magazine radar toxic emission domestic cradle vocal petition mule toxic acid hobo welcome downtown" + ) self.assertIsNone(secret) # If trying to add another one from this group we get a warning. diff --git a/core/tests/test_apps.monero.bulletproof.py b/core/tests/test_apps.monero.bulletproof.py index 9185900053..0bfe59ec11 100644 --- a/core/tests/test_apps.monero.bulletproof.py +++ b/core/tests/test_apps.monero.bulletproof.py @@ -7,7 +7,6 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestMoneroBulletproof(unittest.TestCase): - def test_square_multiply(self): for x in [2, 3, 16, 17, 31, 32]: ss = crypto.random_scalar() @@ -17,10 +16,14 @@ class TestMoneroBulletproof(unittest.TestCase): crypto.sc_mul_into(s1, s1, ss) bp._sc_square_mult(s2, ss, x) - self.assertEqual(crypto.encodeint_into(None, s1), crypto.encodeint_into(None, s2)) + self.assertEqual( + crypto.encodeint_into(None, s1), crypto.encodeint_into(None, s2) + ) def test_dvct_skips(self): - z_sq = unhexlify(b'e0408b528e9d35ccb8386b87f39b85c724740644f4db412483a8852cdb3ceb00') + z_sq = unhexlify( + b"e0408b528e9d35ccb8386b87f39b85c724740644f4db412483a8852cdb3ceb00" + ) d_vct0 = bp.VctD(64, 8, z_sq, raw=True) d_vct1 = bp.VctD(64, 8, z_sq, raw=True) tmp = crypto.Scalar() @@ -28,75 +31,123 @@ class TestMoneroBulletproof(unittest.TestCase): # Linear scan vs jump for i in range(65): tmp = d_vct0[i] - self.assertEqual(crypto.encodeint_into(None, tmp), crypto.encodeint_into(None, d_vct1[64])) + self.assertEqual( + crypto.encodeint_into(None, tmp), crypto.encodeint_into(None, d_vct1[64]) + ) # Jumping around _ = d_vct0[128] - self.assertEqual(crypto.encodeint_into(None, d_vct0[64]), crypto.encodeint_into(None, d_vct1[64])) + self.assertEqual( + crypto.encodeint_into(None, d_vct0[64]), + crypto.encodeint_into(None, d_vct1[64]), + ) # Sync on the same jump - self.assertEqual(crypto.encodeint_into(None, d_vct0[65]), crypto.encodeint_into(None, d_vct1[65])) - self.assertEqual(crypto.encodeint_into(None, d_vct0[65]), crypto.encodeint_into(None, d_vct1[65])) + self.assertEqual( + crypto.encodeint_into(None, d_vct0[65]), + crypto.encodeint_into(None, d_vct1[65]), + ) + self.assertEqual( + crypto.encodeint_into(None, d_vct0[65]), + crypto.encodeint_into(None, d_vct1[65]), + ) # Jump vs linear again, move_one vs move_more for i in range(1, 10): tmp = d_vct0[65 + i] - self.assertEqual(crypto.encodeint_into(None, tmp), crypto.encodeint_into(None, d_vct1[74])) + self.assertEqual( + crypto.encodeint_into(None, tmp), crypto.encodeint_into(None, d_vct1[74]) + ) _ = d_vct0[85] _ = d_vct1[89] # different jump sizes, internal state management test - self.assertEqual(crypto.encodeint_into(None, d_vct0[95]), crypto.encodeint_into(None, d_vct1[95])) + self.assertEqual( + crypto.encodeint_into(None, d_vct0[95]), + crypto.encodeint_into(None, d_vct1[95]), + ) _ = d_vct0[319] # move_one mults by z_sq then; enforce z component updates - self.assertEqual(crypto.encodeint_into(None, d_vct0[320]), crypto.encodeint_into(None, d_vct1[320])) + self.assertEqual( + crypto.encodeint_into(None, d_vct0[320]), + crypto.encodeint_into(None, d_vct1[320]), + ) tmp = crypto.sc_copy(None, d_vct0[64]) # another jump back and forth _ = d_vct0[127] - self.assertEqual(crypto.encodeint_into(None, d_vct0[64]), crypto.encodeint_into(None, tmp)) + self.assertEqual( + crypto.encodeint_into(None, d_vct0[64]), crypto.encodeint_into(None, tmp) + ) _ = d_vct0[0] _ = d_vct1[0] _ = d_vct0[64] - self.assertEqual(crypto.encodeint_into(None, d_vct0[5]), crypto.encodeint_into(None, d_vct1[5])) + self.assertEqual( + crypto.encodeint_into(None, d_vct0[5]), + crypto.encodeint_into(None, d_vct1[5]), + ) def test_pow_back_skips(self): MN = 128 - y = unhexlify('60421950bee0aab949e63336db1eb9532dba6b4599c5cd9fb1dbde909114100e') + y = unhexlify( + "60421950bee0aab949e63336db1eb9532dba6b4599c5cd9fb1dbde909114100e" + ) y_sc = crypto.decodeint_into(None, y) yinv = bp._invert(None, y) y_to_MN_1 = bp._sc_square_mult(None, y_sc, MN - 1) ymax = crypto.sc_mul_into(None, y_to_MN_1, y_sc) ## y**MN ymax2 = bp._sc_square_mult(None, y_sc, MN) - self.assertEqual(crypto.encodeint_into(None, ymax), crypto.encodeint_into(None, ymax2)) + self.assertEqual( + crypto.encodeint_into(None, ymax), crypto.encodeint_into(None, ymax2) + ) size = MN + 1 ypow_back = bp.KeyVPowersBackwards(size, y, x_inv=yinv, x_max=ymax, raw=True) - self.assertEqual(crypto.encodeint_into(None, ymax), crypto.encodeint_into(None, ypow_back[MN])) + self.assertEqual( + crypto.encodeint_into(None, ymax), + crypto.encodeint_into(None, ypow_back[MN]), + ) for i in range(10): _ = ypow_back[MN - i] - self.assertEqual(crypto.encodeint_into(None, ypow_back[MN - 9]), - crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 9))) - self.assertEqual(crypto.encodeint_into(None, ypow_back[MN - 19]), - crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 19))) - self.assertEqual(crypto.encodeint_into(None, ypow_back[MN - 65]), - crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 65))) - self.assertEqual(crypto.encodeint_into(None, ypow_back[MN - 14]), - crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 14))) + self.assertEqual( + crypto.encodeint_into(None, ypow_back[MN - 9]), + crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 9)), + ) + self.assertEqual( + crypto.encodeint_into(None, ypow_back[MN - 19]), + crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 19)), + ) + self.assertEqual( + crypto.encodeint_into(None, ypow_back[MN - 65]), + crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 65)), + ) + self.assertEqual( + crypto.encodeint_into(None, ypow_back[MN - 14]), + crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 14)), + ) tmp = crypto.sc_copy(None, ypow_back[MN - 64]) # another jump back and forth _ = ypow_back[MN - 127] - self.assertEqual(crypto.encodeint_into(None, ypow_back[MN - 64]), crypto.encodeint_into(None, tmp)) - self.assertEqual(crypto.encodeint_into(None, ypow_back[MN - 64]), - crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 64))) + self.assertEqual( + crypto.encodeint_into(None, ypow_back[MN - 64]), + crypto.encodeint_into(None, tmp), + ) + self.assertEqual( + crypto.encodeint_into(None, ypow_back[MN - 64]), + crypto.encodeint_into(None, bp._sc_square_mult(None, y_sc, MN - 64)), + ) def test_bpp_bprime(self): N, M = 64, 4 - MN = N*M - y = unhexlify(b'60421950bee0aab949e63336db1eb9532dba6b4599c5cd9fb1dbde909114100e') - z = unhexlify(b'e0408b528e9d35ccb8386b87f39b85c724740644f4db412483a8852cdb3ceb00') + MN = N * M + y = unhexlify( + b"60421950bee0aab949e63336db1eb9532dba6b4599c5cd9fb1dbde909114100e" + ) + z = unhexlify( + b"e0408b528e9d35ccb8386b87f39b85c724740644f4db412483a8852cdb3ceb00" + ) zc = crypto.decodeint_into(None, z) z_sq = bp._sc_mul(None, z, z) sv = [1234, 8789, 4455, 6697] @@ -231,8 +282,8 @@ class TestMoneroBulletproof(unittest.TestCase): def test_prove_plus_16(self): bpi = bp.BulletProofPlusBuilder() - sv = [crypto.Scalar(i*123 + 45) for i in range(16)] - gamma = [crypto.Scalar(i*456 * 17) for i in range(16)] + sv = [crypto.Scalar(i * 123 + 45) for i in range(16)] + gamma = [crypto.Scalar(i * 456 * 17) for i in range(16)] proof = bpi.prove_batch(sv, gamma) bpi.verify_batch([proof]) @@ -240,18 +291,38 @@ class TestMoneroBulletproof(unittest.TestCase): scalars = [0, 1, 2, 3, 4, 99] point_base = [0, 2, 4, 7, 12, 18] scalar_sc = [crypto.Scalar(x) for x in scalars] - points = [crypto.scalarmult_base_into(None, crypto.Scalar(x)) for x in point_base] + points = [ + crypto.scalarmult_base_into(None, crypto.Scalar(x)) for x in point_base + ] - muex = bp.MultiExp(scalars=[crypto.encodeint(x) for x in scalar_sc], - point_fnc=lambda i, d: crypto.encodepoint(points[i])) + muex = bp.MultiExp( + scalars=[crypto.encodeint(x) for x in scalar_sc], + point_fnc=lambda i, d: crypto.encodepoint(points[i]), + ) self.assertEqual(len(muex), len(scalars)) res = bp.multiexp(None, muex) res2 = bp.vector_exponent_custom( - A=bp.KeyVEval(3, lambda i, d: crypto.encodepoint_into(crypto.scalarmult_base_into(None, crypto.Scalar(point_base[i])), d)), - B=bp.KeyVEval(3, lambda i, d: crypto.encodepoint_into(crypto.scalarmult_base_into(None, crypto.Scalar(point_base[3+i])), d)), - a=bp.KeyVEval(3, lambda i, d: crypto.encodeint_into(crypto.Scalar(scalars[i]), d),), - b=bp.KeyVEval(3, lambda i, d: crypto.encodeint_into(crypto.Scalar(scalars[i+3]), d)), + A=bp.KeyVEval( + 3, + lambda i, d: crypto.encodepoint_into( + crypto.scalarmult_base_into(None, crypto.Scalar(point_base[i])), d + ), + ), + B=bp.KeyVEval( + 3, + lambda i, d: crypto.encodepoint_into( + crypto.scalarmult_base_into(None, crypto.Scalar(point_base[3 + i])), + d, + ), + ), + a=bp.KeyVEval( + 3, + lambda i, d: crypto.encodeint_into(crypto.Scalar(scalars[i]), d), + ), + b=bp.KeyVEval( + 3, lambda i, d: crypto.encodeint_into(crypto.Scalar(scalars[i + 3]), d) + ), ) self.assertEqual(res, res2) diff --git a/core/tests/test_apps.monero.clsag.py b/core/tests/test_apps.monero.clsag.py index 13446ac559..66458998eb 100644 --- a/core/tests/test_apps.monero.clsag.py +++ b/core/tests/test_apps.monero.clsag.py @@ -117,7 +117,9 @@ class TestMoneroClsag(unittest.TestCase): ring.append(tk) index = index if index is not None else random.uniform(len(ring)) - ring.insert(index, TmpKey(crypto_helpers.encodepoint(P), crypto_helpers.encodepoint(C))) + ring.insert( + index, TmpKey(crypto_helpers.encodepoint(P), crypto_helpers.encodepoint(C)) + ) ring2 = list(ring) mg_buffer = [] @@ -137,7 +139,13 @@ class TestMoneroClsag(unittest.TestCase): ) clsag.generate_clsag_simple( - msg, ring, CtKey(priv, msk), alpha, Cp, index, mg_buffer, + msg, + ring, + CtKey(priv, msk), + alpha, + Cp, + index, + mg_buffer, ) sD = crypto_helpers.decodepoint(mg_buffer[-1]) @@ -156,7 +164,9 @@ class TestMoneroClsag(unittest.TestCase): sD = crypto_helpers.decodepoint(ubinascii.unhexlify(clsag["sD"])) sc1 = crypto_helpers.decodeint(ubinascii.unhexlify(clsag["sc1"])) Cout = crypto_helpers.decodepoint(ubinascii.unhexlify(clsag["cout"])) - scalars = [crypto_helpers.decodeint(ubinascii.unhexlify(x)) for x in clsag["ss"]] + scalars = [ + crypto_helpers.decodeint(ubinascii.unhexlify(x)) for x in clsag["ss"] + ] ring = [] for e in clsag["ring"]: ring.append(TmpKey(ubinascii.unhexlify(e[0]), ubinascii.unhexlify(e[1]))) diff --git a/core/tests/test_apps.monero.crypto.py b/core/tests/test_apps.monero.crypto.py index e200dc91b2..6fd1a63e8c 100644 --- a/core/tests/test_apps.monero.crypto.py +++ b/core/tests/test_apps.monero.crypto.py @@ -15,11 +15,15 @@ class TestMoneroCrypto(unittest.TestCase): point = unhexlify( b"2486224797d05cae3cba4be043be2db0df381f3f19cfa113f86ab38e3d8d2bd0" ) - self.assertEqual(point, crypto_helpers.encodepoint(crypto_helpers.decodepoint(point))) + self.assertEqual( + point, crypto_helpers.encodepoint(crypto_helpers.decodepoint(point)) + ) self.assertTrue( crypto.point_eq( crypto_helpers.decodepoint(point), - crypto_helpers.decodepoint(crypto_helpers.encodepoint(crypto_helpers.decodepoint(point))), + crypto_helpers.decodepoint( + crypto_helpers.encodepoint(crypto_helpers.decodepoint(point)) + ), ) ) @@ -61,7 +65,9 @@ class TestMoneroCrypto(unittest.TestCase): b"adcd1f5881f46f254900a03c654e71950a88a0236fa0a3a946c9b8daed6ef43d" ) - res = crypto.scalarmult_into(None, crypto_helpers.decodepoint(pub), crypto_helpers.decodeint(priv)) + res = crypto.scalarmult_into( + None, crypto_helpers.decodepoint(pub), crypto_helpers.decodeint(priv) + ) self.assertEqual(exp, crypto_helpers.encodepoint(res)) self.assertTrue(crypto.point_eq(crypto_helpers.decodepoint(exp), res)) @@ -111,7 +117,9 @@ class TestMoneroCrypto(unittest.TestCase): b"25d08763414c379aa9cf989cdcb3cadd36bd5193b500107d6bf5f921f18e470e" ) - sc_int = crypto_helpers.derivation_to_scalar(crypto_helpers.decodepoint(derivation), 0) + sc_int = crypto_helpers.derivation_to_scalar( + crypto_helpers.decodepoint(derivation), 0 + ) self.assertEqual(scalar, crypto_helpers.encodeint(sc_int)) def test_generate_key_derivation(self): @@ -131,7 +139,9 @@ class TestMoneroCrypto(unittest.TestCase): self.assertEqual( deriv_exp, - crypto_helpers.encodepoint(crypto_helpers.generate_key_derivation(key_pub, key_priv)), + crypto_helpers.encodepoint( + crypto_helpers.generate_key_derivation(key_pub, key_priv) + ), ) def test_h(self): @@ -158,13 +168,20 @@ class TestMoneroCrypto(unittest.TestCase): addr_exp = "4LL9oSLmtpccfufTMvppY6JwXNouMBzSkbLYfpAV5Usx3skxNgYeYTRj5UzqtReoS44qo9mtmXCqY45DJ852K5Jv2bYXZKKQePHES9khPK" addr = tcry.xmr_base58_addr_encode_check( 19, - unhexlify(b"eda9fe8dfcdd25d5430ea64229d04f6b41b2e5a1587c29cd499a63eb79d117113076a02b73d130fb904c9e91075fcd16f735c6850dfadb125eb826d96a113f098a125052fe6f3877")) + unhexlify( + b"eda9fe8dfcdd25d5430ea64229d04f6b41b2e5a1587c29cd499a63eb79d117113076a02b73d130fb904c9e91075fcd16f735c6850dfadb125eb826d96a113f098a125052fe6f3877" + ), + ) addr2 = encode_addr( bytes([19]), - unhexlify(b"eda9fe8dfcdd25d5430ea64229d04f6b41b2e5a1587c29cd499a63eb79d11711"), - unhexlify(b"3076a02b73d130fb904c9e91075fcd16f735c6850dfadb125eb826d96a113f09"), - unhexlify(b"8a125052fe6f3877") + unhexlify( + b"eda9fe8dfcdd25d5430ea64229d04f6b41b2e5a1587c29cd499a63eb79d11711" + ), + unhexlify( + b"3076a02b73d130fb904c9e91075fcd16f735c6850dfadb125eb826d96a113f09" + ), + unhexlify(b"8a125052fe6f3877"), ) self.assertEqual(addr, addr_exp) @@ -215,7 +232,9 @@ class TestMoneroCrypto(unittest.TestCase): b"259ef2aba8feb473cf39058a0fe30b9ff6d245b42b6826687ebd6b63128aff64" ) ) - res = crypto_helpers.encodepoint(monero.derive_subaddress_public_key(out_key, deriv, 5)) + res = crypto_helpers.encodepoint( + monero.derive_subaddress_public_key(out_key, deriv, 5) + ) self.assertEqual( res, unhexlify( @@ -257,13 +276,27 @@ class TestMoneroCrypto(unittest.TestCase): from apps.monero.signing.step_06_set_output import _derive_view_tags test_vectors = [ - (b'0fc47054f355ced4d67de73bfa12e4c78ff19089548fffa7d07a674741860f97', 0, b'\x76'), - (b'fe7770c4b076e95ddb8026affcfab39d31c7c4a2266e0e25e343bc4badc907d0', 15, b'\xeb'), - (b'ea9337d0ddf480abdc4fc56a0cb223702729cb230ae7b9de50243ad25ce90e8d', 13, b'\x42'), + ( + b"0fc47054f355ced4d67de73bfa12e4c78ff19089548fffa7d07a674741860f97", + 0, + b"\x76", + ), + ( + b"fe7770c4b076e95ddb8026affcfab39d31c7c4a2266e0e25e343bc4badc907d0", + 15, + b"\xeb", + ), + ( + b"ea9337d0ddf480abdc4fc56a0cb223702729cb230ae7b9de50243ad25ce90e8d", + 13, + b"\x42", + ), ] for key, idx, exp in test_vectors: - self.assertEqual(_derive_view_tags(crypto_helpers.decodepoint(unhexlify(key)), idx), exp) + self.assertEqual( + _derive_view_tags(crypto_helpers.decodepoint(unhexlify(key)), idx), exp + ) if __name__ == "__main__": diff --git a/core/tests/test_apps.nem.address.py b/core/tests/test_apps.nem.address.py index d8ede1531b..251cefce7a 100644 --- a/core/tests/test_apps.nem.address.py +++ b/core/tests/test_apps.nem.address.py @@ -3,52 +3,111 @@ from apps.common.paths import HARDENED if not utils.BITCOIN_ONLY: from trezor.crypto import nem - from apps.nem.helpers import check_path, NEM_NETWORK_MAINNET, NEM_NETWORK_TESTNET, NEM_NETWORK_MIJIN + from apps.nem.helpers import ( + check_path, + NEM_NETWORK_MAINNET, + NEM_NETWORK_TESTNET, + NEM_NETWORK_MIJIN, + ) @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemAddress(unittest.TestCase): - def test_addresses(self): - pubkey = unhexlify('c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844') + pubkey = unhexlify( + "c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844" + ) address = nem.compute_address(pubkey, NEM_NETWORK_MAINNET) - self.assertEqual(address, 'NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4') + self.assertEqual(address, "NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4") - pubkey = unhexlify('114171230ad6f8522a000cdc73fbc5c733b30bb71f2b146ccbdf34499f79a810') + pubkey = unhexlify( + "114171230ad6f8522a000cdc73fbc5c733b30bb71f2b146ccbdf34499f79a810" + ) address = nem.compute_address(pubkey, NEM_NETWORK_MAINNET) - self.assertEqual(address, 'NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP') + self.assertEqual(address, "NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP") def test_validate_address(self): - validity = nem.validate_address('NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4', NEM_NETWORK_MAINNET) + validity = nem.validate_address( + "NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4", NEM_NETWORK_MAINNET + ) self.assertTrue(validity) - validity = nem.validate_address('NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP', NEM_NETWORK_MAINNET) + validity = nem.validate_address( + "NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP", NEM_NETWORK_MAINNET + ) self.assertTrue(validity) - validity = nem.validate_address('TAU5HO3DRQZNELFEMZZTUKQEZGQ7IUAHKPO7OOLK', NEM_NETWORK_TESTNET) + validity = nem.validate_address( + "TAU5HO3DRQZNELFEMZZTUKQEZGQ7IUAHKPO7OOLK", NEM_NETWORK_TESTNET + ) self.assertTrue(validity) - validity = nem.validate_address('nope', NEM_NETWORK_TESTNET) + validity = nem.validate_address("nope", NEM_NETWORK_TESTNET) self.assertFalse(validity) # not valid on testnet - validity = nem.validate_address('NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP', NEM_NETWORK_TESTNET) + validity = nem.validate_address( + "NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP", NEM_NETWORK_TESTNET + ) self.assertFalse(validity) def test_check_path(self): # mainnet path: - self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_MAINNET)) + self.assertTrue( + check_path( + [ + 44 | HARDENED, + 43 | HARDENED, + 0 | HARDENED, + 0 | HARDENED, + 0 | HARDENED, + ], + NEM_NETWORK_MAINNET, + ) + ) # should be valid on mijin as well: - self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_MIJIN)) + self.assertTrue( + check_path( + [ + 44 | HARDENED, + 43 | HARDENED, + 0 | HARDENED, + 0 | HARDENED, + 0 | HARDENED, + ], + NEM_NETWORK_MIJIN, + ) + ) # testnet path: - self.assertTrue(check_path([44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_TESTNET)) + self.assertTrue( + check_path( + [44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], + NEM_NETWORK_TESTNET, + ) + ) # short path (check_path does not validate pattern match): self.assertTrue(check_path([44 | HARDENED, 43 | HARDENED], NEM_NETWORK_MAINNET)) # testnet path on mainnet: - self.assertFalse(check_path([44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_MAINNET)) + self.assertFalse( + check_path( + [44 | HARDENED, 1 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], + NEM_NETWORK_MAINNET, + ) + ) # mainnet path on testnet: - self.assertFalse(check_path([44 | HARDENED, 43 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], NEM_NETWORK_TESTNET)) + self.assertFalse( + check_path( + [ + 44 | HARDENED, + 43 | HARDENED, + 0 | HARDENED, + 0 | HARDENED, + 0 | HARDENED, + ], + NEM_NETWORK_TESTNET, + ) + ) # path too short to extract SLIP44: self.assertFalse(check_path([44 | HARDENED], NEM_NETWORK_TESTNET)) # unknown SLIP44: @@ -57,5 +116,5 @@ class TestNemAddress(unittest.TestCase): self.assertFalse(check_path([44 | HARDENED, 43, 0], NEM_NETWORK_MAINNET)) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.nem.hdnode.py b/core/tests/test_apps.nem.hdnode.py index 3556b4e4a3..4f506c17f8 100644 --- a/core/tests/test_apps.nem.hdnode.py +++ b/core/tests/test_apps.nem.hdnode.py @@ -8,71 +8,110 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemHDNode(unittest.TestCase): - def test_addresses(self): # test vectors from https://raw.githubusercontent.com/NemProject/nem-test-vectors/master/1.test-keys.dat # private key, public key, address test_cases = [ - ('575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced', - 'c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844', - 'NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4'), - ('5b0e3fa5d3b49a79022d7c1e121ba1cbbf4db5821f47ab8c708ef88defc29bfe', - '96eb2a145211b1b7ab5f0d4b14f8abc8d695c7aee31a3cfc2d4881313c68eea3', - 'NABHFGE5ORQD3LE4O6B7JUFN47ECOFBFASC3SCAC'), - ('738ba9bb9110aea8f15caa353aca5653b4bdfca1db9f34d0efed2ce1325aeeda', - '2d8425e4ca2d8926346c7a7ca39826acd881a8639e81bd68820409c6e30d142a', - 'NAVOZX4HDVOAR4W6K4WJHWPD3MOFU27DFHC7KZOZ'), - ('e8bf9bc0f35c12d8c8bf94dd3a8b5b4034f1063948e3cc5304e55e31aa4b95a6', - '4feed486777ed38e44c489c7c4e93a830e4c4a907fa19a174e630ef0f6ed0409', - 'NBZ6JK5YOCU6UPSSZ5D3G27UHAPHTY5HDQMGE6TT'), - ('c325ea529674396db5675939e7988883d59a5fc17a28ca977e3ba85370232a83', - '83ee32e4e145024d29bca54f71fa335a98b3e68283f1a3099c4d4ae113b53e54', - 'NCQW2P5DNZ5BBXQVGS367DQ4AHC3RXOEVGRCLY6V'), - ('a811cb7a80a7227ae61f6da536534ee3c2744e3c7e4b85f3e0df3c6a9c5613df', - '6d34c04f3a0e42f0c3c6f50e475ae018cfa2f56df58c481ad4300424a6270cbb', - 'NA5IG3XFXZHIPJ5QLKX2FBJPEZYPMBPPK2ZRC3EH'), - ('9c66de1ec77f4dfaaebdf9c8bc599ca7e8e6f0bc71390ffee2c9dd3f3619242a', - 'a8fefd72a3b833dc7c7ed7d57ed86906dac22f88f1f4331873eb2da3152a3e77', - 'NAABHVFJDBM74XMJJ52R7QN2MTTG2ZUXPQS62QZ7'), - ('c56bc16ecf727878c15e24f4ae68569600ac7b251218a44ef50ce54175776edc', - 'c92f761e6d83d20068fd46fe4bd5b97f4c6ba05d23180679b718d1f3e4fb066e', - 'NCLK3OLMHR3F2E3KSBUIZ4K5PNWUDN37MLSJBJZP'), - ('9dd73599283882fa1561ddfc9be5830b5dd453c90465d3fe5eeb646a3606374e', - 'eaf16a4833e59370a04ccd5c63395058de34877b48c17174c71db5ed37b537ed', - 'ND3AHW4VTI5R5QE5V44KIGPRU5FBJ5AFUCJXOY5H'), - ('d9639dc6f49dad02a42fd8c217f1b1b4f8ce31ccd770388b645e639c72ff24fa', - '0f74a2f537cd9c986df018994dde75bdeee05e35eb9fe27adf506ca8475064f7', - 'NCTZ4YAP43ONK3UYTASQVNDMBO24ZHJE65F3QPYE'), - ('efc1992cd50b70ca55ac12c07aa5d026a8b78ffe28a7dbffc9228b26e02c38c1', - '2ebff201255f6cf948c78f528658b99a7c13ac791942fa22d59af610558111f5', - 'NDQ2TMCMXBSFPZQPE2YKH6XLC24HD6LUMN6Z4GIC'), - ('143a815e92e43f3ed1a921ee48cd143931b88b7c3d8e1e981f743c2a5be3c5ba', - '419ed11d48730e4ae2c93f0ea4df853b8d578713a36dab227517cf965861af4e', - 'NA32IDDW2C53BDSBJNFL3Z6UU3J5CJZJMCZDXCF4'), - ('bc1a082f5ac6fdd3a83ade211e5986ac0551bad6c7da96727ec744e5df963e2a', - 'a160e6f9112233a7ce94202ed7a4443e1dac444b5095f9fecbb965fba3f92cac', - 'NADUCEQLC3FTGB25GTA5HOUTB53CBVQNVOIP7NTJ'), - ('4e47b4c6f4c7886e49ec109c61f4af5cfbb1637283218941d55a7f9fe1053f72', - 'fbb91b16df828e21a9802980a44fc757c588bc1382a4cea429d6fa2ae0333f56', - 'NBAF3BFLLPWH33MYE6VUPP5T6DQBZBKIDEQKZQOE'), - ('efc4389da48ce49f85365cfa578c746530e9eac42db1b64ec346119b1becd347', - '2232f24dda0f2ded3ecd831210d4e8521a096b50cadd5a34f3f7083374e1ec12', - 'NBOGTK2I2ATOGGD7ZFJHROG5MWL7XCKAUKSWIVSA'), - ('bdba57c78ca7da16a3360efd13f06276284db8c40351de7fcd38ba0c35ac754d', - 'c334c6c0dad5aaa2a0d0fb4c6032cb6a0edd96bf61125b5ea9062d5a00ee0eee', - 'NCLERTEFYXKLK7RA4MVACEFMXMK3P7QMWTM7FBW2'), - ('20694c1ec3c4a311bcdb29ed2edc428f6d4f9a4c429ad6a5bf3222084e35695f', - '518c4de412efa93de06a55947d11f697639443916ec8fcf04ebc3e6d17d0bd93', - 'NB5V4BPIJHXVONO7UGMJDPFARMFA73BOBNOOYCOV'), - ('e0d4f3760ac107b33c22c2cac24ab2f520b282684f5f66a4212ff95d926323ce', - 'b3d16f4ead9de67c290144da535a0ed2504b03c05e5f1ceb8c7863762f786857', - 'NC4PBAO5TPCAVQKBVOC4F6DMZP3CFSQBU46PSKBD'), - ('efa9afc617412093c9c7a7c211a5332dd556f941e1a88c494ec860608610eea2', - '7e7716e4cebceb731d6f1fd28676f34888e9a0000fcfa1471db1c616c2ddf559', - 'NCFW2LPXIWLBWAQN2QVIWEOD7IVDO3HQBD2OU56K'), - ('d98499b3db61944684ce06a91735af4e14105338473fcf6ebe2b0bcada3dfd21', - '114171230ad6f8522a000cdc73fbc5c733b30bb71f2b146ccbdf34499f79a810', - 'NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP') + ( + "575dbb3062267eff57c970a336ebbc8fbcfe12c5bd3ed7bc11eb0481d7704ced", + "c5f54ba980fcbb657dbaaa42700539b207873e134d2375efeab5f1ab52f87844", + "NDD2CT6LQLIYQ56KIXI3ENTM6EK3D44P5JFXJ4R4", + ), + ( + "5b0e3fa5d3b49a79022d7c1e121ba1cbbf4db5821f47ab8c708ef88defc29bfe", + "96eb2a145211b1b7ab5f0d4b14f8abc8d695c7aee31a3cfc2d4881313c68eea3", + "NABHFGE5ORQD3LE4O6B7JUFN47ECOFBFASC3SCAC", + ), + ( + "738ba9bb9110aea8f15caa353aca5653b4bdfca1db9f34d0efed2ce1325aeeda", + "2d8425e4ca2d8926346c7a7ca39826acd881a8639e81bd68820409c6e30d142a", + "NAVOZX4HDVOAR4W6K4WJHWPD3MOFU27DFHC7KZOZ", + ), + ( + "e8bf9bc0f35c12d8c8bf94dd3a8b5b4034f1063948e3cc5304e55e31aa4b95a6", + "4feed486777ed38e44c489c7c4e93a830e4c4a907fa19a174e630ef0f6ed0409", + "NBZ6JK5YOCU6UPSSZ5D3G27UHAPHTY5HDQMGE6TT", + ), + ( + "c325ea529674396db5675939e7988883d59a5fc17a28ca977e3ba85370232a83", + "83ee32e4e145024d29bca54f71fa335a98b3e68283f1a3099c4d4ae113b53e54", + "NCQW2P5DNZ5BBXQVGS367DQ4AHC3RXOEVGRCLY6V", + ), + ( + "a811cb7a80a7227ae61f6da536534ee3c2744e3c7e4b85f3e0df3c6a9c5613df", + "6d34c04f3a0e42f0c3c6f50e475ae018cfa2f56df58c481ad4300424a6270cbb", + "NA5IG3XFXZHIPJ5QLKX2FBJPEZYPMBPPK2ZRC3EH", + ), + ( + "9c66de1ec77f4dfaaebdf9c8bc599ca7e8e6f0bc71390ffee2c9dd3f3619242a", + "a8fefd72a3b833dc7c7ed7d57ed86906dac22f88f1f4331873eb2da3152a3e77", + "NAABHVFJDBM74XMJJ52R7QN2MTTG2ZUXPQS62QZ7", + ), + ( + "c56bc16ecf727878c15e24f4ae68569600ac7b251218a44ef50ce54175776edc", + "c92f761e6d83d20068fd46fe4bd5b97f4c6ba05d23180679b718d1f3e4fb066e", + "NCLK3OLMHR3F2E3KSBUIZ4K5PNWUDN37MLSJBJZP", + ), + ( + "9dd73599283882fa1561ddfc9be5830b5dd453c90465d3fe5eeb646a3606374e", + "eaf16a4833e59370a04ccd5c63395058de34877b48c17174c71db5ed37b537ed", + "ND3AHW4VTI5R5QE5V44KIGPRU5FBJ5AFUCJXOY5H", + ), + ( + "d9639dc6f49dad02a42fd8c217f1b1b4f8ce31ccd770388b645e639c72ff24fa", + "0f74a2f537cd9c986df018994dde75bdeee05e35eb9fe27adf506ca8475064f7", + "NCTZ4YAP43ONK3UYTASQVNDMBO24ZHJE65F3QPYE", + ), + ( + "efc1992cd50b70ca55ac12c07aa5d026a8b78ffe28a7dbffc9228b26e02c38c1", + "2ebff201255f6cf948c78f528658b99a7c13ac791942fa22d59af610558111f5", + "NDQ2TMCMXBSFPZQPE2YKH6XLC24HD6LUMN6Z4GIC", + ), + ( + "143a815e92e43f3ed1a921ee48cd143931b88b7c3d8e1e981f743c2a5be3c5ba", + "419ed11d48730e4ae2c93f0ea4df853b8d578713a36dab227517cf965861af4e", + "NA32IDDW2C53BDSBJNFL3Z6UU3J5CJZJMCZDXCF4", + ), + ( + "bc1a082f5ac6fdd3a83ade211e5986ac0551bad6c7da96727ec744e5df963e2a", + "a160e6f9112233a7ce94202ed7a4443e1dac444b5095f9fecbb965fba3f92cac", + "NADUCEQLC3FTGB25GTA5HOUTB53CBVQNVOIP7NTJ", + ), + ( + "4e47b4c6f4c7886e49ec109c61f4af5cfbb1637283218941d55a7f9fe1053f72", + "fbb91b16df828e21a9802980a44fc757c588bc1382a4cea429d6fa2ae0333f56", + "NBAF3BFLLPWH33MYE6VUPP5T6DQBZBKIDEQKZQOE", + ), + ( + "efc4389da48ce49f85365cfa578c746530e9eac42db1b64ec346119b1becd347", + "2232f24dda0f2ded3ecd831210d4e8521a096b50cadd5a34f3f7083374e1ec12", + "NBOGTK2I2ATOGGD7ZFJHROG5MWL7XCKAUKSWIVSA", + ), + ( + "bdba57c78ca7da16a3360efd13f06276284db8c40351de7fcd38ba0c35ac754d", + "c334c6c0dad5aaa2a0d0fb4c6032cb6a0edd96bf61125b5ea9062d5a00ee0eee", + "NCLERTEFYXKLK7RA4MVACEFMXMK3P7QMWTM7FBW2", + ), + ( + "20694c1ec3c4a311bcdb29ed2edc428f6d4f9a4c429ad6a5bf3222084e35695f", + "518c4de412efa93de06a55947d11f697639443916ec8fcf04ebc3e6d17d0bd93", + "NB5V4BPIJHXVONO7UGMJDPFARMFA73BOBNOOYCOV", + ), + ( + "e0d4f3760ac107b33c22c2cac24ab2f520b282684f5f66a4212ff95d926323ce", + "b3d16f4ead9de67c290144da535a0ed2504b03c05e5f1ceb8c7863762f786857", + "NC4PBAO5TPCAVQKBVOC4F6DMZP3CFSQBU46PSKBD", + ), + ( + "efa9afc617412093c9c7a7c211a5332dd556f941e1a88c494ec860608610eea2", + "7e7716e4cebceb731d6f1fd28676f34888e9a0000fcfa1471db1c616c2ddf559", + "NCFW2LPXIWLBWAQN2QVIWEOD7IVDO3HQBD2OU56K", + ), + ( + "d98499b3db61944684ce06a91735af4e14105338473fcf6ebe2b0bcada3dfd21", + "114171230ad6f8522a000cdc73fbc5c733b30bb71f2b146ccbdf34499f79a810", + "NCUKWDY3J3THKQHAKOK5ALF6ANJQABZHCH7VN6DP", + ), ] for test in test_cases: @@ -84,7 +123,7 @@ class TestNemHDNode(unittest.TestCase): child_num=0, chain_code=bytearray(32), private_key=private_key, - curve_name=CURVE + curve_name=CURVE, ) self.assertEqual(node.nem_address(NEM_NETWORK_MAINNET), test[2]) @@ -95,146 +134,188 @@ class TestNemHDNode(unittest.TestCase): # test vectors from https://raw.githubusercontent.com/NemProject/nem-test-vectors/master/4.test-cipher.dat # private key, transfer public key, salt, iv, plain text, cipher text test_cases = [ - {'private': '3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6', - 'public': '57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21', - 'salt': '83616c67f076d356fd1288a6e0fd7a60488ba312a3adf0088b1b33c7655c3e6a', - 'iv': 'a73ff5c32f8fd055b09775817a6a3f95', - 'input': '86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c', - 'output': '70815da779b1b954d7a7f00c16940e9917a0412a06a444b539bf147603eef87f'}, - {'private': '3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6', - 'public': '57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21', - 'salt': '703ce0b1d276b10eef35672df03234385a903460db18ba9d4e05b3ad31abb284', - 'iv': '91246c2d5493867c4fa3e78f85963677', - 'input': '86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c', - 'output': '564b2f40d42c0efc1bd6f057115a5abd1564cae36d7ccacf5d825d38401aa894'}, - {'private': '3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6', - 'public': '57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21', - 'salt': 'b22e8e8e7373ac31ca7f0f6eb8b93130aba5266772a658593f3a11792e7e8d92', - 'iv': '9f8e33d82374dad6aac0e3dbe7aea704', - 'input': '86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c', - 'output': '7cab88d00a3fc656002eccbbd966e1d5d14a3090d92cf502cdbf843515625dcf'}, - {'private': '3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6', - 'public': '57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21', - 'salt': 'af646c54cd153dffe453b60efbceeb85c1e95a414ea0036c4da94afb3366f5d9', - 'iv': '6acdf8e01acc8074ddc807281b6af888', - 'input': '86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c', - 'output': 'aa70543a485b63a4dd141bb7fd78019092ac6fad731e914280a287c7467bae1a'}, - {'private': '3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6', - 'public': '57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21', - 'salt': 'd9c0d386636c8a024935c024589f9cd39e820a16485b14951e690a967830e269', - 'iv': 'f2e9f18aeb374965f54d2f4e31189a8f', - 'input': '86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c', - 'output': '33d97c216ea6498dfddabf94c2e2403d73efc495e9b284d9d90aaff840217d25'}, - {'private': 'd5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a', - 'public': '66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04', - 'salt': '06c227baac1ae3b0b1dc583f4850f13f9ba5d53be4a98fa5c3ea16217847530d', - 'iv': '3735123e78c44895df6ea33fa57e9a72', - 'input': '86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c', - 'output': 'd5b5d66ba8cee0eb7ecf95b143fa77a46d6de13749e12eff40f5a7e649167ccb'}, - {'private': 'd5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a', - 'public': '66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04', - 'salt': '92f55ba5bc6fc2f23e3eedc299357c71518e36ba2447a4da7a9dfe9dfeb107b5', - 'iv': '1cbc4982e53e370052af97ab088fa942', - 'input': '86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c', - 'output': 'd48ef1ef526d805656cfc932aff259eadb17aa3391dde1877a722cba31d935b2'}, - {'private': 'd5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a', - 'public': '66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04', - 'salt': '10f15a39ba49866292a43b7781bc71ca8bbd4889f1616461caf056bcb91b0158', - 'iv': 'c40d531d92bfee969dce91417346c892', - 'input': '49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4', - 'output': 'e6d75afdb542785669b42198577c5b358d95397d71ec6f5835dca46d332cc08dbf73ea790b7bcb169a65719c0d55054c'}, - {'private': 'd5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a', - 'public': '66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04', - 'salt': '9c01ed42b219b3bbe1a43ae9d7af5c1dd09363baacfdba8f4d03d1046915e26e', - 'iv': '059a35d5f83249e632790015ed6518b9', - 'input': '49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4', - 'output': '5ef11aadff2eccee8b712dab968fa842eb770818ec0e6663ed242ea8b6bbc1c66d6285ee5b5f03d55dfee382fb4fa25d'}, - {'private': 'd5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a', - 'public': '66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04', - 'salt': 'bc1067e2a7415ea45ff1ca9894338c591ff15f2e57ae2789ae31b9d5bea0f11e', - 'iv': '8c73f0d6613898daeefa3cf8b0686d37', - 'input': '49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4', - 'output': '6d220213b1878cd40a458f2a1e6e3b48040455fdf504dcd857f4f2ca1ad642e3a44fc401d04e339d302f66a9fad3d919'}, - {'private': '9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921', - 'public': '441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094', - 'salt': 'cf4a21cb790552165827b678ca9695fcaf77566d382325112ff79483455de667', - 'iv': 'bfbf5482e06f55b88bdd9e053b7eee6e', - 'input': '49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4', - 'output': '1198a78c29c215d5c450f7b8513ead253160bc9fde80d9cc8e6bee2efe9713cf5a09d6293c41033271c9e8c22036a28b'}, - {'private': '9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921', - 'public': '441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094', - 'salt': 'eba5eae8aef79114082c3e70baef95bb02edf13b3897e8be7a70272962ef8838', - 'iv': 'af9a56da3da18e2fbd2948a16332532b', - 'input': '49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4', - 'output': '1062ab5fbbdee9042ad35bdadfd3047c0a2127fe0f001da1be1b0582185edfc9687be8d68f85795833bb04af9cedd3bb'}, - {'private': '9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921', - 'public': '441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094', - 'salt': '518f8dfd0c138f1ffb4ea8029db15441d70abd893c3d767dc668f23ba7770e27', - 'iv': '42d28307974a1b2a2d921d270cfce03b', - 'input': '49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4', - 'output': '005e49fb7c5da540a84b034c853fc9f78a6b901ea495aed0c2abd4f08f1a96f9ffefc6a57f1ac09e0aea95ca0f03ffd8'}, - {'private': '9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921', - 'public': '441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094', - 'salt': '582fdf58b53715c26e10ba809e8f2ab70502e5a3d4e9a81100b7227732ab0bbc', - 'iv': '91f2aad3189bb2edc93bc891e73911ba', - 'input': '49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4', - 'output': '821a69cb16c57f0cb866e590b38069e35faec3ae18f158bb067db83a11237d29ab1e6b868b3147236a0958f15c2e2167'}, - {'private': '9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921', - 'public': '441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094', - 'salt': 'a415b4c006118fb72fc37b2746ef288e23ac45c8ff7ade5f368a31557b6ac93a', - 'iv': '2b7c5f75606c0b8106c6489ea5657a9e', - 'input': '24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85', - 'output': '2781d5ee8ef1cb1596f8902b33dfae5045f84a987ca58173af5830dbce386062'}, - {'private': 'ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc', - 'public': '5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541', - 'salt': '47e73ec362ea82d3a7c5d55532ad51d2cdf5316b981b2b2bd542b0efa027e8ea', - 'iv': 'b2193f59030c8d05a7d3577b7f64dd33', - 'input': '24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85', - 'output': '3f43912db8dd6672b9996e5272e18c4b88fec9d7e8372db9c5f4709a4af1d86f'}, - {'private': 'ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc', - 'public': '5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541', - 'salt': 'aaa006c57b6d1e402650577fe9787d8d285f4bacd7c01f998be49c766f8860c7', - 'iv': '130304ddb9adc8870cf56bcae9487b7f', - 'input': '24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85', - 'output': '878cc7d8c0ef8dac0182a78eedc8080a402f59d8062a6b4ca8f4a74f3c3b3de7'}, - {'private': 'ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc', - 'public': '5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541', - 'salt': '28dc7ccd6c2a939eef64b8be7b9ae248295e7fcd8471c22fa2f98733fea97611', - 'iv': 'cb13890d3a11bc0a7433738263006710', - 'input': '24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85', - 'output': 'e74ded846bebfa912fa1720e4c1415e6e5df7e7a1a7fedb5665d68f1763209a4'}, - {'private': 'ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc', - 'public': '5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541', - 'salt': '79974fa2cad95154d0873902c153ccc3e7d54b17f2eeb3f29b6344cad9365a9a', - 'iv': '22123357979d20f44cc8eb0263d84e0e', - 'input': '24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85', - 'output': 'eb14dec7b8b64d81a2ee4db07b0adf144d4f79a519bbf332b823583fa2d45405'}, - {'private': 'ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc', - 'public': '5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541', - 'salt': '3409a6f8c4dcd9bd04144eb67e55a98696b674735b01bf1196191f29871ef966', - 'iv': 'a823a0965969380ea1f8659ea5fd8fdd', - 'input': '24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85', - 'output': '00a7eb708eae745847173f8217efb05be13059710aee632e3f471ac3c6202b51'}, + { + "private": "3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6", + "public": "57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21", + "salt": "83616c67f076d356fd1288a6e0fd7a60488ba312a3adf0088b1b33c7655c3e6a", + "iv": "a73ff5c32f8fd055b09775817a6a3f95", + "input": "86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c", + "output": "70815da779b1b954d7a7f00c16940e9917a0412a06a444b539bf147603eef87f", + }, + { + "private": "3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6", + "public": "57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21", + "salt": "703ce0b1d276b10eef35672df03234385a903460db18ba9d4e05b3ad31abb284", + "iv": "91246c2d5493867c4fa3e78f85963677", + "input": "86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c", + "output": "564b2f40d42c0efc1bd6f057115a5abd1564cae36d7ccacf5d825d38401aa894", + }, + { + "private": "3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6", + "public": "57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21", + "salt": "b22e8e8e7373ac31ca7f0f6eb8b93130aba5266772a658593f3a11792e7e8d92", + "iv": "9f8e33d82374dad6aac0e3dbe7aea704", + "input": "86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c", + "output": "7cab88d00a3fc656002eccbbd966e1d5d14a3090d92cf502cdbf843515625dcf", + }, + { + "private": "3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6", + "public": "57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21", + "salt": "af646c54cd153dffe453b60efbceeb85c1e95a414ea0036c4da94afb3366f5d9", + "iv": "6acdf8e01acc8074ddc807281b6af888", + "input": "86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c", + "output": "aa70543a485b63a4dd141bb7fd78019092ac6fad731e914280a287c7467bae1a", + }, + { + "private": "3140f94c79f249787d1ec75a97a885980eb8f0a7d9b7aa03e7200296e422b2b6", + "public": "57a70eb553a7b3fd621f0dba6abf51312ea2e2a2a1e19d0305516730f4bcbd21", + "salt": "d9c0d386636c8a024935c024589f9cd39e820a16485b14951e690a967830e269", + "iv": "f2e9f18aeb374965f54d2f4e31189a8f", + "input": "86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c", + "output": "33d97c216ea6498dfddabf94c2e2403d73efc495e9b284d9d90aaff840217d25", + }, + { + "private": "d5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a", + "public": "66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04", + "salt": "06c227baac1ae3b0b1dc583f4850f13f9ba5d53be4a98fa5c3ea16217847530d", + "iv": "3735123e78c44895df6ea33fa57e9a72", + "input": "86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c", + "output": "d5b5d66ba8cee0eb7ecf95b143fa77a46d6de13749e12eff40f5a7e649167ccb", + }, + { + "private": "d5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a", + "public": "66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04", + "salt": "92f55ba5bc6fc2f23e3eedc299357c71518e36ba2447a4da7a9dfe9dfeb107b5", + "iv": "1cbc4982e53e370052af97ab088fa942", + "input": "86ddb9e713a8ebf67a51830eff03b837e147c20d75e67b2a54aa29e98c", + "output": "d48ef1ef526d805656cfc932aff259eadb17aa3391dde1877a722cba31d935b2", + }, + { + "private": "d5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a", + "public": "66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04", + "salt": "10f15a39ba49866292a43b7781bc71ca8bbd4889f1616461caf056bcb91b0158", + "iv": "c40d531d92bfee969dce91417346c892", + "input": "49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4", + "output": "e6d75afdb542785669b42198577c5b358d95397d71ec6f5835dca46d332cc08dbf73ea790b7bcb169a65719c0d55054c", + }, + { + "private": "d5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a", + "public": "66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04", + "salt": "9c01ed42b219b3bbe1a43ae9d7af5c1dd09363baacfdba8f4d03d1046915e26e", + "iv": "059a35d5f83249e632790015ed6518b9", + "input": "49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4", + "output": "5ef11aadff2eccee8b712dab968fa842eb770818ec0e6663ed242ea8b6bbc1c66d6285ee5b5f03d55dfee382fb4fa25d", + }, + { + "private": "d5c0762ecea2cd6b5c56751b58debcb32713aab348f4a59c493e38beb3244f3a", + "public": "66a35941d615b5644d19c2a602c363ada8b1a8a0dac3682623852dcab4afac04", + "salt": "bc1067e2a7415ea45ff1ca9894338c591ff15f2e57ae2789ae31b9d5bea0f11e", + "iv": "8c73f0d6613898daeefa3cf8b0686d37", + "input": "49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4", + "output": "6d220213b1878cd40a458f2a1e6e3b48040455fdf504dcd857f4f2ca1ad642e3a44fc401d04e339d302f66a9fad3d919", + }, + { + "private": "9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921", + "public": "441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094", + "salt": "cf4a21cb790552165827b678ca9695fcaf77566d382325112ff79483455de667", + "iv": "bfbf5482e06f55b88bdd9e053b7eee6e", + "input": "49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4", + "output": "1198a78c29c215d5c450f7b8513ead253160bc9fde80d9cc8e6bee2efe9713cf5a09d6293c41033271c9e8c22036a28b", + }, + { + "private": "9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921", + "public": "441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094", + "salt": "eba5eae8aef79114082c3e70baef95bb02edf13b3897e8be7a70272962ef8838", + "iv": "af9a56da3da18e2fbd2948a16332532b", + "input": "49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4", + "output": "1062ab5fbbdee9042ad35bdadfd3047c0a2127fe0f001da1be1b0582185edfc9687be8d68f85795833bb04af9cedd3bb", + }, + { + "private": "9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921", + "public": "441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094", + "salt": "518f8dfd0c138f1ffb4ea8029db15441d70abd893c3d767dc668f23ba7770e27", + "iv": "42d28307974a1b2a2d921d270cfce03b", + "input": "49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4", + "output": "005e49fb7c5da540a84b034c853fc9f78a6b901ea495aed0c2abd4f08f1a96f9ffefc6a57f1ac09e0aea95ca0f03ffd8", + }, + { + "private": "9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921", + "public": "441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094", + "salt": "582fdf58b53715c26e10ba809e8f2ab70502e5a3d4e9a81100b7227732ab0bbc", + "iv": "91f2aad3189bb2edc93bc891e73911ba", + "input": "49de3cd5890e0cd0559f143807ff688ff62789b7236a332b7d7255ec0b4e73e6b3a4", + "output": "821a69cb16c57f0cb866e590b38069e35faec3ae18f158bb067db83a11237d29ab1e6b868b3147236a0958f15c2e2167", + }, + { + "private": "9ef87ba8aa2e664bdfdb978b98bc30fb61773d9298e7b8c72911683eeff41921", + "public": "441e76d7e53be0a967181076a842f69c20fd8c0e3f0ce3aa421b490b059fe094", + "salt": "a415b4c006118fb72fc37b2746ef288e23ac45c8ff7ade5f368a31557b6ac93a", + "iv": "2b7c5f75606c0b8106c6489ea5657a9e", + "input": "24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85", + "output": "2781d5ee8ef1cb1596f8902b33dfae5045f84a987ca58173af5830dbce386062", + }, + { + "private": "ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc", + "public": "5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541", + "salt": "47e73ec362ea82d3a7c5d55532ad51d2cdf5316b981b2b2bd542b0efa027e8ea", + "iv": "b2193f59030c8d05a7d3577b7f64dd33", + "input": "24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85", + "output": "3f43912db8dd6672b9996e5272e18c4b88fec9d7e8372db9c5f4709a4af1d86f", + }, + { + "private": "ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc", + "public": "5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541", + "salt": "aaa006c57b6d1e402650577fe9787d8d285f4bacd7c01f998be49c766f8860c7", + "iv": "130304ddb9adc8870cf56bcae9487b7f", + "input": "24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85", + "output": "878cc7d8c0ef8dac0182a78eedc8080a402f59d8062a6b4ca8f4a74f3c3b3de7", + }, + { + "private": "ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc", + "public": "5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541", + "salt": "28dc7ccd6c2a939eef64b8be7b9ae248295e7fcd8471c22fa2f98733fea97611", + "iv": "cb13890d3a11bc0a7433738263006710", + "input": "24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85", + "output": "e74ded846bebfa912fa1720e4c1415e6e5df7e7a1a7fedb5665d68f1763209a4", + }, + { + "private": "ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc", + "public": "5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541", + "salt": "79974fa2cad95154d0873902c153ccc3e7d54b17f2eeb3f29b6344cad9365a9a", + "iv": "22123357979d20f44cc8eb0263d84e0e", + "input": "24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85", + "output": "eb14dec7b8b64d81a2ee4db07b0adf144d4f79a519bbf332b823583fa2d45405", + }, + { + "private": "ed93c5a101ab53382ceee4f7e6b5aa112621d3bb9d18891509b1834ede235bcc", + "public": "5a5e14c633d7d269302849d739d80344ff14db51d7bcda86045723f05c4e4541", + "salt": "3409a6f8c4dcd9bd04144eb67e55a98696b674735b01bf1196191f29871ef966", + "iv": "a823a0965969380ea1f8659ea5fd8fdd", + "input": "24512b714aefd5cbc4bcc4ef44ce6c67ffc447c65460a6c6e4a92e85", + "output": "00a7eb708eae745847173f8217efb05be13059710aee632e3f471ac3c6202b51", + }, ] for test in test_cases: - private_key = bytearray(reversed(unhexlify(test['private']))) + private_key = bytearray(reversed(unhexlify(test["private"]))) node = bip32.HDNode( depth=0, fingerprint=0, child_num=0, chain_code=bytearray(32), private_key=private_key, - curve_name=CURVE + curve_name=CURVE, ) - encrypted = node.nem_encrypt(unhexlify(test['public']), - unhexlify(test['iv']), - unhexlify(test['salt']), - unhexlify(test['input'])) + encrypted = node.nem_encrypt( + unhexlify(test["public"]), + unhexlify(test["iv"]), + unhexlify(test["salt"]), + unhexlify(test["input"]), + ) - self.assertEqual(encrypted, unhexlify(test['output'])) + self.assertEqual(encrypted, unhexlify(test["output"])) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.nem.mosaic.py b/core/tests/test_apps.nem.mosaic.py index fc26af9ae0..c63b5fd5de 100644 --- a/core/tests/test_apps.nem.mosaic.py +++ b/core/tests/test_apps.nem.mosaic.py @@ -23,7 +23,6 @@ def sort_mosaics(mosaics: list[NEMMosaic]) -> list[NEMMosaic]: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMosaic(unittest.TestCase): - def test_get_mosaic_definition(self): m = get_mosaic_definition("nem", "xem", 104) self.assertEqual(m.name, "NEM") diff --git a/core/tests/test_apps.nem.mosaic_creation.py b/core/tests/test_apps.nem.mosaic_creation.py index f4833d1351..f69a50502d 100644 --- a/core/tests/test_apps.nem.mosaic_creation.py +++ b/core/tests/test_apps.nem.mosaic_creation.py @@ -3,7 +3,12 @@ from common import * from trezor.crypto import hashlib if not utils.BITCOIN_ONLY: - from trezor.messages import NEMSignTx, NEMMosaicCreation, NEMMosaicDefinition, NEMTransactionCommon + from trezor.messages import ( + NEMSignTx, + NEMMosaicCreation, + NEMMosaicDefinition, + NEMTransactionCommon, + ) from apps.nem.helpers import * from apps.nem.mosaic import * from apps.nem.mosaic.serialize import * @@ -11,118 +16,199 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMosaicCreation(unittest.TestCase): - def test_nem_transaction_mosaic_creation(self): # http://bob.nem.ninja:8765/#/mosaic/68364353c29105e6d361ad1a42abbccbf419cfc7adb8b74c8f35d8f8bdaca3fa/0 - m = _create_msg(NEM_NETWORK_TESTNET, - 14070896, - 108000000, - 14074496, - 'gimre.games.pong', - 'paddles', - 'Paddles for the bong game.\n', - 0, - 10000, - True, - True, - 0, - 0, - '', - '', - '', - 'TBMOSAICOD4F54EE5CDMR23CCBGOAM2XSJBR5OLC', - 50000000000) + m = _create_msg( + NEM_NETWORK_TESTNET, + 14070896, + 108000000, + 14074496, + "gimre.games.pong", + "paddles", + "Paddles for the bong game.\n", + 0, + 10000, + True, + True, + 0, + 0, + "", + "", + "", + "TBMOSAICOD4F54EE5CDMR23CCBGOAM2XSJBR5OLC", + 50000000000, + ) - t = serialize_mosaic_creation(m.transaction, m.mosaic_creation, unhexlify('994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324')) + t = serialize_mosaic_creation( + m.transaction, + m.mosaic_creation, + unhexlify( + "994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324" + ), + ) - self.assertEqual(t, unhexlify('014000000100009870b4d60020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd32400f36f060000000080c2d600de00000020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd3241f0000001000000067696d72652e67616d65732e706f6e6707000000706164646c65731b000000506164646c657320666f722074686520626f6e672067616d652e0a04000000150000000c00000064697669736962696c69747901000000301a0000000d000000696e697469616c537570706c79050000003130303030190000000d000000737570706c794d757461626c650400000074727565180000000c0000007472616e7366657261626c650400000074727565000000002800000054424d4f534149434f443446353445453543444d523233434342474f414d3258534a4252354f4c4300743ba40b000000')) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('68364353c29105e6d361ad1a42abbccbf419cfc7adb8b74c8f35d8f8bdaca3fa')) + self.assertEqual( + t, + unhexlify( + "014000000100009870b4d60020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd32400f36f060000000080c2d600de00000020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd3241f0000001000000067696d72652e67616d65732e706f6e6707000000706164646c65731b000000506164646c657320666f722074686520626f6e672067616d652e0a04000000150000000c00000064697669736962696c69747901000000301a0000000d000000696e697469616c537570706c79050000003130303030190000000d000000737570706c794d757461626c650400000074727565180000000c0000007472616e7366657261626c650400000074727565000000002800000054424d4f534149434f443446353445453543444d523233434342474f414d3258534a4252354f4c4300743ba40b000000" + ), + ) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "68364353c29105e6d361ad1a42abbccbf419cfc7adb8b74c8f35d8f8bdaca3fa" + ), + ) def test_nem_transaction_mosaic_creation_with_levy(self): # http://bob.nem.ninja:8765/#/mosaic/b2f4a98113ff1f3a8f1e9d7197aa982545297fe0aa3fa6094af8031569953a55/0 - m = _create_msg(NEM_NETWORK_TESTNET, - 21497248, - 108000000, - 21500848, - "alice.misc", - "bar", - "Special offer: get one bar extra by bying one foo!", - 0, - 1000, - False, - True, - 1, - 1, - "TALICE2GMA34CXHD7XLJQ536NM5UNKQHTORNNT2J", - "nem", - "xem", - "TBMOSAICOD4F54EE5CDMR23CCBGOAM2XSJBR5OLC", - 50000000000) + m = _create_msg( + NEM_NETWORK_TESTNET, + 21497248, + 108000000, + 21500848, + "alice.misc", + "bar", + "Special offer: get one bar extra by bying one foo!", + 0, + 1000, + False, + True, + 1, + 1, + "TALICE2GMA34CXHD7XLJQ536NM5UNKQHTORNNT2J", + "nem", + "xem", + "TBMOSAICOD4F54EE5CDMR23CCBGOAM2XSJBR5OLC", + 50000000000, + ) - t = serialize_mosaic_creation(m.transaction, m.mosaic_creation, unhexlify("244fa194e2509ac0d2fbc18779c2618d8c2ebb61c16a3bcbebcf448c661ba8dc"),) + t = serialize_mosaic_creation( + m.transaction, + m.mosaic_creation, + unhexlify( + "244fa194e2509ac0d2fbc18779c2618d8c2ebb61c16a3bcbebcf448c661ba8dc" + ), + ) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('b2f4a98113ff1f3a8f1e9d7197aa982545297fe0aa3fa6094af8031569953a55')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "b2f4a98113ff1f3a8f1e9d7197aa982545297fe0aa3fa6094af8031569953a55" + ), + ) # http://chain.nem.ninja/#/mosaic/e8dc14821dbea4831d9051f86158ef348001447968fc22c01644fdaf2bda75c6/0 - m = _create_msg(NEM_NETWORK_MAINNET, - 69251020, - 20000000, - 69337420, - "dim", - "coin", - "DIM COIN", - 6, - 9000000000, - False, - True, - 2, - 10, - "NCGGLVO2G3CUACVI5GNX2KRBJSQCN4RDL2ZWJ4DP", - "dim", - "coin", - "NBMOSAICOD4F54EE5CDMR23CCBGOAM2XSIUX6TRS", - 500000000) + m = _create_msg( + NEM_NETWORK_MAINNET, + 69251020, + 20000000, + 69337420, + "dim", + "coin", + "DIM COIN", + 6, + 9000000000, + False, + True, + 2, + 10, + "NCGGLVO2G3CUACVI5GNX2KRBJSQCN4RDL2ZWJ4DP", + "dim", + "coin", + "NBMOSAICOD4F54EE5CDMR23CCBGOAM2XSIUX6TRS", + 500000000, + ) - t = serialize_mosaic_creation(m.transaction, m.mosaic_creation, unhexlify("a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a")) - self.assertEqual(t, unhexlify('0140000001000068ccaf200420000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a002d3101000000004c0122040c01000020000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a0f0000000300000064696d04000000636f696e0800000044494d20434f494e04000000150000000c00000064697669736962696c69747901000000361f0000000d000000696e697469616c537570706c790a000000393030303030303030301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c6504000000747275654b00000002000000280000004e4347474c564f32473343554143564935474e58324b52424a5351434e3452444c325a574a3444500f0000000300000064696d04000000636f696e0a00000000000000280000004e424d4f534149434f443446353445453543444d523233434342474f414d325853495558365452530065cd1d00000000')) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('e8dc14821dbea4831d9051f86158ef348001447968fc22c01644fdaf2bda75c6')) + t = serialize_mosaic_creation( + m.transaction, + m.mosaic_creation, + unhexlify( + "a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a" + ), + ) + self.assertEqual( + t, + unhexlify( + "0140000001000068ccaf200420000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a002d3101000000004c0122040c01000020000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a0f0000000300000064696d04000000636f696e0800000044494d20434f494e04000000150000000c00000064697669736962696c69747901000000361f0000000d000000696e697469616c537570706c790a000000393030303030303030301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c6504000000747275654b00000002000000280000004e4347474c564f32473343554143564935474e58324b52424a5351434e3452444c325a574a3444500f0000000300000064696d04000000636f696e0a00000000000000280000004e424d4f534149434f443446353445453543444d523233434342474f414d325853495558365452530065cd1d00000000" + ), + ) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "e8dc14821dbea4831d9051f86158ef348001447968fc22c01644fdaf2bda75c6" + ), + ) def test_nem_transaction_mosaic_creation_with_description(self): # http://chain.nem.ninja/#/mosaic/269c6fda657aba3053a0e5b138c075808cc20e244e1182d9b730798b60a1f77b/0 - m = _create_msg(NEM_NETWORK_MAINNET, - 26729938, - 108000000, - 26733538, - "jabo38", - "red_token", - "This token is to celebrate the release of Namespaces and Mosaics " - "on the NEM system. This token was the fist ever mosaic created " - "other than nem.xem. There are only 10,000 Red Tokens that will " - "ever be created. It has no levy and can be traded freely among " - "third parties.", - 2, - 10000, - False, - True, - 0, - 0, - "", - "", - "", - "NBMOSAICOD4F54EE5CDMR23CCBGOAM2XSIUX6TRS", - 50000000000) - t = serialize_mosaic_creation(m.transaction, m.mosaic_creation, unhexlify("58956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f23")) + m = _create_msg( + NEM_NETWORK_MAINNET, + 26729938, + 108000000, + 26733538, + "jabo38", + "red_token", + "This token is to celebrate the release of Namespaces and Mosaics " + "on the NEM system. This token was the fist ever mosaic created " + "other than nem.xem. There are only 10,000 Red Tokens that will " + "ever be created. It has no levy and can be traded freely among " + "third parties.", + 2, + 10000, + False, + True, + 0, + 0, + "", + "", + "", + "NBMOSAICOD4F54EE5CDMR23CCBGOAM2XSIUX6TRS", + 50000000000, + ) + t = serialize_mosaic_creation( + m.transaction, + m.mosaic_creation, + unhexlify( + "58956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f23" + ), + ) - self.assertEqual(t, unhexlify('0140000001000068d2dd97012000000058956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f2300f36f0600000000e2eb9701c80100002000000058956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f2317000000060000006a61626f3338090000007265645f746f6b656e0c0100005468697320746f6b656e20697320746f2063656c656272617465207468652072656c65617365206f66204e616d6573706163657320616e64204d6f7361696373206f6e20746865204e454d2073797374656d2e205468697320746f6b656e207761732074686520666973742065766572206d6f736169632063726561746564206f74686572207468616e206e656d2e78656d2e20546865726520617265206f6e6c792031302c3030302052656420546f6b656e7320746861742077696c6c206576657220626520637265617465642e20497420686173206e6f206c65767920616e642063616e2062652074726164656420667265656c7920616d6f6e6720746869726420706172746965732e04000000150000000c00000064697669736962696c69747901000000321a0000000d000000696e697469616c537570706c790500000031303030301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c65040000007472756500000000280000004e424d4f534149434f443446353445453543444d523233434342474f414d3258534955583654525300743ba40b000000')) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('269c6fda657aba3053a0e5b138c075808cc20e244e1182d9b730798b60a1f77b')) + self.assertEqual( + t, + unhexlify( + "0140000001000068d2dd97012000000058956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f2300f36f0600000000e2eb9701c80100002000000058956ac77951622dc5f1c938affbf017c458e30e6b21ddb5783d38b302531f2317000000060000006a61626f3338090000007265645f746f6b656e0c0100005468697320746f6b656e20697320746f2063656c656272617465207468652072656c65617365206f66204e616d6573706163657320616e64204d6f7361696373206f6e20746865204e454d2073797374656d2e205468697320746f6b656e207761732074686520666973742065766572206d6f736169632063726561746564206f74686572207468616e206e656d2e78656d2e20546865726520617265206f6e6c792031302c3030302052656420546f6b656e7320746861742077696c6c206576657220626520637265617465642e20497420686173206e6f206c65767920616e642063616e2062652074726164656420667265656c7920616d6f6e6720746869726420706172746965732e04000000150000000c00000064697669736962696c69747901000000321a0000000d000000696e697469616c537570706c790500000031303030301a0000000d000000737570706c794d757461626c650500000066616c7365180000000c0000007472616e7366657261626c65040000007472756500000000280000004e424d4f534149434f443446353445453543444d523233434342474f414d3258534955583654525300743ba40b000000" + ), + ) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "269c6fda657aba3053a0e5b138c075808cc20e244e1182d9b730798b60a1f77b" + ), + ) -def _create_msg(network: int, timestamp: int, fee: int, deadline: int, - namespace: str, mosaic: str, description: str, - divisibility: int, supply: int, mutable_supply: bool, transferable: bool, - levy_type: int, levy_fee: int, levy_address: str, levy_namespace: str, - levy_mosaic: str, creation_sink: str, creation_fee: int): +def _create_msg( + network: int, + timestamp: int, + fee: int, + deadline: int, + namespace: str, + mosaic: str, + description: str, + divisibility: int, + supply: int, + mutable_supply: bool, + transferable: bool, + levy_type: int, + levy_fee: int, + levy_address: str, + levy_namespace: str, + levy_mosaic: str, + creation_sink: str, + creation_fee: int, +): transaction = NEMTransactionCommon( network=network, timestamp=timestamp, @@ -146,7 +232,7 @@ def _create_msg(network: int, timestamp: int, fee: int, deadline: int, levy_address=levy_address, levy_namespace=levy_namespace, levy_mosaic=levy_mosaic, - ) + ), ) return NEMSignTx( @@ -155,5 +241,5 @@ def _create_msg(network: int, timestamp: int, fee: int, deadline: int, ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.nem.mosaic_supply_change.py b/core/tests/test_apps.nem.mosaic_supply_change.py index b179f34b0a..2debd0319d 100644 --- a/core/tests/test_apps.nem.mosaic_supply_change.py +++ b/core/tests/test_apps.nem.mosaic_supply_change.py @@ -8,70 +8,119 @@ if not utils.BITCOIN_ONLY: from apps.nem.mosaic.serialize import * from trezor.messages import NEMSignTx, NEMMosaicSupplyChange, NEMTransactionCommon + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMosaicSupplyChange(unittest.TestCase): - def test_nem_transaction_create_mosaic_supply_change(self): # http://bigalice2.nem.ninja:7890/transaction/get?hash=33a50fdd4a54913643a580b2af08b9a5b51b7cee922bde380e84c573a7969c50 - m = _create_msg(NEM_NETWORK_TESTNET, - 14071648, - 108000000, - 14075248, - "gimre.games.pong", - "paddles", - 1, - 1234) - t = serialize_mosaic_supply_change(m.transaction, m.supply_change, unhexlify("994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324")) + m = _create_msg( + NEM_NETWORK_TESTNET, + 14071648, + 108000000, + 14075248, + "gimre.games.pong", + "paddles", + 1, + 1234, + ) + t = serialize_mosaic_supply_change( + m.transaction, + m.supply_change, + unhexlify( + "994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324" + ), + ) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), - unhexlify('33a50fdd4a54913643a580b2af08b9a5b51b7cee922bde380e84c573a7969c50')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "33a50fdd4a54913643a580b2af08b9a5b51b7cee922bde380e84c573a7969c50" + ), + ) # http://bigalice2.nem.ninja:7890/transaction/get?hash=1ce8e8894d077a66ff22294b000825d090a60742ec407efd80eb8b19657704f2 - m = _create_msg(NEM_NETWORK_TESTNET, - 14126909, - 108000000, - 14130509, - "jabo38_ltd.fuzzy_kittens_cafe", - "coupons", - 2, - 1) - t = serialize_mosaic_supply_change(m.transaction, m.supply_change, unhexlify("84afa1bbc993b7f5536344914dde86141e61f8cbecaf8c9cefc07391f3287cf5")) + m = _create_msg( + NEM_NETWORK_TESTNET, + 14126909, + 108000000, + 14130509, + "jabo38_ltd.fuzzy_kittens_cafe", + "coupons", + 2, + 1, + ) + t = serialize_mosaic_supply_change( + m.transaction, + m.supply_change, + unhexlify( + "84afa1bbc993b7f5536344914dde86141e61f8cbecaf8c9cefc07391f3287cf5" + ), + ) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), - unhexlify('1ce8e8894d077a66ff22294b000825d090a60742ec407efd80eb8b19657704f2')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "1ce8e8894d077a66ff22294b000825d090a60742ec407efd80eb8b19657704f2" + ), + ) # http://bigalice3.nem.ninja:7890/transaction/get?hash=694e493e9576d2bcf60d85747e302ac2e1cc27783187947180d4275a713ff1ff - m = _create_msg(NEM_NETWORK_MAINNET, - 53377685, - 20000000, - 53464085, - "abvapp", - "abv", - 1, - 9000000) - t = serialize_mosaic_supply_change(m.transaction, m.supply_change, unhexlify("b7ccc27b21ba6cf5c699a8dc86ba6ba98950442597ff9fa30e0abe0f5f4dd05d")) + m = _create_msg( + NEM_NETWORK_MAINNET, + 53377685, + 20000000, + 53464085, + "abvapp", + "abv", + 1, + 9000000, + ) + t = serialize_mosaic_supply_change( + m.transaction, + m.supply_change, + unhexlify( + "b7ccc27b21ba6cf5c699a8dc86ba6ba98950442597ff9fa30e0abe0f5f4dd05d" + ), + ) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), - unhexlify('694e493e9576d2bcf60d85747e302ac2e1cc27783187947180d4275a713ff1ff')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "694e493e9576d2bcf60d85747e302ac2e1cc27783187947180d4275a713ff1ff" + ), + ) # http://bigalice3.nem.ninja:7890/transaction/get?hash=09836334e123970e068d5b411e4d1df54a3ead10acf1ad5935a2cdd9f9680185 - m = _create_msg(NEM_NETWORK_MAINNET, - 55176304, - 20000000, - 55262704, - "sushi", - "wasabi", - 2, - 20) - t = serialize_mosaic_supply_change(m.transaction, m.supply_change, unhexlify("75f001a8641e2ce5c4386883dda561399ed346177411b492a677b73899502f13")) + m = _create_msg( + NEM_NETWORK_MAINNET, 55176304, 20000000, 55262704, "sushi", "wasabi", 2, 20 + ) + t = serialize_mosaic_supply_change( + m.transaction, + m.supply_change, + unhexlify( + "75f001a8641e2ce5c4386883dda561399ed346177411b492a677b73899502f13" + ), + ) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), - unhexlify('09836334e123970e068d5b411e4d1df54a3ead10acf1ad5935a2cdd9f9680185')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "09836334e123970e068d5b411e4d1df54a3ead10acf1ad5935a2cdd9f9680185" + ), + ) -def _create_msg(network: int, timestamp: int, fee: int, deadline: int, - namespace: str, mosaic: str, mod_type: int, delta: int): +def _create_msg( + network: int, + timestamp: int, + fee: int, + deadline: int, + namespace: str, + mosaic: str, + mod_type: int, + delta: int, +): transaction = NEMTransactionCommon( network=network, timestamp=timestamp, @@ -92,5 +141,5 @@ def _create_msg(network: int, timestamp: int, fee: int, deadline: int, ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.nem.multisig.aggregate_modification.py b/core/tests/test_apps.nem.multisig.aggregate_modification.py index a89311c6a5..e9384620c5 100644 --- a/core/tests/test_apps.nem.multisig.aggregate_modification.py +++ b/core/tests/test_apps.nem.multisig.aggregate_modification.py @@ -164,8 +164,11 @@ def _create_msg( ) aggregate_modification = NEMAggregateModification( - modifications=[NEMCosignatoryModification(type=5, public_key=b"abc") for _ in range(modifications)], - relative_change=relative_change + modifications=[ + NEMCosignatoryModification(type=5, public_key=b"abc") + for _ in range(modifications) + ], + relative_change=relative_change, ) return NEMSignTx( diff --git a/core/tests/test_apps.nem.multisig.py b/core/tests/test_apps.nem.multisig.py index 07f9b41724..c6e0323b7d 100644 --- a/core/tests/test_apps.nem.multisig.py +++ b/core/tests/test_apps.nem.multisig.py @@ -6,73 +6,141 @@ if not utils.BITCOIN_ONLY: from apps.nem.multisig.serialize import * from apps.nem.namespace import * from apps.nem.namespace.serialize import * - from trezor.messages import NEMSignTx, NEMAggregateModification, NEMProvisionNamespace, NEMCosignatoryModification, NEMTransactionCommon + from trezor.messages import ( + NEMSignTx, + NEMAggregateModification, + NEMProvisionNamespace, + NEMCosignatoryModification, + NEMTransactionCommon, + ) + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemMultisig(unittest.TestCase): - def test_nem_multisig(self): # http://bob.nem.ninja:8765/#/multisig/7d3a7087023ee29005262016706818579a2b5499eb9ca76bad98c1e6f4c46642 - m = _create_msg(NEM_NETWORK_TESTNET, - 3939039, - 16000000, - 3960639, - 1, - 0) - base_tx = serialize_aggregate_modification(m.transaction, m.aggregate_modification, unhexlify("abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac")) + m = _create_msg(NEM_NETWORK_TESTNET, 3939039, 16000000, 3960639, 1, 0) + base_tx = serialize_aggregate_modification( + m.transaction, + m.aggregate_modification, + unhexlify( + "abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac" + ), + ) - write_cosignatory_modification(base_tx, 2, unhexlify("e6cff9b3725a91f31089c3acca0fac3e341c00b1c8c6e9578f66c4514509c3b3")) - m = _create_common_msg(NEM_NETWORK_TESTNET, - 3939039, - 6000000, - 3960639) - multisig = serialize_multisig(m, unhexlify("59d89076964742ef2a2089d26a5aa1d2c7a7bb052a46c1de159891e91ad3d76e"), base_tx) + write_cosignatory_modification( + base_tx, + 2, + unhexlify( + "e6cff9b3725a91f31089c3acca0fac3e341c00b1c8c6e9578f66c4514509c3b3" + ), + ) + m = _create_common_msg(NEM_NETWORK_TESTNET, 3939039, 6000000, 3960639) + multisig = serialize_multisig( + m, + unhexlify( + "59d89076964742ef2a2089d26a5aa1d2c7a7bb052a46c1de159891e91ad3d76e" + ), + base_tx, + ) - self.assertEqual(multisig, unhexlify("0410000001000098df1a3c002000000059d89076964742ef2a2089d26a5aa1d2c7a7bb052a46c1de159891e91ad3d76e808d5b00000000003f6f3c006c0000000110000001000098df1a3c0020000000abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac0024f400000000003f6f3c0001000000280000000200000020000000e6cff9b3725a91f31089c3acca0fac3e341c00b1c8c6e9578f66c4514509c3b3")) + self.assertEqual( + multisig, + unhexlify( + "0410000001000098df1a3c002000000059d89076964742ef2a2089d26a5aa1d2c7a7bb052a46c1de159891e91ad3d76e808d5b00000000003f6f3c006c0000000110000001000098df1a3c0020000000abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac0024f400000000003f6f3c0001000000280000000200000020000000e6cff9b3725a91f31089c3acca0fac3e341c00b1c8c6e9578f66c4514509c3b3" + ), + ) - address_pubkey = unhexlify("abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac") - m = _create_common_msg(NEM_NETWORK_TESTNET, - 3939891, - 6000000, - 3961491) - multisig = serialize_multisig_signature(m, unhexlify("71cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4"), base_tx, address_pubkey) + address_pubkey = unhexlify( + "abac2ee3d4aaa7a3bfb65261a00cc04c761521527dd3f2cf741e2815cbba83ac" + ) + m = _create_common_msg(NEM_NETWORK_TESTNET, 3939891, 6000000, 3961491) + multisig = serialize_multisig_signature( + m, + unhexlify( + "71cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4" + ), + base_tx, + address_pubkey, + ) - self.assertEqual(multisig, unhexlify("0210000001000098331e3c002000000071cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4808d5b000000000093723c0024000000200000008ec165580bdabfd31ce6007a1748ce5bdf30eab7a214743097de3bc822ac7e002800000054435258595551494d464137414f474c354c463359574c43375641424c59554d4a35414342554e4c")) + self.assertEqual( + multisig, + unhexlify( + "0210000001000098331e3c002000000071cba4f2a28fd19f902ba40e9937994154d9eeaad0631d25d525ec37922567d4808d5b000000000093723c0024000000200000008ec165580bdabfd31ce6007a1748ce5bdf30eab7a214743097de3bc822ac7e002800000054435258595551494d464137414f474c354c463359574c43375641424c59554d4a35414342554e4c" + ), + ) def test_nem_multisig_2(self): # http://chain.nem.ninja/#/multisig/1016cf3bdd61bd57b9b2b07b6ff2dee390279d8d899265bdc23d42360abe2e6c - m = _create_provision_msg(NEM_NETWORK_MAINNET, - 59414272, - 20000000, - 59500672, - "dim", - "", - "NAMESPACEWH4MKFMBCVFERDPOOP4FK7MTBXDPZZA", - 5000000000) - base_tx = serialize_provision_namespace(m.transaction, m.provision_namespace, unhexlify("a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a")) + m = _create_provision_msg( + NEM_NETWORK_MAINNET, + 59414272, + 20000000, + 59500672, + "dim", + "", + "NAMESPACEWH4MKFMBCVFERDPOOP4FK7MTBXDPZZA", + 5000000000, + ) + base_tx = serialize_provision_namespace( + m.transaction, + m.provision_namespace, + unhexlify( + "a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a" + ), + ) - m = _create_common_msg(NEM_NETWORK_MAINNET, - 59414272, - 6000000, - 59500672) + m = _create_common_msg(NEM_NETWORK_MAINNET, 59414272, 6000000, 59500672) - multisig = serialize_multisig(m, unhexlify("cfe58463f0eaebceb5d00717f8aead49171a5d7c08f6b1299bd534f11715acc9"), base_tx) - self.assertEqual(multisig, unhexlify("041000000100006800978a0320000000cfe58463f0eaebceb5d00717f8aead49171a5d7c08f6b1299bd534f11715acc9808d5b000000000080e88b037b000000012000000100006800978a0320000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a002d31010000000080e88b03280000004e414d4553504143455748344d4b464d42435646455244504f4f5034464b374d54425844505a5a4100f2052a010000000300000064696dffffffff")) + multisig = serialize_multisig( + m, + unhexlify( + "cfe58463f0eaebceb5d00717f8aead49171a5d7c08f6b1299bd534f11715acc9" + ), + base_tx, + ) + self.assertEqual( + multisig, + unhexlify( + "041000000100006800978a0320000000cfe58463f0eaebceb5d00717f8aead49171a5d7c08f6b1299bd534f11715acc9808d5b000000000080e88b037b000000012000000100006800978a0320000000a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a002d31010000000080e88b03280000004e414d4553504143455748344d4b464d42435646455244504f4f5034464b374d54425844505a5a4100f2052a010000000300000064696dffffffff" + ), + ) - m = _create_common_msg(NEM_NETWORK_MAINNET, - 59414342, - 6000000, - 59500742) - address_pubkey = unhexlify("a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a") - multisig = serialize_multisig_signature(m, unhexlify("1b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2"), base_tx, address_pubkey) - self.assertEqual(multisig, unhexlify("021000000100006846978a03200000001b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2808d5b0000000000c6e88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56")) + m = _create_common_msg(NEM_NETWORK_MAINNET, 59414342, 6000000, 59500742) + address_pubkey = unhexlify( + "a1df5306355766bd2f9a64efdc089eb294be265987b3359093ae474c051d7d5a" + ) + multisig = serialize_multisig_signature( + m, + unhexlify( + "1b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2" + ), + base_tx, + address_pubkey, + ) + self.assertEqual( + multisig, + unhexlify( + "021000000100006846978a03200000001b49b80203007117d034e45234ffcdf402c044aeef6dbb06351f346ca892bce2808d5b0000000000c6e88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56" + ), + ) - m = _create_common_msg(NEM_NETWORK_MAINNET, - 59414381, - 6000000, - 59500781) - multisig = serialize_multisig_signature(m, unhexlify("7ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87"), base_tx, address_pubkey) - self.assertEqual(multisig, unhexlify("02100000010000686d978a03200000007ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87808d5b0000000000ede88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56")) + m = _create_common_msg(NEM_NETWORK_MAINNET, 59414381, 6000000, 59500781) + multisig = serialize_multisig_signature( + m, + unhexlify( + "7ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87" + ), + base_tx, + address_pubkey, + ) + self.assertEqual( + multisig, + unhexlify( + "02100000010000686d978a03200000007ba4b39209f1b9846b098fe43f74381e43cb2882ccde780f558a63355840aa87808d5b0000000000ede88b032400000020000000bfa2088f7720f89dd4664d650e321dabd02fab61b7355bc88a391a848a49786a280000004e4444524733554542354c5a5a5a4d445742453452544b5a4b37334a424850414957424843464d56" + ), + ) def _create_common_msg(network: int, timestamp: int, fee: int, deadline: int): @@ -84,11 +152,20 @@ def _create_common_msg(network: int, timestamp: int, fee: int, deadline: int): ) -def _create_msg(network: int, timestamp: int, fee: int, deadline: int, - modifications: int, relative_change: int): +def _create_msg( + network: int, + timestamp: int, + fee: int, + deadline: int, + modifications: int, + relative_change: int, +): aggregate_modification = NEMAggregateModification( - modifications=[NEMCosignatoryModification(type=5, public_key=b"abc") for _ in range(modifications)], - relative_change=relative_change + modifications=[ + NEMCosignatoryModification(type=5, public_key=b"abc") + for _ in range(modifications) + ], + relative_change=relative_change, ) return NEMSignTx( @@ -97,8 +174,16 @@ def _create_msg(network: int, timestamp: int, fee: int, deadline: int, ) -def _create_provision_msg(network: int, timestamp: int, fee: int, deadline: int, - name: str, parent: str, sink: str, rental_fee: int): +def _create_provision_msg( + network: int, + timestamp: int, + fee: int, + deadline: int, + name: str, + parent: str, + sink: str, + rental_fee: int, +): provision_namespace = NEMProvisionNamespace( namespace=name, parent=parent, @@ -112,6 +197,5 @@ def _create_provision_msg(network: int, timestamp: int, fee: int, deadline: int, ) - -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.nem.namespace.py b/core/tests/test_apps.nem.namespace.py index bcfa72c5be..8e78c61f73 100644 --- a/core/tests/test_apps.nem.namespace.py +++ b/core/tests/test_apps.nem.namespace.py @@ -12,50 +12,96 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemNamespace(unittest.TestCase): - def test_create_provision_namespace(self): # http://bob.nem.ninja:8765/#/transfer/0acbf8df91e6a65dc56c56c43d65f31ff2a6a48d06fc66e78c7f3436faf3e74f - m = _create_msg(NEM_NETWORK_TESTNET, - 56999445, - 20000000, - 57003045, - 'gimre', - '', - 'TAMESPACEWH4MKFMBCVFERDPOOP4FK7MTDJEYP35', - 5000000000) - t = serialize_provision_namespace(m.transaction, m.provision_namespace, unhexlify('84afa1bbc993b7f5536344914dde86141e61f8cbecaf8c9cefc07391f3287cf5')) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('f7cab28da57204d01a907c697836577a4ae755e6c9bac60dcc318494a22debb3')) + m = _create_msg( + NEM_NETWORK_TESTNET, + 56999445, + 20000000, + 57003045, + "gimre", + "", + "TAMESPACEWH4MKFMBCVFERDPOOP4FK7MTDJEYP35", + 5000000000, + ) + t = serialize_provision_namespace( + m.transaction, + m.provision_namespace, + unhexlify( + "84afa1bbc993b7f5536344914dde86141e61f8cbecaf8c9cefc07391f3287cf5" + ), + ) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "f7cab28da57204d01a907c697836577a4ae755e6c9bac60dcc318494a22debb3" + ), + ) # http://bob.nem.ninja:8765/#/namespace/7ddd5fe607e1bfb5606e0ac576024c318c8300d237273117d4db32a60c49524d - m = _create_msg(NEM_NETWORK_TESTNET, - 21496797, - 108000000, - 21500397, - 'misc', - 'alice', - 'TAMESPACEWH4MKFMBCVFERDPOOP4FK7MTDJEYP35', - 5000000000) - t = serialize_provision_namespace(m.transaction, m.provision_namespace, unhexlify('244fa194e2509ac0d2fbc18779c2618d8c2ebb61c16a3bcbebcf448c661ba8dc')) + m = _create_msg( + NEM_NETWORK_TESTNET, + 21496797, + 108000000, + 21500397, + "misc", + "alice", + "TAMESPACEWH4MKFMBCVFERDPOOP4FK7MTDJEYP35", + 5000000000, + ) + t = serialize_provision_namespace( + m.transaction, + m.provision_namespace, + unhexlify( + "244fa194e2509ac0d2fbc18779c2618d8c2ebb61c16a3bcbebcf448c661ba8dc" + ), + ) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('7ddd5fe607e1bfb5606e0ac576024c318c8300d237273117d4db32a60c49524d')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "7ddd5fe607e1bfb5606e0ac576024c318c8300d237273117d4db32a60c49524d" + ), + ) # http://chain.nem.ninja/#/namespace/57071aad93ca125dc231dc02c07ad8610cd243d35068f9b36a7d231383907569 - m = _create_msg(NEM_NETWORK_MAINNET, - 26699717, - 108000000, - 26703317, - 'sex', - '', - 'NAMESPACEWH4MKFMBCVFERDPOOP4FK7MTBXDPZZA', - 50000000000) - t = serialize_provision_namespace(m.transaction, m.provision_namespace, unhexlify('9f3c14f304309c8b72b2821339c4428793b1518bea72d58dd01f19d523518614')) + m = _create_msg( + NEM_NETWORK_MAINNET, + 26699717, + 108000000, + 26703317, + "sex", + "", + "NAMESPACEWH4MKFMBCVFERDPOOP4FK7MTBXDPZZA", + 50000000000, + ) + t = serialize_provision_namespace( + m.transaction, + m.provision_namespace, + unhexlify( + "9f3c14f304309c8b72b2821339c4428793b1518bea72d58dd01f19d523518614" + ), + ) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('57071aad93ca125dc231dc02c07ad8610cd243d35068f9b36a7d231383907569')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "57071aad93ca125dc231dc02c07ad8610cd243d35068f9b36a7d231383907569" + ), + ) -def _create_msg(network: int, timestamp: int, fee: int, deadline: int, - name: str, parent: str, sink: str, rental_fee: int): +def _create_msg( + network: int, + timestamp: int, + fee: int, + deadline: int, + name: str, + parent: str, + sink: str, + rental_fee: int, +): transaction = NEMTransactionCommon( network=network, timestamp=timestamp, @@ -76,5 +122,5 @@ def _create_msg(network: int, timestamp: int, fee: int, deadline: int, ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.nem.transfer.py b/core/tests/test_apps.nem.transfer.py index 587a00c932..480a0188e2 100644 --- a/core/tests/test_apps.nem.transfer.py +++ b/core/tests/test_apps.nem.transfer.py @@ -12,96 +12,177 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestNemTransfer(unittest.TestCase): - def test_create_transfer(self): # http://bob.nem.ninja:8765/#/transfer/0acbf8df91e6a65dc56c56c43d65f31ff2a6a48d06fc66e78c7f3436faf3e74f - m = _create_msg(NEM_NETWORK_TESTNET, - 0, - 0, - 0, - 'TBGIMRE4SBFRUJXMH7DVF2IBY36L2EDWZ37GVSC4', - 50000000000000) + m = _create_msg( + NEM_NETWORK_TESTNET, + 0, + 0, + 0, + "TBGIMRE4SBFRUJXMH7DVF2IBY36L2EDWZ37GVSC4", + 50000000000000, + ) - t = serialize_transfer(m.transaction, m.transfer, unhexlify('e59ef184a612d4c3c4d89b5950eb57262c69862b2f96e59c5043bf41765c482f'), None, False) - self.assertEqual(t, unhexlify('01010000010000980000000020000000e59ef184a612d4c3c4d89b5950eb57262c69862b2f96e59c5043bf41765c482f00000000000000000000000028000000544247494d52453453424652554a584d48374456463249425933364c324544575a3337475653433400203d88792d000000000000')) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('0acbf8df91e6a65dc56c56c43d65f31ff2a6a48d06fc66e78c7f3436faf3e74f')) + t = serialize_transfer( + m.transaction, + m.transfer, + unhexlify( + "e59ef184a612d4c3c4d89b5950eb57262c69862b2f96e59c5043bf41765c482f" + ), + None, + False, + ) + self.assertEqual( + t, + unhexlify( + "01010000010000980000000020000000e59ef184a612d4c3c4d89b5950eb57262c69862b2f96e59c5043bf41765c482f00000000000000000000000028000000544247494d52453453424652554a584d48374456463249425933364c324544575a3337475653433400203d88792d000000000000" + ), + ) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "0acbf8df91e6a65dc56c56c43d65f31ff2a6a48d06fc66e78c7f3436faf3e74f" + ), + ) def test_create_transfer_with_payload(self): # http://chain.nem.ninja/#/transfer/e90e98614c7598fbfa4db5411db1b331d157c2f86b558fb7c943d013ed9f71cb - m = _create_msg(NEM_NETWORK_MAINNET, - 0, - 0, - 0, - 'NBT3WHA2YXG2IR4PWKFFMO772JWOITTD2V4PECSB', - 5175000000000) + m = _create_msg( + NEM_NETWORK_MAINNET, + 0, + 0, + 0, + "NBT3WHA2YXG2IR4PWKFFMO772JWOITTD2V4PECSB", + 5175000000000, + ) - t = serialize_transfer(m.transaction, m.transfer, - unhexlify('8d07f90fb4bbe7715fa327c926770166a11be2e494a970605f2e12557f66c9b9'), - bytearray('Good luck!'), - False) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('e90e98614c7598fbfa4db5411db1b331d157c2f86b558fb7c943d013ed9f71cb')) + t = serialize_transfer( + m.transaction, + m.transfer, + unhexlify( + "8d07f90fb4bbe7715fa327c926770166a11be2e494a970605f2e12557f66c9b9" + ), + bytearray("Good luck!"), + False, + ) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "e90e98614c7598fbfa4db5411db1b331d157c2f86b558fb7c943d013ed9f71cb" + ), + ) def test_create_transfer_with_encrypted_payload(self): # http://chain.nem.ninja/#/transfer/40e89160e6f83d37f7c82defc0afe2c1605ae8c919134570a51dd27ea1bb516c - m = _create_msg(NEM_NETWORK_MAINNET, - 77229, - 30000000, - 80829, - 'NALICEPFLZQRZGPRIJTMJOCPWDNECXTNNG7QLSG3', - 30000000) + m = _create_msg( + NEM_NETWORK_MAINNET, + 77229, + 30000000, + 80829, + "NALICEPFLZQRZGPRIJTMJOCPWDNECXTNNG7QLSG3", + 30000000, + ) - t = serialize_transfer(m.transaction, m.transfer, - unhexlify('f85ab43dad059b9d2331ddacc384ad925d3467f03207182e01296bacfb242d01'), - unhexlify('4d9dcf9186967d30be93d6d5404ded22812dbbae7c3f0de501bcd7228cba45bded13000eec7b4c6215fc4d3588168c9218167cec98e6977359153a4132e050f594548e61e0dc61c153f0f53c5e65c595239c9eb7c4e7d48e0f4bb8b1dd2f5ddc'), - True) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('40e89160e6f83d37f7c82defc0afe2c1605ae8c919134570a51dd27ea1bb516c')) + t = serialize_transfer( + m.transaction, + m.transfer, + unhexlify( + "f85ab43dad059b9d2331ddacc384ad925d3467f03207182e01296bacfb242d01" + ), + unhexlify( + "4d9dcf9186967d30be93d6d5404ded22812dbbae7c3f0de501bcd7228cba45bded13000eec7b4c6215fc4d3588168c9218167cec98e6977359153a4132e050f594548e61e0dc61c153f0f53c5e65c595239c9eb7c4e7d48e0f4bb8b1dd2f5ddc" + ), + True, + ) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "40e89160e6f83d37f7c82defc0afe2c1605ae8c919134570a51dd27ea1bb516c" + ), + ) def test_create_transfer_with_mosaic(self): # http://bob.nem.ninja:8765/#/transfer/3409d9ece28d6296d6d5e220a7e3cb8641a3fb235ffcbd20c95da64f003ace6c - m = _create_msg(NEM_NETWORK_TESTNET, - 14072100, - 194000000, - 14075700, - 'TBLOODPLWOWMZ2TARX4RFPOSOWLULHXMROBN2WXI', - 3000000, - 2) + m = _create_msg( + NEM_NETWORK_TESTNET, + 14072100, + 194000000, + 14075700, + "TBLOODPLWOWMZ2TARX4RFPOSOWLULHXMROBN2WXI", + 3000000, + 2, + ) - t = serialize_transfer(m.transaction, m.transfer, - unhexlify('994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324'), - bytearray('sending you 3 pairs of paddles\n'), - False) + t = serialize_transfer( + m.transaction, + m.transfer, + unhexlify( + "994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd324" + ), + bytearray("sending you 3 pairs of paddles\n"), + False, + ) - self.assertEqual(t, unhexlify('010100000200009824b9d60020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd3248034900b0000000034c7d6002800000054424c4f4f44504c574f574d5a3254415258345246504f534f574c554c48584d524f424e32575849c0c62d000000000027000000010000001f00000073656e64696e6720796f752033207061697273206f6620706164646c65730a02000000')) + self.assertEqual( + t, + unhexlify( + "010100000200009824b9d60020000000994793ba1c789fa9bdea918afc9b06e2d0309beb1081ac5b6952991e4defd3248034900b0000000034c7d6002800000054424c4f4f44504c574f574d5a3254415258345246504f534f574c554c48584d524f424e32575849c0c62d000000000027000000010000001f00000073656e64696e6720796f752033207061697273206f6620706164646c65730a02000000" + ), + ) - serialize_mosaic(t, 'gimre.games.pong', 'paddles', 2) - serialize_mosaic(t, 'nem', 'xem', 44000000) + serialize_mosaic(t, "gimre.games.pong", "paddles", 2) + serialize_mosaic(t, "nem", "xem", 44000000) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('3409d9ece28d6296d6d5e220a7e3cb8641a3fb235ffcbd20c95da64f003ace6c')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "3409d9ece28d6296d6d5e220a7e3cb8641a3fb235ffcbd20c95da64f003ace6c" + ), + ) # http://chain.nem.ninja/#/transfer/882dca18dcbe075e15e0ec5a1d7e6ccd69cc0f1309ffd3fde227bfbc107b3f6e - m = _create_msg(NEM_NETWORK_MAINNET, - 26730750, - 179500000, - 26734350, - 'NBE223WPKEBHQPCYUC4U4CDUQCRRFMPZLOQLB5OP', - 1000000, - 1) + m = _create_msg( + NEM_NETWORK_MAINNET, + 26730750, + 179500000, + 26734350, + "NBE223WPKEBHQPCYUC4U4CDUQCRRFMPZLOQLB5OP", + 1000000, + 1, + ) - t = serialize_transfer(m.transaction, m.transfer, - unhexlify('f85ab43dad059b9d2331ddacc384ad925d3467f03207182e01296bacfb242d01'), - bytearray('enjoy! :)'), - False) - serialize_mosaic(t, 'imre.g', 'tokens', 1) + t = serialize_transfer( + m.transaction, + m.transfer, + unhexlify( + "f85ab43dad059b9d2331ddacc384ad925d3467f03207182e01296bacfb242d01" + ), + bytearray("enjoy! :)"), + False, + ) + serialize_mosaic(t, "imre.g", "tokens", 1) - self.assertEqual(hashlib.sha3_256(t, keccak=True).digest(), unhexlify('882dca18dcbe075e15e0ec5a1d7e6ccd69cc0f1309ffd3fde227bfbc107b3f6e')) + self.assertEqual( + hashlib.sha3_256(t, keccak=True).digest(), + unhexlify( + "882dca18dcbe075e15e0ec5a1d7e6ccd69cc0f1309ffd3fde227bfbc107b3f6e" + ), + ) -def _create_msg(network: int, timestamp: int, fee: int, deadline: int, - recipient: str, amount: int, mosaics: int = 0): +def _create_msg( + network: int, + timestamp: int, + fee: int, + deadline: int, + recipient: str, + amount: int, + mosaics: int = 0, +): transaction = NEMTransactionCommon( network=network, timestamp=timestamp, @@ -112,7 +193,10 @@ def _create_msg(network: int, timestamp: int, fee: int, deadline: int, transfer = NEMTransfer( recipient=recipient, amount=amount, - mosaics=[NEMMosaic(namespace="abc", quantity=5, mosaic="mosaic") for _ in range(mosaics)], + mosaics=[ + NEMMosaic(namespace="abc", quantity=5, mosaic="mosaic") + for _ in range(mosaics) + ], ) return NEMSignTx( @@ -121,5 +205,5 @@ def _create_msg(network: int, timestamp: int, fee: int, deadline: int, ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.ripple.address.py b/core/tests/test_apps.ripple.address.py index 69d7dfad48..884f36c8b4 100644 --- a/core/tests/test_apps.ripple.address.py +++ b/core/tests/test_apps.ripple.address.py @@ -6,17 +6,28 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestRippleAddress(unittest.TestCase): - def test_pubkey_to_address(self): - addr = address_from_public_key(unhexlify('ed9434799226374926eda3b54b1b461b4abf7237962eae18528fea67595397fa32')) - self.assertEqual(addr, 'rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN') + addr = address_from_public_key( + unhexlify( + "ed9434799226374926eda3b54b1b461b4abf7237962eae18528fea67595397fa32" + ) + ) + self.assertEqual(addr, "rDTXLQ7ZKZVKz33zJbHjgVShjsBnqMBhmN") - addr = address_from_public_key(unhexlify('03e2b079e9b09ae8916da8f5ee40cbda9578dbe7c820553fe4d5f872eec7b1fdd4')) - self.assertEqual(addr, 'rhq549rEtUrJowuxQC2WsHNGLjAjBQdAe8') + addr = address_from_public_key( + unhexlify( + "03e2b079e9b09ae8916da8f5ee40cbda9578dbe7c820553fe4d5f872eec7b1fdd4" + ) + ) + self.assertEqual(addr, "rhq549rEtUrJowuxQC2WsHNGLjAjBQdAe8") - addr = address_from_public_key(unhexlify('0282ee731039929e97db6aec242002e9aa62cd62b989136df231f4bb9b8b7c7eb2')) - self.assertEqual(addr, 'rKzE5DTyF9G6z7k7j27T2xEas2eMo85kmw') + addr = address_from_public_key( + unhexlify( + "0282ee731039929e97db6aec242002e9aa62cd62b989136df231f4bb9b8b7c7eb2" + ) + ) + self.assertEqual(addr, "rKzE5DTyF9G6z7k7j27T2xEas2eMo85kmw") -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.stellar.address.py b/core/tests/test_apps.stellar.address.py index bb59e9a835..dbc477361e 100644 --- a/core/tests/test_apps.stellar.address.py +++ b/core/tests/test_apps.stellar.address.py @@ -7,35 +7,72 @@ if not utils.BITCOIN_ONLY: @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestStellarAddress(unittest.TestCase): - def test_address_to_pubkey(self): - self.assertEqual(public_key_from_address('GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V'), - unhexlify('5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0')) + self.assertEqual( + public_key_from_address( + "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V" + ), + unhexlify( + "5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0" + ), + ) - self.assertEqual(public_key_from_address('GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2U6'), - unhexlify('9ba568e6eec16bea4fed0f17b134a1d692eae199a578ba6fb44c0c24431bfdb4')) + self.assertEqual( + public_key_from_address( + "GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2U6" + ), + unhexlify( + "9ba568e6eec16bea4fed0f17b134a1d692eae199a578ba6fb44c0c24431bfdb4" + ), + ) def test_pubkey_to_address(self): - addr = address_from_public_key(unhexlify('5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0')) - self.assertEqual(addr, 'GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V') + addr = address_from_public_key( + unhexlify( + "5d55642466b185b843152e9e219151dbc5892027ec40101a517bed5ca030c2e0" + ) + ) + self.assertEqual( + addr, "GBOVKZBEM2YYLOCDCUXJ4IMRKHN4LCJAE7WEAEA2KF562XFAGDBOB64V" + ) - addr = address_from_public_key(unhexlify('9ba568e6eec16bea4fed0f17b134a1d692eae199a578ba6fb44c0c24431bfdb4')) - self.assertEqual(addr, 'GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2U6') + addr = address_from_public_key( + unhexlify( + "9ba568e6eec16bea4fed0f17b134a1d692eae199a578ba6fb44c0c24431bfdb4" + ) + ) + self.assertEqual( + addr, "GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2U6" + ) def test_both(self): - pubkey = unhexlify('dfcc77d08588601702e02de2dc603f5c5281bea23baa894ae3b3b4778e5bbe40') - self.assertEqual(public_key_from_address(address_from_public_key(pubkey)), pubkey) + pubkey = unhexlify( + "dfcc77d08588601702e02de2dc603f5c5281bea23baa894ae3b3b4778e5bbe40" + ) + self.assertEqual( + public_key_from_address(address_from_public_key(pubkey)), pubkey + ) - pubkey = unhexlify('53214e6155469c32fb882b1b1d94930d5445a78202867b7ddc6a33ad42ff4464') - self.assertEqual(public_key_from_address(address_from_public_key(pubkey)), pubkey) + pubkey = unhexlify( + "53214e6155469c32fb882b1b1d94930d5445a78202867b7ddc6a33ad42ff4464" + ) + self.assertEqual( + public_key_from_address(address_from_public_key(pubkey)), pubkey + ) - pubkey = unhexlify('5ed4690134e5ef79b290ea1e7a4b8f3b6b3bcf287463c18bfe36baa030e7efbd') - self.assertEqual(public_key_from_address(address_from_public_key(pubkey)), pubkey) + pubkey = unhexlify( + "5ed4690134e5ef79b290ea1e7a4b8f3b6b3bcf287463c18bfe36baa030e7efbd" + ) + self.assertEqual( + public_key_from_address(address_from_public_key(pubkey)), pubkey + ) def test_invalid_address(self): with self.assertRaises(ProcessError): - public_key_from_address('GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2AA') # invalid checksum + public_key_from_address( + "GCN2K2HG53AWX2SP5UHRPMJUUHLJF2XBTGSXROTPWRGAYJCDDP63J2AA" + ) # invalid checksum -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.tezos.encode.py b/core/tests/test_apps.tezos.encode.py index a7f463a01d..25fb549559 100644 --- a/core/tests/test_apps.tezos.encode.py +++ b/core/tests/test_apps.tezos.encode.py @@ -89,7 +89,15 @@ class TestTezosEncoding(unittest.TestCase): def test_tezos_encode_natural(self): inputs = [200000000000, 2000000, 159066, 200, 60000, 157000000, 0] - outputs = ["0080c0ee8ed20b", "008092f401", "009ab513", "008803", "00a0a907", "008085dd9501", "0000"] + outputs = [ + "0080c0ee8ed20b", + "008092f401", + "009ab513", + "008803", + "00a0a907", + "008085dd9501", + "0000", + ] for i, o in zip(inputs, outputs): w = bytearray() diff --git a/core/tests/test_apps.webauthn.credential.py b/core/tests/test_apps.webauthn.credential.py index 07b4497f9e..76d31be65a 100644 --- a/core/tests/test_apps.webauthn.credential.py +++ b/core/tests/test_apps.webauthn.credential.py @@ -23,9 +23,7 @@ class TestCredential(unittest.TestCase): rp_id = "example.com" rp_id_hash = sha256(rp_id).digest() - user_id = ( - b"3082019330820138a0030201023082019330820138a003020102308201933082" - ) + user_id = b"3082019330820138a0030201023082019330820138a003020102308201933082" user_name = "johnpsmith@example.com" @@ -107,18 +105,32 @@ class TestCredential(unittest.TestCase): c2 = U2fCredential() - self.assertEqual(sorted(_distinguishable_cred_list([a1, a2, a3, b1, b2, c1, c2])), [b2, a3, a1, c1]) - self.assertEqual(sorted(_distinguishable_cred_list([c2, c1, b2, b1, a3, a2, a1])), [b2, a3, a1, c2]) + self.assertEqual( + sorted(_distinguishable_cred_list([a1, a2, a3, b1, b2, c1, c2])), + [b2, a3, a1, c1], + ) + self.assertEqual( + sorted(_distinguishable_cred_list([c2, c1, b2, b1, a3, a2, a1])), + [b2, a3, a1, c2], + ) # Test input by creation time. - self.assertEqual(sorted(_distinguishable_cred_list([b2, a3, c1, a2, b1, a1, c2])), [b2, a3, a1, c1]) - self.assertEqual(sorted(_distinguishable_cred_list([c2, a1, b1, a2, c1, a3, b2])), [b2, a3, a1, c2]) + self.assertEqual( + sorted(_distinguishable_cred_list([b2, a3, c1, a2, b1, a1, c2])), + [b2, a3, a1, c1], + ) + self.assertEqual( + sorted(_distinguishable_cred_list([c2, a1, b1, a2, c1, a3, b2])), + [b2, a3, a1, c2], + ) # Test duplicities. - self.assertEqual(sorted(_distinguishable_cred_list([c1, a1, a1, c2, c1])), [a1, c1]) + self.assertEqual( + sorted(_distinguishable_cred_list([c1, a1, a1, c2, c1])), [a1, c1] + ) self.assertEqual(sorted(_distinguishable_cred_list([b2, b3])), [b2]) self.assertEqual(sorted(_distinguishable_cred_list([b3, b2])), [b3]) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.zcash.f4jumble.py b/core/tests/test_apps.zcash.f4jumble.py index 2c502731a7..001e4a9adf 100644 --- a/core/tests/test_apps.zcash.f4jumble.py +++ b/core/tests/test_apps.zcash.f4jumble.py @@ -2,21 +2,52 @@ from common import * from apps.zcash.f4jumble import f4jumble, f4unjumble + @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestZcashF4jumble(unittest.TestCase): def test_f4jumble(self): - #source: https://github.com/zcash/librustzcash/blob/main/components/f4jumble/src/test_vectors.rs + # source: https://github.com/zcash/librustzcash/blob/main/components/f4jumble/src/test_vectors.rs TEST_VECTORS = [ - {'jumbled': unhexlify('0304d029141b995da5387c125970673504d6c764d91ea6c082123770c7139ccd88ee27368cd0c0921a0444c8e5858d22'), - 'normal': unhexlify('5d7a8f739a2d9e945b0ce152a8049e294c4d6e66b164939daffa2ef6ee6921481cdd86b3cc4318d9614fc820905d042b')}, - {'jumbled': unhexlify('5271fa3321f3adbcfb075196883d542b438ec6339176537daf859841fe6a56222bff76d1662b5509a9e1079e446eeedd2e683c31aae3ee1851d7954328526be1'), - 'normal': unhexlify('b1ef9ca3f24988c7b3534201cfb1cd8dbf69b8250c18ef41294ca97993db546c1fe01f7e9c8e36d6a5e29d4e30a73594bf5098421c69378af1e40f64e125946f')}, - {'jumbled': unhexlify('498cf1b1ba6f4577effe64151d67469adc30acc325e326207e7d78487085b4162669f82f02f9774c0cc26ae6e1a76f1e266c6a9a8a2f4ffe8d2d676b1ed71cc47195a3f19208998f7d8cdfc0b74d2a96364d733a62b4273c77d9828aa1fa061588a7c4c88dd3d3dde02239557acfaad35c55854f4541e1a1b3bc8c17076e7316'), - 'normal': unhexlify('62c2fa7b2fecbcb64b6968912a6381ce3dc166d56a1d62f5a8d7551db5fd9313e8c7203d996af7d477083756d59af80d06a745f44ab023752cb5b406ed8985e18130ab33362697b0e4e4c763ccb8f676495c222f7fba1e31defa3d5a57efc2e1e9b01a035587d5fb1a38e01d94903d3c3e0ad3360c1d3710acd20b183e31d49f')}, - {'jumbled': unhexlify('7508a3a146714f229db91b543e240633ed57853f6451c9db6d64c6e86af1b88b28704f608582c53c51ce7d5b8548827a971d2b98d41b7f6258655902440cd66ee11e84dbfac7d2a43696fd0468810a3d9637c3fa58e7d2d341ef250fa09b9fb71a78a41d389370138a55ea58fcde779d714a04e0d30e61dc2d8be0da61cd684509'), - 'normal': unhexlify('25c9a138f49b1a537edcf04be34a9851a7af9db6990ed83dd64af3597c04323ea51b0052ad8084a8b9da948d320dadd64f5431e61ddf658d24ae67c22c8d1309131fc00fe7f235734276d38d47f1e191e00c7a1d48af046827591e9733a97fa6b679f3dc601d008285edcbdae69ce8fc1be4aac00ff2711ebd931de518856878f7')}, - {'jumbled': unhexlify('5139912fe8b95492c12731995a0f4478dbeb81ec36653a21bc80d673f3c6a0feef70b6c566f9d34bb726c098648382d105afb19b2b8486b73cbd47a17a0d2d1fd593b14bb9826c5d114b850c6f0cf3083a6f61e38e42713a37ef7997ebd2b376c8a410d797b3932e5a6e39e726b2894ce79604b4ae3c00acaea3be2c1dfe697fa644755102cf9ad78794d0594585494fe38ab56fa6ef3271a68a33481015adf3944c115311421a7dc3ce73ef2abf47e18a6aca7f9dd25a85ce8dbd6f1ad89c8d'), - 'normal': unhexlify('3476f21a482ec9378365c8f7393c94e2885315eb4671098b79535e790fe53e29fef2b3766697ac32b4f473f468a008e72389fc03880d780cb07fcfaabe3f1a84b27db59a4a153d882d2b2103596555ed9494c6ac893c49723833ec8926c1039586a7afcf4a0d9c731e985d99589c8bb838e8aaf745533ed9e8ae3a1cd074a51a20da8aba18d1dbebbc862ded42435e92476930d069896cff30eb414f727b89e001afa2fb8dc3436d75a4a6f26572504b192232ecb9f0c02411e52596bc5e9045')} + { + "jumbled": unhexlify( + "0304d029141b995da5387c125970673504d6c764d91ea6c082123770c7139ccd88ee27368cd0c0921a0444c8e5858d22" + ), + "normal": unhexlify( + "5d7a8f739a2d9e945b0ce152a8049e294c4d6e66b164939daffa2ef6ee6921481cdd86b3cc4318d9614fc820905d042b" + ), + }, + { + "jumbled": unhexlify( + "5271fa3321f3adbcfb075196883d542b438ec6339176537daf859841fe6a56222bff76d1662b5509a9e1079e446eeedd2e683c31aae3ee1851d7954328526be1" + ), + "normal": unhexlify( + "b1ef9ca3f24988c7b3534201cfb1cd8dbf69b8250c18ef41294ca97993db546c1fe01f7e9c8e36d6a5e29d4e30a73594bf5098421c69378af1e40f64e125946f" + ), + }, + { + "jumbled": unhexlify( + "498cf1b1ba6f4577effe64151d67469adc30acc325e326207e7d78487085b4162669f82f02f9774c0cc26ae6e1a76f1e266c6a9a8a2f4ffe8d2d676b1ed71cc47195a3f19208998f7d8cdfc0b74d2a96364d733a62b4273c77d9828aa1fa061588a7c4c88dd3d3dde02239557acfaad35c55854f4541e1a1b3bc8c17076e7316" + ), + "normal": unhexlify( + "62c2fa7b2fecbcb64b6968912a6381ce3dc166d56a1d62f5a8d7551db5fd9313e8c7203d996af7d477083756d59af80d06a745f44ab023752cb5b406ed8985e18130ab33362697b0e4e4c763ccb8f676495c222f7fba1e31defa3d5a57efc2e1e9b01a035587d5fb1a38e01d94903d3c3e0ad3360c1d3710acd20b183e31d49f" + ), + }, + { + "jumbled": unhexlify( + "7508a3a146714f229db91b543e240633ed57853f6451c9db6d64c6e86af1b88b28704f608582c53c51ce7d5b8548827a971d2b98d41b7f6258655902440cd66ee11e84dbfac7d2a43696fd0468810a3d9637c3fa58e7d2d341ef250fa09b9fb71a78a41d389370138a55ea58fcde779d714a04e0d30e61dc2d8be0da61cd684509" + ), + "normal": unhexlify( + "25c9a138f49b1a537edcf04be34a9851a7af9db6990ed83dd64af3597c04323ea51b0052ad8084a8b9da948d320dadd64f5431e61ddf658d24ae67c22c8d1309131fc00fe7f235734276d38d47f1e191e00c7a1d48af046827591e9733a97fa6b679f3dc601d008285edcbdae69ce8fc1be4aac00ff2711ebd931de518856878f7" + ), + }, + { + "jumbled": unhexlify( + "5139912fe8b95492c12731995a0f4478dbeb81ec36653a21bc80d673f3c6a0feef70b6c566f9d34bb726c098648382d105afb19b2b8486b73cbd47a17a0d2d1fd593b14bb9826c5d114b850c6f0cf3083a6f61e38e42713a37ef7997ebd2b376c8a410d797b3932e5a6e39e726b2894ce79604b4ae3c00acaea3be2c1dfe697fa644755102cf9ad78794d0594585494fe38ab56fa6ef3271a68a33481015adf3944c115311421a7dc3ce73ef2abf47e18a6aca7f9dd25a85ce8dbd6f1ad89c8d" + ), + "normal": unhexlify( + "3476f21a482ec9378365c8f7393c94e2885315eb4671098b79535e790fe53e29fef2b3766697ac32b4f473f468a008e72389fc03880d780cb07fcfaabe3f1a84b27db59a4a153d882d2b2103596555ed9494c6ac893c49723833ec8926c1039586a7afcf4a0d9c731e985d99589c8bb838e8aaf745533ed9e8ae3a1cd074a51a20da8aba18d1dbebbc862ded42435e92476930d069896cff30eb414f727b89e001afa2fb8dc3436d75a4a6f26572504b192232ecb9f0c02411e52596bc5e9045" + ), + }, ] for tv in TEST_VECTORS: @@ -26,5 +57,6 @@ class TestZcashF4jumble(unittest.TestCase): f4unjumble(message) self.assertEqual(bytes(message), tv["normal"]) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_apps.zcash.unified_addresses.py b/core/tests/test_apps.zcash.unified_addresses.py index 2e39582d90..3ce1b1c701 100644 --- a/core/tests/test_apps.zcash.unified_addresses.py +++ b/core/tests/test_apps.zcash.unified_addresses.py @@ -9,53 +9,278 @@ SAPLING = unified_addresses.Typecode.SAPLING ORCHARD = unified_addresses.Typecode.ORCHARD TESTVECTORS = [ - ["From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/unified_address.py"], - ["p2pkh_bytes, p2sh_bytes, sapling_raw_addr, orchard_raw_addr, unknown_typecode, unknown_bytes, unified_addr, root_seed, account, diversifier_index"], - ["e6cabf813929132d772d04b03ae85223d03b9be8", None, None, "d4714ee761d1ae823b6972152e20957fefa3f6e3129ea4dfb0a9e98703a63dab929589d6dc51c970f935b3", 65533, "f6ee6921481cdd86b3cc4318d9614fc820905d042bb1ef9ca3f24988c7b3534201cfb1cd8dbf69b8250c18ef41294ca97993db546c1fe0", "753179793677386e336a6d6a73676a39777663656e7238723570366833387679636c686d71307767396b7a70786c7534367a387636346b3567737a72387966777a346a7672796c76766733673633337a30326c756b38356e6d73636b366432736578336e3564376b6e3638687a7a3574763475647439703673793770676c6565756c76676c767832363237646666353771396665703577676478386d3065737832386d307a767578706d7779617a74336a756e3272707177386e75366a326663657167686b353563656436366a73366b366a786e387932787475653866337061716a726b3871366e70746e6e", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 0, 0], - ["7bec9de217c04f7ce1a86f1fb458aa881c8f39e4", None, None, "d8e5ecb4e005c28718e61a5c336a4f369e771ccdb3363f4f7a04b02a966901a4c05da662d5fd75678f7fb4", 65530, None, "75317a35677538783364766b7677636d726a30716b3568727839706361646c3536683834663777647970366e7635337233643563636365646563686d77393835746765357733633272353639716137326c676775753578727178683739616a7a63376b716d65733230706b747a71726a6c707835367168676d716d3536686e39777432686379787064616d616b", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 1, 0], - ["aa6d43480fd9d91375ce6c4a020706361bd296de", None, "88533c398a49c2513dc85162bf220abaf47dc983f14e908ddaaa7322dba16531bc62efe750fe575c8d149b", None, 65530, None, "7531343367706a3772643934766d39356d7a73757537746a74716161677934706d6678386c6b77656d70786a7463777a33357a746361383530796e6c7a323932307477617a6171703270367168787878337a357178616b6e73716372676c7578716a337070757367776635757963686c61677938376b376874613768773965793336776d7930367065776c6470", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 2, 0], - [None, "a8d7551db5fd9313e8c7203d996af7d477083756", "52fd6aedefbf401633c2e4532515ebcf95bcc2b4b8e4d676dfad7e17925c6dfb8671e52544dc2ca075e261", None, 65534, None, "753178797970646a307a7978637466666b6878796d766a6e6b376e383371666c376e7365356c3071726b346e3266376465376c3733727a79787970347463727975356d6b7875617a6c646e633279306479747a7567797a79636739373034616a66786173376b63757761776d706877776e383839743938743735376579716667346a766566746b687672337167", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 3, 0], - [None, "f44ab023752cb5b406ed8985e18130ab33362697", None, "165082de84f2ad7204426ffafd6b6c7de9cab6d25c13846a1786715268c415948db788f4a5e0daa03d699e", 65533, None, "7531706a336c72656d6e7175737368393878667161336a66647077303872726b35377330346b6c32366865707a7133746a72736e78653574367371716567653976716d776c63366c786373746e6333306e3575357232776b6b7a687039367a3564306a797530716137746b686378366663386a35396b616b387a35636570363261716d61336d36343566683863", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 4, 0], - [None, None, None, "ea9df83fbee07d6f7895ebb2ea41ec7c4ba682b863e069b4a438e31c9571c83126c305d75456412aeaef1b", 65531, None, "753132787567643930666c726b646b6575336e6c6e6e337565736b793533707175356d323479366170786d38386d34387637333734636c7335367a7039336e61796c617864636866307161796678747267653034376d393533717a3376326772346c74737232736b3372", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 5, 0], - [None, None, None, "3c40246912b6efefab9a55244ac2c174e1a9f8c0bc0fd526933963c6ecb9b84ec8b0f6b40dc858fa23c72b", 65530, None, "75317370757467353667736a763233637435346d7277646c616e7a7665716337747a73356d78786e616135636465676d303368673778363661797079647336356d39327674397561786c3637327375687063367a3768747776657079686b727066757376617a71756539", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 6, 0], - [None, "defa3d5a57efc2e1e9b01a035587d5fb1a38e01d", None, "cc099cc214e56b1192c7b5b17e958c3413e27fefd553380700aca81b24b2918cac951a1a68017fac525a18", 65535, None, "75317667736b636d3939783567687561757668337978713777747037756e366130793663617964736e6e33357032647577707773356873367079676a6877703738326a716e65727a6c6878773370343971666d713237383339716a7472667976686b377964393877396e3064366a6e7336756834666333687364663736366b6e74716e6c6a646b64353667636e", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 7, 0], - [None, None, None, "5f09a9807a56323b263b05df368dc28391b21a64a0e1b40f9a6803b7e68f3905923f35cb01f119b223f493", 65530, None, "75316378636379656d6d3038747964776d743968703273356e6638776a766c757575366c32653861396a666c6c647861736e7a6b6438667665727170636a30786e767261637a71673235356377356e767936783977727566666d703975657a727a72376763783535396b", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 8, 0], - [None, "10acd20b183e31d49f25c9a138f49b1a537edcf0", "9b60ae3d302248b349d601567e3d7795bfb334ea1fd1a7e71402169ebbe14bd2ceaa244ccd6e5aa2245613", "e340636542ece1c81285ed4eab448adbb5a8c0f4d386eeff337e88e6915f6c3ec1b6ea835a88d56612d2bd", 65531, None, "75317a656b68686d686b353478356365356333367274376e63323735676570376e6176326e73783473683061666c6c75703976726835687338367a38736b6a746436646e736c7667736d6174743068386832343763676e666b73646c776c39786d617275797570666c743064716673637830647979656d3266616139776571653378616b397736656672353437636a3832397232746e7974613032687866647873646a6d76397a72356b746b70323066706378656164686672683032616b346136686e7876357336377267717272766670646a7435", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 9, 0], - [None, "af9db6990ed83dd64af3597c04323ea51b0052ad", None, "cdf7fed0d0822fd849cffb20a4d5ee701ad8141e66d81ddfabf87875117c05092240603c546b8dc187cd8c", 65532, None, "753165353471636e30746570796c33307a7a326672677a37713461366d736e326530326e7076326e6666736433683532336d747838643232616a7666767371757235736a7a3876666e6d77327973363730387170386b6139306a3561343330757938763833616c6a63306330357a6a7535347879356e7677336d66686b376e7737366b6b7964796c713466656c", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 10, 0], - [None, None, None, "24fd59f32b2d39dde66e46c39206a31bc04fa5c6847976ea6bbd3163ee14f58f584acc131479ea558d3f84", 65530, None, "75317a38777372686d66366d3967766136766c33737a636b303670393730783577686d36336a666a3266726d6d63396e39756d34796373387975746a37673833387672676832306c667879353279306832367474386e6776643267796370797176396b793032716b6373", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 11, 0], - [None, None, "78d85bd0db639043377987cdd814c6390016964b684016faf1ad4f166c5f72399a5e8d469ec6beb873d55d", None, 65535, None, "75317861686a333570376d7639756c6b3337327333766465687172663438753077646633786c3772787a7270653461307468753864306d396d7961617078376b35767836747a357074636a76637675346472667137753771777a6d667565336b74387376736333736535", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 12, 0], - ["33a6dd87b4d872a4895d345761e4ec423b77928d", None, None, "5178924f7067eac261044ca27ba3cf52f798486973af0795e61587aa1b1ecad333dc520497edc61df88980", 65533, "91e00c7a1d48af046827591e9733a97fa6b679f3dc601d008285edcbdae69ce8fc1be4aac00ff2711ebd931de518856878f73476f21a482ec9378365c8f7393c94e2885315eb4671098b79535e790fe53e29fef2b3766697ac32b4f473f468a008e72389fc03880d780cb07fcfaabe3f1a84b27db59a4a153d882d2b2103596555ed9494c6ac893c49723833ec8926c1", "7531687970706c733364776d616c783373756c746b72397564763237376679716a6478307378716c746638676a6e777976343968743575327270336c6c767632756e796d7330383675616a6b6638393837636175616a7136383670356638687276393474616336663078796637796d7a3636747279366b7936726179336d6a633567786661683030637370766b3564676d67736e3737663274336775763270307861366b6c6138717479376d6b6e6b6d337a68303932306c77733633326166743071686b3532363579736c337067323237747866373461736d7075656e326c746533616a6330667a376b34736878797a656d6e7035773770336b746c6874643030366d6b61787979306d746637646a73646175397a666b657332616e387661687a6737647173677938326330707830396d39683061657a736e7936786c66706767667268656d7661786a3578747871356a6e67763076306167726c3073757079676639636574656a35323779727a7a6574386471747164616771", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 13, 0], - ["a56c057ef71dab58aa90e47025695c5faaea5123", None, "a75a6de421d2ad1ee8f4b25e398adda9c0aaa6ab1f2518981a9ddb1de6a3957d77842332d6289dbe94e832", "b208c9235c8d40e49b76100b2d010f3783f12c66e7d3beb117b2c96321b7f6562adb4efc144e39d909e728", 65533, None, "7531646670723876647335683361756e79657a7a7877726d38756461353273743837733876726c676732746730357430713070783336686368783974676b786b6c77747370753332786a6135617271336b7470326e387a613470773779776a30676d68713372776539353072386b3973756e736a76773734743538716c3333347065673464766b616c6b746d6e676e716b7077723332353837653779747932376e6d673636747371377976723779343639776570366b7077346a3530786e6c6d78306a78786737766c6735796c6671387566657664", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 14, 0], - [None, None, None, "9e5445d6cd3cb9f98b0df1062bda47adffd5a66c0c2c483c8bf15c3176d755914a3576496b5c35fee28a88", 65531, None, "75316a676c686a326d617936646674777a39753271796e786a717a6e75743637343768617375306d646d6c63303266636173756178756764797a776a326c38346d6a3966677a6a3779306b396663706a373336736c6d6a38676b37377567386c6c61766367326c666d6d", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 15, 0], - ["b02aec10f6fa02a08667bf9b924c3d0574a1334f", None, None, "2598d84dffb34f5908b90732490f3881399150d4c694fce9bf30d1560b2c56f09829fe123b9add20e5d71c", 65534, None, "7531397163617a647761793438707566366a77616a78307732386d307871756d746d6e6435677974796c6c6e79676867396c76393978356d3872387439673566396a307a30786e34787a6d6e7866747a3772746633756164786b79367178706e6b7438666b66686c78386b63396d6e72646c6e7874733536786378656a7a6472776c65787a7637377876797634", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 16, 0], - [None, None, "d3a803803feee7a032a24adfaa8f6a94cecb9671c1333d0d5d1a3d79d82bc310727c665364d71022559c50", "7c98b8f613f9ff02746bea2a167cfd1bd3a1862af9631bf61d9d604e0824e2cb8467a1e549db87a76e7a8a", 65535, None, "75316136346c303971727378756c666a7a6e6d366b326735333575737968746166386564363076346a726a6d6b77766b757834743770647963336e6b7a7265666467746e77383432306c6a3873686d30356a6139667878676e68726139326e6873713536677838633270757a33666b6b676e726b7166357975716664746637743672616e343767646366357676646661637a7766337575793466797368336d7a7538686435746b6c30356d76726765396e38", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 17, 0], - ["26c061d67beb8bad48c6b4774a156551e30e4fe2", None, None, "a80405d5568ab8ab8f8546163d951ab297fd5e6f43e7fcebcb664feacfab5afd80aaf7f354c07a9901788c", 65535, None, "7531787a757764386163686667776d336577793976326d6a3537373268726b6e6d6578777a6339346d7a6133356d78363863656e767877727a3973396670306e39767a753872756a357a71666d6d376c65387775366c363275346c6d30376e75717865656d383733677838366a766e776c70787379636c397576366b786b72686d30726c677037307830357366", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 18, 0], - [None, None, "8660070e3757ff6507060791fd694f6a631b8495a2b74ffa39236cf653caea5575b86af3200b010e513bab", "63b7b706d991169986aee56133f0a50b2a0c8225fba6dae95176007b1f023a1e97c1aa366e99bf970fda82", 65534, None, "7531766736326d676a64646e6c763577366c646b793278653063387465746d633832747539766c7a7a6b75796e783439666e75716a76786a743564676e33636d3874356e38357a6371356c6a727467377a6d77686b3730683672646d636c6637736378786e67756b35666c76663261707037367875393037636d6a796c787673656e3235786539763776336b727378613975793076326a6a7133376b6834796d6c61666e3870657671616c716134646d3637", "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", 19, 5] + [ + "From https://github.com/zcash-hackworks/zcash-test-vectors/blob/master/unified_address.py" + ], + [ + "p2pkh_bytes, p2sh_bytes, sapling_raw_addr, orchard_raw_addr, unknown_typecode, unknown_bytes, unified_addr, root_seed, account, diversifier_index" + ], + [ + "e6cabf813929132d772d04b03ae85223d03b9be8", + None, + None, + "d4714ee761d1ae823b6972152e20957fefa3f6e3129ea4dfb0a9e98703a63dab929589d6dc51c970f935b3", + 65533, + "f6ee6921481cdd86b3cc4318d9614fc820905d042bb1ef9ca3f24988c7b3534201cfb1cd8dbf69b8250c18ef41294ca97993db546c1fe0", + "753179793677386e336a6d6a73676a39777663656e7238723570366833387679636c686d71307767396b7a70786c7534367a387636346b3567737a72387966777a346a7672796c76766733673633337a30326c756b38356e6d73636b366432736578336e3564376b6e3638687a7a3574763475647439703673793770676c6565756c76676c767832363237646666353771396665703577676478386d3065737832386d307a767578706d7779617a74336a756e3272707177386e75366a326663657167686b353563656436366a73366b366a786e387932787475653866337061716a726b3871366e70746e6e", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 0, + 0, + ], + [ + "7bec9de217c04f7ce1a86f1fb458aa881c8f39e4", + None, + None, + "d8e5ecb4e005c28718e61a5c336a4f369e771ccdb3363f4f7a04b02a966901a4c05da662d5fd75678f7fb4", + 65530, + None, + "75317a35677538783364766b7677636d726a30716b3568727839706361646c3536683834663777647970366e7635337233643563636365646563686d77393835746765357733633272353639716137326c676775753578727178683739616a7a63376b716d65733230706b747a71726a6c707835367168676d716d3536686e39777432686379787064616d616b", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 1, + 0, + ], + [ + "aa6d43480fd9d91375ce6c4a020706361bd296de", + None, + "88533c398a49c2513dc85162bf220abaf47dc983f14e908ddaaa7322dba16531bc62efe750fe575c8d149b", + None, + 65530, + None, + "7531343367706a3772643934766d39356d7a73757537746a74716161677934706d6678386c6b77656d70786a7463777a33357a746361383530796e6c7a323932307477617a6171703270367168787878337a357178616b6e73716372676c7578716a337070757367776635757963686c61677938376b376874613768773965793336776d7930367065776c6470", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 2, + 0, + ], + [ + None, + "a8d7551db5fd9313e8c7203d996af7d477083756", + "52fd6aedefbf401633c2e4532515ebcf95bcc2b4b8e4d676dfad7e17925c6dfb8671e52544dc2ca075e261", + None, + 65534, + None, + "753178797970646a307a7978637466666b6878796d766a6e6b376e383371666c376e7365356c3071726b346e3266376465376c3733727a79787970347463727975356d6b7875617a6c646e633279306479747a7567797a79636739373034616a66786173376b63757761776d706877776e383839743938743735376579716667346a766566746b687672337167", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 3, + 0, + ], + [ + None, + "f44ab023752cb5b406ed8985e18130ab33362697", + None, + "165082de84f2ad7204426ffafd6b6c7de9cab6d25c13846a1786715268c415948db788f4a5e0daa03d699e", + 65533, + None, + "7531706a336c72656d6e7175737368393878667161336a66647077303872726b35377330346b6c32366865707a7133746a72736e78653574367371716567653976716d776c63366c786373746e6333306e3575357232776b6b7a687039367a3564306a797530716137746b686378366663386a35396b616b387a35636570363261716d61336d36343566683863", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 4, + 0, + ], + [ + None, + None, + None, + "ea9df83fbee07d6f7895ebb2ea41ec7c4ba682b863e069b4a438e31c9571c83126c305d75456412aeaef1b", + 65531, + None, + "753132787567643930666c726b646b6575336e6c6e6e337565736b793533707175356d323479366170786d38386d34387637333734636c7335367a7039336e61796c617864636866307161796678747267653034376d393533717a3376326772346c74737232736b3372", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 5, + 0, + ], + [ + None, + None, + None, + "3c40246912b6efefab9a55244ac2c174e1a9f8c0bc0fd526933963c6ecb9b84ec8b0f6b40dc858fa23c72b", + 65530, + None, + "75317370757467353667736a763233637435346d7277646c616e7a7665716337747a73356d78786e616135636465676d303368673778363661797079647336356d39327674397561786c3637327375687063367a3768747776657079686b727066757376617a71756539", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 6, + 0, + ], + [ + None, + "defa3d5a57efc2e1e9b01a035587d5fb1a38e01d", + None, + "cc099cc214e56b1192c7b5b17e958c3413e27fefd553380700aca81b24b2918cac951a1a68017fac525a18", + 65535, + None, + "75317667736b636d3939783567687561757668337978713777747037756e366130793663617964736e6e33357032647577707773356873367079676a6877703738326a716e65727a6c6878773370343971666d713237383339716a7472667976686b377964393877396e3064366a6e7336756834666333687364663736366b6e74716e6c6a646b64353667636e", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 7, + 0, + ], + [ + None, + None, + None, + "5f09a9807a56323b263b05df368dc28391b21a64a0e1b40f9a6803b7e68f3905923f35cb01f119b223f493", + 65530, + None, + "75316378636379656d6d3038747964776d743968703273356e6638776a766c757575366c32653861396a666c6c647861736e7a6b6438667665727170636a30786e767261637a71673235356377356e767936783977727566666d703975657a727a72376763783535396b", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 8, + 0, + ], + [ + None, + "10acd20b183e31d49f25c9a138f49b1a537edcf0", + "9b60ae3d302248b349d601567e3d7795bfb334ea1fd1a7e71402169ebbe14bd2ceaa244ccd6e5aa2245613", + "e340636542ece1c81285ed4eab448adbb5a8c0f4d386eeff337e88e6915f6c3ec1b6ea835a88d56612d2bd", + 65531, + None, + "75317a656b68686d686b353478356365356333367274376e63323735676570376e6176326e73783473683061666c6c75703976726835687338367a38736b6a746436646e736c7667736d6174743068386832343763676e666b73646c776c39786d617275797570666c743064716673637830647979656d3266616139776571653378616b397736656672353437636a3832397232746e7974613032687866647873646a6d76397a72356b746b70323066706378656164686672683032616b346136686e7876357336377267717272766670646a7435", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 9, + 0, + ], + [ + None, + "af9db6990ed83dd64af3597c04323ea51b0052ad", + None, + "cdf7fed0d0822fd849cffb20a4d5ee701ad8141e66d81ddfabf87875117c05092240603c546b8dc187cd8c", + 65532, + None, + "753165353471636e30746570796c33307a7a326672677a37713461366d736e326530326e7076326e6666736433683532336d747838643232616a7666767371757235736a7a3876666e6d77327973363730387170386b6139306a3561343330757938763833616c6a63306330357a6a7535347879356e7677336d66686b376e7737366b6b7964796c713466656c", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 10, + 0, + ], + [ + None, + None, + None, + "24fd59f32b2d39dde66e46c39206a31bc04fa5c6847976ea6bbd3163ee14f58f584acc131479ea558d3f84", + 65530, + None, + "75317a38777372686d66366d3967766136766c33737a636b303670393730783577686d36336a666a3266726d6d63396e39756d34796373387975746a37673833387672676832306c667879353279306832367474386e6776643267796370797176396b793032716b6373", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 11, + 0, + ], + [ + None, + None, + "78d85bd0db639043377987cdd814c6390016964b684016faf1ad4f166c5f72399a5e8d469ec6beb873d55d", + None, + 65535, + None, + "75317861686a333570376d7639756c6b3337327333766465687172663438753077646633786c3772787a7270653461307468753864306d396d7961617078376b35767836747a357074636a76637675346472667137753771777a6d667565336b74387376736333736535", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 12, + 0, + ], + [ + "33a6dd87b4d872a4895d345761e4ec423b77928d", + None, + None, + "5178924f7067eac261044ca27ba3cf52f798486973af0795e61587aa1b1ecad333dc520497edc61df88980", + 65533, + "91e00c7a1d48af046827591e9733a97fa6b679f3dc601d008285edcbdae69ce8fc1be4aac00ff2711ebd931de518856878f73476f21a482ec9378365c8f7393c94e2885315eb4671098b79535e790fe53e29fef2b3766697ac32b4f473f468a008e72389fc03880d780cb07fcfaabe3f1a84b27db59a4a153d882d2b2103596555ed9494c6ac893c49723833ec8926c1", + "7531687970706c733364776d616c783373756c746b72397564763237376679716a6478307378716c746638676a6e777976343968743575327270336c6c767632756e796d7330383675616a6b6638393837636175616a7136383670356638687276393474616336663078796637796d7a3636747279366b7936726179336d6a633567786661683030637370766b3564676d67736e3737663274336775763270307861366b6c6138717479376d6b6e6b6d337a68303932306c77733633326166743071686b3532363579736c337067323237747866373461736d7075656e326c746533616a6330667a376b34736878797a656d6e7035773770336b746c6874643030366d6b61787979306d746637646a73646175397a666b657332616e387661687a6737647173677938326330707830396d39683061657a736e7936786c66706767667268656d7661786a3578747871356a6e67763076306167726c3073757079676639636574656a35323779727a7a6574386471747164616771", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 13, + 0, + ], + [ + "a56c057ef71dab58aa90e47025695c5faaea5123", + None, + "a75a6de421d2ad1ee8f4b25e398adda9c0aaa6ab1f2518981a9ddb1de6a3957d77842332d6289dbe94e832", + "b208c9235c8d40e49b76100b2d010f3783f12c66e7d3beb117b2c96321b7f6562adb4efc144e39d909e728", + 65533, + None, + "7531646670723876647335683361756e79657a7a7877726d38756461353273743837733876726c676732746730357430713070783336686368783974676b786b6c77747370753332786a6135617271336b7470326e387a613470773779776a30676d68713372776539353072386b3973756e736a76773734743538716c3333347065673464766b616c6b746d6e676e716b7077723332353837653779747932376e6d673636747371377976723779343639776570366b7077346a3530786e6c6d78306a78786737766c6735796c6671387566657664", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 14, + 0, + ], + [ + None, + None, + None, + "9e5445d6cd3cb9f98b0df1062bda47adffd5a66c0c2c483c8bf15c3176d755914a3576496b5c35fee28a88", + 65531, + None, + "75316a676c686a326d617936646674777a39753271796e786a717a6e75743637343768617375306d646d6c63303266636173756178756764797a776a326c38346d6a3966677a6a3779306b396663706a373336736c6d6a38676b37377567386c6c61766367326c666d6d", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 15, + 0, + ], + [ + "b02aec10f6fa02a08667bf9b924c3d0574a1334f", + None, + None, + "2598d84dffb34f5908b90732490f3881399150d4c694fce9bf30d1560b2c56f09829fe123b9add20e5d71c", + 65534, + None, + "7531397163617a647761793438707566366a77616a78307732386d307871756d746d6e6435677974796c6c6e79676867396c76393978356d3872387439673566396a307a30786e34787a6d6e7866747a3772746633756164786b79367178706e6b7438666b66686c78386b63396d6e72646c6e7874733536786378656a7a6472776c65787a7637377876797634", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 16, + 0, + ], + [ + None, + None, + "d3a803803feee7a032a24adfaa8f6a94cecb9671c1333d0d5d1a3d79d82bc310727c665364d71022559c50", + "7c98b8f613f9ff02746bea2a167cfd1bd3a1862af9631bf61d9d604e0824e2cb8467a1e549db87a76e7a8a", + 65535, + None, + "75316136346c303971727378756c666a7a6e6d366b326735333575737968746166386564363076346a726a6d6b77766b757834743770647963336e6b7a7265666467746e77383432306c6a3873686d30356a6139667878676e68726139326e6873713536677838633270757a33666b6b676e726b7166357975716664746637743672616e343767646366357676646661637a7766337575793466797368336d7a7538686435746b6c30356d76726765396e38", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 17, + 0, + ], + [ + "26c061d67beb8bad48c6b4774a156551e30e4fe2", + None, + None, + "a80405d5568ab8ab8f8546163d951ab297fd5e6f43e7fcebcb664feacfab5afd80aaf7f354c07a9901788c", + 65535, + None, + "7531787a757764386163686667776d336577793976326d6a3537373268726b6e6d6578777a6339346d7a6133356d78363863656e767877727a3973396670306e39767a753872756a357a71666d6d376c65387775366c363275346c6d30376e75717865656d383733677838366a766e776c70787379636c397576366b786b72686d30726c677037307830357366", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 18, + 0, + ], + [ + None, + None, + "8660070e3757ff6507060791fd694f6a631b8495a2b74ffa39236cf653caea5575b86af3200b010e513bab", + "63b7b706d991169986aee56133f0a50b2a0c8225fba6dae95176007b1f023a1e97c1aa366e99bf970fda82", + 65534, + None, + "7531766736326d676a64646e6c763577366c646b793278653063387465746d633832747539766c7a7a6b75796e783439666e75716a76786a743564676e33636d3874356e38357a6371356c6a727467377a6d77686b3730683672646d636c6637736378786e67756b35666c76663261707037367875393037636d6a796c787673656e3235786539763776336b727378613975793076326a6a7133376b6834796d6c61666e3870657671616c716134646d3637", + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f", + 19, + 5, + ], ] -class ZcashTestVector: - def __init__(self, inner): - self.inner = inner - def __getattr__(self, name): - index = TESTVECTORS[1][0].split(", ").index(name) - return self.inner[index] +class ZcashTestVector: + def __init__(self, inner): + self.inner = inner + + def __getattr__(self, name): + index = TESTVECTORS[1][0].split(", ").index(name) + return self.inner[index] def get_receivers(tv: ZcashTestVector): - receivers = dict() - if tv.p2pkh_bytes is not None: - receivers[P2PKH] = unhexlify(tv.p2pkh_bytes) - if tv.p2sh_bytes is not None: - receivers[P2SH] = unhexlify(tv.p2sh_bytes) - if tv.sapling_raw_addr is not None: - receivers[SAPLING] = unhexlify(tv.sapling_raw_addr) - if tv.orchard_raw_addr is not None: - receivers[ORCHARD] = unhexlify(tv.orchard_raw_addr) - if tv.unknown_bytes is not None: - receivers[tv.unknown_typecode] = unhexlify(tv.unknown_bytes) + receivers = dict() + if tv.p2pkh_bytes is not None: + receivers[P2PKH] = unhexlify(tv.p2pkh_bytes) + if tv.p2sh_bytes is not None: + receivers[P2SH] = unhexlify(tv.p2sh_bytes) + if tv.sapling_raw_addr is not None: + receivers[SAPLING] = unhexlify(tv.sapling_raw_addr) + if tv.orchard_raw_addr is not None: + receivers[ORCHARD] = unhexlify(tv.orchard_raw_addr) + if tv.unknown_bytes is not None: + receivers[tv.unknown_typecode] = unhexlify(tv.unknown_bytes) - return receivers + return receivers COIN = coininfo.by_name("Zcash") @@ -63,18 +288,18 @@ COIN = coininfo.by_name("Zcash") @unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin") class TestZcashAddress(unittest.TestCase): - def test_encode_unified(self): - for tv in map(ZcashTestVector, TESTVECTORS[2:]): - receivers = get_receivers(tv) - ua = unified_addresses.encode(receivers, COIN) - self.assertEqual(ua, unhexlify(tv.unified_addr).decode()) + def test_encode_unified(self): + for tv in map(ZcashTestVector, TESTVECTORS[2:]): + receivers = get_receivers(tv) + ua = unified_addresses.encode(receivers, COIN) + self.assertEqual(ua, unhexlify(tv.unified_addr).decode()) - def test_decode_unified(self): - for tv in map(ZcashTestVector, TESTVECTORS[2:]): - address = unhexlify(tv.unified_addr).decode() - receivers = unified_addresses.decode(address, COIN) - self.assertEqual(receivers, get_receivers(tv)) + def test_decode_unified(self): + for tv in map(ZcashTestVector, TESTVECTORS[2:]): + address = unhexlify(tv.unified_addr).decode() + receivers = unified_addresses.decode(address, COIN) + self.assertEqual(receivers, get_receivers(tv)) -if __name__ == '__main__': - unittest.main() +if __name__ == "__main__": + unittest.main() diff --git a/core/tests/test_apps.zcash.zip244.py b/core/tests/test_apps.zcash.zip244.py index b55018eaee..d443cc9245 100644 --- a/core/tests/test_apps.zcash.zip244.py +++ b/core/tests/test_apps.zcash.zip244.py @@ -44,57 +44,89 @@ class TestZcashSigHasher(unittest.TestCase): ) inputs = [ TxInput( - prev_hash=unhexlify("4f61d91843ccb386dd1c482169eef62efaaf9d9364b1666e4d4c299e04a852e1"), + prev_hash=unhexlify( + "4f61d91843ccb386dd1c482169eef62efaaf9d9364b1666e4d4c299e04a852e1" + ), prev_index=1569726664, multisig=None, amount=1249971475008092, script_type=InputScriptType.SPENDADDRESS, - sequence=0x8849f2a3, - script_pubkey=unhexlify("76a9149466817faf329208fc3c3ef42ce4513d22fc1f9b88ac"), + sequence=0x8849F2A3, + script_pubkey=unhexlify( + "76a9149466817faf329208fc3c3ef42ce4513d22fc1f9b88ac" + ), ), TxInput( - prev_hash=unhexlify("368e9c7e1fe01f6c54db9379a94c2941ef180c25b869bf8dcdb1cf014253b3c7"), + prev_hash=unhexlify( + "368e9c7e1fe01f6c54db9379a94c2941ef180c25b869bf8dcdb1cf014253b3c7" + ), prev_index=2648876502, multisig=None, amount=1353789347081201, script_type=InputScriptType.SPENDADDRESS, - sequence=0x8a37691c, - script_pubkey=unhexlify("76a9142275979f97043edd9a6083ee27d136727ce5f42888ac"), + sequence=0x8A37691C, + script_pubkey=unhexlify( + "76a9142275979f97043edd9a6083ee27d136727ce5f42888ac" + ), ), TxInput( - prev_hash=unhexlify("f5621d6ad566c13dce81632a9168694bb6bcec2f7bfac2626f9425e1640fe4f1"), + prev_hash=unhexlify( + "f5621d6ad566c13dce81632a9168694bb6bcec2f7bfac2626f9425e1640fe4f1" + ), prev_index=492165032, multisig=None, amount=1672802384749611, script_type=InputScriptType.SPENDADDRESS, - sequence=0x6a993d20, - script_pubkey=unhexlify("76a914682c89bfc3940621bd4a4bfc349a79b46ce707e388ac"), + sequence=0x6A993D20, + script_pubkey=unhexlify( + "76a914682c89bfc3940621bd4a4bfc349a79b46ce707e388ac" + ), ), ] outputs = [ PrevOutput( amount=865034086766210, - script_pubkey=unhexlify("76a9140d06a745f44ab023752cb5b406ed8985e18130ab88ac"), + script_pubkey=unhexlify( + "76a9140d06a745f44ab023752cb5b406ed8985e18130ab88ac" + ), ), PrevOutput( amount=2088955338922857, - script_pubkey=unhexlify("76a91463ccb8f676495c222f7fba1e31defa3d5a57efc288ac"), + script_pubkey=unhexlify( + "76a91463ccb8f676495c222f7fba1e31defa3d5a57efc288ac" + ), ), PrevOutput( amount=1760123755646275, - script_pubkey=unhexlify("76a914fb1a38e01d94903d3c3e0ad3360c1d3710acd20b88ac"), + script_pubkey=unhexlify( + "76a914fb1a38e01d94903d3c3e0ad3360c1d3710acd20b88ac" + ), ), ] pubkeys = [ - unhexlify("02ed9c769c787fda78a7da13764707d14217e74e26428b47a2a8fe6d5a0bc46196"), - unhexlify("0219ac5de9a45f76e7efede5259acd94bb047ab8e7cc60fe844cb32317072ebbf3"), - unhexlify("02829099a7cf1f617c956c0222e7b77ae331813d6a736eab3c5f6344d961843d39"), + unhexlify( + "02ed9c769c787fda78a7da13764707d14217e74e26428b47a2a8fe6d5a0bc46196" + ), + unhexlify( + "0219ac5de9a45f76e7efede5259acd94bb047ab8e7cc60fe844cb32317072ebbf3" + ), + unhexlify( + "02829099a7cf1f617c956c0222e7b77ae331813d6a736eab3c5f6344d961843d39" + ), ] - expected_txid = unhexlify("c91d34ecc44484b07ee573f385d80e57e4e57571bb86aa6ec6c44d654123e4e9") + expected_txid = unhexlify( + "c91d34ecc44484b07ee573f385d80e57e4e57571bb86aa6ec6c44d654123e4e9" + ) expected_sighashes = [ - unhexlify("4d82669c8c0e9b1f26d59bcb347212f2d044eeb839fce21e039d8bb082bbc343"), - unhexlify("2e2a27d78d117e28760d3c972f9614547ec57688c970f06c19c515cded6b030c"), - unhexlify("d0a92ffd4a4d262f5b84598bcfca741a42c17b8e9d26cf4fd87839df8f33e4ee"), + unhexlify( + "4d82669c8c0e9b1f26d59bcb347212f2d044eeb839fce21e039d8bb082bbc343" + ), + unhexlify( + "2e2a27d78d117e28760d3c972f9614547ec57688c970f06c19c515cded6b030c" + ), + unhexlify( + "d0a92ffd4a4d262f5b84598bcfca741a42c17b8e9d26cf4fd87839df8f33e4ee" + ), ] hasher = ZcashHasher(tx) @@ -109,9 +141,7 @@ class TestZcashSigHasher(unittest.TestCase): # test ZcashSigHasher.signature_digest for txi, expected_sighash, pk in zip(inputs, expected_sighashes, pubkeys): - computed_sighash = hasher.signature_digest( - txi, txi.script_pubkey - ) + computed_sighash = hasher.signature_digest(txi, txi.script_pubkey) self.assertEqual(computed_sighash, expected_sighash) diff --git a/core/tests/test_storage.py b/core/tests/test_storage.py index f7a936ba8c..ee76e0a572 100644 --- a/core/tests/test_storage.py +++ b/core/tests/test_storage.py @@ -4,7 +4,6 @@ from storage import device class TestConfig(unittest.TestCase): - def test_counter(self): config.init() config.wipe() @@ -17,5 +16,5 @@ class TestConfig(unittest.TestCase): self.assertEqual(device.next_u2f_counter(), 1) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.config.py b/core/tests/test_trezor.config.py index c173976910..201cfcf38c 100644 --- a/core/tests/test_trezor.config.py +++ b/core/tests/test_trezor.config.py @@ -17,7 +17,6 @@ def random_entry(): class TestConfig(unittest.TestCase): - def test_init(self): config.init() config.init() @@ -26,13 +25,13 @@ class TestConfig(unittest.TestCase): def test_wipe(self): config.init() config.wipe() - self.assertEqual(config.unlock('', None), True) - config.set(1, 1, b'hello') - config.set(1, 2, b'world') + self.assertEqual(config.unlock("", None), True) + config.set(1, 1, b"hello") + config.set(1, 2, b"world") v0 = config.get(1, 1) v1 = config.get(1, 2) - self.assertEqual(v0, b'hello') - self.assertEqual(v1, b'world') + self.assertEqual(v0, b"hello") + self.assertEqual(v1, b"world") config.wipe() v0 = config.get(1, 1) v1 = config.get(1, 2) @@ -43,7 +42,7 @@ class TestConfig(unittest.TestCase): for _ in range(128): config.init() config.wipe() - self.assertEqual(config.unlock('', None), True) + self.assertEqual(config.unlock("", None), True) appid, key = random_entry() value = random.bytes(16) config.set(appid, key, value) @@ -57,7 +56,7 @@ class TestConfig(unittest.TestCase): def test_public(self): config.init() config.wipe() - self.assertEqual(config.unlock('', None), True) + self.assertEqual(config.unlock("", None), True) appid, key = random_entry() @@ -83,26 +82,32 @@ class TestConfig(unittest.TestCase): def test_change_pin(self): config.init() config.wipe() - self.assertTrue(config.unlock('', None)) - config.set(1, 1, b'value') - PINS = ('123', '123', 'Trezor T', '3141592653589793238462643383279502884197', '') - old_pin = '' + self.assertTrue(config.unlock("", None)) + config.set(1, 1, b"value") + PINS = ( + "123", + "123", + "Trezor T", + "3141592653589793238462643383279502884197", + "", + ) + old_pin = "" for new_pin in PINS: self.assertTrue(config.unlock(old_pin, None)) # The APP namespace which is reserved for storage related values is inaccessible even # when unlocked. with self.assertRaises(ValueError): - config.set(PINAPP, PINKEY, b'value') + config.set(PINAPP, PINKEY, b"value") self.assertTrue(config.change_pin(old_pin, new_pin, None, None)) # Old PIN cannot be used to change the current PIN. if old_pin != new_pin: - self.assertFalse(config.change_pin(old_pin, '666', None, None)) + self.assertFalse(config.change_pin(old_pin, "666", None, None)) # Storage remains unlocked. - self.assertEqual(config.get(1, 1), b'value') + self.assertEqual(config.get(1, 1), b"value") # The APP namespace which is reserved for storage related values is inaccessible even # when unlocked. @@ -115,11 +120,11 @@ class TestConfig(unittest.TestCase): self.assertFalse(config.unlock(old_pin, None)) self.assertEqual(config.get(1, 1), None) with self.assertRaises(RuntimeError): - config.set(1, 1, b'new value') + config.set(1, 1, b"new value") # New PIN unlocks the storage. self.assertTrue(config.unlock(new_pin, None)) - self.assertEqual(config.get(1, 1), b'value') + self.assertEqual(config.get(1, 1), b"value") # Lock the storage. config.init() @@ -132,37 +137,37 @@ class TestConfig(unittest.TestCase): # Enable PIN and SD salt. config.init() config.wipe() - self.assertTrue(config.unlock('', None)) - config.set(1, 1, b'value') - self.assertFalse(config.change_pin('', '', salt1, None)) - self.assertTrue(config.change_pin('', '000', None, salt1)) - self.assertEqual(config.get(1, 1), b'value') + self.assertTrue(config.unlock("", None)) + config.set(1, 1, b"value") + self.assertFalse(config.change_pin("", "", salt1, None)) + self.assertTrue(config.change_pin("", "000", None, salt1)) + self.assertEqual(config.get(1, 1), b"value") # Disable PIN and change SD salt. config.init() - self.assertFalse(config.unlock('000', None)) + self.assertFalse(config.unlock("000", None)) self.assertIsNone(config.get(1, 1)) - self.assertTrue(config.unlock('000', salt1)) - self.assertTrue(config.change_pin('000', '', salt1, salt2)) - self.assertEqual(config.get(1, 1), b'value') + self.assertTrue(config.unlock("000", salt1)) + self.assertTrue(config.change_pin("000", "", salt1, salt2)) + self.assertEqual(config.get(1, 1), b"value") # Disable SD salt. config.init() - self.assertFalse(config.unlock('000', salt2)) + self.assertFalse(config.unlock("000", salt2)) self.assertIsNone(config.get(1, 1)) - self.assertTrue(config.unlock('', salt2)) - self.assertTrue(config.change_pin('', '', salt2, None)) - self.assertEqual(config.get(1, 1), b'value') + self.assertTrue(config.unlock("", salt2)) + self.assertTrue(config.change_pin("", "", salt2, None)) + self.assertEqual(config.get(1, 1), b"value") # Check that PIN and SD salt are disabled. config.init() - self.assertTrue(config.unlock('', None)) - self.assertEqual(config.get(1, 1), b'value') + self.assertTrue(config.unlock("", None)) + self.assertEqual(config.get(1, 1), b"value") def test_set_get(self): config.init() config.wipe() - self.assertEqual(config.unlock('', None), True) + self.assertEqual(config.unlock("", None), True) for _ in range(32): appid, key = random_entry() value = random.bytes(128) @@ -178,13 +183,13 @@ class TestConfig(unittest.TestCase): # Test get/set for APP out ouf range. with self.assertRaises(ValueError): - config.set(0, 1, b'test') + config.set(0, 1, b"test") with self.assertRaises(ValueError): config.get(0, 1) with self.assertRaises(ValueError): - config.set(192, 1, b'test') + config.set(192, 1, b"test") with self.assertRaises(ValueError): config.get(192, 1) @@ -209,7 +214,7 @@ class TestConfig(unittest.TestCase): # Test increment with storage unlocked. - self.assertEqual(config.unlock('', None), True) + self.assertEqual(config.unlock("", None), True) for i in range(200, 300): self.assertEqual(config.next_counter(1, 2, True), i + 1) @@ -235,7 +240,7 @@ class TestConfig(unittest.TestCase): def test_compact(self): config.init() config.wipe() - self.assertEqual(config.unlock('', None), True) + self.assertEqual(config.unlock("", None), True) appid, key = 1, 1 for _ in range(259): value = random.bytes(259) @@ -246,12 +251,12 @@ class TestConfig(unittest.TestCase): def test_get_default(self): config.init() config.wipe() - self.assertEqual(config.unlock('', None), True) + self.assertEqual(config.unlock("", None), True) for _ in range(128): appid, key = random_entry() value = config.get(appid, key) self.assertEqual(value, None) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.base32.py b/core/tests/test_trezor.crypto.base32.py index a651b7d4dd..4d62b5ecca 100644 --- a/core/tests/test_trezor.crypto.base32.py +++ b/core/tests/test_trezor.crypto.base32.py @@ -8,29 +8,29 @@ class TestCryptoBase32(unittest.TestCase): # https://tools.ietf.org/html/rfc4648 # https://github.com/emn178/hi-base32/blob/master/tests/test.js vectors = [ - (b'', ''), - (b'f', 'MY======'), - (b'fo', 'MZXQ===='), - (b'foo', 'MZXW6==='), - (b'foob', 'MZXW6YQ='), - (b'fooba', 'MZXW6YTB'), - (b'foobar', 'MZXW6YTBOI======'), - - (b'H', 'JA======'), - (b'He', 'JBSQ===='), - (b'Hel', 'JBSWY==='), - (b'Hell', 'JBSWY3A='), - (b'Hello', 'JBSWY3DP'), - - (b'zlutoucky kun upel dabelske ody', 'PJWHK5DPOVRWW6JANN2W4IDVOBSWYIDEMFRGK3DTNNSSA33EPE======'), - - (b'中文', '4S4K3ZUWQ4======'), # noqa:E999 - (b'中文1', '4S4K3ZUWQ4YQ===='), # noqa:E999 - (b'中文12', '4S4K3ZUWQ4YTE==='), # noqa:E999 - (b'aécio', 'MHB2SY3JN4======'), # noqa:E999 - (b'𠜎', '6CQJZDQ='), # noqa:E999 - (b'Base64是一種基於64個可列印字元來表示二進制資料的表示方法', # noqa:E999 - 'IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V') + (b"", ""), + (b"f", "MY======"), + (b"fo", "MZXQ===="), + (b"foo", "MZXW6==="), + (b"foob", "MZXW6YQ="), + (b"fooba", "MZXW6YTB"), + (b"foobar", "MZXW6YTBOI======"), + (b"H", "JA======"), + (b"He", "JBSQ===="), + (b"Hel", "JBSWY==="), + (b"Hell", "JBSWY3A="), + (b"Hello", "JBSWY3DP"), + ( + b"zlutoucky kun upel dabelske ody", + "PJWHK5DPOVRWW6JANN2W4IDVOBSWYIDEMFRGK3DTNNSSA33EPE======", + ), + (b"中文", "4S4K3ZUWQ4======"), # noqa:E999 + (b"中文1", "4S4K3ZUWQ4YQ===="), # noqa:E999 + (b"中文12", "4S4K3ZUWQ4YTE==="), # noqa:E999 + (b"aécio", "MHB2SY3JN4======"), # noqa:E999 + (b"𠜎", "6CQJZDQ="), # noqa:E999 + (b"Base64是一種基於64個可列印字元來表示二進制資料的表示方法", # noqa:E999 + "IJQXGZJWGTTJRL7EXCAOPKFO4WP3VZUWXQ3DJZMARPSY7L7FRCL6LDNQ4WWZPZMFQPSL5BXIUGUOPJF24S5IZ2MAWLSYRNXIWOD6NFUZ46NIJ2FBVDT2JOXGS246NM4V") ] def test_encode(self): @@ -42,5 +42,5 @@ class TestCryptoBase32(unittest.TestCase): self.assertEqual(base32.decode(b), a) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.base58.py b/core/tests/test_trezor.crypto.base58.py index bc4f7d672f..e17c1a90f8 100644 --- a/core/tests/test_trezor.crypto.base58.py +++ b/core/tests/test_trezor.crypto.base58.py @@ -13,77 +13,243 @@ class TestCryptoBase58(unittest.TestCase): # vectors from https://github.com/bitcoin/bitcoin/blob/master/src/test/data/base58_keys_valid.json vectors = [ - ('0065a16059864a2fdbc7c99a4723a8395bc6f188eb', '1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i'), - ('0574f209f6ea907e2ea48f74fae05782ae8a665257', '3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou'), - ('6f53c0307d6851aa0ce7825ba883c6bd9ad242b486', 'mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs'), - ('c46349a418fc4578d10a372b54b45c280cc8c4382f', '2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br'), - ('80eddbdc1168f1daeadbd3e44c1e3f8f5a284c2029f78ad26af98583a499de5b19', '5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr'), - ('8055c9bccb9ed68446d1b75273bbce89d7fe013a8acd1625514420fb2aca1a21c401', 'Kz6UJmQACJmLtaQj5A3JAge4kVTNQ8gbvXuwbmCj7bsaabudb3RD'), - ('ef36cb93b9ab1bdabf7fb9f2c04f1b9cc879933530ae7842398eef5a63a56800c2', '9213qJab2HNEpMpYNBa7wHGFKKbkDn24jpANDs2huN3yi4J11ko'), - ('efb9f4892c9e8282028fea1d2667c4dc5213564d41fc5783896a0d843fc15089f301', 'cTpB4YiyKiBcPxnefsDpbnDxFDffjqJob8wGCEDXxgQ7zQoMXJdH'), - ('006d23156cbbdcc82a5a47eee4c2c7c583c18b6bf4', '1Ax4gZtb7gAit2TivwejZHYtNNLT18PUXJ'), - ('05fcc5460dd6e2487c7d75b1963625da0e8f4c5975', '3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy'), - ('6ff1d470f9b02370fdec2e6b708b08ac431bf7a5f7', 'n3ZddxzLvAY9o7184TB4c6FJasAybsw4HZ'), - ('c4c579342c2c4c9220205e2cdc285617040c924a0a', '2NBFNJTktNa7GZusGbDbGKRZTxdK9VVez3n'), - ('80a326b95ebae30164217d7a7f57d72ab2b54e3be64928a19da0210b9568d4015e', '5K494XZwps2bGyeL71pWid4noiSNA2cfCibrvRWqcHSptoFn7rc'), - ('807d998b45c219a1e38e99e7cbd312ef67f77a455a9b50c730c27f02c6f730dfb401', 'L1RrrnXkcKut5DEMwtDthjwRcTTwED36thyL1DebVrKuwvohjMNi'), - ('efd6bca256b5abc5602ec2e1c121a08b0da2556587430bcf7e1898af2224885203', '93DVKyFYwSN6wEo3E2fCrFPUp17FtrtNi2Lf7n4G3garFb16CRj'), - ('efa81ca4e8f90181ec4b61b6a7eb998af17b2cb04de8a03b504b9e34c4c61db7d901', 'cTDVKtMGVYWTHCb1AFjmVbEbWjvKpKqKgMaR3QJxToMSQAhmCeTN'), - ('007987ccaa53d02c8873487ef919677cd3db7a6912', '1C5bSj1iEGUgSTbziymG7Cn18ENQuT36vv'), - ('0563bcc565f9e68ee0189dd5cc67f1b0e5f02f45cb', '3AnNxabYGoTxYiTEZwFEnerUoeFXK2Zoks'), - ('6fef66444b5b17f14e8fae6e7e19b045a78c54fd79', 'n3LnJXCqbPjghuVs8ph9CYsAe4Sh4j97wk'), - ('c4c3e55fceceaa4391ed2a9677f4a4d34eacd021a0', '2NB72XtkjpnATMggui83aEtPawyyKvnbX2o'), - ('80e75d936d56377f432f404aabb406601f892fd49da90eb6ac558a733c93b47252', '5KaBW9vNtWNhc3ZEDyNCiXLPdVPHCikRxSBWwV9NrpLLa4LsXi9'), - ('808248bd0375f2f75d7e274ae544fb920f51784480866b102384190b1addfbaa5c01', 'L1axzbSyynNYA8mCAhzxkipKkfHtAXYF4YQnhSKcLV8YXA874fgT'), - ('ef44c4f6a096eac5238291a94cc24c01e3b19b8d8cef72874a079e00a242237a52', '927CnUkUbasYtDwYwVn2j8GdTuACNnKkjZ1rpZd2yBB1CLcnXpo'), - ('efd1de707020a9059d6d3abaf85e17967c6555151143db13dbb06db78df0f15c6901', 'cUcfCMRjiQf85YMzzQEk9d1s5A4K7xL5SmBCLrezqXFuTVefyhY7'), - ('00adc1cc2081a27206fae25792f28bbc55b831549d', '1Gqk4Tv79P91Cc1STQtU3s1W6277M2CVWu'), - ('05188f91a931947eddd7432d6e614387e32b244709', '33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk'), - ('6f1694f5bc1a7295b600f40018a618a6ea48eeb498', 'mhaMcBxNh5cqXm4aTQ6EcVbKtfL6LGyK2H'), - ('c43b9b3fd7a50d4f08d1a5b0f62f644fa7115ae2f3', '2MxgPqX1iThW3oZVk9KoFcE5M4JpiETssVN'), - ('80091035445ef105fa1bb125eccfb1882f3fe69592265956ade751fd095033d8d0', '5HtH6GdcwCJA4ggWEL1B3jzBBUB8HPiBi9SBc5h9i4Wk4PSeApR'), - ('80ab2b4bcdfc91d34dee0ae2a8c6b6668dadaeb3a88b9859743156f462325187af01', 'L2xSYmMeVo3Zek3ZTsv9xUrXVAmrWxJ8Ua4cw8pkfbQhcEFhkXT8'), - ('efb4204389cef18bbe2b353623cbf93e8678fbc92a475b664ae98ed594e6cf0856', '92xFEve1Z9N8Z641KQQS7ByCSb8kGjsDzw6fAmjHN1LZGKQXyMq'), - ('efe7b230133f1b5489843260236b06edca25f66adb1be455fbd38d4010d48faeef01', 'cVM65tdYu1YK37tNoAyGoJTR13VBYFva1vg9FLuPAsJijGvG6NEA'), - ('00c4c1b72491ede1eedaca00618407ee0b772cad0d', '1JwMWBVLtiqtscbaRHai4pqHokhFCbtoB4'), - ('05f6fe69bcb548a829cce4c57bf6fff8af3a5981f9', '3QCzvfL4ZRvmJFiWWBVwxfdaNBT8EtxB5y'), - ('6f261f83568a098a8638844bd7aeca039d5f2352c0', 'mizXiucXRCsEriQCHUkCqef9ph9qtPbZZ6'), - ('c4e930e1834a4d234702773951d627cce82fbb5d2e', '2NEWDzHWwY5ZZp8CQWbB7ouNMLqCia6YRda'), - ('80d1fab7ab7385ad26872237f1eb9789aa25cc986bacc695e07ac571d6cdac8bc0', '5KQmDryMNDcisTzRp3zEq9e4awRmJrEVU1j5vFRTKpRNYPqYrMg'), - ('80b0bbede33ef254e8376aceb1510253fc3550efd0fcf84dcd0c9998b288f166b301', 'L39Fy7AC2Hhj95gh3Yb2AU5YHh1mQSAHgpNixvm27poizcJyLtUi'), - ('ef037f4192c630f399d9271e26c575269b1d15be553ea1a7217f0cb8513cef41cb', '91cTVUcgydqyZLgaANpf1fvL55FH53QMm4BsnCADVNYuWuqdVys'), - ('ef6251e205e8ad508bab5596bee086ef16cd4b239e0cc0c5d7c4e6035441e7d5de01', 'cQspfSzsgLeiJGB2u8vrAiWpCU4MxUT6JseWo2SjXy4Qbzn2fwDw'), - ('005eadaf9bb7121f0f192561a5a62f5e5f54210292', '19dcawoKcZdQz365WpXWMhX6QCUpR9SY4r'), - ('053f210e7277c899c3a155cc1c90f4106cbddeec6e', '37Sp6Rv3y4kVd1nQ1JV5pfqXccHNyZm1x3'), - ('6fc8a3c2a09a298592c3e180f02487cd91ba3400b5', 'myoqcgYiehufrsnnkqdqbp69dddVDMopJu'), - ('c499b31df7c9068d1481b596578ddbb4d3bd90baeb', '2N7FuwuUuoTBrDFdrAZ9KxBmtqMLxce9i1C'), - ('80c7666842503db6dc6ea061f092cfb9c388448629a6fe868d068c42a488b478ae', '5KL6zEaMtPRXZKo1bbMq7JDjjo1bJuQcsgL33je3oY8uSJCR5b4'), - ('8007f0803fc5399e773555ab1e8939907e9badacc17ca129e67a2f5f2ff84351dd01', 'KwV9KAfwbwt51veZWNscRTeZs9CKpojyu1MsPnaKTF5kz69H1UN2'), - ('efea577acfb5d1d14d3b7b195c321566f12f87d2b77ea3a53f68df7ebf8604a801', '93N87D6uxSBzwXvpokpzg8FFmfQPmvX4xHoWQe3pLdYpbiwT5YV'), - ('ef0b3b34f0958d8a268193a9814da92c3e8b58b4a4378a542863e34ac289cd830c01', 'cMxXusSihaX58wpJ3tNuuUcZEQGt6DKJ1wEpxys88FFaQCYjku9h'), - ('001ed467017f043e91ed4c44b4e8dd674db211c4e6', '13p1ijLwsnrcuyqcTvJXkq2ASdXqcnEBLE'), - ('055ece0cadddc415b1980f001785947120acdb36fc', '3ALJH9Y951VCGcVZYAdpA3KchoP9McEj1G'), + ( + "0065a16059864a2fdbc7c99a4723a8395bc6f188eb", + "1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", + ), + ( + "0574f209f6ea907e2ea48f74fae05782ae8a665257", + "3CMNFxN1oHBc4R1EpboAL5yzHGgE611Xou", + ), + ( + "6f53c0307d6851aa0ce7825ba883c6bd9ad242b486", + "mo9ncXisMeAoXwqcV5EWuyncbmCcQN4rVs", + ), + ( + "c46349a418fc4578d10a372b54b45c280cc8c4382f", + "2N2JD6wb56AfK4tfmM6PwdVmoYk2dCKf4Br", + ), + ( + "80eddbdc1168f1daeadbd3e44c1e3f8f5a284c2029f78ad26af98583a499de5b19", + "5Kd3NBUAdUnhyzenEwVLy9pBKxSwXvE9FMPyR4UKZvpe6E3AgLr", + ), + ( + "8055c9bccb9ed68446d1b75273bbce89d7fe013a8acd1625514420fb2aca1a21c401", + "Kz6UJmQACJmLtaQj5A3JAge4kVTNQ8gbvXuwbmCj7bsaabudb3RD", + ), + ( + "ef36cb93b9ab1bdabf7fb9f2c04f1b9cc879933530ae7842398eef5a63a56800c2", + "9213qJab2HNEpMpYNBa7wHGFKKbkDn24jpANDs2huN3yi4J11ko", + ), + ( + "efb9f4892c9e8282028fea1d2667c4dc5213564d41fc5783896a0d843fc15089f301", + "cTpB4YiyKiBcPxnefsDpbnDxFDffjqJob8wGCEDXxgQ7zQoMXJdH", + ), + ( + "006d23156cbbdcc82a5a47eee4c2c7c583c18b6bf4", + "1Ax4gZtb7gAit2TivwejZHYtNNLT18PUXJ", + ), + ( + "05fcc5460dd6e2487c7d75b1963625da0e8f4c5975", + "3QjYXhTkvuj8qPaXHTTWb5wjXhdsLAAWVy", + ), + ( + "6ff1d470f9b02370fdec2e6b708b08ac431bf7a5f7", + "n3ZddxzLvAY9o7184TB4c6FJasAybsw4HZ", + ), + ( + "c4c579342c2c4c9220205e2cdc285617040c924a0a", + "2NBFNJTktNa7GZusGbDbGKRZTxdK9VVez3n", + ), + ( + "80a326b95ebae30164217d7a7f57d72ab2b54e3be64928a19da0210b9568d4015e", + "5K494XZwps2bGyeL71pWid4noiSNA2cfCibrvRWqcHSptoFn7rc", + ), + ( + "807d998b45c219a1e38e99e7cbd312ef67f77a455a9b50c730c27f02c6f730dfb401", + "L1RrrnXkcKut5DEMwtDthjwRcTTwED36thyL1DebVrKuwvohjMNi", + ), + ( + "efd6bca256b5abc5602ec2e1c121a08b0da2556587430bcf7e1898af2224885203", + "93DVKyFYwSN6wEo3E2fCrFPUp17FtrtNi2Lf7n4G3garFb16CRj", + ), + ( + "efa81ca4e8f90181ec4b61b6a7eb998af17b2cb04de8a03b504b9e34c4c61db7d901", + "cTDVKtMGVYWTHCb1AFjmVbEbWjvKpKqKgMaR3QJxToMSQAhmCeTN", + ), + ( + "007987ccaa53d02c8873487ef919677cd3db7a6912", + "1C5bSj1iEGUgSTbziymG7Cn18ENQuT36vv", + ), + ( + "0563bcc565f9e68ee0189dd5cc67f1b0e5f02f45cb", + "3AnNxabYGoTxYiTEZwFEnerUoeFXK2Zoks", + ), + ( + "6fef66444b5b17f14e8fae6e7e19b045a78c54fd79", + "n3LnJXCqbPjghuVs8ph9CYsAe4Sh4j97wk", + ), + ( + "c4c3e55fceceaa4391ed2a9677f4a4d34eacd021a0", + "2NB72XtkjpnATMggui83aEtPawyyKvnbX2o", + ), + ( + "80e75d936d56377f432f404aabb406601f892fd49da90eb6ac558a733c93b47252", + "5KaBW9vNtWNhc3ZEDyNCiXLPdVPHCikRxSBWwV9NrpLLa4LsXi9", + ), + ( + "808248bd0375f2f75d7e274ae544fb920f51784480866b102384190b1addfbaa5c01", + "L1axzbSyynNYA8mCAhzxkipKkfHtAXYF4YQnhSKcLV8YXA874fgT", + ), + ( + "ef44c4f6a096eac5238291a94cc24c01e3b19b8d8cef72874a079e00a242237a52", + "927CnUkUbasYtDwYwVn2j8GdTuACNnKkjZ1rpZd2yBB1CLcnXpo", + ), + ( + "efd1de707020a9059d6d3abaf85e17967c6555151143db13dbb06db78df0f15c6901", + "cUcfCMRjiQf85YMzzQEk9d1s5A4K7xL5SmBCLrezqXFuTVefyhY7", + ), + ( + "00adc1cc2081a27206fae25792f28bbc55b831549d", + "1Gqk4Tv79P91Cc1STQtU3s1W6277M2CVWu", + ), + ( + "05188f91a931947eddd7432d6e614387e32b244709", + "33vt8ViH5jsr115AGkW6cEmEz9MpvJSwDk", + ), + ( + "6f1694f5bc1a7295b600f40018a618a6ea48eeb498", + "mhaMcBxNh5cqXm4aTQ6EcVbKtfL6LGyK2H", + ), + ( + "c43b9b3fd7a50d4f08d1a5b0f62f644fa7115ae2f3", + "2MxgPqX1iThW3oZVk9KoFcE5M4JpiETssVN", + ), + ( + "80091035445ef105fa1bb125eccfb1882f3fe69592265956ade751fd095033d8d0", + "5HtH6GdcwCJA4ggWEL1B3jzBBUB8HPiBi9SBc5h9i4Wk4PSeApR", + ), + ( + "80ab2b4bcdfc91d34dee0ae2a8c6b6668dadaeb3a88b9859743156f462325187af01", + "L2xSYmMeVo3Zek3ZTsv9xUrXVAmrWxJ8Ua4cw8pkfbQhcEFhkXT8", + ), + ( + "efb4204389cef18bbe2b353623cbf93e8678fbc92a475b664ae98ed594e6cf0856", + "92xFEve1Z9N8Z641KQQS7ByCSb8kGjsDzw6fAmjHN1LZGKQXyMq", + ), + ( + "efe7b230133f1b5489843260236b06edca25f66adb1be455fbd38d4010d48faeef01", + "cVM65tdYu1YK37tNoAyGoJTR13VBYFva1vg9FLuPAsJijGvG6NEA", + ), + ( + "00c4c1b72491ede1eedaca00618407ee0b772cad0d", + "1JwMWBVLtiqtscbaRHai4pqHokhFCbtoB4", + ), + ( + "05f6fe69bcb548a829cce4c57bf6fff8af3a5981f9", + "3QCzvfL4ZRvmJFiWWBVwxfdaNBT8EtxB5y", + ), + ( + "6f261f83568a098a8638844bd7aeca039d5f2352c0", + "mizXiucXRCsEriQCHUkCqef9ph9qtPbZZ6", + ), + ( + "c4e930e1834a4d234702773951d627cce82fbb5d2e", + "2NEWDzHWwY5ZZp8CQWbB7ouNMLqCia6YRda", + ), + ( + "80d1fab7ab7385ad26872237f1eb9789aa25cc986bacc695e07ac571d6cdac8bc0", + "5KQmDryMNDcisTzRp3zEq9e4awRmJrEVU1j5vFRTKpRNYPqYrMg", + ), + ( + "80b0bbede33ef254e8376aceb1510253fc3550efd0fcf84dcd0c9998b288f166b301", + "L39Fy7AC2Hhj95gh3Yb2AU5YHh1mQSAHgpNixvm27poizcJyLtUi", + ), + ( + "ef037f4192c630f399d9271e26c575269b1d15be553ea1a7217f0cb8513cef41cb", + "91cTVUcgydqyZLgaANpf1fvL55FH53QMm4BsnCADVNYuWuqdVys", + ), + ( + "ef6251e205e8ad508bab5596bee086ef16cd4b239e0cc0c5d7c4e6035441e7d5de01", + "cQspfSzsgLeiJGB2u8vrAiWpCU4MxUT6JseWo2SjXy4Qbzn2fwDw", + ), + ( + "005eadaf9bb7121f0f192561a5a62f5e5f54210292", + "19dcawoKcZdQz365WpXWMhX6QCUpR9SY4r", + ), + ( + "053f210e7277c899c3a155cc1c90f4106cbddeec6e", + "37Sp6Rv3y4kVd1nQ1JV5pfqXccHNyZm1x3", + ), + ( + "6fc8a3c2a09a298592c3e180f02487cd91ba3400b5", + "myoqcgYiehufrsnnkqdqbp69dddVDMopJu", + ), + ( + "c499b31df7c9068d1481b596578ddbb4d3bd90baeb", + "2N7FuwuUuoTBrDFdrAZ9KxBmtqMLxce9i1C", + ), + ( + "80c7666842503db6dc6ea061f092cfb9c388448629a6fe868d068c42a488b478ae", + "5KL6zEaMtPRXZKo1bbMq7JDjjo1bJuQcsgL33je3oY8uSJCR5b4", + ), + ( + "8007f0803fc5399e773555ab1e8939907e9badacc17ca129e67a2f5f2ff84351dd01", + "KwV9KAfwbwt51veZWNscRTeZs9CKpojyu1MsPnaKTF5kz69H1UN2", + ), + ( + "efea577acfb5d1d14d3b7b195c321566f12f87d2b77ea3a53f68df7ebf8604a801", + "93N87D6uxSBzwXvpokpzg8FFmfQPmvX4xHoWQe3pLdYpbiwT5YV", + ), + ( + "ef0b3b34f0958d8a268193a9814da92c3e8b58b4a4378a542863e34ac289cd830c01", + "cMxXusSihaX58wpJ3tNuuUcZEQGt6DKJ1wEpxys88FFaQCYjku9h", + ), + ( + "001ed467017f043e91ed4c44b4e8dd674db211c4e6", + "13p1ijLwsnrcuyqcTvJXkq2ASdXqcnEBLE", + ), + ( + "055ece0cadddc415b1980f001785947120acdb36fc", + "3ALJH9Y951VCGcVZYAdpA3KchoP9McEj1G", + ), ] vectors_graphene = [ - ('02e649f63f8e8121345fd7f47d0d185a3ccaa843115cd2e9392dcd9b82263bc680', '6dumtt9swxCqwdPZBGXh9YmHoEjFFnNfwHaTqRbQTghGAY2gRz'), - ('021c7359cd885c0e319924d97e3980206ad64387aff54908241125b3a88b55ca16', '5725vivYpuFWbeyTifZ5KevnHyqXCi5hwHbNU9cYz1FHbFXCxX'), - ('02f561e0b57a552df3fa1df2d87a906b7a9fc33a83d5d15fa68a644ecb0806b49a', '6kZKHSuxqAwdCYsMvwTcipoTsNE2jmEUNBQufGYywpniBKXWZK'), - ('03e7595c3e6b58f907bee951dc29796f3757307e700ecf3d09307a0cc4a564eba3', '8b82mpnH8YX1E9RHnU2a2YgLTZ8ooevEGP9N15c1yFqhoBvJur'), + ( + "02e649f63f8e8121345fd7f47d0d185a3ccaa843115cd2e9392dcd9b82263bc680", + "6dumtt9swxCqwdPZBGXh9YmHoEjFFnNfwHaTqRbQTghGAY2gRz", + ), + ( + "021c7359cd885c0e319924d97e3980206ad64387aff54908241125b3a88b55ca16", + "5725vivYpuFWbeyTifZ5KevnHyqXCi5hwHbNU9cYz1FHbFXCxX", + ), + ( + "02f561e0b57a552df3fa1df2d87a906b7a9fc33a83d5d15fa68a644ecb0806b49a", + "6kZKHSuxqAwdCYsMvwTcipoTsNE2jmEUNBQufGYywpniBKXWZK", + ), + ( + "03e7595c3e6b58f907bee951dc29796f3757307e700ecf3d09307a0cc4a564eba3", + "8b82mpnH8YX1E9RHnU2a2YgLTZ8ooevEGP9N15c1yFqhoBvJur", + ), ] def test_decode_check(self): for a, b in self.vectors: self.assertEqual(base58.decode_check(b), unhexlify(a)) for a, b in self.vectors_graphene: - self.assertEqual(base58.decode_check(b, digestfunc=digestfunc_graphene), unhexlify(a)) + self.assertEqual( + base58.decode_check(b, digestfunc=digestfunc_graphene), unhexlify(a) + ) def test_encode_check(self): for a, b in self.vectors: self.assertEqual(base58.encode_check(unhexlify(a)), b) for a, b in self.vectors_graphene: - self.assertEqual(base58.encode_check(unhexlify(a), digestfunc=digestfunc_graphene), b) + self.assertEqual( + base58.encode_check(unhexlify(a), digestfunc=digestfunc_graphene), b + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.bech32.py b/core/tests/test_trezor.crypto.bech32.py index 9a9d11fc2b..1fd397e457 100644 --- a/core/tests/test_trezor.crypto.bech32.py +++ b/core/tests/test_trezor.crypto.bech32.py @@ -34,18 +34,36 @@ VALID_CHECKSUM = [ # BIP-173 ("A12UEL5L", bech32.Encoding.BECH32), ("a12uel5l", bech32.Encoding.BECH32), - ("an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs", bech32.Encoding.BECH32), + ( + "an83characterlonghumanreadablepartthatcontainsthenumber1andtheexcludedcharactersbio1tt5tgs", + bech32.Encoding.BECH32, + ), ("abcdef1qpzry9x8gf2tvdw0s3jn54khce6mua7lmqqqxw", bech32.Encoding.BECH32), - ("11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", bech32.Encoding.BECH32), - ("split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", bech32.Encoding.BECH32), + ( + "11qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqc8247j", + bech32.Encoding.BECH32, + ), + ( + "split1checkupstagehandshakeupstreamerranterredcaperred2y9e3w", + bech32.Encoding.BECH32, + ), ("?1ezyfcl", bech32.Encoding.BECH32), # BIP-350 ("A1LQFN3A", bech32.Encoding.BECH32M), ("a1lqfn3a", bech32.Encoding.BECH32M), - ("an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6", bech32.Encoding.BECH32M), + ( + "an83characterlonghumanreadablepartthatcontainsthetheexcludedcharactersbioandnumber11sg7hg6", + bech32.Encoding.BECH32M, + ), ("abcdef1l7aum6echk45nj3s0wdvt2fg8x9yrzpqzd3ryx", bech32.Encoding.BECH32M), - ("11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8", bech32.Encoding.BECH32M), - ("split1checkupstagehandshakeupstreamerranterredcaperredlc445v", bech32.Encoding.BECH32M), + ( + "11llllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllllludsr8", + bech32.Encoding.BECH32M, + ), + ( + "split1checkupstagehandshakeupstreamerranterredcaperredlc445v", + bech32.Encoding.BECH32M, + ), ("?1v759aa", bech32.Encoding.BECH32M), ] @@ -82,20 +100,45 @@ INVALID_CHECKSUM = [ VALID_ADDRESS = [ # BIP-173 - ("BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4", "0014751e76e8199196d454941c45d1b3a323f1433bd6"), - ("tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7", - "00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262"), - ("tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy", - "0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433"), + ( + "BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4", + "0014751e76e8199196d454941c45d1b3a323f1433bd6", + ), + ( + "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7", + "00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262", + ), + ( + "tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy", + "0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433", + ), # BIP-350 - ("BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4", "0014751e76e8199196d454941c45d1b3a323f1433bd6"), - ("tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7", "00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262"), - ("bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y", "5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6"), + ( + "BC1QW508D6QEJXTDG4Y5R3ZARVARY0C5XW7KV8F3T4", + "0014751e76e8199196d454941c45d1b3a323f1433bd6", + ), + ( + "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3q0sl5k7", + "00201863143c14c5166804bd19203356da136c985678cd4d27a1b8c6329604903262", + ), + ( + "bc1pw508d6qejxtdg4y5r3zarvary0c5xw7kw508d6qejxtdg4y5r3zarvary0c5xw7kt5nd6y", + "5128751e76e8199196d454941c45d1b3a323f1433bd6751e76e8199196d454941c45d1b3a323f1433bd6", + ), ("BC1SW50QGDZ25J", "6002751e"), ("bc1zw508d6qejxtdg4y5r3zarvaryvaxxpcs", "5210751e76e8199196d454941c45d1b3a323"), - ("tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy", "0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433"), - ("tb1pqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesf3hn0c", "5120000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433"), - ("bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0", "512079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798"), + ( + "tb1qqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesrxh6hy", + "0020000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433", + ), + ( + "tb1pqqqqp399et2xygdj5xreqhjjvcmzhxw4aywxecjdzew6hylgvsesf3hn0c", + "5120000000c4a5cad46221b2a187905e5266362b99d5e91c6ce24d165dab93e86433", + ), + ( + "bc1p0xlxvlhemja6c4dqv22uapctqupfhlxm9h8z3k2e72q4k9hcz7vqzk5jj0", + "512079be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", + ), ] INVALID_ADDRESS = [ diff --git a/core/tests/test_trezor.crypto.bip32.py b/core/tests/test_trezor.crypto.bip32.py index 866d96cb12..892ee8838d 100644 --- a/core/tests/test_trezor.crypto.bip32.py +++ b/core/tests/test_trezor.crypto.bip32.py @@ -2,286 +2,731 @@ from common import * from trezor.crypto import bip32 -SECP256K1_NAME = 'secp256k1' +SECP256K1_NAME = "secp256k1" HARDENED = 0x80000000 -VERSION_PUBLIC = 0x0488b21e -VERSION_PRIVATE = 0x0488ade4 +VERSION_PUBLIC = 0x0488B21E +VERSION_PRIVATE = 0x0488ADE4 class TestCryptoBip32(unittest.TestCase): - def test_from_seed_invalid(self): for c in [SECP256K1_NAME]: with self.assertRaises(ValueError): - bip32.from_seed('', c) + bip32.from_seed("", c) with self.assertRaises(ValueError): bip32.from_seed(bytes(), c) with self.assertRaises(ValueError): bip32.from_seed(bytearray(), c) with self.assertRaises(TypeError): bip32.from_seed(1, c) - s = unhexlify('000102030405060708090a0b0c0d0e0f') + s = unhexlify("000102030405060708090a0b0c0d0e0f") with self.assertRaises(ValueError): - bip32.from_seed(s, '') + bip32.from_seed(s, "") with self.assertRaises(ValueError): bip32.from_seed(s, bytes()) with self.assertRaises(ValueError): bip32.from_seed(s, bytearray()) with self.assertRaises(ValueError): - bip32.from_seed(s, 'foobar') + bip32.from_seed(s, "foobar") def test_secp256k1_vector_1_derive(self): # pylint: disable=C0301 # test vector 1 from https://en.bitcoin.it/wiki/BIP_0032_TestVectors # init m - n = bip32.from_seed(unhexlify('000102030405060708090a0b0c0d0e0f'), SECP256K1_NAME) + n = bip32.from_seed( + unhexlify("000102030405060708090a0b0c0d0e0f"), SECP256K1_NAME + ) # [Chain m] self.assertEqual(n.fingerprint(), 0x00000000) - self.assertEqual(n.chain_code(), unhexlify('873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508')) - self.assertEqual(n.private_key(), unhexlify('e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35')) - self.assertEqual(n.public_key(), unhexlify('0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2')) + self.assertEqual( + n.chain_code(), + unhexlify( + "873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8') + self.assertEqual( + ns, + "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8", + ) # [Chain m/0'] n.derive(HARDENED | 0) - self.assertEqual(n.fingerprint(), 0x3442193e) - self.assertEqual(n.chain_code(), unhexlify('47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141')) - self.assertEqual(n.private_key(), unhexlify('edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea')) - self.assertEqual(n.public_key(), unhexlify('035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56')) + self.assertEqual(n.fingerprint(), 0x3442193E) + self.assertEqual( + n.chain_code(), + unhexlify( + "47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw') + self.assertEqual( + ns, + "xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw", + ) # [Chain m/0'/1] n.derive(1) - self.assertEqual(n.fingerprint(), 0x5c1bd648) - self.assertEqual(n.chain_code(), unhexlify('2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19')) - self.assertEqual(n.private_key(), unhexlify('3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368')) - self.assertEqual(n.public_key(), unhexlify('03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c')) + self.assertEqual(n.fingerprint(), 0x5C1BD648) + self.assertEqual( + n.chain_code(), + unhexlify( + "2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ') + self.assertEqual( + ns, + "xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ", + ) # [Chain m/0'/1/2'] n.derive(HARDENED | 2) - self.assertEqual(n.fingerprint(), 0xbef5a2f9) - self.assertEqual(n.chain_code(), unhexlify('04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f')) - self.assertEqual(n.private_key(), unhexlify('cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca')) - self.assertEqual(n.public_key(), unhexlify('0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2')) + self.assertEqual(n.fingerprint(), 0xBEF5A2F9) + self.assertEqual( + n.chain_code(), + unhexlify( + "04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5') + self.assertEqual( + ns, + "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5", + ) # [Chain m/0'/1/2'/2] n.derive(2) - self.assertEqual(n.fingerprint(), 0xee7ab90c) - self.assertEqual(n.chain_code(), unhexlify('cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd')) - self.assertEqual(n.private_key(), unhexlify('0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4')) - self.assertEqual(n.public_key(), unhexlify('02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29')) + self.assertEqual(n.fingerprint(), 0xEE7AB90C) + self.assertEqual( + n.chain_code(), + unhexlify( + "cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV') + self.assertEqual( + ns, + "xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV", + ) # [Chain m/0'/1/2'/2/1000000000] n.derive(1000000000) - self.assertEqual(n.fingerprint(), 0xd880d7d8) - self.assertEqual(n.chain_code(), unhexlify('c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e')) - self.assertEqual(n.private_key(), unhexlify('471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8')) - self.assertEqual(n.public_key(), unhexlify('022a471424da5e657499d1ff51cb43c47481a03b1e77f951fe64cec9f5a48f7011')) + self.assertEqual(n.fingerprint(), 0xD880D7D8) + self.assertEqual( + n.chain_code(), + unhexlify( + "c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "022a471424da5e657499d1ff51cb43c47481a03b1e77f951fe64cec9f5a48f7011" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy') + self.assertEqual( + ns, + "xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy", + ) def test_secp256k1_vector_2_derive(self): # pylint: disable=C0301 # test vector 2 from https://en.bitcoin.it/wiki/BIP_0032_TestVectors # init m - n = bip32.from_seed(unhexlify('fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'), SECP256K1_NAME) + n = bip32.from_seed( + unhexlify( + "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542" + ), + SECP256K1_NAME, + ) # [Chain m] self.assertEqual(n.fingerprint(), 0x00000000) - self.assertEqual(n.chain_code(), unhexlify('60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689')) - self.assertEqual(n.private_key(), unhexlify('4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e')) - self.assertEqual(n.public_key(), unhexlify('03cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7')) + self.assertEqual( + n.chain_code(), + unhexlify( + "60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "03cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB') + self.assertEqual( + ns, + "xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB", + ) # [Chain m/0] n.derive(0) - self.assertEqual(n.fingerprint(), 0xbd16bee5) - self.assertEqual(n.chain_code(), unhexlify('f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c')) - self.assertEqual(n.private_key(), unhexlify('abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e')) - self.assertEqual(n.public_key(), unhexlify('02fc9e5af0ac8d9b3cecfe2a888e2117ba3d089d8585886c9c826b6b22a98d12ea')) + self.assertEqual(n.fingerprint(), 0xBD16BEE5) + self.assertEqual( + n.chain_code(), + unhexlify( + "f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "02fc9e5af0ac8d9b3cecfe2a888e2117ba3d089d8585886c9c826b6b22a98d12ea" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH') + self.assertEqual( + ns, + "xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH", + ) # [Chain m/0/2147483647'] n.derive(HARDENED | 2147483647) - self.assertEqual(n.fingerprint(), 0x5a61ff8e) - self.assertEqual(n.chain_code(), unhexlify('be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9')) - self.assertEqual(n.private_key(), unhexlify('877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93')) - self.assertEqual(n.public_key(), unhexlify('03c01e7425647bdefa82b12d9bad5e3e6865bee0502694b94ca58b666abc0a5c3b')) + self.assertEqual(n.fingerprint(), 0x5A61FF8E) + self.assertEqual( + n.chain_code(), + unhexlify( + "be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "03c01e7425647bdefa82b12d9bad5e3e6865bee0502694b94ca58b666abc0a5c3b" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a') + self.assertEqual( + ns, + "xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a", + ) # [Chain m/0/2147483647'/1] n.derive(1) - self.assertEqual(n.fingerprint(), 0xd8ab4937) - self.assertEqual(n.chain_code(), unhexlify('f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb')) - self.assertEqual(n.private_key(), unhexlify('704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7')) - self.assertEqual(n.public_key(), unhexlify('03a7d1d856deb74c508e05031f9895dab54626251b3806e16b4bd12e781a7df5b9')) + self.assertEqual(n.fingerprint(), 0xD8AB4937) + self.assertEqual( + n.chain_code(), + unhexlify( + "f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "03a7d1d856deb74c508e05031f9895dab54626251b3806e16b4bd12e781a7df5b9" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon') + self.assertEqual( + ns, + "xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon", + ) # [Chain m/0/2147483647'/1/2147483646'] n.derive(HARDENED | 2147483646) - self.assertEqual(n.fingerprint(), 0x78412e3a) - self.assertEqual(n.chain_code(), unhexlify('637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29')) - self.assertEqual(n.private_key(), unhexlify('f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d')) - self.assertEqual(n.public_key(), unhexlify('02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0')) + self.assertEqual(n.fingerprint(), 0x78412E3A) + self.assertEqual( + n.chain_code(), + unhexlify( + "637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL') + self.assertEqual( + ns, + "xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL", + ) # [Chain m/0/2147483647'/1/2147483646'/2] n.derive(2) - self.assertEqual(n.fingerprint(), 0x31a507b8) - self.assertEqual(n.chain_code(), unhexlify('9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271')) - self.assertEqual(n.private_key(), unhexlify('bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23')) - self.assertEqual(n.public_key(), unhexlify('024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c')) + self.assertEqual(n.fingerprint(), 0x31A507B8) + self.assertEqual( + n.chain_code(), + unhexlify( + "9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt') + self.assertEqual( + ns, + "xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt", + ) def test_secp256k1_vector_1_derive_path(self): # pylint: disable=C0301 # test vector 1 from https://en.bitcoin.it/wiki/BIP_0032_TestVectors # init m - m = bip32.from_seed(unhexlify('000102030405060708090a0b0c0d0e0f'), SECP256K1_NAME) + m = bip32.from_seed( + unhexlify("000102030405060708090a0b0c0d0e0f"), SECP256K1_NAME + ) # [Chain m] n = m.clone() self.assertEqual(n.fingerprint(), 0x00000000) - self.assertEqual(n.chain_code(), unhexlify('873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508')) - self.assertEqual(n.private_key(), unhexlify('e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35')) - self.assertEqual(n.public_key(), unhexlify('0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2')) + self.assertEqual( + n.chain_code(), + unhexlify( + "873dff81c02f525623fd1fe5167eac3a55a049de3d314bb42ee227ffed37d508" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "e8f32e723decf4051aefac8e2c93c9c5b214313817cdb01a1494b917c8436b35" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "0339a36013301597daef41fbe593a02cc513d0b55527ec2df1050e2e8ff49c85c2" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8') + self.assertEqual( + ns, + "xpub661MyMwAqRbcFtXgS5sYJABqqG9YLmC4Q1Rdap9gSE8NqtwybGhePY2gZ29ESFjqJoCu1Rupje8YtGqsefD265TMg7usUDFdp6W1EGMcet8", + ) # [Chain m/0'] n = m.clone() n.derive_path([HARDENED | 0]) - self.assertEqual(n.fingerprint(), 0x3442193e) - self.assertEqual(n.chain_code(), unhexlify('47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141')) - self.assertEqual(n.private_key(), unhexlify('edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea')) - self.assertEqual(n.public_key(), unhexlify('035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56')) + self.assertEqual(n.fingerprint(), 0x3442193E) + self.assertEqual( + n.chain_code(), + unhexlify( + "47fdacbd0f1097043b78c63c20c34ef4ed9a111d980047ad16282c7ae6236141" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "edb2e14f9ee77d26dd93b4ecede8d16ed408ce149b6cd80b0715a2d911a0afea" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "035a784662a4a20a65bf6aab9ae98a6c068a81c52e4b032c0fb5400c706cfccc56" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw') + self.assertEqual( + ns, + "xpub68Gmy5EdvgibQVfPdqkBBCHxA5htiqg55crXYuXoQRKfDBFA1WEjWgP6LHhwBZeNK1VTsfTFUHCdrfp1bgwQ9xv5ski8PX9rL2dZXvgGDnw", + ) # [Chain m/0'/1] n = m.clone() n.derive_path([HARDENED | 0, 1]) - self.assertEqual(n.fingerprint(), 0x5c1bd648) - self.assertEqual(n.chain_code(), unhexlify('2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19')) - self.assertEqual(n.private_key(), unhexlify('3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368')) - self.assertEqual(n.public_key(), unhexlify('03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c')) + self.assertEqual(n.fingerprint(), 0x5C1BD648) + self.assertEqual( + n.chain_code(), + unhexlify( + "2a7857631386ba23dacac34180dd1983734e444fdbf774041578e9b6adb37c19" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "3c6cb8d0f6a264c91ea8b5030fadaa8e538b020f0a387421a12de9319dc93368" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "03501e454bf00751f24b1b489aa925215d66af2234e3891c3b21a52bedb3cd711c" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ') + self.assertEqual( + ns, + "xpub6ASuArnXKPbfEwhqN6e3mwBcDTgzisQN1wXN9BJcM47sSikHjJf3UFHKkNAWbWMiGj7Wf5uMash7SyYq527Hqck2AxYysAA7xmALppuCkwQ", + ) # [Chain m/0'/1/2'] n = m.clone() n.derive_path([HARDENED | 0, 1, HARDENED | 2]) - self.assertEqual(n.fingerprint(), 0xbef5a2f9) - self.assertEqual(n.chain_code(), unhexlify('04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f')) - self.assertEqual(n.private_key(), unhexlify('cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca')) - self.assertEqual(n.public_key(), unhexlify('0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2')) + self.assertEqual(n.fingerprint(), 0xBEF5A2F9) + self.assertEqual( + n.chain_code(), + unhexlify( + "04466b9cc8e161e966409ca52986c584f07e9dc81f735db683c3ff6ec7b1503f" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "cbce0d719ecf7431d88e6a89fa1483e02e35092af60c042b1df2ff59fa424dca" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "0357bfe1e341d01c69fe5654309956cbea516822fba8a601743a012a7896ee8dc2" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5') + self.assertEqual( + ns, + "xpub6D4BDPcP2GT577Vvch3R8wDkScZWzQzMMUm3PWbmWvVJrZwQY4VUNgqFJPMM3No2dFDFGTsxxpG5uJh7n7epu4trkrX7x7DogT5Uv6fcLW5", + ) # [Chain m/0'/1/2'/2] n = m.clone() n.derive_path([HARDENED | 0, 1, HARDENED | 2, 2]) - self.assertEqual(n.fingerprint(), 0xee7ab90c) - self.assertEqual(n.chain_code(), unhexlify('cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd')) - self.assertEqual(n.private_key(), unhexlify('0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4')) - self.assertEqual(n.public_key(), unhexlify('02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29')) + self.assertEqual(n.fingerprint(), 0xEE7AB90C) + self.assertEqual( + n.chain_code(), + unhexlify( + "cfb71883f01676f587d023cc53a35bc7f88f724b1f8c2892ac1275ac822a3edd" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "0f479245fb19a38a1954c5c7c0ebab2f9bdfd96a17563ef28a6a4b1a2a764ef4" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "02e8445082a72f29b75ca48748a914df60622a609cacfce8ed0e35804560741d29" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV') + self.assertEqual( + ns, + "xpub6FHa3pjLCk84BayeJxFW2SP4XRrFd1JYnxeLeU8EqN3vDfZmbqBqaGJAyiLjTAwm6ZLRQUMv1ZACTj37sR62cfN7fe5JnJ7dh8zL4fiyLHV", + ) # [Chain m/0'/1/2'/2/1000000000] n = m.clone() n.derive_path([HARDENED | 0, 1, HARDENED | 2, 2, 1000000000]) - self.assertEqual(n.fingerprint(), 0xd880d7d8) - self.assertEqual(n.chain_code(), unhexlify('c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e')) - self.assertEqual(n.private_key(), unhexlify('471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8')) - self.assertEqual(n.public_key(), unhexlify('022a471424da5e657499d1ff51cb43c47481a03b1e77f951fe64cec9f5a48f7011')) + self.assertEqual(n.fingerprint(), 0xD880D7D8) + self.assertEqual( + n.chain_code(), + unhexlify( + "c783e67b921d2beb8f6b389cc646d7263b4145701dadd2161548a8b078e65e9e" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "471b76e389e528d6de6d816857e012c5455051cad6660850e58372a6c3e6e7c8" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "022a471424da5e657499d1ff51cb43c47481a03b1e77f951fe64cec9f5a48f7011" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy') + self.assertEqual( + ns, + "xpub6H1LXWLaKsWFhvm6RVpEL9P4KfRZSW7abD2ttkWP3SSQvnyA8FSVqNTEcYFgJS2UaFcxupHiYkro49S8yGasTvXEYBVPamhGW6cFJodrTHy", + ) def test_secp256k1_vector_2_derive_path(self): # pylint: disable=C0301 # test vector 2 from https://en.bitcoin.it/wiki/BIP_0032_TestVectors # init m - m = bip32.from_seed(unhexlify('fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542'), SECP256K1_NAME) + m = bip32.from_seed( + unhexlify( + "fffcf9f6f3f0edeae7e4e1dedbd8d5d2cfccc9c6c3c0bdbab7b4b1aeaba8a5a29f9c999693908d8a8784817e7b7875726f6c696663605d5a5754514e4b484542" + ), + SECP256K1_NAME, + ) # [Chain m] n = m.clone() self.assertEqual(n.fingerprint(), 0x00000000) - self.assertEqual(n.chain_code(), unhexlify('60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689')) - self.assertEqual(n.private_key(), unhexlify('4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e')) - self.assertEqual(n.public_key(), unhexlify('03cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7')) + self.assertEqual( + n.chain_code(), + unhexlify( + "60499f801b896d83179a4374aeb7822aaeaceaa0db1f85ee3e904c4defbd9689" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "4b03d6fc340455b363f51020ad3ecca4f0850280cf436c70c727923f6db46c3e" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "03cbcaa9c98c877a26977d00825c956a238e8dddfbd322cce4f74b0b5bd6ace4a7" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB') + self.assertEqual( + ns, + "xpub661MyMwAqRbcFW31YEwpkMuc5THy2PSt5bDMsktWQcFF8syAmRUapSCGu8ED9W6oDMSgv6Zz8idoc4a6mr8BDzTJY47LJhkJ8UB7WEGuduB", + ) # [Chain m/0] n = m.clone() n.derive_path([0]) - self.assertEqual(n.fingerprint(), 0xbd16bee5) - self.assertEqual(n.chain_code(), unhexlify('f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c')) - self.assertEqual(n.private_key(), unhexlify('abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e')) - self.assertEqual(n.public_key(), unhexlify('02fc9e5af0ac8d9b3cecfe2a888e2117ba3d089d8585886c9c826b6b22a98d12ea')) + self.assertEqual(n.fingerprint(), 0xBD16BEE5) + self.assertEqual( + n.chain_code(), + unhexlify( + "f0909affaa7ee7abe5dd4e100598d4dc53cd709d5a5c2cac40e7412f232f7c9c" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "abe74a98f6c7eabee0428f53798f0ab8aa1bd37873999041703c742f15ac7e1e" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "02fc9e5af0ac8d9b3cecfe2a888e2117ba3d089d8585886c9c826b6b22a98d12ea" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH') + self.assertEqual( + ns, + "xpub69H7F5d8KSRgmmdJg2KhpAK8SR3DjMwAdkxj3ZuxV27CprR9LgpeyGmXUbC6wb7ERfvrnKZjXoUmmDznezpbZb7ap6r1D3tgFxHmwMkQTPH", + ) # [Chain m/0/2147483647'] n = m.clone() n.derive_path([0, HARDENED | 2147483647]) - self.assertEqual(n.fingerprint(), 0x5a61ff8e) - self.assertEqual(n.chain_code(), unhexlify('be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9')) - self.assertEqual(n.private_key(), unhexlify('877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93')) - self.assertEqual(n.public_key(), unhexlify('03c01e7425647bdefa82b12d9bad5e3e6865bee0502694b94ca58b666abc0a5c3b')) + self.assertEqual(n.fingerprint(), 0x5A61FF8E) + self.assertEqual( + n.chain_code(), + unhexlify( + "be17a268474a6bb9c61e1d720cf6215e2a88c5406c4aee7b38547f585c9a37d9" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "877c779ad9687164e9c2f4f0f4ff0340814392330693ce95a58fe18fd52e6e93" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "03c01e7425647bdefa82b12d9bad5e3e6865bee0502694b94ca58b666abc0a5c3b" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a') + self.assertEqual( + ns, + "xpub6ASAVgeehLbnwdqV6UKMHVzgqAG8Gr6riv3Fxxpj8ksbH9ebxaEyBLZ85ySDhKiLDBrQSARLq1uNRts8RuJiHjaDMBU4Zn9h8LZNnBC5y4a", + ) # [Chain m/0/2147483647'/1] n = m.clone() n.derive_path([0, HARDENED | 2147483647, 1]) - self.assertEqual(n.fingerprint(), 0xd8ab4937) - self.assertEqual(n.chain_code(), unhexlify('f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb')) - self.assertEqual(n.private_key(), unhexlify('704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7')) - self.assertEqual(n.public_key(), unhexlify('03a7d1d856deb74c508e05031f9895dab54626251b3806e16b4bd12e781a7df5b9')) + self.assertEqual(n.fingerprint(), 0xD8AB4937) + self.assertEqual( + n.chain_code(), + unhexlify( + "f366f48f1ea9f2d1d3fe958c95ca84ea18e4c4ddb9366c336c927eb246fb38cb" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "704addf544a06e5ee4bea37098463c23613da32020d604506da8c0518e1da4b7" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "03a7d1d856deb74c508e05031f9895dab54626251b3806e16b4bd12e781a7df5b9" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon') + self.assertEqual( + ns, + "xpub6DF8uhdarytz3FWdA8TvFSvvAh8dP3283MY7p2V4SeE2wyWmG5mg5EwVvmdMVCQcoNJxGoWaU9DCWh89LojfZ537wTfunKau47EL2dhHKon", + ) # [Chain m/0/2147483647'/1/2147483646'] n = m.clone() n.derive_path([0, HARDENED | 2147483647, 1, HARDENED | 2147483646]) - self.assertEqual(n.fingerprint(), 0x78412e3a) - self.assertEqual(n.chain_code(), unhexlify('637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29')) - self.assertEqual(n.private_key(), unhexlify('f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d')) - self.assertEqual(n.public_key(), unhexlify('02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0')) + self.assertEqual(n.fingerprint(), 0x78412E3A) + self.assertEqual( + n.chain_code(), + unhexlify( + "637807030d55d01f9a0cb3a7839515d796bd07706386a6eddf06cc29a65a0e29" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "f1c7c871a54a804afe328b4c83a1c33b8e5ff48f5087273f04efa83b247d6a2d" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "02d2b36900396c9282fa14628566582f206a5dd0bcc8d5e892611806cafb0301f0" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL') + self.assertEqual( + ns, + "xpub6ERApfZwUNrhLCkDtcHTcxd75RbzS1ed54G1LkBUHQVHQKqhMkhgbmJbZRkrgZw4koxb5JaHWkY4ALHY2grBGRjaDMzQLcgJvLJuZZvRcEL", + ) # [Chain m/0/2147483647'/1/2147483646'/2] n = m.clone() n.derive_path([0, HARDENED | 2147483647, 1, HARDENED | 2147483646, 2]) - self.assertEqual(n.fingerprint(), 0x31a507b8) - self.assertEqual(n.chain_code(), unhexlify('9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271')) - self.assertEqual(n.private_key(), unhexlify('bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23')) - self.assertEqual(n.public_key(), unhexlify('024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c')) + self.assertEqual(n.fingerprint(), 0x31A507B8) + self.assertEqual( + n.chain_code(), + unhexlify( + "9452b549be8cea3ecb7a84bec10dcfd94afe4d129ebfd3b3cb58eedf394ed271" + ), + ) + self.assertEqual( + n.private_key(), + unhexlify( + "bb7d39bdb83ecf58f2fd82b6d918341cbef428661ef01ab97c28a4842125ac23" + ), + ) + self.assertEqual( + n.public_key(), + unhexlify( + "024d902e1a2fc7a8755ab5b694c575fce742c48d9ff192e63df5193e4c7afe1f9c" + ), + ) ns = n.serialize_public(VERSION_PUBLIC) - self.assertEqual(ns, 'xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt') + self.assertEqual( + ns, + "xpub6FnCn6nSzZAw5Tw7cgR9bi15UV96gLZhjDstkXXxvCLsUXBGXPdSnLFbdpq8p9HmGsApME5hQTZ3emM2rnY5agb9rXpVGyy3bdW6EEgAtqt", + ) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.bip39.py b/core/tests/test_trezor.crypto.bip39.py index f36cfa9b47..b9e836d29a 100644 --- a/core/tests/test_trezor.crypto.bip39.py +++ b/core/tests/test_trezor.crypto.bip39.py @@ -4,122 +4,217 @@ from trezor.crypto import bip39 class TestCryptoBip39(unittest.TestCase): - def test_mnemonic(self): v = [ - ('00000000000000000000000000000000', 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', 'c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04'), - ('7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'legal winner thank year wave sausage worth useful legal winner thank yellow', '2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607'), - ('80808080808080808080808080808080', 'letter advice cage absurd amount doctor acoustic avoid letter advice cage above', 'd71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8'), - ('ffffffffffffffffffffffffffffffff', 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong', 'ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069'), - ('000000000000000000000000000000000000000000000000', 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent', '035895f2f481b1b0f01fcf8c289c794660b289981a78f8106447707fdd9666ca06da5a9a565181599b79f53b844d8a71dd9f439c52a3d7b3e8a79c906ac845fa'), - ('7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will', 'f2b94508732bcbacbcc020faefecfc89feafa6649a5491b8c952cede496c214a0c7b3c392d168748f2d4a612bada0753b52a1c7ac53c1e93abd5c6320b9e95dd'), - ('808080808080808080808080808080808080808080808080', 'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always', '107d7c02a5aa6f38c58083ff74f04c607c2d2c0ecc55501dadd72d025b751bc27fe913ffb796f841c49b1d33b610cf0e91d3aa239027f5e99fe4ce9e5088cd65'), - ('ffffffffffffffffffffffffffffffffffffffffffffffff', 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when', '0cd6e5d827bb62eb8fc1e262254223817fd068a74b5b449cc2f667c3f1f985a76379b43348d952e2265b4cd129090758b3e3c2c49103b5051aac2eaeb890a528'), - ('0000000000000000000000000000000000000000000000000000000000000000', 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art', 'bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8'), - ('7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f', 'legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title', 'bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87'), - ('8080808080808080808080808080808080808080808080808080808080808080', 'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless', 'c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f'), - ('ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff', 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote', 'dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad'), - ('77c2b00716cec7213839159e404db50d', 'jelly better achieve collect unaware mountain thought cargo oxygen act hood bridge', 'b5b6d0127db1a9d2226af0c3346031d77af31e918dba64287a1b44b8ebf63cdd52676f672a290aae502472cf2d602c051f3e6f18055e84e4c43897fc4e51a6ff'), - ('b63a9c59a6e641f288ebc103017f1da9f8290b3da6bdef7b', 'renew stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap', '9248d83e06f4cd98debf5b6f010542760df925ce46cf38a1bdb4e4de7d21f5c39366941c69e1bdbf2966e0f6e6dbece898a0e2f0a4c2b3e640953dfe8b7bbdc5'), - ('3e141609b97933b66a060dcddc71fad1d91677db872031e85f4c015c5e7e8982', 'dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic', 'ff7f3184df8696d8bef94b6c03114dbee0ef89ff938712301d27ed8336ca89ef9635da20af07d4175f2bf5f3de130f39c9d9e8dd0472489c19b1a020a940da67'), - ('0460ef47585604c5660618db2e6a7e7f', 'afford alter spike radar gate glance object seek swamp infant panel yellow', '65f93a9f36b6c85cbe634ffc1f99f2b82cbb10b31edc7f087b4f6cb9e976e9faf76ff41f8f27c99afdf38f7a303ba1136ee48a4c1e7fcd3dba7aa876113a36e4'), - ('72f60ebac5dd8add8d2a25a797102c3ce21bc029c200076f', 'indicate race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left', '3bbf9daa0dfad8229786ace5ddb4e00fa98a044ae4c4975ffd5e094dba9e0bb289349dbe2091761f30f382d4e35c4a670ee8ab50758d2c55881be69e327117ba'), - ('2c85efc7f24ee4573d2b81a6ec66cee209b2dcbd09d8eddc51e0215b0b68e416', 'clutch control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste', 'fe908f96f46668b2d5b37d82f558c77ed0d69dd0e7e043a5b0511c48c2f1064694a956f86360c93dd04052a8899497ce9e985ebe0c8c52b955e6ae86d4ff4449'), - ('eaebabb2383351fd31d703840b32e9e2', 'turtle front uncle idea crush write shrug there lottery flower risk shell', 'bdfb76a0759f301b0b899a1e3985227e53b3f51e67e3f2a65363caedf3e32fde42a66c404f18d7b05818c95ef3ca1e5146646856c461c073169467511680876c'), - ('7ac45cfe7722ee6c7ba84fbc2d5bd61b45cb2fe5eb65aa78', 'kiss carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment', 'ed56ff6c833c07982eb7119a8f48fd363c4a9b1601cd2de736b01045c5eb8ab4f57b079403485d1c4924f0790dc10a971763337cb9f9c62226f64fff26397c79'), - ('4fa1a8bc3e6d80ee1316050e862c1812031493212b7ec3f3bb1b08f168cabeef', 'exile ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top', '095ee6f817b4c2cb30a5a797360a81a40ab0f9a4e25ecd672a3f58a0b5ba0687c096a6b14d2c0deb3bdefce4f61d01ae07417d502429352e27695163f7447a8c'), - ('18ab19a9f54a9274f03e5209a2ac8a91', 'board flee heavy tunnel powder denial science ski answer betray cargo cat', '6eff1bb21562918509c73cb990260db07c0ce34ff0e3cc4a8cb3276129fbcb300bddfe005831350efd633909f476c45c88253276d9fd0df6ef48609e8bb7dca8'), - ('18a2e1d81b8ecfb2a333adcb0c17a5b9eb76cc5d05db91a4', 'board blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief', 'f84521c777a13b61564234bf8f8b62b3afce27fc4062b51bb5e62bdfecb23864ee6ecf07c1d5a97c0834307c5c852d8ceb88e7c97923c0a3b496bedd4e5f88a9'), - ('15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419', 'beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut', 'b15509eaa2d09d3efd3e006ef42151b30367dc6e3aa5e44caba3fe4d3e352e65101fbdb86a96776b91946ff06f8eac594dc6ee1d3e82a42dfe1b40fef6bcc3fd'), + ( + "00000000000000000000000000000000", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + "c55257c360c07c72029aebc1b53c05ed0362ada38ead3e3e9efa3708e53495531f09a6987599d18264c1e1c92f2cf141630c7a3c4ab7c81b2f001698e7463b04", + ), + ( + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "legal winner thank year wave sausage worth useful legal winner thank yellow", + "2e8905819b8723fe2c1d161860e5ee1830318dbf49a83bd451cfb8440c28bd6fa457fe1296106559a3c80937a1c1069be3a3a5bd381ee6260e8d9739fce1f607", + ), + ( + "80808080808080808080808080808080", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage above", + "d71de856f81a8acc65e6fc851a38d4d7ec216fd0796d0a6827a3ad6ed5511a30fa280f12eb2e47ed2ac03b5c462a0358d18d69fe4f985ec81778c1b370b652a8", + ), + ( + "ffffffffffffffffffffffffffffffff", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong", + "ac27495480225222079d7be181583751e86f571027b0497b5b5d11218e0a8a13332572917f0f8e5a589620c6f15b11c61dee327651a14c34e18231052e48c069", + ), + ( + "000000000000000000000000000000000000000000000000", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent", + "035895f2f481b1b0f01fcf8c289c794660b289981a78f8106447707fdd9666ca06da5a9a565181599b79f53b844d8a71dd9f439c52a3d7b3e8a79c906ac845fa", + ), + ( + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will", + "f2b94508732bcbacbcc020faefecfc89feafa6649a5491b8c952cede496c214a0c7b3c392d168748f2d4a612bada0753b52a1c7ac53c1e93abd5c6320b9e95dd", + ), + ( + "808080808080808080808080808080808080808080808080", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always", + "107d7c02a5aa6f38c58083ff74f04c607c2d2c0ecc55501dadd72d025b751bc27fe913ffb796f841c49b1d33b610cf0e91d3aa239027f5e99fe4ce9e5088cd65", + ), + ( + "ffffffffffffffffffffffffffffffffffffffffffffffff", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when", + "0cd6e5d827bb62eb8fc1e262254223817fd068a74b5b449cc2f667c3f1f985a76379b43348d952e2265b4cd129090758b3e3c2c49103b5051aac2eaeb890a528", + ), + ( + "0000000000000000000000000000000000000000000000000000000000000000", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art", + "bda85446c68413707090a52022edd26a1c9462295029f2e60cd7c4f2bbd3097170af7a4d73245cafa9c3cca8d561a7c3de6f5d4a10be8ed2a5e608d68f92fcc8", + ), + ( + "7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f7f", + "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title", + "bc09fca1804f7e69da93c2f2028eb238c227f2e9dda30cd63699232578480a4021b146ad717fbb7e451ce9eb835f43620bf5c514db0f8add49f5d121449d3e87", + ), + ( + "8080808080808080808080808080808080808080808080808080808080808080", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless", + "c0c519bd0e91a2ed54357d9d1ebef6f5af218a153624cf4f2da911a0ed8f7a09e2ef61af0aca007096df430022f7a2b6fb91661a9589097069720d015e4e982f", + ), + ( + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote", + "dd48c104698c30cfe2b6142103248622fb7bb0ff692eebb00089b32d22484e1613912f0a5b694407be899ffd31ed3992c456cdf60f5d4564b8ba3f05a69890ad", + ), + ( + "77c2b00716cec7213839159e404db50d", + "jelly better achieve collect unaware mountain thought cargo oxygen act hood bridge", + "b5b6d0127db1a9d2226af0c3346031d77af31e918dba64287a1b44b8ebf63cdd52676f672a290aae502472cf2d602c051f3e6f18055e84e4c43897fc4e51a6ff", + ), + ( + "b63a9c59a6e641f288ebc103017f1da9f8290b3da6bdef7b", + "renew stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap", + "9248d83e06f4cd98debf5b6f010542760df925ce46cf38a1bdb4e4de7d21f5c39366941c69e1bdbf2966e0f6e6dbece898a0e2f0a4c2b3e640953dfe8b7bbdc5", + ), + ( + "3e141609b97933b66a060dcddc71fad1d91677db872031e85f4c015c5e7e8982", + "dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic", + "ff7f3184df8696d8bef94b6c03114dbee0ef89ff938712301d27ed8336ca89ef9635da20af07d4175f2bf5f3de130f39c9d9e8dd0472489c19b1a020a940da67", + ), + ( + "0460ef47585604c5660618db2e6a7e7f", + "afford alter spike radar gate glance object seek swamp infant panel yellow", + "65f93a9f36b6c85cbe634ffc1f99f2b82cbb10b31edc7f087b4f6cb9e976e9faf76ff41f8f27c99afdf38f7a303ba1136ee48a4c1e7fcd3dba7aa876113a36e4", + ), + ( + "72f60ebac5dd8add8d2a25a797102c3ce21bc029c200076f", + "indicate race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left", + "3bbf9daa0dfad8229786ace5ddb4e00fa98a044ae4c4975ffd5e094dba9e0bb289349dbe2091761f30f382d4e35c4a670ee8ab50758d2c55881be69e327117ba", + ), + ( + "2c85efc7f24ee4573d2b81a6ec66cee209b2dcbd09d8eddc51e0215b0b68e416", + "clutch control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste", + "fe908f96f46668b2d5b37d82f558c77ed0d69dd0e7e043a5b0511c48c2f1064694a956f86360c93dd04052a8899497ce9e985ebe0c8c52b955e6ae86d4ff4449", + ), + ( + "eaebabb2383351fd31d703840b32e9e2", + "turtle front uncle idea crush write shrug there lottery flower risk shell", + "bdfb76a0759f301b0b899a1e3985227e53b3f51e67e3f2a65363caedf3e32fde42a66c404f18d7b05818c95ef3ca1e5146646856c461c073169467511680876c", + ), + ( + "7ac45cfe7722ee6c7ba84fbc2d5bd61b45cb2fe5eb65aa78", + "kiss carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment", + "ed56ff6c833c07982eb7119a8f48fd363c4a9b1601cd2de736b01045c5eb8ab4f57b079403485d1c4924f0790dc10a971763337cb9f9c62226f64fff26397c79", + ), + ( + "4fa1a8bc3e6d80ee1316050e862c1812031493212b7ec3f3bb1b08f168cabeef", + "exile ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top", + "095ee6f817b4c2cb30a5a797360a81a40ab0f9a4e25ecd672a3f58a0b5ba0687c096a6b14d2c0deb3bdefce4f61d01ae07417d502429352e27695163f7447a8c", + ), + ( + "18ab19a9f54a9274f03e5209a2ac8a91", + "board flee heavy tunnel powder denial science ski answer betray cargo cat", + "6eff1bb21562918509c73cb990260db07c0ce34ff0e3cc4a8cb3276129fbcb300bddfe005831350efd633909f476c45c88253276d9fd0df6ef48609e8bb7dca8", + ), + ( + "18a2e1d81b8ecfb2a333adcb0c17a5b9eb76cc5d05db91a4", + "board blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief", + "f84521c777a13b61564234bf8f8b62b3afce27fc4062b51bb5e62bdfecb23864ee6ecf07c1d5a97c0834307c5c852d8ceb88e7c97923c0a3b496bedd4e5f88a9", + ), + ( + "15da872c95a13dd738fbf50e427583ad61f18fd99f628c417a61cf8343c90419", + "beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut", + "b15509eaa2d09d3efd3e006ef42151b30367dc6e3aa5e44caba3fe4d3e352e65101fbdb86a96776b91946ff06f8eac594dc6ee1d3e82a42dfe1b40fef6bcc3fd", + ), ] for d, m, s in v: self.assertEqual(bip39.from_data(unhexlify(d)), m) - self.assertEqual(bip39.seed(m, 'TREZOR'), unhexlify(s)) + self.assertEqual(bip39.seed(m, "TREZOR"), unhexlify(s)) def test_check_ok(self): v = [ - 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', - 'legal winner thank year wave sausage worth useful legal winner thank yellow', - 'letter advice cage absurd amount doctor acoustic avoid letter advice cage above', - 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong', - 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent', - 'legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will', - 'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always', - 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when', - 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art', - 'legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title', - 'letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless', - 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote', - 'jelly better achieve collect unaware mountain thought cargo oxygen act hood bridge', - 'renew stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap', - 'dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic', - 'afford alter spike radar gate glance object seek swamp infant panel yellow', - 'indicate race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left', - 'clutch control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste', - 'turtle front uncle idea crush write shrug there lottery flower risk shell', - 'kiss carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment', - 'exile ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top', - 'board flee heavy tunnel powder denial science ski answer betray cargo cat', - 'board blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief', - 'beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut', + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + "legal winner thank year wave sausage worth useful legal winner thank yellow", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage above", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent", + "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art", + "legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title", + "letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote", + "jelly better achieve collect unaware mountain thought cargo oxygen act hood bridge", + "renew stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap", + "dignity pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic", + "afford alter spike radar gate glance object seek swamp infant panel yellow", + "indicate race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left", + "clutch control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste", + "turtle front uncle idea crush write shrug there lottery flower risk shell", + "kiss carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment", + "exile ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top", + "board flee heavy tunnel powder denial science ski answer betray cargo cat", + "board blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief", + "beyond stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut", ] for m in v: self.assertEqual(bip39.check(m), True) def test_check_fail(self): v = [ - 'above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', - 'above winner thank year wave sausage worth useful legal winner thank yellow', - 'above advice cage absurd amount doctor acoustic avoid letter advice cage above', - 'above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong', - 'above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent', - 'above winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will', - 'above advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always', - 'above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when', - 'above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art', - 'above winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title', - 'above advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless', - 'above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote', - 'above better achieve collect unaware mountain thought cargo oxygen act hood bridge', - 'above stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap', - 'above pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic', - 'above alter spike radar gate glance object seek swamp infant panel yellow', - 'above race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left', - 'above control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste', - 'above front uncle idea crush write shrug there lottery flower risk shell', - 'above carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment', - 'above ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top', - 'above flee heavy tunnel powder denial science ski answer betray cargo cat', - 'above blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief', - 'above stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut', - 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about', - 'winner thank year wave sausage worth useful legal winner thank yellow', - 'advice cage absurd amount doctor acoustic avoid letter advice cage above', - 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong', - 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent', - 'winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will', - 'advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always', - 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when', - 'abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art', - 'winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title', - 'advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless', - 'zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote', - 'better achieve collect unaware mountain thought cargo oxygen act hood bridge', - 'stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap', - 'pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic', - 'alter spike radar gate glance object seek swamp infant panel yellow', - 'race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left', - 'control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste', - 'front uncle idea crush write shrug there lottery flower risk shell', - 'carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment', - 'ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top', - 'flee heavy tunnel powder denial science ski answer betray cargo cat', - 'blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief', - 'stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut', + "above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + "above winner thank year wave sausage worth useful legal winner thank yellow", + "above advice cage absurd amount doctor acoustic avoid letter advice cage above", + "above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong", + "above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent", + "above winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will", + "above advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always", + "above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when", + "above abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art", + "above winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title", + "above advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless", + "above zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote", + "above better achieve collect unaware mountain thought cargo oxygen act hood bridge", + "above stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap", + "above pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic", + "above alter spike radar gate glance object seek swamp infant panel yellow", + "above race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left", + "above control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste", + "above front uncle idea crush write shrug there lottery flower risk shell", + "above carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment", + "above ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top", + "above flee heavy tunnel powder denial science ski answer betray cargo cat", + "above blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief", + "above stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about", + "winner thank year wave sausage worth useful legal winner thank yellow", + "advice cage absurd amount doctor acoustic avoid letter advice cage above", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo wrong", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon agent", + "winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal will", + "advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter always", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo when", + "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon art", + "winner thank year wave sausage worth useful legal winner thank year wave sausage worth useful legal winner thank year wave sausage worth title", + "advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic avoid letter advice cage absurd amount doctor acoustic bless", + "zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo zoo vote", + "better achieve collect unaware mountain thought cargo oxygen act hood bridge", + "stay biology evidence goat welcome casual join adapt armor shuffle fault little machine walk stumble urge swap", + "pass list indicate nasty swamp pool script soccer toe leaf photo multiply desk host tomato cradle drill spread actor shine dismiss champion exotic", + "alter spike radar gate glance object seek swamp infant panel yellow", + "race push merry suffer human cruise dwarf pole review arch keep canvas theme poem divorce alter left", + "control vehicle tonight unusual clog visa ice plunge glimpse recipe series open hour vintage deposit universe tip job dress radar refuse motion taste", + "front uncle idea crush write shrug there lottery flower risk shell", + "carry display unusual confirm curtain upgrade antique rotate hello void custom frequent obey nut hole price segment", + "ask congress lamp submit jacket era scheme attend cousin alcohol catch course end lucky hurt sentence oven short ball bird grab wing top", + "flee heavy tunnel powder denial science ski answer betray cargo cat", + "blade invite damage undo sun mimic interest slam gaze truly inherit resist great inject rocket museum chief", + "stage sleep clip because twist token leaf atom beauty genius food business side grid unable middle armed observe pair crouch tonight away coconut", ] for m in v: self.assertEqual(bip39.check(m), False) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.cashaddr.py b/core/tests/test_trezor.crypto.cashaddr.py index 88ffee43ea..560c0a1193 100644 --- a/core/tests/test_trezor.crypto.cashaddr.py +++ b/core/tests/test_trezor.crypto.cashaddr.py @@ -35,26 +35,43 @@ VALID_CHECKSUM = [ ] VALID_ADDRESS = [ - ("1BpEi6DfDAUFd7GtittLSdBeYJvcoaVggu", "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a"), - ("1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR", "bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy"), - ("16w1D5WRVKJuZUsSRzdLp9w3YGcgoxDXb", "bitcoincash:qqq3728yw0y47sqn6l2na30mcw6zm78dzqre909m2r"), - ("3CWFddi6m4ndiGyKqzYvsFYagqDLPVMTzC", "bitcoincash:ppm2qsznhks23z7629mms6s4cwef74vcwvn0h829pq"), - ("3LDsS579y7sruadqu11beEJoTjdFiFCdX4", "bitcoincash:pr95sy3j9xwd2ap32xkykttr4cvcu7as4yc93ky28e"), - ("31nwvkZwyPdgzjBJZXfDmSWsC4ZLKpYyUw", "bitcoincash:pqq3728yw0y47sqn6l2na30mcw6zm78dzq5ucqzc37") + ( + "1BpEi6DfDAUFd7GtittLSdBeYJvcoaVggu", + "bitcoincash:qpm2qsznhks23z7629mms6s4cwef74vcwvy22gdx6a", + ), + ( + "1KXrWXciRDZUpQwQmuM1DbwsKDLYAYsVLR", + "bitcoincash:qr95sy3j9xwd2ap32xkykttr4cvcu7as4y0qverfuy", + ), + ( + "16w1D5WRVKJuZUsSRzdLp9w3YGcgoxDXb", + "bitcoincash:qqq3728yw0y47sqn6l2na30mcw6zm78dzqre909m2r", + ), + ( + "3CWFddi6m4ndiGyKqzYvsFYagqDLPVMTzC", + "bitcoincash:ppm2qsznhks23z7629mms6s4cwef74vcwvn0h829pq", + ), + ( + "3LDsS579y7sruadqu11beEJoTjdFiFCdX4", + "bitcoincash:pr95sy3j9xwd2ap32xkykttr4cvcu7as4yc93ky28e", + ), + ( + "31nwvkZwyPdgzjBJZXfDmSWsC4ZLKpYyUw", + "bitcoincash:pqq3728yw0y47sqn6l2na30mcw6zm78dzq5ucqzc37", + ), ] class TestCryptoCashAddr(unittest.TestCase): - def test_valid_checksum(self): for test in VALID_CHECKSUM: - prefix, addr = test.split(':') + prefix, addr = test.split(":") cashaddr.decode(prefix, addr) def test_invalid_checksum(self): for test in VALID_CHECKSUM: - test += 'xxx' - prefix, addr = test.split(':') + test += "xxx" + prefix, addr = test.split(":") with self.assertRaises(ValueError): cashaddr.decode(prefix, addr) @@ -65,11 +82,11 @@ class TestCryptoCashAddr(unittest.TestCase): version = data[0] if version == 5: version = 8 - enc = cashaddr.encode('bitcoincash', version, data[1:]) + enc = cashaddr.encode("bitcoincash", version, data[1:]) self.assertEqual(ca, enc) # cashaddr -> base58 for b58, ca in VALID_ADDRESS: - prefix, addr = ca.split(':') + prefix, addr = ca.split(":") version, data = cashaddr.decode(prefix, addr) if version == 8: version = 5 diff --git a/core/tests/test_trezor.crypto.chacha20poly1305.py b/core/tests/test_trezor.crypto.chacha20poly1305.py index b16b5230cf..1055cb4546 100644 --- a/core/tests/test_trezor.crypto.chacha20poly1305.py +++ b/core/tests/test_trezor.crypto.chacha20poly1305.py @@ -8,21 +8,21 @@ class TestCryptoChaCha20Poly1305(unittest.TestCase): vectors = [ # from https://github.com/wg/c20p1305/blob/master/rfc7539_test.c ( - '4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e', - '50515253c0c1c2c3c4c5c6c7', - '808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f', - '070000004041424344454647', - 'd31a8d34648e60db7b86afbc53ef7ec2a4aded51296e08fea9e2b5a736ee62d63dbea45e8ca9671282fafb69da92728b1a71de0a9e060b2905d6a5b67ecd3b3692ddbd7f2d778b8c9803aee328091b58fab324e4fad675945585808b4831d7bc3ff4def08e4b7a9de576d26586cec64b6116', - '1ae10b594f09e26a7e902ecbd0600691', + "4c616469657320616e642047656e746c656d656e206f662074686520636c617373206f66202739393a204966204920636f756c64206f6666657220796f75206f6e6c79206f6e652074697020666f7220746865206675747572652c2073756e73637265656e20776f756c642062652069742e", + "50515253c0c1c2c3c4c5c6c7", + "808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9f", + "070000004041424344454647", + "d31a8d34648e60db7b86afbc53ef7ec2a4aded51296e08fea9e2b5a736ee62d63dbea45e8ca9671282fafb69da92728b1a71de0a9e060b2905d6a5b67ecd3b3692ddbd7f2d778b8c9803aee328091b58fab324e4fad675945585808b4831d7bc3ff4def08e4b7a9de576d26586cec64b6116", + "1ae10b594f09e26a7e902ecbd0600691", ), # from https://tools.ietf.org/html/rfc7539#appendix-A.5 ( - '496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d6f6e74687320616e64206d617920626520757064617465642c207265706c616365642c206f72206f62736f6c65746564206279206f7468657220646f63756d656e747320617420616e792074696d652e20497420697320696e617070726f70726961746520746f2075736520496e7465726e65742d447261667473206173207265666572656e6365206d6174657269616c206f7220746f2063697465207468656d206f74686572207468616e206173202fe2809c776f726b20696e2070726f67726573732e2fe2809d', - 'f33388860000000000004e91', - '1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0', - '000000000102030405060708', - '64a0861575861af460f062c79be643bd5e805cfd345cf389f108670ac76c8cb24c6cfc18755d43eea09ee94e382d26b0bdb7b73c321b0100d4f03b7f355894cf332f830e710b97ce98c8a84abd0b948114ad176e008d33bd60f982b1ff37c8559797a06ef4f0ef61c186324e2b3506383606907b6a7c02b0f9f6157b53c867e4b9166c767b804d46a59b5216cde7a4e99040c5a40433225ee282a1b0a06c523eaf4534d7f83fa1155b0047718cbc546a0d072b04b3564eea1b422273f548271a0bb2316053fa76991955ebd63159434ecebb4e466dae5a1073a6727627097a1049e617d91d361094fa68f0ff77987130305beaba2eda04df997b714d6c6f2c29a6ad5cb4022b02709b', - 'eead9d67890cbb22392336fea1851f38', + "496e7465726e65742d4472616674732061726520647261667420646f63756d656e74732076616c696420666f722061206d6178696d756d206f6620736978206d6f6e74687320616e64206d617920626520757064617465642c207265706c616365642c206f72206f62736f6c65746564206279206f7468657220646f63756d656e747320617420616e792074696d652e20497420697320696e617070726f70726961746520746f2075736520496e7465726e65742d447261667473206173207265666572656e6365206d6174657269616c206f7220746f2063697465207468656d206f74686572207468616e206173202fe2809c776f726b20696e2070726f67726573732e2fe2809d", + "f33388860000000000004e91", + "1c9240a5eb55d38af333888604f6b5f0473917c1402b80099dca5cbc207075c0", + "000000000102030405060708", + "64a0861575861af460f062c79be643bd5e805cfd345cf389f108670ac76c8cb24c6cfc18755d43eea09ee94e382d26b0bdb7b73c321b0100d4f03b7f355894cf332f830e710b97ce98c8a84abd0b948114ad176e008d33bd60f982b1ff37c8559797a06ef4f0ef61c186324e2b3506383606907b6a7c02b0f9f6157b53c867e4b9166c767b804d46a59b5216cde7a4e99040c5a40433225ee282a1b0a06c523eaf4534d7f83fa1155b0047718cbc546a0d072b04b3564eea1b422273f548271a0bb2316053fa76991955ebd63159434ecebb4e466dae5a1073a6727627097a1049e617d91d361094fa68f0ff77987130305beaba2eda04df997b714d6c6f2c29a6ad5cb4022b02709b", + "eead9d67890cbb22392336fea1851f38", ), ] @@ -57,5 +57,5 @@ class TestCryptoChaCha20Poly1305(unittest.TestCase): self.assertEqual(out, unhexlify(tag)) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.crc.py b/core/tests/test_trezor.crypto.crc.py index b9d968460b..ba0dfa3df1 100644 --- a/core/tests/test_trezor.crypto.crc.py +++ b/core/tests/test_trezor.crypto.crc.py @@ -6,11 +6,26 @@ from trezor.crypto import crc class TestCryptoCrc(unittest.TestCase): vectors_crc32 = [ - ('123456789', 0xCBF43926), - (unhexlify('0000000000000000000000000000000000000000000000000000000000000000'), 0x190A55AD), - (unhexlify('FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF'), 0xFF6CAB0B), - (unhexlify('000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F'), 0x91267E8A), - ('The quick brown fox jumps over the lazy dog', 0x414FA339), + ("123456789", 0xCBF43926), + ( + unhexlify( + "0000000000000000000000000000000000000000000000000000000000000000" + ), + 0x190A55AD, + ), + ( + unhexlify( + "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF" + ), + 0xFF6CAB0B, + ), + ( + unhexlify( + "000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F" + ), + 0x91267E8A, + ), + ("The quick brown fox jumps over the lazy dog", 0x414FA339), ] def test_crc32(self): @@ -18,5 +33,5 @@ class TestCryptoCrc(unittest.TestCase): self.assertEqual(crc.crc32(i), o) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.curve.curve25519.py b/core/tests/test_trezor.crypto.curve.curve25519.py index b6c6f5499c..1f0a31961f 100644 --- a/core/tests/test_trezor.crypto.curve.curve25519.py +++ b/core/tests/test_trezor.crypto.curve.curve25519.py @@ -6,7 +6,11 @@ from trezor.crypto.curve import curve25519 class TestCryptoCurve25519(unittest.TestCase): vectors = [ - ('38c9d9b17911de26ed812f5cc19c0029e8d016bcbc6078bc9db2af33f1761e4a', '311b6248af8dabec5cc81eac5bf229925f6d218a12e0547fb1856e015cc76f5d', 'a93dbdb23e5c99da743e203bd391af79f2b83fb8d0fd6ec813371c71f08f2d4d'), + ( + "38c9d9b17911de26ed812f5cc19c0029e8d016bcbc6078bc9db2af33f1761e4a", + "311b6248af8dabec5cc81eac5bf229925f6d218a12e0547fb1856e015cc76f5d", + "a93dbdb23e5c99da743e203bd391af79f2b83fb8d0fd6ec813371c71f08f2d4d", + ), ] def test_generate_secret(self): @@ -31,5 +35,5 @@ class TestCryptoCurve25519(unittest.TestCase): self.assertEqual(session1, session2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.curve.ed25519.py b/core/tests/test_trezor.crypto.curve.ed25519.py index 4183f241c2..79fda72b40 100644 --- a/core/tests/test_trezor.crypto.curve.ed25519.py +++ b/core/tests/test_trezor.crypto.curve.ed25519.py @@ -9,14 +9,46 @@ class TestCryptoEd25519(unittest.TestCase): # vectors from https://github.com/torproject/tor/blob/master/src/test/ed25519_vectors.inc vectors = [ - ('26c76712d89d906e6672dafa614c42e5cb1caac8c6568e4d2493087db51f0d36', 'c2247870536a192d142d056abefca68d6193158e7c1a59c1654c954eccaff894', 'd23188eac3773a316d46006fa59c095060be8b1a23582a0dd99002a82a0662bd246d8449e172e04c5f46ac0d1404cebe4aabd8a75a1457aa06cae41f3334f104'), - ('fba7a5366b5cb98c2667a18783f5cf8f4f8d1a2ce939ad22a6e685edde85128d', '1519a3b15816a1aafab0b213892026ebf5c0dc232c58b21088d88cb90e9b940d', '3a785ac1201c97ee5f6f0d99323960d5f264c7825e61aa7cc81262f15bef75eb4fa5723add9b9d45b12311b6d403eb3ac79ff8e4e631fc3cd51e4ad2185b200b'), - ('67e3aa7a14fac8445d15e45e38a523481a69ae35513c9e4143eb1c2196729a0e', '081faa81992e360ea22c06af1aba096e7a73f1c665bc8b3e4e531c46455fd1dd', 'cf431fd0416bfbd20c9d95ef9b723e2acddffb33900edc72195dea95965d52d888d30b7b8a677c0bd8ae1417b1e1a0ec6700deadd5d8b54b6689275e04a04509'), - ('d51385942033a76dc17f089a59e6a5a7fe80d9c526ae8ddd8c3a506b99d3d0a6', '73cfa1189a723aad7966137cbffa35140bb40d7e16eae4c40b79b5f0360dd65a', '2375380cd72d1a6c642aeddff862be8a5804b916acb72c02d9ed052c1561881aa658a5af856fcd6d43113e42f698cd6687c99efeef7f2ce045824440d26c5d00'), - ('5c8eac469bb3f1b85bc7cd893f52dc42a9ab66f1b02b5ce6a68e9b175d3bb433', '66c1a77104d86461b6f98f73acf3cd229c80624495d2d74d6fda1e940080a96b', '2385a472f599ca965bbe4d610e391cdeabeba9c336694b0d6249e551458280be122c2441dd9746a81bbfb9cd619364bab0df37ff4ceb7aefd24469c39d3bc508'), - ('eda433d483059b6d1ff8b7cfbd0fe406bfb23722c8f3c8252629284573b61b86', 'd21c294db0e64cb2d8976625786ede1d9754186ae8197a64d72f68c792eecc19', 'e500cd0b8cfff35442f88008d894f3a2fa26ef7d3a0ca5714ae0d3e2d40caae58ba7cdf69dd126994dad6be536fcda846d89dd8138d1683cc144c8853dce7607'), - ('4377c40431c30883c5fbd9bc92ae48d1ed8a47b81d13806beac5351739b5533d', 'c4d58b4cf85a348ff3d410dd936fa460c4f18da962c01b1963792b9dcc8a6ea6', 'd187b9e334b0050154de10bf69b3e4208a584e1a65015ec28b14bcc252cf84b8baa9c94867daa60f2a82d09ba9652d41e8dde292b624afc8d2c26441b95e3c0e'), - ('c6bbcce615839756aed2cc78b1de13884dd3618f48367a17597a16c1cd7a290b', '95126f14d86494020665face03f2d42ee2b312a85bc729903eb17522954a1c4a', '815213640a643d198bd056e02bba74e1c8d2d931643e84497adf3347eb485079c9afe0afce9284cdc084946b561abbb214f1304ca11228ff82702185cf28f60d'), + ( + "26c76712d89d906e6672dafa614c42e5cb1caac8c6568e4d2493087db51f0d36", + "c2247870536a192d142d056abefca68d6193158e7c1a59c1654c954eccaff894", + "d23188eac3773a316d46006fa59c095060be8b1a23582a0dd99002a82a0662bd246d8449e172e04c5f46ac0d1404cebe4aabd8a75a1457aa06cae41f3334f104", + ), + ( + "fba7a5366b5cb98c2667a18783f5cf8f4f8d1a2ce939ad22a6e685edde85128d", + "1519a3b15816a1aafab0b213892026ebf5c0dc232c58b21088d88cb90e9b940d", + "3a785ac1201c97ee5f6f0d99323960d5f264c7825e61aa7cc81262f15bef75eb4fa5723add9b9d45b12311b6d403eb3ac79ff8e4e631fc3cd51e4ad2185b200b", + ), + ( + "67e3aa7a14fac8445d15e45e38a523481a69ae35513c9e4143eb1c2196729a0e", + "081faa81992e360ea22c06af1aba096e7a73f1c665bc8b3e4e531c46455fd1dd", + "cf431fd0416bfbd20c9d95ef9b723e2acddffb33900edc72195dea95965d52d888d30b7b8a677c0bd8ae1417b1e1a0ec6700deadd5d8b54b6689275e04a04509", + ), + ( + "d51385942033a76dc17f089a59e6a5a7fe80d9c526ae8ddd8c3a506b99d3d0a6", + "73cfa1189a723aad7966137cbffa35140bb40d7e16eae4c40b79b5f0360dd65a", + "2375380cd72d1a6c642aeddff862be8a5804b916acb72c02d9ed052c1561881aa658a5af856fcd6d43113e42f698cd6687c99efeef7f2ce045824440d26c5d00", + ), + ( + "5c8eac469bb3f1b85bc7cd893f52dc42a9ab66f1b02b5ce6a68e9b175d3bb433", + "66c1a77104d86461b6f98f73acf3cd229c80624495d2d74d6fda1e940080a96b", + "2385a472f599ca965bbe4d610e391cdeabeba9c336694b0d6249e551458280be122c2441dd9746a81bbfb9cd619364bab0df37ff4ceb7aefd24469c39d3bc508", + ), + ( + "eda433d483059b6d1ff8b7cfbd0fe406bfb23722c8f3c8252629284573b61b86", + "d21c294db0e64cb2d8976625786ede1d9754186ae8197a64d72f68c792eecc19", + "e500cd0b8cfff35442f88008d894f3a2fa26ef7d3a0ca5714ae0d3e2d40caae58ba7cdf69dd126994dad6be536fcda846d89dd8138d1683cc144c8853dce7607", + ), + ( + "4377c40431c30883c5fbd9bc92ae48d1ed8a47b81d13806beac5351739b5533d", + "c4d58b4cf85a348ff3d410dd936fa460c4f18da962c01b1963792b9dcc8a6ea6", + "d187b9e334b0050154de10bf69b3e4208a584e1a65015ec28b14bcc252cf84b8baa9c94867daa60f2a82d09ba9652d41e8dde292b624afc8d2c26441b95e3c0e", + ), + ( + "c6bbcce615839756aed2cc78b1de13884dd3618f48367a17597a16c1cd7a290b", + "95126f14d86494020665face03f2d42ee2b312a85bc729903eb17522954a1c4a", + "815213640a643d198bd056e02bba74e1c8d2d931643e84497adf3347eb485079c9afe0afce9284cdc084946b561abbb214f1304ca11228ff82702185cf28f60d", + ), ] def test_publickey(self): @@ -33,7 +65,9 @@ class TestCryptoEd25519(unittest.TestCase): def test_verify(self): for sk, pk, sig in self.vectors: # msg = pk - self.assertTrue(ed25519.verify(unhexlify(pk), unhexlify(sig), unhexlify(pk))) + self.assertTrue( + ed25519.verify(unhexlify(pk), unhexlify(sig), unhexlify(pk)) + ) pass def test_generate_secret(self): @@ -51,5 +85,5 @@ class TestCryptoEd25519(unittest.TestCase): self.assertTrue(ed25519.verify(pk, sig, msg)) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.curve.nist256p1.py b/core/tests/test_trezor.crypto.curve.nist256p1.py index d435bdd715..8d00b1fcd9 100644 --- a/core/tests/test_trezor.crypto.curve.nist256p1.py +++ b/core/tests/test_trezor.crypto.curve.nist256p1.py @@ -8,80 +8,241 @@ class TestCryptoNist256p1(unittest.TestCase): # vectors from http://point-at-infinity.org/ecc/nisttv vectors = [ - (1, '6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5'), - (2, '7CF27B188D034F7E8A52380304B51AC3C08969E277F21B35A60B48FC4766997807775510DB8ED040293D9AC69F7430DBBA7DADE63CE982299E04B79D227873D1'), - (3, '5ECBE4D1A6330A44C8F7EF951D4BF165E6C6B721EFADA985FB41661BC6E7FD6C8734640C4998FF7E374B06CE1A64A2ECD82AB036384FB83D9A79B127A27D5032'), - (4, 'E2534A3532D08FBBA02DDE659EE62BD0031FE2DB785596EF509302446B030852E0F1575A4C633CC719DFEE5FDA862D764EFC96C3F30EE0055C42C23F184ED8C6'), - (5, '51590B7A515140D2D784C85608668FDFEF8C82FD1F5BE52421554A0DC3D033EDE0C17DA8904A727D8AE1BF36BF8A79260D012F00D4D80888D1D0BB44FDA16DA4'), - (6, 'B01A172A76A4602C92D3242CB897DDE3024C740DEBB215B4C6B0AAE93C2291A9E85C10743237DAD56FEC0E2DFBA703791C00F7701C7E16BDFD7C48538FC77FE2'), - (7, '8E533B6FA0BF7B4625BB30667C01FB607EF9F8B8A80FEF5B300628703187B2A373EB1DBDE03318366D069F83A6F5900053C73633CB041B21C55E1A86C1F400B4'), - (8, '62D9779DBEE9B0534042742D3AB54CADC1D238980FCE97DBB4DD9DC1DB6FB393AD5ACCBD91E9D8244FF15D771167CEE0A2ED51F6BBE76A78DA540A6A0F09957E'), - (9, 'EA68D7B6FEDF0B71878938D51D71F8729E0ACB8C2C6DF8B3D79E8A4B90949EE02A2744C972C9FCE787014A964A8EA0C84D714FEAA4DE823FE85A224A4DD048FA'), - (10, 'CEF66D6B2A3A993E591214D1EA223FB545CA6C471C48306E4C36069404C5723F878662A229AAAE906E123CDD9D3B4C10590DED29FE751EEECA34BBAA44AF0773'), - (11, '3ED113B7883B4C590638379DB0C21CDA16742ED0255048BF433391D374BC21D19099209ACCC4C8A224C843AFA4F4C68A090D04DA5E9889DAE2F8EEFCE82A3740'), - (12, '741DD5BDA817D95E4626537320E5D55179983028B2F82C99D500C5EE8624E3C40770B46A9C385FDC567383554887B1548EEB912C35BA5CA71995FF22CD4481D3'), - (13, '177C837AE0AC495A61805DF2D85EE2FC792E284B65EAD58A98E15D9D46072C0163BB58CD4EBEA558A24091ADB40F4E7226EE14C3A1FB4DF39C43BBE2EFC7BFD8'), - (14, '54E77A001C3862B97A76647F4336DF3CF126ACBE7A069C5E5709277324D2920BF599F1BB29F4317542121F8C05A2E7C37171EA77735090081BA7C82F60D0B375'), - (15, 'F0454DC6971ABAE7ADFB378999888265AE03AF92DE3A0EF163668C63E59B9D5FB5B93EE3592E2D1F4E6594E51F9643E62A3B21CE75B5FA3F47E59CDE0D034F36'), - (16, '76A94D138A6B41858B821C629836315FCD28392EFF6CA038A5EB4787E1277C6EA985FE61341F260E6CB0A1B5E11E87208599A0040FC78BAA0E9DDD724B8C5110'), - (17, '47776904C0F1CC3A9C0984B66F75301A5FA68678F0D64AF8BA1ABCE34738A73EAA005EE6B5B957286231856577648E8381B2804428D5733F32F787FF71F1FCDC'), - (18, '1057E0AB5780F470DEFC9378D1C7C87437BB4C6F9EA55C63D936266DBD781FDAF6F1645A15CBE5DC9FA9B7DFD96EE5A7DCC11B5C5EF4F1F78D83B3393C6A45A2'), - (19, 'CB6D2861102C0C25CE39B7C17108C507782C452257884895C1FC7B74AB03ED8358D7614B24D9EF515C35E7100D6D6CE4A496716E30FA3E03E39150752BCECDAA'), - (20, '83A01A9378395BAB9BCD6A0AD03CC56D56E6B19250465A94A234DC4C6B28DA9A76E49B6DE2F73234AE6A5EB9D612B75C9F2202BB6923F54FF8240AAA86F640B8'), - (112233445566778899, '339150844EC15234807FE862A86BE77977DBFB3AE3D96F4C22795513AEAAB82FB1C14DDFDC8EC1B2583F51E85A5EB3A155840F2034730E9B5ADA38B674336A21'), - (112233445566778899112233445566778899, '1B7E046A076CC25E6D7FA5003F6729F665CC3241B5ADAB12B498CD32F2803264BFEA79BE2B666B073DB69A2A241ADAB0738FE9D2DD28B5604EB8C8CF097C457B'), - (29852220098221261079183923314599206100666902414330245206392788703677545185283, '9EACE8F4B071E677C5350B02F2BB2B384AAE89D58AA72CA97A170572E0FB222F1BBDAEC2430B09B93F7CB08678636CE12EAAFD58390699B5FD2F6E1188FC2A78'), - (57896042899961394862005778464643882389978449576758748073725983489954366354431, '878F22CC6DB6048D2B767268F22FFAD8E56AB8E2DC615F7BD89F1E350500DD8D714A5D7BB901C9C5853400D12341A892EF45D87FC553786756C4F0C9391D763E'), - (1766845392945710151501889105729049882997660004824848915955419660366636031, '659A379625AB122F2512B8DADA02C6348D53B54452DFF67AC7ACE4E8856295CA49D81AB97B648464D0B4A288BD7818FAB41A16426E943527C4FED8736C53D0F6'), - (28948025760307534517734791687894775804466072615242963443097661355606862201087, 'CBCEAAA8A4DD44BBCE58E8DB7740A5510EC2CB7EA8DA8D8F036B3FB04CDA4DE44BD7AA301A80D7F59FD983FEDBE59BB7B2863FE46494935E3745B360E32332FA'), - (113078210460870548944811695960290644973229224625838436424477095834645696384, 'F0C4A0576154FF3A33A3460D42EAED806E854DFA37125221D37935124BA462A45B392FA964434D29EEC6C9DBC261CF116796864AA2FAADB984A2DF38D1AEF7A3'), - (12078056106883488161242983286051341125085761470677906721917479268909056, '5E6C8524B6369530B12C62D31EC53E0288173BD662BDF680B53A41ECBCAD00CC447FE742C2BFEF4D0DB14B5B83A2682309B5618E0064A94804E9282179FE089F'), - (57782969857385448082319957860328652998540760998293976083718804450708503920639, '03792E541BC209076A3D7920A915021ECD396A6EB5C3960024BE5575F3223484FC774AE092403101563B712F68170312304F20C80B40C06282063DB25F268DE4'), - (57896017119460046759583662757090100341435943767777707906455551163257755533312, '2379FF85AB693CDF901D6CE6F2473F39C04A2FE3DCD842CE7AAB0E002095BCF8F8B476530A634589D5129E46F322B02FBC610A703D80875EE70D7CE1877436A1'), - (452312848374287284681282171017647412726433684238464212999305864837160993279, 'C1E4072C529BF2F44DA769EFC934472848003B3AF2C0F5AA8F8DDBD53E12ED7C39A6EE77812BB37E8079CD01ED649D3830FCA46F718C1D3993E4A591824ABCDB'), - (904571339174065134293634407946054000774746055866917729876676367558469746684, '34DFBC09404C21E250A9B40FA8772897AC63A094877DB65862B61BD1507B34F3CF6F8A876C6F99CEAEC87148F18C7E1E0DA6E165FFC8ED82ABB65955215F77D3'), - (115792089210356248762697446949407573529996955224135760342422259061068512044349, '83A01A9378395BAB9BCD6A0AD03CC56D56E6B19250465A94A234DC4C6B28DA9A891B64911D08CDCC5195A14629ED48A360DDFD4596DC0AB007DBF5557909BF47'), - (115792089210356248762697446949407573529996955224135760342422259061068512044350, 'CB6D2861102C0C25CE39B7C17108C507782C452257884895C1FC7B74AB03ED83A7289EB3DB2610AFA3CA18EFF292931B5B698E92CF05C1FC1C6EAF8AD4313255'), - (115792089210356248762697446949407573529996955224135760342422259061068512044351, '1057E0AB5780F470DEFC9378D1C7C87437BB4C6F9EA55C63D936266DBD781FDA090E9BA4EA341A246056482026911A58233EE4A4A10B0E08727C4CC6C395BA5D'), - (115792089210356248762697446949407573529996955224135760342422259061068512044352, '47776904C0F1CC3A9C0984B66F75301A5FA68678F0D64AF8BA1ABCE34738A73E55FFA1184A46A8D89DCE7A9A889B717C7E4D7FBCD72A8CC0CD0878008E0E0323'), - (115792089210356248762697446949407573529996955224135760342422259061068512044353, '76A94D138A6B41858B821C629836315FCD28392EFF6CA038A5EB4787E1277C6E567A019DCBE0D9F2934F5E4A1EE178DF7A665FFCF0387455F162228DB473AEEF'), - (115792089210356248762697446949407573529996955224135760342422259061068512044354, 'F0454DC6971ABAE7ADFB378999888265AE03AF92DE3A0EF163668C63E59B9D5F4A46C11BA6D1D2E1B19A6B1AE069BC19D5C4DE328A4A05C0B81A6321F2FCB0C9'), - (115792089210356248762697446949407573529996955224135760342422259061068512044355, '54E77A001C3862B97A76647F4336DF3CF126ACBE7A069C5E5709277324D2920B0A660E43D60BCE8BBDEDE073FA5D183C8E8E15898CAF6FF7E45837D09F2F4C8A'), - (115792089210356248762697446949407573529996955224135760342422259061068512044356, '177C837AE0AC495A61805DF2D85EE2FC792E284B65EAD58A98E15D9D46072C019C44A731B1415AA85DBF6E524BF0B18DD911EB3D5E04B20C63BC441D10384027'), - (115792089210356248762697446949407573529996955224135760342422259061068512044357, '741DD5BDA817D95E4626537320E5D55179983028B2F82C99D500C5EE8624E3C4F88F4B9463C7A024A98C7CAAB7784EAB71146ED4CA45A358E66A00DD32BB7E2C'), - (115792089210356248762697446949407573529996955224135760342422259061068512044358, '3ED113B7883B4C590638379DB0C21CDA16742ED0255048BF433391D374BC21D16F66DF64333B375EDB37BC505B0B3975F6F2FB26A16776251D07110317D5C8BF'), - (115792089210356248762697446949407573529996955224135760342422259061068512044359, 'CEF66D6B2A3A993E591214D1EA223FB545CA6C471C48306E4C36069404C5723F78799D5CD655517091EDC32262C4B3EFA6F212D7018AE11135CB4455BB50F88C'), - (115792089210356248762697446949407573529996955224135760342422259061068512044360, 'EA68D7B6FEDF0B71878938D51D71F8729E0ACB8C2C6DF8B3D79E8A4B90949EE0D5D8BB358D36031978FEB569B5715F37B28EB0165B217DC017A5DDB5B22FB705'), - (115792089210356248762697446949407573529996955224135760342422259061068512044361, '62D9779DBEE9B0534042742D3AB54CADC1D238980FCE97DBB4DD9DC1DB6FB39352A533416E1627DCB00EA288EE98311F5D12AE0A4418958725ABF595F0F66A81'), - (115792089210356248762697446949407573529996955224135760342422259061068512044362, '8E533B6FA0BF7B4625BB30667C01FB607EF9F8B8A80FEF5B300628703187B2A38C14E2411FCCE7CA92F9607C590A6FFFAC38C9CD34FBE4DE3AA1E5793E0BFF4B'), - (115792089210356248762697446949407573529996955224135760342422259061068512044363, 'B01A172A76A4602C92D3242CB897DDE3024C740DEBB215B4C6B0AAE93C2291A917A3EF8ACDC8252B9013F1D20458FC86E3FF0890E381E9420283B7AC7038801D'), - (115792089210356248762697446949407573529996955224135760342422259061068512044364, '51590B7A515140D2D784C85608668FDFEF8C82FD1F5BE52421554A0DC3D033ED1F3E82566FB58D83751E40C9407586D9F2FED1002B27F7772E2F44BB025E925B'), - (115792089210356248762697446949407573529996955224135760342422259061068512044365, 'E2534A3532D08FBBA02DDE659EE62BD0031FE2DB785596EF509302446B0308521F0EA8A4B39CC339E62011A02579D289B103693D0CF11FFAA3BD3DC0E7B12739'), - (115792089210356248762697446949407573529996955224135760342422259061068512044366, '5ECBE4D1A6330A44C8F7EF951D4BF165E6C6B721EFADA985FB41661BC6E7FD6C78CB9BF2B6670082C8B4F931E59B5D1327D54FCAC7B047C265864ED85D82AFCD'), - (115792089210356248762697446949407573529996955224135760342422259061068512044367, '7CF27B188D034F7E8A52380304B51AC3C08969E277F21B35A60B48FC47669978F888AAEE24712FC0D6C26539608BCF244582521AC3167DD661FB4862DD878C2E'), - (115792089210356248762697446949407573529996955224135760342422259061068512044368, '6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296B01CBD1C01E58065711814B583F061E9D431CCA994CEA1313449BF97C840AE0A'), + ( + 1, + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C2964FE342E2FE1A7F9B8EE7EB4A7C0F9E162BCE33576B315ECECBB6406837BF51F5", + ), + ( + 2, + "7CF27B188D034F7E8A52380304B51AC3C08969E277F21B35A60B48FC4766997807775510DB8ED040293D9AC69F7430DBBA7DADE63CE982299E04B79D227873D1", + ), + ( + 3, + "5ECBE4D1A6330A44C8F7EF951D4BF165E6C6B721EFADA985FB41661BC6E7FD6C8734640C4998FF7E374B06CE1A64A2ECD82AB036384FB83D9A79B127A27D5032", + ), + ( + 4, + "E2534A3532D08FBBA02DDE659EE62BD0031FE2DB785596EF509302446B030852E0F1575A4C633CC719DFEE5FDA862D764EFC96C3F30EE0055C42C23F184ED8C6", + ), + ( + 5, + "51590B7A515140D2D784C85608668FDFEF8C82FD1F5BE52421554A0DC3D033EDE0C17DA8904A727D8AE1BF36BF8A79260D012F00D4D80888D1D0BB44FDA16DA4", + ), + ( + 6, + "B01A172A76A4602C92D3242CB897DDE3024C740DEBB215B4C6B0AAE93C2291A9E85C10743237DAD56FEC0E2DFBA703791C00F7701C7E16BDFD7C48538FC77FE2", + ), + ( + 7, + "8E533B6FA0BF7B4625BB30667C01FB607EF9F8B8A80FEF5B300628703187B2A373EB1DBDE03318366D069F83A6F5900053C73633CB041B21C55E1A86C1F400B4", + ), + ( + 8, + "62D9779DBEE9B0534042742D3AB54CADC1D238980FCE97DBB4DD9DC1DB6FB393AD5ACCBD91E9D8244FF15D771167CEE0A2ED51F6BBE76A78DA540A6A0F09957E", + ), + ( + 9, + "EA68D7B6FEDF0B71878938D51D71F8729E0ACB8C2C6DF8B3D79E8A4B90949EE02A2744C972C9FCE787014A964A8EA0C84D714FEAA4DE823FE85A224A4DD048FA", + ), + ( + 10, + "CEF66D6B2A3A993E591214D1EA223FB545CA6C471C48306E4C36069404C5723F878662A229AAAE906E123CDD9D3B4C10590DED29FE751EEECA34BBAA44AF0773", + ), + ( + 11, + "3ED113B7883B4C590638379DB0C21CDA16742ED0255048BF433391D374BC21D19099209ACCC4C8A224C843AFA4F4C68A090D04DA5E9889DAE2F8EEFCE82A3740", + ), + ( + 12, + "741DD5BDA817D95E4626537320E5D55179983028B2F82C99D500C5EE8624E3C40770B46A9C385FDC567383554887B1548EEB912C35BA5CA71995FF22CD4481D3", + ), + ( + 13, + "177C837AE0AC495A61805DF2D85EE2FC792E284B65EAD58A98E15D9D46072C0163BB58CD4EBEA558A24091ADB40F4E7226EE14C3A1FB4DF39C43BBE2EFC7BFD8", + ), + ( + 14, + "54E77A001C3862B97A76647F4336DF3CF126ACBE7A069C5E5709277324D2920BF599F1BB29F4317542121F8C05A2E7C37171EA77735090081BA7C82F60D0B375", + ), + ( + 15, + "F0454DC6971ABAE7ADFB378999888265AE03AF92DE3A0EF163668C63E59B9D5FB5B93EE3592E2D1F4E6594E51F9643E62A3B21CE75B5FA3F47E59CDE0D034F36", + ), + ( + 16, + "76A94D138A6B41858B821C629836315FCD28392EFF6CA038A5EB4787E1277C6EA985FE61341F260E6CB0A1B5E11E87208599A0040FC78BAA0E9DDD724B8C5110", + ), + ( + 17, + "47776904C0F1CC3A9C0984B66F75301A5FA68678F0D64AF8BA1ABCE34738A73EAA005EE6B5B957286231856577648E8381B2804428D5733F32F787FF71F1FCDC", + ), + ( + 18, + "1057E0AB5780F470DEFC9378D1C7C87437BB4C6F9EA55C63D936266DBD781FDAF6F1645A15CBE5DC9FA9B7DFD96EE5A7DCC11B5C5EF4F1F78D83B3393C6A45A2", + ), + ( + 19, + "CB6D2861102C0C25CE39B7C17108C507782C452257884895C1FC7B74AB03ED8358D7614B24D9EF515C35E7100D6D6CE4A496716E30FA3E03E39150752BCECDAA", + ), + ( + 20, + "83A01A9378395BAB9BCD6A0AD03CC56D56E6B19250465A94A234DC4C6B28DA9A76E49B6DE2F73234AE6A5EB9D612B75C9F2202BB6923F54FF8240AAA86F640B8", + ), + ( + 112233445566778899, + "339150844EC15234807FE862A86BE77977DBFB3AE3D96F4C22795513AEAAB82FB1C14DDFDC8EC1B2583F51E85A5EB3A155840F2034730E9B5ADA38B674336A21", + ), + ( + 112233445566778899112233445566778899, + "1B7E046A076CC25E6D7FA5003F6729F665CC3241B5ADAB12B498CD32F2803264BFEA79BE2B666B073DB69A2A241ADAB0738FE9D2DD28B5604EB8C8CF097C457B", + ), + ( + 29852220098221261079183923314599206100666902414330245206392788703677545185283, + "9EACE8F4B071E677C5350B02F2BB2B384AAE89D58AA72CA97A170572E0FB222F1BBDAEC2430B09B93F7CB08678636CE12EAAFD58390699B5FD2F6E1188FC2A78", + ), + ( + 57896042899961394862005778464643882389978449576758748073725983489954366354431, + "878F22CC6DB6048D2B767268F22FFAD8E56AB8E2DC615F7BD89F1E350500DD8D714A5D7BB901C9C5853400D12341A892EF45D87FC553786756C4F0C9391D763E", + ), + ( + 1766845392945710151501889105729049882997660004824848915955419660366636031, + "659A379625AB122F2512B8DADA02C6348D53B54452DFF67AC7ACE4E8856295CA49D81AB97B648464D0B4A288BD7818FAB41A16426E943527C4FED8736C53D0F6", + ), + ( + 28948025760307534517734791687894775804466072615242963443097661355606862201087, + "CBCEAAA8A4DD44BBCE58E8DB7740A5510EC2CB7EA8DA8D8F036B3FB04CDA4DE44BD7AA301A80D7F59FD983FEDBE59BB7B2863FE46494935E3745B360E32332FA", + ), + ( + 113078210460870548944811695960290644973229224625838436424477095834645696384, + "F0C4A0576154FF3A33A3460D42EAED806E854DFA37125221D37935124BA462A45B392FA964434D29EEC6C9DBC261CF116796864AA2FAADB984A2DF38D1AEF7A3", + ), + ( + 12078056106883488161242983286051341125085761470677906721917479268909056, + "5E6C8524B6369530B12C62D31EC53E0288173BD662BDF680B53A41ECBCAD00CC447FE742C2BFEF4D0DB14B5B83A2682309B5618E0064A94804E9282179FE089F", + ), + ( + 57782969857385448082319957860328652998540760998293976083718804450708503920639, + "03792E541BC209076A3D7920A915021ECD396A6EB5C3960024BE5575F3223484FC774AE092403101563B712F68170312304F20C80B40C06282063DB25F268DE4", + ), + ( + 57896017119460046759583662757090100341435943767777707906455551163257755533312, + "2379FF85AB693CDF901D6CE6F2473F39C04A2FE3DCD842CE7AAB0E002095BCF8F8B476530A634589D5129E46F322B02FBC610A703D80875EE70D7CE1877436A1", + ), + ( + 452312848374287284681282171017647412726433684238464212999305864837160993279, + "C1E4072C529BF2F44DA769EFC934472848003B3AF2C0F5AA8F8DDBD53E12ED7C39A6EE77812BB37E8079CD01ED649D3830FCA46F718C1D3993E4A591824ABCDB", + ), + ( + 904571339174065134293634407946054000774746055866917729876676367558469746684, + "34DFBC09404C21E250A9B40FA8772897AC63A094877DB65862B61BD1507B34F3CF6F8A876C6F99CEAEC87148F18C7E1E0DA6E165FFC8ED82ABB65955215F77D3", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044349, + "83A01A9378395BAB9BCD6A0AD03CC56D56E6B19250465A94A234DC4C6B28DA9A891B64911D08CDCC5195A14629ED48A360DDFD4596DC0AB007DBF5557909BF47", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044350, + "CB6D2861102C0C25CE39B7C17108C507782C452257884895C1FC7B74AB03ED83A7289EB3DB2610AFA3CA18EFF292931B5B698E92CF05C1FC1C6EAF8AD4313255", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044351, + "1057E0AB5780F470DEFC9378D1C7C87437BB4C6F9EA55C63D936266DBD781FDA090E9BA4EA341A246056482026911A58233EE4A4A10B0E08727C4CC6C395BA5D", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044352, + "47776904C0F1CC3A9C0984B66F75301A5FA68678F0D64AF8BA1ABCE34738A73E55FFA1184A46A8D89DCE7A9A889B717C7E4D7FBCD72A8CC0CD0878008E0E0323", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044353, + "76A94D138A6B41858B821C629836315FCD28392EFF6CA038A5EB4787E1277C6E567A019DCBE0D9F2934F5E4A1EE178DF7A665FFCF0387455F162228DB473AEEF", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044354, + "F0454DC6971ABAE7ADFB378999888265AE03AF92DE3A0EF163668C63E59B9D5F4A46C11BA6D1D2E1B19A6B1AE069BC19D5C4DE328A4A05C0B81A6321F2FCB0C9", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044355, + "54E77A001C3862B97A76647F4336DF3CF126ACBE7A069C5E5709277324D2920B0A660E43D60BCE8BBDEDE073FA5D183C8E8E15898CAF6FF7E45837D09F2F4C8A", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044356, + "177C837AE0AC495A61805DF2D85EE2FC792E284B65EAD58A98E15D9D46072C019C44A731B1415AA85DBF6E524BF0B18DD911EB3D5E04B20C63BC441D10384027", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044357, + "741DD5BDA817D95E4626537320E5D55179983028B2F82C99D500C5EE8624E3C4F88F4B9463C7A024A98C7CAAB7784EAB71146ED4CA45A358E66A00DD32BB7E2C", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044358, + "3ED113B7883B4C590638379DB0C21CDA16742ED0255048BF433391D374BC21D16F66DF64333B375EDB37BC505B0B3975F6F2FB26A16776251D07110317D5C8BF", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044359, + "CEF66D6B2A3A993E591214D1EA223FB545CA6C471C48306E4C36069404C5723F78799D5CD655517091EDC32262C4B3EFA6F212D7018AE11135CB4455BB50F88C", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044360, + "EA68D7B6FEDF0B71878938D51D71F8729E0ACB8C2C6DF8B3D79E8A4B90949EE0D5D8BB358D36031978FEB569B5715F37B28EB0165B217DC017A5DDB5B22FB705", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044361, + "62D9779DBEE9B0534042742D3AB54CADC1D238980FCE97DBB4DD9DC1DB6FB39352A533416E1627DCB00EA288EE98311F5D12AE0A4418958725ABF595F0F66A81", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044362, + "8E533B6FA0BF7B4625BB30667C01FB607EF9F8B8A80FEF5B300628703187B2A38C14E2411FCCE7CA92F9607C590A6FFFAC38C9CD34FBE4DE3AA1E5793E0BFF4B", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044363, + "B01A172A76A4602C92D3242CB897DDE3024C740DEBB215B4C6B0AAE93C2291A917A3EF8ACDC8252B9013F1D20458FC86E3FF0890E381E9420283B7AC7038801D", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044364, + "51590B7A515140D2D784C85608668FDFEF8C82FD1F5BE52421554A0DC3D033ED1F3E82566FB58D83751E40C9407586D9F2FED1002B27F7772E2F44BB025E925B", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044365, + "E2534A3532D08FBBA02DDE659EE62BD0031FE2DB785596EF509302446B0308521F0EA8A4B39CC339E62011A02579D289B103693D0CF11FFAA3BD3DC0E7B12739", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044366, + "5ECBE4D1A6330A44C8F7EF951D4BF165E6C6B721EFADA985FB41661BC6E7FD6C78CB9BF2B6670082C8B4F931E59B5D1327D54FCAC7B047C265864ED85D82AFCD", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044367, + "7CF27B188D034F7E8A52380304B51AC3C08969E277F21B35A60B48FC47669978F888AAEE24712FC0D6C26539608BCF244582521AC3167DD661FB4862DD878C2E", + ), + ( + 115792089210356248762697446949407573529996955224135760342422259061068512044368, + "6B17D1F2E12C4247F8BCE6E563A440F277037D812DEB33A0F4A13945D898C296B01CBD1C01E58065711814B583F061E9D431CCA994CEA1313449BF97C840AE0A", + ), ] def test_generate_secret(self): for _ in range(100): sk = nist256p1.generate_secret() self.assertTrue(len(sk) == 32) - self.assertTrue(sk != b'\x00' * 32) - self.assertTrue(sk < b'\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xBC\xE6\xFA\xAD\xA7\x17\x9E\x84\xF3\xB9\xCA\xC2\xFC\x63\x25\x51') + self.assertTrue(sk != b"\x00" * 32) + self.assertTrue( + sk + < b"\xFF\xFF\xFF\xFF\x00\x00\x00\x00\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xBC\xE6\xFA\xAD\xA7\x17\x9E\x84\xF3\xB9\xCA\xC2\xFC\x63\x25\x51" + ) def test_publickey(self): for sk, pk in self.vectors: sk = hex(sk)[2:] if len(sk) < 64: - sk = '0' * (64 - len(sk)) + sk + sk = "0" * (64 - len(sk)) + sk pk = pk.lower() - pk65 = hexlify(nist256p1.publickey(unhexlify(sk), False)).decode() # uncompressed - self.assertEqual(str(pk65), '04' + pk) + pk65 = hexlify( + nist256p1.publickey(unhexlify(sk), False) + ).decode() # uncompressed + self.assertEqual(str(pk65), "04" + pk) pk33 = hexlify(nist256p1.publickey(unhexlify(sk))).decode() - if pk[-1] in '02468ace': - self.assertEqual(pk33, '02' + pk[:64]) + if pk[-1] in "02468ace": + self.assertEqual(pk33, "02" + pk[:64]) else: - self.assertEqual(pk33, '03' + pk[:64]) + self.assertEqual(pk33, "03" + pk[:64]) def test_sign_verify_min_max(self): sk = nist256p1.generate_secret() @@ -122,5 +283,5 @@ class TestCryptoNist256p1(unittest.TestCase): self.assertEqual(pk, pk2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.curve.secp256k1.py b/core/tests/test_trezor.crypto.curve.secp256k1.py index 7b621826e4..d89b120b48 100644 --- a/core/tests/test_trezor.crypto.curve.secp256k1.py +++ b/core/tests/test_trezor.crypto.curve.secp256k1.py @@ -7,73 +7,213 @@ from trezor.crypto.curve import secp256k1 class TestCryptoSecp256k1(unittest.TestCase): # vectors from https://crypto.stackexchange.com/questions/784/are-there-any-secp256k1-ecdsa-test-examples-available vectors = [ - (1, '79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8'), - (2, 'C6047F9441ED7D6D3045406E95C07CD85C778E4B8CEF3CA7ABAC09B95C709EE51AE168FEA63DC339A3C58419466CEAEEF7F632653266D0E1236431A950CFE52A'), - (3, 'F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9388F7B0F632DE8140FE337E62A37F3566500A99934C2231B6CB9FD7584B8E672'), - (4, 'E493DBF1C10D80F3581E4904930B1404CC6C13900EE0758474FA94ABE8C4CD1351ED993EA0D455B75642E2098EA51448D967AE33BFBDFE40CFE97BDC47739922'), - (5, '2F8BDE4D1A07209355B4A7250A5C5128E88B84BDDC619AB7CBA8D569B240EFE4D8AC222636E5E3D6D4DBA9DDA6C9C426F788271BAB0D6840DCA87D3AA6AC62D6'), - (6, 'FFF97BD5755EEEA420453A14355235D382F6472F8568A18B2F057A1460297556AE12777AACFBB620F3BE96017F45C560DE80F0F6518FE4A03C870C36B075F297'), - (7, '5CBDF0646E5DB4EAA398F365F2EA7A0E3D419B7E0330E39CE92BDDEDCAC4F9BC6AEBCA40BA255960A3178D6D861A54DBA813D0B813FDE7B5A5082628087264DA'), - (8, '2F01E5E15CCA351DAFF3843FB70F3C2F0A1BDD05E5AF888A67784EF3E10A2A015C4DA8A741539949293D082A132D13B4C2E213D6BA5B7617B5DA2CB76CBDE904'), - (9, 'ACD484E2F0C7F65309AD178A9F559ABDE09796974C57E714C35F110DFC27CCBECC338921B0A7D9FD64380971763B61E9ADD888A4375F8E0F05CC262AC64F9C37'), - (10, 'A0434D9E47F3C86235477C7B1AE6AE5D3442D49B1943C2B752A68E2A47E247C7893ABA425419BC27A3B6C7E693A24C696F794C2ED877A1593CBEE53B037368D7'), - (11, '774AE7F858A9411E5EF4246B70C65AAC5649980BE5C17891BBEC17895DA008CBD984A032EB6B5E190243DD56D7B7B365372DB1E2DFF9D6A8301D74C9C953C61B'), - (12, 'D01115D548E7561B15C38F004D734633687CF4419620095BC5B0F47070AFE85AA9F34FFDC815E0D7A8B64537E17BD81579238C5DD9A86D526B051B13F4062327'), - (13, 'F28773C2D975288BC7D1D205C3748651B075FBC6610E58CDDEEDDF8F19405AA80AB0902E8D880A89758212EB65CDAF473A1A06DA521FA91F29B5CB52DB03ED81'), - (14, '499FDF9E895E719CFD64E67F07D38E3226AA7B63678949E6E49B241A60E823E4CAC2F6C4B54E855190F044E4A7B3D464464279C27A3F95BCC65F40D403A13F5B'), - (15, 'D7924D4F7D43EA965A465AE3095FF41131E5946F3C85F79E44ADBCF8E27E080E581E2872A86C72A683842EC228CC6DEFEA40AF2BD896D3A5C504DC9FF6A26B58'), - (16, 'E60FCE93B59E9EC53011AABC21C23E97B2A31369B87A5AE9C44EE89E2A6DEC0AF7E3507399E595929DB99F34F57937101296891E44D23F0BE1F32CCE69616821'), - (17, 'DEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A344211AB0694635168E997B0EAD2A93DAECED1F4A04A95C0F6CFB199F69E56EB77'), - (18, '5601570CB47F238D2B0286DB4A990FA0F3BA28D1A319F5E7CF55C2A2444DA7CCC136C1DC0CBEB930E9E298043589351D81D8E0BC736AE2A1F5192E5E8B061D58'), - (19, '2B4EA0A797A443D293EF5CFF444F4979F06ACFEBD7E86D277475656138385B6C85E89BC037945D93B343083B5A1C86131A01F60C50269763B570C854E5C09B7A'), - (20, '4CE119C96E2FA357200B559B2F7DD5A5F02D5290AFF74B03F3E471B273211C9712BA26DCB10EC1625DA61FA10A844C676162948271D96967450288EE9233DC3A'), - (112233445566778899, 'A90CC3D3F3E146DAADFC74CA1372207CB4B725AE708CEF713A98EDD73D99EF295A79D6B289610C68BC3B47F3D72F9788A26A06868B4D8E433E1E2AD76FB7DC76'), - (112233445566778899112233445566778899, 'E5A2636BCFD412EBF36EC45B19BFB68A1BC5F8632E678132B885F7DF99C5E9B3736C1CE161AE27B405CAFD2A7520370153C2C861AC51D6C1D5985D9606B45F39'), - (28948022309329048855892746252171976963209391069768726095651290785379540373584, 'A6B594B38FB3E77C6EDF78161FADE2041F4E09FD8497DB776E546C41567FEB3C71444009192228730CD8237A490FEBA2AFE3D27D7CC1136BC97E439D13330D55'), - (57896044618658097711785492504343953926418782139537452191302581570759080747168, '00000000000000000000003B78CE563F89A0ED9414F5AA28AD0D96D6795F9C633F3979BF72AE8202983DC989AEC7F2FF2ED91BDD69CE02FC0700CA100E59DDF3'), - (86844066927987146567678238756515930889628173209306178286953872356138621120752, 'E24CE4BEEE294AA6350FAA67512B99D388693AE4E7F53D19882A6EA169FC1CE18B71E83545FC2B5872589F99D948C03108D36797C4DE363EBD3FF6A9E1A95B10'), - (115792089237316195423570985008687907852837564279074904382605163141518161494317, '4CE119C96E2FA357200B559B2F7DD5A5F02D5290AFF74B03F3E471B273211C97ED45D9234EF13E9DA259E05EF57BB3989E9D6B7D8E269698BAFD77106DCC1FF5'), - (115792089237316195423570985008687907852837564279074904382605163141518161494318, '2B4EA0A797A443D293EF5CFF444F4979F06ACFEBD7E86D277475656138385B6C7A17643FC86BA26C4CBCF7C4A5E379ECE5FE09F3AFD9689C4A8F37AA1A3F60B5'), - (115792089237316195423570985008687907852837564279074904382605163141518161494319, '5601570CB47F238D2B0286DB4A990FA0F3BA28D1A319F5E7CF55C2A2444DA7CC3EC93E23F34146CF161D67FBCA76CAE27E271F438C951D5E0AE6D1A074F9DED7'), - (115792089237316195423570985008687907852837564279074904382605163141518161494320, 'DEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34BDEE54F96B9CAE9716684F152D56C251312E0B5FB56A3F09304E660861A910B8'), - (115792089237316195423570985008687907852837564279074904382605163141518161494321, 'E60FCE93B59E9EC53011AABC21C23E97B2A31369B87A5AE9C44EE89E2A6DEC0A081CAF8C661A6A6D624660CB0A86C8EFED6976E1BB2DC0F41E0CD330969E940E'), - (115792089237316195423570985008687907852837564279074904382605163141518161494322, 'D7924D4F7D43EA965A465AE3095FF41131E5946F3C85F79E44ADBCF8E27E080EA7E1D78D57938D597C7BD13DD733921015BF50D427692C5A3AFB235F095D90D7'), - (115792089237316195423570985008687907852837564279074904382605163141518161494323, '499FDF9E895E719CFD64E67F07D38E3226AA7B63678949E6E49B241A60E823E4353D093B4AB17AAE6F0FBB1B584C2B9BB9BD863D85C06A4339A0BF2AFC5EBCD4'), - (115792089237316195423570985008687907852837564279074904382605163141518161494324, 'F28773C2D975288BC7D1D205C3748651B075FBC6610E58CDDEEDDF8F19405AA8F54F6FD17277F5768A7DED149A3250B8C5E5F925ADE056E0D64A34AC24FC0EAE'), - (115792089237316195423570985008687907852837564279074904382605163141518161494325, 'D01115D548E7561B15C38F004D734633687CF4419620095BC5B0F47070AFE85A560CB00237EA1F285749BAC81E8427EA86DC73A2265792AD94FAE4EB0BF9D908'), - (115792089237316195423570985008687907852837564279074904382605163141518161494326, '774AE7F858A9411E5EF4246B70C65AAC5649980BE5C17891BBEC17895DA008CB267B5FCD1494A1E6FDBC22A928484C9AC8D24E1D20062957CFE28B3536AC3614'), - (115792089237316195423570985008687907852837564279074904382605163141518161494327, 'A0434D9E47F3C86235477C7B1AE6AE5D3442D49B1943C2B752A68E2A47E247C776C545BDABE643D85C4938196C5DB3969086B3D127885EA6C3411AC3FC8C9358'), - (115792089237316195423570985008687907852837564279074904382605163141518161494328, 'ACD484E2F0C7F65309AD178A9F559ABDE09796974C57E714C35F110DFC27CCBE33CC76DE4F5826029BC7F68E89C49E165227775BC8A071F0FA33D9D439B05FF8'), - (115792089237316195423570985008687907852837564279074904382605163141518161494329, '2F01E5E15CCA351DAFF3843FB70F3C2F0A1BDD05E5AF888A67784EF3E10A2A01A3B25758BEAC66B6D6C2F7D5ECD2EC4B3D1DEC2945A489E84A25D3479342132B'), - (115792089237316195423570985008687907852837564279074904382605163141518161494330, '5CBDF0646E5DB4EAA398F365F2EA7A0E3D419B7E0330E39CE92BDDEDCAC4F9BC951435BF45DAA69F5CE8729279E5AB2457EC2F47EC02184A5AF7D9D6F78D9755'), - (115792089237316195423570985008687907852837564279074904382605163141518161494331, 'FFF97BD5755EEEA420453A14355235D382F6472F8568A18B2F057A146029755651ED8885530449DF0C4169FE80BA3A9F217F0F09AE701B5FC378F3C84F8A0998'), - (115792089237316195423570985008687907852837564279074904382605163141518161494332, '2F8BDE4D1A07209355B4A7250A5C5128E88B84BDDC619AB7CBA8D569B240EFE42753DDD9C91A1C292B24562259363BD90877D8E454F297BF235782C459539959'), - (115792089237316195423570985008687907852837564279074904382605163141518161494333, 'E493DBF1C10D80F3581E4904930B1404CC6C13900EE0758474FA94ABE8C4CD13AE1266C15F2BAA48A9BD1DF6715AEBB7269851CC404201BF30168422B88C630D'), - (115792089237316195423570985008687907852837564279074904382605163141518161494334, 'F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9C77084F09CD217EBF01CC819D5C80CA99AFF5666CB3DDCE4934602897B4715BD'), - (115792089237316195423570985008687907852837564279074904382605163141518161494335, 'C6047F9441ED7D6D3045406E95C07CD85C778E4B8CEF3CA7ABAC09B95C709EE5E51E970159C23CC65C3A7BE6B99315110809CD9ACD992F1EDC9BCE55AF301705'), - (115792089237316195423570985008687907852837564279074904382605163141518161494336, '79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798B7C52588D95C3B9AA25B0403F1EEF75702E84BB7597AABE663B82F6F04EF2777'), + ( + 1, + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8", + ), + ( + 2, + "C6047F9441ED7D6D3045406E95C07CD85C778E4B8CEF3CA7ABAC09B95C709EE51AE168FEA63DC339A3C58419466CEAEEF7F632653266D0E1236431A950CFE52A", + ), + ( + 3, + "F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9388F7B0F632DE8140FE337E62A37F3566500A99934C2231B6CB9FD7584B8E672", + ), + ( + 4, + "E493DBF1C10D80F3581E4904930B1404CC6C13900EE0758474FA94ABE8C4CD1351ED993EA0D455B75642E2098EA51448D967AE33BFBDFE40CFE97BDC47739922", + ), + ( + 5, + "2F8BDE4D1A07209355B4A7250A5C5128E88B84BDDC619AB7CBA8D569B240EFE4D8AC222636E5E3D6D4DBA9DDA6C9C426F788271BAB0D6840DCA87D3AA6AC62D6", + ), + ( + 6, + "FFF97BD5755EEEA420453A14355235D382F6472F8568A18B2F057A1460297556AE12777AACFBB620F3BE96017F45C560DE80F0F6518FE4A03C870C36B075F297", + ), + ( + 7, + "5CBDF0646E5DB4EAA398F365F2EA7A0E3D419B7E0330E39CE92BDDEDCAC4F9BC6AEBCA40BA255960A3178D6D861A54DBA813D0B813FDE7B5A5082628087264DA", + ), + ( + 8, + "2F01E5E15CCA351DAFF3843FB70F3C2F0A1BDD05E5AF888A67784EF3E10A2A015C4DA8A741539949293D082A132D13B4C2E213D6BA5B7617B5DA2CB76CBDE904", + ), + ( + 9, + "ACD484E2F0C7F65309AD178A9F559ABDE09796974C57E714C35F110DFC27CCBECC338921B0A7D9FD64380971763B61E9ADD888A4375F8E0F05CC262AC64F9C37", + ), + ( + 10, + "A0434D9E47F3C86235477C7B1AE6AE5D3442D49B1943C2B752A68E2A47E247C7893ABA425419BC27A3B6C7E693A24C696F794C2ED877A1593CBEE53B037368D7", + ), + ( + 11, + "774AE7F858A9411E5EF4246B70C65AAC5649980BE5C17891BBEC17895DA008CBD984A032EB6B5E190243DD56D7B7B365372DB1E2DFF9D6A8301D74C9C953C61B", + ), + ( + 12, + "D01115D548E7561B15C38F004D734633687CF4419620095BC5B0F47070AFE85AA9F34FFDC815E0D7A8B64537E17BD81579238C5DD9A86D526B051B13F4062327", + ), + ( + 13, + "F28773C2D975288BC7D1D205C3748651B075FBC6610E58CDDEEDDF8F19405AA80AB0902E8D880A89758212EB65CDAF473A1A06DA521FA91F29B5CB52DB03ED81", + ), + ( + 14, + "499FDF9E895E719CFD64E67F07D38E3226AA7B63678949E6E49B241A60E823E4CAC2F6C4B54E855190F044E4A7B3D464464279C27A3F95BCC65F40D403A13F5B", + ), + ( + 15, + "D7924D4F7D43EA965A465AE3095FF41131E5946F3C85F79E44ADBCF8E27E080E581E2872A86C72A683842EC228CC6DEFEA40AF2BD896D3A5C504DC9FF6A26B58", + ), + ( + 16, + "E60FCE93B59E9EC53011AABC21C23E97B2A31369B87A5AE9C44EE89E2A6DEC0AF7E3507399E595929DB99F34F57937101296891E44D23F0BE1F32CCE69616821", + ), + ( + 17, + "DEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A344211AB0694635168E997B0EAD2A93DAECED1F4A04A95C0F6CFB199F69E56EB77", + ), + ( + 18, + "5601570CB47F238D2B0286DB4A990FA0F3BA28D1A319F5E7CF55C2A2444DA7CCC136C1DC0CBEB930E9E298043589351D81D8E0BC736AE2A1F5192E5E8B061D58", + ), + ( + 19, + "2B4EA0A797A443D293EF5CFF444F4979F06ACFEBD7E86D277475656138385B6C85E89BC037945D93B343083B5A1C86131A01F60C50269763B570C854E5C09B7A", + ), + ( + 20, + "4CE119C96E2FA357200B559B2F7DD5A5F02D5290AFF74B03F3E471B273211C9712BA26DCB10EC1625DA61FA10A844C676162948271D96967450288EE9233DC3A", + ), + ( + 112233445566778899, + "A90CC3D3F3E146DAADFC74CA1372207CB4B725AE708CEF713A98EDD73D99EF295A79D6B289610C68BC3B47F3D72F9788A26A06868B4D8E433E1E2AD76FB7DC76", + ), + ( + 112233445566778899112233445566778899, + "E5A2636BCFD412EBF36EC45B19BFB68A1BC5F8632E678132B885F7DF99C5E9B3736C1CE161AE27B405CAFD2A7520370153C2C861AC51D6C1D5985D9606B45F39", + ), + ( + 28948022309329048855892746252171976963209391069768726095651290785379540373584, + "A6B594B38FB3E77C6EDF78161FADE2041F4E09FD8497DB776E546C41567FEB3C71444009192228730CD8237A490FEBA2AFE3D27D7CC1136BC97E439D13330D55", + ), + ( + 57896044618658097711785492504343953926418782139537452191302581570759080747168, + "00000000000000000000003B78CE563F89A0ED9414F5AA28AD0D96D6795F9C633F3979BF72AE8202983DC989AEC7F2FF2ED91BDD69CE02FC0700CA100E59DDF3", + ), + ( + 86844066927987146567678238756515930889628173209306178286953872356138621120752, + "E24CE4BEEE294AA6350FAA67512B99D388693AE4E7F53D19882A6EA169FC1CE18B71E83545FC2B5872589F99D948C03108D36797C4DE363EBD3FF6A9E1A95B10", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494317, + "4CE119C96E2FA357200B559B2F7DD5A5F02D5290AFF74B03F3E471B273211C97ED45D9234EF13E9DA259E05EF57BB3989E9D6B7D8E269698BAFD77106DCC1FF5", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494318, + "2B4EA0A797A443D293EF5CFF444F4979F06ACFEBD7E86D277475656138385B6C7A17643FC86BA26C4CBCF7C4A5E379ECE5FE09F3AFD9689C4A8F37AA1A3F60B5", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494319, + "5601570CB47F238D2B0286DB4A990FA0F3BA28D1A319F5E7CF55C2A2444DA7CC3EC93E23F34146CF161D67FBCA76CAE27E271F438C951D5E0AE6D1A074F9DED7", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494320, + "DEFDEA4CDB677750A420FEE807EACF21EB9898AE79B9768766E4FAA04A2D4A34BDEE54F96B9CAE9716684F152D56C251312E0B5FB56A3F09304E660861A910B8", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494321, + "E60FCE93B59E9EC53011AABC21C23E97B2A31369B87A5AE9C44EE89E2A6DEC0A081CAF8C661A6A6D624660CB0A86C8EFED6976E1BB2DC0F41E0CD330969E940E", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494322, + "D7924D4F7D43EA965A465AE3095FF41131E5946F3C85F79E44ADBCF8E27E080EA7E1D78D57938D597C7BD13DD733921015BF50D427692C5A3AFB235F095D90D7", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494323, + "499FDF9E895E719CFD64E67F07D38E3226AA7B63678949E6E49B241A60E823E4353D093B4AB17AAE6F0FBB1B584C2B9BB9BD863D85C06A4339A0BF2AFC5EBCD4", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494324, + "F28773C2D975288BC7D1D205C3748651B075FBC6610E58CDDEEDDF8F19405AA8F54F6FD17277F5768A7DED149A3250B8C5E5F925ADE056E0D64A34AC24FC0EAE", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494325, + "D01115D548E7561B15C38F004D734633687CF4419620095BC5B0F47070AFE85A560CB00237EA1F285749BAC81E8427EA86DC73A2265792AD94FAE4EB0BF9D908", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494326, + "774AE7F858A9411E5EF4246B70C65AAC5649980BE5C17891BBEC17895DA008CB267B5FCD1494A1E6FDBC22A928484C9AC8D24E1D20062957CFE28B3536AC3614", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494327, + "A0434D9E47F3C86235477C7B1AE6AE5D3442D49B1943C2B752A68E2A47E247C776C545BDABE643D85C4938196C5DB3969086B3D127885EA6C3411AC3FC8C9358", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494328, + "ACD484E2F0C7F65309AD178A9F559ABDE09796974C57E714C35F110DFC27CCBE33CC76DE4F5826029BC7F68E89C49E165227775BC8A071F0FA33D9D439B05FF8", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494329, + "2F01E5E15CCA351DAFF3843FB70F3C2F0A1BDD05E5AF888A67784EF3E10A2A01A3B25758BEAC66B6D6C2F7D5ECD2EC4B3D1DEC2945A489E84A25D3479342132B", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494330, + "5CBDF0646E5DB4EAA398F365F2EA7A0E3D419B7E0330E39CE92BDDEDCAC4F9BC951435BF45DAA69F5CE8729279E5AB2457EC2F47EC02184A5AF7D9D6F78D9755", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494331, + "FFF97BD5755EEEA420453A14355235D382F6472F8568A18B2F057A146029755651ED8885530449DF0C4169FE80BA3A9F217F0F09AE701B5FC378F3C84F8A0998", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494332, + "2F8BDE4D1A07209355B4A7250A5C5128E88B84BDDC619AB7CBA8D569B240EFE42753DDD9C91A1C292B24562259363BD90877D8E454F297BF235782C459539959", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494333, + "E493DBF1C10D80F3581E4904930B1404CC6C13900EE0758474FA94ABE8C4CD13AE1266C15F2BAA48A9BD1DF6715AEBB7269851CC404201BF30168422B88C630D", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494334, + "F9308A019258C31049344F85F89D5229B531C845836F99B08601F113BCE036F9C77084F09CD217EBF01CC819D5C80CA99AFF5666CB3DDCE4934602897B4715BD", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494335, + "C6047F9441ED7D6D3045406E95C07CD85C778E4B8CEF3CA7ABAC09B95C709EE5E51E970159C23CC65C3A7BE6B99315110809CD9ACD992F1EDC9BCE55AF301705", + ), + ( + 115792089237316195423570985008687907852837564279074904382605163141518161494336, + "79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798B7C52588D95C3B9AA25B0403F1EEF75702E84BB7597AABE663B82F6F04EF2777", + ), ] def test_generate_secret(self): for _ in range(100): sk = secp256k1.generate_secret() self.assertTrue(len(sk) == 32) - self.assertTrue(sk != b'\x00' * 32) - self.assertTrue(sk < b'\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\xBA\xAE\xDC\xE6\xAF\x48\xA0\x3B\xBF\xD2\x5E\x8C\xD0\x36\x41\x41') + self.assertTrue(sk != b"\x00" * 32) + self.assertTrue( + sk + < b"\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFE\xBA\xAE\xDC\xE6\xAF\x48\xA0\x3B\xBF\xD2\x5E\x8C\xD0\x36\x41\x41" + ) def test_publickey(self): for sk, pk in self.vectors: sk = hex(sk)[2:] if len(sk) < 64: - sk = '0' * (64 - len(sk)) + sk + sk = "0" * (64 - len(sk)) + sk pk = pk.lower() - pk65 = hexlify(secp256k1.publickey(unhexlify(sk), False)).decode() # uncompressed - self.assertEqual(str(pk65), '04' + pk) + pk65 = hexlify( + secp256k1.publickey(unhexlify(sk), False) + ).decode() # uncompressed + self.assertEqual(str(pk65), "04" + pk) pk33 = hexlify(secp256k1.publickey(unhexlify(sk))).decode() - if pk[-1] in '02468ace': - self.assertEqual(pk33, '02' + pk[:64]) + if pk[-1] in "02468ace": + self.assertEqual(pk33, "02" + pk[:64]) else: - self.assertEqual(pk33, '03' + pk[:64]) + self.assertEqual(pk33, "03" + pk[:64]) def test_sign_verify_min_max(self): sk = secp256k1.generate_secret() @@ -120,7 +260,7 @@ class TestCryptoSecp256k1(unittest.TestCase): (sk, pk) = self.vectors[0] sk = hex(sk)[2:] if len(sk) < 64: - sk = '0' * (64 - len(sk)) + sk + sk = "0" * (64 - len(sk)) + sk sk = unhexlify(sk) pk = pk.lower() pk33 = secp256k1.publickey(sk) @@ -132,5 +272,6 @@ class TestCryptoSecp256k1(unittest.TestCase): self.assertEqual(fixed_vector1, fixed_vector2) self.assertEqual(hexlify(fixed_vector1), fixed_vector_hex) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.der.py b/core/tests/test_trezor.crypto.der.py index d935b85b9c..2e4fd6072e 100644 --- a/core/tests/test_trezor.crypto.der.py +++ b/core/tests/test_trezor.crypto.der.py @@ -6,41 +6,69 @@ from trezor.crypto import der class TestCryptoDer(unittest.TestCase): vectors_seq = [ - (('9a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b70771', - '2b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede781'), - '30450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede781'), - - (('6666666666666666666666666666666666666666666666666666666666666666', - '7777777777777777777777777777777777777777777777777777777777777777'), - '30440220666666666666666666666666666666666666666666666666666666666666666602207777777777777777777777777777777777777777777777777777777777777777'), - - (('6666666666666666666666666666666666666666666666666666666666666666', - 'eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), - '304502206666666666666666666666666666666666666666666666666666666666666666022100eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee'), - - (('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', - '7777777777777777777777777777777777777777777777777777777777777777'), - '3045022100eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee02207777777777777777777777777777777777777777777777777777777777777777'), - - (('eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee', - 'ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), - '3046022100eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee022100ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'), - - (('0000000000000000000000000000000000000000000000000000000000000066', - '0000000000000000000000000000000000000000000000000000000000000077'), - '3006020166020177'), - - (('0000000000000000000000000000000000000000000000000000000000000066', - '00000000000000000000000000000000000000000000000000000000000000ee'), - '3007020166020200ee'), - - (('00000000000000000000000000000000000000000000000000000000000000ee', - '0000000000000000000000000000000000000000000000000000000000000077'), - '3007020200ee020177'), - - (('00000000000000000000000000000000000000000000000000000000000000ee', - '00000000000000000000000000000000000000000000000000000000000000ff'), - '3008020200ee020200ff'), + ( + ( + "9a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b70771", + "2b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede781", + ), + "30450221009a0b7be0d4ed3146ee262b42202841834698bb3ee39c24e7437df208b8b7077102202b79ab1e7736219387dffe8d615bbdba87e11477104b867ef47afed1a5ede781", + ), + ( + ( + "6666666666666666666666666666666666666666666666666666666666666666", + "7777777777777777777777777777777777777777777777777777777777777777", + ), + "30440220666666666666666666666666666666666666666666666666666666666666666602207777777777777777777777777777777777777777777777777777777777777777", + ), + ( + ( + "6666666666666666666666666666666666666666666666666666666666666666", + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + ), + "304502206666666666666666666666666666666666666666666666666666666666666666022100eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + ), + ( + ( + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "7777777777777777777777777777777777777777777777777777777777777777", + ), + "3045022100eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee02207777777777777777777777777777777777777777777777777777777777777777", + ), + ( + ( + "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", + "ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + ), + "3046022100eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee022100ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + ), + ( + ( + "0000000000000000000000000000000000000000000000000000000000000066", + "0000000000000000000000000000000000000000000000000000000000000077", + ), + "3006020166020177", + ), + ( + ( + "0000000000000000000000000000000000000000000000000000000000000066", + "00000000000000000000000000000000000000000000000000000000000000ee", + ), + "3007020166020200ee", + ), + ( + ( + "00000000000000000000000000000000000000000000000000000000000000ee", + "0000000000000000000000000000000000000000000000000000000000000077", + ), + "3007020200ee020177", + ), + ( + ( + "00000000000000000000000000000000000000000000000000000000000000ee", + "00000000000000000000000000000000000000000000000000000000000000ff", + ), + "3008020200ee020200ff", + ), ] def test_der_encode_seq(self): @@ -56,7 +84,7 @@ class TestCryptoDer(unittest.TestCase): def test_der_encode_decode_long_seq(self): for length in (1, 127, 128, 129, 255, 256, 257): - raw_int = bytes((i & 0xfe) + 1 for i in range(length)) + raw_int = bytes((i & 0xFE) + 1 for i in range(length)) for leading_zeros in range(3): encoded = der.encode_seq((b"\x00" * leading_zeros + raw_int,)) decoded = der.decode_seq(encoded) @@ -67,5 +95,6 @@ class TestCryptoDer(unittest.TestCase): decoded = der.decode_seq(encoded) self.assertEqual(decoded, [b"\x00"]) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.blake256.py b/core/tests/test_trezor.crypto.hashlib.blake256.py index c338a166f2..5baa1f6758 100644 --- a/core/tests/test_trezor.crypto.hashlib.blake256.py +++ b/core/tests/test_trezor.crypto.hashlib.blake256.py @@ -8,26 +8,74 @@ class TestCryptoBlake256(unittest.TestCase): # vectors from https://raw.githubusercontent.com/monero-project/monero/master/tests/hash/tests-extra-blake.txt vectors = [ - ('', '716f6e863f744b9ac22c97ec7b76ea5f5908bc5b2f67c61510bfc4751384ea7a'), - ('cc', 'e104256a2bc501f459d03fac96b9014f593e22d30f4de525fa680c3aa189eb4f'), - ('41fb', '8f341148be7e354fdf38b693d8c6b4e0bd57301a734f6fd35cd85b8491c3ddcd'), - ('1f877c', 'bc334d1069099f10c601883ac6f3e7e9787c6aa53171f76a21923cc5ad3ab937'), - ('c1ecfdfc', 'b672a16f53982bab1e77685b71c0a5f6703ffd46a1c834be69f614bd128d658e'), - ('21f134ac57', 'd9134b2899057a7d8d320cc99e3e116982bc99d3c69d260a7f1ed3da8be68d99'), - ('c6f50bb74e29', '637923bd29a35aa3ecbbd2a50549fc32c14cf0fdcaf41c3194dd7414fd224815'), - ('119713cc83eeef', '70c092fd5c8c21e9ef4bbc82a5c7819e262a530a748caf285ff0cba891954f1e'), - ('4a4f202484512526', 'fdf092993edbb7a0dc7ca67f04051bbd14481639da0808947aff8bfab5abed4b'), - ('1f66ab4185ed9b6375', '6f6fc234bf35beae1a366c44c520c59ad5aa70351b5f5085e21e1fe2bfcee709'), - ('eed7422227613b6f53c9', '4fdaf89e2a0e78c000061b59455e0ea93a4445b440e7562c8f0cfa165c93de2e'), - ('eaeed5cdffd89dece455f1', 'd6b780eee9c811f664393dc2c58b5a68c92b3c9fe9ceb70371d33ece63b5787e'), - ('5be43c90f22902e4fe8ed2d3', 'd0015071d3e7ed048c764850d76406eceae52b8e2e6e5a2c3aa92ae880485b34'), - ('a746273228122f381c3b46e4f1', '9b0207902f9932f7a85c24722e93e31f6ed2c75c406509aa0f2f6d1cab046ce4'), - ('3c5871cd619c69a63b540eb5a625', '258020d5b04a814f2b72c1c661e1f5a5c395d9799e5eee8b8519cf7300e90cb1'), - ('fa22874bcc068879e8ef11a69f0722', '4adae3b55baa907fefc253365fdd99d8398befd0551ed6bf9a2a2784d3c304d1'), - ('52a608ab21ccdd8a4457a57ede782176', '6dd10d772f8d5b4a96c3c5d30878cd9a1073fa835bfe6d2b924fa64a1fab1711'), - ('82e192e4043ddcd12ecf52969d0f807eed', '0b8741ddf2259d3af2901eb1ae354f22836442c965556f5c1eb89501191cb46a'), - ('75683dcb556140c522543bb6e9098b21a21e', 'f48a754ca8193a82643150ab94038b5dd170b4ebd1e0751b78cfb0a98fa5076a'), - ('06e4efe45035e61faaf4287b4d8d1f12ca97e5', '5698409ab856b74d9fa5e9b259dfa46001f89041752da424e56e491577b88c86'), + ("", "716f6e863f744b9ac22c97ec7b76ea5f5908bc5b2f67c61510bfc4751384ea7a"), + ("cc", "e104256a2bc501f459d03fac96b9014f593e22d30f4de525fa680c3aa189eb4f"), + ("41fb", "8f341148be7e354fdf38b693d8c6b4e0bd57301a734f6fd35cd85b8491c3ddcd"), + ("1f877c", "bc334d1069099f10c601883ac6f3e7e9787c6aa53171f76a21923cc5ad3ab937"), + ( + "c1ecfdfc", + "b672a16f53982bab1e77685b71c0a5f6703ffd46a1c834be69f614bd128d658e", + ), + ( + "21f134ac57", + "d9134b2899057a7d8d320cc99e3e116982bc99d3c69d260a7f1ed3da8be68d99", + ), + ( + "c6f50bb74e29", + "637923bd29a35aa3ecbbd2a50549fc32c14cf0fdcaf41c3194dd7414fd224815", + ), + ( + "119713cc83eeef", + "70c092fd5c8c21e9ef4bbc82a5c7819e262a530a748caf285ff0cba891954f1e", + ), + ( + "4a4f202484512526", + "fdf092993edbb7a0dc7ca67f04051bbd14481639da0808947aff8bfab5abed4b", + ), + ( + "1f66ab4185ed9b6375", + "6f6fc234bf35beae1a366c44c520c59ad5aa70351b5f5085e21e1fe2bfcee709", + ), + ( + "eed7422227613b6f53c9", + "4fdaf89e2a0e78c000061b59455e0ea93a4445b440e7562c8f0cfa165c93de2e", + ), + ( + "eaeed5cdffd89dece455f1", + "d6b780eee9c811f664393dc2c58b5a68c92b3c9fe9ceb70371d33ece63b5787e", + ), + ( + "5be43c90f22902e4fe8ed2d3", + "d0015071d3e7ed048c764850d76406eceae52b8e2e6e5a2c3aa92ae880485b34", + ), + ( + "a746273228122f381c3b46e4f1", + "9b0207902f9932f7a85c24722e93e31f6ed2c75c406509aa0f2f6d1cab046ce4", + ), + ( + "3c5871cd619c69a63b540eb5a625", + "258020d5b04a814f2b72c1c661e1f5a5c395d9799e5eee8b8519cf7300e90cb1", + ), + ( + "fa22874bcc068879e8ef11a69f0722", + "4adae3b55baa907fefc253365fdd99d8398befd0551ed6bf9a2a2784d3c304d1", + ), + ( + "52a608ab21ccdd8a4457a57ede782176", + "6dd10d772f8d5b4a96c3c5d30878cd9a1073fa835bfe6d2b924fa64a1fab1711", + ), + ( + "82e192e4043ddcd12ecf52969d0f807eed", + "0b8741ddf2259d3af2901eb1ae354f22836442c965556f5c1eb89501191cb46a", + ), + ( + "75683dcb556140c522543bb6e9098b21a21e", + "f48a754ca8193a82643150ab94038b5dd170b4ebd1e0751b78cfb0a98fa5076a", + ), + ( + "06e4efe45035e61faaf4287b4d8d1f12ca97e5", + "5698409ab856b74d9fa5e9b259dfa46001f89041752da424e56e491577b88c86", + ), ] def test_digest(self): @@ -50,5 +98,5 @@ class TestCryptoBlake256(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.blake2b.py b/core/tests/test_trezor.crypto.hashlib.blake2b.py index 5f666246d2..51203e2d7e 100644 --- a/core/tests/test_trezor.crypto.hashlib.blake2b.py +++ b/core/tests/test_trezor.crypto.hashlib.blake2b.py @@ -7,34 +7,88 @@ class TestCryptoBlake2b(unittest.TestCase): # vectors from https://raw.githubusercontent.com/BLAKE2/BLAKE2/master/testvectors/blake2b-kat.txt vectors = [ - ('', '10ebb67700b1868efb4417987acf4690ae9d972fb7a590c2f02871799aaa4786b5e996e8f0f4eb981fc214b005f42d2ff4233499391653df7aefcbc13fc51568'), - ('00', '961f6dd1e4dd30f63901690c512e78e4b45e4742ed197c3c5e45c549fd25f2e4187b0bc9fe30492b16b0d0bc4ef9b0f34c7003fac09a5ef1532e69430234cebd'), - ('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e', 'eba51acffb4cea31db4b8d87e9bf7dd48fe97b0253ae67aa580f9ac4a9d941f2bea518ee286818cc9f633f2a3b9fb68e594b48cdd6d515bf1d52ba6c85a203a7'), - ('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20', '5595e05c13a7ec4dc8f41fb70cb50a71bce17c024ff6de7af618d0cc4e9c32d9570d6d3ea45b86525491030c0d8f2b1836d5778c1ce735c17707df364d054347'), - ('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041', 'c516541701863f91005f314108ceece3c643e04fc8c42fd2ff556220e616aaa6a48aeb97a84bad74782e8dff96a1a2fa949339d722edcaa32b57067041df88cc'), - ('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60', '31fc79738b8772b3f55cd8178813b3b52d0db5a419d30ba9495c4b9da0219fac6df8e7c23a811551a62b827f256ecdb8124ac8a6792ccfecc3b3012722e94463'), + ( + "", + "10ebb67700b1868efb4417987acf4690ae9d972fb7a590c2f02871799aaa4786b5e996e8f0f4eb981fc214b005f42d2ff4233499391653df7aefcbc13fc51568", + ), + ( + "00", + "961f6dd1e4dd30f63901690c512e78e4b45e4742ed197c3c5e45c549fd25f2e4187b0bc9fe30492b16b0d0bc4ef9b0f34c7003fac09a5ef1532e69430234cebd", + ), + ( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e", + "eba51acffb4cea31db4b8d87e9bf7dd48fe97b0253ae67aa580f9ac4a9d941f2bea518ee286818cc9f633f2a3b9fb68e594b48cdd6d515bf1d52ba6c85a203a7", + ), + ( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", + "5595e05c13a7ec4dc8f41fb70cb50a71bce17c024ff6de7af618d0cc4e9c32d9570d6d3ea45b86525491030c0d8f2b1836d5778c1ce735c17707df364d054347", + ), + ( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041", + "c516541701863f91005f314108ceece3c643e04fc8c42fd2ff556220e616aaa6a48aeb97a84bad74782e8dff96a1a2fa949339d722edcaa32b57067041df88cc", + ), + ( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60", + "31fc79738b8772b3f55cd8178813b3b52d0db5a419d30ba9495c4b9da0219fac6df8e7c23a811551a62b827f256ecdb8124ac8a6792ccfecc3b3012722e94463", + ), ] def test_digest(self): - key = unhexlify('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f') + key = unhexlify( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" + ) for d, h in self.vectors: - self.assertEqual(hashlib.blake2b(data=unhexlify(d), key=key).digest(), unhexlify(h)) + self.assertEqual( + hashlib.blake2b(data=unhexlify(d), key=key).digest(), unhexlify(h) + ) def test_update(self): - key = unhexlify('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f') + key = unhexlify( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f" + ) x = hashlib.blake2b(key=key) x.update(bytes(range(10))) - self.assertEqual(x.digest(), unhexlify('4fe181f54ad63a2983feaaf77d1e7235c2beb17fa328b6d9505bda327df19fc37f02c4b6f0368ce23147313a8e5738b5fa2a95b29de1c7f8264eb77b69f585cd')) + self.assertEqual( + x.digest(), + unhexlify( + "4fe181f54ad63a2983feaaf77d1e7235c2beb17fa328b6d9505bda327df19fc37f02c4b6f0368ce23147313a8e5738b5fa2a95b29de1c7f8264eb77b69f585cd" + ), + ) x.update(bytes(range(10, 30))) - self.assertEqual(x.digest(), unhexlify('c6dbc61dec6eaeac81e3d5f755203c8e220551534a0b2fd105a91889945a638550204f44093dd998c076205dffad703a0e5cd3c7f438a7e634cd59fededb539e')) + self.assertEqual( + x.digest(), + unhexlify( + "c6dbc61dec6eaeac81e3d5f755203c8e220551534a0b2fd105a91889945a638550204f44093dd998c076205dffad703a0e5cd3c7f438a7e634cd59fededb539e" + ), + ) x.update(bytes(range(30, 80))) - self.assertEqual(x.digest(), unhexlify('fa1549c9796cd4d303dcf452c1fbd5744fd9b9b47003d920b92de34839d07ef2a29ded68f6fc9e6c45e071a2e48bd50c5084e96b657dd0404045a1ddefe282ed')) + self.assertEqual( + x.digest(), + unhexlify( + "fa1549c9796cd4d303dcf452c1fbd5744fd9b9b47003d920b92de34839d07ef2a29ded68f6fc9e6c45e071a2e48bd50c5084e96b657dd0404045a1ddefe282ed" + ), + ) x.update(bytes(range(80, 111))) - self.assertEqual(x.digest(), unhexlify('2620f687e8625f6a412460b42e2cef67634208ce10a0cbd4dff7044a41b7880077e9f8dc3b8d1216d3376a21e015b58fb279b521d83f9388c7382c8505590b9b')) + self.assertEqual( + x.digest(), + unhexlify( + "2620f687e8625f6a412460b42e2cef67634208ce10a0cbd4dff7044a41b7880077e9f8dc3b8d1216d3376a21e015b58fb279b521d83f9388c7382c8505590b9b" + ), + ) x.update(bytes(range(111, 127))) - self.assertEqual(x.digest(), unhexlify('76d2d819c92bce55fa8e092ab1bf9b9eab237a25267986cacf2b8ee14d214d730dc9a5aa2d7b596e86a1fd8fa0804c77402d2fcd45083688b218b1cdfa0dcbcb')) + self.assertEqual( + x.digest(), + unhexlify( + "76d2d819c92bce55fa8e092ab1bf9b9eab237a25267986cacf2b8ee14d214d730dc9a5aa2d7b596e86a1fd8fa0804c77402d2fcd45083688b218b1cdfa0dcbcb" + ), + ) x.update(bytes(range(127, 255))) - self.assertEqual(x.digest(), unhexlify('142709d62e28fcccd0af97fad0f8465b971e82201dc51070faa0372aa43e92484be1c1e73ba10906d5d1853db6a4106e0a7bf9800d373d6dee2d46d62ef2a461')) + self.assertEqual( + x.digest(), + unhexlify( + "142709d62e28fcccd0af97fad0f8465b971e82201dc51070faa0372aa43e92484be1c1e73ba10906d5d1853db6a4106e0a7bf9800d373d6dee2d46d62ef2a461" + ), + ) def test_digest_multi(self): x = hashlib.blake2b() @@ -45,5 +99,5 @@ class TestCryptoBlake2b(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.blake2s.py b/core/tests/test_trezor.crypto.hashlib.blake2s.py index 0b5dcfb085..ba3a5ba1cd 100644 --- a/core/tests/test_trezor.crypto.hashlib.blake2s.py +++ b/core/tests/test_trezor.crypto.hashlib.blake2s.py @@ -8,34 +8,82 @@ class TestCryptoBlake2s(unittest.TestCase): # vectors from https://raw.githubusercontent.com/BLAKE2/BLAKE2/master/testvectors/blake2s-kat.txt vectors = [ - ('', '48a8997da407876b3d79c0d92325ad3b89cbb754d86ab71aee047ad345fd2c49'), - ('00', '40d15fee7c328830166ac3f918650f807e7e01e177258cdc0a39b11f598066f1'), - ('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e', 'b6156f72d380ee9ea6acd190464f2307a5c179ef01fd71f99f2d0f7a57360aea'), - ('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20', '2c3e08176f760c6264c3a2cd66fec6c3d78de43fc192457b2a4a660a1e0eb22b'), - ('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041', '2ef73f3c26f12d93889f3c78b6a66c1d52b649dc9e856e2c172ea7c58ac2b5e3'), - ('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60', '288c4ad9b9409762ea07c24a41f04f69a7d74bee2d95435374bde946d7241c7b'), + ("", "48a8997da407876b3d79c0d92325ad3b89cbb754d86ab71aee047ad345fd2c49"), + ("00", "40d15fee7c328830166ac3f918650f807e7e01e177258cdc0a39b11f598066f1"), + ( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e", + "b6156f72d380ee9ea6acd190464f2307a5c179ef01fd71f99f2d0f7a57360aea", + ), + ( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f20", + "2c3e08176f760c6264c3a2cd66fec6c3d78de43fc192457b2a4a660a1e0eb22b", + ), + ( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f4041", + "2ef73f3c26f12d93889f3c78b6a66c1d52b649dc9e856e2c172ea7c58ac2b5e3", + ), + ( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f505152535455565758595a5b5c5d5e5f60", + "288c4ad9b9409762ea07c24a41f04f69a7d74bee2d95435374bde946d7241c7b", + ), ] def test_digest(self): - key = unhexlify('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f') + key = unhexlify( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" + ) for d, h in self.vectors: - self.assertEqual(hashlib.blake2s(unhexlify(d), key=key).digest(), unhexlify(h)) + self.assertEqual( + hashlib.blake2s(unhexlify(d), key=key).digest(), unhexlify(h) + ) def test_update(self): - key = unhexlify('000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f') - x = hashlib.blake2s(b'', key=key) + key = unhexlify( + "000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f" + ) + x = hashlib.blake2s(b"", key=key) x.update(bytes(range(10))) - self.assertEqual(x.digest(), unhexlify('f5c4b2ba1a00781b13aba0425242c69cb1552f3f71a9a3bb22b4a6b4277b46dd')) + self.assertEqual( + x.digest(), + unhexlify( + "f5c4b2ba1a00781b13aba0425242c69cb1552f3f71a9a3bb22b4a6b4277b46dd" + ), + ) x.update(bytes(range(10, 30))) - self.assertEqual(x.digest(), unhexlify('3ca989de10cfe609909472c8d35610805b2f977734cf652cc64b3bfc882d5d89')) + self.assertEqual( + x.digest(), + unhexlify( + "3ca989de10cfe609909472c8d35610805b2f977734cf652cc64b3bfc882d5d89" + ), + ) x.update(bytes(range(30, 80))) - self.assertEqual(x.digest(), unhexlify('30f3548370cfdceda5c37b569b6175e799eef1a62aaa943245ae7669c227a7b5')) + self.assertEqual( + x.digest(), + unhexlify( + "30f3548370cfdceda5c37b569b6175e799eef1a62aaa943245ae7669c227a7b5" + ), + ) x.update(bytes(range(80, 111))) - self.assertEqual(x.digest(), unhexlify('9fe03bbe69ab1834f5219b0da88a08b30a66c5913f0151963c360560db0387b3')) + self.assertEqual( + x.digest(), + unhexlify( + "9fe03bbe69ab1834f5219b0da88a08b30a66c5913f0151963c360560db0387b3" + ), + ) x.update(bytes(range(111, 127))) - self.assertEqual(x.digest(), unhexlify('ddbfea75cc467882eb3483ce5e2e756a4f4701b76b445519e89f22d60fa86e06')) + self.assertEqual( + x.digest(), + unhexlify( + "ddbfea75cc467882eb3483ce5e2e756a4f4701b76b445519e89f22d60fa86e06" + ), + ) x.update(bytes(range(127, 255))) - self.assertEqual(x.digest(), unhexlify('3fb735061abc519dfe979e54c1ee5bfad0a9d858b3315bad34bde999efd724dd')) + self.assertEqual( + x.digest(), + unhexlify( + "3fb735061abc519dfe979e54c1ee5bfad0a9d858b3315bad34bde999efd724dd" + ), + ) def test_digest_multi(self): x = hashlib.blake2s() @@ -46,5 +94,5 @@ class TestCryptoBlake2s(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.groestl512.py b/core/tests/test_trezor.crypto.hashlib.groestl512.py index 4c8de36b12..b65be4cbc9 100644 --- a/core/tests/test_trezor.crypto.hashlib.groestl512.py +++ b/core/tests/test_trezor.crypto.hashlib.groestl512.py @@ -7,20 +7,48 @@ class TestCryptoGroestl512(unittest.TestCase): # vectors from www.groestl.info/Groestl.zip #/KAT_MCT/* vectors = [ - (b'', '6D3AD29D279110EEF3ADBD66DE2A0345A77BAEDE1557F5D099FCE0C03D6DC2BA8E6D4A6633DFBD66053C20FAA87D1A11F39A7FBE4A6C2F009801370308FC4AD8'), - (unhexlify('C1ECFDFC'), '4726D760203C1EAF847F6837C74C16ADCEF5B55EAD5768A7C13E21A33D0D7B740F52DE8C81356DA63DABA791DA6680AF015DEB81246550201F232822BB087CE5'), - (unhexlify('82E192E4043DDCD12ECF52969D0F807EED'), - '8CD831960FE9726055F7B3693CC5639DB7D01EDDA045AE41E877853111C4CF53D26D5B4E135118571721C247ACA6607979A4DF73849D1477365F7DB0149FBC9F'), - (unhexlify('F5961DFD2B1FFFFDA4FFBF30560C165BFEDAB8CE0BE525845DEB8DC61004B7DB38467205F5DCFB34A2ACFE96C0'), - 'CE24486770D443B423274DD30AF746EA4080065393D13DF0535709E260CF14B033CCD190A9FA5F81705178EB656031A6F1465A5A993BE62BE8D43931950BD5DB'), - (unhexlify('2B6DB7CED8665EBE9DEB080295218426BDAA7C6DA9ADD2088932CDFFBAA1C14129BCCDD70F369EFB149285858D2B1D155D14DE2FDB680A8B027284055182A0CAE275234CC9C92863C1B4AB66F304CF0621CD54565F5BFF461D3B461BD40DF28198E3732501B4860EADD503D26D6E69338F4E0456E9E9BAF3D827AE685FB1D817'), - 'FF410B511135DBC0B8644C28EFA3EC632326FEB98E50EDC6390C441610D7C514ACDF0A61A0BF01AA9DC1F55D92E085248EBA1C24EE23978B4986AF41C13A6176'), - (unhexlify('EECBB8FDFA4DA62170FD06727F697D81F83F601FF61E478105D3CB7502F2C89BF3E8F56EDD469D049807A38882A7EEFBC85FC9A950952E9FA84B8AFEBD3CE782D4DA598002827B1EB98882EA1F0A8F7AA9CE013A6E9BC462FB66C8D4A18DA21401E1B93356EB12F3725B6DB1684F2300A98B9A119E5D27FF704AFFB618E12708E77E6E5F34139A5A41131FD1D6336C272A8FC37080F041C71341BEE6AB550CB4A20A6DDB6A8E0299F2B14BC730C54B8B1C1C487B494BDCCFD3A53535AB2F231590BF2C4062FD2AD58F906A2D0D'), - '3AE2AABD659C5844C923FD171CA36431A7E606ECA52A21B96A0F5E8CD1FA24141BEDAADF58608781DFABC103FE929CD2EADE8D6FBD6185D4F4B855DCA610D7A0'), - (unhexlify('724627916C50338643E6996F07877EAFD96BDF01DA7E991D4155B9BE1295EA7D21C9391F4C4A41C75F77E5D27389253393725F1427F57914B273AB862B9E31DABCE506E558720520D33352D119F699E784F9E548FF91BC35CA147042128709820D69A8287EA3257857615EB0321270E94B84F446942765CE882B191FAEE7E1C87E0F0BD4E0CD8A927703524B559B769CA4ECE1F6DBF313FDCF67C572EC4185C1A88E86EC11B6454B371980020F19633B6B95BD280E4FBCB0161E1A82470320CEC6ECFA25AC73D09F1536F286D3F9DACAFB2CD1D0CE72D64D197F5C7520B3CCB2FD74EB72664BA93853EF41EABF52F015DD591500D018DD162815CC993595B195'), - 'F88E8E86FBE2200E90226A181E48348E06D1643270C079B8BDD3660E8D21CD0493C55051CBFA607B1CFACA2C5A2C9354CDD405C1D3AD1D8435B825884CC0559F'), - (unhexlify('D0FF6E045F4B636F75A389799F314066644854821B6E7AE4047ADFDE2D0C0E02C250F0BE582BEC94011189B964A8AF430F5921ED9D9F4446E4C788515B89CA69E5F7CDFCCC9E83E8F9460145B43DDC41C07CC512B7E6FDD0E1E7AABA29A6C016CCB7BD54B145F3951EAB9BC4908F623E5A9B0C5B36056292540B79FD15C53457DC74A65FD773A34D6B313A056F79BC29A3FAC15F6A1446BFAEEAAFBAC8ECF8168DDE5F6AE6B6E579BD3CE74E7ABFADF361D0FD32D56586A8D2D4FF4CFDF8A750FAFDE4C2E9EB32B06847FA30B13CC273532D1A23C8257F80C60B8FA94FA976F534145CD61C41C0A511B62CADD5848CEFF643F83CE43F8E6969C5A559AFAD60E310599A34B2E5E029FBDDF2988FCE59269C7128A1FC79A74B154D8AA2850DCFDBF594684E74099E37882B440367C1DD3003F61CAFB46AC75D30E677AF54559A5DAB70C506CF61A9C35E0E56E1430746916DDEEC8D89B0C10DAA02C5D7E9F42621D2B312EAFFC9FF306297952A32D26C2148570AEC90501CA739CE5E689E7066D9580A4FC25E2023897C74C6856273133E1275A0D275DC5B75DB724CD12C9C01BB95AB5A227B7850020630506096878D289923177183EA9282A4C78EC212D2E898CB99D81A3364DF20927EE34D4475A5CF5CDB24088ED75B60201922E9C972D8556CA75F8274D15F3FB88A6B42C766DEF6B21329DEE7C457446DDE8C26405FE5D0309A04229F449E8490CF9000EE8DF400CB7C7EE831BD7059D24088FB42D61681CDE45050FCA78FF64D9C8D1F58B55F802FA5D2F2E723F3E4EED4338B060D31C8ACC46D26870BD45D0DE0798D48E32AAD1A6D4322E69F5E72309B9D7FA1F24BB1D63FF09ED47391C232497BF222C542A70975C8292D275197A4CA'), - '27AB9EA01D8FD80ED14990761ED6BC329DC842770F83FDD1CE95C0A074D6D7495C7C85297CC73F3A695377E4211F897F68C1A7F910F6BF440264FB63F120ABA2'), + ( + b"", + "6D3AD29D279110EEF3ADBD66DE2A0345A77BAEDE1557F5D099FCE0C03D6DC2BA8E6D4A6633DFBD66053C20FAA87D1A11F39A7FBE4A6C2F009801370308FC4AD8", + ), + ( + unhexlify("C1ECFDFC"), + "4726D760203C1EAF847F6837C74C16ADCEF5B55EAD5768A7C13E21A33D0D7B740F52DE8C81356DA63DABA791DA6680AF015DEB81246550201F232822BB087CE5", + ), + ( + unhexlify("82E192E4043DDCD12ECF52969D0F807EED"), + "8CD831960FE9726055F7B3693CC5639DB7D01EDDA045AE41E877853111C4CF53D26D5B4E135118571721C247ACA6607979A4DF73849D1477365F7DB0149FBC9F", + ), + ( + unhexlify( + "F5961DFD2B1FFFFDA4FFBF30560C165BFEDAB8CE0BE525845DEB8DC61004B7DB38467205F5DCFB34A2ACFE96C0" + ), + "CE24486770D443B423274DD30AF746EA4080065393D13DF0535709E260CF14B033CCD190A9FA5F81705178EB656031A6F1465A5A993BE62BE8D43931950BD5DB", + ), + ( + unhexlify( + "2B6DB7CED8665EBE9DEB080295218426BDAA7C6DA9ADD2088932CDFFBAA1C14129BCCDD70F369EFB149285858D2B1D155D14DE2FDB680A8B027284055182A0CAE275234CC9C92863C1B4AB66F304CF0621CD54565F5BFF461D3B461BD40DF28198E3732501B4860EADD503D26D6E69338F4E0456E9E9BAF3D827AE685FB1D817" + ), + "FF410B511135DBC0B8644C28EFA3EC632326FEB98E50EDC6390C441610D7C514ACDF0A61A0BF01AA9DC1F55D92E085248EBA1C24EE23978B4986AF41C13A6176", + ), + ( + unhexlify( + "EECBB8FDFA4DA62170FD06727F697D81F83F601FF61E478105D3CB7502F2C89BF3E8F56EDD469D049807A38882A7EEFBC85FC9A950952E9FA84B8AFEBD3CE782D4DA598002827B1EB98882EA1F0A8F7AA9CE013A6E9BC462FB66C8D4A18DA21401E1B93356EB12F3725B6DB1684F2300A98B9A119E5D27FF704AFFB618E12708E77E6E5F34139A5A41131FD1D6336C272A8FC37080F041C71341BEE6AB550CB4A20A6DDB6A8E0299F2B14BC730C54B8B1C1C487B494BDCCFD3A53535AB2F231590BF2C4062FD2AD58F906A2D0D" + ), + "3AE2AABD659C5844C923FD171CA36431A7E606ECA52A21B96A0F5E8CD1FA24141BEDAADF58608781DFABC103FE929CD2EADE8D6FBD6185D4F4B855DCA610D7A0", + ), + ( + unhexlify( + "724627916C50338643E6996F07877EAFD96BDF01DA7E991D4155B9BE1295EA7D21C9391F4C4A41C75F77E5D27389253393725F1427F57914B273AB862B9E31DABCE506E558720520D33352D119F699E784F9E548FF91BC35CA147042128709820D69A8287EA3257857615EB0321270E94B84F446942765CE882B191FAEE7E1C87E0F0BD4E0CD8A927703524B559B769CA4ECE1F6DBF313FDCF67C572EC4185C1A88E86EC11B6454B371980020F19633B6B95BD280E4FBCB0161E1A82470320CEC6ECFA25AC73D09F1536F286D3F9DACAFB2CD1D0CE72D64D197F5C7520B3CCB2FD74EB72664BA93853EF41EABF52F015DD591500D018DD162815CC993595B195" + ), + "F88E8E86FBE2200E90226A181E48348E06D1643270C079B8BDD3660E8D21CD0493C55051CBFA607B1CFACA2C5A2C9354CDD405C1D3AD1D8435B825884CC0559F", + ), + ( + unhexlify( + "D0FF6E045F4B636F75A389799F314066644854821B6E7AE4047ADFDE2D0C0E02C250F0BE582BEC94011189B964A8AF430F5921ED9D9F4446E4C788515B89CA69E5F7CDFCCC9E83E8F9460145B43DDC41C07CC512B7E6FDD0E1E7AABA29A6C016CCB7BD54B145F3951EAB9BC4908F623E5A9B0C5B36056292540B79FD15C53457DC74A65FD773A34D6B313A056F79BC29A3FAC15F6A1446BFAEEAAFBAC8ECF8168DDE5F6AE6B6E579BD3CE74E7ABFADF361D0FD32D56586A8D2D4FF4CFDF8A750FAFDE4C2E9EB32B06847FA30B13CC273532D1A23C8257F80C60B8FA94FA976F534145CD61C41C0A511B62CADD5848CEFF643F83CE43F8E6969C5A559AFAD60E310599A34B2E5E029FBDDF2988FCE59269C7128A1FC79A74B154D8AA2850DCFDBF594684E74099E37882B440367C1DD3003F61CAFB46AC75D30E677AF54559A5DAB70C506CF61A9C35E0E56E1430746916DDEEC8D89B0C10DAA02C5D7E9F42621D2B312EAFFC9FF306297952A32D26C2148570AEC90501CA739CE5E689E7066D9580A4FC25E2023897C74C6856273133E1275A0D275DC5B75DB724CD12C9C01BB95AB5A227B7850020630506096878D289923177183EA9282A4C78EC212D2E898CB99D81A3364DF20927EE34D4475A5CF5CDB24088ED75B60201922E9C972D8556CA75F8274D15F3FB88A6B42C766DEF6B21329DEE7C457446DDE8C26405FE5D0309A04229F449E8490CF9000EE8DF400CB7C7EE831BD7059D24088FB42D61681CDE45050FCA78FF64D9C8D1F58B55F802FA5D2F2E723F3E4EED4338B060D31C8ACC46D26870BD45D0DE0798D48E32AAD1A6D4322E69F5E72309B9D7FA1F24BB1D63FF09ED47391C232497BF222C542A70975C8292D275197A4CA" + ), + "27AB9EA01D8FD80ED14990761ED6BC329DC842770F83FDD1CE95C0A074D6D7495C7C85297CC73F3A695377E4211F897F68C1A7F910F6BF440264FB63F120ABA2", + ), ] def test_digest(self): @@ -34,12 +62,12 @@ class TestCryptoGroestl512(unittest.TestCase): self.assertEqual(x.digest(), unhexlify(d)) # Test from ExtremelyLongMsgKAT_512.txt, disabled by default because it resource-expensive - ''' + """ x = hashlib.groestl512() for i in range(16777216): x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') self.assertEqual(x.digest(), unhexlify('787C88460E5D09ABD7A98C050F3422BBFDBD36A74B05DE04B57A13FA3F36A570B8561580AB9DA4096CCD5111B5DE948F769D9D61833A6CE2B2F223061E688994')) - ''' + """ def test_digest_multi(self): x = hashlib.groestl512() @@ -50,5 +78,5 @@ class TestCryptoGroestl512(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.ripemd160.py b/core/tests/test_trezor.crypto.hashlib.ripemd160.py index a975cabba1..e761fd33f0 100644 --- a/core/tests/test_trezor.crypto.hashlib.ripemd160.py +++ b/core/tests/test_trezor.crypto.hashlib.ripemd160.py @@ -7,14 +7,23 @@ class TestCryptoRipemd160(unittest.TestCase): # vectors from http://homes.esat.kuleuven.be/~bosselae/ripemd160.html vectors = [ - (b'', '9c1185a5c5e9fc54612808977ee8f548b2258d31'), - (b'a', '0bdc9d2d256b3ee9daae347be6f4dc835a467ffe'), - (b'abc', '8eb208f7e05d987a9b044a8e98c6b087f15a0bfc'), - (b'message digest', '5d0689ef49d2fae572b881b123a85ffa21595f36'), - (b'abcdefghijklmnopqrstuvwxyz', 'f71c27109c692c1b56bbdceb5b9d2865b3708dbc'), - (b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', '12a053384a9c0c88e405a06c27dcf49ada62eb2b'), - (b'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789', 'b0e20b6e3116640286ed3a87a5713079b21f5189'), - (b'12345678901234567890123456789012345678901234567890123456789012345678901234567890', '9b752e45573d4b39f4dbd3323cab82bf63326bfb'), + (b"", "9c1185a5c5e9fc54612808977ee8f548b2258d31"), + (b"a", "0bdc9d2d256b3ee9daae347be6f4dc835a467ffe"), + (b"abc", "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc"), + (b"message digest", "5d0689ef49d2fae572b881b123a85ffa21595f36"), + (b"abcdefghijklmnopqrstuvwxyz", "f71c27109c692c1b56bbdceb5b9d2865b3708dbc"), + ( + b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "12a053384a9c0c88e405a06c27dcf49ada62eb2b", + ), + ( + b"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", + "b0e20b6e3116640286ed3a87a5713079b21f5189", + ), + ( + b"12345678901234567890123456789012345678901234567890123456789012345678901234567890", + "9b752e45573d4b39f4dbd3323cab82bf63326bfb", + ), ] def test_digest(self): @@ -29,8 +38,10 @@ class TestCryptoRipemd160(unittest.TestCase): x = hashlib.ripemd160() for i in range(8): - x.update(b'1234567890') - self.assertEqual(x.digest(), unhexlify('9b752e45573d4b39f4dbd3323cab82bf63326bfb')) + x.update(b"1234567890") + self.assertEqual( + x.digest(), unhexlify("9b752e45573d4b39f4dbd3323cab82bf63326bfb") + ) def test_digest_multi(self): x = hashlib.ripemd160() @@ -41,5 +52,5 @@ class TestCryptoRipemd160(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.sha1.py b/core/tests/test_trezor.crypto.hashlib.sha1.py index 039691e06a..26cfd6c92b 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha1.py +++ b/core/tests/test_trezor.crypto.hashlib.sha1.py @@ -7,10 +7,16 @@ class TestCryptoSha1(unittest.TestCase): # vectors from https://www.di-mgt.com.au/sha_testvectors.html vectors = [ - (b'', 'da39a3ee5e6b4b0d3255bfef95601890afd80709'), - (b'abc', 'a9993e364706816aba3e25717850c26c9cd0d89d'), - (b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', '84983e441c3bd26ebaae4aa1f95129e5e54670f1'), - (b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'a49b2446a02c645bf419f995b67091253a04a259') + (b"", "da39a3ee5e6b4b0d3255bfef95601890afd80709"), + (b"abc", "a9993e364706816aba3e25717850c26c9cd0d89d"), + ( + b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "84983e441c3bd26ebaae4aa1f95129e5e54670f1", + ), + ( + b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "a49b2446a02c645bf419f995b67091253a04a259", + ), ] def test_digest(self): @@ -25,15 +31,17 @@ class TestCryptoSha1(unittest.TestCase): x = hashlib.sha1() for i in range(1000000): - x.update(b'a') - self.assertEqual(x.digest(), unhexlify('34aa973cd4c4daa4f61eeb2bdbad27316534016f')) + x.update(b"a") + self.assertEqual( + x.digest(), unhexlify("34aa973cd4c4daa4f61eeb2bdbad27316534016f") + ) - ''' + """ x = hashlib.sha1() for i in range(16777216): x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') self.assertEqual(x.digest(), unhexlify('7789f0c9ef7bfc40d93311143dfbe69e2017f592')) - ''' + """ def test_digest_multi(self): x = hashlib.sha1() @@ -44,5 +52,5 @@ class TestCryptoSha1(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.sha256.py b/core/tests/test_trezor.crypto.hashlib.sha256.py index 28a7db1ab9..6d14236ef6 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha256.py +++ b/core/tests/test_trezor.crypto.hashlib.sha256.py @@ -7,10 +7,16 @@ class TestCryptoSha256(unittest.TestCase): # vectors from http://www.di-mgt.com.au/sha_testvectors.html vectors = [ - (b'', 'e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855'), - (b'abc', 'ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad'), - (b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', '248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1'), - (b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1'), + (b"", "e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855"), + (b"abc", "ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad"), + ( + b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1", + ), + ( + b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "cf5b16a778af8380036ce59e7b0492370b249b11e8f07a51afac45037afee9d1", + ), ] def test_digest(self): @@ -25,15 +31,20 @@ class TestCryptoSha256(unittest.TestCase): x = hashlib.sha256() for i in range(1000000): - x.update(b'a') - self.assertEqual(x.digest(), unhexlify('cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0')) + x.update(b"a") + self.assertEqual( + x.digest(), + unhexlify( + "cdc76e5c9914fb9281a1c7e284d73e67f1809a48a497200e046d39ccc7112cd0" + ), + ) - ''' + """ x = hashlib.sha256() for i in range(16777216): x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') self.assertEqual(x.digest(), unhexlify('50e72a0e26442fe2552dc3938ac58658228c0cbfb1d2ca872ae435266fcd055e')) - ''' + """ def test_digest_multi(self): x = hashlib.sha256() @@ -44,5 +55,5 @@ class TestCryptoSha256(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.sha3_256.py b/core/tests/test_trezor.crypto.hashlib.sha3_256.py index 522cf3b1bf..2c1e409076 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha3_256.py +++ b/core/tests/test_trezor.crypto.hashlib.sha3_256.py @@ -7,17 +7,29 @@ class TestCryptoSha3_256(unittest.TestCase): # vectors from http://www.di-mgt.com.au/sha_testvectors.html vectors = [ - (b'', 'a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a'), - (b'abc', '3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532'), - (b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', '41c0dba2a9d6240849100376a8235e2c82e1b9998a999e21db32dd97496d3376'), - (b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', '916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18'), + (b"", "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a"), + (b"abc", "3a985da74fe225b2045c172d6bd390bd855f086e3e9d525b46bfe24511431532"), + ( + b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "41c0dba2a9d6240849100376a8235e2c82e1b9998a999e21db32dd97496d3376", + ), + ( + b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "916f6061fe879741ca6469b43971dfdb28b1a32dc36cb3254e812be27aad1d18", + ), ] vectors_keccak = [ - (b'', 'c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470'), - (b'abc', '4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45'), - (b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', '45d3b367a6904e6e8d502ee04999a7c27647f91fa845d456525fd352ae3d7371'), - (b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67'), + (b"", "c5d2460186f7233c927e7db2dcc703c0e500b653ca82273b7bfad8045d85a470"), + (b"abc", "4e03657aea45a94fc7d47ba826c8d667c0d1e6e33a64a036ec44f58fa12d6c45"), + ( + b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "45d3b367a6904e6e8d502ee04999a7c27647f91fa845d456525fd352ae3d7371", + ), + ( + b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "f519747ed599024f3882238e5ab43960132572b7345fbeb9a90769dafd21ad67", + ), ] def test_digest(self): @@ -36,15 +48,20 @@ class TestCryptoSha3_256(unittest.TestCase): x = hashlib.sha3_256() for i in range(1000000): - x.update(b'a') - self.assertEqual(x.digest(), unhexlify('5c8875ae474a3634ba4fd55ec85bffd661f32aca75c6d699d0cdcb6c115891c1')) + x.update(b"a") + self.assertEqual( + x.digest(), + unhexlify( + "5c8875ae474a3634ba4fd55ec85bffd661f32aca75c6d699d0cdcb6c115891c1" + ), + ) - ''' + """ x = hashlib.sha3_256() for i in range(16777216): x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') self.assertEqual(x.digest(), unhexlify('ecbbc42cbf296603acb2c6bc0410ef4378bafb24b710357f12df607758b33e2b')) - ''' + """ def test_update_keccak(self): for b, d in self.vectors_keccak: @@ -69,5 +86,5 @@ class TestCryptoSha3_256(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.sha3_512.py b/core/tests/test_trezor.crypto.hashlib.sha3_512.py index 2ebfff6a89..73de6f5b13 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha3_512.py +++ b/core/tests/test_trezor.crypto.hashlib.sha3_512.py @@ -7,17 +7,41 @@ class TestCryptoSha3_512(unittest.TestCase): # vectors from https://www.di-mgt.com.au/sha_testvectors.html vectors = [ - (b'', 'a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26'), - (b'abc', 'b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0'), - (b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', '04a371e84ecfb5b8b77cb48610fca8182dd457ce6f326a0fd3d7ec2f1e91636dee691fbe0c985302ba1b0d8dc78c086346b533b49c030d99a27daf1139d6e75e'), - (b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185'), + ( + b"", + "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26", + ), + ( + b"abc", + "b751850b1a57168a5693cd924b6b096e08f621827444f70d884f5d0240d2712e10e116e9192af3c91a7ec57647e3934057340b4cf408d5a56592f8274eec53f0", + ), + ( + b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "04a371e84ecfb5b8b77cb48610fca8182dd457ce6f326a0fd3d7ec2f1e91636dee691fbe0c985302ba1b0d8dc78c086346b533b49c030d99a27daf1139d6e75e", + ), + ( + b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "afebb2ef542e6579c50cad06d2e578f9f8dd6881d7dc824d26360feebf18a4fa73e3261122948efcfd492e74e82e2189ed0fb440d187f382270cb455f21dd185", + ), ] vectors_keccak = [ - (b'', '0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e'), - (b'abc', '18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96'), - (b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', '6aa6d3669597df6d5a007b00d09c20795b5c4218234e1698a944757a488ecdc09965435d97ca32c3cfed7201ff30e070cd947f1fc12b9d9214c467d342bcba5d'), - (b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', 'ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682'), + ( + b"", + "0eab42de4c3ceb9235fc91acffe746b29c29a8c366b7c60e4e67c466f36a4304c00fa9caf9d87976ba469bcbe06713b435f091ef2769fb160cdab33d3670680e", + ), + ( + b"abc", + "18587dc2ea106b9a1563e32b3312421ca164c7f1f07bc922a9c83d77cea3a1e5d0c69910739025372dc14ac9642629379540c17e2a65b19d77aa511a9d00bb96", + ), + ( + b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "6aa6d3669597df6d5a007b00d09c20795b5c4218234e1698a944757a488ecdc09965435d97ca32c3cfed7201ff30e070cd947f1fc12b9d9214c467d342bcba5d", + ), + ( + b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "ac2fb35251825d3aa48468a9948c0a91b8256f6d97d8fa4160faff2dd9dfcc24f3f1db7a983dad13d53439ccac0b37e24037e7b95f80f59f37a2f683c4ba4682", + ), ] def test_digest(self): @@ -36,15 +60,20 @@ class TestCryptoSha3_512(unittest.TestCase): x = hashlib.sha3_512() for i in range(1000000): - x.update(b'a') - self.assertEqual(x.digest(), unhexlify('3c3a876da14034ab60627c077bb98f7e120a2a5370212dffb3385a18d4f38859ed311d0a9d5141ce9cc5c66ee689b266a8aa18ace8282a0e0db596c90b0a7b87')) + x.update(b"a") + self.assertEqual( + x.digest(), + unhexlify( + "3c3a876da14034ab60627c077bb98f7e120a2a5370212dffb3385a18d4f38859ed311d0a9d5141ce9cc5c66ee689b266a8aa18ace8282a0e0db596c90b0a7b87" + ), + ) - ''' + """ x = hashlib.sha3_512() for i in range(16777216): x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') self.assertEqual(x.digest(), unhexlify('235ffd53504ef836a1342b488f483b396eabbfe642cf78ee0d31feec788b23d0d18d5c339550dd5958a500d4b95363da1b5fa18affc1bab2292dc63b7d85097c')) - ''' + """ def test_update_keccak(self): for b, d in self.vectors_keccak: @@ -69,5 +98,5 @@ class TestCryptoSha3_512(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hashlib.sha512.py b/core/tests/test_trezor.crypto.hashlib.sha512.py index 66530eadc1..a05e7874ef 100644 --- a/core/tests/test_trezor.crypto.hashlib.sha512.py +++ b/core/tests/test_trezor.crypto.hashlib.sha512.py @@ -7,10 +7,22 @@ class TestCryptoSha512(unittest.TestCase): # vectors from http://www.di-mgt.com.au/sha_testvectors.html vectors = [ - (b'', 'cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e'), - (b'abc', 'ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f'), - (b'abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq', '204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445'), - (b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu', '8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909'), + ( + b"", + "cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e", + ), + ( + b"abc", + "ddaf35a193617abacc417349ae20413112e6fa4e89a97ea20a9eeee64b55d39a2192992a274fc1a836ba3c23a3feebbd454d4423643ce80e2a9ac94fa54ca49f", + ), + ( + b"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq", + "204a8fc6dda82f0a0ced7beb8e08a41657c16ef468b228a8279be331a703c33596fd15c13b1b07f9aa1d3bea57789ca031ad85c7a71dd70354ec631238ca3445", + ), + ( + b"abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmnoijklmnopjklmnopqklmnopqrlmnopqrsmnopqrstnopqrstu", + "8e959b75dae313da8cf4f72814fc143f8f7779c6eb9f7fa17299aeadb6889018501d289e4900f7e4331b99dec4b5433ac7d329eeb6dd26545e96e55b874be909", + ), ] def test_digest(self): @@ -25,15 +37,20 @@ class TestCryptoSha512(unittest.TestCase): x = hashlib.sha512() for i in range(1000000): - x.update(b'a') - self.assertEqual(x.digest(), unhexlify('e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b')) + x.update(b"a") + self.assertEqual( + x.digest(), + unhexlify( + "e718483d0ce769644e2e42c7bc15b4638e1f98b13b2044285632a803afa973ebde0ff244877ea60a4cb0432ce577c31beb009c5c2c49aa2e4eadb217ad8cc09b" + ), + ) - ''' + """ x = hashlib.sha512() for i in range(16777216): x.update(b'abcdefghbcdefghicdefghijdefghijkefghijklfghijklmghijklmnhijklmno') self.assertEqual(x.digest(), unhexlify('b47c933421ea2db149ad6e10fce6c7f93d0752380180ffd7f4629a712134831d77be6091b819ed352c2967a2e2d4fa5050723c9630691f1a05a7281dbe6c1086')) - ''' + """ def test_digest_multi(self): x = hashlib.sha512() @@ -44,5 +61,5 @@ class TestCryptoSha512(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.hmac.py b/core/tests/test_trezor.crypto.hmac.py index aaacfdc6c6..4fff7d306d 100644 --- a/core/tests/test_trezor.crypto.hmac.py +++ b/core/tests/test_trezor.crypto.hmac.py @@ -10,67 +10,147 @@ class TestCryptoHmac(unittest.TestCase): def test_digest(self): # case 1 - key = b'\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b' - msg = b'Hi There' - self.assertEqual(hmac(hmac.SHA256, key, msg).digest(), unhexlify('b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7')) - self.assertEqual(hmac(hmac.SHA512, key, msg).digest(), unhexlify('87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854')) + key = b"\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b\x0b" + msg = b"Hi There" + self.assertEqual( + hmac(hmac.SHA256, key, msg).digest(), + unhexlify( + "b0344c61d8db38535ca8afceaf0bf12b881dc200c9833da726e9376c2e32cff7" + ), + ) + self.assertEqual( + hmac(hmac.SHA512, key, msg).digest(), + unhexlify( + "87aa7cdea5ef619d4ff0b4241a1d6cb02379f4e2ce4ec2787ad0b30545e17cdedaa833b7d6b8a702038b274eaea3f4e4be9d914eeb61f1702e696c203a126854" + ), + ) # case 2 - key = b'Jefe' - msg = b'what do ya want for nothing?' - self.assertEqual(hmac(hmac.SHA256, key, msg).digest(), unhexlify('5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843')) - self.assertEqual(hmac(hmac.SHA512, key, msg).digest(), unhexlify('164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737')) + key = b"Jefe" + msg = b"what do ya want for nothing?" + self.assertEqual( + hmac(hmac.SHA256, key, msg).digest(), + unhexlify( + "5bdcc146bf60754e6a042426089575c75a003f089d2739839dec58b964ec3843" + ), + ) + self.assertEqual( + hmac(hmac.SHA512, key, msg).digest(), + unhexlify( + "164b7a7bfcf819e2e395fbe73b56e0a387bd64222e831fd610270cd7ea2505549758bf75c05a994a6d034f65f8f0e6fdcaeab1a34d4a6b4b636e070a38bce737" + ), + ) # case 3 - key = b'\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa' - msg = b'\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd' - self.assertEqual(hmac(hmac.SHA256, key, msg).digest(), unhexlify('773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe')) - self.assertEqual(hmac(hmac.SHA512, key, msg).digest(), unhexlify('fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb')) + key = b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" + msg = b"\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd\xdd" + self.assertEqual( + hmac(hmac.SHA256, key, msg).digest(), + unhexlify( + "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe" + ), + ) + self.assertEqual( + hmac(hmac.SHA512, key, msg).digest(), + unhexlify( + "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb" + ), + ) # case 4 - key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19' - msg = b'\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd' - self.assertEqual(hmac(hmac.SHA256, key, msg).digest(), unhexlify('82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b')) - self.assertEqual(hmac(hmac.SHA512, key, msg).digest(), unhexlify('b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd')) + key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19" + msg = b"\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd\xcd" + self.assertEqual( + hmac(hmac.SHA256, key, msg).digest(), + unhexlify( + "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b" + ), + ) + self.assertEqual( + hmac(hmac.SHA512, key, msg).digest(), + unhexlify( + "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd" + ), + ) # case 6 key = bytes([0xAA] * 131) - msg = b'Test Using Larger Than Block-Size Key - Hash Key First' - self.assertEqual(hmac(hmac.SHA256, key, msg).digest(), unhexlify('60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54')) - self.assertEqual(hmac(hmac.SHA512, key, msg).digest(), unhexlify('80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598')) + msg = b"Test Using Larger Than Block-Size Key - Hash Key First" + self.assertEqual( + hmac(hmac.SHA256, key, msg).digest(), + unhexlify( + "60e431591ee0b67f0d8a26aacbf5b77f8e0bc6213728c5140546040f0ee37f54" + ), + ) + self.assertEqual( + hmac(hmac.SHA512, key, msg).digest(), + unhexlify( + "80b24263c7c1a3ebb71493c1dd7be8b49b46d1f41b4aeec1121b013783f8f3526b56d037e05f2598bd0fd2215d6a1e5295e64f73f63f0aec8b915a985d786598" + ), + ) # case 7 key = bytes([0xAA] * 131) - msg = b'This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm.' - self.assertEqual(hmac(hmac.SHA256, key, msg).digest(), unhexlify('9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2')) - self.assertEqual(hmac(hmac.SHA512, key, msg).digest(), unhexlify('e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58')) + msg = b"This is a test using a larger than block-size key and a larger than block-size data. The key needs to be hashed before being used by the HMAC algorithm." + self.assertEqual( + hmac(hmac.SHA256, key, msg).digest(), + unhexlify( + "9b09ffa71b942fcb27635fbcd5b0e944bfdc63644f0713938a7f51535c3a35e2" + ), + ) + self.assertEqual( + hmac(hmac.SHA512, key, msg).digest(), + unhexlify( + "e37b6a775dc87dbaa4dfa9f96e5e3ffddebd71f8867289865df5a32d20cdc944b6022cac3c4982b10d5eeb55c3e4de15134676fb6de0446065c97440fa8c6a58" + ), + ) def test_update(self): # case 3 - key = b'\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa' + key = b"\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa\xaa" x = hmac(hmac.SHA256, key) for i in range(50): - x.update(b'\xdd') - self.assertEqual(x.digest(), unhexlify('773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe')) + x.update(b"\xdd") + self.assertEqual( + x.digest(), + unhexlify( + "773ea91e36800e46854db8ebd09181a72959098b3ef8c122d9635514ced565fe" + ), + ) x = hmac(hmac.SHA512, key) for i in range(50): - x.update(b'\xdd') - self.assertEqual(x.digest(), unhexlify('fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb')) + x.update(b"\xdd") + self.assertEqual( + x.digest(), + unhexlify( + "fa73b0089d56a284efb0f0756c890be9b1b5dbdd8ee81a3655f83e33b2279d39bf3e848279a722c806b485a47e67c807b946a337bee8942674278859e13292fb" + ), + ) # case 4 - key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19' + key = b"\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19" x = hmac(hmac.SHA256, key) for i in range(50): - x.update(b'\xcd') - self.assertEqual(x.digest(), unhexlify('82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b')) + x.update(b"\xcd") + self.assertEqual( + x.digest(), + unhexlify( + "82558a389a443c0ea4cc819899f2083a85f0faa3e578f8077a2e3ff46729665b" + ), + ) x = hmac(hmac.SHA512, key) for i in range(50): - x.update(b'\xcd') - self.assertEqual(x.digest(), unhexlify('b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd')) + x.update(b"\xcd") + self.assertEqual( + x.digest(), + unhexlify( + "b0ba465637458c6990e5a8c5f61d4af7e576d97ff94b872de76f8050361ee3dba91ca5c11aa25eb4d679275cc5788063a5f19741120c4f2de2adebeb10a298dd" + ), + ) def test_digest_multi(self): - x = hmac(hmac.SHA256, b'') + x = hmac(hmac.SHA256, b"") d0 = x.digest() d1 = x.digest() d2 = x.digest() @@ -78,5 +158,5 @@ class TestCryptoHmac(unittest.TestCase): self.assertEqual(d0, d2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.pbkdf2.py b/core/tests/test_trezor.crypto.pbkdf2.py index fd9b436c97..9554ad237c 100644 --- a/core/tests/test_trezor.crypto.pbkdf2.py +++ b/core/tests/test_trezor.crypto.pbkdf2.py @@ -8,88 +8,168 @@ class TestCryptoPbkdf2(unittest.TestCase): # vectors from https://stackoverflow.com/questions/5130513/pbkdf2-hmac-sha2-test-vectors def test_pbkdf2_hmac_sha256(self): - P = b'password' - S = b'salt' + P = b"password" + S = b"salt" dk = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 1).key() - self.assertEqual(dk, unhexlify('120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b')) + self.assertEqual( + dk, + unhexlify( + "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b" + ), + ) dk = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 2).key() - self.assertEqual(dk, unhexlify('ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43')) + self.assertEqual( + dk, + unhexlify( + "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43" + ), + ) dk = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 4096).key() - self.assertEqual(dk, unhexlify('c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a')) - P = b'passwordPASSWORDpassword' - S = b'saltSALTsaltSALTsaltSALTsaltSALTsalt' + self.assertEqual( + dk, + unhexlify( + "c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a" + ), + ) + P = b"passwordPASSWORDpassword" + S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt" dk = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 4096).key() - self.assertEqual(dk, unhexlify('348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1')) + self.assertEqual( + dk, + unhexlify( + "348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1" + ), + ) def test_pbkdf2_hmac_sha256_update(self): - P = b'password' - S = b'salt' + P = b"password" + S = b"salt" p = pbkdf2(pbkdf2.HMAC_SHA256, P, S) p.update(1) dk = p.key() - self.assertEqual(dk, unhexlify('120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b')) + self.assertEqual( + dk, + unhexlify( + "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b" + ), + ) p = pbkdf2(pbkdf2.HMAC_SHA256, P, S) p.update(1) p.update(1) dk = p.key() - self.assertEqual(dk, unhexlify('ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43')) + self.assertEqual( + dk, + unhexlify( + "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43" + ), + ) p = pbkdf2(pbkdf2.HMAC_SHA256, P, S) for i in range(32): p.update(128) dk = p.key() - self.assertEqual(dk, unhexlify('c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a')) - P = b'passwordPASSWORDpassword' - S = b'saltSALTsaltSALTsaltSALTsaltSALTsalt' + self.assertEqual( + dk, + unhexlify( + "c5e478d59288c841aa530db6845c4c8d962893a001ce4e11a4963873aa98134a" + ), + ) + P = b"passwordPASSWORDpassword" + S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt" p = pbkdf2(pbkdf2.HMAC_SHA256, P, S) for i in range(64): p.update(64) dk = p.key() - self.assertEqual(dk, unhexlify('348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1')) + self.assertEqual( + dk, + unhexlify( + "348c89dbcbd32b2f32d814b8116e84cf2b17347ebc1800181c4e2a1fb8dd53e1" + ), + ) # vectors from https://stackoverflow.com/questions/15593184/pbkdf2-hmac-sha-512-test-vectors def test_pbkdf2_hmac_sha512(self): - P = b'password' - S = b'salt' + P = b"password" + S = b"salt" dk = pbkdf2(pbkdf2.HMAC_SHA512, P, S, 1).key() - self.assertEqual(dk, unhexlify('867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce')) + self.assertEqual( + dk, + unhexlify( + "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce" + ), + ) dk = pbkdf2(pbkdf2.HMAC_SHA512, P, S, 2).key() - self.assertEqual(dk, unhexlify('e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e')) + self.assertEqual( + dk, + unhexlify( + "e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e" + ), + ) dk = pbkdf2(pbkdf2.HMAC_SHA512, P, S, 4096).key() - self.assertEqual(dk, unhexlify('d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5')) - P = b'passwordPASSWORDpassword' - S = b'saltSALTsaltSALTsaltSALTsaltSALTsalt' + self.assertEqual( + dk, + unhexlify( + "d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5" + ), + ) + P = b"passwordPASSWORDpassword" + S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt" dk = pbkdf2(pbkdf2.HMAC_SHA512, P, S, 4096).key() - self.assertEqual(dk, unhexlify('8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8')) + self.assertEqual( + dk, + unhexlify( + "8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8" + ), + ) def test_pbkdf2_hmac_sha512_update(self): - P = b'password' - S = b'salt' + P = b"password" + S = b"salt" p = pbkdf2(pbkdf2.HMAC_SHA512, P, S) p.update(1) dk = p.key() - self.assertEqual(dk, unhexlify('867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce')) + self.assertEqual( + dk, + unhexlify( + "867f70cf1ade02cff3752599a3a53dc4af34c7a669815ae5d513554e1c8cf252c02d470a285a0501bad999bfe943c08f050235d7d68b1da55e63f73b60a57fce" + ), + ) p = pbkdf2(pbkdf2.HMAC_SHA512, P, S) p.update(1) p.update(1) dk = p.key() - self.assertEqual(dk, unhexlify('e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e')) + self.assertEqual( + dk, + unhexlify( + "e1d9c16aa681708a45f5c7c4e215ceb66e011a2e9f0040713f18aefdb866d53cf76cab2868a39b9f7840edce4fef5a82be67335c77a6068e04112754f27ccf4e" + ), + ) p = pbkdf2(pbkdf2.HMAC_SHA512, P, S) for i in range(32): p.update(128) dk = p.key() - self.assertEqual(dk, unhexlify('d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5')) - P = b'passwordPASSWORDpassword' - S = b'saltSALTsaltSALTsaltSALTsaltSALTsalt' + self.assertEqual( + dk, + unhexlify( + "d197b1b33db0143e018b12f3d1d1479e6cdebdcc97c5c0f87f6902e072f457b5143f30602641b3d55cd335988cb36b84376060ecd532e039b742a239434af2d5" + ), + ) + P = b"passwordPASSWORDpassword" + S = b"saltSALTsaltSALTsaltSALTsaltSALTsalt" p = pbkdf2(pbkdf2.HMAC_SHA512, P, S) for i in range(64): p.update(64) dk = p.key() - self.assertEqual(dk, unhexlify('8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8')) + self.assertEqual( + dk, + unhexlify( + "8c0511f4c6e597c6ac6315d8f0362e225f3c501495ba23b868c005174dc4ee71115b59f9e60cd9532fa33e0f75aefe30225c583a186cd82bd4daea9724a3d3b8" + ), + ) def test_key_multi(self): - P = b'password' - S = b'salt' + P = b"password" + S = b"salt" p = pbkdf2(pbkdf2.HMAC_SHA256, P, S, 16) k0 = p.key() k1 = p.key() @@ -104,5 +184,5 @@ class TestCryptoPbkdf2(unittest.TestCase): self.assertEqual(k0, k2) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.random.py b/core/tests/test_trezor.crypto.random.py index d05a1179a8..e9da06ecbc 100644 --- a/core/tests/test_trezor.crypto.random.py +++ b/core/tests/test_trezor.crypto.random.py @@ -4,7 +4,6 @@ from trezor.crypto import random class TestCryptoRandom(unittest.TestCase): - def test_uniform(self): c = {} for i in range(15): @@ -27,13 +26,13 @@ class TestCryptoRandom(unittest.TestCase): def test_bytes_uniform(self): for _ in range(100): c = {} - for h in '0123456789abcdef': + for h in "0123456789abcdef": c[h] = 0 for _ in range(8): b = random.bytes(1000) for h in hexlify(b): c[chr(h)] += 1 - for h in '0123456789abcdef': + for h in "0123456789abcdef": self.assertAlmostEqual(c[h], 1000, delta=200) def test_shuffle(self): @@ -44,5 +43,5 @@ class TestCryptoRandom(unittest.TestCase): self.assertEqual(sorted(lst), list(range(l))) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.rlp.py b/core/tests/test_trezor.crypto.rlp.py index 37e43be81e..27f3e8fcd7 100644 --- a/core/tests/test_trezor.crypto.rlp.py +++ b/core/tests/test_trezor.crypto.rlp.py @@ -7,74 +7,122 @@ class TestCryptoRlp(unittest.TestCase): # from https://raw.githubusercontent.com/ethereum/pyrlp/develop/tests/rlptest.json vectors = [ - (b'', - '80'), - (b'dog', - '83646f67'), - (b'Lorem ipsum dolor sit amet, consectetur adipisicing eli', - 'b74c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c69'), - (b'Lorem ipsum dolor sit amet, consectetur adipisicing elit', - 'b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974'), - (b'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mauris magna, suscipit sed vehicula non, iaculis faucibus tortor. Proin suscipit ultricies malesuada. Duis tortor elit, dictum quis tristique eu, ultrices at risus. Morbi a est imperdiet mi ullamcorper aliquet suscipit nec lorem. Aenean quis leo mollis, vulputate elit varius, consequat enim. Nulla ultrices turpis justo, et posuere urna consectetur nec. Proin non convallis metus. Donec tempor ipsum in mauris congue sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse convallis sem vel massa faucibus, eget lacinia lacus tempor. Nulla quis ultricies purus. Proin auctor rhoncus nibh condimentum mollis. Aliquam consequat enim at metus luctus, a eleifend purus egestas. Curabitur at nibh metus. Nam bibendum, neque at auctor tristique, lorem libero aliquet arcu, non interdum tellus lectus sit amet eros. Cras rhoncus, metus ac ornare cursus, dolor justo ultrices metus, at ullamcorper volutpat', - 'b904004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20437572616269747572206d6175726973206d61676e612c20737573636970697420736564207665686963756c61206e6f6e2c20696163756c697320666175636962757320746f72746f722e2050726f696e20737573636970697420756c74726963696573206d616c6573756164612e204475697320746f72746f7220656c69742c2064696374756d2071756973207472697374697175652065752c20756c7472696365732061742072697375732e204d6f72626920612065737420696d70657264696574206d6920756c6c616d636f7270657220616c6971756574207375736369706974206e6563206c6f72656d2e2041656e65616e2071756973206c656f206d6f6c6c69732c2076756c70757461746520656c6974207661726975732c20636f6e73657175617420656e696d2e204e756c6c6120756c74726963657320747572706973206a7573746f2c20657420706f73756572652075726e6120636f6e7365637465747572206e65632e2050726f696e206e6f6e20636f6e76616c6c6973206d657475732e20446f6e65632074656d706f7220697073756d20696e206d617572697320636f6e67756520736f6c6c696369747564696e2e20566573746962756c756d20616e746520697073756d207072696d697320696e206661756369627573206f726369206c756374757320657420756c74726963657320706f737565726520637562696c69612043757261653b2053757370656e646973736520636f6e76616c6c69732073656d2076656c206d617373612066617563696275732c2065676574206c6163696e6961206c616375732074656d706f722e204e756c6c61207175697320756c747269636965732070757275732e2050726f696e20617563746f722072686f6e637573206e69626820636f6e64696d656e74756d206d6f6c6c69732e20416c697175616d20636f6e73657175617420656e696d206174206d65747573206c75637475732c206120656c656966656e6420707572757320656765737461732e20437572616269747572206174206e696268206d657475732e204e616d20626962656e64756d2c206e6571756520617420617563746f72207472697374697175652c206c6f72656d206c696265726f20616c697175657420617263752c206e6f6e20696e74657264756d2074656c6c7573206c65637475732073697420616d65742065726f732e20437261732072686f6e6375732c206d65747573206163206f726e617265206375727375732c20646f6c6f72206a7573746f20756c747269636573206d657475732c20617420756c6c616d636f7270657220766f6c7574706174'), - (0, - '80'), - (1, - '01'), - (16, - '10'), - (79, - '4f'), - (127, - '7f'), - (128, - '8180'), - (254, - '81fe'), - (255, - '81ff'), - (256, - '820100'), - (1000, - '8203e8'), - (100000, - '830186a0'), - (0xffff, - '82ffff'), - (0x1_0000, - '83010000'), - (0xff_ffff, - '83ffffff'), - (0x100_0000, - '8401000000'), - (0xffff_ffff, - '84ffffffff'), - (0x1_0000_0000, - '850100000000'), - (83729609699884896815286331701780722, - '8f102030405060708090a0b0c0d0e0f2'), - (105315505618206987246253880190783558935785933862974822347068935681, - '9c0100020003000400050006000700080009000a000b000c000d000e01'), - ([], - 'c0'), - ([b'dog', b'god', b'cat'], - 'cc83646f6783676f6483636174'), - ([b'zw', [4], 1], - 'c6827a77c10401'), - ([b'asdf', b'qwer', b'zxcv', b'asdf', b'qwer', b'zxcv', b'asdf', b'qwer', b'zxcv', b'asdf', b'qwer'], - 'f784617364668471776572847a78637684617364668471776572847a78637684617364668471776572847a78637684617364668471776572'), - ([[b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv']], - 'f840cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376'), - ([[b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv'], [b'asdf', b'qwer', b'zxcv']], - 'f90200cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376'), - ([[[], []], []], - 'c4c2c0c0c0'), - ([[], [[]], [[], [[]]]], - 'c7c0c1c0c3c0c1c0'), - ([[b'key1', b'val1'], [b'key2', b'val2'], [b'key3', b'val3'], [b'key4', b'val4']], - 'ecca846b6579318476616c31ca846b6579328476616c32ca846b6579338476616c33ca846b6579348476616c34'), - (115792089237316195423570985008687907853269984665640564039457584007913129639936, - 'a1010000000000000000000000000000000000000000000000000000000000000000'), + (b"", "80"), + (b"dog", "83646f67"), + ( + b"Lorem ipsum dolor sit amet, consectetur adipisicing eli", + "b74c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c69", + ), + ( + b"Lorem ipsum dolor sit amet, consectetur adipisicing elit", + "b8384c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e7365637465747572206164697069736963696e6720656c6974", + ), + ( + b"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mauris magna, suscipit sed vehicula non, iaculis faucibus tortor. Proin suscipit ultricies malesuada. Duis tortor elit, dictum quis tristique eu, ultrices at risus. Morbi a est imperdiet mi ullamcorper aliquet suscipit nec lorem. Aenean quis leo mollis, vulputate elit varius, consequat enim. Nulla ultrices turpis justo, et posuere urna consectetur nec. Proin non convallis metus. Donec tempor ipsum in mauris congue sollicitudin. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Suspendisse convallis sem vel massa faucibus, eget lacinia lacus tempor. Nulla quis ultricies purus. Proin auctor rhoncus nibh condimentum mollis. Aliquam consequat enim at metus luctus, a eleifend purus egestas. Curabitur at nibh metus. Nam bibendum, neque at auctor tristique, lorem libero aliquet arcu, non interdum tellus lectus sit amet eros. Cras rhoncus, metus ac ornare cursus, dolor justo ultrices metus, at ullamcorper volutpat", + "b904004c6f72656d20697073756d20646f6c6f722073697420616d65742c20636f6e73656374657475722061646970697363696e6720656c69742e20437572616269747572206d6175726973206d61676e612c20737573636970697420736564207665686963756c61206e6f6e2c20696163756c697320666175636962757320746f72746f722e2050726f696e20737573636970697420756c74726963696573206d616c6573756164612e204475697320746f72746f7220656c69742c2064696374756d2071756973207472697374697175652065752c20756c7472696365732061742072697375732e204d6f72626920612065737420696d70657264696574206d6920756c6c616d636f7270657220616c6971756574207375736369706974206e6563206c6f72656d2e2041656e65616e2071756973206c656f206d6f6c6c69732c2076756c70757461746520656c6974207661726975732c20636f6e73657175617420656e696d2e204e756c6c6120756c74726963657320747572706973206a7573746f2c20657420706f73756572652075726e6120636f6e7365637465747572206e65632e2050726f696e206e6f6e20636f6e76616c6c6973206d657475732e20446f6e65632074656d706f7220697073756d20696e206d617572697320636f6e67756520736f6c6c696369747564696e2e20566573746962756c756d20616e746520697073756d207072696d697320696e206661756369627573206f726369206c756374757320657420756c74726963657320706f737565726520637562696c69612043757261653b2053757370656e646973736520636f6e76616c6c69732073656d2076656c206d617373612066617563696275732c2065676574206c6163696e6961206c616375732074656d706f722e204e756c6c61207175697320756c747269636965732070757275732e2050726f696e20617563746f722072686f6e637573206e69626820636f6e64696d656e74756d206d6f6c6c69732e20416c697175616d20636f6e73657175617420656e696d206174206d65747573206c75637475732c206120656c656966656e6420707572757320656765737461732e20437572616269747572206174206e696268206d657475732e204e616d20626962656e64756d2c206e6571756520617420617563746f72207472697374697175652c206c6f72656d206c696265726f20616c697175657420617263752c206e6f6e20696e74657264756d2074656c6c7573206c65637475732073697420616d65742065726f732e20437261732072686f6e6375732c206d65747573206163206f726e617265206375727375732c20646f6c6f72206a7573746f20756c747269636573206d657475732c20617420756c6c616d636f7270657220766f6c7574706174", + ), + (0, "80"), + (1, "01"), + (16, "10"), + (79, "4f"), + (127, "7f"), + (128, "8180"), + (254, "81fe"), + (255, "81ff"), + (256, "820100"), + (1000, "8203e8"), + (100000, "830186a0"), + (0xFFFF, "82ffff"), + (0x1_0000, "83010000"), + (0xFF_FFFF, "83ffffff"), + (0x100_0000, "8401000000"), + (0xFFFF_FFFF, "84ffffffff"), + (0x1_0000_0000, "850100000000"), + (83729609699884896815286331701780722, "8f102030405060708090a0b0c0d0e0f2"), + ( + 105315505618206987246253880190783558935785933862974822347068935681, + "9c0100020003000400050006000700080009000a000b000c000d000e01", + ), + ([], "c0"), + ([b"dog", b"god", b"cat"], "cc83646f6783676f6483636174"), + ([b"zw", [4], 1], "c6827a77c10401"), + ( + [ + b"asdf", + b"qwer", + b"zxcv", + b"asdf", + b"qwer", + b"zxcv", + b"asdf", + b"qwer", + b"zxcv", + b"asdf", + b"qwer", + ], + "f784617364668471776572847a78637684617364668471776572847a78637684617364668471776572847a78637684617364668471776572", + ), + ( + [ + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + ], + "f840cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376", + ), + ( + [ + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + [b"asdf", b"qwer", b"zxcv"], + ], + "f90200cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376cf84617364668471776572847a786376", + ), + ([[[], []], []], "c4c2c0c0c0"), + ([[], [[]], [[], [[]]]], "c7c0c1c0c3c0c1c0"), + ( + [ + [b"key1", b"val1"], + [b"key2", b"val2"], + [b"key3", b"val3"], + [b"key4", b"val4"], + ], + "ecca846b6579318476616c31ca846b6579328476616c32ca846b6579338476616c33ca846b6579348476616c34", + ), + ( + 115792089237316195423570985008687907853269984665640564039457584007913129639936, + "a1010000000000000000000000000000000000000000000000000000000000000000", + ), ] def test_rlp_write(self): @@ -84,13 +132,11 @@ class TestCryptoRlp(unittest.TestCase): rlp.write(w, i) self.assertEqual(w, o) - def test_rlp_length(self): for i, o in self.vectors: length = rlp.length(i) self.assertEqual(length, len(o) // 2) - -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.crypto.slip39.py b/core/tests/test_trezor.crypto.slip39.py index eb4c4f7cf4..7eb9365375 100644 --- a/core/tests/test_trezor.crypto.slip39.py +++ b/core/tests/test_trezor.crypto.slip39.py @@ -18,10 +18,11 @@ def combinations(iterable, r): else: return indices[i] += 1 - for j in range(i+1, r): - indices[j] = indices[j-1] + 1 + for j in range(i + 1, r): + indices[j] = indices[j - 1] + 1 yield tuple(pool[i] for i in indices) + class TestCryptoSlip39(unittest.TestCase): EMS = b"ABCDEFGHIJKLMNOP" @@ -30,8 +31,9 @@ class TestCryptoSlip39(unittest.TestCase): identifier = slip39.generate_random_identifier() mnemonics = slip39.split_ems(1, [(3, 5)], identifier, 1, ems) mnemonics = mnemonics[0] - self.assertEqual(slip39.recover_ems(mnemonics[:3]), slip39.recover_ems(mnemonics[2:])) - + self.assertEqual( + slip39.recover_ems(mnemonics[:3]), slip39.recover_ems(mnemonics[2:]) + ) def test_basic_sharing_fixed(self): generated_identifier = slip39.generate_random_identifier() @@ -44,12 +46,11 @@ class TestCryptoSlip39(unittest.TestCase): with self.assertRaises(slip39.MnemonicError): slip39.recover_ems(mnemonics[1:3]) - def test_iteration_exponent(self): identifier = slip39.generate_random_identifier() mnemonics = slip39.split_ems(1, [(3, 5)], identifier, 1, self.EMS) mnemonics = mnemonics[0] - identifier, exponent, ems = slip39.recover_ems(mnemonics[1:4]) + identifier, exponent, ems = slip39.recover_ems(mnemonics[1:4]) self.assertEqual(ems, self.EMS) identifier = slip39.generate_random_identifier() @@ -58,14 +59,17 @@ class TestCryptoSlip39(unittest.TestCase): identifier, exponent, ems = slip39.recover_ems(mnemonics[1:4]) self.assertEqual(ems, self.EMS) - def test_group_sharing(self): group_threshold = 2 group_sizes = (5, 3, 5, 1) member_thresholds = (3, 2, 2, 1) identifier = slip39.generate_random_identifier() mnemonics = slip39.split_ems( - group_threshold, list(zip(member_thresholds, group_sizes)), identifier, 1, self.EMS + group_threshold, + list(zip(member_thresholds, group_sizes)), + identifier, + 1, + self.EMS, ) # Test all valid combinations of mnemonics. @@ -77,11 +81,15 @@ class TestCryptoSlip39(unittest.TestCase): identifier, exponent, ems = slip39.recover_ems(mnemonic_subset) self.assertEqual(ems, self.EMS) - # Minimal sets of mnemonics. - identifier, exponent, ems = slip39.recover_ems([mnemonics[2][0], mnemonics[2][2], mnemonics[3][0]]) + identifier, exponent, ems = slip39.recover_ems( + [mnemonics[2][0], mnemonics[2][2], mnemonics[3][0]] + ) self.assertEqual(ems, self.EMS) - self.assertEqual(slip39.recover_ems([mnemonics[2][3], mnemonics[3][0], mnemonics[2][4]])[2], ems) + self.assertEqual( + slip39.recover_ems([mnemonics[2][3], mnemonics[3][0], mnemonics[2][4]])[2], + ems, + ) # One complete group and one incomplete group out of two groups required. with self.assertRaises(slip39.MnemonicError): @@ -91,14 +99,17 @@ class TestCryptoSlip39(unittest.TestCase): with self.assertRaises(slip39.MnemonicError): slip39.recover_ems(mnemonics[0][1:4]) - def test_group_sharing_threshold_1(self): group_threshold = 1 group_sizes = (5, 3, 5, 1) member_thresholds = (3, 2, 2, 1) identifier = slip39.generate_random_identifier() mnemonics = slip39.split_ems( - group_threshold, list(zip(member_thresholds, group_sizes)), identifier, 1, self.EMS + group_threshold, + list(zip(member_thresholds, group_sizes)), + identifier, + 1, + self.EMS, ) # Test all valid combinations of mnemonics. @@ -109,17 +120,19 @@ class TestCryptoSlip39(unittest.TestCase): identifier, exponent, ems = slip39.recover_ems(mnemonic_subset) self.assertEqual(ems, self.EMS) - def test_all_groups_exist(self): for group_threshold in (1, 2, 5): identifier = slip39.generate_random_identifier() mnemonics = slip39.split_ems( - group_threshold, [(3, 5), (1, 1), (2, 3), (2, 5), (3, 5)], identifier, 1, self.EMS + group_threshold, + [(3, 5), (1, 1), (2, 3), (2, 5), (3, 5)], + identifier, + 1, + self.EMS, ) self.assertEqual(len(mnemonics), 5) self.assertEqual(len(sum(mnemonics, [])), 19) - def test_invalid_sharing(self): identifier = slip39.generate_random_identifier() @@ -143,16 +156,18 @@ class TestCryptoSlip39(unittest.TestCase): with self.assertRaises(ValueError): slip39.split_ems(2, [(3, 5), (1, 3), (2, 5)], identifier, 1, self.EMS) - def test_vectors(self): for mnemonics, secret in vectors: if secret: identifier, exponent, ems = slip39.recover_ems(mnemonics) - self.assertEqual(slip39.decrypt(ems, b"TREZOR", exponent, identifier), unhexlify(secret)) + self.assertEqual( + slip39.decrypt(ems, b"TREZOR", exponent, identifier), + unhexlify(secret), + ) else: with self.assertRaises(slip39.MnemonicError): slip39.recover_ems(mnemonics) -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.io.sdcard.py b/core/tests/test_trezor.io.sdcard.py index 290a52e062..1b59a914d1 100644 --- a/core/tests/test_trezor.io.sdcard.py +++ b/core/tests/test_trezor.io.sdcard.py @@ -4,7 +4,6 @@ from trezor import io class TestTrezorIoSdcard(unittest.TestCase): - def test_start(self): self.assertTrue(io.sdcard.is_present()) @@ -31,8 +30,8 @@ class TestTrezorIoSdcard(unittest.TestCase): def test_read_write(self): r = bytearray(8 * 512) - w0 = bytearray(b'0' * (8 * 512)) - w1 = bytearray(b'1' * (8 * 512)) + w0 = bytearray(b"0" * (8 * 512)) + w1 = bytearray(b"1" * (8 * 512)) io.sdcard.power_on() io.sdcard.write(0, w0) io.sdcard.read(0, r) @@ -43,5 +42,5 @@ class TestTrezorIoSdcard(unittest.TestCase): io.sdcard.power_off() -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.protobuf.py b/core/tests/test_trezor.protobuf.py index 7f0c632886..f2aad14bc2 100644 --- a/core/tests/test_trezor.protobuf.py +++ b/core/tests/test_trezor.protobuf.py @@ -1,7 +1,12 @@ from common import * from trezor import protobuf -from trezor.messages import WebAuthnCredential, Failure, SignMessage, DebugLinkMemoryRead +from trezor.messages import ( + WebAuthnCredential, + Failure, + SignMessage, + DebugLinkMemoryRead, +) def load_uvarint32(data: bytes) -> int: @@ -49,7 +54,9 @@ def dump_message(msg: protobuf.MessageType) -> bytearray: return buffer -def load_message(msg_type: Type[protobuf.MessageType], buffer: bytes) -> protobuf.MessageType: +def load_message( + msg_type: Type[protobuf.MessageType], buffer: bytes +) -> protobuf.MessageType: return protobuf.decode(buffer, msg_type, False) @@ -110,6 +117,5 @@ class TestProtobuf(unittest.TestCase): self.assertEqual(nmsg.coin_name, "Bitcoin") - if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.sdcard.py b/core/tests/test_trezor.sdcard.py index dff5e9fc15..ddff4d0b34 100644 --- a/core/tests/test_trezor.sdcard.py +++ b/core/tests/test_trezor.sdcard.py @@ -4,6 +4,7 @@ from trezor import io, sdcard fatfs = io.fatfs + class TestTrezorSdcard(unittest.TestCase): def test_power(self): # sdcard.capacity() will return 0 if the card is not powered, diff --git a/core/tests/test_trezor.ui.display.py b/core/tests/test_trezor.ui.display.py index 1f7f2a628c..37eb5f5b63 100644 --- a/core/tests/test_trezor.ui.display.py +++ b/core/tests/test_trezor.ui.display.py @@ -26,5 +26,5 @@ class TestDisplay(unittest.TestCase): pass -if __name__ == '__main__': +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_trezor.utils.py b/core/tests/test_trezor.utils.py index 2d87543705..41292866c5 100644 --- a/core/tests/test_trezor.utils.py +++ b/core/tests/test_trezor.utils.py @@ -4,7 +4,6 @@ from trezor import utils class TestUtils(unittest.TestCase): - def test_chunks(self): c = list(utils.chunks(range(100), 7)) for i in range(15): @@ -25,25 +24,44 @@ class TestUtils(unittest.TestCase): self.assertEqual(utils.truncate_utf8("ab\u0123", 3), "ab") # b'ab\xc4\xa3' self.assertEqual(utils.truncate_utf8("ab\u1234", 3), "ab") # b'ab\xe1\x88\xb4' self.assertEqual(utils.truncate_utf8("abc\u0123", 3), "abc") # b'abc\xc4\xa3' - self.assertEqual(utils.truncate_utf8("abc\u1234", 3), "abc") # b'abc\xe1\x88\xb4' - self.assertEqual(utils.truncate_utf8("\u1234\u5678", 0), "") # b'\xe1\x88\xb4\xe5\x99\xb8 - self.assertEqual(utils.truncate_utf8("\u1234\u5678", 1), "") # b'\xe1\x88\xb4\xe5\x99\xb8 - self.assertEqual(utils.truncate_utf8("\u1234\u5678", 2), "") # b'\xe1\x88\xb4\xe5\x99\xb8 - self.assertEqual(utils.truncate_utf8("\u1234\u5678", 3), "\u1234") # b'\xe1\x88\xb4\xe5\x99\xb8 - self.assertEqual(utils.truncate_utf8("\u1234\u5678", 4), "\u1234") # b'\xe1\x88\xb4\xe5\x99\xb8 - self.assertEqual(utils.truncate_utf8("\u1234\u5678", 5), "\u1234") # b'\xe1\x88\xb4\xe5\x99\xb8 - self.assertEqual(utils.truncate_utf8("\u1234\u5678", 6), "\u1234\u5678") # b'\xe1\x88\xb4\xe5\x99\xb8 - self.assertEqual(utils.truncate_utf8("\u1234\u5678", 7), "\u1234\u5678") # b'\xe1\x88\xb4\xe5\x99\xb8 + self.assertEqual( + utils.truncate_utf8("abc\u1234", 3), "abc" + ) # b'abc\xe1\x88\xb4' + self.assertEqual( + utils.truncate_utf8("\u1234\u5678", 0), "" + ) # b'\xe1\x88\xb4\xe5\x99\xb8 + self.assertEqual( + utils.truncate_utf8("\u1234\u5678", 1), "" + ) # b'\xe1\x88\xb4\xe5\x99\xb8 + self.assertEqual( + utils.truncate_utf8("\u1234\u5678", 2), "" + ) # b'\xe1\x88\xb4\xe5\x99\xb8 + self.assertEqual( + utils.truncate_utf8("\u1234\u5678", 3), "\u1234" + ) # b'\xe1\x88\xb4\xe5\x99\xb8 + self.assertEqual( + utils.truncate_utf8("\u1234\u5678", 4), "\u1234" + ) # b'\xe1\x88\xb4\xe5\x99\xb8 + self.assertEqual( + utils.truncate_utf8("\u1234\u5678", 5), "\u1234" + ) # b'\xe1\x88\xb4\xe5\x99\xb8 + self.assertEqual( + utils.truncate_utf8("\u1234\u5678", 6), "\u1234\u5678" + ) # b'\xe1\x88\xb4\xe5\x99\xb8 + self.assertEqual( + utils.truncate_utf8("\u1234\u5678", 7), "\u1234\u5678" + ) # b'\xe1\x88\xb4\xe5\x99\xb8 def test_firmware_hash(self): self.assertEqual( utils.firmware_hash(), - b'\xd2\xdb\x90\xa7jV6\xa7\x00N\xc3\xb4\x8eq\xa9U\xe0\xcb\xb2\xcbZo\xd7\xae\x9f\xbe\xf8F\xbc\x16l\x8c', + b"\xd2\xdb\x90\xa7jV6\xa7\x00N\xc3\xb4\x8eq\xa9U\xe0\xcb\xb2\xcbZo\xd7\xae\x9f\xbe\xf8F\xbc\x16l\x8c", ) self.assertEqual( utils.firmware_hash(b"0123456789abcdef"), b"\xa0\x93@\x98\xa6\x80\xdb\x07m\xdf~\xe2'E\xf1\x19\xd8\xfd\xa4`\x10H\xf0_\xdbf\xa6N\xdd\xc0\xcf\xed", ) -if __name__ == '__main__': + +if __name__ == "__main__": unittest.main() diff --git a/core/tests/test_unittest.py b/core/tests/test_unittest.py index 63c657d6de..f41adb7d6b 100644 --- a/core/tests/test_unittest.py +++ b/core/tests/test_unittest.py @@ -2,7 +2,6 @@ from common import * class TestUnittest(unittest.TestCase): - def test_debug(self): if not __debug__: # Fail the test if debug is turned off, because `assert` is not executed then. diff --git a/core/tests/unittest.py b/core/tests/unittest.py index 20f7013cc6..13a8a59e20 100644 --- a/core/tests/unittest.py +++ b/core/tests/unittest.py @@ -8,7 +8,6 @@ class SkipTest(Exception): class AssertRaisesContext: - def __init__(self, exc): self.expected = exc self.value = None @@ -29,14 +28,14 @@ class TestCase: def __init__(self) -> None: self.__equality_functions = {} - def fail(self, msg=''): + def fail(self, msg=""): ensure(False, msg) def addTypeEqualityFunc(self, typeobj, function): ensure(callable(function)) self.__equality_functions[typeobj.__name__] = function - def assertEqual(self, x, y, msg=''): + def assertEqual(self, x, y, msg=""): if not msg: msg = f"{repr(x)} vs (expected) {repr(y)}" @@ -47,12 +46,12 @@ class TestCase: else: ensure(x == y, msg) - def assertNotEqual(self, x, y, msg=''): + def assertNotEqual(self, x, y, msg=""): if not msg: msg = f"{repr(x)} not expected to be equal {repr(y)}" ensure(x != y, msg) - def assertAlmostEqual(self, x, y, places=None, msg='', delta=None): + def assertAlmostEqual(self, x, y, places=None, msg="", delta=None): if x == y: return if delta is not None and places is not None: @@ -62,18 +61,18 @@ class TestCase: if abs(x - y) <= delta: return if not msg: - msg = f'{repr(x)} != {repr(y)} within {repr(delta)} delta' + msg = f"{repr(x)} != {repr(y)} within {repr(delta)} delta" else: if places is None: places = 7 if round(abs(y - x), places) == 0: return if not msg: - msg = f'{repr(x)} != {repr(y)} within {repr(places)} places' + msg = f"{repr(x)} != {repr(y)} within {repr(places)} places" ensure(False, msg) - def assertNotAlmostEqual(self, x, y, places=None, msg='', delta=None): + def assertNotAlmostEqual(self, x, y, places=None, msg="", delta=None): if delta is not None and places is not None: raise TypeError("specify delta or places not both") @@ -81,53 +80,53 @@ class TestCase: if not (x == y) and abs(x - y) > delta: return if not msg: - msg = f'{repr(x)} == {repr(y)} within {repr(delta)} delta' + msg = f"{repr(x)} == {repr(y)} within {repr(delta)} delta" else: if places is None: places = 7 if not (x == y) and round(abs(y - x), places) != 0: return if not msg: - msg = f'{repr(x)} == {repr(y)} within {repr(places)} places' + msg = f"{repr(x)} == {repr(y)} within {repr(places)} places" ensure(False, msg) - def assertIs(self, x, y, msg=''): + def assertIs(self, x, y, msg=""): if not msg: msg = f"{repr(x)} is not {repr(y)}" ensure(x is y, msg) - def assertIsNot(self, x, y, msg=''): + def assertIsNot(self, x, y, msg=""): if not msg: msg = f"{repr(x)} is {repr(y)}" ensure(x is not y, msg) - def assertIsNone(self, x, msg=''): + def assertIsNone(self, x, msg=""): if not msg: msg = f"{repr(x)} is not None" ensure(x is None, msg) - def assertIsNotNone(self, x, msg=''): + def assertIsNotNone(self, x, msg=""): if not msg: msg = f"{repr(x)} is None" ensure(x is not None, msg) - def assertTrue(self, x, msg=''): + def assertTrue(self, x, msg=""): if not msg: msg = f"Expected {repr(x)} to be True" ensure(x, msg) - def assertFalse(self, x, msg=''): + def assertFalse(self, x, msg=""): if not msg: msg = f"Expected {repr(x)} to be False" ensure(not x, msg) - def assertIn(self, x, y, msg=''): + def assertIn(self, x, y, msg=""): if not msg: msg = f"Expected {repr(x)} to be in {repr(y)}" ensure(x in y, msg) - def assertIsInstance(self, x, y, msg=''): + def assertIsInstance(self, x, y, msg=""): ensure(isinstance(x, y), msg) def assertRaises(self, exc, func=None, *args, **kwargs): @@ -142,7 +141,7 @@ class TestCase: else: ensure(False, f"{repr(exc)} not raised") - def assertListEqual(self, x, y, msg=''): + def assertListEqual(self, x, y, msg=""): if len(x) != len(y): if not msg: msg = "List lengths not equal" @@ -160,34 +159,26 @@ class TestCase: syscall = task.send(prev_result) self.assertObjectEqual(syscall, expected) - def assertObjectEqual(self, a, b, msg=''): + def assertObjectEqual(self, a, b, msg=""): self.assertIsInstance(a, b.__class__, msg) self.assertEqual(a.__dict__, b.__dict__, msg) def assertDictEqual(self, x, y): self.assertEqual( - len(x), - len(y), - f"Dict lengths not equal - {len(x)} vs {len(y)}" + len(x), len(y), f"Dict lengths not equal - {len(x)} vs {len(y)}" ) for key in x: - self.assertIn( - key, - y, - f"Key {key} not found in second dict." - ) + self.assertIn(key, y, f"Key {key} not found in second dict.") self.assertEqual( - x[key], - y[key], - f"At key {key} expected {x[key]}, found {y[key]}" + x[key], y[key], f"At key {key} expected {x[key]}, found {y[key]}" ) def assertMessageEqual(self, x, y): self.assertEqual( x.MESSAGE_NAME, y.MESSAGE_NAME, - f"Expected {x.MESSAGE_NAME}, found {y.MESSAGE_NAME}" + f"Expected {x.MESSAGE_NAME}, found {y.MESSAGE_NAME}", ) self.assertDictEqual(x.__dict__, y.__dict__) @@ -197,7 +188,9 @@ def skip(msg): # We just replace original fun with _inner def _inner(self): raise SkipTest(msg) + return _inner + return _decor @@ -208,7 +201,6 @@ def skipUnless(cond, msg): class TestSuite: - def __init__(self): self.tests = [] @@ -217,7 +209,6 @@ class TestSuite: class TestRunner: - def run(self, suite): res = TestResult() for c in suite.tests: @@ -226,7 +217,6 @@ class TestRunner: class TestResult: - def __init__(self): self.errorsNum = 0 self.failuresNum = 0 @@ -244,10 +234,10 @@ def run_class(c, test_result): o = c() set_up = getattr(o, "setUp", lambda: None) tear_down = getattr(o, "tearDown", lambda: None) - print('class', c.__qualname__) + print("class", c.__qualname__) for name in dir(o): if name.startswith("test"): - print(' ', name, end=' ...') + print(" ", name, end=" ...") m = getattr(o, name) try: try: @@ -255,7 +245,9 @@ def run_class(c, test_result): test_result.testsRun += 1 retval = m() if isinstance(retval, generator_type): - raise RuntimeError(f"{name} must not be a generator (it is async, uses yield or await).") + raise RuntimeError( + f"{name} must not be a generator (it is async, uses yield or await)." + ) elif retval is not None: raise RuntimeError(f"{name} should not return a result.") finally: @@ -278,7 +270,11 @@ def main(module="__main__"): def test_cases(m): for tn in dir(m): c = getattr(m, tn) - if isinstance(c, object) and isinstance(c, type) and issubclass(c, TestCase): + if ( + isinstance(c, object) + and isinstance(c, type) + and issubclass(c, TestCase) + ): yield c m = __import__(module)