@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,12 +1,15 @@
|
|
|
1
|
-
use wasm_bindgen::JsValue;
|
|
1
|
+
use wasm_bindgen::{JsError, JsValue};
|
|
2
2
|
|
|
3
3
|
use super::consensus_error::from_consensus_error;
|
|
4
4
|
|
|
5
|
-
pub fn from_protocol_error(
|
|
6
|
-
match
|
|
5
|
+
pub fn from_protocol_error(protocol_error: dpp::ProtocolError) -> JsValue {
|
|
6
|
+
match protocol_error {
|
|
7
7
|
dpp::ProtocolError::AbstractConsensusError(consensus_error) => {
|
|
8
8
|
from_consensus_error(*consensus_error)
|
|
9
9
|
}
|
|
10
|
-
|
|
10
|
+
dpp::ProtocolError::Error(anyhow_error) => {
|
|
11
|
+
format!("Non-protocol error: {}", anyhow_error).into()
|
|
12
|
+
}
|
|
13
|
+
_ => todo!("Implement protocol error conversions"),
|
|
11
14
|
}
|
|
12
15
|
}
|
package/src/identifier/mod.rs
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
|
+
use dpp::prelude::Identifier;
|
|
2
|
+
use dpp::util::string_encoding::Encoding;
|
|
3
|
+
use itertools::Itertools;
|
|
1
4
|
pub use serde::{Deserialize, Serialize};
|
|
5
|
+
use serde_json::Value;
|
|
2
6
|
use wasm_bindgen::prelude::*;
|
|
3
7
|
use wasm_bindgen::JsCast;
|
|
4
8
|
|
|
9
|
+
use crate::bail_js;
|
|
5
10
|
use crate::buffer::Buffer;
|
|
6
11
|
use crate::errors::from_dpp_err;
|
|
12
|
+
use crate::utils::ToSerdeJSONExt;
|
|
13
|
+
use crate::utils::WithJsError;
|
|
7
14
|
use dpp::identifier;
|
|
8
15
|
|
|
9
16
|
#[derive(Serialize, Deserialize, PartialEq, Eq)]
|
|
@@ -35,7 +42,6 @@ impl std::convert::From<identifier::Identifier> for IdentifierWrapper {
|
|
|
35
42
|
impl IdentifierWrapper {
|
|
36
43
|
#[wasm_bindgen(constructor)]
|
|
37
44
|
pub fn new(buffer: Vec<u8>) -> Result<IdentifierWrapper, JsValue> {
|
|
38
|
-
// TODO: remove unwrap
|
|
39
45
|
let identifier = identifier::Identifier::from_bytes(&buffer).map_err(from_dpp_err)?;
|
|
40
46
|
|
|
41
47
|
Ok(IdentifierWrapper {
|
|
@@ -73,7 +79,7 @@ impl IdentifierWrapper {
|
|
|
73
79
|
|
|
74
80
|
#[wasm_bindgen(js_name=toBuffer)]
|
|
75
81
|
pub fn to_buffer(&self) -> Buffer {
|
|
76
|
-
Buffer::from_bytes(self.wrapped.buffer
|
|
82
|
+
Buffer::from_bytes(&self.wrapped.buffer)
|
|
77
83
|
}
|
|
78
84
|
|
|
79
85
|
#[wasm_bindgen(js_name=toJSON)]
|
|
@@ -97,7 +103,46 @@ impl IdentifierWrapper {
|
|
|
97
103
|
self.wrapped.buffer.len()
|
|
98
104
|
}
|
|
99
105
|
|
|
100
|
-
|
|
106
|
+
#[wasm_bindgen(js_name=toBytes)]
|
|
107
|
+
pub fn to_bytes(&self) -> Vec<u8> {
|
|
101
108
|
self.wrapped.buffer.to_vec()
|
|
102
109
|
}
|
|
110
|
+
|
|
111
|
+
#[wasm_bindgen(js_name=clone)]
|
|
112
|
+
pub fn deep_clone(&self) -> IdentifierWrapper {
|
|
113
|
+
IdentifierWrapper {
|
|
114
|
+
wrapped: self.wrapped.clone(),
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
impl IdentifierWrapper {
|
|
120
|
+
pub fn inner(self) -> Identifier {
|
|
121
|
+
self.wrapped
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// tries to create identifier from
|
|
126
|
+
pub fn identifier_from_js_value(js_value: &JsValue) -> Result<Identifier, JsValue> {
|
|
127
|
+
let value = js_value.with_serde_to_json_value()?;
|
|
128
|
+
match value {
|
|
129
|
+
Value::Array(arr) => {
|
|
130
|
+
let bytes: Vec<u8> = arr.into_iter().map(value_to_u8).try_collect()?;
|
|
131
|
+
Identifier::from_bytes(&bytes).with_js_error()
|
|
132
|
+
}
|
|
133
|
+
Value::String(string) => Identifier::from_string(&string, Encoding::Base58).with_js_error(),
|
|
134
|
+
_ => {
|
|
135
|
+
bail_js!("Invalid ID. Expected array or string")
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
fn value_to_u8(v: Value) -> Result<u8, JsValue> {
|
|
141
|
+
let number = v
|
|
142
|
+
.as_u64()
|
|
143
|
+
.ok_or_else(|| format!("failed converting {} into u64", v))?;
|
|
144
|
+
if number > u8::MAX as u64 {
|
|
145
|
+
bail_js!("the integer in the array isn't a byte: {}", number);
|
|
146
|
+
}
|
|
147
|
+
Ok(number as u8)
|
|
103
148
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
use dpp::identity::errors::AssetLockOutputNotFoundError;
|
|
2
|
+
use wasm_bindgen::prelude::*;
|
|
3
|
+
|
|
4
|
+
#[wasm_bindgen(js_name=AssetLockOutputNotFoundError)]
|
|
5
|
+
pub struct AssetLockOutputNotFoundErrorWasm(AssetLockOutputNotFoundError);
|
|
6
|
+
|
|
7
|
+
impl From<&AssetLockOutputNotFoundError> for AssetLockOutputNotFoundErrorWasm {
|
|
8
|
+
fn from(e: &AssetLockOutputNotFoundError) -> Self {
|
|
9
|
+
Self(e.clone())
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
use dpp::dashcore::hashes::hex::ToHex;
|
|
2
|
+
use dpp::identity::errors::AssetLockTransactionIsNotFoundError;
|
|
3
|
+
use wasm_bindgen::prelude::*;
|
|
4
|
+
|
|
5
|
+
#[wasm_bindgen(js_name=AssetLockTransactionIsNotFoundError)]
|
|
6
|
+
pub struct AssetLockTransactionIsNotFoundErrorWasm(AssetLockTransactionIsNotFoundError);
|
|
7
|
+
|
|
8
|
+
impl From<&AssetLockTransactionIsNotFoundError> for AssetLockTransactionIsNotFoundErrorWasm {
|
|
9
|
+
fn from(e: &AssetLockTransactionIsNotFoundError) -> Self {
|
|
10
|
+
Self(e.clone())
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
#[wasm_bindgen(js_class=AssetLockTransactionIsNotFoundError)]
|
|
15
|
+
impl AssetLockTransactionIsNotFoundErrorWasm {
|
|
16
|
+
#[wasm_bindgen(js_name=getTransactionId)]
|
|
17
|
+
pub fn transaction_id(&self) -> JsValue {
|
|
18
|
+
self.0.transaction_id().to_hex().into()
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
pub use asset_lock_output_not_found_error::*;
|
|
2
|
+
pub use asset_lock_transaction_is_not_found_error::*;
|
|
3
|
+
pub use unknown_asset_lock_proof_type_error::*;
|
|
4
|
+
|
|
5
|
+
mod asset_lock_output_not_found_error;
|
|
6
|
+
mod asset_lock_transaction_is_not_found_error;
|
|
7
|
+
mod unknown_asset_lock_proof_type_error;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
use dpp::identity::errors::UnknownAssetLockProofTypeError;
|
|
2
|
+
use wasm_bindgen::prelude::*;
|
|
3
|
+
|
|
4
|
+
#[derive(Clone)]
|
|
5
|
+
#[wasm_bindgen(js_name=UnknownAssetLockProofTypeError)]
|
|
6
|
+
pub struct UnknownAssetLockProofTypeErrorWasm(UnknownAssetLockProofTypeError);
|
|
7
|
+
|
|
8
|
+
impl From<&UnknownAssetLockProofTypeError> for UnknownAssetLockProofTypeErrorWasm {
|
|
9
|
+
fn from(e: &UnknownAssetLockProofTypeError) -> Self {
|
|
10
|
+
Self(e.clone())
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
impl From<UnknownAssetLockProofTypeError> for UnknownAssetLockProofTypeErrorWasm {
|
|
15
|
+
fn from(e: UnknownAssetLockProofTypeError) -> Self {
|
|
16
|
+
Self(e)
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
#[wasm_bindgen(js_class=UnknownAssetLockProofTypeError)]
|
|
21
|
+
impl UnknownAssetLockProofTypeErrorWasm {
|
|
22
|
+
#[wasm_bindgen(js_name=getType)]
|
|
23
|
+
pub fn get_type(&self) -> Option<u8> {
|
|
24
|
+
self.0.asset_lock_type()
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -38,10 +38,8 @@ impl IdentityFacadeWasm {
|
|
|
38
38
|
let identity_json = serde_wasm_bindgen::from_value(raw_identity_object)
|
|
39
39
|
.expect("unable to serialize identity");
|
|
40
40
|
// TODO: handle the case when
|
|
41
|
-
self.0
|
|
42
|
-
|
|
43
|
-
.map(|res| res.into())
|
|
44
|
-
.map_err(|err| err.into())
|
|
41
|
+
let validation_result = self.0.validate(&identity_json)?;
|
|
42
|
+
Ok(validation_result.map(|_| JsValue::undefined()).into())
|
|
45
43
|
}
|
|
46
44
|
}
|
|
47
45
|
|
|
@@ -136,32 +136,66 @@ impl IdentityPublicKeyWasm {
|
|
|
136
136
|
}
|
|
137
137
|
|
|
138
138
|
#[wasm_bindgen(js_name=toObject)]
|
|
139
|
-
pub fn to_object(&self,
|
|
139
|
+
pub fn to_object(&self, skip_signatures: Option<bool>) -> Result<JsValue, JsValue> {
|
|
140
140
|
let val = self
|
|
141
141
|
.0
|
|
142
|
-
.to_raw_json_object(
|
|
142
|
+
.to_raw_json_object(skip_signatures.unwrap_or(false))
|
|
143
143
|
.map_err(|e| from_dpp_err(e.into()))?;
|
|
144
144
|
|
|
145
145
|
let data_buffer = Buffer::from_bytes(self.0.get_data());
|
|
146
|
-
let signature_buffer = Buffer::from_bytes(self.0.get_signature());
|
|
147
146
|
|
|
148
147
|
let json = val.to_string();
|
|
149
148
|
let js_object = js_sys::JSON::parse(&json)?;
|
|
150
149
|
|
|
151
150
|
js_sys::Reflect::set(
|
|
152
151
|
&js_object,
|
|
153
|
-
&"
|
|
154
|
-
&JsValue::from(
|
|
152
|
+
&JsValue::from_str("type"),
|
|
153
|
+
&JsValue::from(self.get_type()),
|
|
155
154
|
)?;
|
|
156
155
|
|
|
157
156
|
js_sys::Reflect::set(
|
|
158
157
|
&js_object,
|
|
159
|
-
&"
|
|
160
|
-
&JsValue::from(
|
|
158
|
+
&"data".to_owned().into(),
|
|
159
|
+
&JsValue::from(data_buffer),
|
|
161
160
|
)?;
|
|
162
161
|
|
|
162
|
+
if !skip_signatures.unwrap_or(false) {
|
|
163
|
+
let signature = self.0.get_signature();
|
|
164
|
+
if !signature.is_empty() {
|
|
165
|
+
js_sys::Reflect::set(
|
|
166
|
+
&js_object,
|
|
167
|
+
&"signature".to_owned().into(),
|
|
168
|
+
&JsValue::from(Buffer::from_bytes(signature)),
|
|
169
|
+
)?;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
163
173
|
Ok(js_object)
|
|
164
174
|
}
|
|
175
|
+
|
|
176
|
+
#[wasm_bindgen(js_name=setSignature)]
|
|
177
|
+
pub fn set_signature(&mut self, signature: Vec<u8>) {
|
|
178
|
+
self.0.set_signature(signature);
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#[wasm_bindgen(js_name=getSignature)]
|
|
182
|
+
pub fn get_signature(&mut self) -> Buffer {
|
|
183
|
+
Buffer::from_bytes(self.0.get_signature())
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
impl IdentityPublicKeyWasm {
|
|
188
|
+
pub fn into_inner(self) -> IdentityPublicKey {
|
|
189
|
+
self.0
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
pub fn inner(&self) -> &IdentityPublicKey {
|
|
193
|
+
&self.0
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
pub fn inner_mut(&mut self) -> &mut IdentityPublicKey {
|
|
197
|
+
&mut self.0
|
|
198
|
+
}
|
|
165
199
|
}
|
|
166
200
|
|
|
167
201
|
impl From<IdentityPublicKey> for IdentityPublicKeyWasm {
|
package/src/identity/mod.rs
CHANGED
|
@@ -19,15 +19,24 @@ use crate::utils::to_vec_of_serde_values;
|
|
|
19
19
|
use crate::MetadataWasm;
|
|
20
20
|
pub use identity_public_key::*;
|
|
21
21
|
|
|
22
|
+
pub use state_transition::*;
|
|
23
|
+
|
|
24
|
+
pub mod errors;
|
|
25
|
+
pub mod state_transition;
|
|
26
|
+
|
|
22
27
|
#[wasm_bindgen(js_name=Identity)]
|
|
23
28
|
#[derive(Clone)]
|
|
24
29
|
pub struct IdentityWasm(Identity);
|
|
25
30
|
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
impl From<IdentityWasm> for Identity {
|
|
32
|
+
fn from(identity: IdentityWasm) -> Self {
|
|
33
|
+
identity.0
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
impl From<Identity> for IdentityWasm {
|
|
38
|
+
fn from(identity: Identity) -> Self {
|
|
39
|
+
Self(identity)
|
|
31
40
|
}
|
|
32
41
|
}
|
|
33
42
|
|
|
@@ -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
|
+
}
|