Use BIP39 from bip-utils with xx Network
· One min read
bip-utils
bip-utils allows generating mnemonics, seeds, private/public keys and addresses for different types of cryptocurrencies, including Substrate-based currencies.
xx Network support
I added it to a fork here. You could make similar/same modifications to bip-utils and build it yourself, of course.
I'd have to submit a patch to upstream, but "generic" Substrate coins are supported as well, so you could use it the same way without "hardcoded" XX configuration in bip-utils. You'd need to specify a custom coin/chain configuration, though. In the fork, that's already done.
Use from Substrate and bip-utils
Using Substrate:
>>> from substrateinterface import SubstrateInterface, Keypair, KeypairType
>>> from substrateinterface.exceptions import SubstrateRequestException
>>> kp = Keypair.create_from_mnemonic('abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about',ss58_format=55)
>>> kp.ss58_address
'6XcmqdSCi4Y4Qa4aVjqZRZbuB5P83CZ2XeuKnmtrd1DK75BL'
Using bip-utils, we follow the Substrate example from here:
>>> import binascii
>>> from bip_utils import Bip39MnemonicGenerator, Bip39WordsNum, Substrate, SubstrateBip39SeedGenerator, SubstrateCoins
>>> mnemonic = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
>>> seed_bytes = SubstrateBip39SeedGenerator(mnemonic).Generate()
>>> substrate_ctx.m_pub_key.ToAddress()
'6XcmqdSCi4Y4Qa4aVjqZRZbuB5P83CZ2XeuKnmtrd1DK75BL'