Documentation ¶
Overview ¶
Package daghash provides abstracted hash functionality.
This package provides a generic hash type and associated functions that allows the specific hash algorithm to be abstracted.
Index ¶
- Constants
- Variables
- func AreEqual(first []*Hash, second []*Hash) bool
- func Decode(dst *Hash, src string) error
- func DoubleHashB(b []byte) []byte
- func HashB(b []byte) []byte
- func HashToBig(hash *Hash) *big.Int
- func JoinHashesStrings(hashes []*Hash, separator string) string
- func Less(a *Hash, b *Hash) bool
- func LessTxID(a *TxID, b *TxID) bool
- func Sort(hashes []*Hash)
- func Strings(hashes []*Hash) []string
- type Hash
- type TxID
Constants ¶
const HashSize = 32
HashSize of array used to store hashes. See Hash.
const MaxHashStringSize = HashSize * 2
MaxHashStringSize is the maximum length of a Hash hash string.
const TxIDSize = HashSize
TxIDSize of array used to store TxID. See TxID.
Variables ¶
var ErrHashStrSize = errors.Errorf("max hash string length is %d bytes", MaxHashStringSize)
ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.
Functions ¶
func AreEqual ¶
AreEqual returns true if both slices contain the same hashes. Either slice must not contain duplicates.
func Decode ¶
Decode decodes the byte-reversed hexadecimal string encoding of a Hash to a destination.
func DoubleHashB ¶
DoubleHashB calculates hash(hash(b)) and returns the resulting bytes.
func HashToBig ¶
HashToBig converts a daghash.Hash into a big.Int that can be used to perform math comparisons.
func JoinHashesStrings ¶
JoinHashesStrings joins all the stringified hashes separated by a separator
Types ¶
type Hash ¶
Hash is used in several of the kaspa messages and common structures. It typically represents the double sha256 of data.
var ZeroHash Hash
ZeroHash is the Hash value of all zero bytes, defined here for convenience.
func DoubleHashH ¶
DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.
func DoubleHashP ¶
DoubleHashP calculates hash(hash(b)) and returns the resulting bytes as a pointer to Hash.
func NewHash ¶
NewHash returns a new Hash from a byte slice. An error is returned if the number of bytes passed in is not HashSize.
func NewHashFromStr ¶
NewHashFromStr creates a Hash from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.
func (*Hash) CloneBytes ¶
CloneBytes returns a copy of the bytes which represent the hash as a byte slice.
NOTE: It is generally cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.
func (*Hash) Cmp ¶
Cmp compares hash and target and returns:
-1 if hash < target 0 if hash == target +1 if hash > target
type TxID ¶
type TxID Hash
TxID is transaction hash not including payload and signature.
var ZeroTxID TxID
ZeroTxID is the Hash value of all zero bytes, defined here for convenience.
func NewTxID ¶
NewTxID returns a new TxID from a byte slice. An error is returned if the number of bytes passed in is not HashSize.
func NewTxIDFromStr ¶
NewTxIDFromStr creates a TxID from a hash string. The string should be the hexadecimal string of a byte-reversed hash, but any missing characters result in zero padding at the end of the Hash.
func (*TxID) CloneBytes ¶
CloneBytes returns a copy of the bytes which represent the TxID as a byte slice.
NOTE: It is generally cheaper to just slice the hash directly thereby reusing the same bytes rather than calling this method.