Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
RFCs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
documents
RFCs
Merge requests
!15
modify rfc0016
Code
Review changes
Check out branch
Download
Patches
Plain diff
Expand sidebar
Open
modify rfc0016
0016_checksum
into
master
Overview
0
Commits
1
Changes
1
Open
matograine
requested to merge
0016_checksum
into
master
3 years ago
Overview
0
Commits
1
Changes
1
[CHECKSUM] modify RFC0016:
check that checksums do not begin with leading 1
add test pubkeys
0
0
Merge request reports
Compare
master
version 1
9a249758
3 years ago
master (HEAD)
and
latest version
latest version
b278a6ff
1 commit,
3 years ago
version 1
9a249758
1 commit,
3 years ago
1 file
+
38
−
7
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
rfc/0016_public_key_checksum.md
+
38
−
7
View file @ 353a7008
Edit in single-file editor
Open in Web IDE
Show full file
@@ -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("J
4c8CARmP9vAFNGtHRuzx14zvxojyRWHW2darguVqjtX
"))`
`pubkey = bytearray(base58.b58decode("J
66fMDgSVVcdRgKucj1D5ssXAcQvg35JopvHNQo6cGY6
"))`
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