pub trait Hash: Copy + Clone + PartialEq<Self> + Eq + PartialOrd<Self> + Ord + Hash + Debug + Display + LowerHex + Index<RangeFull, Output = [u8], Output = [u8], Output = [u8], Output = [u8], Output = u8> + Index<RangeFrom<usize>> + Index<RangeTo<usize>> + Index<Range<usize>> + Index<usize> + Borrow<[u8]> {
    type Engine: HashEngine;
    type Bytes: FromHex + Copy;

    const LEN: usize;
    const DISPLAY_BACKWARD: bool = false;

    // Required methods
    fn from_engine(e: Self::Engine) -> Self;
    fn from_slice(sl: &[u8]) -> Result<Self, Error>;
    fn to_byte_array(self) -> Self::Bytes;
    fn as_byte_array(&self) -> &Self::Bytes;
    fn from_byte_array(bytes: Self::Bytes) -> Self;
    fn all_zeros() -> Self;

    // Provided methods
    fn engine() -> Self::Engine { ... }
    fn hash(data: &[u8]) -> Self { ... }
}
Expand description

Trait which applies to hashes of all types.

Required Associated Types§

type Engine: HashEngine

A hashing engine which bytes can be serialized into. It is expected to implement the io::Write trait, and to never return errors under any conditions.

type Bytes: FromHex + Copy

The byte array that represents the hash internally.

Required Associated Constants§

const LEN: usize

Length of the hash, in bytes.

Provided Associated Constants§

const DISPLAY_BACKWARD: bool = false

Flag indicating whether user-visible serializations of this hash should be backward. For some reason Satoshi decided this should be true for Sha256dHash, so here we are.

Required Methods§

fn from_engine(e: Self::Engine) -> Self

Produces a hash from the current state of a given engine.

fn from_slice(sl: &[u8]) -> Result<Self, Error>

Copies a byte slice into a hash object.

fn to_byte_array(self) -> Self::Bytes

Returns the underlying byte array.

fn as_byte_array(&self) -> &Self::Bytes

Returns a reference to the underlying byte array.

fn from_byte_array(bytes: Self::Bytes) -> Self

Constructs a hash from the underlying byte array.

fn all_zeros() -> Self

Returns an all zero hash.

An all zeros hash is a made up construct because there is not a known input that can create it, however it is used in various places in Bitcoin e.g., the Bitcoin genesis block’s previous blockhash and the coinbase transaction’s outpoint txid.

Provided Methods§

fn engine() -> Self::Engine

Constructs a new engine.

fn hash(data: &[u8]) -> Self

Hashes some bytes.

Implementations on Foreign Types§

§

impl Hash for TapSighash

§

type Engine = <Hash<TapSighashTag> as Hash>::Engine

§

type Bytes = <Hash<TapSighashTag> as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

fn engine() -> <TapSighash as Hash>::Engine

§

fn from_engine(e: <TapSighash as Hash>::Engine) -> TapSighash

§

fn from_slice(sl: &[u8]) -> Result<TapSighash, Error>

§

fn from_byte_array(bytes: <TapSighash as Hash>::Bytes) -> TapSighash

§

fn to_byte_array(self) -> <TapSighash as Hash>::Bytes

§

fn as_byte_array(&self) -> &<TapSighash as Hash>::Bytes

§

fn all_zeros() -> TapSighash

§

impl Hash for TapLeafHash

§

type Engine = <Hash<TapLeafTag> as Hash>::Engine

§

type Bytes = <Hash<TapLeafTag> as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

fn engine() -> <TapLeafHash as Hash>::Engine

§

fn from_engine(e: <TapLeafHash as Hash>::Engine) -> TapLeafHash

§

fn from_slice(sl: &[u8]) -> Result<TapLeafHash, Error>

§

fn from_byte_array(bytes: <TapLeafHash as Hash>::Bytes) -> TapLeafHash

§

fn to_byte_array(self) -> <TapLeafHash as Hash>::Bytes

§

fn as_byte_array(&self) -> &<TapLeafHash as Hash>::Bytes

§

fn all_zeros() -> TapLeafHash

§

impl Hash for WitnessCommitment

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

