pshenmic-dpp 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +9 -1
- package/.github/workflows/publish.yml +9 -1
- package/Cargo.lock +222 -76
- package/Cargo.toml +28 -19
- package/README.md +75 -23
- package/babel.config.json +19 -0
- package/dist/wasm/index.d.ts +52 -0
- package/dist/wasm/pshenmic_dpp.d.ts +962 -0
- package/dist/wasm/pshenmic_dpp.js +5565 -966
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
- package/docs/AssetLockProof.md +107 -0
- package/docs/Building.md +50 -0
- package/docs/ChainLockProof.md +63 -0
- package/docs/CoreScript.md +17 -0
- package/docs/DataContract.md +192 -0
- package/docs/DataContractCreateTransition.md +84 -0
- package/docs/DataContractUpdateTransition.md +84 -0
- package/docs/Document.md +396 -0
- package/docs/DocumentBaseTransition.md +111 -0
- package/docs/DocumentCreateTransition.md +132 -0
- package/docs/DocumentDeleteTransition.md +82 -0
- package/docs/DocumentPurchaseTransition.md +109 -0
- package/docs/DocumentReplaceTransition.md +112 -0
- package/docs/DocumentTransferTransition.md +96 -0
- package/docs/DocumentTransition.md +125 -0
- package/docs/DocumentUpdatePriceTransition.md +109 -0
- package/docs/DocumentsBatch.md +133 -0
- package/docs/Enums.md +103 -0
- package/docs/Home.md +28 -0
- package/docs/Identifier.md +37 -0
- package/docs/Identity.md +140 -0
- package/docs/IdentityCreateTransition.md +155 -0
- package/docs/IdentityCreditTransfer.md +187 -0
- package/docs/IdentityCreditWithdrawalTransition.md +244 -0
- package/docs/IdentityPublicKey.md +348 -0
- package/docs/IdentityPublicKeyInCreation.md +141 -0
- package/docs/IdentityTopUpTransition.md +166 -0
- package/docs/IdentityUpdateTransition.md +234 -0
- package/docs/InstantAssetLockProof.md +117 -0
- package/docs/InstantLock.md +100 -0
- package/docs/OutPoint.md +80 -0
- package/docs/PrefundedVotingBalance.md +48 -0
- package/docs/PrivateKey.md +112 -0
- package/docs/TxOut.md +93 -0
- package/package.json +15 -8
- package/packages/asset_lock_proof/Cargo.toml +19 -0
- package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
- package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
- package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
- package/packages/asset_lock_proof/src/lib.rs +133 -0
- package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
- package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
- package/packages/cbor_conversation/Cargo.toml +2 -2
- package/packages/core_script/Cargo.toml +13 -0
- package/packages/core_script/src/lib.rs +69 -0
- package/packages/data_contract/Cargo.toml +4 -3
- package/packages/data_contract/src/lib.rs +209 -33
- package/packages/data_contract_transitions/Cargo.toml +2 -2
- package/packages/data_contract_transitions/src/create/mod.rs +23 -16
- package/packages/data_contract_transitions/src/update/mod.rs +21 -12
- package/packages/document/Cargo.toml +3 -2
- package/packages/document/src/lib.rs +14 -13
- package/packages/document/src/methods/mod.rs +373 -2
- package/packages/{document_batch → documents_batch}/Cargo.toml +7 -4
- package/packages/documents_batch/src/document_base_transition/mod.rs +88 -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 +195 -0
- package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
- package/packages/documents_batch/src/transitions/create/mod.rs +126 -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 +84 -0
- package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
- package/packages/enums/Cargo.toml +4 -4
- 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 +3 -0
- package/packages/enums/src/lock_types/mod.rs +65 -0
- package/packages/enums/src/network/mod.rs +67 -0
- package/packages/enums/src/platform/mod.rs +68 -8
- package/packages/enums/src/withdrawal/mod.rs +72 -0
- package/packages/identifier/Cargo.toml +9 -0
- package/packages/identifier/src/lib.rs +105 -0
- package/packages/identity/Cargo.toml +5 -5
- package/packages/identity/src/lib.rs +31 -25
- package/packages/{public_key → identity_public_key}/Cargo.toml +2 -2
- package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
- package/packages/identity_transitions/Cargo.toml +8 -4
- package/packages/identity_transitions/src/create_transition/mod.rs +102 -37
- package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
- package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
- package/packages/identity_transitions/src/lib.rs +6 -1
- package/packages/identity_transitions/src/public_key_in_creation/mod.rs +197 -0
- package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
- package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
- package/packages/mock_bls/Cargo.toml +1 -1
- package/packages/private_key/Cargo.toml +4 -3
- package/packages/private_key/src/lib.rs +44 -6
- package/packages/state_transition/Cargo.toml +6 -4
- package/packages/state_transition/src/lib.rs +102 -36
- package/packages/utils/Cargo.toml +3 -4
- package/packages/utils/src/lib.rs +17 -18
- package/scripts/build-js.sh +22 -5
- package/scripts/build.sh +27 -2
- package/src/lib.rs +8 -1
- package/tests/AssetLockProof.spec.js +80 -0
- package/tests/ChainLockProof.spec.js +69 -0
- package/tests/CoreScript.spec.js +37 -0
- package/tests/DataContract.spec.js +178 -0
- package/tests/DataContractCreateStateTransition.spec.js +109 -0
- package/tests/DataContractUpdateStateTransition.spec.js +109 -0
- package/tests/Document.spec.js +238 -0
- package/tests/DocumentBatchTransition.spec.js +109 -0
- package/tests/DocumentTransition.spec.js +97 -0
- package/tests/DocumentsTransitions.spec.js +705 -0
- package/tests/Identifier.spec.js +84 -0
- package/tests/Identity.spec.js +113 -0
- package/tests/IdentityCreateTransition.spec.js +93 -0
- package/tests/IdentityCreditTransferTransition.spec.js +146 -0
- package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
- package/tests/IdentityPublicKey.spec.js +132 -0
- package/tests/IdentityTopUpTransition.spec.js +131 -0
- package/tests/IdentityUpdateTransition.spec.js +147 -0
- package/tests/InstantLockProof.spec.js +97 -0
- package/tests/OutPoint.spec.js +55 -0
- package/tests/PrivateKey.spec.js +73 -0
- package/tests/PublicKeyInCreation.spec.js +258 -0
- package/tests/TxOut.spec.js +76 -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/Locks/index.js +5 -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/typings/index.d.ts +52 -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/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +0 -146
|
@@ -1,18 +1,24 @@
|
|
|
1
1
|
use dpp::dashcore::hashes::serde::Serialize;
|
|
2
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;
|
|
6
7
|
use dpp::data_contract::errors::DataContractError;
|
|
7
8
|
use dpp::data_contract::schema::DataContractSchemaMethodsV0;
|
|
8
9
|
use dpp::data_contract::{DataContract, DataContractV0};
|
|
10
|
+
use dpp::platform_value::string_encoding::Encoding::Base58;
|
|
11
|
+
use dpp::platform_value::{Value, ValueMap};
|
|
9
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
|
|
19
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
20
|
+
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError};
|
|
21
|
+
use std::collections::BTreeMap;
|
|
16
22
|
use wasm_bindgen::JsValue;
|
|
17
23
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
18
24
|
|
|
@@ -35,11 +41,101 @@ impl From<DataContractWASM> for DataContract {
|
|
|
35
41
|
#[wasm_bindgen]
|
|
36
42
|
impl DataContractWASM {
|
|
37
43
|
#[wasm_bindgen(constructor)]
|
|
38
|
-
pub fn
|
|
44
|
+
pub fn from_js_values(
|
|
45
|
+
js_owner_id: &JsValue,
|
|
46
|
+
identity_nonce: IdentityNonce,
|
|
47
|
+
js_schema: JsValue,
|
|
48
|
+
js_definitions: Option<js_sys::Object>,
|
|
49
|
+
full_validation: bool,
|
|
50
|
+
js_platform_version: JsValue,
|
|
51
|
+
) -> Result<DataContractWASM, JsValue> {
|
|
52
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
53
|
+
|
|
54
|
+
let owner_id: IdentifierWASM = js_owner_id.clone().try_into()?;
|
|
55
|
+
|
|
56
|
+
let owner_id_value = Value::from(owner_id.get_base58());
|
|
57
|
+
|
|
58
|
+
let schema: Value = serde_wasm_bindgen::from_value(js_schema)?;
|
|
59
|
+
|
|
60
|
+
let platform_version: PlatformVersion = match js_platform_version.is_undefined() {
|
|
61
|
+
true => PlatformVersionWASM::default().into(),
|
|
62
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?.into(),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
let data_contract_structure_version_value = Value::from(
|
|
66
|
+
platform_version
|
|
67
|
+
.dpp
|
|
68
|
+
.contract_versions
|
|
69
|
+
.contract_structure_version
|
|
70
|
+
.to_string(),
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
let definitions = js_definitions
|
|
74
|
+
.map(|definitions| serde_wasm_bindgen::from_value(definitions.into()))
|
|
75
|
+
.transpose()?;
|
|
76
|
+
|
|
77
|
+
let definitions_value = Value::from(definitions);
|
|
78
|
+
|
|
79
|
+
let data_contract_id =
|
|
80
|
+
DataContract::generate_data_contract_id_v0(owner_id.get_bytes(), identity_nonce);
|
|
81
|
+
|
|
82
|
+
let data_contract_id_value = Value::from(data_contract_id.to_string(Base58));
|
|
83
|
+
|
|
84
|
+
let config =
|
|
85
|
+
DataContractConfig::default_for_version(&platform_version.clone()).with_js_error()?;
|
|
86
|
+
|
|
87
|
+
let config_value = config
|
|
88
|
+
.serialize(&serializer)
|
|
89
|
+
.map_err(JsValue::from)?
|
|
90
|
+
.with_serde_to_platform_value_map()?;
|
|
91
|
+
|
|
92
|
+
let mut contract_value = Value::Map(ValueMap::new());
|
|
93
|
+
|
|
94
|
+
contract_value
|
|
95
|
+
.set_value("$format_version", data_contract_structure_version_value)
|
|
96
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
97
|
+
|
|
98
|
+
contract_value
|
|
99
|
+
.set_value("id", data_contract_id_value)
|
|
100
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
101
|
+
|
|
102
|
+
contract_value
|
|
103
|
+
.set_value("config", Value::from(config_value))
|
|
104
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
105
|
+
|
|
106
|
+
contract_value
|
|
107
|
+
.set_value("version", Value::from(1u16))
|
|
108
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
109
|
+
|
|
110
|
+
contract_value
|
|
111
|
+
.set_value("ownerId", owner_id_value)
|
|
112
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
113
|
+
|
|
114
|
+
contract_value
|
|
115
|
+
.set_value("schemaDefs", definitions_value)
|
|
116
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
117
|
+
|
|
118
|
+
contract_value
|
|
119
|
+
.set_value("documentSchemas", schema)
|
|
120
|
+
.map_err(|err| JsValue::from(err.to_string()))?;
|
|
121
|
+
|
|
122
|
+
Ok(DataContractWASM(
|
|
123
|
+
DataContract::from_value(contract_value, full_validation, &platform_version)
|
|
124
|
+
.with_js_error()?,
|
|
125
|
+
))
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
#[wasm_bindgen(js_name = "fromValue")]
|
|
129
|
+
pub fn from_value(
|
|
39
130
|
js_value: JsValue,
|
|
40
131
|
full_validation: bool,
|
|
41
|
-
|
|
132
|
+
js_platform_version: JsValue,
|
|
42
133
|
) -> Result<DataContractWASM, JsValue> {
|
|
134
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
135
|
+
true => PlatformVersionWASM::default(),
|
|
136
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
137
|
+
};
|
|
138
|
+
|
|
43
139
|
let value = js_value.with_serde_to_platform_value()?;
|
|
44
140
|
|
|
45
141
|
let v0_contract =
|
|
@@ -53,8 +149,13 @@ impl DataContractWASM {
|
|
|
53
149
|
pub fn from_bytes(
|
|
54
150
|
bytes: Vec<u8>,
|
|
55
151
|
full_validation: bool,
|
|
56
|
-
|
|
152
|
+
js_platform_version: JsValue,
|
|
57
153
|
) -> Result<DataContractWASM, JsValue> {
|
|
154
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
155
|
+
true => PlatformVersionWASM::default(),
|
|
156
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
157
|
+
};
|
|
158
|
+
|
|
58
159
|
let rs_data_contract = DataContract::versioned_deserialize(
|
|
59
160
|
&bytes.as_slice(),
|
|
60
161
|
full_validation,
|
|
@@ -66,7 +167,12 @@ impl DataContractWASM {
|
|
|
66
167
|
}
|
|
67
168
|
|
|
68
169
|
#[wasm_bindgen(js_name = "toBytes")]
|
|
69
|
-
pub fn to_bytes(&self,
|
|
170
|
+
pub fn to_bytes(&self, js_platform_version: JsValue) -> Result<Vec<u8>, JsValue> {
|
|
171
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
172
|
+
true => PlatformVersionWASM::default(),
|
|
173
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
174
|
+
};
|
|
175
|
+
|
|
70
176
|
let rs_data_contract: DataContract = self.0.clone();
|
|
71
177
|
|
|
72
178
|
rs_data_contract
|
|
@@ -75,7 +181,12 @@ impl DataContractWASM {
|
|
|
75
181
|
}
|
|
76
182
|
|
|
77
183
|
#[wasm_bindgen(js_name = "toValue")]
|
|
78
|
-
pub fn to_value(&self,
|
|
184
|
+
pub fn to_value(&self, js_platform_version: JsValue) -> Result<JsValue, JsValue> {
|
|
185
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
186
|
+
true => PlatformVersionWASM::default(),
|
|
187
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
188
|
+
};
|
|
189
|
+
|
|
79
190
|
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
80
191
|
|
|
81
192
|
self.0
|
|
@@ -86,7 +197,7 @@ impl DataContractWASM {
|
|
|
86
197
|
.map_err(JsValue::from)
|
|
87
198
|
}
|
|
88
199
|
|
|
89
|
-
#[wasm_bindgen(js_name = "
|
|
200
|
+
#[wasm_bindgen(js_name = "getSchema")]
|
|
90
201
|
pub fn get_schemas(&self) -> Result<JsValue, JsValue> {
|
|
91
202
|
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
92
203
|
|
|
@@ -96,19 +207,19 @@ impl DataContractWASM {
|
|
|
96
207
|
.map_err(JsValue::from)
|
|
97
208
|
}
|
|
98
209
|
|
|
99
|
-
#[wasm_bindgen(js_name = "
|
|
100
|
-
pub fn
|
|
210
|
+
#[wasm_bindgen(js_name = "getVersion")]
|
|
211
|
+
pub fn get_version(&self) -> u32 {
|
|
101
212
|
self.0.version()
|
|
102
213
|
}
|
|
103
214
|
|
|
104
215
|
#[wasm_bindgen(js_name = "getId")]
|
|
105
|
-
pub fn get_id(&self) ->
|
|
106
|
-
self.0.id().
|
|
216
|
+
pub fn get_id(&self) -> IdentifierWASM {
|
|
217
|
+
self.0.id().into()
|
|
107
218
|
}
|
|
108
219
|
|
|
109
220
|
#[wasm_bindgen(js_name = "getOwnerId")]
|
|
110
|
-
pub fn get_owner_id(&self) ->
|
|
111
|
-
self.0.owner_id().
|
|
221
|
+
pub fn get_owner_id(&self) -> IdentifierWASM {
|
|
222
|
+
self.0.owner_id().into()
|
|
112
223
|
}
|
|
113
224
|
|
|
114
225
|
#[wasm_bindgen(js_name = "getConfig")]
|
|
@@ -119,36 +230,101 @@ impl DataContractWASM {
|
|
|
119
230
|
.map_err(JsValue::from)
|
|
120
231
|
}
|
|
121
232
|
|
|
122
|
-
#[wasm_bindgen(js_name = "
|
|
123
|
-
pub fn
|
|
124
|
-
|
|
233
|
+
#[wasm_bindgen(js_name = "setId")]
|
|
234
|
+
pub fn set_id(&mut self, js_data_contract_id: &JsValue) -> Result<(), JsValue> {
|
|
235
|
+
self.0
|
|
236
|
+
.set_id(IdentifierWASM::try_from(js_data_contract_id)?.into());
|
|
237
|
+
Ok(())
|
|
238
|
+
}
|
|
125
239
|
|
|
126
|
-
|
|
127
|
-
|
|
240
|
+
#[wasm_bindgen(js_name = "setOwnerId")]
|
|
241
|
+
pub fn set_owner_id(&mut self, js_owner_id: &JsValue) -> Result<(), JsValue> {
|
|
242
|
+
self.0
|
|
243
|
+
.set_owner_id(IdentifierWASM::try_from(js_owner_id)?.into());
|
|
244
|
+
Ok(())
|
|
128
245
|
}
|
|
129
246
|
|
|
130
|
-
#[wasm_bindgen(js_name = "
|
|
131
|
-
pub fn
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
247
|
+
#[wasm_bindgen(js_name = "setVersion")]
|
|
248
|
+
pub fn set_version(&mut self, version: u32) {
|
|
249
|
+
self.0.set_version(version)
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
#[wasm_bindgen(js_name = "setConfig")]
|
|
253
|
+
pub fn set_config(
|
|
254
|
+
&mut self,
|
|
255
|
+
js_config: JsValue,
|
|
256
|
+
js_platform_version: JsValue,
|
|
257
|
+
) -> Result<(), JsValue> {
|
|
258
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
259
|
+
true => PlatformVersionWASM::default(),
|
|
260
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
let config_value: Value = serde_wasm_bindgen::from_value(js_config)?;
|
|
136
264
|
|
|
137
|
-
|
|
265
|
+
let config = DataContractConfig::from_value(config_value, &platform_version.into())
|
|
266
|
+
.with_js_error()?;
|
|
267
|
+
|
|
268
|
+
self.0.set_config(config);
|
|
269
|
+
|
|
270
|
+
Ok(())
|
|
138
271
|
}
|
|
139
272
|
|
|
140
|
-
#[wasm_bindgen(js_name = "
|
|
141
|
-
pub fn
|
|
142
|
-
|
|
273
|
+
#[wasm_bindgen(js_name = "setSchema")]
|
|
274
|
+
pub fn set_schemas(
|
|
275
|
+
&mut self,
|
|
276
|
+
js_schema: JsValue,
|
|
277
|
+
js_definitions: Option<js_sys::Object>,
|
|
278
|
+
full_validation: bool,
|
|
279
|
+
js_platform_version: JsValue,
|
|
280
|
+
) -> Result<(), JsValue> {
|
|
281
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
282
|
+
true => PlatformVersionWASM::default(),
|
|
283
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
284
|
+
};
|
|
143
285
|
|
|
144
|
-
|
|
286
|
+
let schema = js_schema.with_serde_to_platform_value_map()?;
|
|
287
|
+
|
|
288
|
+
let definitions: Option<BTreeMap<String, Value>> = js_definitions
|
|
289
|
+
.map(|definitions| serde_wasm_bindgen::from_value(definitions.into()))
|
|
290
|
+
.transpose()?;
|
|
291
|
+
|
|
292
|
+
self.0
|
|
293
|
+
.set_document_schemas(
|
|
294
|
+
schema,
|
|
295
|
+
definitions,
|
|
296
|
+
full_validation,
|
|
297
|
+
&mut Vec::new(),
|
|
298
|
+
&platform_version.into(),
|
|
299
|
+
)
|
|
300
|
+
.with_js_error()?;
|
|
301
|
+
|
|
302
|
+
Ok(())
|
|
145
303
|
}
|
|
146
304
|
|
|
147
|
-
#[wasm_bindgen(js_name = "
|
|
148
|
-
pub fn
|
|
149
|
-
let
|
|
305
|
+
#[wasm_bindgen(js_name = "toJson")]
|
|
306
|
+
pub fn to_json(&self, js_platform_version: JsValue) -> Result<JsValue, JsValue> {
|
|
307
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
308
|
+
true => PlatformVersionWASM::default(),
|
|
309
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
let json = self.0.to_json(&platform_version.into()).with_js_error()?;
|
|
150
313
|
|
|
151
|
-
|
|
314
|
+
json.serialize(&serde_wasm_bindgen::Serializer::json_compatible())
|
|
315
|
+
.map_err(JsValue::from)
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
#[wasm_bindgen(js_name = "generateId")]
|
|
319
|
+
pub fn generate_id(
|
|
320
|
+
js_owner_id: &JsValue,
|
|
321
|
+
identity_nonce: IdentityNonce,
|
|
322
|
+
) -> Result<IdentifierWASM, JsValue> {
|
|
323
|
+
Ok(DataContract::generate_data_contract_id_v0(
|
|
324
|
+
IdentifierWASM::try_from(js_owner_id)?.get_bytes(),
|
|
325
|
+
identity_nonce,
|
|
326
|
+
)
|
|
327
|
+
.into())
|
|
152
328
|
}
|
|
153
329
|
}
|
|
154
330
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_data_contract_transitions"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[dependencies]
|
|
7
|
-
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
7
|
+
wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
|
|
8
8
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
9
9
|
"state-transition-signing"
|
|
10
10
|
]}
|
|
@@ -27,18 +27,19 @@ impl DataContractCreateTransitionWASM {
|
|
|
27
27
|
pub fn new(
|
|
28
28
|
data_contract: &DataContractWASM,
|
|
29
29
|
identity_nonce: IdentityNonce,
|
|
30
|
-
|
|
30
|
+
js_platform_version: JsValue,
|
|
31
31
|
) -> Result<DataContractCreateTransitionWASM, JsValue> {
|
|
32
32
|
let rs_data_contract: DataContract = data_contract.clone().into();
|
|
33
33
|
|
|
34
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
35
|
+
true => PlatformVersionWASM::default(),
|
|
36
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
37
|
+
};
|
|
38
|
+
|
|
34
39
|
let rs_data_contract_in_serialized: Result<
|
|
35
40
|
DataContractInSerializationFormat,
|
|
36
41
|
ProtocolError,
|
|
37
|
-
> = rs_data_contract.try_into_platform_versioned(
|
|
38
|
-
&platform_version
|
|
39
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
40
|
-
.into(),
|
|
41
|
-
);
|
|
42
|
+
> = rs_data_contract.try_into_platform_versioned(&platform_version.into());
|
|
42
43
|
|
|
43
44
|
let rs_data_contract_create_transition_v0: DataContractCreateTransitionV0 =
|
|
44
45
|
DataContractCreateTransitionV0 {
|
|
@@ -91,15 +92,18 @@ impl DataContractCreateTransitionWASM {
|
|
|
91
92
|
#[wasm_bindgen(js_name = "setDataContract")]
|
|
92
93
|
pub fn set_data_contract(
|
|
93
94
|
&mut self,
|
|
94
|
-
data_contract: DataContractWASM,
|
|
95
|
-
|
|
95
|
+
data_contract: &DataContractWASM,
|
|
96
|
+
js_platform_version: JsValue,
|
|
96
97
|
) -> Result<(), JsValue> {
|
|
98
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
99
|
+
true => PlatformVersionWASM::default(),
|
|
100
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
101
|
+
};
|
|
102
|
+
|
|
97
103
|
let data_contract_serialization_format =
|
|
98
104
|
DataContractInSerializationFormat::try_from_platform_versioned(
|
|
99
|
-
DataContract::from(data_contract),
|
|
100
|
-
&
|
|
101
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
102
|
-
.into(),
|
|
105
|
+
DataContract::from(data_contract.clone()),
|
|
106
|
+
&platform_version.into(),
|
|
103
107
|
)
|
|
104
108
|
.with_js_error()?;
|
|
105
109
|
|
|
@@ -111,9 +115,14 @@ impl DataContractCreateTransitionWASM {
|
|
|
111
115
|
#[wasm_bindgen(js_name = "getDataContract")]
|
|
112
116
|
pub fn get_data_contract(
|
|
113
117
|
&self,
|
|
114
|
-
|
|
118
|
+
js_platform_version: JsValue,
|
|
115
119
|
full_validation: Option<bool>,
|
|
116
120
|
) -> Result<DataContractWASM, JsValue> {
|
|
121
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
122
|
+
true => PlatformVersionWASM::default(),
|
|
123
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
124
|
+
};
|
|
125
|
+
|
|
117
126
|
let rs_data_contract_serialization_format = self.0.data_contract();
|
|
118
127
|
|
|
119
128
|
let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
|
|
@@ -122,9 +131,7 @@ impl DataContractCreateTransitionWASM {
|
|
|
122
131
|
rs_data_contract_serialization_format.clone(),
|
|
123
132
|
full_validation.unwrap_or(false),
|
|
124
133
|
&mut validation_operations,
|
|
125
|
-
&
|
|
126
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
127
|
-
.into(),
|
|
134
|
+
&platform_version.into(),
|
|
128
135
|
)
|
|
129
136
|
.with_js_error()?;
|
|
130
137
|
|
|
@@ -22,14 +22,17 @@ impl DataContractUpdateTransitionWASM {
|
|
|
22
22
|
pub fn new(
|
|
23
23
|
data_contract: &DataContractWASM,
|
|
24
24
|
identity_nonce: IdentityNonce,
|
|
25
|
-
|
|
25
|
+
js_platform_version: JsValue,
|
|
26
26
|
) -> Result<DataContractUpdateTransitionWASM, JsValue> {
|
|
27
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
28
|
+
true => PlatformVersionWASM::default(),
|
|
29
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
30
|
+
};
|
|
31
|
+
|
|
27
32
|
let rs_data_contract_update_transition =
|
|
28
33
|
DataContractUpdateTransition::try_from_platform_versioned(
|
|
29
34
|
(DataContract::from(data_contract.clone()), identity_nonce),
|
|
30
|
-
&platform_version
|
|
31
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
32
|
-
.into(),
|
|
35
|
+
&platform_version.into(),
|
|
33
36
|
)
|
|
34
37
|
.with_js_error()?;
|
|
35
38
|
|
|
@@ -73,14 +76,17 @@ impl DataContractUpdateTransitionWASM {
|
|
|
73
76
|
pub fn set_data_contract(
|
|
74
77
|
&mut self,
|
|
75
78
|
data_contract: &DataContractWASM,
|
|
76
|
-
|
|
79
|
+
js_platform_version: JsValue,
|
|
77
80
|
) -> Result<(), JsValue> {
|
|
81
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
82
|
+
true => PlatformVersionWASM::default(),
|
|
83
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
84
|
+
};
|
|
85
|
+
|
|
78
86
|
let data_contract_serialization_format =
|
|
79
87
|
DataContractInSerializationFormat::try_from_platform_versioned(
|
|
80
88
|
DataContract::from(data_contract.clone()),
|
|
81
|
-
&
|
|
82
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
83
|
-
.into(),
|
|
89
|
+
&platform_version.into(),
|
|
84
90
|
)
|
|
85
91
|
.with_js_error()?;
|
|
86
92
|
|
|
@@ -93,8 +99,13 @@ impl DataContractUpdateTransitionWASM {
|
|
|
93
99
|
pub fn get_data_contract(
|
|
94
100
|
&self,
|
|
95
101
|
full_validation: Option<bool>,
|
|
96
|
-
|
|
102
|
+
js_platform_version: JsValue,
|
|
97
103
|
) -> Result<DataContractWASM, JsValue> {
|
|
104
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
105
|
+
true => PlatformVersionWASM::default(),
|
|
106
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
107
|
+
};
|
|
108
|
+
|
|
98
109
|
let data_contract_serialization_format = self.0.data_contract();
|
|
99
110
|
|
|
100
111
|
let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
|
|
@@ -103,9 +114,7 @@ impl DataContractUpdateTransitionWASM {
|
|
|
103
114
|
data_contract_serialization_format.clone(),
|
|
104
115
|
full_validation.unwrap_or(false),
|
|
105
116
|
&mut validation_operations,
|
|
106
|
-
&
|
|
107
|
-
.unwrap_or(PlatformVersionWASM::PLATFORM_V1)
|
|
108
|
-
.into(),
|
|
117
|
+
&platform_version.into(),
|
|
109
118
|
)
|
|
110
119
|
.with_js_error()?;
|
|
111
120
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_document"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
7
7
|
crate-type = ["cdylib", "lib"]
|
|
8
8
|
|
|
9
9
|
[dependencies]
|
|
10
|
-
wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
|
|
10
|
+
wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
|
|
11
11
|
pshenmic_dpp_utils = {path = "../utils"}
|
|
12
|
+
pshenmic_dpp_identifier = { path = "../identifier" }
|
|
12
13
|
pshenmic_dpp_enums = {path = "../enums"}
|
|
13
14
|
pshenmic_dpp_data_contract = {path = "../data_contract"}
|
|
14
15
|
dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
|
|
@@ -1,20 +1,21 @@
|
|
|
1
|
-
mod methods;
|
|
1
|
+
pub mod methods;
|
|
2
2
|
|
|
3
3
|
use dpp::document::{Document, DocumentV0, DocumentV0Getters};
|
|
4
4
|
use dpp::identifier::Identifier;
|
|
5
5
|
use dpp::identity::TimestampMillis;
|
|
6
6
|
use dpp::platform_value::Value;
|
|
7
7
|
use dpp::prelude::{BlockHeight, CoreBlockHeight, Revision};
|
|
8
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
8
9
|
use std::collections::BTreeMap;
|
|
9
10
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
10
11
|
|
|
11
|
-
#[derive(
|
|
12
|
+
#[derive(Clone)]
|
|
12
13
|
#[wasm_bindgen(js_name = DocumentWASM)]
|
|
13
14
|
pub struct DocumentWASM {
|
|
14
|
-
id:
|
|
15
|
-
owner_id:
|
|
15
|
+
id: IdentifierWASM,
|
|
16
|
+
owner_id: IdentifierWASM,
|
|
16
17
|
revision: Option<Revision>,
|
|
17
|
-
data_contract_id:
|
|
18
|
+
data_contract_id: IdentifierWASM,
|
|
18
19
|
document_type_name: String,
|
|
19
20
|
properties: BTreeMap<String, Value>,
|
|
20
21
|
created_at: Option<TimestampMillis>,
|
|
@@ -32,8 +33,8 @@ pub struct DocumentWASM {
|
|
|
32
33
|
impl From<DocumentWASM> for Document {
|
|
33
34
|
fn from(wasm_doc: DocumentWASM) -> Self {
|
|
34
35
|
Document::V0(DocumentV0 {
|
|
35
|
-
id: wasm_doc.id,
|
|
36
|
-
owner_id: wasm_doc.owner_id,
|
|
36
|
+
id: wasm_doc.id.into(),
|
|
37
|
+
owner_id: wasm_doc.owner_id.into(),
|
|
37
38
|
properties: wasm_doc.properties,
|
|
38
39
|
revision: wasm_doc.revision,
|
|
39
40
|
created_at: wasm_doc.created_at,
|
|
@@ -52,10 +53,10 @@ impl From<DocumentWASM> for Document {
|
|
|
52
53
|
impl From<Document> for DocumentWASM {
|
|
53
54
|
fn from(doc: Document) -> Self {
|
|
54
55
|
DocumentWASM {
|
|
55
|
-
id: doc.id(),
|
|
56
|
-
owner_id: doc.owner_id(),
|
|
56
|
+
id: doc.id().into(),
|
|
57
|
+
owner_id: doc.owner_id().into(),
|
|
57
58
|
revision: doc.revision(),
|
|
58
|
-
data_contract_id:
|
|
59
|
+
data_contract_id: Identifier::default().into(),
|
|
59
60
|
document_type_name: "".to_string(),
|
|
60
61
|
properties: doc.properties().clone(),
|
|
61
62
|
created_at: doc.created_at(),
|
|
@@ -80,10 +81,10 @@ impl DocumentWASM {
|
|
|
80
81
|
entropy: Option<[u8; 32]>,
|
|
81
82
|
) -> Self {
|
|
82
83
|
DocumentWASM {
|
|
83
|
-
id: document.id(),
|
|
84
|
-
owner_id: document.owner_id(),
|
|
84
|
+
id: document.id().into(),
|
|
85
|
+
owner_id: document.owner_id().into(),
|
|
85
86
|
revision: document.revision(),
|
|
86
|
-
data_contract_id,
|
|
87
|
+
data_contract_id: data_contract_id.into(),
|
|
87
88
|
document_type_name,
|
|
88
89
|
properties: document.properties().clone(),
|
|
89
90
|
created_at: document.created_at(),
|