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