Close Menu
  • Home
  • Bitcoin
    • Bitcoin Atm Machines
    • Bitcoin Books
      • Bitcoin Jobs
        • Bitcoin Price Prediction
        • Bitcoin Coin
  • Bitcoin Farm
  • Bitcoin Gifts
    • Bitcoin Gift Card
    • Bitcoin Mining
    • Bitcoin Wallets
  • Technology
  • Shop
    • Bitcoin Atm Machine
    • Bitcoin Coins
    • Bitcoin Coins, Wallets,Shirts,Books,Gifts
    • Bitcoin Mining Machine
    • Bitcoin Mining Machine Full Set Up
    • Computers and Accessories
    • USB Flash Drives
    • Mini Bitcoin Mining Machine
What's Hot

Adam Again Invests SEK 21 Million To H100 Group Bitcoin Treasury Technique

June 4, 2025

World Liberty Monetary airdrops $47 USD1 stablecoin in symbolic ‘stimulus’ nod to Donald Trump

June 4, 2025

Allow This Hidden iPhone Characteristic. Your Eyes Will Thank You

June 3, 2025
Facebook X (Twitter) Instagram
  • Bitcoin
  • Bitcoin Books
  • Bitcoin Coin
  • Bitcoin Farm
  • Bitcoin Gift Card
Facebook X (Twitter) Instagram
farm-bitcoin.com
  • Home
  • Bitcoin
    • Bitcoin Atm Machines
    • Bitcoin Books
      • Bitcoin Jobs
        • Bitcoin Price Prediction
        • Bitcoin Coin
  • Bitcoin Farm
  • Bitcoin Gifts
    • Bitcoin Gift Card
    • Bitcoin Mining
    • Bitcoin Wallets
  • Technology
  • Shop
    • Bitcoin Atm Machine
    • Bitcoin Coins
    • Bitcoin Coins, Wallets,Shirts,Books,Gifts
    • Bitcoin Mining Machine
    • Bitcoin Mining Machine Full Set Up
    • Computers and Accessories
    • USB Flash Drives
    • Mini Bitcoin Mining Machine
farm-bitcoin.com
Home » address – how to evaluate if this (or any) bitcoin public key / private key combination is valid?
address – how to evaluate if this (or any) bitcoin public key / private key combination is valid?
Bitcoin

address – how to evaluate if this (or any) bitcoin public key / private key combination is valid?

adminBy adminMarch 18, 2025No Comments3 Mins Read
Share
Facebook Twitter LinkedIn Pinterest Email


First, what you defining as public key and private key are actually a bitcoin address and a private key encoded in Wallet Import Format (WIF).

In order to check that the WIF and the bitcoin addresses are from the same key pair, we will need to decode the private key from its WIF format (checking that the encoding is ok), derive the public key from the private key, and generate the bitcoin address using the public key. If the generated bitcoin address matches with the provided one, then the provided one and the WIF are created from the same key pair.

In order to decode the WIF we will follow the steps from the bitcoin wiki.

Lets see how we can do this in python:

from binascii import hexlify, unhexlify
from ecdsa import SigningKey, SECP256k1
from hashlib import sha256
from bitcoin_tools.wallet import generate_btc_addr, WIF, TESTNET_WIF


def wif_to_sk(wif, network='main'):
    if network not in ['main', 'test']:
        # Add more networks if needed.
        raise Exception('Bad network')
    else:
        if network is 'main':
            version = WIF
        else:
            version = TESTNET_WIF

    decoded_wif = b58decode(wif)

    c = decoded_wif[-4:]
    v = decoded_wif[:1]

    # The byte defines the version, assert that is correct.
    assert v == chr(version)

    # The four last bytes of the WIF are the four first bytes of the checksum, check that it holds
    checksum = sha256(sha256(decoded_wif[:-4]).digest()).digest()
    assert checksum[:4] == c

    # If the private key in the WIF corresponds to a compressed public key, you must also drop the last byte, that will
    # be 01. We can check that by checking the length of the current key. 32 bytes wil mean uncompressed, while 33 and
    # a leading 01 means compressed.
    sk = hexlify(decoded_wif[1:-4])

    compressed = False

    # Notice that since we have hexlified the sk, the sizes are doubled.
    if len(sk) is 66 and sk[-2:] == '01':
        sk = unhexlify(sk[:-2])
        compressed = True
    else:
        sk = unhexlify(sk)

    return sk, compressed

# Your provided data
wif="KwfNqMip1ZdgG2o6wYQUBXv8BqkMQ8VWWeScVU5TLPZp31M5EHeq"
btc_addr="13YcHBzsBX8SxHoBftb69cXJkdXLfAVQos"
network = 'main'

sk, compressed = wif_to_sk(wif, network=network)

# Derive the public key from the private key
pk = SigningKey.from_string(sk, curve=SECP256k1).get_verifying_key()

# Assert that the computed bitcoin address and the provided one matches.
assert generate_btc_addr(pk, v=network, compressed=compressed) == btc_addr

To decode the WIF format there is a couple of things that you may know. First, the version of the network (normally either mainnet or testnet) and then, if the private key corresponds to a compressed or uncompressed public key. The version of the network will determine the first byte of the WIF format, while whether the related public key is compressed or uncompressed will determine the last byte before the checksum.

Disclaimer: The provided code uses a function generate_btc_addr, from a python library I’ve developed, that computes a bitcoin address from a given public key. Such function call a bunch of other simple functions to derive the bitcoin address, but including all on the answer will make it even longer that what it is. You can either get the library from GitHub, or get the functions from the specific file.



Source link

Post Views: 38
Address Bitcoin combination evaluate Key private public valid
Share. Facebook Twitter Pinterest LinkedIn Tumblr Email
admin
  • Website

Related Posts

Adam Again Invests SEK 21 Million To H100 Group Bitcoin Treasury Technique

June 4, 2025

World Liberty Monetary airdrops $47 USD1 stablecoin in symbolic ‘stimulus’ nod to Donald Trump

June 4, 2025

ETH Stays Robust at $2,600 After $321M Spot ETF Surge

June 3, 2025

How To Purchase Bitcoin From Malta? – The World Of Cryptocurrency

June 3, 2025
Add A Comment
Leave A Reply Cancel Reply

Subscribe to Updates

Get the latest creative news from farm-bitcoin about crypto, bitcoin, business and technology.

Please enable JavaScript in your browser to complete this form.
Loading
About

At Farm Bitcoin, we are passionate about unlocking the potential of cryptocurrency and blockchain technology. Our mission is to make the world of digital currencies accessible and understandable for everyone, from beginners to seasoned investors. We believe that cryptocurrency represents the future of finance, and we are here to guide you through this exciting landscape.

Get Informed

Subscribe to Updates

Get the latest creative news from farm-bitcoin about crypto, bitcoin, business and technology.

Please enable JavaScript in your browser to complete this form.
Loading
Top Insights

Adam Again Invests SEK 21 Million To H100 Group Bitcoin Treasury Technique

June 4, 2025

World Liberty Monetary airdrops $47 USD1 stablecoin in symbolic ‘stimulus’ nod to Donald Trump

June 4, 2025
Facebook X (Twitter) Instagram Pinterest
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions
Copyright 2024 Farm Bitcoin Design By Prince Ayaan.

Type above and press Enter to search. Press Esc to cancel.

Go to mobile version