dpp/identity/identity_public_key/conversion/json/
mod.rs

1mod v0;
2use crate::identity::identity_public_key::v0::IdentityPublicKeyV0;
3use crate::identity::IdentityPublicKey;
4use crate::version::PlatformVersion;
5use crate::ProtocolError;
6use serde_json::Value as JsonValue;
7pub use v0::IdentityPublicKeyJsonConversionMethodsV0;
8
9impl IdentityPublicKeyJsonConversionMethodsV0 for IdentityPublicKey {
10    fn to_json(&self) -> Result<JsonValue, ProtocolError> {
11        match self {
12            IdentityPublicKey::V0(key) => key.to_json(),
13        }
14    }
15
16    fn to_json_object(&self) -> Result<JsonValue, ProtocolError> {
17        match self {
18            IdentityPublicKey::V0(key) => key.to_json_object(),
19        }
20    }
21
22    fn from_json_object(
23        raw_object: JsonValue,
24        platform_version: &PlatformVersion,
25    ) -> Result<Self, ProtocolError>
26    where
27        Self: Sized,
28    {
29        match platform_version
30            .dpp
31            .identity_versions
32            .identity_key_structure_version
33        {
34            0 => {
35                IdentityPublicKeyV0::from_json_object(raw_object, platform_version).map(Into::into)
36            }
37            version => Err(ProtocolError::UnknownVersionMismatch {
38                method: "IdentityPublicKey::from_json_object".to_string(),
39                known_versions: vec![0],
40                received: version,
41            }),
42        }
43    }
44}