rusnap_api/
entropy.rs

1use serde::{Deserialize, Serialize};
2
3use crate::Result;
4
5use super::request;
6
7#[derive(Debug, Serialize, Deserialize)]
8struct EntropyParams {
9    pub version: u64,
10
11    #[serde(skip_serializing_if = "Option::is_none")]
12    pub salt: Option<String>,
13}
14
15/// Create entropy v1 using salt
16pub async fn get_entropy_v1_salt<S>(salt: S) -> Result<Vec<u8>>
17where
18    S: Into<String>,
19{
20    let params = EntropyParams {
21        version: 1,
22        salt: Some(salt.into()),
23    };
24
25    let r: String = request("snap_getEntropy", params).await?;
26
27    Ok(const_hex::decode(r)?)
28}
29
30/// Create entropy v1
31pub async fn get_entropy_v1() -> Result<Vec<u8>> {
32    let params = EntropyParams {
33        version: 1,
34        salt: None,
35    };
36
37    let r: String = request("snap_getEntropy", params).await?;
38
39    Ok(const_hex::decode(r)?)
40}