fn engine() -> <WitnessCommitment as Hash>::Engine

§

fn from_engine(e: <WitnessCommitment as Hash>::Engine) -> WitnessCommitment

§

fn from_slice(sl: &[u8]) -> Result<WitnessCommitment, Error>

§

fn from_byte_array( bytes: <WitnessCommitment as Hash>::Bytes ) -> WitnessCommitment

§

fn to_byte_array(self) -> <WitnessCommitment as Hash>::Bytes

§

fn as_byte_array(&self) -> &<WitnessCommitment as Hash>::Bytes

§

fn all_zeros() -> WitnessCommitment

§

impl Hash for XpubIdentifier

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

fn engine() -> <XpubIdentifier as Hash>::Engine

§

fn from_engine(e: <XpubIdentifier as Hash>::Engine) -> XpubIdentifier

§

fn from_slice(sl: &[u8]) -> Result<XpubIdentifier, Error>

§

fn from_byte_array(bytes: <XpubIdentifier as Hash>::Bytes) -> XpubIdentifier

§

fn to_byte_array(self) -> <XpubIdentifier as Hash>::Bytes

§

fn as_byte_array(&self) -> &<XpubIdentifier as Hash>::Bytes

§

fn all_zeros() -> XpubIdentifier

§

impl Hash for FilterHeader

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

fn engine() -> <FilterHeader as Hash>::Engine

§

fn from_engine(e: <FilterHeader as Hash>::Engine) -> FilterHeader

§

fn from_slice(sl: &[u8]) -> Result<FilterHeader, Error>

§

fn from_byte_array(bytes: <FilterHeader as Hash>::Bytes) -> FilterHeader

§

fn to_byte_array(self) -> <FilterHeader as Hash>::Bytes

§

fn as_byte_array(&self) -> &<FilterHeader as Hash>::Bytes

§

fn all_zeros() -> FilterHeader

§

impl Hash for WitnessMerkleNode

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

fn engine() -> <WitnessMerkleNode as Hash>::Engine

§

fn from_engine(e: <WitnessMerkleNode as Hash>::Engine) -> WitnessMerkleNode

§

fn from_slice(sl: &[u8]) -> Result<WitnessMerkleNode, Error>

§

fn from_byte_array( bytes: <WitnessMerkleNode as Hash>::Bytes ) -> WitnessMerkleNode

§

fn to_byte_array(self) -> <WitnessMerkleNode as Hash>::Bytes

§

fn as_byte_array(&self) -> &<WitnessMerkleNode as Hash>::Bytes

§

fn all_zeros() -> WitnessMerkleNode

§

impl Hash for Wtxid

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

fn engine() -> <Wtxid as Hash>::Engine

§

fn from_engine(e: <Wtxid as Hash>::Engine) -> Wtxid

§

fn from_slice(sl: &[u8]) -> Result<Wtxid, Error>

§

fn from_byte_array(bytes: <Wtxid as Hash>::Bytes) -> Wtxid

§

fn to_byte_array(self) -> <Wtxid as Hash>::Bytes

§

fn as_byte_array(&self) -> &<Wtxid as Hash>::Bytes

§

fn all_zeros() -> Wtxid

§

impl Hash for TapNodeHash

§

type Engine = <Hash<TapBranchTag> as Hash>::Engine

§

type Bytes = <Hash<TapBranchTag> as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

fn engine() -> <TapNodeHash as Hash>::Engine

§

fn from_engine(e: <TapNodeHash as Hash>::Engine) -> TapNodeHash

§

fn from_slice(sl: &[u8]) -> Result<TapNodeHash, Error>

§

fn from_byte_array(bytes: <TapNodeHash as Hash>::Bytes) -> TapNodeHash

§

fn to_byte_array(self) -> <TapNodeHash as Hash>::Bytes

§

fn as_byte_array(&self) -> &<TapNodeHash as Hash>::Bytes

§

fn all_zeros() -> TapNodeHash

§

impl Hash for FilterHash

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

fn engine() -> <FilterHash as Hash>::Engine

§

fn from_engine(e: <FilterHash as Hash>::Engine) -> FilterHash

