1use crate::identity::identity_public_key::v0::IdentityPublicKeyV0;
2use crate::identity::{IdentityV0, KeyType, Purpose, SecurityLevel};
3use platform_value::platform_value;
4use platform_value::string_encoding::Encoding;
5use platform_value::BinaryData;
6use serde_json::json;
7
8use crate::prelude::{Identifier, Identity};
9
10use crate::version::PlatformVersion;
11use crate::ProtocolError;
12
13pub fn identity_fixture_raw_object() -> platform_value::Value {
17 platform_value!({
18 "id": Identifier::from([198, 23, 40, 120, 58, 93, 0, 165, 27, 49, 4, 117, 107, 204, 67, 46, 164, 216, 230, 135, 201, 92, 31, 155, 62, 131, 211, 177, 139, 175, 163, 237]),
19 "publicKeys": [
20 {
21 "id": 0u32,
22 "type": 0u8,
23 "purpose": 0u8,
24 "securityLevel": 0u8,
25 "data": BinaryData::from_string("AuryIuMtRrl/VviQuyLD1l4nmxi9ogPzC9LT7tdpo0di", Encoding::Base64).unwrap(),
26 "readOnly": false
27 },
28 {
29 "id": 1u32,
30 "type": 0u8,
31 "purpose": 1u8,
32 "securityLevel": 3u8,
33 "data": BinaryData::from_string("A8AK95PYMVX5VQKzOhcVQRCUbc9pyg3RiL7jttEMDU+L", Encoding::Base64).unwrap(),
34 "readOnly": false
35 }
36 ],
37 "balance": 10u64,
38 "revision": 0u64
39 })
40}
41
42pub fn identity_v0_fixture() -> Identity {
43 IdentityV0 {
44 id: Identifier::from([
45 198, 23, 40, 120, 58, 93, 0, 165, 27, 49, 4, 117, 107, 204, 67, 46, 164, 216, 230, 135,
46 201, 92, 31, 155, 62, 131, 211, 177, 139, 175, 163, 237,
47 ]),
48 public_keys: [
49 (
50 0,
51 IdentityPublicKeyV0 {
52 id: 0,
53 purpose: Purpose::AUTHENTICATION,
54 security_level: SecurityLevel::MASTER,
55 contract_bounds: None,
56 key_type: KeyType::ECDSA_SECP256K1,
57 read_only: false,
58 data: BinaryData::from_string(
59 "AuryIuMtRrl/VviQuyLD1l4nmxi9ogPzC9LT7tdpo0di",
60 Encoding::Base64,
61 )
62 .unwrap(),
63 disabled_at: None,
64 }
65 .into(),
66 ),
67 (
68 1,
69 IdentityPublicKeyV0 {
70 id: 0,
71 purpose: Purpose::ENCRYPTION,
72 security_level: SecurityLevel::MEDIUM,
73 contract_bounds: None,
74 key_type: KeyType::ECDSA_SECP256K1,
75 read_only: false,
76 data: BinaryData::from_string(
77 "A8AK95PYMVX5VQKzOhcVQRCUbc9pyg3RiL7jttEMDU+L",
78 Encoding::Base64,
79 )
80 .unwrap(),
81 disabled_at: None,
82 }
83 .into(),
84 ),
85 ]
86 .into(),
87 balance: 10,
88 revision: 0,
89 }
90 .into()
91}
92
93pub fn identity_fixture_json() -> serde_json::Value {
94 json!({
95 "id": "3bufpwQjL5qsvuP4fmCKgXJrKG852DDMYfi9J6XKqPAT",
96 "publicKeys": [
97 {
98 "id": 0,
99 "type": 0,
100 "purpose": 0,
101 "securityLevel": 0,
102 "data": "AuryIuMtRrl/VviQuyLD1l4nmxi9ogPzC9LT7tdpo0di",
103 "readOnly": false
104 },
105 {
106 "id": 1,
107 "type": 0,
108 "purpose": 1,
109 "securityLevel": 3,
110 "data": "A8AK95PYMVX5VQKzOhcVQRCUbc9pyg3RiL7jttEMDU+L",
111 "readOnly": false
112 }
113 ],
114 "balance": 10,
115 "revision": 0
116 })
117}
118
119pub fn get_identity_fixture(protocol_version: u32) -> Result<Identity, ProtocolError> {
120 let platform_version = PlatformVersion::get(protocol_version)?;
121 match platform_version
122 .dpp
123 .identity_versions
124 .identity_structure_version
125 {
126 0 => Ok(identity_v0_fixture()),
127 version => Err(ProtocolError::UnknownVersionMismatch {
128 method: "identity_fixture".to_string(),
129 known_versions: vec![0],
130 received: version,
131 }),
132 }
133}