pshenmic-dpp 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (36) hide show
  1. package/Cargo.lock +41 -13
  2. package/Cargo.toml +28 -10
  3. package/README.md +2 -0
  4. package/dist/wasm/pshenmic_dpp.js +1287 -289
  5. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  6. package/package.json +3 -2
  7. package/packages/{cbor-conversation → cbor_conversation}/Cargo.toml +0 -4
  8. package/packages/data_contract/Cargo.toml +17 -0
  9. package/packages/data_contract/src/lib.rs +162 -0
  10. package/packages/data_contract_transitions/Cargo.toml +14 -0
  11. package/packages/data_contract_transitions/src/create/mod.rs +154 -0
  12. package/packages/data_contract_transitions/src/lib.rs +2 -0
  13. package/packages/data_contract_transitions/src/update/mod.rs +135 -0
  14. package/packages/document/Cargo.toml +4 -6
  15. package/packages/document/src/lib.rs +44 -1
  16. package/packages/document/src/methods/js.rs +64 -8
  17. package/packages/document_batch/Cargo.toml +1 -8
  18. package/packages/document_batch/src/lib.rs +5 -4
  19. package/packages/enums/Cargo.toml +1 -5
  20. package/packages/enums/src/lib.rs +1 -0
  21. package/packages/enums/src/platform/mod.rs +38 -0
  22. package/packages/identity/Cargo.toml +4 -5
  23. package/packages/identity/src/lib.rs +23 -3
  24. package/packages/identity_transitions/Cargo.toml +1 -5
  25. package/packages/identity_transitions/src/create_transition/mod.rs +6 -6
  26. package/packages/mock_bls/Cargo.toml +1 -5
  27. package/packages/private_key/Cargo.toml +1 -5
  28. package/packages/private_key/src/lib.rs +1 -1
  29. package/packages/public_key/Cargo.toml +1 -5
  30. package/packages/public_key/src/lib.rs +5 -7
  31. package/packages/state_transition/Cargo.toml +1 -5
  32. package/packages/state_transition/src/lib.rs +11 -9
  33. package/packages/utils/Cargo.toml +1 -5
  34. package/scripts/build-js.sh +3 -2
  35. package/src/lib.rs +7 -1
  36. /package/packages/{cbor-conversation → cbor_conversation}/src/lib.rs +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pshenmic-dpp",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/wasm/pshenmic_dpp.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -20,5 +20,6 @@
20
20
  "babel": "^6.23.0",
21
21
  "babel-cli": "^6.26.0",
22
22
  "typescript": "^5.8.2"
23
- }
23
+ },
24
+ "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
24
25
  }
@@ -15,7 +15,3 @@ pshenmic_dpp_utils = {path = "../utils"}
15
15
  base64 = "0.22.1"
16
16
  ciborium = "0.2.2"
17
17
  serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
