pshenmic-dpp 1.0.4 → 1.0.6

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 (152) hide show
  1. package/.github/workflows/build.yml +9 -1
  2. package/.github/workflows/publish.yml +9 -1
  3. package/Cargo.lock +222 -76
  4. package/Cargo.toml +28 -19
  5. package/README.md +75 -23
  6. package/babel.config.json +19 -0
  7. package/dist/wasm/index.d.ts +52 -0
  8. package/dist/wasm/pshenmic_dpp.d.ts +962 -0
  9. package/dist/wasm/pshenmic_dpp.js +5565 -966
  10. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  11. package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
  12. package/docs/AssetLockProof.md +107 -0
  13. package/docs/Building.md +50 -0
  14. package/docs/ChainLockProof.md +63 -0
  15. package/docs/CoreScript.md +17 -0
  16. package/docs/DataContract.md +192 -0
  17. package/docs/DataContractCreateTransition.md +84 -0
  18. package/docs/DataContractUpdateTransition.md +84 -0
  19. package/docs/Document.md +396 -0
  20. package/docs/DocumentBaseTransition.md +111 -0
  21. package/docs/DocumentCreateTransition.md +132 -0
  22. package/docs/DocumentDeleteTransition.md +82 -0
  23. package/docs/DocumentPurchaseTransition.md +109 -0
  24. package/docs/DocumentReplaceTransition.md +112 -0
  25. package/docs/DocumentTransferTransition.md +96 -0
  26. package/docs/DocumentTransition.md +125 -0
  27. package/docs/DocumentUpdatePriceTransition.md +109 -0
  28. package/docs/DocumentsBatch.md +133 -0
  29. package/docs/Enums.md +103 -0
  30. package/docs/Home.md +28 -0
  31. package/docs/Identifier.md +37 -0
  32. package/docs/Identity.md +140 -0
  33. package/docs/IdentityCreateTransition.md +155 -0
  34. package/docs/IdentityCreditTransfer.md +187 -0
  35. package/docs/IdentityCreditWithdrawalTransition.md +244 -0
  36. package/docs/IdentityPublicKey.md +348 -0
  37. package/docs/IdentityPublicKeyInCreation.md +141 -0
  38. package/docs/IdentityTopUpTransition.md +166 -0
  39. package/docs/IdentityUpdateTransition.md +234 -0
  40. package/docs/InstantAssetLockProof.md +117 -0
  41. package/docs/InstantLock.md +100 -0
  42. package/docs/OutPoint.md +80 -0
  43. package/docs/PrefundedVotingBalance.md +48 -0
  44. package/docs/PrivateKey.md +112 -0
  45. package/docs/TxOut.md +93 -0
  46. package/package.json +15 -8
  47. package/packages/asset_lock_proof/Cargo.toml +19 -0
  48. package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
  49. package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
  50. package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
  51. package/packages/asset_lock_proof/src/lib.rs +133 -0
  52. package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
  53. package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
  54. package/packages/cbor_conversation/Cargo.toml +2 -2
  55. package/packages/core_script/Cargo.toml +13 -0
  56. package/packages/core_script/src/lib.rs +69 -0
  57. package/packages/data_contract/Cargo.toml +4 -3
  58. package/packages/data_contract/src/lib.rs +209 -33
  59. package/packages/data_contract_transitions/Cargo.toml +2 -2
  60. package/packages/data_contract_transitions/src/create/mod.rs +23 -16
  61. package/packages/data_contract_transitions/src/update/mod.rs +21 -12
  62. package/packages/document/Cargo.toml +3 -2
  63. package/packages/document/src/lib.rs +14 -13
  64. package/packages/document/src/methods/mod.rs +373 -2
  65. package/packages/{document_batch → documents_batch}/Cargo.toml +7 -4
  66. package/packages/documents_batch/src/document_base_transition/mod.rs +88 -0
  67. package/packages/documents_batch/src/document_transition/mod.rs +166 -0
  68. package/packages/documents_batch/src/generators.rs +122 -0
  69. package/packages/documents_batch/src/lib.rs +195 -0
  70. package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
  71. package/packages/documents_batch/src/transitions/create/mod.rs +126 -0
  72. package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
  73. package/packages/documents_batch/src/transitions/mod.rs +6 -0
  74. package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
  75. package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
  76. package/packages/documents_batch/src/transitions/transfer/mod.rs +84 -0
  77. package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
  78. package/packages/enums/Cargo.toml +4 -4
  79. package/packages/enums/src/batch/batch_enum.rs +75 -10
  80. package/packages/enums/src/keys/key_type.rs +46 -0
  81. package/packages/enums/src/keys/purpose.rs +55 -0
  82. package/packages/enums/src/keys/security_level.rs +46 -0
  83. package/packages/enums/src/lib.rs +3 -0
  84. package/packages/enums/src/lock_types/mod.rs +65 -0
  85. package/packages/enums/src/network/mod.rs +67 -0
  86. package/packages/enums/src/platform/mod.rs +68 -8
  87. package/packages/enums/src/withdrawal/mod.rs +72 -0
  88. package/packages/identifier/Cargo.toml +9 -0
  89. package/packages/identifier/src/lib.rs +105 -0
  90. package/packages/identity/Cargo.toml +5 -5
  91. package/packages/identity/src/lib.rs +31 -25
  92. package/packages/{public_key → identity_public_key}/Cargo.toml +2 -2
  93. package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
  94. package/packages/identity_transitions/Cargo.toml +8 -4
  95. package/packages/identity_transitions/src/create_transition/mod.rs +102 -37
  96. package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
  97. package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
  98. package/packages/identity_transitions/src/lib.rs +6 -1
  99. package/packages/identity_transitions/src/public_key_in_creation/mod.rs +197 -0
  100. package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
  101. package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
  102. package/packages/mock_bls/Cargo.toml +1 -1
  103. package/packages/private_key/Cargo.toml +4 -3
  104. package/packages/private_key/src/lib.rs +44 -6
  105. package/packages/state_transition/Cargo.toml +6 -4
  106. package/packages/state_transition/src/lib.rs +102 -36
  107. package/packages/utils/Cargo.toml +3 -4
  108. package/packages/utils/src/lib.rs +17 -18
  109. package/scripts/build-js.sh +22 -5
  110. package/scripts/build.sh +27 -2
  111. package/src/lib.rs +8 -1
  112. package/tests/AssetLockProof.spec.js +80 -0
  113. package/tests/ChainLockProof.spec.js +69 -0
  114. package/tests/CoreScript.spec.js +37 -0
  115. package/tests/DataContract.spec.js +178 -0
  116. package/tests/DataContractCreateStateTransition.spec.js +109 -0
  117. package/tests/DataContractUpdateStateTransition.spec.js +109 -0
  118. package/tests/Document.spec.js +238 -0
  119. package/tests/DocumentBatchTransition.spec.js +109 -0
  120. package/tests/DocumentTransition.spec.js +97 -0
  121. package/tests/DocumentsTransitions.spec.js +705 -0
  122. package/tests/Identifier.spec.js +84 -0
  123. package/tests/Identity.spec.js +113 -0
  124. package/tests/IdentityCreateTransition.spec.js +93 -0
  125. package/tests/IdentityCreditTransferTransition.spec.js +146 -0
  126. package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
  127. package/tests/IdentityPublicKey.spec.js +132 -0
  128. package/tests/IdentityTopUpTransition.spec.js +131 -0
  129. package/tests/IdentityUpdateTransition.spec.js +147 -0
  130. package/tests/InstantLockProof.spec.js +97 -0
  131. package/tests/OutPoint.spec.js +55 -0
  132. package/tests/PrivateKey.spec.js +73 -0
  133. package/tests/PublicKeyInCreation.spec.js +258 -0
  134. package/tests/TxOut.spec.js +76 -0
  135. package/tests/mocks/DataContract/DataContract.json +153 -0
  136. package/tests/mocks/DataContract/index.js +6 -0
  137. package/tests/mocks/Document/DataContract.json +23 -0
  138. package/tests/mocks/Document/document.json +3 -0
  139. package/tests/mocks/Document/document2.json +3 -0
  140. package/tests/mocks/Document/index.js +11 -0
  141. package/tests/mocks/Identity/index.js +7 -0
  142. package/tests/mocks/Locks/index.js +5 -0
  143. package/tests/mocks/PrivateKey/index.js +5 -0
  144. package/tests/mocks/PublicKey/index.js +14 -0
  145. package/tests/utils/hex.js +15 -0
  146. package/tests/utils/wasm.js +14 -0
  147. package/typings/index.d.ts +52 -0
  148. package/packages/document/src/methods/js.rs +0 -260
  149. package/packages/document/src/methods/rust.rs +0 -92
  150. package/packages/document_batch/src/generators.rs +0 -63
  151. package/packages/document_batch/src/lib.rs +0 -228
  152. package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +0 -146
