Extract public key hashing into a separate function
This commit is contained in:
parent
e6eed1105f
commit
484d0bbae2
27
wallet.go
27
wallet.go
|
@ -31,17 +31,10 @@ type Wallets struct {
|
||||||
|
|
||||||
// GetAddress returns wallet address
|
// GetAddress returns wallet address
|
||||||
func (w Wallet) GetAddress() []byte {
|
func (w Wallet) GetAddress() []byte {
|
||||||
public := append(w.PublicKey.X.Bytes(), w.PublicKey.Y.Bytes()...)
|
pubKey := append(w.PublicKey.X.Bytes(), w.PublicKey.Y.Bytes()...)
|
||||||
publicSHA256 := sha256.Sum256(public)
|
pubKeyHash := HashPubKey(pubKey)
|
||||||
|
|
||||||
RIPEMD160Hasher := ripemd160.New()
|
versionedPayload := append([]byte{version}, pubKeyHash...)
|
||||||
_, err := RIPEMD160Hasher.Write(publicSHA256[:])
|
|
||||||
if err != nil {
|
|
||||||
log.Panic(err)
|
|
||||||
}
|
|
||||||
publicRIPEMD160 := RIPEMD160Hasher.Sum(nil)
|
|
||||||
|
|
||||||
versionedPayload := append([]byte{version}, publicRIPEMD160...)
|
|
||||||
checksum := checksum(versionedPayload)
|
checksum := checksum(versionedPayload)
|
||||||
|
|
||||||
fullPayload := append(versionedPayload, checksum...)
|
fullPayload := append(versionedPayload, checksum...)
|
||||||
|
@ -141,6 +134,20 @@ func NewWallets() (*Wallets, error) {
|
||||||
return &wallets, err
|
return &wallets, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// HashPubKey hashes public key
|
||||||
|
func HashPubKey(pubKey []byte) []byte {
|
||||||
|
publicSHA256 := sha256.Sum256(pubKey)
|
||||||
|
|
||||||
|
RIPEMD160Hasher := ripemd160.New()
|
||||||
|
_, err := RIPEMD160Hasher.Write(publicSHA256[:])
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
publicRIPEMD160 := RIPEMD160Hasher.Sum(nil)
|
||||||
|
|
||||||
|
return publicRIPEMD160
|
||||||
|
}
|
||||||
|
|
||||||
// Checksum generates a checksum for a public key
|
// Checksum generates a checksum for a public key
|
||||||
func checksum(payload []byte) []byte {
|
func checksum(payload []byte) []byte {
|
||||||
firstSHA := sha256.Sum256(payload)
|
firstSHA := sha256.Sum256(payload)
|
||||||
|
|
Loading…
Reference in New Issue