Cómo obtener la dirección correcta de la frase mnemotécnica BTC en Python

Enfrenté un problema, tengo una billetera criptográfica escrita en Python, hay un código que crea una dirección de billetera a partir de una frase mnemotécnica (en este caso, dirección BTC). Pero si ingreso esta frase mnemotécnica en la aplicación móvil Trust Wallet, me dará una dirección de Bitcoin completamente diferente. ¿Por qué? ¿Como arreglarlo? Aquí está el código:

from bipwallet import wallet
from bipwallet.utils import *

Seed = wallet.generate_mnemonic()

WalletBTC = wallet.create_wallet(network="BTC", seed=Seed, children=0)

AddressBTC = WalletBTC.get("address")

print("BTC Address: ", AddressBTC)
La ruta de derivación también debe ser la misma, no solo la mnemotécnica

Respuestas (2)

Supongo que tanto la biblioteca de Python como Trustwallet implementan BIP32 para crear billeteras jerárquicas deterministas (HD).

La dirección que obtenga depende de la ruta de derivación . Si su biblioteca de Python y Trustwallet usan rutas de derivación diferentes, obtendrá direcciones diferentes.

Una billetera HD producirá múltiples direcciones, una diferente cada vez que solicite una dirección. Por lo tanto, debe tener cuidado de no comparar la primera dirección de una billetera con la segunda dirección de otra.

Gracias. Encontré de forma independiente bibliotecas que generan la misma dirección que Trust Wallet, así como Cryptoneed (aplicaciones móviles). Quién necesita mi código, cópialo y personalízalo tú mismo:

from hdwallet import BIP44HDWallet
from hdwallet.utils import generate_mnemonic
from hdwallet.derivations import BIP44Derivation
from hdwallet.cryptocurrencies import BitcoinMainnet, EthereumMainnet
from bip_utils import Bip84, Bip84Coins, Bip44Changes, Bip39SeedGenerator


LanguageInMnemonic = "english"

Mnemonic = generate_mnemonic(language = LanguageInMnemonic, strength = 128)
    Seed = Bip39SeedGenerator(Mnemonic).Generate()

    print(Mnemonic)

    if IsCheckBTC == "+":
        if IsCheckBTCBip44 == "+":
            CheckedWalletBTCBip44 = BIP44HDWallet(cryptocurrency=BitcoinMainnet)
            CheckedWalletBTCBip44.from_mnemonic(mnemonic = Mnemonic, language = LanguageInMnemonic, passphrase = None)
            CheckedWalletBTCBip44.clean_derivation()
            CheckedWalletBTCBip44Derivation = BIP44Derivation(cryptocurrency = BitcoinMainnet, account = 0, change = False, address = 0)
            CheckedWalletBTCBip44.from_path(path = CheckedWalletBTCBip44Derivation)

            CheckedAddressBTCBip44 = CheckedWalletBTCBip44.address()
            print(CheckedAddressBTCBip44)

        if IsCheckBTCBip84 == "+":
            CheckedWalletBTCBip84 = Bip84.FromSeed(Seed, Bip84Coins.BITCOIN)
            CheckedWalletBTCBip84Step1 = (CheckedWalletBTCBip84.Purpose().Coin().Account(0)).Change(Bip44Changes.CHAIN_EXT)
            CheckedWalletBTCBip84Step2 = CheckedWalletBTCBip84Step1.AddressIndex(0)

            CheckedAddressBTCBip84 = CheckedWalletBTCBip84Step2.PublicKey().ToAddress()
            print(CheckedAddressBTCBip84)

    if IsCheckETH == "+":
        CheckedWalletETH = BIP44HDWallet(cryptocurrency = EthereumMainnet)
        CheckedWalletETH.from_mnemonic(mnemonic = Mnemonic, language = LanguageInMnemonic, passphrase = None)
        CheckedWalletETH.clean_derivation()
        CheckedWalletETHDerivation: BIP44Derivation = BIP44Derivation(cryptocurrency = EthereumMainnet, account = 0, change = False, address = 0)
        CheckedWalletETH.from_path(path=CheckedWalletETHDerivation)

        CheckedAddressETH = CheckedWalletETH.address()
        print(CheckedAddressETH)

(PD, usé el traductor de Google)

¿Por qué la definición de IsCheckBTC no está definida en su fragmento de código?