@@ -1,2 +1,373 @@
1
- mod js;
2
- mod rust;
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;
7
+ use dpp::identifier::Identifier;
8
+ use dpp::platform_value::Value;
9
+ use dpp::platform_value::converter::serde_json::BTreeValueJsonConverter;
10
+ use dpp::prelude::Revision;
11
+ use dpp::util::entropy_generator;
12
+ use dpp::util::entropy_generator::EntropyGenerator;
13
+ use pshenmic_dpp_data_contract::DataContractWASM;
14
+ use pshenmic_dpp_enums::platform::PlatformVersionWASM;
15
+ use pshenmic_dpp_identifier::IdentifierWASM;
16
+ use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError};
17
+ use std::collections::BTreeMap;
18
+ use wasm_bindgen::JsValue;
19
+ use wasm_bindgen::prelude::wasm_bindgen;
20
+
21
+ #[wasm_bindgen]
22
+ impl DocumentWASM {
23
+ #[wasm_bindgen(constructor)]
24
+ pub fn new(
25
+ js_raw_document: JsValue,
26
+ js_document_type_name: &str,
27
+ js_revision: u64,
28
+ js_data_contract_id: &JsValue,
29
+ js_owner_id: &JsValue,
30
+ js_document_id: JsValue,
31
+ ) -> Result<DocumentWASM, JsValue> {
32
+ let data_contract_id = IdentifierWASM::try_from(js_data_contract_id)?;
33
+ let owner_id = IdentifierWASM::try_from(js_owner_id)?;
34
+
35
+ let revision = Revision::from(js_revision);
36
+
37
+ let document = js_raw_document
38
+ .with_serde_to_platform_value_map()
39
+ .expect("cannot convert document to platform value map");
40
+
41
+ let revision = Revision::from(revision);
42
+
43
+ let entropy = entropy_generator::DefaultEntropyGenerator
44
+ .generate()
45
+ .unwrap();
46
+
47
+ let document_id: IdentifierWASM = match js_document_id.is_undefined() {
48
+ true => pshenmic_dpp_utils::generate_document_id_v0(
49
+ &data_contract_id.into(),
50
+ &owner_id.into(),
51
+ js_document_type_name,
52
+ &entropy,
53
+ )?
54
+ .into(),
55
+ false => js_document_id.try_into()?,
56
+ };
57
+
58
+ Ok(DocumentWASM {
59
+ owner_id,
60
+ entropy: Some(entropy),
61
+ id: document_id,
62
+ document_type_name: js_document_type_name.to_string(),
63
+ data_contract_id,
64
+ properties: document,
65
+ revision: Some(revision),
66
+ created_at: None,
67
+ updated_at: None,
68
+ transferred_at: None,
69
+ created_at_block_height: None,
70
+ updated_at_block_height: None,
71
+ transferred_at_block_height: None,
72
+ created_at_core_block_height: None,
73
+ updated_at_core_block_height: None,
74
+ transferred_at_core_block_height: None,
75
+ })
76
+ }
77
+
78
+ #[wasm_bindgen(js_name=getId)]
79
+ pub fn get_id(&self) -> IdentifierWASM {
80
+ self.id
81
+ }
82
+
83
+ #[wasm_bindgen(js_name=getEntropy)]
84
+ pub fn get_entropy(&self) -> Option<Vec<u8>> {
85
+ match self.entropy {
86
+ Some(entropy) => Some(entropy.to_vec()),
87
+ None => None,
88
+ }
89
+ }
90
+
91
+ #[wasm_bindgen(js_name=getDataContractId)]
92
+ pub fn get_data_contract_id(&self) -> IdentifierWASM {
93
+ self.data_contract_id
94
+ }
95
+
96
+ #[wasm_bindgen(js_name=getOwnerId)]
97
+ pub fn get_owner_id(&self) -> IdentifierWASM {
98
+ self.owner_id
99
+ }
100
+
101
+ #[wasm_bindgen(js_name=getProperties)]
102
+ pub fn get_properties(&self) -> Result<JsValue, JsValue> {
103
+ let json_value: JsonValue = self
104
+ .properties
105
+ .clone()
106
+ .to_json_value()
107
+ .map_err(ProtocolError::ValueError)
108
+ .with_js_error()?;
109
+
110
+ let js_value = json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?;
111
+ Ok(js_value)
112
+ }
113
+
114
+ #[wasm_bindgen(js_name=getRevision)]
115
+ pub fn get_revision(&self) -> Option<u64> {
116
+ self.revision
117
+ }
118
+
119
+ #[wasm_bindgen(js_name=getCreatedAt)]
120
+ pub fn get_created_at(&self) -> Option<u64> {
121
+ self.created_at
122
+ }
123
+
124
+ #[wasm_bindgen(js_name=getUpdatedAt)]
125
+ pub fn get_updated_at(&self) -> Option<u64> {
126
+ self.updated_at
127
+ }
128
+
129
+ #[wasm_bindgen(js_name=getTransferredAt)]
130
+ pub fn get_transferred_at(&self) -> Option<u64> {
131
+ self.transferred_at
132
+ }
133
+
134
+ #[wasm_bindgen(js_name=getCreatedAtBlockHeight)]
135
+ pub fn get_created_at_block_height(&self) -> Option<u64> {
136
+ self.created_at_block_height
137
+ }
138
+
139
+ #[wasm_bindgen(js_name=getUpdatedAtBlockHeight)]
140
+ pub fn get_updated_at_block_height(&self) -> Option<u64> {
141
+ self.updated_at_block_height
142
+ }
143
+
144
+ #[wasm_bindgen(js_name=getTransferredAtBlockHeight)]
145
+ pub fn get_transferred_at_block_height(&self) -> Option<u64> {
146
+ self.transferred_at_block_height
147
+ }
148
+
149
+ #[wasm_bindgen(js_name=getCreatedAtCoreBlockHeight)]
150
+ pub fn get_created_at_core_block_height(&self) -> Option<u32> {
151
+ self.created_at_core_block_height
152
+ }
153
+
154
+ #[wasm_bindgen(js_name=getUpdatedAtCoreBlockHeight)]
155
+ pub fn get_updated_at_core_block_height(&self) -> Option<u32> {
156
+ self.updated_at_core_block_height
157
+ }
158
+
159
+ #[wasm_bindgen(js_name=getTransferredAtCoreBlockHeight)]
160
+ pub fn get_transferred_at_core_block_height(&self) -> Option<u32> {
161
+ self.transferred_at_core_block_height
162
+ }
163
+
164
+ #[wasm_bindgen(js_name=getDocumentTypeName)]
165
+ pub fn get_document_type_name(&self) -> String {
166
+ self.document_type_name.clone()
167
+ }
168
+
169
+ #[wasm_bindgen(js_name=setId)]
170
+ pub fn set_id(&mut self, id: &JsValue) -> Result<(), JsValue> {
171
+ self.id = IdentifierWASM::try_from(id)?.clone();
172
+ Ok(())
173
+ }
174
+
175
+ #[wasm_bindgen(js_name=setEntropy)]
176
+ pub fn set_entropy(&mut self, entropy: JsValue) {
177
+ match entropy.is_undefined() {
178
+ false => {
179
+ let value = entropy.with_serde_to_platform_value().unwrap();
180
+
181
+ let mut entropy = [0u8; 32];
182
+ let bytes = value.as_bytes().unwrap();
183
+ let len = bytes.len().min(32);
184
+ entropy[..len].copy_from_slice(&bytes[..len]);
185
+ self.entropy = Some(entropy);
186
+ }
187
+ true => self.entropy = None,
188
+ }
189
+ }
190
+
191
+ #[wasm_bindgen(js_name=setOwnerId)]
192
+ pub fn set_owner_id(&mut self, id: &JsValue) -> Result<(), JsValue> {
193
+ self.owner_id = IdentifierWASM::try_from(id)?.clone();
194
+ Ok(())
195
+ }
196
+
197
+ #[wasm_bindgen(js_name=setProperties)]
198
+ pub fn set_properties(&mut self, properties: JsValue) {
199
+ self.properties = properties.with_serde_to_platform_value_map().unwrap()
200
+ }
201
+
202
+ #[wasm_bindgen(js_name=setRevision)]
203
+ pub fn set_revision(&mut self, revision: Option<u64>) {
204
+ self.revision = revision
205
+ }
206
+
207
+ #[wasm_bindgen(js_name=setCreatedAt)]
208
+ pub fn set_created_at(&mut self, created_at: Option<u64>) {
209
+ self.created_at = created_at
210
+ }
211
+
212
+ #[wasm_bindgen(js_name=setUpdatedAt)]
213
+ pub fn set_get_updated_at(&mut self, updated_at: Option<u64>) {
214
+ self.updated_at = updated_at
215
+ }
216
+
217
+ #[wasm_bindgen(js_name=setTransferredAt)]
218
+ pub fn set_transferred_at(&mut self, transferred_at: Option<u64>) {
219
+ self.transferred_at = transferred_at
220
+ }
221
+
222
+ #[wasm_bindgen(js_name=setCreatedAtBlockHeight)]
223
+ pub fn set_created_at_block_height(&mut self, created_at_block_height: Option<u64>) {
224
+ self.created_at_block_height = created_at_block_height
225
+ }
226
+
227
+ #[wasm_bindgen(js_name=setUpdatedAtBlockHeight)]
228
+ pub fn set_updated_at_block_height(&mut self, updated_at_block_height: Option<u64>) {
229
+ self.updated_at_block_height = updated_at_block_height
230
+ }
231
+
232
+ #[wasm_bindgen(js_name=setTransferredAtBlockHeight)]
233
+ pub fn set_transferred_at_block_height(&mut self, transferred_at_block_height: Option<u64>) {
234
+ self.transferred_at_block_height = transferred_at_block_height
235
+ }
236
+
237
+ #[wasm_bindgen(js_name=setCreatedAtCoreBlockHeight)]
238
+ pub fn set_created_at_core_block_height(&mut self, created_at_core_block_height: Option<u32>) {
239
+ self.created_at_core_block_height = created_at_core_block_height
240
+ }
241
+
242
+ #[wasm_bindgen(js_name=setUpdatedAtCoreBlockHeight)]
243
+ pub fn set_updated_at_core_block_height(&mut self, updated_at_core_block_height: Option<u32>) {
244
+ self.updated_at_core_block_height = updated_at_core_block_height
245
+ }
246
+
247
+ #[wasm_bindgen(js_name=setTransferredAtCoreBlockHeight)]
248
+ pub fn set_transferred_at_core_block_height(
249
+ &mut self,
250
+ transferred_at_core_block_height: Option<u32>,
251
+ ) {
252
+ self.transferred_at_core_block_height = transferred_at_core_block_height
253
+ }
254
+
255
+ #[wasm_bindgen(js_name=setDocumentTypeName)]
256
+ pub fn set_document_type_name(&mut self, document_type_name: &str) {
257
+ self.document_type_name = document_type_name.to_string();
258
+ }
259
+
260
+ #[wasm_bindgen(js_name=toBytes)]
261
+ pub fn to_bytes(
262
+ &self,
263
+ data_contract: &DataContractWASM,
264
+ type_name: String,
265
+ js_platform_version: JsValue,
266
+ ) -> Result<Vec<u8>, JsValue> {
267
+ let platform_version = match js_platform_version.is_undefined() {
268
+ true => PlatformVersionWASM::default(),
269
+ false => PlatformVersionWASM::try_from(js_platform_version)?,
270
+ };
271
+
272
+ let rs_document: Document = Document::from(self.clone());
273
+
274
+ let document_type_ref = data_contract
275
+ .get_document_type_ref_by_name(type_name)
276
+ .map_err(|err| JsValue::from_str(err.to_string().as_str()))?;
277
+
278
+ DocumentPlatformConversionMethodsV0::serialize(
279
+ &rs_document,
280
+ document_type_ref,
281
+ &platform_version.into(),
282
+ )
283
+ .with_js_error()
284
+ }
285
+
286
+ #[wasm_bindgen(js_name=fromBytes)]
287
+ pub fn from_bytes(
288
+ bytes: Vec<u8>,
289
+ data_contract: &DataContractWASM,
290
+ type_name: String,
291
+ js_platform_version: JsValue,
292
+ ) -> Result<DocumentWASM, JsValue> {
293
+ let platform_version = match js_platform_version.is_undefined() {
294
+ true => PlatformVersionWASM::default(),
295
+ false => PlatformVersionWASM::try_from(js_platform_version)?,
296
+ };
297
+
298
+ let document_type_ref = match data_contract.get_document_type_ref_by_name(type_name) {
299
+ Ok(type_ref) => Ok(type_ref),
300
+ Err(err) => Err(JsValue::from_str(err.to_string().as_str())),
301
+ }?;
302
+
303
+ let rs_document = Document::from_bytes(
304
+ bytes.as_slice(),
305
+ document_type_ref,
306
+ &platform_version.into(),
307
+ )
308
+ .with_js_error();
309
+
310
+ match rs_document {
311
+ Ok(doc) => Ok(DocumentWASM::from(doc)),
312
+ Err(err) => Err(err),
313
+ }
314
+ }
315
+
316
+ #[wasm_bindgen(js_name=generateId)]
317
+ pub fn generate_id(
318
+ js_document_type_name: &str,
319
+ js_owner_id: &JsValue,
320
+ js_data_contract_id: &JsValue,
321
+ opt_entropy: Option<Vec<u8>>,
322
+ ) -> Result<Vec<u8>, JsValue> {
323
+ let owner_id = IdentifierWASM::try_from(js_owner_id)?;
324
+ let data_contract_id = IdentifierWASM::try_from(js_data_contract_id)?;
325
+
326
+ let entropy: [u8; 32] = match opt_entropy {
327
+ Some(entropy_vec) => {
328
+ let mut entropy = [0u8; 32];
329
+ let bytes = entropy_vec.as_slice();
330
+ let len = bytes.len().min(32);
331
+ entropy[..len].copy_from_slice(&bytes[..len]);
332
+ entropy
333
+ }
334
+ None => entropy_generator::DefaultEntropyGenerator
335
+ .generate()
336
+ .with_js_error()?,
337
+ };
338
+
339
+ let identifier = pshenmic_dpp_utils::generate_document_id_v0(
340
+ &data_contract_id.into(),
341
+ &owner_id.into(),
342
+ js_document_type_name,
343
+ &entropy,
344
+ );
345
+
346
+ match identifier {
347
+ Ok(identifier) => Ok(identifier.to_vec()),
348
+ Err(err) => Err(err),
349
+ }
350
+ }
351
+ }
352
+
353
+ impl DocumentWASM {
354
+ pub fn rs_get_owner_id(&self) -> Identifier {
355
+ self.owner_id.into()
356
+ }
357
+
358
+ pub fn rs_get_id(&self) -> Identifier {
359
+ self.id.into()
360
+ }
361
+
362
+ pub fn rs_get_data_contract_id(&self) -> Identifier {
363
+ self.data_contract_id.into()
364
+ }
365
+
366
+ pub fn rs_get_entropy(&self) -> Option<[u8; 32]> {
367
+ self.entropy
368
+ }
369
+
370
+ pub fn rs_get_properties(&self) -> BTreeMap<String, Value> {
371
+ self.clone().properties
372
+ }
373
+ }
@@ -1,17 +1,20 @@
1
1
  [package]
