mirror of
https://gitlab.com/pulsechaincom/staking-deposit-cli.git
synced 2024-12-25 12:57:18 +00:00
96200d76ae
* Move tests to /tests * Rename `src` to `eth2deposit` * Fix path * Fix path and move eth2deposit/utils/credentials.py -> eth2deposit/credentials.py * Update Makefile * Kick CI cache * Fix package setup * Fix path back * PR feedback from Carl
30 lines
823 B
Python
30 lines
823 B
Python
from typing import List
|
|
|
|
from .mnemonic import get_seed
|
|
from .tree import (
|
|
derive_master_SK,
|
|
derive_child_SK,
|
|
)
|
|
|
|
|
|
def path_to_nodes(path: str) -> List[int]:
|
|
"""
|
|
Returns a list of the child index at every level in `path`.
|
|
"""
|
|
path = path.replace(' ', '')
|
|
assert set(path).issubset(set('m1234567890/'))
|
|
indices = path.split('/')
|
|
assert indices.pop(0) == 'm'
|
|
return [int(index) for index in indices]
|
|
|
|
|
|
def mnemonic_and_path_to_key(*, mnemonic: str, path: str, password: str='') -> int:
|
|
"""
|
|
Returns the SK at position `path` secures with `password` derived from `mnemonic`.
|
|
"""
|
|
seed = get_seed(mnemonic=mnemonic, password=password)
|
|
sk = derive_master_SK(seed)
|
|
for node in path_to_nodes(path):
|
|
sk = derive_child_SK(parent_SK=sk, index=node)
|
|
return sk
|