I have this code:
# pip install mnemonic bip32
from mnemonic import Mnemonic
from bip32 import BIP32
def generar_semilla_y_bip32():
mnemo = Mnemonic("english")
mnemonic_words = mnemo.generate(strength=192)
print("Frase mnemónica generada (18 palabras):")
print(mnemonic_words)
seed = mnemo.to_seed(mnemonic_words)
bip32 = BIP32.from_seed(seed)
root_key = bip32.get_xpriv_from_path("m")
print("\nBIP32 Root Key generada a partir de la frase mnemónica:")
print(root_key)
def obtener_bip32_desde_semilla():
mnemo = Mnemonic("english")
mnemonic_words = input("Introduce tu frase mnemónica: ")
seed = mnemo.to_seed(mnemonic_words)
bip32 = BIP32.from_seed(seed)
root_key = bip32.get_xpriv_from_path("m")
print("\nBIP32 Root Key generada a partir de la frase mnemónica:")
print(root_key)
def main():
print("Elige una opción:")
print("1. Crear nueva semilla")
print("2. Ya tengo una semilla (dame la BIP32 Root Key)")
opcion = input("Introduce el número de la opción que quieres: ")
if opcion == "1":
generar_semilla_y_bip32()
elif opcion == "2":
obtener_bip32_desde_semilla()
else:
print("Opción no válida")
if __name__ == "__main__":
main()
It creates a 18 words seed phrase, and shows its BIP32 Root Key. With this, you can use the seed words in Electrum (or any BIP39 compatible wallet) and with the BIP32 Root Key you can import the same wallet in Bitcoin core (using importdescriptors command).
If you already have one seed phrase, it returns just the BIP32 Root Key.
In case you want to mantain a wallet for spendings with Electurm in your mobile, and just watch-only in Bitcoin core, you can use de importdescriptors with the xpub instead of the BIP32 Root Key (extracting the public descriptors with listdescriptors first).