@dashevo/wasm-dpp 0.24.0-dev.10 → 0.24.0-dev.12
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.
- package/Cargo.toml +2 -0
- package/dist/index.js +1 -1
- package/dist/lib/dpp.d.ts +9 -0
- package/dist/lib/errors/AbstractConsensusError.d.ts +10 -0
- package/dist/lib/errors/DPPError.d.ts +5 -0
- package/dist/lib/errors/patchConsensusErrors.d.ts +1 -0
- package/dist/lib/{patchIdentifier.d.ts → identifier/patchIdentifier.d.ts} +1 -1
- package/dist/{index.d.ts → lib/index.d.ts} +1 -1
- package/dist/lib/utils/extend.d.ts +1 -0
- package/dist/wasm/wasm_dpp.d.ts +503 -262
- package/lib/dpp.ts +24 -0
- package/lib/errors/AbstractConsensusError.ts +13 -0
- package/lib/errors/DPPError.ts +15 -0
- package/lib/errors/patchConsensusErrors.ts +175 -0
- package/lib/{patchIdentifier.ts → identifier/patchIdentifier.ts} +1 -1
- package/{index.ts → lib/index.ts} +4 -3
- package/lib/test/expect/expectError.js +4 -2
- package/lib/utils/extend.ts +6 -0
- package/package.json +5 -5
- package/src/data_contract/errors/invalid_data_contract.rs +21 -0
- package/src/data_contract/state_transition/data_contract_create_transition/apply.rs +44 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +107 -6
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +24 -0
- package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +44 -0
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +147 -0
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +46 -0
- package/src/data_contract/state_transition/mod.rs +2 -0
- package/src/data_contract_factory/data_contract_factory.rs +27 -12
- package/src/document/errors/document_already_exists_error.rs +1 -1
- package/src/document/errors/document_not_provided_error.rs +1 -1
- package/src/document/errors/invalid_document_action_error.rs +1 -1
- package/src/errors/consensus/basic/data_contract/data_contract_max_depth_exceed_error.rs +5 -5
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +4 -4
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +36 -0
- package/src/errors/consensus/basic/document/missing_document_transition_type_error.rs +20 -0
- package/src/errors/consensus/basic/document/mod.rs +4 -0
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +2 -2
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +2 -2
- package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +2 -2
- package/src/errors/consensus/basic/json_schema_error.rs +1 -1
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_condition_error.rs +1 -1
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_execution_error.rs +1 -1
- package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_invalid_result_error.rs +1 -1
- package/src/errors/consensus_error.rs +15 -8
- package/src/errors/from.rs +1 -1
- package/src/errors/mod.rs +1 -0
- package/src/errors/protocol_error.rs +12 -0
- package/src/{identifier.rs → identifier/mod.rs} +0 -0
- package/src/{identity_facade.rs → identity/identity_facade.rs} +1 -1
- package/src/{identity_public_key → identity/identity_public_key}/key_type.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/mod.rs +0 -3
- package/src/{identity_public_key → identity/identity_public_key}/purpose.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/security_level.rs +0 -0
- package/src/{identity.rs → identity/mod.rs} +6 -7
- package/src/identity/validation/mod.rs +3 -0
- package/src/identity/validation/public_keys_validator.rs +70 -0
- package/src/lib.rs +4 -8
- package/src/state_repository.rs +229 -0
- package/src/state_transition/mod.rs +41 -0
- package/src/utils.rs +2 -2
- package/src/validation/mod.rs +3 -0
- package/src/{validation_result.rs → validation/validation_result.rs} +0 -0
- package/test/integration/identity/stateTransition/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +1 -1
- package/test/integration/identity/validation/validatePublicKeysFactory.spec.js +79 -114
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -11
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +1 -1
- package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +135 -0
- package/test/unit/dataContract/DataContract.spec.js +5 -9
- package/test/unit/dataContract/DataContractFactory.spec.js +13 -6
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +11 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +17 -64
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/applyDataContractCreateTransitionFactory.spec.js +28 -22
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +49 -42
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +23 -59
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +27 -23
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +29 -12
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +66 -49
- package/test/unit/dataContract/validation/validateDataContractPatterns.spec.js +73 -0
- package/test/unit/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +1 -1
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +1 -1
- package/test/unit/identity/IdentityPublicKey.spec.js +25 -31
- package/tsconfig.json +1 -1
- package/wasm/wasm_dpp.d.ts +503 -262
- package/wasm/wasm_dpp.js +925 -310
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +273 -225
- package/webpack.config.js +1 -1
- package/src/identity_public_key/public_keys_validator.rs +0 -44
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +0 -32
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +0 -93
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +0 -64
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
mod apply;
|
|
2
|
+
mod validation;
|
|
3
|
+
|
|
4
|
+
pub use apply::*;
|
|
5
|
+
pub use validation::*;
|
|
6
|
+
|
|
7
|
+
use dpp::{
|
|
8
|
+
data_contract::state_transition::DataContractUpdateTransition,
|
|
9
|
+
state_transition::{
|
|
10
|
+
StateTransitionConvert, StateTransitionIdentitySigned, StateTransitionLike,
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
use serde::{Deserialize, Serialize};
|
|
14
|
+
use wasm_bindgen::prelude::*;
|
|
15
|
+
|
|
16
|
+
use crate::{
|
|
17
|
+
buffer::Buffer,
|
|
18
|
+
errors::{from_dpp_err, RustConversionError},
|
|
19
|
+
identifier::IdentifierWrapper,
|
|
20
|
+
with_js_error, DataContractParameters, DataContractWasm, StateTransitionExecutionContextWasm,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
#[wasm_bindgen(js_name=DataContractUpdateTransition)]
|
|
24
|
+
pub struct DataContractUpdateTransitionWasm(DataContractUpdateTransition);
|
|
25
|
+
|
|
26
|
+
impl From<DataContractUpdateTransition> for DataContractUpdateTransitionWasm {
|
|
27
|
+
fn from(v: DataContractUpdateTransition) -> Self {
|
|
28
|
+
DataContractUpdateTransitionWasm(v)
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
impl From<DataContractUpdateTransitionWasm> for DataContractUpdateTransition {
|
|
33
|
+
fn from(val: DataContractUpdateTransitionWasm) -> Self {
|
|
34
|
+
val.0
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[derive(Debug, Serialize, Deserialize)]
|
|
39
|
+
#[serde(rename_all = "camelCase")]
|
|
40
|
+
struct DataContractUpdateTransitionParameters {
|
|
41
|
+
protocol_version: u32,
|
|
42
|
+
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
43
|
+
data_contract: Option<DataContractParameters>,
|
|
44
|
+
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
45
|
+
entropy: Option<Vec<u8>>,
|
|
46
|
+
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
47
|
+
signature_public_key_id: Option<u64>,
|
|
48
|
+
#[serde(skip_serializing_if = "Option::is_none", default)]
|
|
49
|
+
signature: Option<Vec<u8>>,
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[wasm_bindgen(js_class=DataContractUpdateTransition)]
|
|
53
|
+
impl DataContractUpdateTransitionWasm {
|
|
54
|
+
#[wasm_bindgen(constructor)]
|
|
55
|
+
pub fn new(raw_parameters: JsValue) -> Result<DataContractUpdateTransitionWasm, JsValue> {
|
|
56
|
+
let parameters: DataContractUpdateTransitionParameters =
|
|
57
|
+
with_js_error!(serde_wasm_bindgen::from_value(raw_parameters))?;
|
|
58
|
+
DataContractUpdateTransition::from_raw_object(
|
|
59
|
+
serde_json::to_value(parameters).expect("the struct will be a valid json"),
|
|
60
|
+
)
|
|
61
|
+
.map(Into::into)
|
|
62
|
+
.map_err(from_dpp_err)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[wasm_bindgen(js_name=getDataContract)]
|
|
66
|
+
pub fn get_data_contract(&self) -> DataContractWasm {
|
|
67
|
+
self.0.data_contract.clone().into()
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#[wasm_bindgen(js_name=getProtocolVersion)]
|
|
71
|
+
pub fn get_protocol_version(&self) -> u32 {
|
|
72
|
+
self.0.protocol_version
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[wasm_bindgen(js_name=getEntropy)]
|
|
76
|
+
pub fn get_entropy(&self) -> Buffer {
|
|
77
|
+
Buffer::from_bytes(&self.0.data_contract.entropy)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
#[wasm_bindgen(js_name=getOwnerId)]
|
|
81
|
+
pub fn get_owner_id(&self) -> IdentifierWrapper {
|
|
82
|
+
self.0.get_owner_id().clone().into()
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#[wasm_bindgen(js_name=getType)]
|
|
86
|
+
pub fn get_type(&self) -> u32 {
|
|
87
|
+
self.0.get_type() as u32
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
91
|
+
pub fn to_json(&self, skip_signature: Option<bool>) -> Result<JsValue, JsValue> {
|
|
92
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
93
|
+
Ok(self
|
|
94
|
+
.0
|
|
95
|
+
.to_json(skip_signature.unwrap_or(false))
|
|
96
|
+
.map_err(from_dpp_err)?
|
|
97
|
+
.serialize(&serializer)
|
|
98
|
+
.expect("JSON is a valid object"))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#[wasm_bindgen(js_name=toBuffer)]
|
|
102
|
+
pub fn to_buffer(&self, skip_signature: Option<bool>) -> Result<Buffer, JsValue> {
|
|
103
|
+
let bytes = self
|
|
104
|
+
.0
|
|
105
|
+
.to_buffer(skip_signature.unwrap_or(false))
|
|
106
|
+
.map_err(from_dpp_err)?;
|
|
107
|
+
Ok(Buffer::from_bytes(&bytes))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#[wasm_bindgen(js_name=getModifiedDataIds)]
|
|
111
|
+
pub fn get_modified_data_ids(&self) -> Vec<JsValue> {
|
|
112
|
+
self.0
|
|
113
|
+
.get_modified_data_ids()
|
|
114
|
+
.into_iter()
|
|
115
|
+
.map(|identifier| Into::<IdentifierWrapper>::into(identifier.clone()).into())
|
|
116
|
+
.collect()
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#[wasm_bindgen(js_name=isDataContractStateTransition)]
|
|
120
|
+
pub fn is_data_contract_state_transition(&self) -> bool {
|
|
121
|
+
self.0.is_data_contract_state_transition()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[wasm_bindgen(js_name=isDocumentStateTransition)]
|
|
125
|
+
pub fn is_document_state_transition(&self) -> bool {
|
|
126
|
+
self.0.is_document_state_transition()
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[wasm_bindgen(js_name=isIdentityStateTransition)]
|
|
130
|
+
pub fn is_identity_state_transition(&self) -> bool {
|
|
131
|
+
self.0.is_identity_state_transition()
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[wasm_bindgen(js_name=setExecutionContext)]
|
|
135
|
+
pub fn set_execution_context(&mut self, context: &StateTransitionExecutionContextWasm) {
|
|
136
|
+
self.0.set_execution_context(context.into())
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#[wasm_bindgen(js_name=hash)]
|
|
140
|
+
pub fn hash(&self, skip_signature: Option<bool>) -> Result<Buffer, JsValue> {
|
|
141
|
+
let bytes = self
|
|
142
|
+
.0
|
|
143
|
+
.hash(skip_signature.unwrap_or(false))
|
|
144
|
+
.map_err(from_dpp_err)?;
|
|
145
|
+
Ok(Buffer::from_bytes(&bytes))
|
|
146
|
+
}
|
|
147
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
use std::collections::BTreeMap;
|
|
2
|
+
|
|
3
|
+
use dpp::data_contract::state_transition::data_contract_update_transition::validation::{
|
|
4
|
+
basic::validate_indices_are_backward_compatible as dpp_validate_indices_are_backward_compatible,
|
|
5
|
+
state::validate_data_contract_update_transition_state::validate_data_contract_update_transition_state as dpp_validate_data_contract_update_transition_state,
|
|
6
|
+
};
|
|
7
|
+
use wasm_bindgen::prelude::*;
|
|
8
|
+
|
|
9
|
+
use crate::{
|
|
10
|
+
errors::{from_dpp_err, protocol_error::from_protocol_error},
|
|
11
|
+
state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
|
|
12
|
+
validation::ValidationResultWasm,
|
|
13
|
+
DataContractUpdateTransitionWasm,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
#[wasm_bindgen(js_name=validateDataContractUpdateTransitionState)]
|
|
17
|
+
pub async fn validate_data_contract_update_transition_state(
|
|
18
|
+
state_repository: ExternalStateRepositoryLike,
|
|
19
|
+
state_transition: DataContractUpdateTransitionWasm,
|
|
20
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
21
|
+
let wrapped_state_repository = ExternalStateRepositoryLikeWrapper::new(state_repository);
|
|
22
|
+
dpp_validate_data_contract_update_transition_state(
|
|
23
|
+
&wrapped_state_repository,
|
|
24
|
+
&state_transition.into(),
|
|
25
|
+
)
|
|
26
|
+
.await
|
|
27
|
+
.map(Into::into)
|
|
28
|
+
.map_err(from_dpp_err)
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
#[wasm_bindgen(js_name=validateIndicesAreBackwardCompatible)]
|
|
32
|
+
pub fn validate_indices_are_backward_compatible(
|
|
33
|
+
old_documents_schema: JsValue,
|
|
34
|
+
new_documents_schema: JsValue,
|
|
35
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
36
|
+
let old_documents = serde_wasm_bindgen::from_value::<BTreeMap<String, serde_json::Value>>(
|
|
37
|
+
old_documents_schema,
|
|
38
|
+
)?;
|
|
39
|
+
let new_documents = serde_wasm_bindgen::from_value::<BTreeMap<String, serde_json::Value>>(
|
|
40
|
+
new_documents_schema,
|
|
41
|
+
)?;
|
|
42
|
+
|
|
43
|
+
dpp_validate_indices_are_backward_compatible(old_documents.iter(), new_documents.iter())
|
|
44
|
+
.map(Into::into)
|
|
45
|
+
.map_err(from_protocol_error)
|
|
46
|
+
}
|
|
@@ -12,7 +12,11 @@ use wasm_bindgen::prelude::*;
|
|
|
12
12
|
|
|
13
13
|
use crate::{
|
|
14
14
|
data_contract::errors::InvalidDataContractError,
|
|
15
|
-
errors::{
|
|
15
|
+
errors::{
|
|
16
|
+
consensus_error::from_consensus_error, from_dpp_err, protocol_error::from_protocol_error,
|
|
17
|
+
RustConversionError,
|
|
18
|
+
},
|
|
19
|
+
validation::ValidationResultWasm,
|
|
16
20
|
with_js_error, DataContractCreateTransitionWasm, DataContractParameters, DataContractWasm,
|
|
17
21
|
};
|
|
18
22
|
|
|
@@ -25,9 +29,9 @@ impl From<DataContractValidator> for DataContractValidatorWasm {
|
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
|
|
28
|
-
impl
|
|
29
|
-
fn
|
|
30
|
-
|
|
32
|
+
impl From<DataContractValidatorWasm> for DataContractValidator {
|
|
33
|
+
fn from(val: DataContractValidatorWasm) -> Self {
|
|
34
|
+
val.0
|
|
31
35
|
}
|
|
32
36
|
}
|
|
33
37
|
|
|
@@ -37,6 +41,17 @@ impl DataContractValidatorWasm {
|
|
|
37
41
|
pub fn new() -> Self {
|
|
38
42
|
DataContractValidator::new(std::sync::Arc::new(ProtocolVersionValidator::default())).into()
|
|
39
43
|
}
|
|
44
|
+
|
|
45
|
+
#[wasm_bindgen(js_name=validate)]
|
|
46
|
+
pub fn validate(&self, raw_data_contract: JsValue) -> Result<ValidationResultWasm, JsValue> {
|
|
47
|
+
let parameters: DataContractParameters =
|
|
48
|
+
with_js_error!(serde_wasm_bindgen::from_value(raw_data_contract))?;
|
|
49
|
+
let json_object = serde_json::to_value(parameters).expect("Implements Serialize");
|
|
50
|
+
self.0
|
|
51
|
+
.validate(&json_object)
|
|
52
|
+
.map(Into::into)
|
|
53
|
+
.map_err(from_protocol_error)
|
|
54
|
+
}
|
|
40
55
|
}
|
|
41
56
|
|
|
42
57
|
#[wasm_bindgen(js_name=DataContractFactory)]
|
|
@@ -48,9 +63,9 @@ impl From<DataContractFactory> for DataContractFactoryWasm {
|
|
|
48
63
|
}
|
|
49
64
|
}
|
|
50
65
|
|
|
51
|
-
impl
|
|
52
|
-
fn
|
|
53
|
-
|
|
66
|
+
impl From<DataContractFactoryWasm> for DataContractFactory {
|
|
67
|
+
fn from(val: DataContractFactoryWasm) -> Self {
|
|
68
|
+
val.0
|
|
54
69
|
}
|
|
55
70
|
}
|
|
56
71
|
|
|
@@ -65,10 +80,10 @@ extern "C" {
|
|
|
65
80
|
impl EntropyGenerator for ExternalEntropyGenerator {
|
|
66
81
|
fn generate(&self) -> [u8; 32] {
|
|
67
82
|
// TODO: think about changing API to return an error but does it worth it for JS?
|
|
68
|
-
|
|
83
|
+
|
|
84
|
+
ExternalEntropyGenerator::generate(self)
|
|
69
85
|
.try_into()
|
|
70
|
-
.expect("Bad entropy generator provided: should return 32 bytes")
|
|
71
|
-
res
|
|
86
|
+
.expect("Bad entropy generator provided: should return 32 bytes")
|
|
72
87
|
}
|
|
73
88
|
}
|
|
74
89
|
#[wasm_bindgen(js_class=DataContractFactory)]
|
|
@@ -86,7 +101,7 @@ impl DataContractFactoryWasm {
|
|
|
86
101
|
Box::new(external_entropy_generator),
|
|
87
102
|
)
|
|
88
103
|
} else {
|
|
89
|
-
DataContractFactory::new(protocol_version, validate_data_contract.into())
|
|
104
|
+
DataContractFactory::new(protocol_version, validate_data_contract.into())
|
|
90
105
|
}
|
|
91
106
|
.into()
|
|
92
107
|
}
|
|
@@ -139,7 +154,7 @@ impl DataContractFactoryWasm {
|
|
|
139
154
|
.create_from_buffer(buffer, skip_validation.unwrap_or(false))
|
|
140
155
|
.await
|
|
141
156
|
.map(Into::into)
|
|
142
|
-
.map_err(
|
|
157
|
+
.map_err(from_protocol_error)
|
|
143
158
|
}
|
|
144
159
|
|
|
145
160
|
#[wasm_bindgen(js_name=createDataContractCreateTransition)]
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
1
|
+
use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
2
|
use dpp::prelude::DocumentTransition;
|
|
3
3
|
use thiserror::Error;
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
1
|
+
use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
2
|
use dpp::prelude::DocumentTransition;
|
|
3
3
|
use thiserror::Error;
|
|
4
4
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
1
|
+
use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
2
|
use dpp::prelude::DocumentTransition;
|
|
3
3
|
use thiserror::Error;
|
|
4
4
|
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
use wasm_bindgen::prelude::*;
|
|
2
2
|
|
|
3
|
-
#[wasm_bindgen(js_name=
|
|
4
|
-
pub struct
|
|
3
|
+
#[wasm_bindgen(js_name=DataContractMaxDepthExceedError)]
|
|
4
|
+
pub struct DataContractMaxDepthExceedErrorWasm {
|
|
5
5
|
depth: usize,
|
|
6
6
|
code: u32,
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
impl
|
|
9
|
+
impl DataContractMaxDepthExceedErrorWasm {
|
|
10
10
|
pub fn new(depth: usize, code: u32) -> Self {
|
|
11
|
-
|
|
11
|
+
DataContractMaxDepthExceedErrorWasm { depth, code }
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
#[wasm_bindgen(js_class=DataContractMaxDepthError)]
|
|
16
|
-
impl
|
|
16
|
+
impl DataContractMaxDepthExceedErrorWasm {
|
|
17
17
|
#[wasm_bindgen(js_name=getDepth)]
|
|
18
18
|
pub fn get_expected_version(&self) -> usize {
|
|
19
19
|
self.depth
|
package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs
CHANGED
|
@@ -3,19 +3,19 @@ use std::iter::FromIterator;
|
|
|
3
3
|
use wasm_bindgen::prelude::*;
|
|
4
4
|
|
|
5
5
|
#[wasm_bindgen(js_name=DuplicateDocumentTransitionsWithIdsError)]
|
|
6
|
-
pub struct
|
|
6
|
+
pub struct DuplicateDocumentTransitionsWithIdsErrorWasm {
|
|
7
7
|
references: Vec<(String, Vec<u8>)>,
|
|
8
8
|
code: u32,
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
impl
|
|
11
|
+
impl DuplicateDocumentTransitionsWithIdsErrorWasm {
|
|
12
12
|
pub fn new(references: Vec<(String, Vec<u8>)>, code: u32) -> Self {
|
|
13
|
-
|
|
13
|
+
DuplicateDocumentTransitionsWithIdsErrorWasm { references, code }
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
#[wasm_bindgen(js_class=DuplicateDocumentTransitionsWithIdsError)]
|
|
18
|
-
impl
|
|
18
|
+
impl DuplicateDocumentTransitionsWithIdsErrorWasm {
|
|
19
19
|
#[wasm_bindgen(js_name=getReferences)]
|
|
20
20
|
pub fn get_references(&self) -> js_sys::Array {
|
|
21
21
|
self.references
|
package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
use crate::buffer::Buffer;
|
|
2
|
+
use std::iter::FromIterator;
|
|
3
|
+
use wasm_bindgen::prelude::*;
|
|
4
|
+
|
|
5
|
+
#[wasm_bindgen(js_name=DuplicateDocumentTransitionsWithIndicesError)]
|
|
6
|
+
pub struct DuplicateDocumentTransitionsWithIndicesErrorWasm {
|
|
7
|
+
references: Vec<(String, Vec<u8>)>,
|
|
8
|
+
code: u32,
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
impl DuplicateDocumentTransitionsWithIndicesErrorWasm {
|
|
12
|
+
pub fn new(references: Vec<(String, Vec<u8>)>, code: u32) -> Self {
|
|
13
|
+
DuplicateDocumentTransitionsWithIndicesErrorWasm { references, code }
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#[wasm_bindgen(js_class=DuplicateDocumentTransitionsWithIndicesError)]
|
|
18
|
+
impl DuplicateDocumentTransitionsWithIndicesErrorWasm {
|
|
19
|
+
#[wasm_bindgen(js_name=getReferences)]
|
|
20
|
+
pub fn get_references(&self) -> js_sys::Array {
|
|
21
|
+
self.references
|
|
22
|
+
.iter()
|
|
23
|
+
.map(|v| {
|
|
24
|
+
js_sys::Array::from_iter(vec![
|
|
25
|
+
JsValue::from(v.0.clone()),
|
|
26
|
+
JsValue::from(Buffer::from_bytes(&v.1)),
|
|
27
|
+
])
|
|
28
|
+
})
|
|
29
|
+
.collect()
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#[wasm_bindgen(js_name=getCode)]
|
|
33
|
+
pub fn get_code(&self) -> u32 {
|
|
34
|
+
self.code
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
use wasm_bindgen::prelude::*;
|
|
2
|
+
|
|
3
|
+
#[wasm_bindgen(js_name=MissingDocumentTransitionTypeError)]
|
|
4
|
+
pub struct MissingDocumentTransitionTypeErrorWasm {
|
|
5
|
+
code: u32,
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
impl MissingDocumentTransitionTypeErrorWasm {
|
|
9
|
+
pub fn new(code: u32) -> Self {
|
|
10
|
+
MissingDocumentTransitionTypeErrorWasm { code }
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[wasm_bindgen(js_class=MissingDocumentTransitionTypeError)]
|
|
15
|
+
impl MissingDocumentTransitionTypeErrorWasm {
|
|
16
|
+
#[wasm_bindgen(js_name=getCode)]
|
|
17
|
+
pub fn get_code(&self) -> u32 {
|
|
18
|
+
self.code
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
mod data_contract_not_present_error;
|
|
2
2
|
mod duplicate_document_transitions_with_ids_error;
|
|
3
|
+
mod duplicate_document_transitions_with_indices_error;
|
|
3
4
|
mod inconsistent_compound_index_data_error;
|
|
4
5
|
mod invalid_document_transition_action_error;
|
|
5
6
|
mod invalid_document_transition_id_error;
|
|
6
7
|
mod invalid_document_type_error;
|
|
7
8
|
mod missing_data_contract_id_error;
|
|
8
9
|
mod missing_document_transition_action_error;
|
|
10
|
+
mod missing_document_transition_type_error;
|
|
9
11
|
mod missing_document_type_error;
|
|
10
12
|
|
|
11
13
|
pub use data_contract_not_present_error::*;
|
|
12
14
|
pub use duplicate_document_transitions_with_ids_error::*;
|
|
15
|
+
pub use duplicate_document_transitions_with_indices_error::*;
|
|
13
16
|
pub use inconsistent_compound_index_data_error::*;
|
|
14
17
|
pub use invalid_document_transition_action_error::*;
|
|
15
18
|
pub use invalid_document_transition_id_error::*;
|
|
16
19
|
pub use invalid_document_type_error::*;
|
|
17
20
|
pub use missing_data_contract_id_error::*;
|
|
18
21
|
pub use missing_document_transition_action_error::*;
|
|
22
|
+
pub use missing_document_transition_type_error::*;
|
|
19
23
|
pub use missing_document_type_error::*;
|
|
@@ -16,12 +16,12 @@ impl From<&DuplicatedIdentityPublicKeyError> for DuplicatedIdentityPublicKeyErro
|
|
|
16
16
|
#[wasm_bindgen(js_class=DuplicatedIdentityPublicKeyError)]
|
|
17
17
|
impl DuplicatedIdentityPublicKeyErrorWasm {
|
|
18
18
|
#[wasm_bindgen(js_name=getDuplicatedPublicKeysIds)]
|
|
19
|
-
pub fn duplicated_public_keys_ids(&self) ->
|
|
19
|
+
pub fn duplicated_public_keys_ids(&self) -> js_sys::Array {
|
|
20
20
|
// TODO: key ids probably should be u32
|
|
21
21
|
self.inner
|
|
22
22
|
.duplicated_public_keys_ids()
|
|
23
23
|
.iter()
|
|
24
|
-
.map(|id| *id as u32)
|
|
24
|
+
.map(|id| JsValue::from(*id as u32))
|
|
25
25
|
.collect()
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -16,12 +16,12 @@ impl From<&DuplicatedIdentityPublicKeyIdError> for DuplicatedIdentityPublicKeyId
|
|
|
16
16
|
#[wasm_bindgen(js_class=DuplicatedIdentityPublicKeyIdError)]
|
|
17
17
|
impl DuplicatedIdentityPublicKeyIdErrorWasm {
|
|
18
18
|
#[wasm_bindgen(js_name=getDuplicatedIds)]
|
|
19
|
-
pub fn duplicated_ids(&self) ->
|
|
19
|
+
pub fn duplicated_ids(&self) -> js_sys::Array {
|
|
20
20
|
// TODO: key ids probably should be u32
|
|
21
21
|
self.inner
|
|
22
22
|
.duplicated_ids()
|
|
23
23
|
.iter()
|
|
24
|
-
.map(|id| *id as u32)
|
|
24
|
+
.map(|id| JsValue::from(*id as u32))
|
|
25
25
|
.collect()
|
|
26
26
|
}
|
|
27
27
|
|
package/src/errors/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs
CHANGED
|
@@ -25,12 +25,12 @@ impl InvalidIdentityPublicKeySecurityLevelErrorWasm {
|
|
|
25
25
|
self.inner.public_key_id() as u32
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
#[wasm_bindgen(js_name=
|
|
28
|
+
#[wasm_bindgen(js_name=getPublicKeyPurpose)]
|
|
29
29
|
pub fn purpose(&self) -> u8 {
|
|
30
30
|
self.inner.purpose() as u8
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
#[wasm_bindgen(js_name=
|
|
33
|
+
#[wasm_bindgen(js_name=getPublicKeySecurityLevel)]
|
|
34
34
|
pub fn security_level(&self) -> u8 {
|
|
35
35
|
self.inner.security_level() as u8
|
|
36
36
|
}
|
|
@@ -141,7 +141,7 @@ impl From<&ValidationErrorKind> for Params {
|
|
|
141
141
|
.build(),
|
|
142
142
|
ValidationErrorKind::MinItems { limit } => ParamsBuilder::new()
|
|
143
143
|
.set_keyword("minItems")
|
|
144
|
-
.add_param("
|
|
144
|
+
.add_param("minItems", Value::from(*limit))
|
|
145
145
|
.build(),
|
|
146
146
|
ValidationErrorKind::Minimum { limit } => ParamsBuilder::new()
|
|
147
147
|
.set_keyword("minimum")
|
package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_condition_error.rs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
use crate::buffer::Buffer;
|
|
2
|
-
use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
|
+
use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
3
3
|
|
|
4
4
|
use dpp::identifier::Identifier;
|
|
5
5
|
use dpp::prelude::DocumentTransition;
|
package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_execution_error.rs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
use crate::buffer::Buffer;
|
|
2
|
-
use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
|
+
use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
3
3
|
|
|
4
4
|
use dpp::identifier::Identifier;
|
|
5
5
|
use dpp::prelude::DocumentTransition;
|
package/src/errors/consensus/state/data_contract/data_trigger/data_trigger_invalid_result_error.rs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
use crate::buffer::Buffer;
|
|
2
|
-
use crate::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
2
|
+
use crate::document::state_transition::document_batch_transition::document_transition::from_document_transition_to_js_value;
|
|
3
3
|
|
|
4
4
|
use dpp::identifier::Identifier;
|
|
5
5
|
use dpp::prelude::DocumentTransition;
|
|
@@ -36,8 +36,9 @@ use crate::errors::consensus::basic::data_contract::{
|
|
|
36
36
|
IncompatibleDataContractSchemaErrorWasm, InvalidDataContractIdErrorWasm,
|
|
37
37
|
};
|
|
38
38
|
use crate::errors::consensus::basic::document::{
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
DuplicateDocumentTransitionsWithIdsErrorWasm, DuplicateDocumentTransitionsWithIndicesErrorWasm,
|
|
40
|
+
InvalidDocumentTransitionActionErrorWasm, InvalidDocumentTransitionIdErrorWasm,
|
|
41
|
+
MissingDataContractIdErrorWasm, MissingDocumentTypeErrorWasm,
|
|
41
42
|
};
|
|
42
43
|
use crate::errors::consensus::basic::state_transition::{
|
|
43
44
|
InvalidStateTransitionTypeErrorWasm, MissingStateTransitionTypeErrorWasm,
|
|
@@ -62,7 +63,7 @@ use crate::errors::consensus::state::identity::{
|
|
|
62
63
|
use dpp::errors::DataTriggerError;
|
|
63
64
|
|
|
64
65
|
use super::consensus::basic::data_contract::{
|
|
65
|
-
|
|
66
|
+
DataContractMaxDepthExceedErrorWasm, DuplicateIndexErrorWasm, DuplicateIndexNameErrorWasm,
|
|
66
67
|
IncompatibleRe2PatternErrorWasm, InvalidCompoundIndexErrorWasm,
|
|
67
68
|
InvalidDataContractVersionErrorWasm, InvalidIndexPropertyTypeErrorWasm,
|
|
68
69
|
InvalidIndexedPropertyConstraintErrorWasm, InvalidJsonSchemaRefErrorWasm,
|
|
@@ -75,7 +76,7 @@ use super::consensus::basic::decode::{
|
|
|
75
76
|
use super::consensus::basic::document::{
|
|
76
77
|
DataContractNotPresentErrorWasm, InconsistentCompoundIndexDataErrorWasm,
|
|
77
78
|
InvalidDocumentTypeErrorWasm, MissingDocumentTransitionActionErrorWasm,
|
|
78
|
-
|
|
79
|
+
MissingDocumentTransitionTypeErrorWasm,
|
|
79
80
|
};
|
|
80
81
|
use super::consensus::basic::identity::{
|
|
81
82
|
InvalidIdentityPublicKeyTypeErrorWasm, MissingPublicKeyErrorWasm,
|
|
@@ -99,7 +100,7 @@ pub fn from_consensus_error_ref(e: &DPPConsensusError) -> JsValue {
|
|
|
99
100
|
DPPConsensusError::IncompatibleProtocolVersionError(e) => {
|
|
100
101
|
IncompatibleProtocolVersionErrorWasm::from(e).into()
|
|
101
102
|
}
|
|
102
|
-
DPPConsensusError::
|
|
103
|
+
DPPConsensusError::DuplicatedIdentityPublicKeyBasicIdError(e) => {
|
|
103
104
|
DuplicatedIdentityPublicKeyIdErrorWasm::from(e).into()
|
|
104
105
|
}
|
|
105
106
|
DPPConsensusError::InvalidIdentityPublicKeyDataError(e) => {
|
|
@@ -108,7 +109,7 @@ pub fn from_consensus_error_ref(e: &DPPConsensusError) -> JsValue {
|
|
|
108
109
|
DPPConsensusError::InvalidIdentityPublicKeySecurityLevelError(e) => {
|
|
109
110
|
InvalidIdentityPublicKeySecurityLevelErrorWasm::from(e).into()
|
|
110
111
|
}
|
|
111
|
-
DPPConsensusError::
|
|
112
|
+
DPPConsensusError::DuplicatedIdentityPublicKeyBasicError(e) => {
|
|
112
113
|
DuplicatedIdentityPublicKeyErrorWasm::from(e).into()
|
|
113
114
|
}
|
|
114
115
|
DPPConsensusError::MissingMasterPublicKeyError(e) => {
|
|
@@ -351,7 +352,7 @@ fn from_basic_error(basic_error: &Box<BasicError>) -> JsValue {
|
|
|
351
352
|
version,
|
|
352
353
|
} => InvalidDataContractVersionErrorWasm::new(*expected_version, *version, code).into(),
|
|
353
354
|
BasicError::DataContractMaxDepthExceedError(depth) => {
|
|
354
|
-
|
|
355
|
+
DataContractMaxDepthExceedErrorWasm::new(*depth, code).into()
|
|
355
356
|
}
|
|
356
357
|
BasicError::InvalidDocumentTypeError {
|
|
357
358
|
document_type,
|
|
@@ -457,6 +458,9 @@ fn from_basic_error(basic_error: &Box<BasicError>) -> JsValue {
|
|
|
457
458
|
code,
|
|
458
459
|
)
|
|
459
460
|
.into(),
|
|
461
|
+
BasicError::MissingDocumentTransitionTypeError => {
|
|
462
|
+
MissingDocumentTransitionTypeErrorWasm::new(code).into()
|
|
463
|
+
}
|
|
460
464
|
BasicError::MissingDocumentTypeError => MissingDocumentTypeErrorWasm::new(code).into(),
|
|
461
465
|
BasicError::MissingDocumentTransitionActionError => {
|
|
462
466
|
MissingDocumentTransitionActionErrorWasm::new(code).into()
|
|
@@ -472,8 +476,11 @@ fn from_basic_error(basic_error: &Box<BasicError>) -> JsValue {
|
|
|
472
476
|
InvalidDocumentTransitionIdErrorWasm::new(expected_id.clone(), invalid_id.clone(), code)
|
|
473
477
|
.into()
|
|
474
478
|
}
|
|
479
|
+
BasicError::DuplicateDocumentTransitionsWithIndicesError { references } => {
|
|
480
|
+
DuplicateDocumentTransitionsWithIndicesErrorWasm::new(references.clone(), code).into()
|
|
481
|
+
}
|
|
475
482
|
BasicError::DuplicateDocumentTransitionsWithIdsError { references } => {
|
|
476
|
-
|
|
483
|
+
DuplicateDocumentTransitionsWithIdsErrorWasm::new(references.clone(), code).into()
|
|
477
484
|
}
|
|
478
485
|
BasicError::MissingDataContractIdError => MissingDataContractIdErrorWasm::new(code).into(),
|
|
479
486
|
BasicError::InvalidIdentifierError {
|
package/src/errors/from.rs
CHANGED
package/src/errors/mod.rs
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
use wasm_bindgen::JsValue;
|
|
2
|
+
|
|
3
|
+
use super::consensus_error::from_consensus_error;
|
|
4
|
+
|
|
5
|
+
pub fn from_protocol_error(e: dpp::ProtocolError) -> JsValue {
|
|
6
|
+
match e {
|
|
7
|
+
dpp::ProtocolError::AbstractConsensusError(consensus_error) => {
|
|
8
|
+
from_consensus_error(*consensus_error)
|
|
9
|
+
}
|
|
10
|
+
_ => unimplemented!(),
|
|
11
|
+
}
|
|
12
|
+
}
|
|
File without changes
|
|
@@ -6,7 +6,7 @@ use dpp::identity::validation::PublicKeysValidator;
|
|
|
6
6
|
use dpp::identity::IdentityFacade;
|
|
7
7
|
|
|
8
8
|
use crate::bls_adapter::{BlsAdapter, JsBlsAdapter};
|
|
9
|
-
use crate::
|
|
9
|
+
use crate::validation::ValidationResultWasm;
|
|
10
10
|
use dpp::version::ProtocolVersionValidator;
|
|
11
11
|
use dpp::NonConsensusError;
|
|
12
12
|
|
|
File without changes
|