@dashevo/wasm-dpp 0.24.0-dev.12 → 0.24.0-dev.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Cargo.toml +3 -0
- package/README.md +5 -1
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +9 -0
- package/dist/wasm/wasm_dpp.d.ts +1495 -565
- package/karma.conf.js +5 -0
- package/lib/identifier/patchIdentifier.ts +5 -4
- package/lib/index.ts +1 -1
- package/lib/test/bootstrap.js +5 -0
- package/lib/test/mocks/getBlsAdapterMock.js +36 -0
- package/lib/test/utils/newDocumentsContainer.js +36 -0
- package/package.json +7 -4
- package/src/bls_adapter.rs +16 -1
- package/src/data_contract/data_contract.rs +35 -7
- package/src/data_contract/errors/invalid_document_type.rs +1 -1
- package/src/data_contract/index.rs +56 -1
- package/src/data_contract/mod.rs +1 -0
- package/src/data_contract/state_transition/data_contract_create_transition/mod.rs +2 -4
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +3 -3
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +2 -4
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +9 -6
- package/src/data_contract_factory/data_contract_factory.rs +4 -6
- package/src/document/errors/invalid_document_error.rs +10 -9
- package/src/document/errors/invalid_initial_revision_error.rs +1 -1
- package/src/document/errors/mismatch_owners_ids_error.rs +14 -4
- package/src/document/errors/mod.rs +17 -13
- package/src/document/errors/no_documents_supplied_error.rs +4 -4
- package/src/document/factory.rs +192 -0
- package/src/document/mod.rs +222 -30
- package/src/document/state_transition/document_batch_transition/document_transition/document_create_transition.rs +47 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_delete_transition.rs +25 -1
- package/src/document/state_transition/document_batch_transition/document_transition/document_replace_transition.rs +65 -0
- package/src/document/state_transition/document_batch_transition/document_transition/mod.rs +123 -3
- package/src/document/state_transition/document_batch_transition/mod.rs +378 -0
- package/src/document/validator.rs +30 -0
- package/src/errors/consensus/basic/identity/identity_asset_lock_proof_locked_transaction_mismatch_error.rs +6 -2
- package/src/errors/consensus/basic/identity/identity_asset_lock_transaction_out_point_already_exists_error.rs +5 -2
- package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_transaction_height_error.rs +3 -3
- package/src/errors/dpp_error.rs +17 -0
- package/src/errors/from.rs +5 -0
- package/src/errors/js_conversion.rs +19 -4
- package/src/errors/mod.rs +2 -0
- package/src/errors/protocol_error.rs +7 -4
- package/src/identifier/mod.rs +48 -3
- package/src/identity/errors/asset_lock_output_not_found_error.rs +11 -0
- package/src/identity/errors/asset_lock_transaction_is_not_found_error.rs +20 -0
- package/src/identity/errors/mod.rs +7 -0
- package/src/identity/errors/unknown_asset_lock_proof_type_error.rs +26 -0
- package/src/identity/identity_facade.rs +2 -4
- package/src/identity/identity_public_key/mod.rs +41 -7
- package/src/identity/mod.rs +14 -5
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof.rs +132 -0
- package/src/identity/state_transition/asset_lock_proof/chain/chain_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/chain/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof.rs +177 -0
- package/src/identity/state_transition/asset_lock_proof/instant/instant_asset_lock_proof_structure_validator.rs +72 -0
- package/src/identity/state_transition/asset_lock_proof/instant/mod.rs +4 -0
- package/src/identity/state_transition/asset_lock_proof/mod.rs +269 -0
- package/src/identity/state_transition/identity_create_transition/apply_identity_create_transition.rs +26 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs +335 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_basic_validator.rs +153 -0
- package/src/identity/state_transition/identity_create_transition/identity_create_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_create_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_create_transition/to_object.rs +46 -0
- package/src/identity/state_transition/identity_topup_transition/apply_identity_topup_transition.rs +31 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition.rs +280 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_basic_validator.rs +113 -0
- package/src/identity/state_transition/identity_topup_transition/identity_topup_transition_state_validator.rs +37 -0
- package/src/identity/state_transition/identity_topup_transition/mod.rs +8 -0
- package/src/identity/state_transition/identity_topup_transition/to_object.rs +42 -0
- package/src/identity/state_transition/mod.rs +9 -0
- package/src/identity/state_transition/validate_public_key_signatures.rs +59 -0
- package/src/identity/validation/public_keys_validator.rs +16 -10
- package/src/identity_public_key/public_keys_validator.rs +44 -0
- package/src/lib.rs +2 -0
- package/src/lodash.rs +7 -0
- package/src/state_repository.rs +188 -36
- package/src/state_transition/mod.rs +12 -0
- package/src/utils.rs +102 -7
- package/src/validation/json_schema_validator.rs +41 -0
- package/src/validation/mod.rs +2 -0
- package/src/validation/validation_result.rs +23 -5
- package/src/version/mod.rs +2 -0
- package/src/version/protocol_version.rs +26 -0
- package/test/integration/dataContract/validation/validateDataContractFactory.spec.js +579 -502
- package/test/integration/identity/stateTransition/IdentityCreateTransition/validation/basic/validateIdentityCreateTransitionBasicFactory.spec.js +175 -165
- package/test/integration/identity/stateTransition/IdentityTopUpTransition/validation/basic/validateIdentityTopUpTransitionBasicFactory.spec.js +83 -114
- package/test/integration/identity/stateTransition/assetLockProof/chain/validateChainAssetLockProofStructureFactory.spec.js +82 -91
- package/test/integration/identity/stateTransition/assetLockProof/fetchAssetLockTransactionOutputFactory.spec.js +75 -31
- package/test/integration/identity/stateTransition/assetLockProof/instant/validateInstantAssetLockProofStructureFactory.spec.js +93 -148
- package/test/integration/identity/stateTransition/assetLockProof/validateAssetLockTransactionFactory.spec.js +63 -75
- package/test/integration/identity/stateTransition/validatePublicKeySignaturesFactory.spec.js +48 -19
- package/test/unit/dataContract/DataContract.spec.js +3 -3
- package/test/unit/dataContract/createDataContract.spec.js +0 -1
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +3 -3
- package/test/unit/decodeProtocolEntityFactory.spec.js +2 -2
- package/test/unit/document/Document.spec.js +147 -155
- package/test/unit/document/DocumentFactory.spec.js +325 -91
- package/test/unit/document/stateTransition/DocumetsBatchTransition/DocumentsBatchTransition.spec.js +142 -64
- package/test/unit/identity/Identity.spec.js +2 -2
- package/test/unit/identity/stateTransition/IdentityCreateTransition/IdentityCreateTransition.spec.js +69 -30
- package/test/unit/identity/stateTransition/IdentityCreateTransition/applyIdentityCreateTransitionFactory.spec.js +32 -32
- package/test/unit/identity/stateTransition/IdentityCreateTransition/validation/state/validateIdentityCreateTransitionStateFactory.spec.js +56 -25
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/IdentityTopUpTransition.spec.js +36 -16
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/applyIdentityTopUpTransitionFactory.spec.js +48 -46
- package/test/unit/identity/stateTransition/IdentityTopUpTransition/validation/state/validateIdentityTopUpTransitionStateFactory.spec.js +24 -6
- package/test/unit/identity/stateTransition/assetLockProof/ChainAssetLockProof.spec.js +63 -0
- package/test/unit/identity/stateTransition/assetLockProof/InstantAssetLockProof.spec.js +90 -0
- package/test/unit/identity/stateTransition/assetLockProof/createAssetLockProofInstance.spec.js +18 -3
- package/test/unit/identity/stateTransition/assetLockProof/fetchAssetLockPublicKeyHashFactory.spec.js +38 -11
- package/wasm/package.json +5 -0
- package/wasm/wasm_dpp.d.ts +1495 -565
- package/wasm/wasm_dpp.js +3654 -1206
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +557 -386
- package/webpack.config.js +9 -0
|
@@ -1,14 +1,134 @@
|
|
|
1
1
|
mod document_create_transition;
|
|
2
2
|
mod document_delete_transition;
|
|
3
|
-
mod
|
|
3
|
+
mod document_replace_transition;
|
|
4
4
|
|
|
5
5
|
pub use document_create_transition::*;
|
|
6
6
|
pub use document_delete_transition::*;
|
|
7
|
-
pub use
|
|
7
|
+
pub use document_replace_transition::*;
|
|
8
8
|
|
|
9
|
-
use dpp::
|
|
9
|
+
use dpp::{
|
|
10
|
+
document::document_transition::{DocumentTransitionExt, DocumentTransitionObjectLike},
|
|
11
|
+
prelude::{DocumentTransition, Identifier},
|
|
12
|
+
util::json_schema::JsonSchemaExt,
|
|
13
|
+
};
|
|
14
|
+
use serde::Serialize;
|
|
10
15
|
use wasm_bindgen::prelude::*;
|
|
11
16
|
|
|
17
|
+
use crate::{
|
|
18
|
+
buffer::Buffer, identifier::IdentifierWrapper, utils::WithJsError, with_js_error, BinaryType,
|
|
19
|
+
DataContractWasm,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
#[wasm_bindgen]
|
|
23
|
+
#[derive(Debug, Clone)]
|
|
24
|
+
pub struct DocumentTransitionWasm(DocumentTransition);
|
|
25
|
+
|
|
26
|
+
#[wasm_bindgen(js_class=DocumentTransitionWasm)]
|
|
27
|
+
impl DocumentTransitionWasm {
|
|
28
|
+
#[wasm_bindgen(js_name=getId)]
|
|
29
|
+
pub fn get_id(&self) -> IdentifierWrapper {
|
|
30
|
+
self.0.get_id().to_owned().into()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[wasm_bindgen(js_name=getType)]
|
|
34
|
+
pub fn get_type(&self) -> String {
|
|
35
|
+
self.0.get_document_type().to_owned()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#[wasm_bindgen(js_name=getAction)]
|
|
39
|
+
pub fn get_action(&self) -> u8 {
|
|
40
|
+
self.0.get_action().into()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
#[wasm_bindgen(js_name=getDataContract)]
|
|
44
|
+
pub fn get_data_contract(&self) -> DataContractWasm {
|
|
45
|
+
self.0.get_data_contract().to_owned().into()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#[wasm_bindgen(js_name=getDataContractId)]
|
|
49
|
+
pub fn get_data_contract_id(&self) -> IdentifierWrapper {
|
|
50
|
+
self.0.get_data_contract_id().to_owned().into()
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[wasm_bindgen(js_name=get)]
|
|
54
|
+
pub fn get(&self, path: &str) -> JsValue {
|
|
55
|
+
let binary_type = self.get_binary_type_of_path(path);
|
|
56
|
+
|
|
57
|
+
if let Some(value) = self.0.get_dynamic_property(path) {
|
|
58
|
+
match binary_type {
|
|
59
|
+
BinaryType::Identifier => {
|
|
60
|
+
if let Ok(bytes) = serde_json::from_value::<Vec<u8>>(value.to_owned()) {
|
|
61
|
+
let id: IdentifierWrapper = Identifier::from_bytes(&bytes).unwrap().into();
|
|
62
|
+
|
|
63
|
+
return id.into();
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
BinaryType::Buffer => {
|
|
67
|
+
if let Ok(bytes) = serde_json::from_value::<Vec<u8>>(value.to_owned()) {
|
|
68
|
+
return Buffer::from_bytes(&bytes).into();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
BinaryType::None => {
|
|
72
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
73
|
+
if let Ok(js_value) = value.serialize(&serializer) {
|
|
74
|
+
return js_value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
JsValue::undefined()
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#[wasm_bindgen(js_name=getObject)]
|
|
84
|
+
pub fn to_object(&self, _options: &JsValue) -> Result<JsValue, JsValue> {
|
|
85
|
+
// TODO options??
|
|
86
|
+
|
|
87
|
+
match self.0 {
|
|
88
|
+
DocumentTransition::Create(ref t) => {
|
|
89
|
+
DocumentCreateTransitionWasm::from(t.to_owned()).to_object()
|
|
90
|
+
}
|
|
91
|
+
DocumentTransition::Replace(ref t) => {
|
|
92
|
+
DocumentReplaceTransitionWasm::from(t.to_owned()).to_object()
|
|
93
|
+
}
|
|
94
|
+
DocumentTransition::Delete(ref t) => {
|
|
95
|
+
DocumentDeleteTransitionWasm::from(t.to_owned()).to_object()
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
101
|
+
pub fn to_json(&self) -> Result<JsValue, JsValue> {
|
|
102
|
+
let json_value = self.0.to_json().with_js_error()?;
|
|
103
|
+
with_js_error!(json_value.serialize(&serde_wasm_bindgen::Serializer::json_compatible()))
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
impl DocumentTransitionWasm {
|
|
108
|
+
fn get_binary_type_of_path(&self, path: impl AsRef<str>) -> BinaryType {
|
|
109
|
+
let maybe_binary_properties = self
|
|
110
|
+
.0
|
|
111
|
+
.get_data_contract()
|
|
112
|
+
.get_binary_properties(self.0.get_document_type());
|
|
113
|
+
|
|
114
|
+
if let Ok(binary_properties) = maybe_binary_properties {
|
|
115
|
+
if let Some(data) = binary_properties.get(path.as_ref()) {
|
|
116
|
+
if data.is_type_of_identifier() {
|
|
117
|
+
return BinaryType::Identifier;
|
|
118
|
+
}
|
|
119
|
+
return BinaryType::Buffer;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
BinaryType::None
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
impl From<DocumentTransition> for DocumentTransitionWasm {
|
|
127
|
+
fn from(v: DocumentTransition) -> Self {
|
|
128
|
+
DocumentTransitionWasm(v)
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
12
132
|
pub fn from_document_transition_to_js_value(document_transition: DocumentTransition) -> JsValue {
|
|
13
133
|
match document_transition {
|
|
14
134
|
DocumentTransition::Create(create_transition) => {
|
|
@@ -1 +1,379 @@
|
|
|
1
|
+
use dpp::{
|
|
2
|
+
document::{
|
|
3
|
+
state_transition::documents_batch_transition::property_names, DocumentsBatchTransition,
|
|
4
|
+
},
|
|
5
|
+
prelude::{DataContract, Document, Identifier},
|
|
6
|
+
state_transition::{
|
|
7
|
+
state_transition_execution_context::StateTransitionExecutionContext,
|
|
8
|
+
StateTransitionConvert, StateTransitionIdentitySigned, StateTransitionLike,
|
|
9
|
+
StateTransitionType,
|
|
10
|
+
},
|
|
11
|
+
util::json_value::JsonValueExt,
|
|
12
|
+
};
|
|
13
|
+
use js_sys::{Array, Reflect};
|
|
14
|
+
use serde::Serialize;
|
|
15
|
+
use wasm_bindgen::prelude::*;
|
|
16
|
+
|
|
17
|
+
use crate::{
|
|
18
|
+
bls_adapter::{BlsAdapter, JsBlsAdapter},
|
|
19
|
+
buffer::Buffer,
|
|
20
|
+
document_batch_transition::document_transition::DocumentTransitionWasm,
|
|
21
|
+
identifier::IdentifierWrapper,
|
|
22
|
+
lodash::lodash_set,
|
|
23
|
+
utils::{ToSerdeJSONExt, WithJsError},
|
|
24
|
+
DocumentWasm, IdentityPublicKeyWasm,
|
|
25
|
+
};
|
|
1
26
|
pub mod document_transition;
|
|
27
|
+
|
|
28
|
+
#[derive(Debug)]
|
|
29
|
+
#[wasm_bindgen(js_name = DocumentsBatchTransition)]
|
|
30
|
+
pub struct DocumentsBatchTransitionWASM(DocumentsBatchTransition);
|
|
31
|
+
|
|
32
|
+
/// Collections of Documents split by actions
|
|
33
|
+
#[derive(Debug, Default)]
|
|
34
|
+
#[wasm_bindgen(js_name=DocumentsContainer)]
|
|
35
|
+
pub struct DocumentsContainer {
|
|
36
|
+
create: Vec<Document>,
|
|
37
|
+
replace: Vec<Document>,
|
|
38
|
+
delete: Vec<Document>,
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#[wasm_bindgen(js_class=DocumentsContainer)]
|
|
42
|
+
impl DocumentsContainer {
|
|
43
|
+
#[wasm_bindgen(constructor)]
|
|
44
|
+
pub fn new() -> Self {
|
|
45
|
+
Default::default()
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
#[wasm_bindgen(js_name=pushDocumentCreate)]
|
|
49
|
+
pub fn push_document_create(&mut self, d: DocumentWasm) {
|
|
50
|
+
self.create.push(d.0);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[wasm_bindgen(js_name=pushDocumentReplace)]
|
|
54
|
+
pub fn push_document_replace(&mut self, d: DocumentWasm) {
|
|
55
|
+
self.replace.push(d.0);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#[wasm_bindgen(js_name=pushDocumentDelete)]
|
|
59
|
+
pub fn push_document_delete(&mut self, d: DocumentWasm) {
|
|
60
|
+
self.delete.push(d.0);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
impl DocumentsContainer {
|
|
65
|
+
pub fn take_documents_create(&mut self) -> Vec<Document> {
|
|
66
|
+
std::mem::take(&mut self.create)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
pub fn take_documents_replace(&mut self) -> Vec<Document> {
|
|
70
|
+
std::mem::take(&mut self.replace)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
pub fn take_documents_delete(&mut self) -> Vec<Document> {
|
|
74
|
+
std::mem::take(&mut self.delete)
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#[wasm_bindgen(js_class=DocumentsBatchTransition)]
|
|
79
|
+
impl DocumentsBatchTransitionWASM {
|
|
80
|
+
#[wasm_bindgen(constructor)]
|
|
81
|
+
pub fn from_raw_object(
|
|
82
|
+
js_raw_transition: JsValue,
|
|
83
|
+
data_contracts: Array,
|
|
84
|
+
) -> Result<DocumentsBatchTransitionWASM, JsValue> {
|
|
85
|
+
let data_contracts_array_js = Array::from(&data_contracts);
|
|
86
|
+
|
|
87
|
+
let mut data_contracts: Vec<DataContract> = vec![];
|
|
88
|
+
for contract in data_contracts_array_js.iter() {
|
|
89
|
+
let json_value = contract.with_serde_to_json_value()?;
|
|
90
|
+
let data_contract = DataContract::from_json_object(json_value).with_js_error()?;
|
|
91
|
+
data_contracts.push(data_contract);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
let documents_batch_transition = DocumentsBatchTransition::from_json_object(
|
|
95
|
+
js_raw_transition.with_serde_to_json_value()?,
|
|
96
|
+
data_contracts,
|
|
97
|
+
)
|
|
98
|
+
.with_js_error()?;
|
|
99
|
+
|
|
100
|
+
Ok(documents_batch_transition.into())
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
#[wasm_bindgen(js_name=getType)]
|
|
104
|
+
pub fn get_type(&self) -> u8 {
|
|
105
|
+
StateTransitionType::DocumentsBatch.into()
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#[wasm_bindgen(js_name=getOwnerId)]
|
|
109
|
+
pub fn get_owner_id(&self) -> IdentifierWrapper {
|
|
110
|
+
self.0.get_owner_id().to_owned().into()
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#[wasm_bindgen(js_name=getTransitions)]
|
|
114
|
+
pub fn get_transitions(&self) -> js_sys::Array {
|
|
115
|
+
let array = js_sys::Array::new();
|
|
116
|
+
let transitions = self.0.get_transitions();
|
|
117
|
+
|
|
118
|
+
for tr in transitions.iter().cloned() {
|
|
119
|
+
let transition: DocumentTransitionWasm = tr.into();
|
|
120
|
+
array.push(&transition.into());
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
array
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
127
|
+
pub fn to_json(&self) -> Result<JsValue, JsValue> {
|
|
128
|
+
let value = self.0.to_json(false).with_js_error()?;
|
|
129
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
130
|
+
|
|
131
|
+
let is_null_signature = value.get(property_names::SIGNATURE).is_none();
|
|
132
|
+
let is_null_signature_public_key_id =
|
|
133
|
+
value.get(property_names::SIGNATURE_PUBLIC_KEY_ID).is_none();
|
|
134
|
+
|
|
135
|
+
let js_value = value.serialize(&serializer)?;
|
|
136
|
+
|
|
137
|
+
if is_null_signature {
|
|
138
|
+
js_sys::Reflect::set(
|
|
139
|
+
&js_value,
|
|
140
|
+
&property_names::SIGNATURE.into(),
|
|
141
|
+
&JsValue::undefined(),
|
|
142
|
+
)?;
|
|
143
|
+
}
|
|
144
|
+
if is_null_signature_public_key_id {
|
|
145
|
+
js_sys::Reflect::set(
|
|
146
|
+
&js_value,
|
|
147
|
+
&property_names::SIGNATURE_PUBLIC_KEY_ID.into(),
|
|
148
|
+
&JsValue::undefined(),
|
|
149
|
+
)?;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
Ok(js_value)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#[wasm_bindgen(js_name=toObject)]
|
|
156
|
+
pub fn to_object(&self, options: &JsValue) -> Result<JsValue, JsValue> {
|
|
157
|
+
let skip_signature = if options.is_object() {
|
|
158
|
+
let options = options.with_serde_to_json_value()?;
|
|
159
|
+
options.get_bool("skipSignature").unwrap_or_default()
|
|
160
|
+
} else {
|
|
161
|
+
false
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
let mut value = self.0.to_object(skip_signature).with_js_error()?;
|
|
165
|
+
let serializer = serde_wasm_bindgen::Serializer::json_compatible();
|
|
166
|
+
let js_value = value.serialize(&serializer)?;
|
|
167
|
+
|
|
168
|
+
// Transform every transition individually
|
|
169
|
+
let transitions = Array::new();
|
|
170
|
+
for transition in self.0.transitions.iter() {
|
|
171
|
+
let js_value =
|
|
172
|
+
DocumentTransitionWasm::from(transition.to_owned()).to_object(options)?;
|
|
173
|
+
transitions.push(&js_value);
|
|
174
|
+
}
|
|
175
|
+
// Replace the whole collection of transitions
|
|
176
|
+
Reflect::set(
|
|
177
|
+
&js_value,
|
|
178
|
+
&property_names::TRANSITIONS.into(),
|
|
179
|
+
&transitions.into(),
|
|
180
|
+
)?;
|
|
181
|
+
|
|
182
|
+
// Transform paths that are specific to the DocumentsBatchTransition
|
|
183
|
+
for path in DocumentsBatchTransition::binary_property_paths() {
|
|
184
|
+
if let Ok(bytes) = value.remove_path_into::<Vec<u8>>(path) {
|
|
185
|
+
let buffer = Buffer::from_bytes(&bytes);
|
|
186
|
+
lodash_set(&js_value, path, buffer.into());
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for path in DocumentsBatchTransition::identifiers_property_paths() {
|
|
190
|
+
if let Ok(bytes) = value.remove_path_into::<Vec<u8>>(path) {
|
|
191
|
+
let id = IdentifierWrapper::new(bytes)?;
|
|
192
|
+
lodash_set(&js_value, path, id.into());
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
if value.get(property_names::SIGNATURE).is_none() && !skip_signature {
|
|
197
|
+
js_sys::Reflect::set(
|
|
198
|
+
&js_value,
|
|
199
|
+
&property_names::SIGNATURE.into(),
|
|
200
|
+
&JsValue::undefined(),
|
|
201
|
+
)?;
|
|
202
|
+
}
|
|
203
|
+
if value.get(property_names::SIGNATURE_PUBLIC_KEY_ID).is_none() {
|
|
204
|
+
js_sys::Reflect::set(
|
|
205
|
+
&js_value,
|
|
206
|
+
&property_names::SIGNATURE_PUBLIC_KEY_ID.into(),
|
|
207
|
+
&JsValue::undefined(),
|
|
208
|
+
)?;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
Ok(js_value)
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
#[wasm_bindgen(js_name=getModifiedDataIds)]
|
|
215
|
+
pub fn get_modified_ids(&self) -> Array {
|
|
216
|
+
let array = Array::new();
|
|
217
|
+
|
|
218
|
+
for id in self.0.get_modified_data_ids() {
|
|
219
|
+
let id = <IdentifierWrapper as From<Identifier>>::from(id.to_owned());
|
|
220
|
+
array.push(&id.into());
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
array
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// AbstractSTateTransitionIdentitySigned methods
|
|
227
|
+
#[wasm_bindgen(js_name=getSignaturePublicKeyId)]
|
|
228
|
+
pub fn get_signature_public_key_id(&self) -> Option<f64> {
|
|
229
|
+
self.0.get_signature_public_key_id().map(|v| v as f64)
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
#[wasm_bindgen(js_name=sign)]
|
|
233
|
+
pub fn sign(
|
|
234
|
+
&mut self,
|
|
235
|
+
identity_public_key: &IdentityPublicKeyWasm,
|
|
236
|
+
private_key: &[u8],
|
|
237
|
+
bls: JsBlsAdapter,
|
|
238
|
+
) -> Result<(), JsValue> {
|
|
239
|
+
self.0
|
|
240
|
+
.sign(identity_public_key.inner(), private_key, &BlsAdapter(bls))
|
|
241
|
+
.with_js_error()
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
#[wasm_bindgen(js_name=verifyPublicKeyLevelAndPurpose)]
|
|
245
|
+
pub fn verify_public_key_level_and_purpose(
|
|
246
|
+
&self,
|
|
247
|
+
public_key: &IdentityPublicKeyWasm,
|
|
248
|
+
) -> Result<(), JsValue> {
|
|
249
|
+
self.0
|
|
250
|
+
.verify_public_key_level_and_purpose(public_key.inner())
|
|
251
|
+
.with_js_error()
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
#[wasm_bindgen(js_name=verifyPublicKeyIsEnabled)]
|
|
255
|
+
pub fn verify_public_key_is_enabled(
|
|
256
|
+
&self,
|
|
257
|
+
public_key: &IdentityPublicKeyWasm,
|
|
258
|
+
) -> Result<(), JsValue> {
|
|
259
|
+
self.0
|
|
260
|
+
.verify_public_key_is_enabled(public_key.inner())
|
|
261
|
+
.with_js_error()
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
#[wasm_bindgen(js_name=verifySignature)]
|
|
265
|
+
pub fn verify_signature(
|
|
266
|
+
&self,
|
|
267
|
+
public_key: &IdentityPublicKeyWasm,
|
|
268
|
+
bls: JsBlsAdapter,
|
|
269
|
+
) -> Result<(), JsValue> {
|
|
270
|
+
self.0
|
|
271
|
+
.verify_signature(public_key.inner(), &BlsAdapter(bls))
|
|
272
|
+
.with_js_error()
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
#[wasm_bindgen(js_name=setSignaturePublicKey)]
|
|
276
|
+
pub fn set_signature_public_key(&mut self, key_id: u64) {
|
|
277
|
+
self.0.set_signature_public_key_id(key_id)
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
#[wasm_bindgen(js_name=getSecurityLevelRequirement)]
|
|
281
|
+
pub fn get_security_level_requirement(&self) -> u8 {
|
|
282
|
+
self.0.get_security_level_requirement().into()
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// AbstractStateTransition methods
|
|
286
|
+
#[wasm_bindgen(js_name=getProtocolVersion)]
|
|
287
|
+
pub fn get_protocol_version(&self) -> u32 {
|
|
288
|
+
self.0.get_protocol_version()
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
#[wasm_bindgen(js_name=getSignature)]
|
|
292
|
+
pub fn get_signature(&self) -> Vec<u8> {
|
|
293
|
+
self.0.get_signature().to_owned()
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
#[wasm_bindgen(js_name=setSignature)]
|
|
297
|
+
pub fn set_signature(&mut self, signature: Vec<u8>) {
|
|
298
|
+
self.0.set_signature(signature)
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
#[wasm_bindgen(js_name=calculateFee)]
|
|
302
|
+
pub fn calculate_fee(&self) -> i64 {
|
|
303
|
+
self.0.calculate_fee()
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
#[wasm_bindgen(js_name=isDocumentStateTransition)]
|
|
307
|
+
pub fn is_document_state_transition(&self) -> bool {
|
|
308
|
+
self.0.is_document_state_transition()
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
#[wasm_bindgen(js_name=isDataContractStateTransition)]
|
|
312
|
+
pub fn is_data_contract_state_transition(&self) -> bool {
|
|
313
|
+
self.0.is_data_contract_state_transition()
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
#[wasm_bindgen(js_name=isIdentityStateTransition)]
|
|
317
|
+
pub fn is_identity_state_transition(&self) -> bool {
|
|
318
|
+
self.0.is_identity_state_transition()
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
#[wasm_bindgen(js_name=setExecutionContext)]
|
|
322
|
+
pub fn set_execution_context(&mut self, context: StateExecutionContext) {
|
|
323
|
+
self.0.set_execution_context(context.into_inner());
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
#[wasm_bindgen(js_name=getExecutionContext)]
|
|
327
|
+
pub fn get_execution_context(&mut self) -> StateExecutionContext {
|
|
328
|
+
StateExecutionContext(self.0.get_execution_context().to_owned())
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
#[wasm_bindgen(js_name=toBuffer)]
|
|
332
|
+
pub fn to_buffer(&self, options: &JsValue) -> Result<Buffer, JsValue> {
|
|
333
|
+
let skip_signature = if options.is_object() {
|
|
334
|
+
let options = options.with_serde_to_json_value()?;
|
|
335
|
+
options.get_bool("skipSignature").unwrap_or_default()
|
|
336
|
+
} else {
|
|
337
|
+
false
|
|
338
|
+
};
|
|
339
|
+
let bytes = self.0.to_buffer(skip_signature).with_js_error()?;
|
|
340
|
+
|
|
341
|
+
Ok(Buffer::from_bytes(&bytes))
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
#[wasm_bindgen(js_name=hash)]
|
|
345
|
+
pub fn hash(&self, options: JsValue) -> Result<Buffer, JsValue> {
|
|
346
|
+
let skip_signature = if options.is_object() {
|
|
347
|
+
let options = options.with_serde_to_json_value()?;
|
|
348
|
+
options.get_bool("skipSignature").unwrap_or_default()
|
|
349
|
+
} else {
|
|
350
|
+
false
|
|
351
|
+
};
|
|
352
|
+
let bytes = self.0.hash(skip_signature).with_js_error()?;
|
|
353
|
+
|
|
354
|
+
Ok(Buffer::from_bytes(&bytes))
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
#[wasm_bindgen(js_name=StateExecutionContext)]
|
|
359
|
+
pub struct StateExecutionContext(StateTransitionExecutionContext);
|
|
360
|
+
|
|
361
|
+
impl StateExecutionContext {
|
|
362
|
+
pub fn into_inner(self) -> StateTransitionExecutionContext {
|
|
363
|
+
self.0
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
pub fn inner(&self) -> &StateTransitionExecutionContext {
|
|
367
|
+
&self.0
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
pub fn inner_mut(&mut self) -> &mut StateTransitionExecutionContext {
|
|
371
|
+
&mut self.0
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
impl From<DocumentsBatchTransition> for DocumentsBatchTransitionWASM {
|
|
376
|
+
fn from(t: DocumentsBatchTransition) -> Self {
|
|
377
|
+
DocumentsBatchTransitionWASM(t)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
use std::sync::Arc;
|
|
2
|
+
|
|
3
|
+
use dpp::document::document_validator::DocumentValidator;
|
|
4
|
+
|
|
5
|
+
use wasm_bindgen::prelude::*;
|
|
6
|
+
|
|
7
|
+
use crate::version::ProtocolVersionValidatorWasm;
|
|
8
|
+
|
|
9
|
+
#[wasm_bindgen(js_name = DocumentValidator)]
|
|
10
|
+
pub struct DocumentValidatorWasm(DocumentValidator);
|
|
11
|
+
|
|
12
|
+
#[wasm_bindgen(js_class=DocumentValidator)]
|
|
13
|
+
impl DocumentValidatorWasm {
|
|
14
|
+
#[wasm_bindgen(constructor)]
|
|
15
|
+
pub fn new(protocol_validator: ProtocolVersionValidatorWasm) -> DocumentValidatorWasm {
|
|
16
|
+
DocumentValidatorWasm(DocumentValidator::new(Arc::new(protocol_validator.into())))
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
impl From<DocumentValidator> for DocumentValidatorWasm {
|
|
21
|
+
fn from(doc_validator: DocumentValidator) -> Self {
|
|
22
|
+
DocumentValidatorWasm(doc_validator)
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
impl From<DocumentValidatorWasm> for DocumentValidator {
|
|
27
|
+
fn from(val: DocumentValidatorWasm) -> Self {
|
|
28
|
+
val.0
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
use dpp::consensus::basic::identity::IdentityAssetLockProofLockedTransactionMismatchError;
|
|
2
2
|
use dpp::consensus::ConsensusError;
|
|
3
|
+
use dpp::dashcore::hashes::Hash;
|
|
3
4
|
use wasm_bindgen::prelude::*;
|
|
4
5
|
|
|
5
6
|
use crate::buffer::Buffer;
|
|
@@ -22,13 +23,16 @@ impl IdentityAssetLockProofLockedTransactionMismatchErrorWasm {
|
|
|
22
23
|
#[wasm_bindgen(js_name=getInstantLockTransactionId)]
|
|
23
24
|
pub fn instant_lock_transaction_id(&self) -> Buffer {
|
|
24
25
|
let tx_id = self.inner.instant_lock_transaction_id();
|
|
25
|
-
Buffer::from_bytes(tx_id
|
|
26
|
+
Buffer::from_bytes(&tx_id)
|
|
26
27
|
}
|
|
27
28
|
|
|
28
29
|
#[wasm_bindgen(js_name=getAssetLockTransactionId)]
|
|
29
30
|
pub fn asset_lock_transaction_id(&self) -> Buffer {
|
|
30
31
|
let tx_id = self.inner.asset_lock_transaction_id();
|
|
31
|
-
|
|
32
|
+
let mut hash_bytes = tx_id.as_hash().into_inner();
|
|
33
|
+
hash_bytes.reverse();
|
|
34
|
+
|
|
35
|
+
Buffer::from_bytes(&hash_bytes)
|
|
32
36
|
}
|
|
33
37
|
|
|
34
38
|
#[wasm_bindgen(js_name=getCode)]
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
use dpp::consensus::basic::identity::IdentityAssetLockTransactionOutPointAlreadyExistsError;
|
|
2
2
|
use dpp::consensus::ConsensusError;
|
|
3
|
+
use dpp::dashcore::hashes::Hash;
|
|
3
4
|
use wasm_bindgen::prelude::*;
|
|
4
5
|
|
|
5
6
|
use crate::buffer::Buffer;
|
|
@@ -19,7 +20,7 @@ impl From<&IdentityAssetLockTransactionOutPointAlreadyExistsError>
|
|
|
19
20
|
|
|
20
21
|
#[wasm_bindgen(js_class=IdentityAssetLockTransactionOutPointAlreadyExistsError)]
|
|
21
22
|
impl IdentityAssetLockTransactionOutPointAlreadyExistsErrorWasm {
|
|
22
|
-
#[wasm_bindgen(js_name=
|
|
23
|
+
#[wasm_bindgen(js_name=getOutputIndex)]
|
|
23
24
|
pub fn output_index(&self) -> usize {
|
|
24
25
|
self.inner.output_index()
|
|
25
26
|
}
|
|
@@ -27,7 +28,9 @@ impl IdentityAssetLockTransactionOutPointAlreadyExistsErrorWasm {
|
|
|
27
28
|
#[wasm_bindgen(js_name=getTransactionId)]
|
|
28
29
|
pub fn transaction_id(&self) -> Buffer {
|
|
29
30
|
let tx_id = self.inner.transaction_id();
|
|
30
|
-
|
|
31
|
+
let mut tx_id_bytes = tx_id.as_hash().into_inner();
|
|
32
|
+
tx_id_bytes.reverse();
|
|
33
|
+
Buffer::from_bytes(&tx_id_bytes)
|
|
31
34
|
}
|
|
32
35
|
|
|
33
36
|
#[wasm_bindgen(js_name=getCode)]
|
package/src/errors/consensus/basic/identity/invalid_asset_lock_proof_transaction_height_error.rs
CHANGED
|
@@ -22,9 +22,9 @@ impl InvalidAssetLockProofTransactionHeightErrorWasm {
|
|
|
22
22
|
self.inner.proof_core_chain_locked_height()
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
#[wasm_bindgen(js_name=
|
|
26
|
-
pub fn
|
|
27
|
-
self.inner.
|
|
25
|
+
#[wasm_bindgen(js_name=getTransactionHeight)]
|
|
26
|
+
pub fn transaction_height(&self) -> Option<u32> {
|
|
27
|
+
self.inner.transaction_height()
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
#[wasm_bindgen(js_name=getCode)]
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
use crate::identity::errors::{
|
|
2
|
+
AssetLockOutputNotFoundErrorWasm, AssetLockTransactionIsNotFoundErrorWasm,
|
|
3
|
+
};
|
|
4
|
+
use dpp::DPPError;
|
|
5
|
+
use wasm_bindgen::JsValue;
|
|
6
|
+
|
|
7
|
+
pub fn from_dpp_error_ref(e: &DPPError) -> JsValue {
|
|
8
|
+
match e {
|
|
9
|
+
DPPError::AssetLockOutputNotFoundError(e) => {
|
|
10
|
+
AssetLockOutputNotFoundErrorWasm::from(e).into()
|
|
11
|
+
}
|
|
12
|
+
DPPError::AssetLockTransactionIsNotFoundError(e) => {
|
|
13
|
+
AssetLockTransactionIsNotFoundErrorWasm::from(e).into()
|
|
14
|
+
}
|
|
15
|
+
_ => unimplemented!(),
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/errors/from.rs
CHANGED
|
@@ -5,8 +5,13 @@ use dpp::errors::ProtocolError;
|
|
|
5
5
|
use crate::data_contract::errors::from_data_contract_to_js_error;
|
|
6
6
|
use crate::document::errors::from_document_to_js_error;
|
|
7
7
|
|
|
8
|
+
use super::consensus_error::from_consensus_error;
|
|
9
|
+
|
|
8
10
|
pub fn from_dpp_err(pe: ProtocolError) -> JsValue {
|
|
9
11
|
match pe {
|
|
12
|
+
ProtocolError::AbstractConsensusError(consensus_error) => {
|
|
13
|
+
from_consensus_error(*consensus_error)
|
|
14
|
+
}
|
|
10
15
|
ProtocolError::DataContractError(e) => from_data_contract_to_js_error(e),
|
|
11
16
|
|
|
12
17
|
ProtocolError::Document(e) => from_document_to_js_error(*e),
|
|
@@ -41,23 +41,38 @@ impl From<serde_wasm_bindgen::Error> for RustConversionError {
|
|
|
41
41
|
#[macro_export]
|
|
42
42
|
macro_rules! with_js_error {
|
|
43
43
|
($o:expr) => {
|
|
44
|
-
$o.map_err(|e| RustConversionError::from(e).to_js_value())
|
|
44
|
+
$o.map_err(|e| $crate::errors::RustConversionError::from(e).to_js_value())
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
#[macro_export]
|
|
49
49
|
macro_rules! bail_js {
|
|
50
50
|
($msg:literal) => ({
|
|
51
|
-
return Err(RustConversionError::from(String::from($msg)).to_js_value())
|
|
51
|
+
return Err($crate::errors::RustConversionError::from(String::from($msg)).to_js_value())
|
|
52
52
|
});
|
|
53
53
|
|
|
54
54
|
($err:expr $(,)?) => ({
|
|
55
55
|
use $crate::private::kind::*;
|
|
56
|
-
return Err(RustConversionError::from($err).to_js_value())
|
|
56
|
+
return Err($crate::errors::RustConversionError::from($err).to_js_value())
|
|
57
57
|
});
|
|
58
58
|
|
|
59
59
|
($fmt:expr, $($arg:tt)*) => {
|
|
60
|
-
return Err(RustConversionError::from(format!($fmt, $($arg)*)).to_js_value())
|
|
60
|
+
return Err($crate::errors::RustConversionError::from(format!($fmt, $($arg)*)).to_js_value())
|
|
61
61
|
};
|
|
62
62
|
|
|
63
63
|
}
|
|
64
|
+
|
|
65
|
+
#[macro_export]
|
|
66
|
+
macro_rules! console_log {
|
|
67
|
+
($msg:literal) => {{
|
|
68
|
+
web_sys::console::log_1(&format!($msg).into())
|
|
69
|
+
}};
|
|
70
|
+
|
|
71
|
+
($msg:expr $(,)?) => {{
|
|
72
|
+
web_sys::console::log_1(&format!("{}", $msg).into())
|
|
73
|
+
}};
|
|
74
|
+
|
|
75
|
+
($fmt:expr, $($arg:tt)*) => {
|
|
76
|
+
web_sys::console::log_1(&format!($fmt, $($arg)*).into())
|
|
77
|
+
};
|
|
78
|
+
}
|