Post
Topic
Board Development & Technical Discussion
Re: Decipher xprv or seed from keystore when I know the password
by
BlackHatCoiner
on 14/03/2023, 18:54:44 UTC
Both xprv and seed are in hex. I've already told you.
Maybe, but you haven't cleared up what you want to do, and it's difficult to understand what is what from your wording.

I need xprv and seed to be converted to xprv in base58 format, seed to words.
So you want hexadecimally represented xprv to base58 and hexadecimally represented seed to words (AKA, seed phrase).

I don't know python, so I asked ChatGPT. Isn't this what you want basically?
Code:
import base58
import binascii

def encode_xprv(hex_xprv):
    # Convert hex xprv to bytes
    xprv_bytes = binascii.unhexlify(hex_xprv)
   
    # Add version byte (0x0488ADE4) to the beginning
    version_bytes = bytes.fromhex('0488ADE4')
    xprv_bytes = version_bytes + xprv_bytes
   
    # Add 4-byte checksum to the end
    checksum_bytes = hash256(xprv_bytes)[:4]
    xprv_bytes += checksum_bytes
   
    # Encode the result in base58
    encoded_xprv = base58.b58encode(xprv_bytes).decode('utf-8')
   
    return encoded_xprv

def hash256(data):
    # Compute SHA256 hash of data
    import hashlib
    sha256_hash = hashlib.sha256(data).digest()
   
    # Compute SHA256 hash of SHA256 hash
    sha256_twice = hashlib.sha256(sha256_hash).digest()
   
    return sha256_twice

# Example usage
hex_xprv = "0488ade4000000000000000000d094cde7b1ca97a07c82d73bbd6b018f6b3e6d94c6c122f1b883e2e8fa6e76c261d96e4c4baebf8af4b4d05cfef4b1c2b47fa8f8640eb9a16f4d39473df7"
encoded_xprv = encode_xprv(hex_xprv)
print(encoded_xprv)