Skip to content

Commit

Permalink
PASS1-206: More fixes for address verification
Browse files Browse the repository at this point in the history
Added missing testnet prefixes
Some bitcoin addresses wrapped badly with 16 characters across, so just limit all to 14 characters per line
  • Loading branch information
FoundationKen committed Feb 2, 2022
1 parent 3fec593 commit a0a2382
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 9 deletions.
20 changes: 16 additions & 4 deletions ports/stm32/boards/Passport/modules/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -871,10 +871,8 @@ async def needs_microsd():
def format_btc_address(address, addr_type):
from public_constants import AF_P2WPKH

if addr_type == AF_P2WPKH:
width = 14
else:
width = 16
# The max number of characters on a single line
width = 14

return split_to_lines(address, width)

Expand Down Expand Up @@ -904,4 +902,18 @@ def split_by_char_size(msg, font):
lines.append(ln)
return lines

def partition_evenly_by_max_size(total, max_part_size):
num_total_parts = (total + max_part_size - 1) // max_part_size
min_size = int(total / num_total_parts)
num_big_parts = total % num_total_parts
parts = []

for i in range(0, num_big_parts):
parts.append(min_size + 1)

for i in range(num_big_parts, num_total_parts):
parts.append(min_size)

return parts

# EOF
12 changes: 7 additions & 5 deletions ports/stm32/boards/Passport/modules/wallets/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,18 @@ def get_deriv_fmt_from_address(address, is_multisig):

# Map the address prefix to a standard derivation path and insert the account number
if is_multisig:
if address[0] == '3':
if (address[0] == '3' or address[0] == 'n'):
return "m/48'/{coin_type}'/{acct}'/1'"
elif address[0] == 'b' and address[1] == 'c' and address[2] == '1':
elif ((address[0] == 'b' and address[1] == 'c' and address[2] == '1') or
(address[0] == 't' and address[1] == 'b' and address[2] == '1')):
return "m/48'/{coin_type}'/{acct}'/2'"
else:
if address[0] == '1':
if (address[0] == '1' or address[0] == 'm'):
return "m/44'/{coin_type}'/{acct}'"
elif address[0] == '3':
elif (address[0] == '3' or address[0] == 'n'):
return "m/49'/{coin_type}'/{acct}'"
elif address[0] == 'b' and address[1] == 'c' and address[2] == '1':
elif ((address[0] == 'b' and address[1] == 'c' and address[2] == '1') or
(address[0] == 't' and address[1] == 'b' and address[2] == '1')):
return "m/84'/{coin_type}'/{acct}'"

return None
Expand Down

0 comments on commit a0a2382

Please sign in to comment.