Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/cryptoadvance/specter/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,8 @@ def der_to_bytes(derivation):
if item[-1] == "h" or item[-1] == "'":
index += 0x80000000
item = item[:-1]
if not item.isdigit():
raise ValueError(f"Invalid derivation index: {item}")
index += int(item)
res += index.to_bytes(4, "little")
return res
Expand Down
21 changes: 21 additions & 0 deletions tests/test_der_to_bytes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import unittest

from cryptoadvance.specter.helpers import der_to_bytes


class TestDerToBytes(unittest.TestCase):
def test_underscore_is_rejected(self):
with self.assertRaises(ValueError):
der_to_bytes("m/1_0")

def test_plain_index(self):
self.assertEqual(der_to_bytes("m/10"), (10).to_bytes(4, "little"))

def test_hardened_index(self):
self.assertEqual(
der_to_bytes("m/1h"), (0x80000001).to_bytes(4, "little")
)


if __name__ == "__main__":
unittest.main()