Skip to content
Snippets Groups Projects

modify rfc0016

Open matograine requested to merge 0016_checksum into master
1 file
+ 38
7
Compare changes
  • Side-by-side
  • Inline
+ 38
7
@@ -39,6 +39,8 @@ When converting a public key to its binary representation, the length of the byt
- If there is one leading non-zero byte and length is superior to 32, then the public key is not valid.
```python
# you should install module base58
import base58
# convert public key string to bytes
pubkey_byte = bytearray(base58.b58decode(pubkey))
@@ -105,13 +107,42 @@ To compute the checksum:
0) use the binary representation of the public key :
for simplification we use a pubkey that is 32 bits long once decoded.
`pubkey = bytearray(base58.b58decode("J4c8CARmP9vAFNGtHRuzx14zvxojyRWHW2darguVqjtX"))`
`pubkey = bytearray(base58.b58decode("J66fMDgSVVcdRgKucj1D5ssXAcQvg35JopvHNQo6cGY6"))`
1) `sha256(pubkey)`
`0x47c7aee49dfb9bea99949d04623281d8ad6188be8f6a698b0eb5994fa44d0a67`
1) Hash the public key with sha256
`sha256(pubkey)`
`0x0daeb23dfe219d49d45af2367a56d3ef1086bbf2b2c128bc64625a4cef90c731`
2) Encode the hash as base58
`Base58.encode(sha256(pubkey))`
`vQoY2iTFrYyBqSDAiWz9f9rRgNQm7FTsHTNpwqdEbct`
2b) IF the public key is less than 44 char long, add leading "1" until it is 44 chars long.
This aims at making checksums coherent among base58 implementations.
`1vQoY2iTFrYyBqSDAiWz9f9rRgNQm7FTsHTNpwqdEbct`
3) We only take the 3 first characters of this value to get the checksum
`1vQ`
## Test pubkeys
Public keys associated to their correct checksum :
[
["J4c8CARmP9vAFNGtHRuzx14zvxojyRWHW2darguVqjtX" , "5qC"],
["12BjyvjoAf5qik7R8TKDJAHJugsX23YgJGi2LmBUv2nx" , "8BD"],
["2BjyvjoAf5qik7R8TKDJAHJugsX23YgJGi2LmBUv2nx" , "8BD"],
# rare cases with numerous leading 1.
["111111111111111111111111111111111pubKey49311" , "C7L"],
["11111111111111111111111111111111pubKey49311" , "C7L"],
# public key whose checksum may be wrong by beginning with 1
["23iex3vD7sp9AK7wakwW1rj4F7RwYfQoXXR87Zttdte8", "14j"],
["J66fMDgSVVcdRgKucj1D5ssXAcQvg35JopvHNQo6cGY6", "1vQ"],
# invalid public keys represented in 44 base58 chars. Should raise an error.
["Z1111111111111111111111111111111111111111111" , None],
["K1111111111111111111111111111111111111111111" , None],
# Should not raise an error.
["J1111111111111111111111111111111111111111111" , "FqK"],
]
2) `Base58.encode(sha256(pubkey))`
`5qCYkJMWgNA54gZz4HMQLbxL5btDmTS3EuHHCTcJaqGi`
3) We only take the 3 first characters of this value to get the checksum
`5qC`
Loading