@dashevo/wasm-dpp 0.25.6 → 0.25.9

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 (95) hide show
  1. package/Cargo.toml +3 -2
  2. package/README.md +1 -1
  3. package/dist/wasm/wasm_dpp.d.ts +808 -712
  4. package/dist/wasm/wasm_dpp.js +853 -452
  5. package/dist/wasm/wasm_dpp_bg.js +1 -1
  6. package/lib/bls/bls.js +48 -0
  7. package/lib/test/fixtures/getChainAssetLockProofFixture.js +20 -1
  8. package/lib/test/fixtures/getDataContractFixture.js +4 -6
  9. package/lib/test/fixtures/getDocumentTransitionsFixture.js +31 -1
  10. package/lib/test/fixtures/getInstantAssetLockProofFixture.js +32 -12
  11. package/lib/test/mocks/getBlsAdapterMock.js +1 -1
  12. package/lib/utils/creditsConverter.js +14 -0
  13. package/lib/utils/hash.js +18 -0
  14. package/lib/wasm/wasm_dpp.d.ts +808 -712
  15. package/package.json +3 -5
  16. package/src/dash_platform_protocol.rs +5 -5
  17. package/src/document/errors/invalid_document_error.rs +5 -0
  18. package/src/document/extended_document.rs +15 -0
  19. package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +219 -214
  20. package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +1 -1
  21. package/src/errors/consensus/basic/identity/identity_insufficient_balance_error.rs +4 -2
  22. package/src/errors/consensus/basic/json_schema_error.rs +35 -5
  23. package/src/identity/identity_facade.rs +7 -5
  24. package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +32 -17
  25. package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +22 -13
  26. package/src/identity/state_transition/asset_lock_proof/mod.rs +12 -11
  27. package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +1 -0
  28. package/src/identity/state_transition/identity_create_transition/to_object.rs +1 -0
  29. package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +1 -0
  30. package/src/identity/state_transition/identity_topup_transition/to_object.rs +1 -0
  31. package/src/lib.rs +1 -1
  32. package/src/validation/mod.rs +2 -2
  33. package/src/validation/validation_result.rs +16 -15
  34. package/test/integration/document/DocumentFacade.spec.js +11 -27
  35. package/test/integration/document/stateTransition/DocumentsBatchTransition/DocumentBatchTransition.spec.js +9 -19
  36. package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/basic/validateDocumentsBatchTransitionBasicFactory.spec.js +2 -2
  37. package/test/integration/document/validation/validateDocumentFactory.spec.js +2 -2
  38. package/test/integration/identity/IdentityFacade.spec.js +1 -2
  39. package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +2 -2
  40. package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +2 -2
  41. package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +6 -8
  42. package/test/unit/document/Document.spec.js +30 -52
  43. package/test/unit/document/DocumentFactory.spec.js +2 -2
  44. package/test/unit/document/errors/InvalidDocumentError.spec.js +9 -9
  45. package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +158 -155
  46. package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/findDuplicatesByIndices.spec.js +132 -134
  47. package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/basic/validatePartialCompoundIndices.spec.js +3 -3
  48. package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +568 -591
  49. package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsUniquenessByIndicesFactory.spec.js +5 -13
  50. package/test/unit/identity/Identity.spec.js +2 -2
  51. package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +9 -28
  52. package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +19 -27
  53. package/lib/test/fixtures/getDashPayContractFixture.js +0 -1
  54. package/lib/test/fixtures/getDashPayDocumentFixture.js +0 -1
  55. package/lib/test/fixtures/getDpnsContractFixture.js +0 -1
  56. package/lib/test/fixtures/getDpnsDocumentFixture.js +0 -1
  57. package/lib/test/fixtures/getFeatureFlagsContractFixture.js +0 -1
  58. package/lib/test/fixtures/getFeatureFlagsDocumentsFixture.js +0 -1
  59. package/lib/test/fixtures/getIdentityTopUpTransitionFixtureJs.js +0 -1
  60. package/lib/test/fixtures/getMasternodeRewardShareDocumentsFixture.js +0 -1
  61. package/lib/test/fixtures/getMasternodeRewardSharesContractFixture.js +0 -1
  62. package/lib/test/fixtures/getPreorderDocumentFixture.js +0 -1
  63. package/lib/test/fixtures/getRawTransactionFixture.js +0 -1
  64. package/lib/test/fixtures/js/generateRandomIdentifier.js +0 -1
  65. package/lib/test/fixtures/js/getChainAssetLockProofFixture.js +0 -1
  66. package/lib/test/fixtures/js/getDataContractFixture.js +0 -1
  67. package/lib/test/fixtures/js/getDocumentTransitionsFixture.js +0 -1
  68. package/lib/test/fixtures/js/getDocumentsFixture.js +0 -1
  69. package/lib/test/fixtures/js/getInstantAssetLockProofFixture.js +0 -1
  70. package/test/integration/DashPlatformProtocol.spec.js +0 -53
  71. package/test/integration/document/stateTransition/DocumentsBatchTransition/validation/state/executeDataTriggersFactory.spec.js +0 -195
  72. package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -500
  73. package/test/integration/stateTransition/calculateStateTransitionFeeFromOperationsFactory.spec.js +0 -53
  74. package/test/unit/dataContract/getBinaryPropertiesFromSchema.spec.js +0 -103
  75. package/test/unit/dataContract/getPropertyDefinitionByPath.spec.js +0 -84
  76. package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +0 -45
  77. package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +0 -49
  78. package/test/unit/dataTrigger/DataTrigger.spec.js +0 -132
  79. package/test/unit/dataTrigger/DataTriggerExecutionContext.spec.js +0 -29
  80. package/test/unit/dataTrigger/dashpayDataTriggers/createContactRequestDataTrigger.spec.js +0 -107
  81. package/test/unit/dataTrigger/dpnsTriggers/createDomainDataTrigger.spec.js +0 -382
  82. package/test/unit/dataTrigger/featureFlagDataTriggers/createFeatureFlagDataTrigger.spec.js +0 -99
  83. package/test/unit/dataTrigger/getDataTriggersFactory.spec.js +0 -113
  84. package/test/unit/dataTrigger/rejectDataTrigger.spec.js +0 -51
  85. package/test/unit/dataTrigger/rewardShareDataTriggers/createMasternodeRewardSharesDataTrigger.spec.js +0 -202
  86. package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +0 -256
  87. package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/fetchDocumentsFactory.spec.js +0 -94
  88. package/test/unit/errors/consensus/codes.spec.js +0 -102
  89. package/test/unit/identity/creditsConverter.spec.js +0 -34
  90. package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +0 -83
  91. package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +0 -138
  92. package/test/unit/identity/stateTransition/IdentityUpdateTransition/applyIdentityUpdateTransitionFactory.spec.js +0 -100
  93. package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +0 -36
  94. package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +0 -63
  95. package/test/unit/identity/validation/validateRequiredPurposeAndSecurityLevelFactory.spec.js +0 -47
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dashevo/wasm-dpp",
3
- "version": "0.25.6",
3
+ "version": "0.25.9",
4
4
  "description": "The JavaScript implementation of the Dash Platform Protocol",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,10 +43,8 @@