2
- name = "pshenmic_dpp_document_batch"
3
- version = "0.1.0"
2
+ name = "pshenmic_dpp_documents_batch"
3
+ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
7
7
  crate-type = ["cdylib", "lib"]
8
8
 
9
9
  [dependencies]
10
- wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
10
+ wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
11
11
  pshenmic_dpp_document = {path = "../document"}
12
12
  pshenmic_dpp_enums = {path = "../enums"}
13
+ pshenmic_dpp_identifier = {path = "../identifier"}
13
14
  pshenmic_dpp_utils = {path = "../utils"}
14
15
  pshenmic_dpp_state_transition = {path = "../state_transition"}
15
16
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
16
17
  "document-json-conversion",
17
- ]}
18
+ ]}
19
+ js-sys = "0.3.53"
20
+ serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
@@ -0,0 +1,88 @@
1
+ use dpp::prelude::IdentityNonce;
2
+ use dpp::state_transition::documents_batch_transition::document_base_transition::DocumentBaseTransition;
3
+ use dpp::state_transition::documents_batch_transition::document_base_transition::v0::DocumentBaseTransitionV0;
4
+ use dpp::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
5
+ use pshenmic_dpp_identifier::IdentifierWASM;
6
+ use wasm_bindgen::JsValue;
7
+ use wasm_bindgen::prelude::wasm_bindgen;
8
+
9
+ #[derive(Clone)]
10
+ #[wasm_bindgen(js_name = "DocumentBaseTransitionWASM")]
11
+ pub struct DocumentBaseTransitionWASM(DocumentBaseTransition);
12
+
13
+ impl From<DocumentBaseTransition> for DocumentBaseTransitionWASM {
14
+ fn from(v: DocumentBaseTransition) -> Self {
15
+ DocumentBaseTransitionWASM(v)
16
+ }
17
+ }
18
+
19
+ impl From<DocumentBaseTransitionWASM> for DocumentBaseTransition {
20
+ fn from(v: DocumentBaseTransitionWASM) -> Self {
21
+ v.0
22
+ }
23
+ }
24
+
25
+ #[wasm_bindgen]
26
+ impl DocumentBaseTransitionWASM {
27
+ #[wasm_bindgen(constructor)]
28
+ pub fn new(
29
+ js_document_id: &JsValue,
30
+ identity_contract_nonce: IdentityNonce,
31
+ document_type_name: String,
32
+ js_data_contract_id: &JsValue,
33
+ ) -> Result<DocumentBaseTransitionWASM, JsValue> {
34
+ let rs_base_v0 = DocumentBaseTransitionV0 {
35
+ id: IdentifierWASM::try_from(js_document_id)?.into(),
36
+ identity_contract_nonce,
37
+ document_type_name,
38
+ data_contract_id: IdentifierWASM::try_from(js_data_contract_id)?.into(),
39
+ };
40
+
41
+ Ok(DocumentBaseTransitionWASM(DocumentBaseTransition::from(
42
+ rs_base_v0,
43
+ )))
44
+ }
45
+
46
+ #[wasm_bindgen(getter = "id")]
47
+ pub fn get_id(&self) -> IdentifierWASM {
48
+ self.0.id().into()
49
+ }
50
+
51
+ #[wasm_bindgen(getter = "identityContractNonce")]
52
+ pub fn get_identity_contract_nonce(&self) -> IdentityNonce {
53
+ self.0.identity_contract_nonce()
54
+ }
55
+
56
+ #[wasm_bindgen(getter = "dataContractId")]
57
+ pub fn get_data_contract_id(&self) -> IdentifierWASM {
58
+ self.0.data_contract_id().into()
59
+ }
60
+
61
+ #[wasm_bindgen(getter = "documentTypeName")]
62
+ pub fn get_document_type_name(&self) -> String {
63
+ self.0.document_type_name().to_string()
64
+ }
65
+
66
+ #[wasm_bindgen(setter = "id")]
67
+ pub fn set_id(&mut self, js_id: &JsValue) -> Result<(), JsValue> {
68
+ self.0.set_id(IdentifierWASM::try_from(js_id)?.into());
69
+ Ok(())
70
+ }
71
+
72
+ #[wasm_bindgen(setter = "identityContractNonce")]
73
+ pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) {
74
+ self.0.set_identity_contract_nonce(nonce)
75
+ }
76
+
77
+ #[wasm_bindgen(setter = "dataContractId")]
78
+ pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> {
79
+ self.0
80
+ .set_data_contract_id(IdentifierWASM::try_from(js_data_contract_id)?.into());
81
+ Ok(())
82
+ }
83
+
84
+ #[wasm_bindgen(setter = "documentTypeName")]
85
+ pub fn set_document_type_name(&mut self, document_type_name: String) {
86
+ self.0.set_document_type_name(document_type_name)
87
+ }
88
+ }
@@ -0,0 +1,166 @@
1
+ use crate::transitions::create::DocumentCreateTransitionWASM;
2
+ use crate::transitions::delete::DocumentDeleteTransitionWASM;
3
+ use crate::transitions::purchase::DocumentPurchaseTransitionWASM;
4
+ use crate::transitions::replace::DocumentReplaceTransitionWASM;
5
+ use crate::transitions::transfer::DocumentTransferTransitionWASM;
6
+ use crate::transitions::update_price::DocumentUpdatePriceTransitionWASM;
7
+ use dpp::prelude::{Identifier, IdentityNonce, Revision};
8
+ use dpp::state_transition::documents_batch_transition::document_transition::action_type::TransitionActionTypeGetter;
9
+ use dpp::state_transition::documents_batch_transition::document_transition::{
10
+ DocumentTransition, DocumentTransitionV0Methods,
11
+ };
12
+ use pshenmic_dpp_enums::batch::batch_enum::BatchTypeWASM;
13
+ use pshenmic_dpp_identifier::IdentifierWASM;
14
+ use wasm_bindgen::JsValue;
15
+ use wasm_bindgen::prelude::wasm_bindgen;
16
+
17
+ #[derive(Clone)]
18
+ #[wasm_bindgen(js_name = "DocumentTransitionWASM")]
19
+ pub struct DocumentTransitionWASM(DocumentTransition);
20
+
21
+ impl From<DocumentTransition> for DocumentTransitionWASM {
22
+ fn from(transition: DocumentTransition) -> Self {
23
+ DocumentTransitionWASM(transition)
24
+ }
25
+ }
26
+
27
+ impl From<DocumentTransitionWASM> for DocumentTransition {
28
+ fn from(transition: DocumentTransitionWASM) -> Self {
29
+ transition.0
30
+ }
31
+ }
32
+
33
+ #[wasm_bindgen]
34
+ impl DocumentTransitionWASM {
35
+ #[wasm_bindgen(getter = "actionType")]
36
+ pub fn get_action_type(&self) -> String {
37
+ BatchTypeWASM::from(self.0.action_type()).into()
38
+ }
39
+
40
+ #[wasm_bindgen(getter = "dataContractId")]
41
+ pub fn get_data_contract_id(&self) -> IdentifierWASM {
42
+ self.0.data_contract_id().into()
43
+ }
44
+
45
+ #[wasm_bindgen(getter = "id")]
46
+ pub fn get_id(&self) -> IdentifierWASM {
47
+ self.0.get_id().into()
48
+ }
49
+
50
+ #[wasm_bindgen(getter = "documentTypeName")]
51
+ pub fn get_document_type_name(&self) -> String {
52
+ self.0.document_type_name().clone()
53
+ }
54
+
55
+ #[wasm_bindgen(getter = "identityContractNonce")]
56
+ pub fn get_identity_contract_nonce(&self) -> IdentityNonce {
57
+ self.0.identity_contract_nonce()
58
+ }
59
+
60
+ #[wasm_bindgen(getter = "revision")]
61
+ pub fn get_revision(&self) -> Option<Revision> {
62
+ self.0.revision()
63
+ }
64
+
65
+ #[wasm_bindgen(getter = "entropy")]
66
+ pub fn get_entropy(&self) -> Option<Vec<u8>> {
67
+ self.0.entropy()
68
+ }
69
+
70
+ #[wasm_bindgen(getter = "createTransition")]
71
+ pub fn get_create_transition(&self) -> Result<DocumentCreateTransitionWASM, JsValue> {
72
+ match self.0.clone() {
73
+ DocumentTransition::Create(create) => Ok(DocumentCreateTransitionWASM::from(create)),
74
+ _ => Err(JsValue::undefined()),
75
+ }
76
+ }
77
+
78
+ #[wasm_bindgen(getter = "replaceTransition")]
79
+ pub fn get_replace_transition(&self) -> Result<DocumentReplaceTransitionWASM, JsValue> {
80
+ match self.0.clone() {
81
+ DocumentTransition::Replace(replace) => {
82
+ Ok(DocumentReplaceTransitionWASM::from(replace))
83
+ }
84
+ _ => Err(JsValue::undefined()),
85
+ }
86
+ }
87
+
88
+ #[wasm_bindgen(getter = "deleteTransition")]
89
+ pub fn get_delete_transition(&self) -> Result<DocumentDeleteTransitionWASM, JsValue> {
90
+ match self.0.clone() {
91
+ DocumentTransition::Delete(delete) => Ok(DocumentDeleteTransitionWASM::from(delete)),
92
+ _ => Err(JsValue::undefined()),
93
+ }
94
+ }
95
+
96
+ #[wasm_bindgen(getter = "purchaseTransition")]
97
+ pub fn get_purchase_transition(&self) -> Result<DocumentPurchaseTransitionWASM, JsValue> {
98
+ match self.0.clone() {
99
+ DocumentTransition::Purchase(purchase) => {
100
+ Ok(DocumentPurchaseTransitionWASM::from(purchase))
101
+ }
102
+ _ => Err(JsValue::undefined()),
103
+ }
104
+ }
105
+
106
+ #[wasm_bindgen(getter = "transferTransition")]
107
+ pub fn get_transfer_transition(&self) -> Result<DocumentTransferTransitionWASM, JsValue> {
108
+ match self.0.clone() {
109
+ DocumentTransition::Transfer(transfer) => {
110
+ Ok(DocumentTransferTransitionWASM::from(transfer))
111
+ }
112
+ _ => Err(JsValue::undefined()),
113
+ }
114
+ }
115
+
116
+ #[wasm_bindgen(getter = "updatePriceTransition")]
117
+ pub fn get_update_price_transition(
118
+ &self,
119
+ ) -> Result<DocumentUpdatePriceTransitionWASM, JsValue> {
120
+ match self.0.clone() {
121
+ DocumentTransition::UpdatePrice(update_price) => {
122
+ Ok(DocumentUpdatePriceTransitionWASM::from(update_price))
123
+ }
124
+ _ => Err(JsValue::undefined()),
125
+ }
126
+ }
127
+
128
+ #[wasm_bindgen(setter = "dataContractId")]
129
+ pub fn set_data_contract_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> {
130
+ Ok(self
131
+ .0
132
+ .set_data_contract_id(IdentifierWASM::try_from(js_data_contract_id)?.into()))
133
+ }
134
+
135
+ #[wasm_bindgen(setter = "revision")]
136
+ pub fn set_revision(&mut self, revision: Revision) {
137
+ self.0.set_revision(revision)
138
+ }
139
+
140
+ #[wasm_bindgen(setter = "identityContractNonce")]
141
+ pub fn set_identity_contract_nonce(&mut self, identity_contract_nonce: IdentityNonce) {
142
+ self.0.set_identity_contract_nonce(identity_contract_nonce)
143
+ }
144
+ }
145
+
146
+ impl DocumentTransitionWASM {
147
+ pub fn rs_get_data_contract_id(&self) -> Identifier {
148
+ self.0.data_contract_id()
149
+ }
150
+
151
+ pub fn rs_get_id(&self) -> Identifier {
152
+ self.0.get_id()
153
+ }
154
+
155
+ pub fn rs_get_entropy(&self) -> Option<Vec<u8>> {
156
+ self.0.entropy()
157
+ }
158
+
159
+ pub fn rs_get_revision(&self) -> Option<Revision> {
160
+ self.0.revision()
161
+ }
162
+
163
+ pub fn rs_get_identity_contract_nonce(&self) -> IdentityNonce {
164
+ self.0.identity_contract_nonce()
165
+ }
166
+ }