1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
use crate::{
api::CryptoApi,
types::{BoxedBytes, MessageHashType, H256},
};
use alloc::boxed::Box;
pub struct CryptoWrapper<A>
where
A: CryptoApi,
{
pub(crate) api: A,
}
impl<A> CryptoWrapper<A>
where
A: CryptoApi,
{
pub(crate) fn new(api: A) -> Self {
CryptoWrapper { api }
}
pub fn sha256(&self, data: &[u8]) -> H256 {
self.api.sha256(data)
}
pub fn keccak256(&self, data: &[u8]) -> H256 {
self.api.keccak256(data)
}
pub fn ripemd160(&self, data: &[u8]) -> Box<[u8; 20]> {
self.api.ripemd160(data)
}
pub fn verify_bls(&self, key: &[u8], message: &[u8], signature: &[u8]) -> bool {
self.api.verify_bls(key, message, signature)
}
pub fn verify_ed25519(&self, key: &[u8], message: &[u8], signature: &[u8]) -> bool {
self.api.verify_ed25519(key, message, signature)
}
pub fn verify_secp256k1(&self, key: &[u8], message: &[u8], signature: &[u8]) -> bool {
self.api.verify_secp256k1(key, message, signature)
}
pub fn verify_custom_secp256k1(
&self,
key: &[u8],
message: &[u8],
signature: &[u8],
hash_type: MessageHashType,
) -> bool {
self.api
.verify_custom_secp256k1(key, message, signature, hash_type)
}
pub fn encode_secp256k1_der_signature(&self, r: &[u8], s: &[u8]) -> BoxedBytes {
self.api.encode_secp256k1_der_signature(r, s)
}
}