multiversx_sdk/data/
keystore.rs

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
use serde::{Deserialize, Serialize};

pub const KDF_N: u32 = 4096;
pub const KDF_R: u32 = 8;
pub const KDF_P: u32 = 1;
pub const KDF_DKLEN: usize = 32;
pub const KEYSTORE_VERSION: u32 = 4;

#[derive(Debug)]
pub enum WalletError {
    InvalidPassword,
    InvalidKdf,
    InvalidCipher,
}

#[derive(Debug)]
pub enum InsertPassword {
    Plaintext(String),
    StandardInput,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct CryptoParams {
    pub iv: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct KdfParams {
    pub dklen: u32,
    pub salt: String,
    pub n: u32,
    pub r: u32,
    pub p: u32,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Crypto {
    pub ciphertext: String,
    pub cipherparams: CryptoParams,
    pub cipher: String,
    pub kdf: String,
    pub kdfparams: KdfParams,
    pub mac: String,
}

#[derive(Debug, Serialize, Deserialize)]
pub struct Keystore {
    pub version: u32,
    pub kind: String,
    pub id: String,
    pub address: String,
    pub bech32: String,
    pub crypto: Crypto,
}

#[derive(Clone, Debug)]
pub struct DecryptionParams {
    pub derived_key_first_half: Vec<u8>,
    pub iv: Vec<u8>,
    pub data: Vec<u8>,
}