pythnet_sdk/hashers.rs
1use {
2 borsh::{BorshDeserialize, BorshSerialize},
3 serde::{Deserialize, Serialize},
4 std::fmt::Debug,
5};
6
7pub mod keccak256;
8pub mod keccak256_160;
9pub mod prime;
10
11/// We provide `Hasher` as a small hashing abstraction.
12///
13/// This trait allows us to use a more abstract idea of hashing than the `Digest` trait from the
14/// `digest` create provides. In particular, if we want to use none cryptographic hashes or hashes
15/// that fit the mathematical definition of a hash, we can do this with this far more general
16/// abstraction.
17pub trait Hasher
18where
19 Self: Clone,
20 Self: Debug,
21 Self: Default,
22{
23 type Hash: Copy
24 + AsRef<[u8]>
25 + BorshSerialize
26 + BorshDeserialize
27 + Debug
28 + Default
29 + Eq
30 + std::hash::Hash
31 + PartialOrd
32 + PartialEq
33 + Serialize
34 + for<'a> Deserialize<'a>;
35
36 fn hashv(data: &[impl AsRef<[u8]>]) -> Self::Hash;
37}