python – I’m attempting to transform the 12 phrases into BTC addresses, however they don’t match

0
110
python – I’m attempting to transform the 12 phrases into BTC addresses, however they don’t match


I’m attempting to transform the 12 phrases into BTC addresses, however they don’t match those proven to me by Safepal, Coinomi, and Belief Pockets. I’ve tried utilizing a number of libraries and doing it manually.

I managed to efficiently convert to SegWit, however P2PKH and P2SH nonetheless don’t match.

The phrases (they’re for testing functions) are:

false deal summary advance buffalo clock auto banana supply area wage stumble

The code I’m utilizing to transform utilizing the 2 strategies that aren’t working is as follows:

################# P2PKH ##############

seed = hashlib.pbkdf2_hmac('sha512', mnemonic.encode('utf-8'), b'mnemonic', 2048)
private_key = seed[:32]
public_key = hashlib.sha256(private_key).digest()
ripemd160 = hashlib.new('ripemd160')
ripemd160.replace(public_key)
hash160 = ripemd160.digest()
model = b"x00" # model for P2PKH addresses on Bitcoin mainnet
address_bytes = model + hash160
checksum = hashlib.sha256(hashlib.sha256(address_bytes).digest()).digest()[:4]
addressP2PKH = base58.b58encode(address_bytes + checksum).decode('utf-8')

################ P2SH ##############

seed = hashlib.pbkdf2_hmac('sha512', mnemonic.encode('utf-8'), b'mnemonic', 2048)
private_key = seed[:32]
sk = SigningKey.from_string(private_key, curve=SECP256k1)
vk = sk.get_verifying_key()
public_key_bytes = vk.to_string()
hashed_public_key = hashlib.sha256(public_key_bytes).digest()
ripe_hash = hashlib.new('ripemd160', hashed_public_key).digest()
prefix = b'x05'
prefixed_ripe_hash = prefix + ripe_hash
address_bytes = hashlib.sha256(prefixed_ripe_hash).digest()
address_bytes = hashlib.sha256(address_bytes).digest()
checksum = address_bytes[:4]
raw_address = prefixed_ripe_hash + checksum
addressP2SH = base58.b58encode(raw_address).decode()

print(['segwitAddress', 'addressP2PKH', 'addressP2SH'])

The output is:

['bc1qfev3mh2mz3cuvsfn3wt6rwv78qjlkcy7dj27dk', '14ZowctPoxYtaUa55XKpUq8h2VWzPvLQ84', '37qZKk7ZpFFX63fR4HLPRaU5jtdhckmcnP']

But it surely needs to be:

['bc1qfev3mh2mz3cuvsfn3wt6rwv78qjlkcy7dj27dk', '1D9P3s1Daa3dmLq88QAky3uv4vjT6WZRCV', '3HojBjoLmEHjrHfiiUKAL1NCVXEcmAf7iY']

LEAVE A REPLY

Please enter your comment!
Please enter your name here