Bitcoin Forum
June 18, 2024, 03:58:05 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Pls More clarification on WIF private key format and A CHECKSUM is needed.  (Read 166 times)
Hyphen(-) (OP)
Hero Member
*****
Offline Offline

Activity: 854
Merit: 728



View Profile WWW
April 06, 2022, 11:11:14 AM
 #1

When I was doing more research on WIF Private key, I became a little baffled. All I know is that this WIF (Wallet Import Format) of private key is easy to handle and copy, implying that it is not as long as 256 bit, and that it is a short form of private key that makes handling or saving easier.

WIF private key creation has some specific additional features that I am not entirely clear on. Among the features are:

1. Byte version prefix,

2. The suffix Comparison Byte

3. a checksum


Dose that means that after someone has generate wallet's private key and decide to change it to WIF format, one must include these extra features?

If so, then Mainnet's prefix begins with 0x80, while the Testnet's begins with 0xEF. What is the most important factor to consider when providing this difference?
Also, as previously stated, CHECKSUM functions as an error detector, which means that while inserting the wallet, it will detect if it is correct. So, what types of errors does Checksum detect?

Finally, I understand that a WIF private key is a base58 format of a private key that can be described as an alternative way to display the original private key, and that it is possible to return to the original format of the private key, but the steps and processes to achieve this WIP format are confusing.
More explanation is required here pls.

source of research: learnmeabitcoin.com

.
.DuelbitsSPORTS.
▄▄▄███████▄▄▄
▄▄█████████████████▄▄
▄██████████████████████▄
██████████████████████████
███████████████████████████
██████████████████████████████
██████████████████████████████
█████████████████████████████
███████████████████████████
█████████████████████████
▀████████████████████████
▀▀███████████████████
██████████████████████████████
██
██
██
██

██
██
██
██

██
██
██
████████▄▄▄▄██▄▄▄██
███▄█▀▄▄▀███▄█████
█████████████▀▀▀██
██▀ ▀██████████████████
███▄███████████████████
███████████████████████
███████████████████████
███████████████████████
███████████████████████
███████████████████████
▀█████████████████████▀
▀▀███████████████▀▀
▀▀▀▀█▀▀▀▀
OFFICIAL EUROPEAN
BETTING PARTNER OF
ASTON VILLA FC
██
██
██
██

██
██
██
██

██
██
██
10%   CASHBACK  
          100%   MULTICHARGER  
BlackHatCoiner
Legendary
*
Offline Offline

Activity: 1554
Merit: 7565


Protocols over bureaucrats


View Profile
April 06, 2022, 11:30:16 AM
Last edit: April 06, 2022, 11:46:54 AM by BlackHatCoiner
 #2

Dose that means that after someone has generate wallet's private key and decide to change it to WIF format, one must include these extra features?
Yes, which of course happens automatically in the back end. Once you generate your private key the software forms the [prefix, private_key, checksum] and converts that series to base58.

What is the most important factor to consider when providing this difference?
What do you mean what's the most important factor? Mainnet's prefix is 0x80 and Testnet's 0xEF; it's just a way to make WIFs distinguish. Those that start with "K" or "L" are Mainnet's compressed keys while those that start with "c" are Testnet's compressed keys.

Check the symbol chart: https://en.bitcoin.it/wiki/Base58Check_encoding#Base58_symbol_chart

Also, as previously stated, CHECKSUM functions as an error detector, which means that while inserting the wallet, it will detect if it is correct. So, what types of errors does Checksum detect?
It's the first 4 bytes of the SHA256 of the SHA256 of your private key.

It detects if you've written it down correctly. If you make a mistake in your 32 bytes private key, the checksum will be invalid which will make the WIF invalid. If you write the checksum incorrectly, the WIF will be invalid. In both cases, it's because there's mismatch between the SHA256(SHA256(private_key)) and the checksum.

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
stanner.austin
Member
**
Offline Offline

Activity: 67
Merit: 53


View Profile
April 06, 2022, 11:32:27 AM
 #3

Hi
This will be easy way to understand how its made.
Code:
Private key 0000000000000000000000000000000000000000000000000000000000000001 

WIF UNCOMPRESS
5HpHagT65TZzG1PH3CSu63k8DbpvD8s5ip4nEB3kEsreAnchuDf

800000000000000000000000000000000000000000000000000000000000000001A85AA87E
double_sha2("80"+"0000000000000000000000000000000000000000000000000000000000000001")
first 4 bytes is checksum A85AA87E


WIF COMPRESS
KwDiBf89QgGbjEhKnhXJuH7LrciVrZi3qYjgd9M7rFU73sVHnoWn

800000000000000000000000000000000000000000000000000000000000000001014671FC3F
double_sha2("80"+"0000000000000000000000000000000000000000000000000000000000000001"+"01")
first 4 bytes is checksum 4671FC3F

Checksum provide confirmation when import that we loading correct private key compressed or uncompressed.
n0nce
Hero Member
*****
Offline Offline

Activity: 882
Merit: 5830


