1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2024-12-24 07:18:09 +00:00

core/bitcoin: drop unused validate_path_for_bitcoin_public_key

This commit is contained in:
matejcik 2020-07-16 11:43:32 +02:00 committed by matejcik
parent 407375b0c4
commit b741560997
2 changed files with 2 additions and 68 deletions

View File

@ -4,7 +4,7 @@ from trezor.crypto.hashlib import sha256
from trezor.messages import InputScriptType from trezor.messages import InputScriptType
from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType from trezor.messages.MultisigRedeemScriptType import MultisigRedeemScriptType
from apps.common import HARDENED, address_type, paths from apps.common import HARDENED, address_type
from apps.common.coininfo import CoinInfo from apps.common.coininfo import CoinInfo
from .common import ecdsa_hash_pubkey, encode_bech32_address from .common import ecdsa_hash_pubkey, encode_bech32_address
@ -232,25 +232,3 @@ def validate_purpose_against_script_type(
if purpose == 84 | HARDENED and script_type != InputScriptType.SPENDWITNESS: if purpose == 84 | HARDENED and script_type != InputScriptType.SPENDWITNESS:
return False return False
return True return True
def validate_path_for_bitcoin_public_key(path: list, coin: CoinInfo) -> bool:
"""
Validates derivation path to fit Bitcoin-like coins for GetPublicKey.
"""
length = len(path)
if length < 3 or length > 5:
return False
if not validate_purpose(path[0], coin):
return False
if path[1] != coin.slip44 | HARDENED:
return False
if path[2] < HARDENED or path[2] > 20 | HARDENED:
return False
if length > 3 and paths.is_hardened(path[3]):
return False
if length > 4 and paths.is_hardened(path[4]):
return False
return True

View File

@ -2,7 +2,7 @@ from common import *
from trezor.crypto import bip32, bip39 from trezor.crypto import bip32, bip39
from trezor.utils import HashWriter from trezor.utils import HashWriter
from apps.bitcoin.addresses import validate_full_path, validate_path_for_bitcoin_public_key from apps.bitcoin.addresses import validate_full_path
from apps.common.paths import HARDENED from apps.common.paths import HARDENED
from apps.common import coins from apps.common import coins
from apps.bitcoin import scripts from apps.bitcoin import scripts
@ -220,50 +220,6 @@ class TestAddress(unittest.TestCase):
for path, input_type in incorrect_derivation_paths: for path, input_type in incorrect_derivation_paths:
self.assertFalse(validate_full_path(path, coin, input_type)) self.assertFalse(validate_full_path(path, coin, input_type))
def test_paths_public_key(self):
incorrect_derivation_paths = [
[49 | HARDENED], # invalid length
[49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0 | HARDENED], # too many HARDENED
[49 | HARDENED, 0 | HARDENED], # invalid length
[49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0, 0], # invalid length
[49 | HARDENED, 123 | HARDENED, 0 | HARDENED, 0, 0, 0], # invalid slip44
[49 | HARDENED, 0 | HARDENED, 1000 | HARDENED, 0, 0], # account too high
]
correct_derivation_paths = [
[44 | HARDENED, 0 | HARDENED, 0 | HARDENED], # btc is segwit coin, but non-segwit paths are allowed as well
[44 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0],
[49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0],
[49 | HARDENED, 0 | HARDENED, 0 | HARDENED, 1, 0],
[49 | HARDENED, 0 | HARDENED, 5 | HARDENED],
[84 | HARDENED, 0 | HARDENED, 0 | HARDENED, 0, 0],
[84 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 0],
[84 | HARDENED, 0 | HARDENED, 5 | HARDENED, 0, 10],
]
coin = coins.by_name('Bitcoin')
for path in correct_derivation_paths:
self.assertTrue(validate_path_for_bitcoin_public_key(path, coin))
for path in incorrect_derivation_paths:
self.assertFalse(validate_path_for_bitcoin_public_key(path, coin))
@unittest.skipUnless(not utils.BITCOIN_ONLY, "altcoin")
def test_paths_public_key_nosegwit(self):
incorrect_derivation_paths = [
[49 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0, 0], # no segwit
]
correct_derivation_paths = [
[44 | HARDENED, 3 | HARDENED, 0 | HARDENED],
[44 | HARDENED, 3 | HARDENED, 1 | HARDENED],
[44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0],
[44 | HARDENED, 3 | HARDENED, 0 | HARDENED, 0, 0],
]
coin = coins.by_name('Dogecoin') # segwit is disabled
for path in correct_derivation_paths:
self.assertTrue(validate_path_for_bitcoin_public_key(path, coin))
for path in incorrect_derivation_paths:
self.assertFalse(validate_path_for_bitcoin_public_key(path, coin))
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()