diff --git a/research/pos/main.go b/research/pos/main.go new file mode 100644 index 000000000..75d34c57e --- /dev/null +++ b/research/pos/main.go @@ -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) +} diff --git a/research/pos/pos.md b/research/pos/pos.md index 8ebfc1292..4f693676a 100644 --- a/research/pos/pos.md +++ b/research/pos/pos.md @@ -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