checksum in address

0

I want to create a address bitcoin.

I have a payload with version like this:

0050d512c984b1656ef47c145c8fd5d5262d3904b1

where 00 in my version prefix, and 50d512c984b1656ef47c145c8fd5d5262d3904b1 is my payload.

Now I Want to add checksum, with sha256 twice, the result is

4550e2041dd936f17fd8a0d60f17c69faea8ef0e7d3ee82383153d93c2e837a8

where the first 4 bytes is checksum 4550e204

Now I can convert to base58

0050d512c984b1656ef47c145c8fd5d5262d3904b1**4550e204**

And I Get the right address.

I can read that

These four bytes serve as the error-checking code, or checksum. The checksum is concatenated (appended) to the end.

How Can I check if my checksum (4550e204) is correct before base58 ?

monkeyUser

Posted 2019-01-22T10:17:03.217

Reputation: 245

Sorry I don't understand your question. You have described the derivation for the checksum given version&payload. Given a base58 address, you decode the address for the version+payload+checksum. From that you can verify the version+payload. What other scenario do you mean?James C. 2019-01-22T12:33:25.467

Answers

0

One way to check is to use a tool like https://github.com/keis/base58 that implements base58check (-c) encoding and decoding (-d) with checksum verification to try to decode the final address:

$ printf "0050d512c984b1656ef47c145c8fd5d5262d3904b14550e204" | xxd -r -p | base58
18NQJwokxLGA7KsHJdQWh6ANB46K6nP7Hm
$ printf "18NQJwokxLGA7KsHJdQWh6ANB46K6nP7Hm" | base58 -c -d | xxd -p
0050d512c984b1656ef47c145c8fd5d5262d3904b1

Now, change the checksum and see if it is able to decode:

$ printf "0050d512c984b1656ef47c145c8fd5d5262d3904b14550e203" | xxd -r -p | base58
18NQJwokxLGA7KsHJdQWh6ANB46K6nP7Hk
Jordans-MacBook-Pro:~ Jbaczuk$ printf "18NQJwokxLGA7KsHJdQWh6ANB46K6nP7Hk" | base58 -c -d | xxd -p
Invalid checksum

JBaczuk

Posted 2019-01-22T10:17:03.217

Reputation: 6 172

thanks, for do checksum the operation is decode base58 -and reply printf 0050d512c984b1656ef47c145c8fd5d5262d3904b1 |xxd -r -p | sha256sum -b | xxd -r -p | sha256sum -b | head -c 8and Check the output with last 4 bytes ?monkeyUser 2019-01-22T15:46:56.320

1Yes, the first four bytes of the HASH256 is the checksum, which is appended to the end of the value to encode.JBaczuk 2019-01-22T15:50:55.093