INNER CODE UNIT · Python
parse_derivation_path
polhenarejos/pico-hsm · tools/pico-hsm-tool.py:530
def parse_derivation_path(path):
if path == "m":
return []
if len(path) < 3:
raise ValueError(f"derivation path too short: {path}")
elems = path.split("/")
if elems[0] != 'm':
raise ValueError(f"derivation path {path} does not begin with 'm/'")
indices = []
for e in elems[1:]:
if len(e) == 0:
raise ValueError(f"derivation path contains empty index: {path}")
off = 0
if e[-1:] in ["'", "h"]:
off = 0x80000000
e = e[:-1]
indices.append(int(e) + off)
return indices