Skip to content

Commit

Permalink
Calculate a valid pos reward account address
Browse files Browse the repository at this point in the history
  • Loading branch information
robvanmieghem committed Nov 18, 2021
1 parent 4e7f35c commit 785ecf4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
32 changes: 32 additions & 0 deletions research/pos/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}
4 changes: 3 additions & 1 deletion research/pos/pos.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,6 @@ Besides the fact that this is very clear, no private key that can leak or kept s
The Base58 alphabet consists of the following characters:
123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz

`NposRewardPoolAccount11....` should as such be possible, prefixed with the network type and the checksum at the end that should match according to the [SS58 format](https://docs.substrate.io/v3/advanced/ss58/).
`NposRewardAccount11....` should as such be possible, prefixed with the network type and the checksum at the end that should match according to the [SS58 format](https://docs.substrate.io/v3/advanced/ss58/).
The main.go program was used to decode the wanted adress, calculate the correct checksum and encode it again.
The result is the `5CNposRewardAccount11111111111111111111111111FSU` address

0 comments on commit 785ecf4

Please sign in to comment.