Skip to content

Commit

Permalink
Support derivation path started by m/ (#301)
Browse files Browse the repository at this point in the history
* Accept derivation path started by master key

Co-authored-by: Uxío <Uxio0@users.noreply.github.com>

---------

Co-authored-by: Uxío <Uxio0@users.noreply.github.com>
  • Loading branch information
moisses89 and Uxio0 authored Nov 8, 2023
1 parent e79d1d4 commit d99afd2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
4 changes: 4 additions & 0 deletions safe_cli/operators/hw_accounts/ledger_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ def add_account(self, derivation_path: str) -> ChecksumAddress:
:param derivation_path:
:return:
"""
# we should accept m/ or m'/ starting derivation paths
if derivation_path[0:2] == "m/":
derivation_path = derivation_path.replace("m/", "")

if not is_bip32_path(derivation_path):
raise InvalidDerivationPath()

Expand Down
5 changes: 5 additions & 0 deletions tests/test_ledger_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ def test_add_account(self, mock_get_account_by_path: MagicMock):
ledger_account = list(ledger_manager.accounts)[0]
self.assertEqual(ledger_account.address, account_address)
self.assertEqual(ledger_account.path, derivation_path)
# Should accept derivation paths starting with master
master_derivation_path = "m/44'/60'/0'/0"
self.assertEqual(
ledger_manager.add_account(master_derivation_path), account_address
)

def test_delete_account(self):
ledger_manager = LedgerManager()
Expand Down

0 comments on commit d99afd2

Please sign in to comment.