18
-
19
- [profile.release]
20
- lto = true
21
- opt-level = 'z'
@@ -0,0 +1,17 @@
1
+ [package]
2
+ name = "pshenmic_dpp_data_contract"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [lib]
7
+ crate-type = ["cdylib", "lib"]
8
+
9
+ [dependencies]
10
+ wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
+ pshenmic_dpp_utils = {path = "../utils"}
12
+ pshenmic_dpp_enums = {path = "../enums"}
13
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
14
+ "data-contract-json-conversion",
15
+ "platform-value"
16
+ ]}
17
+ serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
@@ -0,0 +1,162 @@
1
+ use dpp::dashcore::hashes::serde::Serialize;
2
+ use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters};
3
+ use dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0;
4
+ use dpp::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0;
5
+ use dpp::data_contract::document_type::DocumentTypeRef;
6
+ use dpp::data_contract::errors::DataContractError;
7
+ use dpp::data_contract::schema::DataContractSchemaMethodsV0;
8
+ use dpp::data_contract::{DataContract, DataContractV0};
9
+ use dpp::prelude::IdentityNonce;
10
+ use dpp::serialization::{
11
+ PlatformDeserializableWithPotentialValidationFromVersionedStructure,
12
+ PlatformSerializableWithPlatformVersion,
13
+ };
14
+ use pshenmic_dpp_enums::platform::PlatformVersionWASM;
15
+ use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError, identifier_from_js_value};
16
+ use wasm_bindgen::JsValue;
17
+ use wasm_bindgen::prelude::wasm_bindgen;
18
+
19
+ #[wasm_bindgen(js_name = "DataContractWASM")]
20
+ #[derive(Clone)]
21
+ pub struct DataContractWASM(DataContract);
22
+
23
+ impl From<DataContract> for DataContractWASM {
24
+ fn from(v: DataContract) -> Self {
25
+ DataContractWASM(v)
26
+ }
27
+ }
28
+
29
+ impl From<DataContractWASM> for DataContract {
30
+ fn from(v: DataContractWASM) -> Self {
31
+ v.0
32
+ }
33
+ }
34
+
35
+ #[wasm_bindgen]
36
+ impl DataContractWASM {
37
+ #[wasm_bindgen(constructor)]
38
+ pub fn new(
39
+ js_value: JsValue,
40
+ full_validation: bool,
41
+ platform_version: PlatformVersionWASM,
42
+ ) -> Result<DataContractWASM, JsValue> {
43
+ let value = js_value.with_serde_to_platform_value()?;
44
+
45
+ let v0_contract =
46
+ DataContractV0::from_value(value, full_validation, &platform_version.into())
47
+ .with_js_error()?;
48
+
49
+ Ok(DataContractWASM(DataContract::V0(v0_contract)))
50
+ }
51
+
52
+ #[wasm_bindgen(js_name = "fromBytes")]
53
+ pub fn from_bytes(
54
+ bytes: Vec<u8>,
55
+ full_validation: bool,
56
+ platform_version: PlatformVersionWASM,
57
+ ) -> Result<DataContractWASM, JsValue> {
58
+ let rs_data_contract = DataContract::versioned_deserialize(
59
+ &bytes.as_slice(),
60
+ full_validation,
61
+ &platform_version.into(),
62
+ )
63
+ .with_js_error()?;
64
+
65
+ Ok(DataContractWASM(rs_data_contract))
66
+ }
67
+
68
+ #[wasm_bindgen(js_name = "toBytes")]
69
+ pub fn to_bytes(&self, platform_version: PlatformVersionWASM) -> Result<Vec<u8>, JsValue> {
70
+ let rs_data_contract: DataContract = self.0.clone();
71
+
72
+ rs_data_contract
73
+ .serialize_to_bytes_with_platform_version(&platform_version.into())
74
+ .with_js_error()
75
+ }
76
+
77
+ #[wasm_bindgen(js_name = "toValue")]
78
+ pub fn to_value(&self, platform_version: PlatformVersionWASM) -> Result<JsValue, JsValue> {
79
+ let serializer = serde_wasm_bindgen::Serializer::json_compatible();
80
+
81
+ self.0
82
+ .clone()
83
+ .to_value(&platform_version.into())
84
+ .with_js_error()?
85
+ .serialize(&serializer)
86
+ .map_err(JsValue::from)
87
+ }
88
+
89
+ #[wasm_bindgen(js_name = "getSchemas")]
90
+ pub fn get_schemas(&self) -> Result<JsValue, JsValue> {
91
+ let serializer = serde_wasm_bindgen::Serializer::json_compatible();
92
+
93
+ self.0
94
+ .document_schemas()
95
+ .serialize(&serializer)
96
+ .map_err(JsValue::from)
97
+ }
98
+
99
+ #[wasm_bindgen(js_name = "getDataContractVersion")]
100
+ pub fn get_data_contract_version(&self) -> u32 {
101
+ self.0.version()
102
+ }
103
+
104
+ #[wasm_bindgen(js_name = "getId")]
105
+ pub fn get_id(&self) -> Vec<u8> {
106
+ self.0.id().to_vec()
107
+ }
108
+
109
+ #[wasm_bindgen(js_name = "getOwnerId")]
110
+ pub fn get_owner_id(&self) -> Vec<u8> {
111
+ self.0.owner_id().to_vec()
112
+ }
113
+
114
+ #[wasm_bindgen(js_name = "getConfig")]
115
+ pub fn get_config(&self) -> Result<JsValue, JsValue> {
116
+ self.0
117
+ .config()
118
+ .serialize(&serde_wasm_bindgen::Serializer::json_compatible())
119
+ .map_err(JsValue::from)
120
+ }
121
+
122
+ #[wasm_bindgen(js_name = "toJson")]
123
+ pub fn to_json(&self, platform_version: PlatformVersionWASM) -> Result<JsValue, JsValue> {
124
+ let json = self.0.to_json(&platform_version.into()).with_js_error()?;
125
+
126
+ json.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
127
+ .map_err(JsValue::from)
128
+ }
129
+
130
+ #[wasm_bindgen(js_name = "generateId")]
131
+ pub fn generate_id(
132
+ js_owner_id: JsValue,
133
+ identity_nonce: IdentityNonce,
134
+ ) -> Result<Vec<u8>, JsValue> {
135
+ let owner_id = identifier_from_js_value(&js_owner_id)?;
136
+
137
+ Ok(DataContract::generate_data_contract_id_v0(owner_id, identity_nonce).to_vec())
138
+ }
139
+
140
+ #[wasm_bindgen(js_name = "setId")]
141
+ pub fn set_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
142
+ let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
143
+
144
+ Ok(self.0.set_id(data_contract_id))
145
+ }
146
+
147
+ #[wasm_bindgen(js_name = "setOwnerId")]
148
+ pub fn set_owner_id(&mut self, js_owner_id: JsValue) -> Result<(), JsValue> {
149
+ let owner_id = identifier_from_js_value(&js_owner_id)?;
150
+
151
+ Ok(self.0.set_owner_id(owner_id))
152
+ }
153
+ }
154
+
155
+ impl DataContractWASM {
156
+ pub fn get_document_type_ref_by_name(
157
+ &self,
158
+ name: String,
159
+ ) -> Result<DocumentTypeRef, DataContractError> {
160
+ self.0.document_type_for_name(name.as_str()).clone()
161
+ }
162
+ }
@@ -0,0 +1,14 @@
1
+ [package]
2
+ name = "pshenmic_dpp_data_contract_transitions"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [dependencies]
7
+ wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
8
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
9
+ "state-transition-signing"
10
+ ]}
11
+ pshenmic_dpp_data_contract = {path = "../data_contract"}
12
+ pshenmic_dpp_enums = {path = "../enums"}
13
+ pshenmic_dpp_utils = {path = "../utils"}
14
+ pshenmic_dpp_state_transition = {path = "../state_transition"}
@@ -0,0 +1,154 @@
1
+ use dpp::ProtocolError;
2
+ use dpp::data_contract::serialized_version::DataContractInSerializationFormat;
3
+ use dpp::prelude::{DataContract, IdentityNonce};
4
+ use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
5
+ use dpp::state_transition::StateTransition;
6
+ use dpp::state_transition::data_contract_create_transition::accessors::DataContractCreateTransitionAccessorsV0;
7
+ use dpp::state_transition::data_contract_create_transition::{
8
+ DataContractCreateTransition, DataContractCreateTransitionV0,
9
+ };
10
+ use dpp::validation::operations::ProtocolValidationOperation;
11
+ use dpp::version::{
12
+ FeatureVersion, ProtocolVersion, TryFromPlatformVersioned, TryIntoPlatformVersioned,
13
+ };
14
+ use pshenmic_dpp_data_contract::DataContractWASM;
15
+ use pshenmic_dpp_enums::platform::PlatformVersionWASM;
16
+ use pshenmic_dpp_state_transition::StateTransitionWASM;
17
+ use pshenmic_dpp_utils::WithJsError;
18
+ use wasm_bindgen::JsValue;
19
+ use wasm_bindgen::prelude::wasm_bindgen;
20
+
21
+ #[wasm_bindgen(js_name = "DataContractCreateTransitionWASM")]
22
+ pub struct DataContractCreateTransitionWASM(DataContractCreateTransition);
23
+
24
+ #[wasm_bindgen]
25
+ impl DataContractCreateTransitionWASM {
26
+ #[wasm_bindgen(constructor)]
27
+ pub fn new(
28
+ data_contract: &DataContractWASM,
29
+ identity_nonce: IdentityNonce,
30
+ platform_version: Option<PlatformVersionWASM>,
31
+ ) -> Result<DataContractCreateTransitionWASM, JsValue> {
32
+ let rs_data_contract: DataContract = data_contract.clone().into();
33
+
34
+ let rs_data_contract_in_serialized: Result<
35
+ DataContractInSerializationFormat,
36
+ ProtocolError,
37
+ > = rs_data_contract.try_into_platform_versioned(
38
+ &platform_version
39
+ .unwrap_or(PlatformVersionWASM::PLATFORM_V1)
40
+ .into(),
41
+ );
42
+
43
+ let rs_data_contract_create_transition_v0: DataContractCreateTransitionV0 =
44
+ DataContractCreateTransitionV0 {
45
+ data_contract: rs_data_contract_in_serialized.with_js_error()?,
46
+ identity_nonce,
47
+ user_fee_increase: 0,
48
+ signature_public_key_id: 0,
49
+ signature: Default::default(),
50
+ };
51
+
52
+ let rs_data_contract_transition =
53
+ DataContractCreateTransition::V0(rs_data_contract_create_transition_v0);
54
+
55
+ Ok(DataContractCreateTransitionWASM(
56
+ rs_data_contract_transition,
57
+ ))
58
+ }
59
+
60
+ #[wasm_bindgen(js_name = "fromBytes")]
61
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<DataContractCreateTransitionWASM, JsValue> {
62
+ let rs_data_contract_create_transition: DataContractCreateTransition =
63
+ DataContractCreateTransition::deserialize_from_bytes(bytes.as_slice())
64
+ .with_js_error()?;
65
+
66
+ Ok(DataContractCreateTransitionWASM(
67
+ rs_data_contract_create_transition,
68
+ ))
69
+ }
70
+
71
+ #[wasm_bindgen(js_name = "toBytes")]
72
+ pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
73
+ self.0.serialize_to_bytes().with_js_error()
74
+ }
75
+
76
+ #[wasm_bindgen(js_name = "getFeatureVersion")]
77
+ pub fn get_feature_version(&self) -> FeatureVersion {
78
+ self.0.feature_version()
79
+ }
80
+
81
+ #[wasm_bindgen(js_name = "verifyProtocolVersion")]
82
+ pub fn verify_protocol_version(
83
+ &self,
84
+ protocol_version: ProtocolVersion,
85
+ ) -> Result<bool, JsValue> {
86
+ self.0
87
+ .verify_protocol_version(protocol_version)
88
+ .with_js_error()
89
+ }
90
+
91
+ #[wasm_bindgen(js_name = "setDataContract")]
92
+ pub fn set_data_contract(
93
+ &mut self,
94
+ data_contract: DataContractWASM,
95
+ platform_version_wasm: Option<PlatformVersionWASM>,
96
+ ) -> Result<(), JsValue> {
97
+ let data_contract_serialization_format =
98
+ DataContractInSerializationFormat::try_from_platform_versioned(
99
+ DataContract::from(data_contract),
100
+ &platform_version_wasm
101
+ .unwrap_or(PlatformVersionWASM::PLATFORM_V1)
102
+ .into(),
103
+ )
104
+ .with_js_error()?;
105
+
106
+ self.0.set_data_contract(data_contract_serialization_format);
107
+
108
+ Ok(())
109
+ }
110
+
111
+ #[wasm_bindgen(js_name = "getDataContract")]
112
+ pub fn get_data_contract(
113
+ &self,
114
+ platform_version_wasm: Option<PlatformVersionWASM>,
115
+ full_validation: Option<bool>,
116
+ ) -> Result<DataContractWASM, JsValue> {
117
+ let rs_data_contract_serialization_format = self.0.data_contract();
118
+
119
+ let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
120
+
121
+ let rs_data_contract = DataContract::try_from_platform_versioned(
122
+ rs_data_contract_serialization_format.clone(),
123
+ full_validation.unwrap_or(false),
124
+ &mut validation_operations,
125
+ &platform_version_wasm
126
+ .unwrap_or(PlatformVersionWASM::PLATFORM_V1)
127
+ .into(),
128
+ )
129
+ .with_js_error()?;
130
+
131
+ Ok(DataContractWASM::from(rs_data_contract))
132
+ }
133
+
134
+ #[wasm_bindgen(js_name = "toStateTransition")]
135
+ pub fn to_state_transition(&self) -> StateTransitionWASM {
136
+ let rs_state_transition = StateTransition::from(self.0.clone());
137
+
138
+ StateTransitionWASM::from(rs_state_transition)
139
+ }
140
+
141
+ #[wasm_bindgen(js_name = "fromStateTransition")]
142
+ pub fn from_state_transition(
143
+ state_transition: &StateTransitionWASM,
144
+ ) -> Result<DataContractCreateTransitionWASM, JsValue> {
145
+ let rs_transition = StateTransition::from(state_transition.clone());
146
+
147
+ match rs_transition {
148
+ StateTransition::DataContractCreate(state_transition) => {
149
+ Ok(DataContractCreateTransitionWASM(state_transition))
150
+ }
151
+ _ => Err(JsValue::from("Incorrect transition type")),
152
+ }
153
+ }
154
+ }
@@ -0,0 +1,2 @@
1
+ mod create;
2
+ mod update;
@@ -0,0 +1,135 @@
1
+ use dpp::data_contract::serialized_version::DataContractInSerializationFormat;
2
+ use dpp::prelude::{DataContract, IdentityNonce};
3
+ use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
4
+ use dpp::state_transition::StateTransition;
5
+ use dpp::state_transition::data_contract_update_transition::DataContractUpdateTransition;
6
+ use dpp::state_transition::data_contract_update_transition::accessors::DataContractUpdateTransitionAccessorsV0;
7
+ use dpp::validation::operations::ProtocolValidationOperation;
8
+ use dpp::version::{FeatureVersion, ProtocolVersion, TryFromPlatformVersioned};
9
+ use pshenmic_dpp_data_contract::DataContractWASM;
10
+ use pshenmic_dpp_enums::platform::PlatformVersionWASM;
11
+ use pshenmic_dpp_state_transition::StateTransitionWASM;
12
+ use pshenmic_dpp_utils::WithJsError;
13
+ use wasm_bindgen::JsValue;
14
+ use wasm_bindgen::prelude::wasm_bindgen;
15
+
16
+ #[wasm_bindgen(js_name = "DataContractUpdateTransitionWASM")]
17
+ pub struct DataContractUpdateTransitionWASM(DataContractUpdateTransition);
18
+
19
+ #[wasm_bindgen]
20
+ impl DataContractUpdateTransitionWASM {
21
+ #[wasm_bindgen(constructor)]
22
+ pub fn new(
23
+ data_contract: &DataContractWASM,
24
+ identity_nonce: IdentityNonce,
25
+ platform_version: Option<PlatformVersionWASM>,
26
+ ) -> Result<DataContractUpdateTransitionWASM, JsValue> {
27
+ let rs_data_contract_update_transition =
28
+ DataContractUpdateTransition::try_from_platform_versioned(
29
+ (DataContract::from(data_contract.clone()), identity_nonce),
30
+ &platform_version
31
+ .unwrap_or(PlatformVersionWASM::PLATFORM_V1)
32
+ .into(),
33
+ )
34
+ .with_js_error()?;
35
+
36
+ Ok(DataContractUpdateTransitionWASM(
37
+ rs_data_contract_update_transition,
38
+ ))
39
+ }
40
+
41
+ #[wasm_bindgen(js_name = "fromBytes")]
42
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<DataContractUpdateTransitionWASM, JsValue> {
43
+ let rs_data_contract_update_transition: DataContractUpdateTransition =
44
+ DataContractUpdateTransition::deserialize_from_bytes(bytes.as_slice())
45
+ .with_js_error()?;
46
+
47
+ Ok(DataContractUpdateTransitionWASM(
48
+ rs_data_contract_update_transition,
49
+ ))
50
+ }
51
+
52
+ #[wasm_bindgen(js_name = "toBytes")]
53
+ pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
54
+ self.0.serialize_to_bytes().with_js_error()
55
+ }
56
+
57
+ #[wasm_bindgen(js_name = "getFeatureVersion")]
58
+ pub fn get_feature_version(&self) -> FeatureVersion {
59
+ self.0.feature_version()
60
+ }
61
+
62
+ #[wasm_bindgen(js_name = "verifyProtocolVersion")]
63
+ pub fn verify_protocol_version(
64
+ &self,
65
+ protocol_version: ProtocolVersion,
66
+ ) -> Result<bool, JsValue> {
67
+ self.0
68
+ .verify_protocol_version(protocol_version)
69
+ .with_js_error()
70
+ }
71
+
72
+ #[wasm_bindgen(js_name = "setDataContract")]
73
+ pub fn set_data_contract(
74
+ &mut self,
75
+ data_contract: &DataContractWASM,
76
+ platform_version_wasm: Option<PlatformVersionWASM>,
77
+ ) -> Result<(), JsValue> {
78
+ let data_contract_serialization_format =
79
+ DataContractInSerializationFormat::try_from_platform_versioned(
80
+ DataContract::from(data_contract.clone()),
81
+ &platform_version_wasm
82
+ .unwrap_or(PlatformVersionWASM::PLATFORM_V1)
83
+ .into(),
84
+ )
85
+ .with_js_error()?;
86
+
87
+ self.0.set_data_contract(data_contract_serialization_format);
88
+
89
+ Ok(())
90
+ }
91
+
92
+ #[wasm_bindgen(js_name = "getDataContract")]
93
+ pub fn get_data_contract(
94
+ &self,
95
+ full_validation: Option<bool>,
96
+ platform_version_wasm: Option<PlatformVersionWASM>,
97
+ ) -> Result<DataContractWASM, JsValue> {
98
+ let data_contract_serialization_format = self.0.data_contract();
99
+
100
+ let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
101
+
102
+ let rs_data_contract = DataContract::try_from_platform_versioned(
103
+ data_contract_serialization_format.clone(),
104
+ full_validation.unwrap_or(false),
105
+ &mut validation_operations,
106
+ &platform_version_wasm
107
+ .unwrap_or(PlatformVersionWASM::PLATFORM_V1)
108
+ .into(),
109
+ )
110
+ .with_js_error()?;
111
+
112
+ Ok(DataContractWASM::from(rs_data_contract))
113
+ }
114
+
115
+ #[wasm_bindgen(js_name = "toStateTransition")]
116
+ pub fn to_state_transition(&self) -> StateTransitionWASM {
117
+ let rs_state_transition = StateTransition::from(self.0.clone());
118
+
119
+ StateTransitionWASM::from(rs_state_transition)
120
+ }
121
+
122
+ #[wasm_bindgen(js_name = "fromStateTransition")]
123
+ pub fn from_state_transition(
124
+ state_transition: &StateTransitionWASM,
125
+ ) -> Result<DataContractUpdateTransitionWASM, JsValue> {
126
+ let rs_transition = StateTransition::from(state_transition.clone());
127
+
128
+ match rs_transition {
129
+ StateTransition::DataContractUpdate(state_transition) => {
130
+ Ok(DataContractUpdateTransitionWASM(state_transition))
131
+ }
132
+ _ => Err(JsValue::from("Incorrect transition type")),
133
+ }
134
+ }
135
+ }
@@ -9,11 +9,9 @@ crate-type = ["cdylib", "lib"]
9
9
  [dependencies]
