pshenmic-dpp 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.lock +14 -1
- package/Cargo.toml +5 -4
- package/dist/wasm/pshenmic_dpp.js +477 -19
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/package.json +1 -1
- package/packages/{cbor-conversation → cbor_conversation}/Cargo.toml +0 -4
- package/packages/data_contract/Cargo.toml +2 -6
- package/packages/data_contract/src/lib.rs +56 -41
- package/packages/data_contract_transitions/Cargo.toml +14 -0
- package/packages/data_contract_transitions/src/create/mod.rs +154 -0
- package/packages/data_contract_transitions/src/lib.rs +2 -0
- package/packages/data_contract_transitions/src/update/mod.rs +135 -0
- package/packages/document/Cargo.toml +1 -6
- package/packages/document_batch/Cargo.toml +1 -6
- package/packages/enums/Cargo.toml +1 -4
- package/packages/identity/Cargo.toml +1 -5
- package/packages/identity_transitions/Cargo.toml +1 -5
- package/packages/identity_transitions/src/create_transition/mod.rs +2 -2
- package/packages/mock_bls/Cargo.toml +1 -5
- package/packages/private_key/Cargo.toml +1 -5
- package/packages/public_key/Cargo.toml +1 -5
- package/packages/state_transition/Cargo.toml +1 -5
- package/packages/state_transition/src/lib.rs +6 -5
- package/packages/utils/Cargo.toml +1 -5
- package/scripts/build-js.sh +3 -2
- package/src/lib.rs +1 -0
- /package/packages/{cbor-conversation → cbor_conversation}/src/lib.rs +0 -0
package/package.json
CHANGED
|
@@ -15,7 +15,3 @@ pshenmic_dpp_utils = {path = "../utils"}
|
|
|
15
15
|
base64 = "0.22.1"
|
|
16
16
|
ciborium = "0.2.2"
|
|
17
17
|
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
18
|
-
|
|
19
|
-
[profile.release]
|
|
20
|
-
lto = true
|
|
21
|
-
opt-level = 'z'
|
|
@@ -11,11 +11,7 @@ wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
|
11
11
|
pshenmic_dpp_utils = {path = "../utils"}
|
|
12
12
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
13
13
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
14
|
-
"data-contract-json-conversion"
|
|
14
|
+
"data-contract-json-conversion",
|
|
15
|
+
"platform-value"
|
|
15
16
|
]}
|
|
16
17
|
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
17
|
-
#serde = { version = "1.0.219", features = ["derive"] }
|
|
18
|
-
|
|
19
|
-
[profile.release]
|
|
20
|
-
lto = true
|
|
21
|
-
opt-level = 'z'
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
use dpp::dashcore::hashes::serde::Serialize;
|
|
2
|
-
use dpp::data_contract::accessors::v0::DataContractV0Getters;
|
|
2
|
+
use dpp::data_contract::accessors::v0::{DataContractV0Getters, DataContractV0Setters};
|
|
3
3
|
use dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0;
|
|
4
4
|
use dpp::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0;
|
|
5
5
|
use dpp::data_contract::document_type::DocumentTypeRef;
|
|
6
6
|
use dpp::data_contract::errors::DataContractError;
|
|
7
7
|
use dpp::data_contract::schema::DataContractSchemaMethodsV0;
|
|
8
8
|
use dpp::data_contract::{DataContract, DataContractV0};
|
|
9
|
-
use dpp::
|
|
9
|
+
use dpp::prelude::IdentityNonce;
|
|
10
10
|
use dpp::serialization::{
|
|
11
11
|
PlatformDeserializableWithPotentialValidationFromVersionedStructure,
|
|
12
12
|
PlatformSerializableWithPlatformVersion,
|
|
13
13
|
};
|
|
14
14
|
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
15
|
-
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError};
|
|
15
|
+
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError, identifier_from_js_value};
|
|
16
16
|
use wasm_bindgen::JsValue;
|
|
17
17
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
18
18
|
|
|
@@ -40,18 +40,13 @@ impl DataContractWASM {
|
|
|
40
40
|
full_validation: bool,
|
|
41
41
|
platform_version: PlatformVersionWASM,
|
|
42
42
|
) -> Result<DataContractWASM, JsValue> {
|
|
43
|
-
let value = js_value.with_serde_to_platform_value()
|
|
43
|
+
let value = js_value.with_serde_to_platform_value()?;
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
DataContractV0::from_value(v, full_validation, &platform_version.into())
|
|
49
|
-
.with_js_error()?;
|
|
45
|
+
let v0_contract =
|
|
46
|
+
DataContractV0::from_value(value, full_validation, &platform_version.into())
|
|
47
|
+
.with_js_error()?;
|
|
50
48
|
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
Err(err) => Err(err),
|
|
54
|
-
}
|
|
49
|
+
Ok(DataContractWASM(DataContract::V0(v0_contract)))
|
|
55
50
|
}
|
|
56
51
|
|
|
57
52
|
#[wasm_bindgen(js_name = "fromBytes")]
|
|
@@ -65,12 +60,9 @@ impl DataContractWASM {
|
|
|
65
60
|
full_validation,
|
|
66
61
|
&platform_version.into(),
|
|
67
62
|
)
|
|
68
|
-
.with_js_error()
|
|
63
|
+
.with_js_error()?;
|
|
69
64
|
|
|
70
|
-
|
|
71
|
-
Ok(rs_data_contract) => Ok(DataContractWASM(rs_data_contract)),
|
|
72
|
-
Err(err) => Err(err),
|
|
73
|
-
}
|
|
65
|
+
Ok(DataContractWASM(rs_data_contract))
|
|
74
66
|
}
|
|
75
67
|
|
|
76
68
|
#[wasm_bindgen(js_name = "toBytes")]
|
|
@@ -84,23 +76,24 @@ impl DataContractWASM {
|
|
|
84
76
|
|
|
85
77
|
#[wasm_bindgen(js_name = "toValue")]
|
|
86
78
|
pub fn to_value(&self, platform_version: PlatformVersionWASM) -> Result<JsValue, JsValue> {
|
|
87
|
-
let
|
|
88
|
-
|
|
79
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
80
|
+
|
|
81
|
+
self.0
|
|
89
82
|
.clone()
|
|
90
83
|
.to_value(&platform_version.into())
|
|
91
|
-
.with_js_error()
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
Ok(v) => Ok(serde_wasm_bindgen::to_value(&v).unwrap()),
|
|
95
|
-
Err(err) => Err(err),
|
|
96
|
-
}
|
|
84
|
+
.with_js_error()?
|
|
85
|
+
.serialize(&serializer)
|
|
86
|
+
.map_err(JsValue::from)
|
|
97
87
|
}
|
|
98
88
|
|
|
99
|
-
#[wasm_bindgen(js_name = "
|
|
100
|
-
pub fn
|
|
89
|
+
#[wasm_bindgen(js_name = "getSchemas")]
|
|
90
|
+
pub fn get_schemas(&self) -> Result<JsValue, JsValue> {
|
|
101
91
|
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
102
92
|
|
|
103
|
-
self.0
|
|
93
|
+
self.0
|
|
94
|
+
.document_schemas()
|
|
95
|
+
.serialize(&serializer)
|
|
96
|
+
.map_err(JsValue::from)
|
|
104
97
|
}
|
|
105
98
|
|
|
106
99
|
#[wasm_bindgen(js_name = "getDataContractVersion")]
|
|
@@ -108,32 +101,54 @@ impl DataContractWASM {
|
|
|
108
101
|
self.0.version()
|
|
109
102
|
}
|
|
110
103
|
|
|
111
|
-
#[wasm_bindgen(js_name = "
|
|
112
|
-
pub fn
|
|
113
|
-
|
|
104
|
+
#[wasm_bindgen(js_name = "getId")]
|
|
105
|
+
pub fn get_id(&self) -> Vec<u8> {
|
|
106
|
+
self.0.id().to_vec()
|
|
114
107
|
}
|
|
115
108
|
|
|
116
109
|
#[wasm_bindgen(js_name = "getOwnerId")]
|
|
117
|
-
pub fn get_owner_id(&self) ->
|
|
118
|
-
|
|
110
|
+
pub fn get_owner_id(&self) -> Vec<u8> {
|
|
111
|
+
self.0.owner_id().to_vec()
|
|
119
112
|
}
|
|
120
113
|
|
|
121
114
|
#[wasm_bindgen(js_name = "getConfig")]
|
|
122
|
-
pub fn get_config(&self) -> JsValue {
|
|
115
|
+
pub fn get_config(&self) -> Result<JsValue, JsValue> {
|
|
123
116
|
self.0
|
|
124
117
|
.config()
|
|
125
118
|
.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
|
|
126
|
-
.
|
|
119
|
+
.map_err(JsValue::from)
|
|
127
120
|
}
|
|
128
121
|
|
|
129
122
|
#[wasm_bindgen(js_name = "toJson")]
|
|
130
123
|
pub fn to_json(&self, platform_version: PlatformVersionWASM) -> Result<JsValue, JsValue> {
|
|
131
|
-
let json = self.0.to_json(&platform_version.into()).with_js_error()
|
|
124
|
+
let json = self.0.to_json(&platform_version.into()).with_js_error()?;
|
|
125
|
+
|
|
126
|
+
json.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
|
|
127
|
+
.map_err(JsValue::from)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
#[wasm_bindgen(js_name = "generateId")]
|
|
131
|
+
pub fn generate_id(
|
|
132
|
+
js_owner_id: JsValue,
|
|
133
|
+
identity_nonce: IdentityNonce,
|
|
134
|
+
) -> Result<Vec<u8>, JsValue> {
|
|
135
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
136
|
+
|
|
137
|
+
Ok(DataContract::generate_data_contract_id_v0(owner_id, identity_nonce).to_vec())
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#[wasm_bindgen(js_name = "setId")]
|
|
141
|
+
pub fn set_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
142
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
143
|
+
|
|
144
|
+
Ok(self.0.set_id(data_contract_id))
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
#[wasm_bindgen(js_name = "setOwnerId")]
|
|
148
|
+
pub fn set_owner_id(&mut self, js_owner_id: JsValue) -> Result<(), JsValue> {
|
|
149
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
132
150
|
|
|
133
|
-
|
|
134
|
-
Ok(json) => Ok(json.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?),
|
|
135
|
-
Err(err) => Err(err),
|
|
136
|
-
}
|
|
151
|
+
Ok(self.0.set_owner_id(owner_id))
|
|
137
152
|
}
|
|
138
153
|
}
|
|
139
154
|
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "pshenmic_dpp_data_contract_transitions"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2024"
|
|
5
|
+
|
|
6
|
+
[dependencies]
|
|
7
|
+
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
8
|
+
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
9
|
+
"state-transition-signing"
|
|
10
|
+
]}
|
|
11
|
+
pshenmic_dpp_data_contract = {path = "../data_contract"}
|
|
12
|
+
pshenmic_dpp_enums = {path = "../enums"}
|
|
13
|
+
pshenmic_dpp_utils = {path = "../utils"}
|
|
14
|
+
pshenmic_dpp_state_transition = {path = "../state_transition"}
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
use dpp::ProtocolError;
|
|
2
|
+
use dpp::data_contract::serialized_version::DataContractInSerializationFormat;
|
|
3
|
+
use dpp::prelude::{DataContract, IdentityNonce};
|
|
4
|
+
use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
|
|
5
|
+
use dpp::state_transition::StateTransition;
|
|
6
|
+
use dpp::state_transition::data_contract_create_transition::accessors::DataContractCreateTransitionAccessorsV0;
|
|
7
|
+
use dpp::state_transition::data_contract_create_transition::{
|
|
8
|
+
DataContractCreateTransition, DataContractCreateTransitionV0,
|
|
9
|
+
};
|
|
10
|
+
use dpp::validation::operations::ProtocolValidationOperation;
|
|
11
|
+
use dpp::version::{
|
|
12
|
+
FeatureVersion, ProtocolVersion, TryFromPlatformVersioned, TryIntoPlatformVersioned,
|
|
13
|
+
};
|
|
14
|
+
use pshenmic_dpp_data_contract::DataContractWASM;
|
|
15
|
+
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
16
|
+
use pshenmic_dpp_state_transition::StateTransitionWASM;
|
|
17
|
+
use pshenmic_dpp_utils::WithJsError;
|
|
18
|
+
use wasm_bindgen::JsValue;
|
|
19
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
20
|
+
|
|
21
|
+
#[wasm_bindgen(js_name = "DataContractCreateTransitionWASM")]
|
|
22
|
+
pub struct DataContractCreateTransitionWASM(DataContractCreateTransition);
|
|
23
|
+
|
|
24
|
+
#[wasm_bindgen]
|
|
25
|
+
impl DataContractCreateTransitionWASM {
|
|
26
|
+
#[wasm_bindgen(constructor)]
|
|
27
|
+
pub fn new(
|
|
28
|
+
data_contract: &DataContractWASM,
|
|
29
|
+
identity_nonce: IdentityNonce,
|
|
30
|
+
platform_version: Option<PlatformVersionWASM>,
|
|
31
|
+
) -> Result<DataContractCreateTransitionWASM, JsValue> {
|
|
32
|
+
let rs_data_contract: DataContract = data_contract.clone().into();
|
|
33
|
+
|
|
34
|
+
let rs_data_contract_in_serialized: Result<
|
|
35
|
+
DataContractInSerializationFormat,
|
|
36
|
+
ProtocolError,
|
|
37
|
+
> = rs_data_contract.try_into_platform_versioned(
|
|
38
|
+
&platform_version
|
|
39
|
+
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
40
|
+
.into(),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
let rs_data_contract_create_transition_v0: DataContractCreateTransitionV0 =
|
|
44
|
+
DataContractCreateTransitionV0 {
|
|
45
|
+
data_contract: rs_data_contract_in_serialized.with_js_error()?,
|
|
46
|
+
identity_nonce,
|
|
47
|
+
user_fee_increase: 0,
|
|
48
|
+
signature_public_key_id: 0,
|
|
49
|
+
signature: Default::default(),
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
let rs_data_contract_transition =
|
|
53
|
+
DataContractCreateTransition::V0(rs_data_contract_create_transition_v0);
|
|
54
|
+
|
|
55
|
+
Ok(DataContractCreateTransitionWASM(
|
|
56
|
+
rs_data_contract_transition,
|
|
57
|
+
))
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
61
|
+
pub fn from_bytes(bytes: Vec<u8>) -> Result<DataContractCreateTransitionWASM, JsValue> {
|
|
62
|
+
let rs_data_contract_create_transition: DataContractCreateTransition =
|
|
63
|
+
DataContractCreateTransition::deserialize_from_bytes(bytes.as_slice())
|
|
64
|
+
.with_js_error()?;
|
|
65
|
+
|
|
66
|
+
Ok(DataContractCreateTransitionWASM(
|
|
67
|
+
rs_data_contract_create_transition,
|
|
68
|
+
))
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#[wasm_bindgen(js_name = "toBytes")]
|
|
72
|
+
pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
73
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[wasm_bindgen(js_name = "getFeatureVersion")]
|
|
77
|
+
pub fn get_feature_version(&self) -> FeatureVersion {
|
|
78
|
+
self.0.feature_version()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[wasm_bindgen(js_name = "verifyProtocolVersion")]
|
|
82
|
+
pub fn verify_protocol_version(
|
|
83
|
+
&self,
|
|
84
|
+
protocol_version: ProtocolVersion,
|
|
85
|
+
) -> Result<bool, JsValue> {
|
|
86
|
+
self.0
|
|
87
|
+
.verify_protocol_version(protocol_version)
|
|
88
|
+
.with_js_error()
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#[wasm_bindgen(js_name = "setDataContract")]
|
|
92
|
+
pub fn set_data_contract(
|
|
93
|
+
&mut self,
|
|
94
|
+
data_contract: DataContractWASM,
|
|
95
|
+
platform_version_wasm: Option<PlatformVersionWASM>,
|
|
96
|
+
) -> Result<(), JsValue> {
|
|
97
|
+
let data_contract_serialization_format =
|
|
98
|
+
DataContractInSerializationFormat::try_from_platform_versioned(
|
|
99
|
+
DataContract::from(data_contract),
|
|
100
|
+
&platform_version_wasm
|
|
101
|
+
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
102
|
+
.into(),
|
|
103
|
+
)
|
|
104
|
+
.with_js_error()?;
|
|
105
|
+
|
|
106
|
+
self.0.set_data_contract(data_contract_serialization_format);
|
|
107
|
+
|
|
108
|
+
Ok(())
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#[wasm_bindgen(js_name = "getDataContract")]
|
|
112
|
+
pub fn get_data_contract(
|
|
113
|
+
&self,
|
|
114
|
+
platform_version_wasm: Option<PlatformVersionWASM>,
|
|
115
|
+
full_validation: Option<bool>,
|
|
116
|
+
) -> Result<DataContractWASM, JsValue> {
|
|
117
|
+
let rs_data_contract_serialization_format = self.0.data_contract();
|
|
118
|
+
|
|
119
|
+
let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
|
|
120
|
+
|
|
121
|
+
let rs_data_contract = DataContract::try_from_platform_versioned(
|
|
122
|
+
rs_data_contract_serialization_format.clone(),
|
|
123
|
+
full_validation.unwrap_or(false),
|
|
124
|
+
&mut validation_operations,
|
|
125
|
+
&platform_version_wasm
|
|
126
|
+
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
127
|
+
.into(),
|
|
128
|
+
)
|
|
129
|
+
.with_js_error()?;
|
|
130
|
+
|
|
131
|
+
Ok(DataContractWASM::from(rs_data_contract))
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[wasm_bindgen(js_name = "toStateTransition")]
|
|
135
|
+
pub fn to_state_transition(&self) -> StateTransitionWASM {
|
|
136
|
+
let rs_state_transition = StateTransition::from(self.0.clone());
|
|
137
|
+
|
|
138
|
+
StateTransitionWASM::from(rs_state_transition)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[wasm_bindgen(js_name = "fromStateTransition")]
|
|
142
|
+
pub fn from_state_transition(
|
|
143
|
+
state_transition: &StateTransitionWASM,
|
|
144
|
+
) -> Result<DataContractCreateTransitionWASM, JsValue> {
|
|
145
|
+
let rs_transition = StateTransition::from(state_transition.clone());
|
|
146
|
+
|
|
147
|
+
match rs_transition {
|
|
148
|
+
StateTransition::DataContractCreate(state_transition) => {
|
|
149
|
+
Ok(DataContractCreateTransitionWASM(state_transition))
|
|
150
|
+
}
|
|
151
|
+
_ => Err(JsValue::from("Incorrect transition type")),
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
use dpp::data_contract::serialized_version::DataContractInSerializationFormat;
|
|
2
|
+
use dpp::prelude::{DataContract, IdentityNonce};
|
|
3
|
+
use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
|
|
4
|
+
use dpp::state_transition::StateTransition;
|
|
5
|
+
use dpp::state_transition::data_contract_update_transition::DataContractUpdateTransition;
|
|
6
|
+
use dpp::state_transition::data_contract_update_transition::accessors::DataContractUpdateTransitionAccessorsV0;
|
|
7
|
+
use dpp::validation::operations::ProtocolValidationOperation;
|
|
8
|
+
use dpp::version::{FeatureVersion, ProtocolVersion, TryFromPlatformVersioned};
|
|
9
|
+
use pshenmic_dpp_data_contract::DataContractWASM;
|
|
10
|
+
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
11
|
+
use pshenmic_dpp_state_transition::StateTransitionWASM;
|
|
12
|
+
use pshenmic_dpp_utils::WithJsError;
|
|
13
|
+
use wasm_bindgen::JsValue;
|
|
14
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
15
|
+
|
|
16
|
+
#[wasm_bindgen(js_name = "DataContractUpdateTransitionWASM")]
|
|
17
|
+
pub struct DataContractUpdateTransitionWASM(DataContractUpdateTransition);
|
|
18
|
+
|
|
19
|
+
#[wasm_bindgen]
|
|
20
|
+
impl DataContractUpdateTransitionWASM {
|
|
21
|
+
#[wasm_bindgen(constructor)]
|
|
22
|
+
pub fn new(
|
|
23
|
+
data_contract: &DataContractWASM,
|
|
24
|
+
identity_nonce: IdentityNonce,
|
|
25
|
+
platform_version: Option<PlatformVersionWASM>,
|
|
26
|
+
) -> Result<DataContractUpdateTransitionWASM, JsValue> {
|
|
27
|
+
let rs_data_contract_update_transition =
|
|
28
|
+
DataContractUpdateTransition::try_from_platform_versioned(
|
|
29
|
+
(DataContract::from(data_contract.clone()), identity_nonce),
|
|
30
|
+
&platform_version
|
|
31
|
+
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
32
|
+
.into(),
|
|
33
|
+
)
|
|
34
|
+
.with_js_error()?;
|
|
35
|
+
|
|
36
|
+
Ok(DataContractUpdateTransitionWASM(
|
|
37
|
+
rs_data_contract_update_transition,
|
|
38
|
+
))
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
42
|
+
pub fn from_bytes(bytes: Vec<u8>) -> Result<DataContractUpdateTransitionWASM, JsValue> {
|
|
43
|
+
let rs_data_contract_update_transition: DataContractUpdateTransition =
|
|
44
|
+
DataContractUpdateTransition::deserialize_from_bytes(bytes.as_slice())
|
|
45
|
+
.with_js_error()?;
|
|
46
|
+
|
|
47
|
+
Ok(DataContractUpdateTransitionWASM(
|
|
48
|
+
rs_data_contract_update_transition,
|
|
49
|
+
))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[wasm_bindgen(js_name = "toBytes")]
|
|
53
|
+
pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
54
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#[wasm_bindgen(js_name = "getFeatureVersion")]
|
|
58
|
+
pub fn get_feature_version(&self) -> FeatureVersion {
|
|
59
|
+
self.0.feature_version()
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[wasm_bindgen(js_name = "verifyProtocolVersion")]
|
|
63
|
+
pub fn verify_protocol_version(
|
|
64
|
+
&self,
|
|
65
|
+
protocol_version: ProtocolVersion,
|
|
66
|
+
) -> Result<bool, JsValue> {
|
|
67
|
+
self.0
|
|
68
|
+
.verify_protocol_version(protocol_version)
|
|
69
|
+
.with_js_error()
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#[wasm_bindgen(js_name = "setDataContract")]
|
|
73
|
+
pub fn set_data_contract(
|
|
74
|
+
&mut self,
|
|
75
|
+
data_contract: &DataContractWASM,
|
|
76
|
+
platform_version_wasm: Option<PlatformVersionWASM>,
|
|
77
|
+
) -> Result<(), JsValue> {
|
|
78
|
+
let data_contract_serialization_format =
|
|
79
|
+
DataContractInSerializationFormat::try_from_platform_versioned(
|
|
80
|
+
DataContract::from(data_contract.clone()),
|
|
81
|
+
&platform_version_wasm
|
|
82
|
+
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
83
|
+
.into(),
|
|
84
|
+
)
|
|
85
|
+
.with_js_error()?;
|
|
86
|
+
|
|
87
|
+
self.0.set_data_contract(data_contract_serialization_format);
|
|
88
|
+
|
|
89
|
+
Ok(())
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#[wasm_bindgen(js_name = "getDataContract")]
|
|
93
|
+
pub fn get_data_contract(
|
|
94
|
+
&self,
|
|
95
|
+
full_validation: Option<bool>,
|
|
96
|
+
platform_version_wasm: Option<PlatformVersionWASM>,
|
|
97
|
+
) -> Result<DataContractWASM, JsValue> {
|
|
98
|
+
let data_contract_serialization_format = self.0.data_contract();
|
|
99
|
+
|
|
100
|
+
let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
|
|
101
|
+
|
|
102
|
+
let rs_data_contract = DataContract::try_from_platform_versioned(
|
|
103
|
+
data_contract_serialization_format.clone(),
|
|
104
|
+
full_validation.unwrap_or(false),
|
|
105
|
+
&mut validation_operations,
|
|
106
|
+
&platform_version_wasm
|
|
107
|
+
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
108
|
+
.into(),
|
|
109
|
+
)
|
|
110
|
+
.with_js_error()?;
|
|
111
|
+
|
|
112
|
+
Ok(DataContractWASM::from(rs_data_contract))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#[wasm_bindgen(js_name = "toStateTransition")]
|
|
116
|
+
pub fn to_state_transition(&self) -> StateTransitionWASM {
|
|
117
|
+
let rs_state_transition = StateTransition::from(self.0.clone());
|
|
118
|
+
|
|
119
|
+
StateTransitionWASM::from(rs_state_transition)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#[wasm_bindgen(js_name = "fromStateTransition")]
|
|
123
|
+
pub fn from_state_transition(
|
|
124
|
+
state_transition: &StateTransitionWASM,
|
|
125
|
+
) -> Result<DataContractUpdateTransitionWASM, JsValue> {
|
|
126
|
+
let rs_transition = StateTransition::from(state_transition.clone());
|
|
127
|
+
|
|
128
|
+
match rs_transition {
|
|
129
|
+
StateTransition::DataContractUpdate(state_transition) => {
|
|
130
|
+
Ok(DataContractUpdateTransitionWASM(state_transition))
|
|
131
|
+
}
|
|
132
|
+
_ => Err(JsValue::from("Incorrect transition type")),
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
@@ -14,9 +14,4 @@ pshenmic_dpp_data_contract = {path = "../data_contract"}
|
|
|
14
14
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
15
15
|
"document-value-conversion"
|
|
16
16
|
]}
|
|
17
|
-
|
|
18
|
-
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
19
|
-
|
|
20
|
-
[profile.release]
|
|
21
|
-
lto = true
|
|
22
|
-
opt-level = 'z'
|
|
17
|
+
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
@@ -14,9 +14,4 @@ pshenmic_dpp_utils = {path = "../utils"}
|
|
|
14
14
|
pshenmic_dpp_state_transition = {path = "../state_transition"}
|
|
15
15
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
16
16
|
"document-json-conversion",
|
|
17
|
-
]}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
[profile.release]
|
|
21
|
-
lto = true
|
|
22
|
-
opt-level = 'z'
|
|
17
|
+
]}
|
|
@@ -10,7 +10,4 @@ crate-type = ["cdylib", "lib"]
|
|
|
10
10
|
wasm-bindgen = "0.2.100"
|
|
11
11
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
12
12
|
"identity-value-conversion",
|
|
13
|
-
]}
|
|
14
|
-
[profile.release]
|
|
15
|
-
lto = true
|
|
16
|
-
opt-level = 'z'
|
|
13
|
+
]}
|
|
@@ -13,8 +13,4 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
|
|
|
13
13
|
]}
|
|
14
14
|
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
15
15
|
pshenmic_dpp_public_key = { path = "../public_key" }
|
|
16
|
-
pshenmic_dpp_utils = { path = "../utils" }
|
|
17
|
-
|
|
18
|
-
[profile.release]
|
|
19
|
-
lto = true
|
|
20
|
-
opt-level = 'z'
|
|
16
|
+
pshenmic_dpp_utils = { path = "../utils" }
|
|
@@ -14,8 +14,4 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
|
|
|
14
14
|
pshenmic_dpp_utils = {path = "../utils"}
|
|
15
15
|
pshenmic_dpp_public_key = {path = "../public_key"}
|
|
16
16
|
pshenmic_dpp_state_transition = {path = "../state_transition"}
|
|
17
|
-
pshenmic_dpp_enums = {path = "../enums"}
|
|
18
|
-
|
|
19
|
-
[profile.release]
|
|
20
|
-
lto = true
|
|
21
|
-
opt-level = 'z'
|
|
17
|
+
pshenmic_dpp_enums = {path = "../enums"}
|
|
@@ -76,9 +76,9 @@ impl IdentityCreateTransitionWASM {
|
|
|
76
76
|
|
|
77
77
|
#[wasm_bindgen(js_name = "fromStateTransition")]
|
|
78
78
|
pub fn from_state_transition(
|
|
79
|
-
st: StateTransitionWASM,
|
|
79
|
+
st: &StateTransitionWASM,
|
|
80
80
|
) -> Result<IdentityCreateTransitionWASM, JsValue> {
|
|
81
|
-
let rs_st: StateTransition = st.into();
|
|
81
|
+
let rs_st: StateTransition = st.clone().into();
|
|
82
82
|
|
|
83
83
|
match rs_st {
|
|
84
84
|
StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWASM(st)),
|
|
@@ -10,8 +10,4 @@ crate-type = ["cdylib", "lib"]
|
|
|
10
10
|
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
11
11
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
12
12
|
"identity-value-conversion",
|
|
13
|
-
]}
|
|
14
|
-
|
|
15
|
-
[profile.release]
|
|
16
|
-
lto = true
|
|
17
|
-
opt-level = 'z'
|
|
13
|
+
]}
|
|
@@ -12,8 +12,4 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
|
|
|
12
12
|
"identity-value-conversion",
|
|
13
13
|
]}
|
|
14
14
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
15
|
-
pshenmic_dpp_utils = {path = "../utils"}
|
|
16
|
-
|
|
17
|
-
[profile.release]
|
|
18
|
-
lto = true
|
|
19
|
-
opt-level = 'z'
|
|
15
|
+
pshenmic_dpp_utils = {path = "../utils"}
|
|
@@ -15,8 +15,4 @@ pshenmic_dpp_mock_bls = {path = "../mock_bls"}
|
|
|
15
15
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
16
16
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
17
17
|
"state-transition-signing"
|
|
18
|
-
]}
|
|
19
|
-
|
|
20
|
-
[profile.release]
|
|
21
|
-
lto = true
|
|
22
|
-
opt-level = 'z'
|
|
18
|
+
]}
|
|
@@ -9,6 +9,7 @@ use pshenmic_dpp_utils::WithJsError;
|
|
|
9
9
|
use wasm_bindgen::JsValue;
|
|
10
10
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
11
11
|
|
|
12
|
+
#[derive(Clone)]
|
|
12
13
|
#[wasm_bindgen(js_name = "StateTransitionWASM")]
|
|
13
14
|
pub struct StateTransitionWASM(StateTransition);
|
|
14
15
|
|
|
@@ -29,11 +30,11 @@ impl StateTransitionWASM {
|
|
|
29
30
|
#[wasm_bindgen(js_name=sign)]
|
|
30
31
|
pub fn sign(
|
|
31
32
|
&mut self,
|
|
32
|
-
private_key: PrivateKeyWASM,
|
|
33
|
-
public_key: IdentityPublicKeyWASM,
|
|
33
|
+
private_key: &PrivateKeyWASM,
|
|
34
|
+
public_key: &IdentityPublicKeyWASM,
|
|
34
35
|
) -> Result<JsValue, JsValue> {
|
|
35
36
|
let sig = self.0.sign(
|
|
36
|
-
&public_key.into(),
|
|
37
|
+
&public_key.clone().into(),
|
|
37
38
|
private_key.get_key_bytes().as_slice(),
|
|
38
39
|
&MockBLS {},
|
|
39
40
|
);
|
|
@@ -57,7 +58,7 @@ impl StateTransitionWASM {
|
|
|
57
58
|
#[wasm_bindgen(js_name=signByPrivateKey)]
|
|
58
59
|
pub fn sign_by_private_key(
|
|
59
60
|
&mut self,
|
|
60
|
-
private_key: PrivateKeyWASM,
|
|
61
|
+
private_key: &PrivateKeyWASM,
|
|
61
62
|
key_type: KeyTypeWASM,
|
|
62
63
|
) -> JsValue {
|
|
63
64
|
let _sig = self
|
|
@@ -79,7 +80,7 @@ impl StateTransitionWASM {
|
|
|
79
80
|
|
|
80
81
|
#[wasm_bindgen(js_name=toBytes)]
|
|
81
82
|
pub fn to_bytes(&self) -> Result<JsValue, JsValue> {
|
|
82
|
-
let bytes = self.0.serialize_to_bytes().
|
|
83
|
+
let bytes = self.0.serialize_to_bytes().with_js_error()?;
|
|
83
84
|
|
|
84
85
|
Ok(JsValue::from(bytes.clone()))
|
|
85
86
|
}
|
|
@@ -17,8 +17,4 @@ js-sys = "0.3.53"
|
|
|
17
17
|
serde_json = { version = "1.0", features = ["preserve_order"] }
|
|
18
18
|
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
19
19
|
serde = { version = "1.0.197", features = ["derive"] }
|
|
20
|
-
itertools = { version = "0.13" }
|
|
21
|
-
|
|
22
|
-
[profile.release]
|
|
23
|
-
lto = true
|
|
24
|
-
opt-level = 'z'
|
|
20
|
+
itertools = { version = "0.13" }
|