@dashevo/wasm-dpp 0.24.0-dev.11 → 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/lib/dpp.d.ts +9 -0
- package/dist/lib/errors/AbstractConsensusError.d.ts +10 -0
- package/dist/lib/errors/DPPError.d.ts +5 -0
- package/dist/lib/errors/patchConsensusErrors.d.ts +1 -0
- package/dist/lib/{patchIdentifier.d.ts → identifier/patchIdentifier.d.ts} +1 -1
- package/dist/{index.d.ts → lib/index.d.ts} +1 -1
- package/dist/lib/utils/extend.d.ts +1 -0
- package/dist/wasm/wasm_dpp.d.ts +1595 -518
- package/karma.conf.js +5 -0
- package/lib/dpp.ts +24 -0
- package/lib/errors/AbstractConsensusError.ts +13 -0
- package/lib/errors/DPPError.ts +15 -0
- package/lib/errors/patchConsensusErrors.ts +175 -0
- package/lib/{patchIdentifier.ts → identifier/patchIdentifier.ts} +6 -5
- package/{index.ts → lib/index.ts} +5 -4
- package/lib/test/bootstrap.js +5 -0
- package/lib/test/expect/expectError.js +4 -2
- package/lib/test/mocks/getBlsAdapterMock.js +36 -0
- package/lib/test/utils/newDocumentsContainer.js +36 -0
- package/lib/utils/extend.ts +6 -0
- package/package.json +9 -6
- package/src/bls_adapter.rs +16 -1
- package/src/data_contract/data_contract.rs +35 -7
- package/src/data_contract/errors/invalid_data_contract.rs +21 -0
- 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 +6 -8
- package/src/data_contract/state_transition/data_contract_create_transition/validation.rs +4 -4
- package/src/data_contract/state_transition/data_contract_update_transition/apply.rs +44 -0
- package/src/data_contract/state_transition/data_contract_update_transition/mod.rs +145 -0
- package/src/data_contract/state_transition/data_contract_update_transition/validation.rs +49 -0
- package/src/data_contract/state_transition/mod.rs +2 -0
- package/src/data_contract_factory/data_contract_factory.rs +25 -12
- 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/data_contract/data_contract_max_depth_exceed_error.rs +5 -5
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_ids_error.rs +4 -4
- package/src/errors/consensus/basic/document/duplicate_document_transitions_with_indices_error.rs +36 -0
- package/src/errors/consensus/basic/document/missing_document_transition_type_error.rs +20 -0
- package/src/errors/consensus/basic/document/mod.rs +4 -0
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_error.rs +2 -2
- package/src/errors/consensus/basic/identity/duplicated_identity_public_key_id_error.rs +2 -2
- 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/consensus/basic/identity/invalid_identity_public_key_security_level_error.rs +2 -2
- package/src/errors/consensus/basic/json_schema_error.rs +1 -1
- package/src/errors/consensus_error.rs +15 -8
- package/src/errors/dpp_error.rs +17 -0
- package/src/errors/from.rs +6 -1
- package/src/errors/js_conversion.rs +19 -4
- package/src/errors/mod.rs +3 -0
- package/src/errors/protocol_error.rs +15 -0
- package/src/{identifier.rs → 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_facade.rs → identity/identity_facade.rs} +3 -5
- package/src/{identity_public_key → identity/identity_public_key}/key_type.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/mod.rs +41 -10
- package/src/{identity_public_key → identity/identity_public_key}/purpose.rs +0 -0
- package/src/{identity_public_key → identity/identity_public_key}/security_level.rs +0 -0
- package/src/{identity.rs → identity/mod.rs} +20 -12
- 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/mod.rs +3 -0
- package/src/identity/validation/public_keys_validator.rs +76 -0
- package/src/identity_public_key/public_keys_validator.rs +1 -1
- package/src/lib.rs +3 -6
- 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 +5 -0
- package/src/{validation_result.rs → 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/IdentityUpdateTransition/validation/state/validateIdentityUpdateTransitionStateFactory.spec.js +1 -1
- 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/integration/identity/validation/validatePublicKeysFactory.spec.js +79 -114
- package/test/integration/stateTransition/AbstractStateTransitionIdentitySigned.spec.js +0 -11
- package/test/integration/stateTransition/StateTransitionFacade.spec.js +1 -1
- package/test/integration/stateTransition/calculateStateTransitionFeeFactory.spec.js +135 -0
- package/test/unit/dataContract/DataContract.spec.js +5 -9
- package/test/unit/dataContract/DataContractFactory.spec.js +13 -6
- package/test/unit/dataContract/createDataContract.spec.js +0 -1
- package/test/unit/dataContract/errors/InvalidDataContractError.spec.js +11 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/DataContractCreateTransition.spec.js +3 -3
- package/test/unit/dataContract/stateTransition/DataContractCreateTransition/validation/state/validateDataContractCreateTransitionStateFactory.spec.js +20 -16
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/DataContractUpdateTransition.spec.js +24 -60
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/applyDataContractUpdateTransitionFactory.spec.js +27 -23
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/basic/validateIndicesAreBackwardCompatible.spec.js +29 -12
- package/test/unit/dataContract/stateTransition/DataContractUpdateTransition/validation/state/validateDataContractUpdateTransitionStateFactory.spec.js +66 -49
- package/test/unit/dataContract/validation/validateDataContractPatterns.spec.js +73 -0
- 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/document/stateTransition/DocumetsBatchTransition/applyDocumentsBatchTransitionFactory.spec.js +1 -1
- package/test/unit/document/stateTransition/DocumetsBatchTransition/validation/state/validateDocumentsBatchTransitionStateFactory.spec.js +1 -1
- package/test/unit/identity/Identity.spec.js +2 -2
- package/test/unit/identity/IdentityPublicKey.spec.js +25 -31
- 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/tsconfig.json +1 -1
- package/wasm/package.json +5 -0
- package/wasm/wasm_dpp.d.ts +1595 -518
- package/wasm/wasm_dpp.js +5007 -2172
- package/wasm/wasm_dpp_bg.js +1 -1
- package/wasm/wasm_dpp_bg.wasm +0 -0
- package/wasm/wasm_dpp_bg.wasm.d.ts +566 -365
- package/webpack.config.js +10 -1
- package/test/integration/stateTransition/calculateStateTransitionFee.spec.js +0 -32
- package/test/unit/dataContract/validation/validateDataContractMaxDepthFactory.spec.js +0 -93
- package/test/unit/dataContract/validation/validateDataContractPatternsFactory.spec.js +0 -64
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
use serde::{Deserialize, Serialize};
|
|
2
|
+
use std::convert::TryInto;
|
|
3
|
+
use wasm_bindgen::prelude::*;
|
|
4
|
+
|
|
5
|
+
use crate::{
|
|
6
|
+
buffer::Buffer,
|
|
7
|
+
errors::{from_dpp_err, RustConversionError},
|
|
8
|
+
identifier::IdentifierWrapper,
|
|
9
|
+
with_js_error,
|
|
10
|
+
};
|
|
11
|
+
use dpp::identity::state_transition::asset_lock_proof::chain::ChainAssetLockProof;
|
|
12
|
+
use dpp::util::string_encoding;
|
|
13
|
+
use dpp::util::string_encoding::Encoding;
|
|
14
|
+
|
|
15
|
+
#[wasm_bindgen(js_name=ChainAssetLockProof)]
|
|
16
|
+
#[derive(Clone)]
|
|
17
|
+
pub struct ChainAssetLockProofWasm(ChainAssetLockProof);
|
|
18
|
+
|
|
19
|
+
#[derive(Debug, Serialize, Deserialize)]
|
|
20
|
+
#[serde(rename_all = "camelCase")]
|
|
21
|
+
struct ChainAssetLockProofParams {
|
|
22
|
+
#[serde(rename = "type")]
|
|
23
|
+
lock_type: u8,
|
|
24
|
+
core_chain_locked_height: u32,
|
|
25
|
+
out_point: Vec<u8>,
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
impl From<ChainAssetLockProof> for ChainAssetLockProofWasm {
|
|
29
|
+
fn from(v: ChainAssetLockProof) -> Self {
|
|
30
|
+
ChainAssetLockProofWasm(v)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
impl From<ChainAssetLockProofWasm> for ChainAssetLockProof {
|
|
35
|
+
fn from(v: ChainAssetLockProofWasm) -> Self {
|
|
36
|
+
v.0
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
#[wasm_bindgen(js_class = ChainAssetLockProof)]
|
|
41
|
+
impl ChainAssetLockProofWasm {
|
|
42
|
+
#[wasm_bindgen(constructor)]
|
|
43
|
+
pub fn new(raw_parameters: JsValue) -> Result<ChainAssetLockProofWasm, JsValue> {
|
|
44
|
+
let parameters: ChainAssetLockProofParams =
|
|
45
|
+
with_js_error!(serde_wasm_bindgen::from_value(raw_parameters))?;
|
|
46
|
+
|
|
47
|
+
let out_point: [u8; 36] = parameters.out_point.try_into().map_err(|_| {
|
|
48
|
+
RustConversionError::Error(String::from("outPoint must be a 36 byte array"))
|
|
49
|
+
.to_js_value()
|
|
50
|
+
})?;
|
|
51
|
+
|
|
52
|
+
let chain_asset_lock_proof =
|
|
53
|
+
ChainAssetLockProof::new(parameters.core_chain_locked_height, out_point);
|
|
54
|
+
|
|
55
|
+
Ok(ChainAssetLockProofWasm(chain_asset_lock_proof))
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
#[wasm_bindgen(js_name=getType)]
|
|
59
|
+
pub fn get_type(&self) -> u8 {
|
|
60
|
+
ChainAssetLockProof::asset_lock_type()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#[wasm_bindgen(js_name=getCoreChainLockedHeight)]
|
|
64
|
+
pub fn get_core_chain_locked_height(&self) -> u32 {
|
|
65
|
+
self.0.core_chain_locked_height()
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#[wasm_bindgen(js_name=setCoreChainLockedHeight)]
|
|
69
|
+
pub fn set_core_chain_locked_height(&mut self, value: u32) {
|
|
70
|
+
self.0.set_core_chain_locked_height(value);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#[wasm_bindgen(js_name=getOutPoint)]
|
|
74
|
+
pub fn get_out_point(&self) -> Buffer {
|
|
75
|
+
Buffer::from_bytes(self.0.out_point())
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#[wasm_bindgen(js_name=setOutPoint)]
|
|
79
|
+
pub fn set_out_point(&mut self, out_point: Vec<u8>) -> Result<(), JsValue> {
|
|
80
|
+
let out_point: [u8; 36] = out_point.try_into().map_err(|_| {
|
|
81
|
+
RustConversionError::Error(String::from("outPoint must be a 36 byte array"))
|
|
82
|
+
.to_js_value()
|
|
83
|
+
})?;
|
|
84
|
+
self.0.set_out_point(out_point);
|
|
85
|
+
|
|
86
|
+
Ok(())
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
90
|
+
pub fn to_json(&self) -> Result<JsValue, JsValue> {
|
|
91
|
+
let js_object = self.to_object()?;
|
|
92
|
+
|
|
93
|
+
let out_point_base64 = string_encoding::encode(self.0.out_point(), Encoding::Base64);
|
|
94
|
+
|
|
95
|
+
js_sys::Reflect::set(
|
|
96
|
+
&js_object,
|
|
97
|
+
&"outPoint".to_owned().into(),
|
|
98
|
+
&JsValue::from(out_point_base64),
|
|
99
|
+
)?;
|
|
100
|
+
|
|
101
|
+
Ok(js_object)
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#[wasm_bindgen(js_name=toObject)]
|
|
105
|
+
pub fn to_object(&self) -> Result<JsValue, JsValue> {
|
|
106
|
+
let asset_lock_json =
|
|
107
|
+
serde_json::to_value(self.0.clone()).map_err(|e| from_dpp_err(e.into()))?;
|
|
108
|
+
|
|
109
|
+
let asset_lock_json_string =
|
|
110
|
+
serde_json::to_string(&asset_lock_json).map_err(|e| from_dpp_err(e.into()))?;
|
|
111
|
+
let js_object = js_sys::JSON::parse(&asset_lock_json_string)?;
|
|
112
|
+
|
|
113
|
+
let out_point = self.get_out_point();
|
|
114
|
+
|
|
115
|
+
js_sys::Reflect::set(
|
|
116
|
+
&js_object,
|
|
117
|
+
&"outPoint".to_owned().into(),
|
|
118
|
+
&JsValue::from(out_point),
|
|
119
|
+
)?;
|
|
120
|
+
|
|
121
|
+
Ok(js_object)
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
#[wasm_bindgen(js_name=createIdentifier)]
|
|
125
|
+
pub fn create_identifier(&self) -> Result<IdentifierWrapper, JsValue> {
|
|
126
|
+
let identifier = self
|
|
127
|
+
.0
|
|
128
|
+
.create_identifier()
|
|
129
|
+
.map_err(|e| from_dpp_err(e.into()))?;
|
|
130
|
+
Ok(identifier.into())
|
|
131
|
+
}
|
|
132
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
use dpp::identity::state_transition::asset_lock_proof::{
|
|
2
|
+
AssetLockTransactionValidator, ChainAssetLockProofStructureValidator,
|
|
3
|
+
};
|
|
4
|
+
use dpp::state_transition::state_transition_execution_context::StateTransitionExecutionContext;
|
|
5
|
+
use dpp::ProtocolError;
|
|
6
|
+
use std::sync::Arc;
|
|
7
|
+
use wasm_bindgen::prelude::*;
|
|
8
|
+
|
|
9
|
+
use crate::buffer::Buffer;
|
|
10
|
+
use crate::utils::ToSerdeJSONExt;
|
|
11
|
+
use crate::{
|
|
12
|
+
errors::from_dpp_err,
|
|
13
|
+
state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
|
|
14
|
+
validation::ValidationResultWasm,
|
|
15
|
+
StateTransitionExecutionContextWasm,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
#[wasm_bindgen(js_name = ChainAssetLockProofStructureValidator)]
|
|
19
|
+
pub struct ChainAssetLockProofStructureValidatorWasm(
|
|
20
|
+
ChainAssetLockProofStructureValidator<ExternalStateRepositoryLikeWrapper>,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
impl From<ChainAssetLockProofStructureValidator<ExternalStateRepositoryLikeWrapper>>
|
|
24
|
+
for ChainAssetLockProofStructureValidatorWasm
|
|
25
|
+
{
|
|
26
|
+
fn from(
|
|
27
|
+
validator: ChainAssetLockProofStructureValidator<ExternalStateRepositoryLikeWrapper>,
|
|
28
|
+
) -> Self {
|
|
29
|
+
Self(validator)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[wasm_bindgen(js_class = ChainAssetLockProofStructureValidator)]
|
|
34
|
+
impl ChainAssetLockProofStructureValidatorWasm {
|
|
35
|
+
#[wasm_bindgen(constructor)]
|
|
36
|
+
pub fn new(
|
|
37
|
+
state_repository: ExternalStateRepositoryLike,
|
|
38
|
+
) -> Result<ChainAssetLockProofStructureValidatorWasm, JsValue> {
|
|
39
|
+
let state_repository_wrapper =
|
|
40
|
+
Arc::new(ExternalStateRepositoryLikeWrapper::new(state_repository));
|
|
41
|
+
|
|
42
|
+
let tx_validator = Arc::new(AssetLockTransactionValidator::new(
|
|
43
|
+
state_repository_wrapper.clone(),
|
|
44
|
+
));
|
|
45
|
+
|
|
46
|
+
let validator =
|
|
47
|
+
ChainAssetLockProofStructureValidator::new(state_repository_wrapper, tx_validator)
|
|
48
|
+
.map_err(|e| from_dpp_err(ProtocolError::Generic(e.to_string())))?;
|
|
49
|
+
|
|
50
|
+
Ok(validator.into())
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[wasm_bindgen]
|
|
54
|
+
pub async fn validate(
|
|
55
|
+
&self,
|
|
56
|
+
raw_asset_lock_proof: JsValue,
|
|
57
|
+
execution_context: &StateTransitionExecutionContextWasm,
|
|
58
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
59
|
+
let asset_lock_proof_json = raw_asset_lock_proof.with_serde_to_json_value()?;
|
|
60
|
+
|
|
61
|
+
let context: &StateTransitionExecutionContext = execution_context.into();
|
|
62
|
+
let validation_result = self
|
|
63
|
+
.0
|
|
64
|
+
.validate(&asset_lock_proof_json, context)
|
|
65
|
+
.await
|
|
66
|
+
.map_err(|e| from_dpp_err(e.into()))?;
|
|
67
|
+
|
|
68
|
+
Ok(validation_result
|
|
69
|
+
.map(|item| JsValue::from(Buffer::from_bytes(&item)))
|
|
70
|
+
.into())
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
use dpp::{
|
|
2
|
+
dashcore::{
|
|
3
|
+
blockdata::{script::Script, transaction::txout::TxOut},
|
|
4
|
+
consensus::encode::serialize,
|
|
5
|
+
},
|
|
6
|
+
util::string_encoding,
|
|
7
|
+
util::string_encoding::Encoding,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
use serde::{Deserialize, Serialize};
|
|
11
|
+
use std::convert::TryInto;
|
|
12
|
+
use wasm_bindgen::prelude::*;
|
|
13
|
+
|
|
14
|
+
use crate::{
|
|
15
|
+
buffer::Buffer,
|
|
16
|
+
errors::{from_dpp_err, RustConversionError},
|
|
17
|
+
identifier::IdentifierWrapper,
|
|
18
|
+
with_js_error,
|
|
19
|
+
};
|
|
20
|
+
use dpp::identity::state_transition::asset_lock_proof::instant::{
|
|
21
|
+
InstantAssetLockProof, RawInstantLock,
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
#[derive(Serialize, Deserialize)]
|
|
25
|
+
#[serde(remote = "TxOut")]
|
|
26
|
+
struct TxOutJS {
|
|
27
|
+
#[serde(rename = "satoshis")]
|
|
28
|
+
value: u64,
|
|
29
|
+
#[serde(rename = "script")]
|
|
30
|
+
script_pubkey: Script,
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[derive(Serialize)]
|
|
34
|
+
struct TxOutSerdeHelper<'a>(#[serde(with = "TxOutJS")] &'a TxOut);
|
|
35
|
+
|
|
36
|
+
#[derive(Debug, Clone, Deserialize, Serialize)]
|
|
37
|
+
#[wasm_bindgen(js_name=InstantAssetLockProof)]
|
|
38
|
+
pub struct InstantAssetLockProofWasm(InstantAssetLockProof);
|
|
39
|
+
|
|
40
|
+
impl From<InstantAssetLockProof> for InstantAssetLockProofWasm {
|
|
41
|
+
fn from(v: InstantAssetLockProof) -> Self {
|
|
42
|
+
InstantAssetLockProofWasm(v)
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
impl From<InstantAssetLockProofWasm> for InstantAssetLockProof {
|
|
47
|
+
fn from(v: InstantAssetLockProofWasm) -> Self {
|
|
48
|
+
v.0
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
#[wasm_bindgen(js_class = InstantAssetLockProof)]
|
|
53
|
+
impl InstantAssetLockProofWasm {
|
|
54
|
+
#[wasm_bindgen(constructor)]
|
|
55
|
+
pub fn new(raw_parameters: JsValue) -> Result<InstantAssetLockProofWasm, JsValue> {
|
|
56
|
+
let raw_instant_lock: RawInstantLock =
|
|
57
|
+
with_js_error!(serde_wasm_bindgen::from_value(raw_parameters))?;
|
|
58
|
+
|
|
59
|
+
let instant_asset_lock_proof: InstantAssetLockProof =
|
|
60
|
+
raw_instant_lock.try_into().map_err(|_| {
|
|
61
|
+
RustConversionError::Error(String::from("object passed is not a raw Instant Lock"))
|
|
62
|
+
.to_js_value()
|
|
63
|
+
})?;
|
|
64
|
+
|
|
65
|
+
Ok(instant_asset_lock_proof.into())
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#[wasm_bindgen(js_name=getType)]
|
|
69
|
+
pub fn get_type(&self) -> u8 {
|
|
70
|
+
self.0.asset_lock_type()
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
#[wasm_bindgen(js_name=getOutputIndex)]
|
|
74
|
+
pub fn get_output_index(&self) -> usize {
|
|
75
|
+
self.0.output_index()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#[wasm_bindgen(js_name=getOutPoint)]
|
|
79
|
+
pub fn get_out_point(&self) -> Option<Buffer> {
|
|
80
|
+
self.0
|
|
81
|
+
.out_point()
|
|
82
|
+
.map(|out_point| Buffer::from_bytes(&out_point))
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
#[wasm_bindgen(js_name=getOutput)]
|
|
86
|
+
pub fn get_output(&self) -> Result<JsValue, JsValue> {
|
|
87
|
+
let output = self.0.output().unwrap();
|
|
88
|
+
let output_json_string =
|
|
89
|
+
serde_json::to_string(&TxOutSerdeHelper(output)).map_err(|e| from_dpp_err(e.into()))?;
|
|
90
|
+
|
|
91
|
+
let js_object = js_sys::JSON::parse(&output_json_string)?;
|
|
92
|
+
Ok(js_object)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[wasm_bindgen(js_name=createIdentifier)]
|
|
96
|
+
pub fn create_identifier(&self) -> Result<IdentifierWrapper, JsValue> {
|
|
97
|
+
let identifier = self
|
|
98
|
+
.0
|
|
99
|
+
.create_identifier()
|
|
100
|
+
.map_err(|e| from_dpp_err(e.into()))?;
|
|
101
|
+
Ok(identifier.into())
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#[wasm_bindgen(js_name=getInstantLock)]
|
|
105
|
+
pub fn get_instant_lock(&self) -> Buffer {
|
|
106
|
+
let instant_lock = self.0.instant_lock();
|
|
107
|
+
let serialized_instant_lock = serialize(instant_lock);
|
|
108
|
+
Buffer::from_bytes(&serialized_instant_lock)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#[wasm_bindgen(js_name=getTransaction)]
|
|
112
|
+
pub fn get_transaction(&self) -> Buffer {
|
|
113
|
+
let transaction = self.0.transaction();
|
|
114
|
+
let serialized_transaction = serialize(transaction);
|
|
115
|
+
Buffer::from_bytes(&serialized_transaction)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
#[wasm_bindgen(js_name=toObject)]
|
|
119
|
+
pub fn to_object(&self) -> Result<JsValue, JsValue> {
|
|
120
|
+
let asset_lock_json =
|
|
121
|
+
serde_json::to_value(self.0.clone()).map_err(|e| from_dpp_err(e.into()))?;
|
|
122
|
+
|
|
123
|
+
let asset_lock_json_string =
|
|
124
|
+
serde_json::to_string(&asset_lock_json).map_err(|e| from_dpp_err(e.into()))?;
|
|
125
|
+
let js_object = js_sys::JSON::parse(&asset_lock_json_string)?;
|
|
126
|
+
|
|
127
|
+
let transaction = self.get_transaction();
|
|
128
|
+
let instant_lock = self.get_instant_lock();
|
|
129
|
+
|
|
130
|
+
js_sys::Reflect::set(
|
|
131
|
+
&js_object,
|
|
132
|
+
&"transaction".to_owned().into(),
|
|
133
|
+
&JsValue::from(transaction),
|
|
134
|
+
)?;
|
|
135
|
+
|
|
136
|
+
js_sys::Reflect::set(
|
|
137
|
+
&js_object,
|
|
138
|
+
&"instantLock".to_owned().into(),
|
|
139
|
+
&JsValue::from(instant_lock),
|
|
140
|
+
)?;
|
|
141
|
+
|
|
142
|
+
Ok(js_object)
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
146
|
+
pub fn to_json(&self) -> Result<JsValue, JsValue> {
|
|
147
|
+
let js_object = self.to_object()?;
|
|
148
|
+
|
|
149
|
+
let transaction = self.0.transaction();
|
|
150
|
+
let serialized_transaction = serialize(transaction);
|
|
151
|
+
|
|
152
|
+
let instant_lock = self.0.instant_lock();
|
|
153
|
+
let serialized_instant_lock = serialize(instant_lock);
|
|
154
|
+
|
|
155
|
+
let instant_lock_base64 =
|
|
156
|
+
string_encoding::encode(serialized_instant_lock.as_slice(), Encoding::Base64);
|
|
157
|
+
|
|
158
|
+
let mut transaction_hex = String::new();
|
|
159
|
+
for &byte in serialized_transaction.as_slice() {
|
|
160
|
+
transaction_hex.push_str(&format!("{:02x}", byte));
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
js_sys::Reflect::set(
|
|
164
|
+
&js_object,
|
|
165
|
+
&"transaction".to_owned().into(),
|
|
166
|
+
&JsValue::from(transaction_hex),
|
|
167
|
+
)?;
|
|
168
|
+
|
|
169
|
+
js_sys::Reflect::set(
|
|
170
|
+
&js_object,
|
|
171
|
+
&"instantLock".to_owned().into(),
|
|
172
|
+
&JsValue::from(instant_lock_base64),
|
|
173
|
+
)?;
|
|
174
|
+
|
|
175
|
+
Ok(js_object)
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
use dpp::identity::state_transition::asset_lock_proof::{
|
|
2
|
+
AssetLockTransactionValidator, InstantAssetLockProofStructureValidator,
|
|
3
|
+
};
|
|
4
|
+
use dpp::state_transition::state_transition_execution_context::StateTransitionExecutionContext;
|
|
5
|
+
use dpp::ProtocolError;
|
|
6
|
+
use std::sync::Arc;
|
|
7
|
+
use wasm_bindgen::prelude::*;
|
|
8
|
+
|
|
9
|
+
use crate::buffer::Buffer;
|
|
10
|
+
use crate::utils::ToSerdeJSONExt;
|
|
11
|
+
use crate::{
|
|
12
|
+
errors::from_dpp_err,
|
|
13
|
+
state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
|
|
14
|
+
validation::ValidationResultWasm,
|
|
15
|
+
StateTransitionExecutionContextWasm,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
#[wasm_bindgen(js_name = InstantAssetLockProofStructureValidator)]
|
|
19
|
+
pub struct InstantAssetLockProofStructureValidatorWasm(
|
|
20
|
+
InstantAssetLockProofStructureValidator<ExternalStateRepositoryLikeWrapper>,
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
impl From<InstantAssetLockProofStructureValidator<ExternalStateRepositoryLikeWrapper>>
|
|
24
|
+
for InstantAssetLockProofStructureValidatorWasm
|
|
25
|
+
{
|
|
26
|
+
fn from(
|
|
27
|
+
validator: InstantAssetLockProofStructureValidator<ExternalStateRepositoryLikeWrapper>,
|
|
28
|
+
) -> Self {
|
|
29
|
+
Self(validator)
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
#[wasm_bindgen(js_class = InstantAssetLockProofStructureValidator)]
|
|
34
|
+
impl InstantAssetLockProofStructureValidatorWasm {
|
|
35
|
+
#[wasm_bindgen(constructor)]
|
|
36
|
+
pub fn new(
|
|
37
|
+
state_repository: ExternalStateRepositoryLike,
|
|
38
|
+
) -> Result<InstantAssetLockProofStructureValidatorWasm, JsValue> {
|
|
39
|
+
let state_repository_wrapper =
|
|
40
|
+
Arc::new(ExternalStateRepositoryLikeWrapper::new(state_repository));
|
|
41
|
+
|
|
42
|
+
let tx_validator = Arc::new(AssetLockTransactionValidator::new(
|
|
43
|
+
state_repository_wrapper.clone(),
|
|
44
|
+
));
|
|
45
|
+
|
|
46
|
+
let validator =
|
|
47
|
+
InstantAssetLockProofStructureValidator::new(state_repository_wrapper, tx_validator)
|
|
48
|
+
.map_err(|e| from_dpp_err(ProtocolError::Generic(e.to_string())))?;
|
|
49
|
+
|
|
50
|
+
Ok(validator.into())
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[wasm_bindgen]
|
|
54
|
+
pub async fn validate(
|
|
55
|
+
&self,
|
|
56
|
+
raw_asset_lock_proof: JsValue,
|
|
57
|
+
execution_context: &StateTransitionExecutionContextWasm,
|
|
58
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
59
|
+
let asset_lock_proof_json = raw_asset_lock_proof.with_serde_to_json_value()?;
|
|
60
|
+
|
|
61
|
+
let context: &StateTransitionExecutionContext = execution_context.into();
|
|
62
|
+
let validation_result = self
|
|
63
|
+
.0
|
|
64
|
+
.validate(&asset_lock_proof_json, context)
|
|
65
|
+
.await
|
|
66
|
+
.map_err(|e| from_dpp_err(e.into()))?;
|
|
67
|
+
|
|
68
|
+
Ok(validation_result
|
|
69
|
+
.map(|item| JsValue::from(Buffer::from_bytes(&item)))
|
|
70
|
+
.into())
|
|
71
|
+
}
|
|
72
|
+
}
|