chainhash provides a generic hash type and associated functions that allows the specific hash algorithm to be abstracted.
Installation and Updating
$ go get -u github.com/btcsuite/btcd/chaincfg/chainhash
GPG Verification Key
All official release tags are signed by Conformal so users can ensure the code has not been tampered with and is coming from the btcsuite developers. To verify the signature perform the following:
Download the public key from the Conformal website at https://opensource.conformal.com/GIT-GPG-KEY-conformal.txt
Import the public key into your GPG keyring:
gpg --import GIT-GPG-KEY-conformal.txt
Verify the release tag with the following command where
TAG_NAMEis a placeholder for the specific tag:
git tag -v TAG_NAME
Package chainhash is licensed under the copyfree ISC License.
Package chainhash provides abstracted hash functionality.
This package provides a generic hash type and associated functions that allows the specific hash algorithm to be abstracted.
- func Decode(dst *Hash, src string) error
- func DoubleHashB(b byte) byte
- func HashB(b byte) byte
- type Hash
const HashSize = 32
HashSize of array used to store hashes. See Hash.
MaxHashStringSize is the maximum length of a Hash hash string.
var ( // TagBIP0340Challenge is the BIP-0340 tag for challenges. TagBIP0340Challenge = byte("BIP0340/challenge") // TagBIP0340Aux is the BIP-0340 tag for aux data. TagBIP0340Aux = byte("BIP0340/aux") // TagBIP0340Nonce is the BIP-0340 tag for nonces. TagBIP0340Nonce = byte("BIP0340/nonce") // TagTapSighash is the tag used by BIP 341 to generate the sighash // flags. TagTapSighash = byte("TapSighash") // TagTagTapLeaf is the message tag prefix used to compute the hash // digest of a tapscript leaf. TagTapLeaf = byte("TapLeaf") // TagTapBranch is the message tag prefix used to compute the // hash digest of two tap leaves into a taproot branch node. TagTapBranch = byte("TapBranch") // TagTapTweak is the message tag prefix used to compute the hash tweak // used to enable a public key to commit to the taproot branch root // for the witness program. TagTapTweak = byte("TapTweak") )
var ErrHashStrSize = fmt.Errorf("max hash string length is %v bytes", MaxHashStringSize)
ErrHashStrSize describes an error that indicates the caller specified a hash string that has too many characters.
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.
Hash is used in several of the bitcoin messages and common structures. It typically represents the double sha256 of data.
func DoubleHashH ¶
DoubleHashH calculates hash(hash(b)) and returns the resulting bytes as a Hash.
HashH calculates hash(b) and returns the resulting bytes as a Hash.
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 TaggedHash ¶
TaggedHash implements the tagged hash scheme described in BIP-340. We use sha-256 to bind a message hash to a specific context using a tag: sha256(sha256(tag) || sha256(tag) || msg).
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.
IsEqual returns true if target is the same as hash.
SetBytes sets the bytes which represent the hash. An error is returned if the number of bytes passed in is not HashSize.