-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.go
32 lines (28 loc) · 930 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package main
import (
"fmt"
"github.com/robvanmieghem/misc/bitcoin"
"golang.org/x/crypto/blake2b"
)
func main() {
wantedSS58Address := "5CNposRewardAccount11111111111111111111111111111"
decoded := bitcoin.DecodeBase58(wantedSS58Address)
fmt.Println("wanted SS58:", wantedSS58Address)
fmt.Printf("base58 decoded: %x\n", decoded)
//last2 bytes should be the checksum
checksumLength := 2
addressBytes := decoded[1 : len(decoded)-checksumLength]
fmt.Printf("Public key: %x\n", addressBytes)
checksumPrefix := []byte("SS58PRE")
addressFormat := append([]byte{decoded[0]}[:], addressBytes[:]...)
checksum, _ := blake2b.New(64, []byte{})
w := append(checksumPrefix[:], addressFormat[:]...)
_, err := checksum.Write(w)
if err != nil {
panic(err)
}
h := checksum.Sum(nil)
b := append(addressFormat[:], h[:checksumLength][:]...)
validAddress := bitcoin.EncodeBase58(b)
fmt.Println("Valid SS58:", validAddress)
}