multiversx_sc/types/crypto/
message_hash_type.rs

1use crate::{
2    abi::{TypeAbi, TypeAbiFrom, TypeName},
3    codec::{
4        self,
5        derive::{NestedDecode, NestedEncode, TopDecode, TopEncode},
6    },
7};
8
9/// Message hash type for the `verifyCustomSecp256k1` CryptoApi function
10#[derive(TopDecode, TopEncode, NestedDecode, NestedEncode, Clone, PartialEq, Eq, Debug)]
11pub enum MessageHashType {
12    ECDSAPlainMsg,
13    ECDSASha256,
14    ECDSADoubleSha256,
15    ECDSAKeccak256,
16    ECDSARipemd160,
17}
18
19impl MessageHashType {
20    pub fn as_u8(&self) -> u8 {
21        match self {
22            Self::ECDSAPlainMsg => 0,
23            Self::ECDSASha256 => 1,
24            Self::ECDSADoubleSha256 => 2,
25            Self::ECDSAKeccak256 => 3,
26            Self::ECDSARipemd160 => 4,
27        }
28    }
29}
30
31impl From<u8> for MessageHashType {
32    fn from(value: u8) -> Self {
33        match value {
34            1 => Self::ECDSASha256,
35            2 => Self::ECDSADoubleSha256,
36            3 => Self::ECDSAKeccak256,
37            4 => Self::ECDSARipemd160,
38            _ => Self::ECDSAPlainMsg,
39        }
40    }
41}
42
43impl TypeAbiFrom<Self> for MessageHashType {}
44
45impl TypeAbi for MessageHashType {
46    type Unmanaged = Self;
47
48    fn type_name() -> TypeName {
49        "MessageHashType".into()
50    }
51}