not your keys, not your coins!


View Profile WWW
April 06, 2022, 11:34:00 AM
Merited by pooya87 (2)
 #4

Dose that means that after someone has generate wallet's private key and decide to change it to WIF format, one must include these extra features?
Those features are already inside the WIF key.
For instance, take the one from https://learnmeabitcoin.com/technical/wif: L5EZftvrYaSudiozVRzTqLcHLNDoVn7H5HSfM9BAN6tMJX8oTWz6.
If you go to any Base58-to-Hex decoder website and put it in, you'll get: 80ef235aacf90d9f4aadd8c92e4b2562e1d9eb97f0df9ba3b508258739cb013db20166557e53
As you can see, the 80 prefix, 01 compression byte suffix and 4-byte checksum in the back, are all in there already. No need to store them separately.

Also, as previously stated, CHECKSUM functions as an error detector, which means that while inserting the wallet, it will detect if it is correct. So, what types of errors does Checksum detect?
As the website you yourself linked says: Checksum - Useful for detecting errors/typos when you type out your private key.

Finally, I understand that a WIF private key is a base58 format of a private key that can be described as an alternative way to display the original private key, and that it is possible to return to the original format of the private key, but the steps and processes to achieve this WIP format are confusing.
More explanation is required here pls.
It's really well explained in https://learnmeabitcoin.com/technical/wif honestly. I don't understand the issue. To go back from the WIF key, you base58 decode it, strip the 'magic bytes' in the front and back (maybe verify the checksum first if feeling fancy), and there you have the private key.

█▀▀▀











█▄▄▄
▀▀▀▀▀▀▀▀▀▀▀
e
▄▄▄▄▄▄▄▄▄▄▄
█████████████
████████████▄███
██▐███████▄█████▀
█████████▄████▀
███▐████▄███▀
████▐██████▀
█████▀█████
███████████▄
████████████▄
██▄█████▀█████▄
▄█████████▀█████▀
███████████▀██▀
████▀█████████
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
c.h.
▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
▀▀▀█











▄▄▄█
▄██████▄▄▄
█████████████▄▄
███████████████
███████████████
███████████████
███████████████
███░░█████████
███▌▐█████████
█████████████
███████████▀
██████████▀
████████▀
▀██▀▀
pooya87
Legendary
*
Offline Offline

Activity: 3486
Merit: 10665



View Profile
April 06, 2022, 01:04:59 PM
 #5

WIF (Wallet Import Format) of private key is easy to handle and copy, implying that it is not as long as 256 bit, and that it is a short form of private key that makes handling or saving easier.
The "size" of the data doesn't change when you use a different encoding. Think of it as representing the same number in different ways for example:
Code:
35
thirty five
0x23
0b00100011
All show the same number but using different set of "digits" or encodings. It is exactly what we do when encoding a private key since they are simply numbers that can be between 1 bit to 256 bits. They are all padded to be 256 bit and encoded using Base58 (has 58 characters) that creates 51-52 digits in the end.
The benefit is that it has a checksum so we can detect a typo easily.

The extra information (suffix/prefix) are also easy ways to tell the wallet what type of address to derive from the entered key.

Quote
the steps and processes to achieve this WIP format are confusing.
More explanation is required here pls.
Which step is confusing?

.
.BLACKJACK ♠ FUN.
█████████
██████████████
████████████
█████████████████
████████████████▄▄
░█████████████▀░▀▀
██████████████████
░██████████████
████████████████
░██████████████
████████████
███████████████░██
██████████
CRYPTO CASINO &
SPORTS BETTING
▄▄███████▄▄
▄███████████████▄
███████████████████
█████████████████████
███████████████████████
█████████████████████████
█████████████████████████
█████████████████████████
███████████████████████
█████████████████████
███████████████████
▀███████████████▀
█████████
.
PawGo
Legendary
*
Offline Offline

Activity: 952
Merit: 1367


View Profile
April 06, 2022, 01:30:07 PM
Merited by BlackHatCoiner (2)
 #6

It detects if you've written it down correctly. If you make a mistake in your 32 bytes private key, the checksum will be invalid which will make the WIF invalid. If you write the checksum incorrectly, the WIF will be invalid. In both cases, it's because there's mismatch between the SHA256(SHA256(private_key)) and the checksum.

Checksum in the form as it is used in WIF is enough for everyday life, but one should be aware of fact that it does not say definitively that provided WIF is correct or incorrect, as it is possible to have invalid (not the one expected) WIF and correct checksum. That's because we do not use the full checksum, but only the part, which increases number of collisions.
Base on that fact (rare checksum collisions) I wrote my WifSolverCuda.
Anyway, as I said, for everyday usage it is enough. If someone would write down his WIF and made a mistake / misspelled one more more characters, but kept checksum and receive a new WIF which is accepted by programs, I would suggest playing a lottery Wink

And one more remark - apart of checksum, we may say that we may have mistake in middle/end part of WIF for compressed key if (after decoding) checksum byte is invalid, as we know it should be always 01.
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!