2017-11-27 16:24:10 +01:00
|
|
|
package base58
|
|
|
|
|
|
|
|
import "crypto/sha256"
|
|
|
|
|
2018-02-15 20:51:51 +01:00
|
|
|
const checksumLength = 4
|
2017-11-27 16:24:10 +01:00
|
|
|
|
|
|
|
func VerifyBase58Checksum(v []byte) bool {
|
2018-02-15 20:51:51 +01:00
|
|
|
checksum := [checksumLength]byte{}
|
2017-11-27 16:24:10 +01:00
|
|
|
for i := range checksum {
|
2018-02-15 20:51:51 +01:00
|
|
|
checksum[i] = v[len(v)-checksumLength+i]
|
2017-11-27 16:24:10 +01:00
|
|
|
}
|
2018-02-15 20:51:51 +01:00
|
|
|
real_checksum := sha256.Sum256(v[:len(v)-checksumLength])
|
2017-11-27 16:24:10 +01:00
|
|
|
real_checksum = sha256.Sum256(real_checksum[:])
|
|
|
|
for i, c := range checksum {
|
|
|
|
if c != real_checksum[i] {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true
|
|
|
|
}
|