-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Calculate a valid pos reward account address
- Loading branch information
1 parent
4e7f35c
commit 785ecf4
Showing
2 changed files
with
35 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters