Refactoring code. Use protocol.HashData and HashSize. Move PublicKey2NodeID into protocol.

This commit is contained in:
Kleissner
2021-10-17 17:15:22 +02:00
parent 39217ab5ef
commit 7be31a9e34
9 changed files with 37 additions and 58 deletions

View File

@@ -6,7 +6,10 @@ Author: Peter Kleissner
package protocol
import "lukechampine.com/blake3"
import (
"github.com/btcsuite/btcd/btcec"
"lukechampine.com/blake3"
)
// HashData abstracts the hash function.
func HashData(data []byte) (hash []byte) {
@@ -16,3 +19,9 @@ func HashData(data []byte) (hash []byte) {
// HashSize is blake3 hash digest size = 256 bits
const HashSize = 32
// PublicKey2NodeID translates the Public Key into the node ID used in the Kademlia network.
// It is also referenced in various other places including blockchain data at runtime. The node ID identifies the owner.
func PublicKey2NodeID(publicKey *btcec.PublicKey) (nodeID []byte) {
return HashData(publicKey.SerializeCompressed())
}