pshenmic-dpp 1.0.3 → 1.0.5
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/.github/workflows/build.yml +8 -0
- package/.github/workflows/publish.yml +8 -0
- package/Cargo.lock +89 -28
- package/Cargo.toml +22 -18
- package/README.md +66 -23
- package/babel.config.json +19 -0
- package/dist/wasm/pshenmic_dpp.js +2992 -402
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/package.json +13 -6
- package/packages/{cbor-conversation → cbor_conversation}/Cargo.toml +1 -5
- package/packages/data_contract/Cargo.toml +3 -7
- package/packages/data_contract/src/lib.rs +234 -47
- package/packages/{document_batch → data_contract_transitions}/Cargo.toml +6 -14
- package/packages/data_contract_transitions/src/create/mod.rs +161 -0
- package/packages/data_contract_transitions/src/lib.rs +2 -0
- package/packages/data_contract_transitions/src/update/mod.rs +144 -0
- package/packages/document/Cargo.toml +2 -7
- package/packages/document/src/lib.rs +1 -1
- package/packages/document/src/methods/mod.rs +370 -2
- package/packages/documents_batch/Cargo.toml +19 -0
- package/packages/documents_batch/src/document_base_transition/mod.rs +92 -0
- package/packages/documents_batch/src/document_transition/mod.rs +166 -0
- package/packages/documents_batch/src/generators.rs +122 -0
- package/packages/documents_batch/src/lib.rs +188 -0
- package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
- package/packages/documents_batch/src/transitions/create/mod.rs +123 -0
- package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
- package/packages/documents_batch/src/transitions/mod.rs +6 -0
- package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
- package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
- package/packages/documents_batch/src/transitions/transfer/mod.rs +86 -0
- package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
- package/packages/enums/Cargo.toml +2 -5
- package/packages/enums/src/batch/batch_enum.rs +75 -10
- package/packages/enums/src/keys/key_type.rs +46 -0
- package/packages/enums/src/keys/purpose.rs +55 -0
- package/packages/enums/src/keys/security_level.rs +46 -0
- package/packages/enums/src/lib.rs +1 -0
- package/packages/enums/src/network/mod.rs +67 -0
- package/packages/enums/src/platform/mod.rs +66 -8
- package/packages/identity/Cargo.toml +2 -7
- package/packages/identity/src/lib.rs +25 -14
- package/packages/{public_key → identity_public_key}/Cargo.toml +2 -6
- package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
- package/packages/identity_transitions/Cargo.toml +3 -7
- package/packages/identity_transitions/src/create_transition/mod.rs +5 -3
- package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +25 -21
- package/packages/mock_bls/Cargo.toml +2 -6
- package/packages/private_key/Cargo.toml +2 -5
- package/packages/private_key/src/lib.rs +44 -6
- package/packages/state_transition/Cargo.toml +4 -7
- package/packages/state_transition/src/lib.rs +106 -40
- package/packages/utils/Cargo.toml +1 -6
- package/packages/utils/src/lib.rs +17 -15
- package/scripts/build-js.sh +8 -6
- package/scripts/build.sh +22 -1
- package/src/lib.rs +8 -1
- package/tests/DataContract.spec.js +175 -0
- package/tests/DataContractCreateStateTransition.spec.js +109 -0
- package/tests/DataContractUpdateStateTransition.spec.js +109 -0
- package/tests/Document.spec.js +232 -0
- package/tests/DocumentBatchTransition.spec.js +109 -0
- package/tests/DocumentTransition.spec.js +97 -0
- package/tests/DocumentsTransitions.spec.js +705 -0
- package/tests/Identity.spec.js +113 -0
- package/tests/IdentityPublicKey.spec.js +132 -0
- package/tests/PrivateKey.spec.js +73 -0
- package/tests/mocks/DataContract/DataContract.json +153 -0
- package/tests/mocks/DataContract/index.js +6 -0
- package/tests/mocks/Document/DataContract.json +23 -0
- package/tests/mocks/Document/document.json +3 -0
- package/tests/mocks/Document/document2.json +3 -0
- package/tests/mocks/Document/index.js +11 -0
- package/tests/mocks/Identity/index.js +7 -0
- package/tests/mocks/PrivateKey/index.js +5 -0
- package/tests/mocks/PublicKey/index.js +14 -0
- package/tests/utils/hex.js +15 -0
- package/tests/utils/wasm.js +14 -0
- package/packages/document/src/methods/js.rs +0 -260
- package/packages/document/src/methods/rust.rs +0 -92
- package/packages/document_batch/src/generators.rs +0 -63
- package/packages/document_batch/src/lib.rs +0 -228
- /package/packages/{cbor-conversation → cbor_conversation}/src/lib.rs +0 -0
package/package.json
CHANGED
|
@@ -1,25 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pshenmic-dpp",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"main": "dist/wasm/pshenmic_dpp.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/owl352/pshenmic-dpp"
|
|
8
8
|
},
|
|
9
9
|
"scripts": {
|
|
10
|
-
"tsc": "tsc",
|
|
11
10
|
"build:bin": "./scripts/build.sh",
|
|
12
11
|
"build:js": "./scripts/build-js.sh",
|
|
13
12
|
"build:full": "./scripts/build.sh && ./scripts/build-js.sh",
|
|
14
|
-
"build:raw": "./scripts/build.sh && RAW=true ./scripts/build-js.sh"
|
|
13
|
+
"build:raw": "./scripts/build.sh && RAW=true ./scripts/build-js.sh",
|
|
14
|
+
"babel": "babel dist/wasm --out-dir dist/cjs/wasm",
|
|
15
|
+
"tests": "mocha ./tests/*.spec.js"
|
|
15
16
|
},
|
|
16
17
|
"author": "owl352",
|
|
17
18
|
"license": "ISC",
|
|
18
19
|
"description": "",
|
|
19
20
|
"devDependencies": {
|
|
20
|
-
"babel": "^
|
|
21
|
-
"babel
|
|
22
|
-
"
|
|
21
|
+
"@babel/cli": "^7.27.0",
|
|
22
|
+
"@babel/core": "^7.26.10",
|
|
23
|
+
"@babel/plugin-transform-modules-commonjs": "^7.26.3",
|
|
24
|
+
"@babel/plugin-transform-runtime": "^7.26.10",
|
|
25
|
+
"@babel/preset-env": "^7.26.9",
|
|
26
|
+
"@scure/base": "^1.2.4",
|
|
27
|
+
"core-js": "^3.41.0",
|
|
28
|
+
"mocha": "^11.1.0",
|
|
29
|
+
"standard": "^17.1.2"
|
|
23
30
|
},
|
|
24
31
|
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
|
|
25
32
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_document_search"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -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'
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_data_contract"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -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
15
|
]}
|
|
16
|
+
js-sys = "0.3.53"
|
|
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,5 +1,6 @@
|
|
|
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
|
+
use dpp::data_contract::config::DataContractConfig;
|
|
3
4
|
use dpp::data_contract::conversion::json::DataContractJsonConversionMethodsV0;
|
|
4
5
|
use dpp::data_contract::conversion::value::v0::DataContractValueConversionMethodsV0;
|
|
5
6
|
use dpp::data_contract::document_type::DocumentTypeRef;
|
|
@@ -7,12 +8,16 @@ use dpp::data_contract::errors::DataContractError;
|
|
|
7
8
|
use dpp::data_contract::schema::DataContractSchemaMethodsV0;
|
|
8
9
|
use dpp::data_contract::{DataContract, DataContractV0};
|
|
9
10
|
use dpp::platform_value::string_encoding::Encoding::Base58;
|
|
11
|
+
use dpp::platform_value::{Value, ValueMap};
|
|
12
|
+
use dpp::prelude::IdentityNonce;
|
|
10
13
|
use dpp::serialization::{
|
|
11
14
|
PlatformDeserializableWithPotentialValidationFromVersionedStructure,
|
|
12
15
|
PlatformSerializableWithPlatformVersion,
|
|
13
16
|
};
|
|
17
|
+
use dpp::version::PlatformVersion;
|
|
14
18
|
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
15
|
-
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError};
|
|
19
|
+
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError, identifier_from_js_value};
|
|
20
|
+
use std::collections::BTreeMap;
|
|
16
21
|
use wasm_bindgen::JsValue;
|
|
17
22
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
18
23
|
|
|
@@ -35,46 +40,137 @@ impl From<DataContractWASM> for DataContract {
|
|
|
35
40
|
#[wasm_bindgen]
|
|
36
41
|
impl DataContractWASM {
|
|
37
42
|
#[wasm_bindgen(constructor)]
|
|
38
|
-
pub fn
|
|
43
|
+
pub fn from_js_values(
|
|
44
|
+
js_owner_id: JsValue,
|
|
45
|
+
identity_nonce: IdentityNonce,
|
|
46
|
+
js_schema: JsValue,
|
|
47
|
+
js_definitions: Option<js_sys::Object>,
|
|
48
|
+
full_validation: bool,
|
|
49
|
+
js_platform_version: JsValue,
|
|
50
|
+
) -> Result<DataContractWASM, JsValue> {
|
|
51
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
52
|
+
|
|
53
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
54
|
+
|
|
55
|
+
let owner_id_value = Value::from(owner_id.to_string(Base58));
|
|
56
|
+
|
|
57
|
+
let schema: Value = serde_wasm_bindgen::from_value(js_schema)?;
|
|
58
|
+
|
|
59
|
+
let platform_version: PlatformVersion = match js_platform_version.is_undefined() {
|
|
60
|
+
true => PlatformVersionWASM::PLATFORM_V1.into(),
|
|
61
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?.into(),
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
let data_contract_structure_version_value = Value::from(
|
|
65
|
+
platform_version
|
|
66
|
+
.dpp
|
|
67
|
+
.contract_versions
|
|
68
|
+
.contract_structure_version
|
|
69
|
+
.to_string(),
|
|
70
|
+
);
|
|
71
|
+
|
|
72
|
+
let definitions = js_definitions
|
|
73
|
+
.map(|definitions| serde_wasm_bindgen::from_value(definitions.into()))
|
|
74
|
+
.transpose()?;
|
|
75
|
+
|
|
76
|
+
let definitions_value = Value::from(definitions);
|
|
77
|
+
|
|
78
|
+
let data_contract_id = DataContract::generate_data_contract_id_v0(owner_id, identity_nonce);
|
|
79
|
+
|
|
80
|
+
let data_contract_id_value = Value::from(data_contract_id.to_string(Base58));
|
|
81
|
+
|
|
82
|
+
let config =
|
|
83
|
+
DataContractConfig::default_for_version(&platform_version.clone()).with_js_error()?;
|
|
84
|
+
|
|
85
|
+
let config_value = config
|
|
86
|
+
.serialize(&serializer)
|
|
87
|
+
.map_err(JsValue::from)?
|
|
88
|
+
.with_serde_to_platform_value_map()?;
|
|
89
|
+
|
|
90
|
+
let mut contract_value = Value::Map(ValueMap::new());
|
|
91
|
+
|
|
92
|
+
contract_value
|
|
93
|
+
.set_value("$format_version", data_contract_structure_version_value)
|
|
94
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
95
|
+
|
|
96
|
+
contract_value
|
|
97
|
+
.set_value("id", data_contract_id_value)
|
|
98
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
99
|
+
|
|
100
|
+
contract_value
|
|
101
|
+
.set_value("config", Value::from(config_value))
|
|
102
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
103
|
+
|
|
104
|
+
contract_value
|
|
105
|
+
.set_value("version", Value::from(1u16))
|
|
106
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
107
|
+
|
|
108
|
+
contract_value
|
|
109
|
+
.set_value("ownerId", owner_id_value)
|
|
110
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
111
|
+
|
|
112
|
+
contract_value
|
|
113
|
+
.set_value("schemaDefs", definitions_value)
|
|
114
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
115
|
+
|
|
116
|
+
contract_value
|
|
117
|
+
.set_value("documentSchemas", schema)
|
|
118
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
119
|
+
|
|
120
|
+
Ok(DataContractWASM(
|
|
121
|
+
DataContract::from_value(contract_value, full_validation, &platform_version)
|
|
122
|
+
.with_js_error()?,
|
|
123
|
+
))
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#[wasm_bindgen(js_name = "fromValue")]
|
|
127
|
+
pub fn from_value(
|
|
39
128
|
js_value: JsValue,
|
|
40
129
|
full_validation: bool,
|
|
41
|
-
|
|
130
|
+
js_platform_version: JsValue,
|
|
42
131
|
) -> Result<DataContractWASM, JsValue> {
|
|
43
|
-
let
|
|
132
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
133
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
134
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
135
|
+
};
|
|
44
136
|
|
|
45
|
-
|
|
46
|
-
Ok(v) => {
|
|
47
|
-
let v0_contract =
|
|
48
|
-
DataContractV0::from_value(v, full_validation, &platform_version.into())
|
|
49
|
-
.with_js_error()?;
|
|
137
|
+
let value = js_value.with_serde_to_platform_value()?;
|
|
50
138
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
139
|
+
let v0_contract =
|
|
140
|
+
DataContractV0::from_value(value, full_validation, &platform_version.into())
|
|
141
|
+
.with_js_error()?;
|
|
142
|
+
|
|
143
|
+
Ok(DataContractWASM(DataContract::V0(v0_contract)))
|
|
55
144
|
}
|
|
56
145
|
|
|
57
146
|
#[wasm_bindgen(js_name = "fromBytes")]
|
|
58
147
|
pub fn from_bytes(
|
|
59
148
|
bytes: Vec<u8>,
|
|
60
149
|
full_validation: bool,
|
|
61
|
-
|
|
150
|
+
js_platform_version: JsValue,
|
|
62
151
|
) -> Result<DataContractWASM, JsValue> {
|
|
152
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
153
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
154
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
155
|
+
};
|
|
156
|
+
|
|
63
157
|
let rs_data_contract = DataContract::versioned_deserialize(
|
|
64
158
|
&bytes.as_slice(),
|
|
65
159
|
full_validation,
|
|
66
160
|
&platform_version.into(),
|
|
67
161
|
)
|
|
68
|
-
.with_js_error()
|
|
162
|
+
.with_js_error()?;
|
|
69
163
|
|
|
70
|
-
|
|
71
|
-
Ok(rs_data_contract) => Ok(DataContractWASM(rs_data_contract)),
|
|
72
|
-
Err(err) => Err(err),
|
|
73
|
-
}
|
|
164
|
+
Ok(DataContractWASM(rs_data_contract))
|
|
74
165
|
}
|
|
75
166
|
|
|
76
167
|
#[wasm_bindgen(js_name = "toBytes")]
|
|
77
|
-
pub fn to_bytes(&self,
|
|
168
|
+
pub fn to_bytes(&self, js_platform_version: JsValue) -> Result<Vec<u8>, JsValue> {
|
|
169
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
170
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
171
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
172
|
+
};
|
|
173
|
+
|
|
78
174
|
let rs_data_contract: DataContract = self.0.clone();
|
|
79
175
|
|
|
80
176
|
rs_data_contract
|
|
@@ -83,57 +179,148 @@ impl DataContractWASM {
|
|
|
83
179
|
}
|
|
84
180
|
|
|
85
181
|
#[wasm_bindgen(js_name = "toValue")]
|
|
86
|
-
pub fn to_value(&self,
|
|
87
|
-
let
|
|
88
|
-
|
|
182
|
+
pub fn to_value(&self, js_platform_version: JsValue) -> Result<JsValue, JsValue> {
|
|
183
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
184
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
185
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
189
|
+
|
|
190
|
+
self.0
|
|
89
191
|
.clone()
|
|
90
192
|
.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
|
-
}
|
|
193
|
+
.with_js_error()?
|
|
194
|
+
.serialize(&serializer)
|
|
195
|
+
.map_err(JsValue::from)
|
|
97
196
|
}
|
|
98
197
|
|
|
99
198
|
#[wasm_bindgen(js_name = "getSchema")]
|
|
100
|
-
pub fn
|
|
199
|
+
pub fn get_schemas(&self) -> Result<JsValue, JsValue> {
|
|
101
200
|
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
102
201
|
|
|
103
|
-
self.0
|
|
202
|
+
self.0
|
|
203
|
+
.document_schemas()
|
|
204
|
+
.serialize(&serializer)
|
|
205
|
+
.map_err(JsValue::from)
|
|
104
206
|
}
|
|
105
207
|
|
|
106
|
-
#[wasm_bindgen(js_name = "
|
|
107
|
-
pub fn
|
|
208
|
+
#[wasm_bindgen(js_name = "getVersion")]
|
|
209
|
+
pub fn get_version(&self) -> u32 {
|
|
108
210
|
self.0.version()
|
|
109
211
|
}
|
|
110
212
|
|
|
111
|
-
#[wasm_bindgen(js_name = "
|
|
112
|
-
pub fn
|
|
113
|
-
|
|
213
|
+
#[wasm_bindgen(js_name = "getId")]
|
|
214
|
+
pub fn get_id(&self) -> Vec<u8> {
|
|
215
|
+
self.0.id().to_vec()
|
|
114
216
|
}
|
|
115
217
|
|
|
116
218
|
#[wasm_bindgen(js_name = "getOwnerId")]
|
|
117
|
-
pub fn get_owner_id(&self) ->
|
|
118
|
-
|
|
219
|
+
pub fn get_owner_id(&self) -> Vec<u8> {
|
|
220
|
+
self.0.owner_id().to_vec()
|
|
119
221
|
}
|
|
120
222
|
|
|
121
223
|
#[wasm_bindgen(js_name = "getConfig")]
|
|
122
|
-
pub fn get_config(&self) -> JsValue {
|
|
224
|
+
pub fn get_config(&self) -> Result<JsValue, JsValue> {
|
|
123
225
|
self.0
|
|
124
226
|
.config()
|
|
125
227
|
.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
|
|
126
|
-
.
|
|
228
|
+
.map_err(JsValue::from)
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
#[wasm_bindgen(js_name = "setId")]
|
|
232
|
+
pub fn set_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
233
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
234
|
+
|
|
235
|
+
Ok(self.0.set_id(data_contract_id))
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
#[wasm_bindgen(js_name = "setOwnerId")]
|
|
239
|
+
pub fn set_owner_id(&mut self, js_owner_id: JsValue) -> Result<(), JsValue> {
|
|
240
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
241
|
+
|
|
242
|
+
Ok(self.0.set_owner_id(owner_id))
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
#[wasm_bindgen(js_name = "setVersion")]
|
|
246
|
+
pub fn set_version(&mut self, version: u32) {
|
|
247
|
+
self.0.set_version(version)
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
#[wasm_bindgen(js_name = "setConfig")]
|
|
251
|
+
pub fn set_config(
|
|
252
|
+
&mut self,
|
|
253
|
+
js_config: JsValue,
|
|
254
|
+
js_platform_version: JsValue,
|
|
255
|
+
) -> Result<(), JsValue> {
|
|
256
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
257
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
258
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
let config_value: Value = serde_wasm_bindgen::from_value(js_config)?;
|
|
262
|
+
|
|
263
|
+
let config = DataContractConfig::from_value(config_value, &platform_version.into())
|
|
264
|
+
.with_js_error()?;
|
|
265
|
+
|
|
266
|
+
self.0.set_config(config);
|
|
267
|
+
|
|
268
|
+
Ok(())
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
#[wasm_bindgen(js_name = "setSchema")]
|
|
272
|
+
pub fn set_schemas(
|
|
273
|
+
&mut self,
|
|
274
|
+
js_schema: JsValue,
|
|
275
|
+
js_definitions: Option<js_sys::Object>,
|
|
276
|
+
full_validation: bool,
|
|
277
|
+
js_platform_version: JsValue,
|
|
278
|
+
) -> Result<(), JsValue> {
|
|
279
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
280
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
281
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
let schema = js_schema.with_serde_to_platform_value_map()?;
|
|
285
|
+
|
|
286
|
+
let definitions: Option<BTreeMap<String, Value>> = js_definitions
|
|
287
|
+
.map(|definitions| serde_wasm_bindgen::from_value(definitions.into()))
|
|
288
|
+
.transpose()?;
|
|
289
|
+
|
|
290
|
+
self.0
|
|
291
|
+
.set_document_schemas(
|
|
292
|
+
schema,
|
|
293
|
+
definitions,
|
|
294
|
+
full_validation,
|
|
295
|
+
&mut Vec::new(),
|
|
296
|
+
&platform_version.into(),
|
|
297
|
+
)
|
|
298
|
+
.with_js_error()?;
|
|
299
|
+
|
|
300
|
+
Ok(())
|
|
127
301
|
}
|
|
128
302
|
|
|
129
303
|
#[wasm_bindgen(js_name = "toJson")]
|
|
130
|
-
pub fn to_json(&self,
|
|
131
|
-
let
|
|
304
|
+
pub fn to_json(&self, js_platform_version: JsValue) -> Result<JsValue, JsValue> {
|
|
305
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
306
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
307
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
let json = self.0.to_json(&platform_version.into()).with_js_error()?;
|
|
311
|
+
|
|
312
|
+
json.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
|
|
313
|
+
.map_err(JsValue::from)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
#[wasm_bindgen(js_name = "generateId")]
|
|
317
|
+
pub fn generate_id(
|
|
318
|
+
js_owner_id: JsValue,
|
|
319
|
+
identity_nonce: IdentityNonce,
|
|
320
|
+
) -> Result<Vec<u8>, JsValue> {
|
|
321
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
132
322
|
|
|
133
|
-
|
|
134
|
-
Ok(json) => Ok(json.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?),
|
|
135
|
-
Err(err) => Err(err),
|
|
136
|
-
}
|
|
323
|
+
Ok(DataContract::generate_data_contract_id_v0(owner_id, identity_nonce).to_vec())
|
|
137
324
|
}
|
|
138
325
|
}
|
|
139
326
|
|
|
@@ -1,22 +1,14 @@
|
|
|
1
1
|
[package]
|
|
2
|
-
name = "
|
|
3
|
-
version =
|
|
2
|
+
name = "pshenmic_dpp_data_contract_transitions"
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
|
-
[lib]
|
|
7
|
-
crate-type = ["cdylib", "lib"]
|
|
8
|
-
|
|
9
6
|
[dependencies]
|
|
10
7
|
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
11
|
-
|
|
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
12
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
13
13
|
pshenmic_dpp_utils = {path = "../utils"}
|
|
14
14
|
pshenmic_dpp_state_transition = {path = "../state_transition"}
|
|
15
|
-
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
16
|
-
"document-json-conversion",
|
|
17
|
-
]}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
[profile.release]
|
|
21
|
-
lto = true
|
|
22
|
-
opt-level = 'z'
|
|
@@ -0,0 +1,161 @@
|
|
|
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
|
+
js_platform_version: JsValue,
|
|
31
|
+
) -> Result<DataContractCreateTransitionWASM, JsValue> {
|
|
32
|
+
let rs_data_contract: DataContract = data_contract.clone().into();
|
|
33
|
+
|
|
34
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
35
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
36
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
let rs_data_contract_in_serialized: Result<
|
|
40
|
+
DataContractInSerializationFormat,
|
|
41
|
+
ProtocolError,
|
|
42
|
+
> = rs_data_contract.try_into_platform_versioned(&platform_version.into());
|
|
43
|
+
|
|
44
|
+
let rs_data_contract_create_transition_v0: DataContractCreateTransitionV0 =
|
|
45
|
+
DataContractCreateTransitionV0 {
|
|
46
|
+
data_contract: rs_data_contract_in_serialized.with_js_error()?,
|
|
47
|
+
identity_nonce,
|
|
48
|
+
user_fee_increase: 0,
|
|
49
|
+
signature_public_key_id: 0,
|
|
50
|
+
signature: Default::default(),
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
let rs_data_contract_transition =
|
|
54
|
+
DataContractCreateTransition::V0(rs_data_contract_create_transition_v0);
|
|
55
|
+
|
|
56
|
+
Ok(DataContractCreateTransitionWASM(
|
|
57
|
+
rs_data_contract_transition,
|
|
58
|
+
))
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
62
|
+
pub fn from_bytes(bytes: Vec<u8>) -> Result<DataContractCreateTransitionWASM, JsValue> {
|
|
63
|
+
let rs_data_contract_create_transition: DataContractCreateTransition =
|
|
64
|
+
DataContractCreateTransition::deserialize_from_bytes(bytes.as_slice())
|
|
65
|
+
.with_js_error()?;
|
|
66
|
+
|
|
67
|
+
Ok(DataContractCreateTransitionWASM(
|
|
68
|
+
rs_data_contract_create_transition,
|
|
69
|
+
))
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
#[wasm_bindgen(js_name = "toBytes")]
|
|
73
|
+
pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
74
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#[wasm_bindgen(js_name = "getFeatureVersion")]
|
|
78
|
+
pub fn get_feature_version(&self) -> FeatureVersion {
|
|
79
|
+
self.0.feature_version()
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#[wasm_bindgen(js_name = "verifyProtocolVersion")]
|
|
83
|
+
pub fn verify_protocol_version(
|
|
84
|
+
&self,
|
|
85
|
+
protocol_version: ProtocolVersion,
|
|
86
|
+
) -> Result<bool, JsValue> {
|
|
87
|
+
self.0
|
|
88
|
+
.verify_protocol_version(protocol_version)
|
|
89
|
+
.with_js_error()
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#[wasm_bindgen(js_name = "setDataContract")]
|
|
93
|
+
pub fn set_data_contract(
|
|
94
|
+
&mut self,
|
|
95
|
+
data_contract: &DataContractWASM,
|
|
96
|
+
js_platform_version: JsValue,
|
|
97
|
+
) -> Result<(), JsValue> {
|
|
98
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
99
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
100
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
let data_contract_serialization_format =
|
|
104
|
+
DataContractInSerializationFormat::try_from_platform_versioned(
|
|
105
|
+
DataContract::from(data_contract.clone()),
|
|
106
|
+
&platform_version.into(),
|
|
107
|
+
)
|
|
108
|
+
.with_js_error()?;
|
|
109
|
+
|
|
110
|
+
self.0.set_data_contract(data_contract_serialization_format);
|
|
111
|
+
|
|
112
|
+
Ok(())
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#[wasm_bindgen(js_name = "getDataContract")]
|
|
116
|
+
pub fn get_data_contract(
|
|
117
|
+
&self,
|
|
118
|
+
js_platform_version: JsValue,
|
|
119
|
+
full_validation: Option<bool>,
|
|
120
|
+
) -> Result<DataContractWASM, JsValue> {
|
|
121
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
122
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
123
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
let rs_data_contract_serialization_format = self.0.data_contract();
|
|
127
|
+
|
|
128
|
+
let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
|
|
129
|
+
|
|
130
|
+
let rs_data_contract = DataContract::try_from_platform_versioned(
|
|
131
|
+
rs_data_contract_serialization_format.clone(),
|
|
132
|
+
full_validation.unwrap_or(false),
|
|
133
|
+
&mut validation_operations,
|
|
134
|
+
&platform_version.into(),
|
|
135
|
+
)
|
|
136
|
+
.with_js_error()?;
|
|
137
|
+
|
|
138
|
+
Ok(DataContractWASM::from(rs_data_contract))
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[wasm_bindgen(js_name = "toStateTransition")]
|
|
142
|
+
pub fn to_state_transition(&self) -> StateTransitionWASM {
|
|
143
|
+
let rs_state_transition = StateTransition::from(self.0.clone());
|
|
144
|
+
|
|
145
|
+
StateTransitionWASM::from(rs_state_transition)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#[wasm_bindgen(js_name = "fromStateTransition")]
|
|
149
|
+
pub fn from_state_transition(
|
|
150
|
+
state_transition: &StateTransitionWASM,
|
|
151
|
+
) -> Result<DataContractCreateTransitionWASM, JsValue> {
|
|
152
|
+
let rs_transition = StateTransition::from(state_transition.clone());
|
|
153
|
+
|
|
154
|
+
match rs_transition {
|
|
155
|
+
StateTransition::DataContractCreate(state_transition) => {
|
|
156
|
+
Ok(DataContractCreateTransitionWASM(state_transition))
|
|
157
|
+
}
|
|
158
|
+
_ => Err(JsValue::from("Incorrect transition type")),
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|