§

fn from_slice(sl: &[u8]) -> Result<FilterHash, Error>

§

fn from_byte_array(bytes: <FilterHash as Hash>::Bytes) -> FilterHash

§

fn to_byte_array(self) -> <FilterHash as Hash>::Bytes

§

fn as_byte_array(&self) -> &<FilterHash as Hash>::Bytes

§

fn all_zeros() -> FilterHash

§

impl Hash for SegwitV0Sighash

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

fn engine() -> <SegwitV0Sighash as Hash>::Engine

§

fn from_engine(e: <SegwitV0Sighash as Hash>::Engine) -> SegwitV0Sighash

§

fn from_slice(sl: &[u8]) -> Result<SegwitV0Sighash, Error>

§

fn from_byte_array(bytes: <SegwitV0Sighash as Hash>::Bytes) -> SegwitV0Sighash

§

fn to_byte_array(self) -> <SegwitV0Sighash as Hash>::Bytes

§

fn as_byte_array(&self) -> &<SegwitV0Sighash as Hash>::Bytes

§

fn all_zeros() -> SegwitV0Sighash

§

impl Hash for TapTweakHash

§

type Engine = <Hash<TapTweakTag> as Hash>::Engine

§

type Bytes = <Hash<TapTweakTag> as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

fn engine() -> <TapTweakHash as Hash>::Engine

§

fn from_engine(e: <TapTweakHash as Hash>::Engine) -> TapTweakHash

§

fn from_slice(sl: &[u8]) -> Result<TapTweakHash, Error>

§

fn from_byte_array(bytes: <TapTweakHash as Hash>::Bytes) -> TapTweakHash

§

fn to_byte_array(self) -> <TapTweakHash as Hash>::Bytes

§

fn as_byte_array(&self) -> &<TapTweakHash as Hash>::Bytes

§

fn all_zeros() -> TapTweakHash

§

impl Hash for LegacySighash

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

fn engine() -> <LegacySighash as Hash>::Engine

§

fn from_engine(e: <LegacySighash as Hash>::Engine) -> LegacySighash

§

fn from_slice(sl: &[u8]) -> Result<LegacySighash, Error>

§

fn from_byte_array(bytes: <LegacySighash as Hash>::Bytes) -> LegacySighash

§

fn to_byte_array(self) -> <LegacySighash as Hash>::Bytes

§

fn as_byte_array(&self) -> &<LegacySighash as Hash>::Bytes

§

fn all_zeros() -> LegacySighash

Implementors§

§

impl Hash for BlockHash

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

impl Hash for PubkeyHash

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for ScriptHash

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for TxMerkleNode

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

impl Hash for Txid

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

impl Hash for WPubkeyHash

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for WScriptHash

§

type Engine = <Hash as Hash>::Engine

§

type Bytes = <Hash as Hash>::Bytes

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for bitcoin::key::secp256k1::hashes::hash160::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for bitcoin::key::secp256k1::hashes::ripemd160::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for bitcoin::key::secp256k1::hashes::sha1::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 20]

§

const LEN: usize = 20usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for bitcoin::key::secp256k1::hashes::sha256::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for bitcoin::key::secp256k1::hashes::sha256d::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

impl Hash for bitcoin::key::secp256k1::hashes::sha512::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 64]

§

const LEN: usize = 64usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for bitcoin::key::secp256k1::hashes::sha512_256::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = false

§

impl Hash for bitcoin::key::secp256k1::hashes::siphash24::Hash

§

type Engine = HashEngine

§

type Bytes = [u8; 8]

§

const LEN: usize = 8usize

§

const DISPLAY_BACKWARD: bool = false

§

impl<T> Hash for bitcoin::key::secp256k1::hashes::sha256t::Hash<T>where T: Tag,

§

type Engine = HashEngine

§

type Bytes = [u8; 32]

§

const LEN: usize = 32usize

§

const DISPLAY_BACKWARD: bool = true

§

impl<T> Hash for Hmac<T>where T: Hash,

§

type Engine = HmacEngine<T>

§

type Bytes = <T as Hash>::Bytes

§

const LEN: usize = T::LEN