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
|
@@ -0,0 +1,144 @@
|
|
|
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
|
+
js_platform_version: JsValue,
|
|
26
|
+
) -> Result<DataContractUpdateTransitionWASM, JsValue> {
|
|
27
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
28
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
29
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
let rs_data_contract_update_transition =
|
|
33
|
+
DataContractUpdateTransition::try_from_platform_versioned(
|
|
34
|
+
(DataContract::from(data_contract.clone()), identity_nonce),
|
|
35
|
+
&platform_version.into(),
|
|
36
|
+
)
|
|
37
|
+
.with_js_error()?;
|
|
38
|
+
|
|
39
|
+
Ok(DataContractUpdateTransitionWASM(
|
|
40
|
+
rs_data_contract_update_transition,
|
|
41
|
+
))
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
45
|
+
pub fn from_bytes(bytes: Vec<u8>) -> Result<DataContractUpdateTransitionWASM, JsValue> {
|
|
46
|
+
let rs_data_contract_update_transition: DataContractUpdateTransition =
|
|
47
|
+
DataContractUpdateTransition::deserialize_from_bytes(bytes.as_slice())
|
|
48
|
+
.with_js_error()?;
|
|
49
|
+
|
|
50
|
+
Ok(DataContractUpdateTransitionWASM(
|
|
51
|
+
rs_data_contract_update_transition,
|
|
52
|
+
))
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
#[wasm_bindgen(js_name = "toBytes")]
|
|
56
|
+
pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
57
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
#[wasm_bindgen(js_name = "getFeatureVersion")]
|
|
61
|
+
pub fn get_feature_version(&self) -> FeatureVersion {
|
|
62
|
+
self.0.feature_version()
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[wasm_bindgen(js_name = "verifyProtocolVersion")]
|
|
66
|
+
pub fn verify_protocol_version(
|
|
67
|
+
&self,
|
|
68
|
+
protocol_version: ProtocolVersion,
|
|
69
|
+
) -> Result<bool, JsValue> {
|
|
70
|
+
self.0
|
|
71
|
+
.verify_protocol_version(protocol_version)
|
|
72
|
+
.with_js_error()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[wasm_bindgen(js_name = "setDataContract")]
|
|
76
|
+
pub fn set_data_contract(
|
|
77
|
+
&mut self,
|
|
78
|
+
data_contract: &DataContractWASM,
|
|
79
|
+
js_platform_version: JsValue,
|
|
80
|
+
) -> Result<(), JsValue> {
|
|
81
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
82
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
83
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
let data_contract_serialization_format =
|
|
87
|
+
DataContractInSerializationFormat::try_from_platform_versioned(
|
|
88
|
+
DataContract::from(data_contract.clone()),
|
|
89
|
+
&platform_version.into(),
|
|
90
|
+
)
|
|
91
|
+
.with_js_error()?;
|
|
92
|
+
|
|
93
|
+
self.0.set_data_contract(data_contract_serialization_format);
|
|
94
|
+
|
|
95
|
+
Ok(())
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
#[wasm_bindgen(js_name = "getDataContract")]
|
|
99
|
+
pub fn get_data_contract(
|
|
100
|
+
&self,
|
|
101
|
+
full_validation: Option<bool>,
|
|
102
|
+
js_platform_version: JsValue,
|
|
103
|
+
) -> Result<DataContractWASM, JsValue> {
|
|
104
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
105
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
106
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
let data_contract_serialization_format = self.0.data_contract();
|
|
110
|
+
|
|
111
|
+
let mut validation_operations: Vec<ProtocolValidationOperation> = Vec::new();
|
|
112
|
+
|
|
113
|
+
let rs_data_contract = DataContract::try_from_platform_versioned(
|
|
114
|
+
data_contract_serialization_format.clone(),
|
|
115
|
+
full_validation.unwrap_or(false),
|
|
116
|
+
&mut validation_operations,
|
|
117
|
+
&platform_version.into(),
|
|
118
|
+
)
|
|
119
|
+
.with_js_error()?;
|
|
120
|
+
|
|
121
|
+
Ok(DataContractWASM::from(rs_data_contract))
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[wasm_bindgen(js_name = "toStateTransition")]
|
|
125
|
+
pub fn to_state_transition(&self) -> StateTransitionWASM {
|
|
126
|
+
let rs_state_transition = StateTransition::from(self.0.clone());
|
|
127
|
+
|
|
128
|
+
StateTransitionWASM::from(rs_state_transition)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#[wasm_bindgen(js_name = "fromStateTransition")]
|
|
132
|
+
pub fn from_state_transition(
|
|
133
|
+
state_transition: &StateTransitionWASM,
|
|
134
|
+
) -> Result<DataContractUpdateTransitionWASM, JsValue> {
|
|
135
|
+
let rs_transition = StateTransition::from(state_transition.clone());
|
|
136
|
+
|
|
137
|
+
match rs_transition {
|
|
138
|
+
StateTransition::DataContractUpdate(state_transition) => {
|
|
139
|
+
Ok(DataContractUpdateTransitionWASM(state_transition))
|
|
140
|
+
}
|
|
141
|
+
_ => Err(JsValue::from("Incorrect transition type")),
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[package]
|
|
2
2
|
name = "pshenmic_dpp_document"
|
|
3
|
-
version =
|
|
3
|
+
version.workspace = true
|
|
4
4
|
edition = "2024"
|
|
5
5
|
|
|
6
6
|
[lib]
|
|
@@ -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" }
|
|
@@ -1,2 +1,370 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
use crate::DocumentWASM;
|
|
2
|
+
use dpp::ProtocolError;
|
|
3
|
+
use dpp::dashcore::hashes::serde::Serialize;
|
|
4
|
+
use dpp::data_contract::JsonValue;
|
|
5
|
+
use dpp::document::Document;
|
|
6
|
+
use dpp::document::serialization_traits::DocumentPlatformConversionMethodsV0;
|
|
7
|
+
use dpp::identifier::Identifier;
|
|
8
|
+
use dpp::platform_value::Value;
|
|
9
|
+
use dpp::platform_value::converter::serde_json::BTreeValueJsonConverter;
|
|
10
|
+
use dpp::prelude::Revision;
|
|
11
|
+
use dpp::util::entropy_generator;
|
|
12
|
+
use dpp::util::entropy_generator::EntropyGenerator;
|
|
13
|
+
use pshenmic_dpp_data_contract::DataContractWASM;
|
|
14
|
+
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
15
|
+
use pshenmic_dpp_utils::{ToSerdeJSONExt, WithJsError, identifier_from_js_value};
|
|
16
|
+
use std::collections::BTreeMap;
|
|
17
|
+
use wasm_bindgen::JsValue;
|
|
18
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
19
|
+
|
|
20
|
+
#[wasm_bindgen]
|
|
21
|
+
impl DocumentWASM {
|
|
22
|
+
#[wasm_bindgen(constructor)]
|
|
23
|
+
pub fn new(
|
|
24
|
+
js_raw_document: JsValue,
|
|
25
|
+
js_document_type_name: &str,
|
|
26
|
+
js_revision: u64,
|
|
27
|
+
js_data_contract_id: JsValue,
|
|
28
|
+
js_owner_id: JsValue,
|
|
29
|
+
js_document_id: JsValue,
|
|
30
|
+
) -> Result<DocumentWASM, JsValue> {
|
|
31
|
+
let revision = Revision::from(js_revision);
|
|
32
|
+
|
|
33
|
+
let document = js_raw_document
|
|
34
|
+
.with_serde_to_platform_value_map()
|
|
35
|
+
.expect("cannot convert document to platform value map");
|
|
36
|
+
|
|
37
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
38
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
39
|
+
let revision = Revision::from(revision);
|
|
40
|
+
|
|
41
|
+
let entropy = entropy_generator::DefaultEntropyGenerator
|
|
42
|
+
.generate()
|
|
43
|
+
.unwrap();
|
|
44
|
+
|
|
45
|
+
let document_id: Identifier = {
|
|
46
|
+
if JsValue::UNDEFINED == js_document_id {
|
|
47
|
+
pshenmic_dpp_utils::generate_document_id_v0(
|
|
48
|
+
&data_contract_id,
|
|
49
|
+
&owner_id,
|
|
50
|
+
js_document_type_name,
|
|
51
|
+
&entropy,
|
|
52
|
+
)
|
|
53
|
+
} else {
|
|
54
|
+
identifier_from_js_value(&js_document_id)
|
|
55
|
+
}
|
|
56
|
+
}?;
|
|
57
|
+
|
|
58
|
+
Ok(DocumentWASM {
|
|
59
|
+
owner_id,
|
|
60
|
+
entropy: Some(entropy),
|
|
61
|
+
id: document_id,
|
|
62
|
+
document_type_name: js_document_type_name.to_string(),
|
|
63
|
+
data_contract_id,
|
|
64
|
+
properties: document,
|
|
65
|
+
revision: Some(revision),
|
|
66
|
+
created_at: None,
|
|
67
|
+
updated_at: None,
|
|
68
|
+
transferred_at: None,
|
|
69
|
+
created_at_block_height: None,
|
|
70
|
+
updated_at_block_height: None,
|
|
71
|
+
transferred_at_block_height: None,
|
|
72
|
+
created_at_core_block_height: None,
|
|
73
|
+
updated_at_core_block_height: None,
|
|
74
|
+
transferred_at_core_block_height: None,
|
|
75
|
+
})
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#[wasm_bindgen(js_name=getId)]
|
|
79
|
+
pub fn get_id(&self) -> Vec<u8> {
|
|
80
|
+
self.id.to_vec()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[wasm_bindgen(js_name=getEntropy)]
|
|
84
|
+
pub fn get_entropy(&self) -> Option<Vec<u8>> {
|
|
85
|
+
match self.entropy {
|
|
86
|
+
Some(entropy) => Some(entropy.to_vec()),
|
|
87
|
+
None => None,
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
#[wasm_bindgen(js_name=getDataContractId)]
|
|
92
|
+
pub fn get_data_contract_id(&self) -> Vec<u8> {
|
|
93
|
+
self.data_contract_id.to_vec()
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
#[wasm_bindgen(js_name=getOwnerId)]
|
|
97
|
+
pub fn get_owner_id(&self) -> Vec<u8> {
|
|
98
|
+
self.owner_id.to_vec()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
#[wasm_bindgen(js_name=getProperties)]
|
|
102
|
+
pub fn get_properties(&self) -> Result<JsValue, JsValue> {
|
|
103
|
+
let json_value: JsonValue = self
|
|
104
|
+
.properties
|
|
105
|
+
.clone()
|
|
106
|
+
.to_json_value()
|
|
107
|
+
.map_err(ProtocolError::ValueError)
|
|
108
|
+
.with_js_error()?;
|
|
109
|
+
|
|
110
|
+
let js_value = json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible())?;
|
|
111
|
+
Ok(js_value)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#[wasm_bindgen(js_name=getRevision)]
|
|
115
|
+
pub fn get_revision(&self) -> Option<u64> {
|
|
116
|
+
self.revision
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
#[wasm_bindgen(js_name=getCreatedAt)]
|
|
120
|
+
pub fn get_created_at(&self) -> Option<u64> {
|
|
121
|
+
self.created_at
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[wasm_bindgen(js_name=getUpdatedAt)]
|
|
125
|
+
pub fn get_updated_at(&self) -> Option<u64> {
|
|
126
|
+
self.updated_at
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
#[wasm_bindgen(js_name=getTransferredAt)]
|
|
130
|
+
pub fn get_transferred_at(&self) -> Option<u64> {
|
|
131
|
+
self.transferred_at
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
#[wasm_bindgen(js_name=getCreatedAtBlockHeight)]
|
|
135
|
+
pub fn get_created_at_block_height(&self) -> Option<u64> {
|
|
136
|
+
self.created_at_block_height
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
#[wasm_bindgen(js_name=getUpdatedAtBlockHeight)]
|
|
140
|
+
pub fn get_updated_at_block_height(&self) -> Option<u64> {
|
|
141
|
+
self.updated_at_block_height
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
#[wasm_bindgen(js_name=getTransferredAtBlockHeight)]
|
|
145
|
+
pub fn get_transferred_at_block_height(&self) -> Option<u64> {
|
|
146
|
+
self.transferred_at_block_height
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
#[wasm_bindgen(js_name=getCreatedAtCoreBlockHeight)]
|
|
150
|
+
pub fn get_created_at_core_block_height(&self) -> Option<u32> {
|
|
151
|
+
self.created_at_core_block_height
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
#[wasm_bindgen(js_name=getUpdatedAtCoreBlockHeight)]
|
|
155
|
+
pub fn get_updated_at_core_block_height(&self) -> Option<u32> {
|
|
156
|
+
self.updated_at_core_block_height
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
#[wasm_bindgen(js_name=getTransferredAtCoreBlockHeight)]
|
|
160
|
+
pub fn get_transferred_at_core_block_height(&self) -> Option<u32> {
|
|
161
|
+
self.transferred_at_core_block_height
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
#[wasm_bindgen(js_name=getDocumentTypeName)]
|
|
165
|
+
pub fn get_document_type_name(&self) -> String {
|
|
166
|
+
self.document_type_name.clone()
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
#[wasm_bindgen(js_name=setId)]
|
|
170
|
+
pub fn set_id(&mut self, id: JsValue) {
|
|
171
|
+
self.id = identifier_from_js_value(&id).unwrap()
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#[wasm_bindgen(js_name=setEntropy)]
|
|
175
|
+
pub fn set_entropy(&mut self, entropy: JsValue) {
|
|
176
|
+
match entropy.is_undefined() {
|
|
177
|
+
false => {
|
|
178
|
+
let value = entropy.with_serde_to_platform_value().unwrap();
|
|
179
|
+
|
|
180
|
+
let mut entropy = [0u8; 32];
|
|
181
|
+
let bytes = value.as_bytes().unwrap();
|
|
182
|
+
let len = bytes.len().min(32);
|
|
183
|
+
entropy[..len].copy_from_slice(&bytes[..len]);
|
|
184
|
+
self.entropy = Some(entropy);
|
|
185
|
+
}
|
|
186
|
+
true => self.entropy = None,
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
#[wasm_bindgen(js_name=setOwnerId)]
|
|
191
|
+
pub fn set_owner_id(&mut self, id: JsValue) {
|
|
192
|
+
self.owner_id = identifier_from_js_value(&id).unwrap()
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#[wasm_bindgen(js_name=setProperties)]
|
|
196
|
+
pub fn set_properties(&mut self, properties: JsValue) {
|
|
197
|
+
self.properties = properties.with_serde_to_platform_value_map().unwrap()
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
#[wasm_bindgen(js_name=setRevision)]
|
|
201
|
+
pub fn set_revision(&mut self, revision: Option<u64>) {
|
|
202
|
+
self.revision = revision
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
#[wasm_bindgen(js_name=setCreatedAt)]
|
|
206
|
+
pub fn set_created_at(&mut self, created_at: Option<u64>) {
|
|
207
|
+
self.created_at = created_at
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
#[wasm_bindgen(js_name=setUpdatedAt)]
|
|
211
|
+
pub fn set_get_updated_at(&mut self, updated_at: Option<u64>) {
|
|
212
|
+
self.updated_at = updated_at
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
#[wasm_bindgen(js_name=setTransferredAt)]
|
|
216
|
+
pub fn set_transferred_at(&mut self, transferred_at: Option<u64>) {
|
|
217
|
+
self.transferred_at = transferred_at
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
#[wasm_bindgen(js_name=setCreatedAtBlockHeight)]
|
|
221
|
+
pub fn set_created_at_block_height(&mut self, created_at_block_height: Option<u64>) {
|
|
222
|
+
self.created_at_block_height = created_at_block_height
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
#[wasm_bindgen(js_name=setUpdatedAtBlockHeight)]
|
|
226
|
+
pub fn set_updated_at_block_height(&mut self, updated_at_block_height: Option<u64>) {
|
|
227
|
+
self.updated_at_block_height = updated_at_block_height
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
#[wasm_bindgen(js_name=setTransferredAtBlockHeight)]
|
|
231
|
+
pub fn set_transferred_at_block_height(&mut self, transferred_at_block_height: Option<u64>) {
|
|
232
|
+
self.transferred_at_block_height = transferred_at_block_height
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
#[wasm_bindgen(js_name=setCreatedAtCoreBlockHeight)]
|
|
236
|
+
pub fn set_created_at_core_block_height(&mut self, created_at_core_block_height: Option<u32>) {
|
|
237
|
+
self.created_at_core_block_height = created_at_core_block_height
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
#[wasm_bindgen(js_name=setUpdatedAtCoreBlockHeight)]
|
|
241
|
+
pub fn set_updated_at_core_block_height(&mut self, updated_at_core_block_height: Option<u32>) {
|
|
242
|
+
self.updated_at_core_block_height = updated_at_core_block_height
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
#[wasm_bindgen(js_name=setTransferredAtCoreBlockHeight)]
|
|
246
|
+
pub fn set_transferred_at_core_block_height(
|
|
247
|
+
&mut self,
|
|
248
|
+
transferred_at_core_block_height: Option<u32>,
|
|
249
|
+
) {
|
|
250
|
+
self.transferred_at_core_block_height = transferred_at_core_block_height
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
#[wasm_bindgen(js_name=setDocumentTypeName)]
|
|
254
|
+
pub fn set_document_type_name(&mut self, document_type_name: &str) {
|
|
255
|
+
self.document_type_name = document_type_name.to_string();
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
#[wasm_bindgen(js_name=toBytes)]
|
|
259
|
+
pub fn to_bytes(
|
|
260
|
+
&self,
|
|
261
|
+
data_contract: &DataContractWASM,
|
|
262
|
+
type_name: String,
|
|
263
|
+
js_platform_version: JsValue,
|
|
264
|
+
) -> Result<Vec<u8>, JsValue> {
|
|
265
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
266
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
267
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
let rs_document: Document = Document::from(self.clone());
|
|
271
|
+
|
|
272
|
+
let document_type_ref = data_contract
|
|
273
|
+
.get_document_type_ref_by_name(type_name)
|
|
274
|
+
.map_err(|err| JsValue::from_str(err.to_string().as_str()))?;
|
|
275
|
+
|
|
276
|
+
DocumentPlatformConversionMethodsV0::serialize(
|
|
277
|
+
&rs_document,
|
|
278
|
+
document_type_ref,
|
|
279
|
+
&platform_version.into(),
|
|
280
|
+
)
|
|
281
|
+
.with_js_error()
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
#[wasm_bindgen(js_name=fromBytes)]
|
|
285
|
+
pub fn from_bytes(
|
|
286
|
+
bytes: Vec<u8>,
|
|
287
|
+
data_contract: &DataContractWASM,
|
|
288
|
+
type_name: String,
|
|
289
|
+
js_platform_version: JsValue,
|
|
290
|
+
) -> Result<DocumentWASM, JsValue> {
|
|
291
|
+
let platform_version = match js_platform_version.is_undefined() {
|
|
292
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
293
|
+
false => PlatformVersionWASM::try_from(js_platform_version)?,
|
|
294
|
+
};
|
|
295
|
+
|
|
296
|
+
let document_type_ref = match data_contract.get_document_type_ref_by_name(type_name) {
|
|
297
|
+
Ok(type_ref) => Ok(type_ref),
|
|
298
|
+
Err(err) => Err(JsValue::from_str(err.to_string().as_str())),
|
|
299
|
+
}?;
|
|
300
|
+
|
|
301
|
+
let rs_document = Document::from_bytes(
|
|
302
|
+
bytes.as_slice(),
|
|
303
|
+
document_type_ref,
|
|
304
|
+
&platform_version.into(),
|
|
305
|
+
)
|
|
306
|
+
.with_js_error();
|
|
307
|
+
|
|
308
|
+
match rs_document {
|
|
309
|
+
Ok(doc) => Ok(DocumentWASM::from(doc)),
|
|
310
|
+
Err(err) => Err(err),
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
#[wasm_bindgen(js_name=generateId)]
|
|
315
|
+
pub fn generate_id(
|
|
316
|
+
js_document_type_name: &str,
|
|
317
|
+
js_owner_id: JsValue,
|
|
318
|
+
js_data_contract_id: JsValue,
|
|
319
|
+
opt_entropy: Option<Vec<u8>>,
|
|
320
|
+
) -> Result<Vec<u8>, JsValue> {
|
|
321
|
+
let owner_id = identifier_from_js_value(&js_owner_id)?;
|
|
322
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
323
|
+
let entropy: [u8; 32] = match opt_entropy {
|
|
324
|
+
Some(entropy_vec) => {
|
|
325
|
+
let mut entropy = [0u8; 32];
|
|
326
|
+
let bytes = entropy_vec.as_slice();
|
|
327
|
+
let len = bytes.len().min(32);
|
|
328
|
+
entropy[..len].copy_from_slice(&bytes[..len]);
|
|
329
|
+
entropy
|
|
330
|
+
}
|
|
331
|
+
None => entropy_generator::DefaultEntropyGenerator
|
|
332
|
+
.generate()
|
|
333
|
+
.with_js_error()?,
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
let identifier = pshenmic_dpp_utils::generate_document_id_v0(
|
|
337
|
+
&data_contract_id,
|
|
338
|
+
&owner_id,
|
|
339
|
+
js_document_type_name,
|
|
340
|
+
&entropy,
|
|
341
|
+
);
|
|
342
|
+
|
|
343
|
+
match identifier {
|
|
344
|
+
Ok(identifier) => Ok(identifier.to_vec()),
|
|
345
|
+
Err(err) => Err(err),
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
impl DocumentWASM {
|
|
351
|
+
pub fn rs_get_owner_id(&self) -> Identifier {
|
|
352
|
+
self.owner_id
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
pub fn rs_get_id(&self) -> Identifier {
|
|
356
|
+
self.id
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
pub fn rs_get_data_contract_id(&self) -> Identifier {
|
|
360
|
+
self.data_contract_id
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
pub fn rs_get_entropy(&self) -> Option<[u8; 32]> {
|
|
364
|
+
self.entropy
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
pub fn rs_get_properties(&self) -> BTreeMap<String, Value> {
|
|
368
|
+
self.clone().properties
|
|
369
|
+
}
|
|
370
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "pshenmic_dpp_documents_batch"
|
|
3
|
+
version.workspace = true
|
|
4
|
+
edition = "2024"
|
|
5
|
+
|
|
6
|
+
[lib]
|
|
7
|
+
crate-type = ["cdylib", "lib"]
|
|
8
|
+
|
|
9
|
+
[dependencies]
|
|
10
|
+
wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
|
|
11
|
+
pshenmic_dpp_document = {path = "../document"}
|
|
12
|
+
pshenmic_dpp_enums = {path = "../enums"}
|
|
13
|
+
pshenmic_dpp_utils = {path = "../utils"}
|
|
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
|
+
js-sys = "0.3.77"
|
|
19
|
+
serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
use dpp::prelude::IdentityNonce;
|
|
2
|
+
use dpp::state_transition::documents_batch_transition::document_base_transition::DocumentBaseTransition;
|
|
3
|
+
use dpp::state_transition::documents_batch_transition::document_base_transition::v0::DocumentBaseTransitionV0;
|
|
4
|
+
use dpp::state_transition::documents_batch_transition::document_base_transition::v0::v0_methods::DocumentBaseTransitionV0Methods;
|
|
5
|
+
use pshenmic_dpp_utils::identifier_from_js_value;
|
|
6
|
+
use wasm_bindgen::JsValue;
|
|
7
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
8
|
+
|
|
9
|
+
#[derive(Clone)]
|
|
10
|
+
#[wasm_bindgen(js_name = "DocumentBaseTransitionWASM")]
|
|
11
|
+
pub struct DocumentBaseTransitionWASM(DocumentBaseTransition);
|
|
12
|
+
|
|
13
|
+
impl From<DocumentBaseTransition> for DocumentBaseTransitionWASM {
|
|
14
|
+
fn from(v: DocumentBaseTransition) -> Self {
|
|
15
|
+
DocumentBaseTransitionWASM(v)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
impl From<DocumentBaseTransitionWASM> for DocumentBaseTransition {
|
|
20
|
+
fn from(v: DocumentBaseTransitionWASM) -> Self {
|
|
21
|
+
v.0
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
#[wasm_bindgen]
|
|
26
|
+
impl DocumentBaseTransitionWASM {
|
|
27
|
+
#[wasm_bindgen(constructor)]
|
|
28
|
+
pub fn new(
|
|
29
|
+
js_document_id: JsValue,
|
|
30
|
+
identity_contract_nonce: IdentityNonce,
|
|
31
|
+
document_type_name: String,
|
|
32
|
+
js_data_contract_id: JsValue,
|
|
33
|
+
) -> Result<DocumentBaseTransitionWASM, JsValue> {
|
|
34
|
+
let document_id = identifier_from_js_value(&js_document_id)?;
|
|
35
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
36
|
+
|
|
37
|
+
let rs_base_v0 = DocumentBaseTransitionV0 {
|
|
38
|
+
id: document_id,
|
|
39
|
+
identity_contract_nonce,
|
|
40
|
+
document_type_name,
|
|
41
|
+
data_contract_id,
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
Ok(DocumentBaseTransitionWASM(DocumentBaseTransition::from(
|
|
45
|
+
rs_base_v0,
|
|
46
|
+
)))
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#[wasm_bindgen(getter = "id")]
|
|
50
|
+
pub fn get_id(&self) -> Vec<u8> {
|
|
51
|
+
self.0.id().to_vec()
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#[wasm_bindgen(getter = "identityContractNonce")]
|
|
55
|
+
pub fn get_identity_contract_nonce(&self) -> IdentityNonce {
|
|
56
|
+
self.0.identity_contract_nonce()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#[wasm_bindgen(getter = "dataContractId")]
|
|
60
|
+
pub fn get_data_contract_id(&self) -> Vec<u8> {
|
|
61
|
+
self.0.data_contract_id().to_vec()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
#[wasm_bindgen(getter = "documentTypeName")]
|
|
65
|
+
pub fn get_document_type_name(&self) -> String {
|
|
66
|
+
self.0.document_type_name().to_string()
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
#[wasm_bindgen(setter = "id")]
|
|
70
|
+
pub fn set_id(&mut self, js_id: JsValue) -> Result<(), JsValue> {
|
|
71
|
+
let id = identifier_from_js_value(&js_id)?;
|
|
72
|
+
|
|
73
|
+
Ok(self.0.set_id(id))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[wasm_bindgen(setter = "identityContractNonce")]
|
|
77
|
+
pub fn set_identity_contract_nonce(&mut self, nonce: IdentityNonce) {
|
|
78
|
+
self.0.set_identity_contract_nonce(nonce)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[wasm_bindgen(setter = "dataContractId")]
|
|
82
|
+
pub fn set_data_contract_id(&mut self, js_data_contract_id: JsValue) -> Result<(), JsValue> {
|
|
83
|
+
let data_contract_id = identifier_from_js_value(&js_data_contract_id)?;
|
|
84
|
+
|
|
85
|
+
Ok(self.0.set_data_contract_id(data_contract_id))
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
#[wasm_bindgen(setter = "documentTypeName")]
|
|
89
|
+
pub fn set_document_type_name(&mut self, document_type_name: String) {
|
|
90
|
+
self.0.set_document_type_name(document_type_name)
|
|
91
|
+
}
|
|
92
|
+
}
|