Skip to main content

dpp/identity/identity_public_key/v0/
mod.rs

1mod accessors;
2mod conversion;
3mod 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, 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)]
41#[serde(rename_all = "camelCase")]
42pub struct IdentityPublicKeyV0 {
43    pub id: KeyID,
44    pub purpose: Purpose,
45    pub security_level: SecurityLevel,
46    pub contract_bounds: Option<ContractBounds>,
47    #[serde(rename = "type")]
48    pub key_type: KeyType,
49    pub read_only: bool,
50    pub data: BinaryData,
51    // Phase D step 4: skip emitting `disabledAt: null` for non-disabled keys.
52    // Bincode (consensus binary path) is independent of this attribute and
53    // always writes the Option discriminant + payload. Identity hashing /
54    // Drive storage / state-transition signing all go through bincode, so
55    // none of those are affected. JSON / platform_value wire path becomes
56    // `{ ...fields }` instead of `{ ..., disabledAt: null }` for the
57    // common non-disabled case.
58    #[serde(default, skip_serializing_if = "Option::is_none")]
59    pub disabled_at: Option<TimestampMillis>,
60}
61
62impl IdentityPublicKeyV0 {
63    pub fn max_possible_size_key(id: KeyID) -> Self {
64        let key_type = *KEY_TYPE_MAX_SIZE_TYPE;
65        let purpose = AUTHENTICATION;
66        let security_level = MASTER;
67        let read_only = false;
68        let data = BinaryData::new(vec![255; key_type.default_size()]);
69
70        IdentityPublicKeyV0 {
71            id,
72            key_type,
73            purpose,
74            security_level,
75            read_only,
76            disabled_at: None,
77            data,
78            contract_bounds: None,
79        }
80    }
81}
82
83#[cfg(feature = "state-transitions")]
84impl Into<IdentityPublicKeyInCreationV0> for &IdentityPublicKeyV0 {
85    fn into(self) -> IdentityPublicKeyInCreationV0 {
86        IdentityPublicKeyInCreationV0 {
87            id: self.id,
88            purpose: self.purpose,
89            security_level: self.security_level,
90            key_type: self.key_type,
91            read_only: self.read_only,
92            data: self.data.clone(),
93            signature: BinaryData::default(),
94            contract_bounds: self.contract_bounds.clone(),
95        }
96    }
97}