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
use crate::error::{Error, Result};
use sodiumoxide::crypto::hash::sha256;
use sodiumoxide::randombytes;
mod keypair;
mod strkey;
pub use self::keypair::{KeyPair, MuxedAccount, MuxedEd25519PublicKey, PublicKey, SecretKey};
pub use self::strkey::*;
pub fn hash(m: &[u8]) -> Vec<u8> {
let digest = sha256::hash(&m);
digest.0.to_vec()
}
pub fn random_bytes(size: usize) -> Vec<u8> {
randombytes::randombytes(size)
}
pub fn init() -> Result<()> {
sodiumoxide::init().map_err(|_| Error::SodiumInitFailed)
}