-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathledger2algo.py
26 lines (20 loc) · 1.02 KB
/
ledger2algo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# convert from a BIP39 mnemonic to an Algorand mnemonic.
from bip_utils import (
AlgorandMnemonicGenerator, Bip32KholawEd25519, Bip39SeedGenerator,
Ed25519PrivateKey
)
from algosdk import account, mnemonic
def convert_seed(bip39_mnemonic: str, passphrase: str, ledger_account: int):
bip39_seed_bytes = Bip39SeedGenerator(bip39_mnemonic).Generate(passphrase)
bip32_ctx = Bip32KholawEd25519.FromSeedAndPath(bip39_seed_bytes, f"m/44'/283'/{ledger_account}'/0/0")
priv_key_bytes = bip32_ctx.PrivateKey().Raw().ToBytes()[:Ed25519PrivateKey.Length()]
return AlgorandMnemonicGenerator().FromEntropy(priv_key_bytes).ToStr()
# Ledger recovery data
bip39_mnemonic = ""
passphrase = ""
ledger_account = 1
algorand_mnemonic = convert_seed(bip39_mnemonic,passphrase,ledger_account)
algorand_address = account.address_from_private_key(mnemonic.to_private_key(algorand_mnemonic))
print("\nALGORAND\n")
print(f" Algorand mnemonic: {algorand_mnemonic}")
print(f" Algorand address: {algorand_address}\n")