10
10
  wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
11
  pshenmic_dpp_utils = {path = "../utils"}
12
+ pshenmic_dpp_enums = {path = "../enums"}
13
+ pshenmic_dpp_data_contract = {path = "../data_contract"}
12
14
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
13
- "document-json-conversion"
15
+ "document-value-conversion"
14
16
  ]}
15
- serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
16
-
17
- [profile.release]
18
- lto = true
19
- opt-level = 'z'
17
+ serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
@@ -1,6 +1,6 @@
1
1
  mod methods;
2
2
 
3
- use dpp::document::{Document, DocumentV0Getters};
3
+ use dpp::document::{Document, DocumentV0, DocumentV0Getters};
4
4
  use dpp::identifier::Identifier;
5
5
  use dpp::identity::TimestampMillis;
6
6
  use dpp::platform_value::Value;
@@ -29,6 +29,49 @@ pub struct DocumentWASM {
29
29
  entropy: Option<[u8; 32]>,
30
30
  }
31
31
 
32
+ impl From<DocumentWASM> for Document {
33
+ fn from(wasm_doc: DocumentWASM) -> Self {
34
+ Document::V0(DocumentV0 {
35
+ id: wasm_doc.id,
36
+ owner_id: wasm_doc.owner_id,
37
+ properties: wasm_doc.properties,
38
+ revision: wasm_doc.revision,
39
+ created_at: wasm_doc.created_at,
40
+ updated_at: wasm_doc.updated_at,
41
+ transferred_at: wasm_doc.transferred_at,
42
+ created_at_block_height: wasm_doc.created_at_block_height,
43
+ updated_at_block_height: wasm_doc.updated_at_block_height,
44
+ transferred_at_block_height: wasm_doc.transferred_at_block_height,
45
+ created_at_core_block_height: wasm_doc.created_at_core_block_height,
46
+ updated_at_core_block_height: wasm_doc.updated_at_core_block_height,
47
+ transferred_at_core_block_height: wasm_doc.transferred_at_core_block_height,
48
+ })
49
+ }
50
+ }
51
+
52
+ impl From<Document> for DocumentWASM {
53
+ fn from(doc: Document) -> Self {
54
+ DocumentWASM {
55
+ id: doc.id(),
56
+ owner_id: doc.owner_id(),
57
+ revision: doc.revision(),
58
+ data_contract_id: Default::default(),
59
+ document_type_name: "".to_string(),
60
+ properties: doc.properties().clone(),
61
+ created_at: doc.created_at(),
62
+ updated_at: doc.updated_at(),
63
+ transferred_at: doc.transferred_at(),
64
+ created_at_block_height: doc.created_at_block_height(),
65
+ updated_at_block_height: doc.updated_at_block_height(),
66
+ transferred_at_block_height: doc.transferred_at_block_height(),
67
+ created_at_core_block_height: doc.created_at_core_block_height(),
68
+ updated_at_core_block_height: doc.updated_at_core_block_height(),
69
+ transferred_at_core_block_height: doc.transferred_at_core_block_height(),
70
+ entropy: None,
71
+ }
72
+ }
73
+ }
74
+
32
75
  impl DocumentWASM {
33
76
  pub fn from_batch(
34
77
  document: Document,
@@ -1,14 +1,21 @@
1
1
  use crate::DocumentWASM;
2
+ use dpp::ProtocolError;
3
+ use dpp::dashcore::hashes::serde::Serialize;
4
+ use dpp::data_contract::JsonValue;
5
+ use dpp::document::Document;
6
+ use dpp::document::serialization_traits::DocumentPlatformConversionMethodsV0;
2
7
  use dpp::platform_value::converter::serde_json::BTreeValueJsonConverter;
3
8
  use dpp::platform_value::string_encoding::Encoding::Base58;
4
9
  use dpp::prelude::Revision;
5
- use pshenmic_dpp_utils::{ToSerdeJSONExt, identifier_from_js_value};
10
+ use pshenmic_dpp_data_contract::DataContractWASM;
11
+ use pshenmic_dpp_enums::platform::PlatformVersionWASM;
12
+ use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError, identifier_from_js_value};
6
13
  use wasm_bindgen::JsValue;
7
14
  use wasm_bindgen::prelude::wasm_bindgen;
8
15
 
9
16
  #[wasm_bindgen]
10
17
  impl DocumentWASM {
11
- #[wasm_bindgen(js_name=new)]
18
+ #[wasm_bindgen(constructor)]
12
19
  pub fn js_new(
13
20
  js_raw_document: JsValue,
14
21
  js_document_type_name: &str,
@@ -50,12 +57,15 @@ impl DocumentWASM {
50
57
  }
51
58
 
52
59
  #[wasm_bindgen(js_name=getProperties)]
53
- pub fn js_get_properties(&self) -> JsValue {
54
- let json = &self.properties.to_json_value().unwrap();
55
-
56
- let obj = json.as_object().unwrap();
57
-
58
- serde_wasm_bindgen::to_value(obj).unwrap()
60
+ pub fn js_get_properties(&self) -> Result<JsValue, JsValue> {
61
+ let json_value: JsonValue = self
62
+ .properties
63
+ .to_json_value()
64
+ .map_err(ProtocolError::ValueError)
65
+ .with_js_error()?;
66
+
67
+ let js_value = json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?;
68
+ Ok(js_value)
59
69
  }
60
70
 
61
71
  #[wasm_bindgen(js_name=getRevision)]
@@ -201,4 +211,50 @@ impl DocumentWASM {
201
211
  pub fn set_document_type_name(&mut self, document_type_name: &str) {
202
212
  self.document_type_name = document_type_name.to_string();
203
213
  }
214
+
215
+ #[wasm_bindgen(js_name=toBytes)]
216
+ pub fn to_bytes(
217
+ &self,
218
+ data_contract: &DataContractWASM,
219
+ type_name: String,
220
+ platform_version: PlatformVersionWASM,
221
+ ) -> Result<Vec<u8>, JsValue> {
222
+ let rs_document: Document = Document::from(self.clone());
223
+
224
+ let document_type_ref = data_contract
225
+ .get_document_type_ref_by_name(type_name)
226
+ .map_err(|err| JsValue::from_str(err.to_string().as_str()))?;
227
+
228
+ DocumentPlatformConversionMethodsV0::serialize(
229
+ &rs_document,
230
+ document_type_ref,
231
+ &platform_version.into(),
232
+ )
233
+ .with_js_error()
234
+ }
235
+
236
+ #[wasm_bindgen(js_name=fromBytes)]
237
+ pub fn from_bytes(
238
+ bytes: Vec<u8>,
239
+ data_contract: &DataContractWASM,
240
+ type_name: String,
241
+ platform_version: PlatformVersionWASM,
242
+ ) -> Result<DocumentWASM, JsValue> {
243
+ let document_type_ref = match data_contract.get_document_type_ref_by_name(type_name) {
244
+ Ok(type_ref) => Ok(type_ref),
245
+ Err(err) => Err(JsValue::from_str(err.to_string().as_str())),
246
+ }?;
247
+
248
+ let rs_document = Document::from_bytes(
249
+ bytes.as_slice(),
250
+ document_type_ref,
251
+ &platform_version.into(),
252
+ )
253
+ .with_js_error();
254
+
255
+ match rs_document {
256
+ Ok(doc) => Ok(DocumentWASM::from(doc)),
257
+ Err(err) => Err(err),
258
+ }
259
+ }
204
260
  }