Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 4 - checksum should be double hashed? #277

Open
ArmanTheParman opened this issue Dec 12, 2023 · 1 comment
Open

Chapter 4 - checksum should be double hashed? #277

ArmanTheParman opened this issue Dec 12, 2023 · 1 comment

Comments

@ArmanTheParman
Copy link

On page 83 (chapter 4 under "Address Format", there is this code:

def encode_base58_checksum(b):
return encode_base58(b + hash256(b)[:4])

I believe the data should be hashed twice before extracting the checksum.
Also, hash256 isn't part of hashlib library, I used sha256.
I suppose if hash256 is a custom double sha256 function, then nothing to see here, move along folks.

I'm getting the right answer for the test with this code:

def base58check_encode(b):
checksum = hashlib.sha256(hashlib.sha256(b).digest()).digest()[:4]
return base58.b58encode(b + checksum)

@Gaming32
Copy link

Gaming32 commented Feb 1, 2024

hash256 is defined like this in helper.py:

def hash256(s):
    '''two rounds of sha256'''
    return hashlib.sha256(hashlib.sha256(s).digest()).digest()

The book never shows the implementation, but it's in the helper.py of each chapter folder in this repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants