Documentation
¶
Index ¶
- func CalculateTarget(difficulty uint64, hashSize int) []byte
- func CompareHash(a, b []byte) bool
- func CountLeadingZeros(hash []byte) int
- func DoubleHash(algorithm Algorithm, data []byte) ([]byte, error)
- func GetDifficultyFromHash(hash []byte) uint64
- func HashToHex(hash []byte) string
- func HashWithSHA256(data []byte) []byte
- func HashWithSHA512(data []byte) []byte
- func HexToHash(hex string) ([]byte, error)
- func IsValidHash(hashValue, target []byte) bool
- func MeetsTargetDifficulty(hash []byte, difficulty uint64) bool
- func NewHasher(algorithm Algorithm) (interfaces.Hasher, error)
- func QuickHash(algorithm Algorithm, data []byte) ([]byte, error)
- type Algorithm
- type Factory
- func (f *Factory) CreateBlake2b() (interfaces.Hasher, error)
- func (f *Factory) CreateHasher(algorithm Algorithm) (interfaces.Hasher, error)
- func (f *Factory) CreateKeccak256() (interfaces.Hasher, error)
- func (f *Factory) CreateSHA3() (interfaces.Hasher, error)
- func (f *Factory) CreateSHA256() (interfaces.Hasher, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CalculateTarget ¶
CalculateTarget calculates the target hash value from a difficulty Higher difficulty means lower target value
func CompareHash ¶
CompareHash compares two hashes and returns true if they are equal
func CountLeadingZeros ¶
CountLeadingZeros counts the number of leading zero bits in a hash
func DoubleHash ¶
DoubleHash performs a double hash (hash of hash) - useful for some consensus algorithms
func GetDifficultyFromHash ¶
GetDifficultyFromHash calculates the effective difficulty of a hash based on the number of leading zero bits
func HashWithSHA256 ¶
HashWithSHA256 is a convenience function for SHA-256 hashing
func HashWithSHA512 ¶
HashWithSHA512 is a convenience function for SHA-512 hashing
func IsValidHash ¶
IsValidHash checks if a hash meets a specific difficulty target The hash must be less than or equal to the target
func MeetsTargetDifficulty ¶
MeetsTargetDifficulty checks if a hash meets the required difficulty
Types ¶
type Algorithm ¶
type Algorithm string
Algorithm represents a hash algorithm type
const ( // AlgorithmSHA256 represents the SHA-256 hash algorithm AlgorithmSHA256 Algorithm = "SHA256" // AlgorithmSHA512 represents the SHA-512 hash algorithm AlgorithmSHA512 Algorithm = "SHA512" // AlgorithmSHA3_256 represents the SHA3-256 hash algorithm AlgorithmSHA3_256 Algorithm = "SHA3-256" // AlgorithmSHA3_512 represents the SHA3-512 hash algorithm AlgorithmSHA3_512 Algorithm = "SHA3-512" // AlgorithmBlake2b256 represents the Blake2b-256 hash algorithm AlgorithmBlake2b256 Algorithm = "BLAKE2b-256" // AlgorithmBlake2b512 represents the Blake2b-512 hash algorithm AlgorithmBlake2b512 Algorithm = "BLAKE2b-512" // AlgorithmBlake2s256 represents the Blake2s-256 hash algorithm AlgorithmBlake2s256 Algorithm = "BLAKE2s-256" // AlgorithmKeccak256 represents the Keccak-256 hash algorithm (Ethereum style) AlgorithmKeccak256 Algorithm = "Keccak256" )
type Factory ¶
type Factory struct{}
Factory provides a hasher factory pattern
func (*Factory) CreateBlake2b ¶
func (f *Factory) CreateBlake2b() (interfaces.Hasher, error)
CreateBlake2b creates a Blake2b-256 hasher
func (*Factory) CreateHasher ¶
func (f *Factory) CreateHasher(algorithm Algorithm) (interfaces.Hasher, error)
CreateHasher creates a hasher for the specified algorithm
func (*Factory) CreateKeccak256 ¶
func (f *Factory) CreateKeccak256() (interfaces.Hasher, error)
CreateKeccak256 creates a Keccak-256 hasher
func (*Factory) CreateSHA3 ¶
func (f *Factory) CreateSHA3() (interfaces.Hasher, error)
CreateSHA3 creates a SHA3-256 hasher
func (*Factory) CreateSHA256 ¶
func (f *Factory) CreateSHA256() (interfaces.Hasher, error)
CreateSHA256 creates a SHA-256 hasher