43
43
  "@babel/cli": "^7.21.0",
44
44
  "@babel/core": "^7.15.5",
45
45
  "@babel/preset-env": "^7.15.4",
46
- "@dashevo/dashcore-lib": "~0.20.9",
47
- "@dashevo/dpns-contract": "0.25.6",
48
- "@dashevo/dpp": "0.25.6",
49
- "@dashevo/wasm-re2": "~2.0.4",
46
+ "@dashevo/dashcore-lib": "~0.21.0",
47
+ "@dashevo/dpns-contract": "0.25.9",
50
48
  "@types/bs58": "^4.0.1",
51
49
  "@types/node": "^14.6.0",
52
50
  "@yarnpkg/pnpify": "^4.0.0-rc.42",
@@ -79,11 +79,11 @@ impl DashPlatformProtocolWasm {
79
79
  pub fn state_transition(&self) -> StateTransitionFactoryWasm {
80
80
  self.protocol.state_transition().into()
81
81
  }
82
- //
83
- // #[wasm_bindgen(getter = protocolVersion)]
84
- // pub fn protocol_version(&self) -> u32 {
85
- // self.protocol_version
86
- // }
82
+
83
+ #[wasm_bindgen(getter = protocolVersion)]
84
+ pub fn protocol_version(&self) -> u32 {
85
+ self.protocol.protocol_version
86
+ }
87
87
  //
88
88
  // #[wasm_bindgen(js_name = getProtocolVersion)]
89
89
  // pub fn get_protocol_version(&self) -> u32 {
@@ -30,4 +30,9 @@ impl InvalidDocumentError {
30
30
  pub fn get_document(&self) -> JsValue {
31
31
  self.raw_document.clone()
32
32
  }
33
+
34
+ #[wasm_bindgen(js_name=getMessage)]
35
+ pub fn get_message(&self) -> String {
36
+ self.to_string()
37
+ }
33
38
  }
@@ -27,6 +27,7 @@ use crate::identifier::{identifier_from_js_value, IdentifierWrapper};
27
27
  use crate::lodash::lodash_set;
28
28
  use crate::metadata::MetadataWasm;
29
29
  use crate::utils::{with_serde_to_platform_value, IntoWasm, ToSerdeJSONExt, WithJsError};
30
+ use crate::validation::ValidationResultWasm;
30
31
  use crate::with_js_error;
31
32
 
32
33
  #[wasm_bindgen(js_name=ExtendedDocument)]
@@ -345,6 +346,20 @@ impl ExtendedDocumentWasm {
345
346
  pub fn deep_clone(&self) -> Self {
346
347
  self.clone()
347
348
  }
349
+
350
+ #[wasm_bindgen]
351
+ pub fn validate(&self, platform_version: u32) -> Result<ValidationResultWasm, JsValue> {
352
+ let platform_version =
353
+ PlatformVersion::get(platform_version).map_err(|e| JsValue::from(e.to_string()))?;
354
+
355
+ let result = self
356
+ .0
357
+ .validate(platform_version)
358
+ .with_js_error()?
359
+ .map(|_| JsValue::undefined());
360
+
361
+ Ok(result.into())
362
+ }
348
363
  }
349
364
 
350
365
  impl ExtendedDocumentWasm {
@@ -59,226 +59,231 @@ impl From<DocumentCreateTransitionWasm> for DocumentCreateTransition {
59
59
 
60
60
  #[wasm_bindgen(js_class=DocumentCreateTransition)]
61
61
  impl DocumentCreateTransitionWasm {
62
- #[wasm_bindgen(constructor)]
63
- pub fn from_object(
64
- raw_object: JsValue,
65
- data_contract: &DataContractWasm,
66
- ) -> Result<DocumentCreateTransitionWasm, JsValue> {
67
- let data_contract: DataContract = data_contract.clone().into();
68
- let mut value = raw_object.with_serde_to_platform_value_map()?;
69
- // let document_type = value
70
- // .get_string(dpp::document::extended_document::property_names::DOCUMENT_TYPE_NAME)
71
- // .map_err(ProtocolError::ValueError)
72
- // .with_js_error()?;
73
- //
74
- // let (identifier_paths, _): (Vec<_>, Vec<_>) = data_contract
75
- // .get_identifiers_and_binary_paths_owned(document_type.as_str())
76
- // .with_js_error()?;
77
- // value
78
- // .replace_at_paths(identifier_paths, ReplacementType::Identifier)
79
- // .map_err(ProtocolError::ValueError)
80
- // .with_js_error()?;
81
- let transition =
82
- DocumentCreateTransition::from_value_map(value, data_contract).with_js_error()?;
83
-
84
- Ok(transition.into())
85
- }
86
-
87
- // DocumentCreateTransition
88
- #[wasm_bindgen(js_name=getEntropy)]
89
- pub fn entropy(&self) -> Vec<u8> {
90
- self.inner.entropy().to_vec()
91
- }
92
-
93
- #[wasm_bindgen(js_name=getCreatedAt)]
94
- pub fn created_at(&self) -> Option<js_sys::Date> {
95
- self.inner
96
- .created_at()
97
- .map(|timestamp| js_sys::Date::new(&JsValue::from_f64(timestamp as f64)))
98
- }
99
-
100
- #[wasm_bindgen(js_name=getUpdatedAt)]
101
- pub fn updated_at(&self) -> Option<js_sys::Date> {
102
- self.inner
103
- .updated_at()
104
- .map(|timestamp| js_sys::Date::new(&JsValue::from_f64(timestamp as f64)))
105
- }
62
+ // #[wasm_bindgen(constructor)]
63
+ // pub fn from_object(
64
+ // raw_object: JsValue,
65
+ // data_contract: &DataContractWasm,
66
+ // ) -> Result<DocumentCreateTransitionWasm, JsValue> {
67
+ // let data_contract: DataContract = data_contract.clone().into();
68
+ // let mut value = raw_object.with_serde_to_platform_value_map()?;
69
+ // // let document_type = value
70
+ // // .get_string(dpp::document::extended_document::property_names::DOCUMENT_TYPE_NAME)
71
+ // // .map_err(ProtocolError::ValueError)
72
+ // // .with_js_error()?;
73
+ // //
74
+ // // let (identifier_paths, _): (Vec<_>, Vec<_>) = data_contract
75
+ // // .get_identifiers_and_binary_paths_owned(document_type.as_str())
76
+ // // .with_js_error()?;
77
+ // // value
78
+ // // .replace_at_paths(identifier_paths, ReplacementType::Identifier)
79
+ // // .map_err(ProtocolError::ValueError)
80
+ // // .with_js_error()?;
81
+ // let transition =
82
+ // DocumentCreateTransition::from_value_map(value, data_contract).with_js_error()?;
83
+ //
84
+ // Ok(transition.into())
85
+ // }
86
+ //
87
+ // // DocumentCreateTransition
88
+ // #[wasm_bindgen(js_name=getEntropy)]
89
+ // pub fn entropy(&self) -> Vec<u8> {
90
+ // self.inner.entropy().to_vec()
91
+ // }
92
+ //
93
+ // #[wasm_bindgen(js_name=getCreatedAt)]
94
+ // pub fn created_at(&self) -> Option<js_sys::Date> {
95
+ // self.inner
96
+ // .created_at()
97
+ // .map(|timestamp| js_sys::Date::new(&JsValue::from_f64(timestamp as f64)))
98
+ // }
99
+ //
100
+ // #[wasm_bindgen(js_name=getUpdatedAt)]
101
+ // pub fn updated_at(&self) -> Option<js_sys::Date> {
102
+ // self.inner
103
+ // .updated_at()
104
+ // .map(|timestamp| js_sys::Date::new(&JsValue::from_f64(timestamp as f64)))
105
+ // }
106
106
 
107
107
  #[wasm_bindgen(js_name=getRevision)]
108
108
  pub fn revision(&self) -> Revision {
109
109
  INITIAL_REVISION
110
110
  }
111
111
 
112
- // AbstractDocumentTransitionMethods
113
- #[wasm_bindgen(js_name=getId)]
114
- pub fn id(&self) -> IdentifierWrapper {
115
- self.inner.base().id().into()
116
- }
117
-
118
- #[wasm_bindgen(js_name=getType)]
119
- pub fn document_type(&self) -> String {
120
- self.inner.base().document_type_name().clone()
121
- }
122
-
123
- #[wasm_bindgen(js_name=getAction)]
124
- pub fn action(&self) -> u8 {
125
- DocumentTransitionActionType::Create as u8
126
- }
127
-
128
- #[wasm_bindgen(js_name=getDataContractId)]
129
- pub fn data_contract_id(&self) -> IdentifierWrapper {
130
- self.inner.base().data_contract_id().into()
131
- }
132
-
133
- #[wasm_bindgen]
134
- pub fn get(&self, path: String, data_contract: &DataContractWasm) -> Result<JsValue, JsValue> {
135
- let document_data = self.inner.data();
136
-
137
- let value = if let Ok(value) = document_data.get_at_path(&path) {
138
- value.clone()
139
- } else {
140
- return Ok(JsValue::undefined());
141
- };
142
-
143
- match self.get_binary_type_of_path(&path) {
144
- BinaryType::Buffer => {
145
- let bytes = value
146
- .to_bytes()
147
- .map_err(ProtocolError::ValueError)
148
- .with_js_error()?;
149
- let buffer = Buffer::from_bytes(&bytes);
150
- return Ok(buffer.into());
151
- }
152
- BinaryType::Identifier => {
153
- let buffer = value
154
- .to_hash256()
155
- .map_err(ProtocolError::ValueError)
156
- .with_js_error()?;
157
- let id = <IdentifierWrapper as convert::From<Identifier>>::from(Identifier::from(
158
- buffer,
159
- ));
160
- return Ok(id.into());
161
- }
162
- BinaryType::None => {
163
- // Do nothing. If is 'None' it means that binary may contain binary data
164
- // or may not captain it at all
165
- }
166
- }
167
-
168
- let json_value: JsonValue = value
169
- .clone()
170
- .try_into()
171
- .map_err(ProtocolError::ValueError)
172
- .with_js_error()?;
173
- let map = value
174
- .to_btree_ref_string_map()
175
- .map_err(ProtocolError::ValueError)
176
- .with_js_error()?;
177
- let js_value = json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?;
178
-
179
- let document_type = data_contract
180
- .inner()
181
- .document_type_for_name(self.inner.base().document_type_name())
182
- .with_js_error()?;
183
- let identifier_paths = document_type.identifier_paths();
184
- let binary_paths = document_type.binary_paths();
185
-
186
- for property_path in identifier_paths {
187
- if property_path.starts_with(&path) {
188
- let (_, suffix) = property_path.split_at(path.len() + 1);
189
-
190
- if let Some(bytes) = map
191
- .get_optional_bytes_at_path(suffix)
192
- .map_err(ProtocolError::ValueError)
193
- .with_js_error()?
194
- {
195
- let id = <IdentifierWrapper as convert::From<Identifier>>::from(
196
- Identifier::from_bytes(&bytes).unwrap(),
197
- );
198
- lodash_set(&js_value, suffix, id.into());
199
- }
200
- }
201
- }
202
-
203
- for property_path in binary_paths {
204
- if property_path.starts_with(&path) {
205
- let (_, suffix) = property_path.split_at(path.len() + 1);
206
-
207
- if let Some(bytes) = map
208
- .get_optional_bytes_at_path(suffix)
209
- .map_err(ProtocolError::ValueError)
210
- .with_js_error()?
211
- {
212
- let buffer = Buffer::from_bytes(&bytes);
213
- lodash_set(&js_value, suffix, buffer.into());
214
- }
215
- }
216
- }
217
- Ok(js_value)
218
- }
219
-
220
- // DocumentTransitionObjectLike
221
- #[wasm_bindgen(js_name=toObject)]
222
- pub fn to_object(&self, options: &JsValue) -> Result<JsValue, JsValue> {
223
- let (identifiers_paths, binary_paths) = self
224
- .inner
225
- .base()
226
- .data_contract
227
- .get_identifiers_and_binary_paths(&self.inner.base().document_type_name)
228
- .with_js_error()?;
229
-
230
- to_object(
231
- self.inner.to_object().with_js_error()?,
232
- options,
233
- identifiers_paths
234
- .into_iter()
235
- .chain(document_create_transition::v0::IDENTIFIER_FIELDS),
236
- binary_paths
237
- .into_iter()
238
- .chain(document_create_transition::v0::BINARY_FIELDS),
239
- )
240
- }
241
-
242
- #[wasm_bindgen(js_name=toJSON)]
243
- pub fn to_json(&self) -> Result<JsValue, JsValue> {
244
- let value = self.inner.to_json().with_js_error()?;
245
- let serializer = serde_wasm_bindgen::Serializer::json_compatible();
246
- let js_value = value.serialize(&serializer)?;
247
- Ok(js_value)
112
+ #[wasm_bindgen(getter, js_name=INITIAL_REVISION)]
113
+ pub fn initial_revision() -> u32 {
114
+ INITIAL_REVISION as u32
248
115
  }
249
116
 
250
- // AbstractDataDocumentTransition
251
- #[wasm_bindgen(js_name=getData)]
252
- pub fn get_data(&self) -> Result<JsValue, JsValue> {
253
- let json_data = if let Some(ref data) = self.inner.data() {
254
- data.to_json_value()
255
- .map_err(ProtocolError::ValueError)
256
- .with_js_error()?
257
- } else {
258
- return Ok(JsValue::undefined());
259
- };
260
-
261
- let js_value = json_data.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?;
262
- Ok(js_value)
263
- }
264
- }
265
-
266
- impl DocumentCreateTransitionWasm {
267
- fn get_binary_type_of_path(&self, path: &String) -> BinaryType {
268
- let maybe_binary_properties = self
269
- .inner
270
- .base
271
- .data_contract
272
- .get_binary_properties(&self.inner.base.document_type_name);
273
-
274
- if let Ok(binary_properties) = maybe_binary_properties {
275
- if let Some(data) = binary_properties.get(path) {
276
- if data.is_type_of_identifier() {
277
- return BinaryType::Identifier;
278
- }
279
- return BinaryType::Buffer;
280
- }
281
- }
282
- BinaryType::None
283
- }
117
+ // // AbstractDocumentTransitionMethods
118
+ // #[wasm_bindgen(js_name=getId)]
119
+ // pub fn id(&self) -> IdentifierWrapper {
120
+ // self.inner.base().id().into()
121
+ // }
122
+ //
123
+ // #[wasm_bindgen(js_name=getType)]
124
+ // pub fn document_type(&self) -> String {
125
+ // self.inner.base().document_type_name().clone()
126
+ // }
127
+ //
128
+ // #[wasm_bindgen(js_name=getAction)]
129
+ // pub fn action(&self) -> u8 {
130
+ // DocumentTransitionActionType::Create as u8
131
+ // }
132
+ //
133
+ // #[wasm_bindgen(js_name=getDataContractId)]
134
+ // pub fn data_contract_id(&self) -> IdentifierWrapper {
135
+ // self.inner.base().data_contract_id().into()
136
+ // }
137
+ //
138
+ // #[wasm_bindgen]
139
+ // pub fn get(&self, path: String, data_contract: &DataContractWasm) -> Result<JsValue, JsValue> {
140
+ // let document_data = self.inner.data();
141
+ //
142
+ // let value = if let Ok(value) = document_data.get_at_path(&path) {
143
+ // value.clone()
144
+ // } else {
145
+ // return Ok(JsValue::undefined());
146
+ // };
147
+ //
148
+ // match self.get_binary_type_of_path(&path) {
149
+ // BinaryType::Buffer => {
150
+ // let bytes = value
151
+ // .to_bytes()
152
+ // .map_err(ProtocolError::ValueError)
153
+ // .with_js_error()?;
154
+ // let buffer = Buffer::from_bytes(&bytes);
155
+ // return Ok(buffer.into());
156
+ // }
157
+ // BinaryType::Identifier => {
158
+ // let buffer = value
159
+ // .to_hash256()
160
+ // .map_err(ProtocolError::ValueError)
161
+ // .with_js_error()?;
162
+ // let id = <IdentifierWrapper as convert::From<Identifier>>::from(Identifier::from(
163
+ // buffer,
164
+ // ));
165
+ // return Ok(id.into());
166
+ // }
167
+ // BinaryType::None => {
168
+ // // Do nothing. If is 'None' it means that binary may contain binary data
169
+ // // or may not captain it at all
170
+ // }
171
+ // }
172
+ //
173
+ // let json_value: JsonValue = value
174
+ // .clone()
175
+ // .try_into()
176
+ // .map_err(ProtocolError::ValueError)
177
+ // .with_js_error()?;
178
+ // let map = value
179
+ // .to_btree_ref_string_map()
180
+ // .map_err(ProtocolError::ValueError)
181
+ // .with_js_error()?;
182
+ // let js_value = json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?;
183
+ //
184
+ // let document_type = data_contract
185
+ // .inner()
186
+ // .document_type_for_name(self.inner.base().document_type_name())
187
+ // .with_js_error()?;
188
+ // let identifier_paths = document_type.identifier_paths();
189
+ // let binary_paths = document_type.binary_paths();
190
+ //
191
+ // for property_path in identifier_paths {
192
+ // if property_path.starts_with(&path) {
193
+ // let (_, suffix) = property_path.split_at(path.len() + 1);
194
+ //
195
+ // if let Some(bytes) = map
196
+ // .get_optional_bytes_at_path(suffix)
197
+ // .map_err(ProtocolError::ValueError)
198
+ // .with_js_error()?
199
+ // {
200
+ // let id = <IdentifierWrapper as convert::From<Identifier>>::from(
201
+ // Identifier::from_bytes(&bytes).unwrap(),
202
+ // );
203
+ // lodash_set(&js_value, suffix, id.into());
204
+ // }
205
+ // }
206
+ // }
207
+ //
208
+ // for property_path in binary_paths {
209
+ // if property_path.starts_with(&path) {
210
+ // let (_, suffix) = property_path.split_at(path.len() + 1);
211
+ //
212
+ // if let Some(bytes) = map
213
+ // .get_optional_bytes_at_path(suffix)
214
+ // .map_err(ProtocolError::ValueError)
215
+ // .with_js_error()?
216
+ // {
217
+ // let buffer = Buffer::from_bytes(&bytes);
218
+ // lodash_set(&js_value, suffix, buffer.into());
219
+ // }
220
+ // }
221
+ // }
222
+ // Ok(js_value)
223
+ // }
224
+ //
225
+ // // DocumentTransitionObjectLike
226
+ // #[wasm_bindgen(js_name=toObject)]
227
+ // pub fn to_object(&self, options: &JsValue) -> Result<JsValue, JsValue> {
228
+ // let (identifiers_paths, binary_paths) = self
229
+ // .inner
230
+ // .base()
231
+ // .data_contract
232
+ // .get_identifiers_and_binary_paths(&self.inner.base().document_type_name)
233
+ // .with_js_error()?;
234
+ //
235
+ // to_object(
236
+ // self.inner.to_object().with_js_error()?,
237
+ // options,
238
+ // identifiers_paths
239
+ // .into_iter()
240
+ // .chain(document_create_transition::v0::IDENTIFIER_FIELDS),
241
+ // binary_paths
242
+ // .into_iter()
243
+ // .chain(document_create_transition::v0::BINARY_FIELDS),
244
+ // )
245
+ // }
246
+ //
247
+ // #[wasm_bindgen(js_name=toJSON)]
248
+ // pub fn to_json(&self) -> Result<JsValue, JsValue> {
249
+ // let value = self.inner.to_json().with_js_error()?;
250
+ // let serializer = serde_wasm_bindgen::Serializer::json_compatible();
251
+ // let js_value = value.serialize(&serializer)?;
252
+ // Ok(js_value)
253
+ // }
254
+ //
255
+ // // AbstractDataDocumentTransition
256
+ // #[wasm_bindgen(js_name=getData)]
257
+ // pub fn get_data(&self) -> Result<JsValue, JsValue> {
258
+ // let json_data = if let Some(ref data) = self.inner.data() {
259
+ // data.to_json_value()
260
+ // .map_err(ProtocolError::ValueError)
261
+ // .with_js_error()?
262
+ // } else {
263
+ // return Ok(JsValue::undefined());
264
+ // };
265
+ //
266
+ // let js_value = json_data.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?;
267
+ // Ok(js_value)
268
+ // }
269
+ // }
270
+ //
271
+ // impl DocumentCreateTransitionWasm {
272
+ // fn get_binary_type_of_path(&self, path: &String) -> BinaryType {
273
+ // let maybe_binary_properties = self
274
+ // .inner
275
+ // .base
276
+ // .data_contract
277
+ // .get_binary_properties(&self.inner.base.document_type_name);
278
+ //
279
+ // if let Ok(binary_properties) = maybe_binary_properties {
280
+ // if let Some(data) = binary_properties.get(path) {
281
+ // if data.is_type_of_identifier() {
282
+ // return BinaryType::Identifier;
283
+ // }
284
+ // return BinaryType::Buffer;
285
+ // }
286
+ // }
287
+ // BinaryType::None
288
+ // }
284
289
  }
@@ -1,4 +1,4 @@
1
- // mod document_create_transition;
1
+ mod document_create_transition;
2
2
  // mod document_delete_transition;
3
3
  // mod document_replace_transition;
4
4
 
@@ -1,8 +1,10 @@
1
1
  use crate::buffer::Buffer;
2
+ use crate::identifier::IdentifierWrapper;
2
3
  use dpp::consensus::codes::ErrorWithCode;
3
4
  use dpp::consensus::state::identity::IdentityInsufficientBalanceError;
4
5
  use dpp::consensus::ConsensusError;
5
6
  use dpp::serialization::PlatformSerializable;
7
+ use std::ops::Deref;
6
8
  use wasm_bindgen::prelude::*;
7
9
 
8
10
  #[wasm_bindgen(js_name=IdentityInsufficientBalanceError)]
@@ -19,8 +21,8 @@ impl From<&IdentityInsufficientBalanceError> for IdentityInsufficientBalanceErro
19
21
  #[wasm_bindgen(js_class=IdentityInsufficientBalanceError)]
20
22
  impl IdentityInsufficientBalanceErrorWasm {
21
23
  #[wasm_bindgen(js_name=getIdentityId)]
22
- pub fn identity_id(&self) -> Buffer {
23
- Buffer::from_bytes(self.inner.identity_id.as_bytes())
24
+ pub fn identity_id(&self) -> IdentifierWrapper {
25
+ (*self.inner.identity_id()).into()
24
26
  }
25
27
 
26
28
  #[wasm_bindgen(js_name=getBalance)]
@@ -24,27 +24,27 @@ impl From<&JsonSchemaError> for JsonSchemaErrorWasm {
24
24
  #[wasm_bindgen(js_class=JsonSchemaError)]
25
25
  impl JsonSchemaErrorWasm {
26
26
  #[wasm_bindgen(js_name=getKeyword)]
27
- pub fn keyword(&self) -> String {
27
+ pub fn get_keyword(&self) -> String {
28
28
  self.inner.keyword().to_string()
29
29
  }
30
30
 
31
31
  #[wasm_bindgen(js_name=getInstancePath)]
32
- pub fn instance_path(&self) -> String {
32
+ pub fn get_instance_path(&self) -> String {
33
33
  self.inner.instance_path().to_string()
34
34
  }
35
35
 
36
36
  #[wasm_bindgen(js_name=getSchemaPath)]
37
- pub fn schema_path(&self) -> String {
37
+ pub fn get_schema_path(&self) -> String {
38
38
  self.inner.schema_path().to_string()
39
39
  }
40
40
 
41
41
  #[wasm_bindgen(js_name=getPropertyName)]
42
- pub fn property_name(&self) -> String {
42
+ pub fn get_property_name(&self) -> String {
43
43
  self.inner.property_name().to_string()
44
44
  }
45
45
 
46
46
  #[wasm_bindgen(js_name=getParams)]
47
- pub fn params(&self) -> Result<JsValue, JsError> {
47
+ pub fn get_params(&self) -> Result<JsValue, JsError> {
48
48
  let ser = serde_wasm_bindgen::Serializer::json_compatible();
49
49
 
50
50
  self.inner.params().serialize(&ser).map_err(|e| e.into())
@@ -64,4 +64,34 @@ impl JsonSchemaErrorWasm {
64
64
  pub fn message(&self) -> String {
65
65
  self.inner.to_string()
66
66
  }
67
+
68
+ #[wasm_bindgen(getter)]
69
+ pub fn keyword(&self) -> String {
70
+ self.get_keyword()
71
+ }
72
+
73
+ #[wasm_bindgen(getter, js_name=instancePath)]
74
+ pub fn instance_path(&self) -> String {
75
+ self.get_instance_path()
76
+ }
77
+
78
+ #[wasm_bindgen(getter, js_name=schemaPath)]
79
+ pub fn schema_path(&self) -> String {
80
+ self.get_schema_path()
81
+ }
82
+
83
+ #[wasm_bindgen(getter, js_name=propertyName)]
84
+ pub fn property_name(&self) -> String {
85
+ self.get_property_name()
86
+ }
87
+
88
+ #[wasm_bindgen(getter)]
89
+ pub fn params(&self) -> Result<JsValue, JsError> {
90
+ self.get_params()
91
+ }
92
+
93
+ #[wasm_bindgen(getter)]
94
+ pub fn code(&self) -> u32 {
95
+ self.get_code()
96
+ }
67
97
  }
@@ -128,12 +128,14 @@ impl IdentityFacadeWasm {
128
128
  instant_lock: Vec<u8>,
129
129
  asset_lock_transaction: Vec<u8>,
130
130
  output_index: u32,
131
- ) -> Result<InstantAssetLockProofWasm, JsValue> {
132
- let instant_lock: InstantLock =
133
- consensus::deserialize(&instant_lock).map_err(|e| e.to_string())?;
131
+ ) -> Result<InstantAssetLockProofWasm, JsError> {
132
+ let instant_lock: InstantLock = consensus::deserialize(&instant_lock)
133
+ .map_err(|e| JsError::new(format!("can't deserialize instant lock: {e}").as_str()))?;
134
134
 
135
- let asset_lock_transaction: Transaction =
136
- consensus::deserialize(&asset_lock_transaction).map_err(|e| e.to_string())?;
135
+ let asset_lock_transaction: Transaction = consensus::deserialize(&asset_lock_transaction)
136
+ .map_err(|e| {
137
+ JsError::new(format!("can't deserialize transaction: {e}").as_str())
138
+ })?;
137
139
 
138
140
  Ok(IdentityFacade::create_instant_lock_proof(
139
141
  instant_lock,