Skip to content

Commit 0068272

Browse files
committed
fix lint
1 parent 57b2fa7 commit 0068272

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

convex_api/account.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
to_hex
1616
)
1717

18+
from mnemonic import Mnemonic
19+
1820
from convex_api.utils import to_address_checksum
1921

2022

@@ -61,6 +63,15 @@ def export_to_text(self, password):
6163
)
6264
return private_data.decode()
6365

66+
@property
67+
def export_to_mnemonic(self):
68+
mnemonic = Mnemonic('english')
69+
return mnemonic.to_mnemonic(self._private_key.private_bytes(
70+
encoding=serialization.Encoding.Raw,
71+
format=serialization.PrivateFormat.Raw,
72+
encryption_algorithm=serialization.NoEncryption()
73+
))
74+
6475
def export_to_file(self, filename, password):
6576
"""
6677
Export the private key to a file. This uses `export_to_text` to export as a string.
@@ -161,6 +172,12 @@ def import_from_text(text, password):
161172
if private_key:
162173
return Account(private_key)
163174

175+
@staticmethod
176+
def import_from_mnemonic(words):
177+
mnemonic = Mnemonic('english')
178+
value = mnemonic.to_entropy(words)
179+
return Account(Ed25519PrivateKey.from_private_bytes(value))
180+
164181
@staticmethod
165182
def import_from_file(filename, password):
166183
"""

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
'cryptography',
2222
'eth-utils',
2323
'requests',
24+
'mnemonic'
2425
]
2526

2627
setup_requirements = ['pytest-runner', ]

tests/unit/test_account.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,10 @@ def test_account_import_export_to_file(test_account):
7272
assert(import_account.address == test_account.address)
7373
os.remove(filename)
7474

75+
def test_account_export_to_mnemonic(test_account):
76+
words = test_account.export_to_mnemonic
77+
assert(words)
78+
new_account = Account.import_from_mnemonic(words)
79+
assert(new_account)
80+
assert(test_account.address == new_account.address)
81+
assert(test_account.export_to_mnemonic == new_account.export_to_mnemonic)

0 commit comments

Comments
 (0)