Skip to main content

dpp/identity/identity_public_key/v0/
mod.rs

1mod accessors;
2mod conversion;
3pub(super) mod methods;
4#[cfg(feature = "random-public-keys")]
5mod random;
6
7pub use crate::identity::KeyType;
8pub use crate::identity::Purpose;
9pub use crate::identity::SecurityLevel;
10
11use bincode::{Decode, DecodeUntrusted, Encode};
12
13#[cfg(feature = "json-conversion")]
14use crate::serialization::json_safe_fields;
15use platform_value::BinaryData;
16use serde::{Deserialize, Serialize};
17
18use crate::identity::identity_public_key::contract_bounds::ContractBounds;
19use crate::identity::identity_public_key::key_type::KEY_TYPE_MAX_SIZE_TYPE;
20use crate::identity::Purpose::AUTHENTICATION;
21use crate::identity::SecurityLevel::MASTER;
22use crate::identity::{KeyID, TimestampMillis};
23#[cfg(feature = "state-transitions")]
24use crate::state_transition::public_key_in_creation::v0::IdentityPublicKeyInCreationV0;
25
26#[cfg_attr(feature = "json-conversion", json_safe_fields)]
27#[derive(
28    Default,
29    Debug,
30    Serialize,
31    Deserialize,
32    Encode,
33    Decode,
34    Clone,
35    PartialEq,
36    Eq,
37    Ord,
38    PartialOrd,
39    Hash,
40    DecodeUntrusted,
41)]
42#[serde(rename_all = "camelCase")]
43pub struct IdentityPublicKeyV0 {
44    pub id: KeyID,
45    pub purpose: Purpose,
46    pub security_level: SecurityLevel,
47    pub contract_bounds: Option<ContractBounds>,
48    #[serde(rename = "type")]
49    pub key_type: KeyType,
50    pub read_only: bool,
51    pub data: BinaryData,
52    // Phase D step 4: skip emitting `disabledAt: null` for non-disabled keys.
53    // Bincode (consensus binary path) is independent of this attribute and
54    // always writes the Option discriminant + payload. Identity hashing /
55    // Drive storage / state-transition signing all go through bincode, so
56    // none of those are affected. JSON / platform_value wire path becomes
57    // `{ ...fields }` instead of `{ ..., disabledAt: null }` for the
58    // common non-disabled case.
59    #[serde(default, skip_serializing_if = "Option::is_none")]
60    pub disabled_at: Option<TimestampMillis>,
61}
62
63impl IdentityPublicKeyV0 {
64    pub fn max_possible_size_key(id: KeyID) -> Self {
65        let key_type = *KEY_TYPE_MAX_SIZE_TYPE;
66        let purpose = AUTHENTICATION;
67        let security_level = MASTER;
68        let read_only = false;
69        let data = BinaryData::new(vec![255; key_type.default_size()]);
70
71        IdentityPublicKeyV0 {
72            id,
73            key_type,
74            purpose,
75            security_level,
76            read_only,
77            disabled_at: None,
78            data,
79            contract_bounds: None,
80        }
81    }
82}
83
84#[cfg(feature = "state-transitions")]
85impl Into<IdentityPublicKeyInCreationV0> for &IdentityPublicKeyV0 {
86    fn into(self) -> IdentityPublicKeyInCreationV0 {
87        IdentityPublicKeyInCreationV0 {
88            id: self.id,
89            purpose: self.purpose,
90            security_level: self.security_level,
91            key_type: self.key_type,
92            read_only: self.read_only,
93            data: self.data.clone(),
94            signature: BinaryData::default(),
95            contract_bounds: self.contract_bounds.clone(),
96        }
97    }
98}