@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
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
mod chain;
|
|
2
|
+
mod instant;
|
|
3
|
+
|
|
4
|
+
pub use chain::*;
|
|
5
|
+
pub use instant::*;
|
|
6
|
+
use std::convert::TryInto;
|
|
7
|
+
use std::sync::Arc;
|
|
8
|
+
use wasm_bindgen::JsCast;
|
|
9
|
+
use wasm_bindgen::__rt::Ref;
|
|
10
|
+
|
|
11
|
+
use crate::errors::{from_dpp_err, RustConversionError};
|
|
12
|
+
use dpp::dashcore::consensus;
|
|
13
|
+
use dpp::dashcore::hashes::hex::FromHex;
|
|
14
|
+
use dpp::identity::errors::UnknownAssetLockProofTypeError;
|
|
15
|
+
use wasm_bindgen::prelude::*;
|
|
16
|
+
|
|
17
|
+
use crate::buffer::Buffer;
|
|
18
|
+
use crate::errors::dpp_error::from_dpp_error_ref;
|
|
19
|
+
use crate::identifier::IdentifierWrapper;
|
|
20
|
+
use crate::identity::errors::UnknownAssetLockProofTypeErrorWasm;
|
|
21
|
+
use crate::state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper};
|
|
22
|
+
use crate::utils::generic_of_js_val;
|
|
23
|
+
use crate::validation::ValidationResultWasm;
|
|
24
|
+
use crate::{Deserialize, StateTransitionExecutionContextWasm};
|
|
25
|
+
use dpp::identity::state_transition::asset_lock_proof::{
|
|
26
|
+
AssetLockProof, AssetLockProofType, AssetLockPublicKeyHashFetcher,
|
|
27
|
+
AssetLockTransactionOutputFetcher, AssetLockTransactionValidator,
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
#[derive(Deserialize, Clone)]
|
|
31
|
+
#[wasm_bindgen(js_name=AssetLockProof)]
|
|
32
|
+
pub struct AssetLockProofWasm(AssetLockProof);
|
|
33
|
+
|
|
34
|
+
impl From<AssetLockProof> for AssetLockProofWasm {
|
|
35
|
+
fn from(v: AssetLockProof) -> Self {
|
|
36
|
+
AssetLockProofWasm(v)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
impl From<AssetLockProofWasm> for AssetLockProof {
|
|
41
|
+
fn from(v: AssetLockProofWasm) -> Self {
|
|
42
|
+
v.0
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
impl From<InstantAssetLockProofWasm> for AssetLockProofWasm {
|
|
47
|
+
fn from(f: InstantAssetLockProofWasm) -> Self {
|
|
48
|
+
AssetLockProof::Instant(f.into()).into()
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
impl From<ChainAssetLockProofWasm> for AssetLockProofWasm {
|
|
53
|
+
fn from(f: ChainAssetLockProofWasm) -> Self {
|
|
54
|
+
AssetLockProof::Chain(f.into()).into()
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
pub trait AssetLockProofLike {
|
|
59
|
+
fn to_object(&self) -> Result<JsValue, JsValue>;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
#[wasm_bindgen(js_class = AssetLockProof)]
|
|
63
|
+
impl AssetLockProofWasm {
|
|
64
|
+
#[wasm_bindgen(constructor)]
|
|
65
|
+
pub fn new(raw_asset_lock_proof: JsValue) -> Result<AssetLockProofWasm, JsValue> {
|
|
66
|
+
let lock_type = get_lock_type(&raw_asset_lock_proof)?;
|
|
67
|
+
|
|
68
|
+
match lock_type {
|
|
69
|
+
AssetLockProofType::Instant => {
|
|
70
|
+
Ok(InstantAssetLockProofWasm::new(raw_asset_lock_proof)?.into())
|
|
71
|
+
}
|
|
72
|
+
AssetLockProofType::Chain => {
|
|
73
|
+
Ok(ChainAssetLockProofWasm::new(raw_asset_lock_proof)?.into())
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#[wasm_bindgen(js_name=createIdentifier)]
|
|
79
|
+
pub fn create_identifier(&self) -> Result<IdentifierWrapper, JsValue> {
|
|
80
|
+
match &self.0 {
|
|
81
|
+
AssetLockProof::Instant(instant) => {
|
|
82
|
+
InstantAssetLockProofWasm::from(instant.to_owned()).create_identifier()
|
|
83
|
+
}
|
|
84
|
+
AssetLockProof::Chain(chain) => {
|
|
85
|
+
ChainAssetLockProofWasm::from(chain.to_owned()).create_identifier()
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
#[wasm_bindgen(js_name=toObject)]
|
|
91
|
+
pub fn to_object(&self) -> Result<JsValue, JsValue> {
|
|
92
|
+
match &self.0 {
|
|
93
|
+
AssetLockProof::Instant(instant) => {
|
|
94
|
+
InstantAssetLockProofWasm::from(instant.to_owned()).to_object()
|
|
95
|
+
}
|
|
96
|
+
AssetLockProof::Chain(chain) => {
|
|
97
|
+
ChainAssetLockProofWasm::from(chain.to_owned()).to_object()
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
fn get_lock_type(raw_asset_lock_proof: &JsValue) -> Result<AssetLockProofType, JsValue> {
|
|
104
|
+
(js_sys::Reflect::get(raw_asset_lock_proof, &JsValue::from_str("type"))
|
|
105
|
+
.map_err(|_| {
|
|
106
|
+
RustConversionError::Error(String::from("error getting type from raw asset lock"))
|
|
107
|
+
.to_js_value()
|
|
108
|
+
})?
|
|
109
|
+
.as_f64()
|
|
110
|
+
.ok_or_else(|| JsValue::from_str("asset lock type must be a number"))? as u64)
|
|
111
|
+
.try_into()
|
|
112
|
+
.map_err(|_| JsValue::from_str("unrecognized asset lock proof type"))
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
#[wasm_bindgen(js_name=createAssetLockProofInstance)]
|
|
116
|
+
pub fn create_asset_lock_proof_instance(raw_parameters: JsValue) -> Result<JsValue, JsValue> {
|
|
117
|
+
let lock_type = get_lock_type(&raw_parameters)?;
|
|
118
|
+
|
|
119
|
+
match lock_type {
|
|
120
|
+
AssetLockProofType::Instant => {
|
|
121
|
+
InstantAssetLockProofWasm::new(raw_parameters).map(|v| v.into())
|
|
122
|
+
}
|
|
123
|
+
AssetLockProofType::Chain => ChainAssetLockProofWasm::new(raw_parameters).map(|v| v.into()),
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
pub fn create_asset_lock_proof_from_wasm_instance(
|
|
128
|
+
js_value: &JsValue,
|
|
129
|
+
) -> Result<AssetLockProof, JsValue> {
|
|
130
|
+
let default_error: UnknownAssetLockProofTypeErrorWasm =
|
|
131
|
+
UnknownAssetLockProofTypeError::new(None).into();
|
|
132
|
+
|
|
133
|
+
let get_type_value = js_sys::Reflect::get(js_value, &JsValue::from_str("getType"))
|
|
134
|
+
.map_err(|_| default_error.clone())?;
|
|
135
|
+
|
|
136
|
+
let get_type_function: &js_sys::Function = get_type_value
|
|
137
|
+
.dyn_ref::<js_sys::Function>()
|
|
138
|
+
.ok_or_else(|| default_error.clone())?;
|
|
139
|
+
|
|
140
|
+
let raw_lock_type = get_type_function
|
|
141
|
+
.call0(js_value)?
|
|
142
|
+
.as_f64()
|
|
143
|
+
.ok_or(default_error)? as u64;
|
|
144
|
+
|
|
145
|
+
let lock_type: AssetLockProofType = raw_lock_type.try_into().map_err(|_| {
|
|
146
|
+
UnknownAssetLockProofTypeErrorWasm::from(UnknownAssetLockProofTypeError::new(Some(
|
|
147
|
+
raw_lock_type as u8,
|
|
148
|
+
)))
|
|
149
|
+
})?;
|
|
150
|
+
|
|
151
|
+
match lock_type {
|
|
152
|
+
AssetLockProofType::Instant => {
|
|
153
|
+
let instant: Ref<InstantAssetLockProofWasm> =
|
|
154
|
+
generic_of_js_val::<InstantAssetLockProofWasm>(js_value, "InstantAssetLockProof")?;
|
|
155
|
+
|
|
156
|
+
Ok(AssetLockProof::Instant(instant.clone().into()))
|
|
157
|
+
}
|
|
158
|
+
AssetLockProofType::Chain => {
|
|
159
|
+
let chain: Ref<ChainAssetLockProofWasm> =
|
|
160
|
+
generic_of_js_val::<ChainAssetLockProofWasm>(js_value, "ChainAssetLockProof")?;
|
|
161
|
+
|
|
162
|
+
Ok(AssetLockProof::Chain(chain.clone().into()))
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
#[wasm_bindgen(js_name=validateAssetLockTransaction)]
|
|
168
|
+
pub async fn validate_asset_lock_transaction(
|
|
169
|
+
state_repository: ExternalStateRepositoryLike,
|
|
170
|
+
raw_transaction: String,
|
|
171
|
+
output_index: usize,
|
|
172
|
+
execution_context: &StateTransitionExecutionContextWasm,
|
|
173
|
+
) -> Result<ValidationResultWasm, JsValue> {
|
|
174
|
+
let tx_bytes = Vec::from_hex(&raw_transaction)
|
|
175
|
+
.map_err(|_| RustConversionError::Error(String::from("invalid transaction hex")))?;
|
|
176
|
+
|
|
177
|
+
let state_repository_wrapper =
|
|
178
|
+
Arc::new(ExternalStateRepositoryLikeWrapper::new(state_repository));
|
|
179
|
+
|
|
180
|
+
let validator = AssetLockTransactionValidator::new(state_repository_wrapper);
|
|
181
|
+
|
|
182
|
+
let result = validator
|
|
183
|
+
.validate(tx_bytes.as_slice(), output_index, execution_context.into())
|
|
184
|
+
.await
|
|
185
|
+
.map_err(|e| from_dpp_err(e.into()))?;
|
|
186
|
+
|
|
187
|
+
let validation_result = result.map(|item| {
|
|
188
|
+
let object = js_sys::Object::new();
|
|
189
|
+
|
|
190
|
+
js_sys::Reflect::set(
|
|
191
|
+
&object,
|
|
192
|
+
&"publicKeyHash".to_owned().into(),
|
|
193
|
+
&Buffer::from_bytes(&item.public_key_hash),
|
|
194
|
+
)
|
|
195
|
+
.unwrap();
|
|
196
|
+
|
|
197
|
+
let deserialized_tx = consensus::serialize(&item.transaction);
|
|
198
|
+
|
|
199
|
+
js_sys::Reflect::set(
|
|
200
|
+
&object,
|
|
201
|
+
&"transaction".to_owned().into(),
|
|
202
|
+
&Buffer::from_bytes(&deserialized_tx),
|
|
203
|
+
)
|
|
204
|
+
.unwrap();
|
|
205
|
+
|
|
206
|
+
object
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
Ok(validation_result.into())
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
#[wasm_bindgen(js_name=fetchAssetLockTransactionOutput)]
|
|
213
|
+
pub async fn fetch_asset_lock_transaction_output(
|
|
214
|
+
state_repository: ExternalStateRepositoryLike,
|
|
215
|
+
raw_asset_lock_proof: JsValue,
|
|
216
|
+
execution_context: &StateTransitionExecutionContextWasm,
|
|
217
|
+
) -> Result<JsValue, JsValue> {
|
|
218
|
+
let asset_lock_proof = create_asset_lock_proof_from_wasm_instance(&raw_asset_lock_proof)?;
|
|
219
|
+
|
|
220
|
+
let state_repository_wrapper =
|
|
221
|
+
Arc::new(ExternalStateRepositoryLikeWrapper::new(state_repository));
|
|
222
|
+
|
|
223
|
+
let fetcher = AssetLockTransactionOutputFetcher::new(state_repository_wrapper);
|
|
224
|
+
|
|
225
|
+
let fetch_result = fetcher
|
|
226
|
+
.fetch(&asset_lock_proof, execution_context.into())
|
|
227
|
+
.await
|
|
228
|
+
.map_err(|e| from_dpp_error_ref(&e))?;
|
|
229
|
+
|
|
230
|
+
let tx_out = js_sys::Object::new();
|
|
231
|
+
|
|
232
|
+
js_sys::Reflect::set(
|
|
233
|
+
&tx_out,
|
|
234
|
+
&"satoshis".to_owned().into(),
|
|
235
|
+
&(fetch_result.value as u32).into(),
|
|
236
|
+
)
|
|
237
|
+
.unwrap();
|
|
238
|
+
|
|
239
|
+
let script_hex = format!("{:x}", fetch_result.script_pubkey);
|
|
240
|
+
|
|
241
|
+
js_sys::Reflect::set(&tx_out, &"script".to_owned().into(), &script_hex.into()).unwrap();
|
|
242
|
+
|
|
243
|
+
Ok(tx_out.into())
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
#[wasm_bindgen(js_name=fetchAssetLockPublicKeyHash)]
|
|
247
|
+
pub async fn fetch_asset_lock_public_key_hash(
|
|
248
|
+
state_repository: ExternalStateRepositoryLike,
|
|
249
|
+
raw_asset_lock_proof: JsValue,
|
|
250
|
+
execution_context: &StateTransitionExecutionContextWasm,
|
|
251
|
+
) -> Result<JsValue, JsValue> {
|
|
252
|
+
let asset_lock_proof = create_asset_lock_proof_from_wasm_instance(&raw_asset_lock_proof)?;
|
|
253
|
+
|
|
254
|
+
let state_repository_wrapper =
|
|
255
|
+
Arc::new(ExternalStateRepositoryLikeWrapper::new(state_repository));
|
|
256
|
+
|
|
257
|
+
let tx_output_fetcher =
|
|
258
|
+
AssetLockTransactionOutputFetcher::new(state_repository_wrapper.clone());
|
|
259
|
+
|
|
260
|
+
let public_key_hash_fetcher =
|
|
261
|
+
AssetLockPublicKeyHashFetcher::new(state_repository_wrapper, tx_output_fetcher);
|
|
262
|
+
|
|
263
|
+
let fetch_result = public_key_hash_fetcher
|
|
264
|
+
.fetch_public_key_hash(asset_lock_proof, execution_context.into())
|
|
265
|
+
.await
|
|
266
|
+
.map_err(|e| from_dpp_error_ref(&e))?;
|
|
267
|
+
|
|
268
|
+
Ok(Buffer::from_bytes(&fetch_result).into())
|
|
269
|
+
}
|
package/src/identity/state_transition/identity_create_transition/apply_identity_create_transition.rs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
use dpp::identity::state_transition::identity_create_transition::ApplyIdentityCreateTransition;
|
|
2
|
+
use std::sync::Arc;
|
|
3
|
+
use wasm_bindgen::prelude::*;
|
|
4
|
+
|
|
5
|
+
use crate::{
|
|
6
|
+
state_repository::{ExternalStateRepositoryLike, ExternalStateRepositoryLikeWrapper},
|
|
7
|
+
IdentityCreateTransitionWasm,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
#[wasm_bindgen(js_name=applyIdentityCreateTransition)]
|
|
11
|
+
pub async fn apply_identity_create_transition_wasm(
|
|
12
|
+
state_repository: ExternalStateRepositoryLike,
|
|
13
|
+
state_transition: &IdentityCreateTransitionWasm,
|
|
14
|
+
) -> Result<(), JsValue> {
|
|
15
|
+
let wrapped_state_repository =
|
|
16
|
+
Arc::new(ExternalStateRepositoryLikeWrapper::new(state_repository));
|
|
17
|
+
|
|
18
|
+
let instance = ApplyIdentityCreateTransition::new(wrapped_state_repository);
|
|
19
|
+
|
|
20
|
+
instance
|
|
21
|
+
.apply_identity_create_transition(&state_transition.to_owned().into())
|
|
22
|
+
.await
|
|
23
|
+
.map_err(|e| JsValue::from_str(&e.to_string()))?;
|
|
24
|
+
|
|
25
|
+
Ok(())
|
|
26
|
+
}
|
package/src/identity/state_transition/identity_create_transition/identity_create_transition.rs
ADDED
|
@@ -0,0 +1,335 @@
|
|
|
1
|
+
use std::convert::TryInto;
|
|
2
|
+
use std::default::Default;
|
|
3
|
+
|
|
4
|
+
use wasm_bindgen::__rt::Ref;
|
|
5
|
+
use wasm_bindgen::prelude::*;
|
|
6
|
+
|
|
7
|
+
use crate::identifier::IdentifierWrapper;
|
|
8
|
+
|
|
9
|
+
use crate::{
|
|
10
|
+
buffer::Buffer,
|
|
11
|
+
create_asset_lock_proof_from_wasm_instance,
|
|
12
|
+
errors::RustConversionError,
|
|
13
|
+
identity::{
|
|
14
|
+
state_transition::asset_lock_proof::{ChainAssetLockProofWasm, InstantAssetLockProofWasm},
|
|
15
|
+
IdentityPublicKeyWasm,
|
|
16
|
+
},
|
|
17
|
+
state_transition::StateTransitionExecutionContextWasm,
|
|
18
|
+
with_js_error,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
use crate::bls_adapter::{BlsAdapter, JsBlsAdapter};
|
|
22
|
+
use crate::errors::from_dpp_err;
|
|
23
|
+
use crate::utils::{generic_of_js_val, ToSerdeJSONExt};
|
|
24
|
+
use dpp::{
|
|
25
|
+
identifier::Identifier,
|
|
26
|
+
identity::{
|
|
27
|
+
state_transition::{
|
|
28
|
+
asset_lock_proof::AssetLockProof, identity_create_transition::IdentityCreateTransition,
|
|
29
|
+
},
|
|
30
|
+
IdentityPublicKey,
|
|
31
|
+
},
|
|
32
|
+
state_transition::StateTransitionLike,
|
|
33
|
+
util::string_encoding,
|
|
34
|
+
util::string_encoding::Encoding,
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
#[wasm_bindgen(js_name=IdentityCreateTransition)]
|
|
38
|
+
#[derive(Clone)]
|
|
39
|
+
pub struct IdentityCreateTransitionWasm(IdentityCreateTransition);
|
|
40
|
+
|
|
41
|
+
impl From<IdentityCreateTransition> for IdentityCreateTransitionWasm {
|
|
42
|
+
fn from(v: IdentityCreateTransition) -> Self {
|
|
43
|
+
IdentityCreateTransitionWasm(v)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
impl From<IdentityCreateTransitionWasm> for IdentityCreateTransition {
|
|
48
|
+
fn from(v: IdentityCreateTransitionWasm) -> Self {
|
|
49
|
+
v.0
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[wasm_bindgen(js_class = IdentityCreateTransition)]
|
|
54
|
+
impl IdentityCreateTransitionWasm {
|
|
55
|
+
#[wasm_bindgen(constructor)]
|
|
56
|
+
pub fn new(raw_parameters: JsValue) -> Result<IdentityCreateTransitionWasm, JsValue> {
|
|
57
|
+
let raw_state_transition = raw_parameters.with_serde_to_json_value()?;
|
|
58
|
+
|
|
59
|
+
let identity_create_transition = IdentityCreateTransition::new(raw_state_transition)
|
|
60
|
+
.map_err(|e| RustConversionError::Error(e.to_string()).to_js_value())?;
|
|
61
|
+
|
|
62
|
+
Ok(identity_create_transition.into())
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
#[wasm_bindgen(js_name=setAssetLockProof)]
|
|
66
|
+
pub fn set_asset_lock_proof(&mut self, asset_lock_proof: JsValue) -> Result<(), JsValue> {
|
|
67
|
+
let asset_lock_proof = create_asset_lock_proof_from_wasm_instance(&asset_lock_proof)?;
|
|
68
|
+
|
|
69
|
+
self.0
|
|
70
|
+
.set_asset_lock_proof(asset_lock_proof)
|
|
71
|
+
.map_err(|e| RustConversionError::Error(e.to_string()).to_js_value())?;
|
|
72
|
+
|
|
73
|
+
Ok(())
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[wasm_bindgen(getter, js_name=assetLockProof)]
|
|
77
|
+
pub fn asset_lock_proof(&self) -> JsValue {
|
|
78
|
+
self.get_asset_lock_proof()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[wasm_bindgen(js_name=getAssetLockProof)]
|
|
82
|
+
pub fn get_asset_lock_proof(&self) -> JsValue {
|
|
83
|
+
let asset_lock_proof = self.0.get_asset_lock_proof().to_owned();
|
|
84
|
+
|
|
85
|
+
match asset_lock_proof {
|
|
86
|
+
AssetLockProof::Chain(chain_asset_lock_proof) => {
|
|
87
|
+
ChainAssetLockProofWasm::from(chain_asset_lock_proof).into()
|
|
88
|
+
}
|
|
89
|
+
AssetLockProof::Instant(instant_asset_lock_proof) => {
|
|
90
|
+
InstantAssetLockProofWasm::from(instant_asset_lock_proof).into()
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[wasm_bindgen(js_name=setPublicKeys)]
|
|
96
|
+
pub fn set_public_keys(&mut self, public_keys: Vec<JsValue>) -> Result<(), JsValue> {
|
|
97
|
+
let public_keys = public_keys
|
|
98
|
+
.iter()
|
|
99
|
+
.map(|value| {
|
|
100
|
+
let public_key: Ref<IdentityPublicKeyWasm> =
|
|
101
|
+
generic_of_js_val::<IdentityPublicKeyWasm>(value, "IdentityPublicKey")?;
|
|
102
|
+
Ok(public_key.clone().into())
|
|
103
|
+
})
|
|
104
|
+
.collect::<Result<Vec<IdentityPublicKey>, JsValue>>()?;
|
|
105
|
+
|
|
106
|
+
self.0.set_public_keys(public_keys);
|
|
107
|
+
|
|
108
|
+
Ok(())
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
#[wasm_bindgen(js_name=addPublicKeys)]
|
|
112
|
+
pub fn add_public_keys(&mut self, public_keys: Vec<JsValue>) -> Result<(), JsValue> {
|
|
113
|
+
let mut public_keys = public_keys
|
|
114
|
+
.iter()
|
|
115
|
+
.map(|value| {
|
|
116
|
+
let public_key: Ref<IdentityPublicKeyWasm> =
|
|
117
|
+
generic_of_js_val::<IdentityPublicKeyWasm>(value, "IdentityPublicKey")?;
|
|
118
|
+
Ok(public_key.clone().into())
|
|
119
|
+
})
|
|
120
|
+
.collect::<Result<Vec<IdentityPublicKey>, JsValue>>()?;
|
|
121
|
+
|
|
122
|
+
self.0.add_public_keys(&mut public_keys);
|
|
123
|
+
|
|
124
|
+
Ok(())
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#[wasm_bindgen(js_name=getPublicKeys)]
|
|
128
|
+
pub fn get_public_keys(&self) -> Vec<JsValue> {
|
|
129
|
+
self.0
|
|
130
|
+
.get_public_keys()
|
|
131
|
+
.iter()
|
|
132
|
+
.map(IdentityPublicKey::to_owned)
|
|
133
|
+
.map(IdentityPublicKeyWasm::from)
|
|
134
|
+
.map(JsValue::from)
|
|
135
|
+
.collect()
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
#[wasm_bindgen(getter, js_name=publicKeys)]
|
|
139
|
+
pub fn public_keys(&self) -> Vec<JsValue> {
|
|
140
|
+
self.get_public_keys()
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
#[wasm_bindgen(js_name=getType)]
|
|
144
|
+
pub fn get_type(&self) -> u8 {
|
|
145
|
+
self.0.get_type() as u8
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
#[wasm_bindgen(getter, js_name=identityId)]
|
|
149
|
+
pub fn identity_id(&self) -> IdentifierWrapper {
|
|
150
|
+
self.get_identity_id()
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
#[wasm_bindgen(js_name=getIdentityId)]
|
|
154
|
+
pub fn get_identity_id(&self) -> IdentifierWrapper {
|
|
155
|
+
self.0.get_identity_id().clone().into()
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
#[wasm_bindgen(js_name=getOwnerId)]
|
|
159
|
+
pub fn get_owner_id(&self) -> IdentifierWrapper {
|
|
160
|
+
self.0.get_owner_id().clone().into()
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
#[wasm_bindgen(js_name=toObject)]
|
|
164
|
+
pub fn to_object(&self, options: JsValue) -> Result<JsValue, JsValue> {
|
|
165
|
+
let opts: super::to_object::ToObjectOptions = if options.is_object() {
|
|
166
|
+
with_js_error!(serde_wasm_bindgen::from_value(options))?
|
|
167
|
+
} else {
|
|
168
|
+
Default::default()
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
let skip_signature = opts.skip_signature;
|
|
172
|
+
let object = super::to_object::to_object_struct(&self.0, opts);
|
|
173
|
+
let js_object = js_sys::Object::new();
|
|
174
|
+
|
|
175
|
+
js_sys::Reflect::set(
|
|
176
|
+
&js_object,
|
|
177
|
+
&"type".to_owned().into(),
|
|
178
|
+
&object.transition_type.into(),
|
|
179
|
+
)?;
|
|
180
|
+
|
|
181
|
+
js_sys::Reflect::set(
|
|
182
|
+
&js_object,
|
|
183
|
+
&"protocolVersion".to_owned().into(),
|
|
184
|
+
&object.protocol_version.into(),
|
|
185
|
+
)?;
|
|
186
|
+
|
|
187
|
+
if let Some(signature) = object.signature {
|
|
188
|
+
let signature_value: JsValue = if signature.is_empty() {
|
|
189
|
+
JsValue::undefined()
|
|
190
|
+
} else {
|
|
191
|
+
Buffer::from_bytes(&signature).into()
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
js_sys::Reflect::set(&js_object, &"signature".to_owned().into(), &signature_value)?;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
let asset_lock_proof_object = match object.asset_lock_proof {
|
|
198
|
+
AssetLockProof::Instant(instant_asset_lock_proof) => {
|
|
199
|
+
InstantAssetLockProofWasm::from(instant_asset_lock_proof).to_object()?
|
|
200
|
+
}
|
|
201
|
+
AssetLockProof::Chain(chain_asset_lock_proof) => {
|
|
202
|
+
ChainAssetLockProofWasm::from(chain_asset_lock_proof).to_object()?
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
js_sys::Reflect::set(
|
|
207
|
+
&js_object,
|
|
208
|
+
&"assetLockProof".to_owned().into(),
|
|
209
|
+
&asset_lock_proof_object,
|
|
210
|
+
)?;
|
|
211
|
+
|
|
212
|
+
let keys_objects = object
|
|
213
|
+
.public_keys
|
|
214
|
+
.into_iter()
|
|
215
|
+
.map(IdentityPublicKeyWasm::from)
|
|
216
|
+
.map(|key| key.to_object(skip_signature))
|
|
217
|
+
.collect::<Result<js_sys::Array, _>>()?;
|
|
218
|
+
|
|
219
|
+
js_sys::Reflect::set(&js_object, &"publicKeys".to_owned().into(), &keys_objects)?;
|
|
220
|
+
|
|
221
|
+
Ok(js_object.into())
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#[wasm_bindgen(js_name=toJSON)]
|
|
225
|
+
pub fn to_json(&self) -> Result<JsValue, JsValue> {
|
|
226
|
+
let object = super::to_object::to_object_struct(&self.0, Default::default());
|
|
227
|
+
let js_object = js_sys::Object::new();
|
|
228
|
+
|
|
229
|
+
js_sys::Reflect::set(
|
|
230
|
+
&js_object,
|
|
231
|
+
&"type".to_owned().into(),
|
|
232
|
+
&object.transition_type.into(),
|
|
233
|
+
)?;
|
|
234
|
+
|
|
235
|
+
js_sys::Reflect::set(
|
|
236
|
+
&js_object,
|
|
237
|
+
&"protocolVersion".to_owned().into(),
|
|
238
|
+
&object.protocol_version.into(),
|
|
239
|
+
)?;
|
|
240
|
+
|
|
241
|
+
if let Some(signature) = object.signature {
|
|
242
|
+
let signature_value: JsValue = if signature.is_empty() {
|
|
243
|
+
JsValue::undefined()
|
|
244
|
+
} else {
|
|
245
|
+
string_encoding::encode(signature.as_slice(), Encoding::Base64).into()
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
js_sys::Reflect::set(&js_object, &"signature".to_owned().into(), &signature_value)?;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
let asset_lock_proof_json = match object.asset_lock_proof {
|
|
252
|
+
AssetLockProof::Instant(instant_asset_lock_proof) => {
|
|
253
|
+
InstantAssetLockProofWasm::from(instant_asset_lock_proof).to_json()?
|
|
254
|
+
}
|
|
255
|
+
AssetLockProof::Chain(chain_asset_lock_proof) => {
|
|
256
|
+
ChainAssetLockProofWasm::from(chain_asset_lock_proof).to_json()?
|
|
257
|
+
}
|
|
258
|
+
};
|
|
259
|
+
|
|
260
|
+
js_sys::Reflect::set(
|
|
261
|
+
&js_object,
|
|
262
|
+
&"assetLockProof".to_owned().into(),
|
|
263
|
+
&asset_lock_proof_json,
|
|
264
|
+
)?;
|
|
265
|
+
|
|
266
|
+
let keys_objects = object
|
|
267
|
+
.public_keys
|
|
268
|
+
.into_iter()
|
|
269
|
+
.map(IdentityPublicKeyWasm::from)
|
|
270
|
+
.map(|key| key.to_json())
|
|
271
|
+
.collect::<Result<js_sys::Array, _>>()?;
|
|
272
|
+
|
|
273
|
+
js_sys::Reflect::set(&js_object, &"publicKeys".to_owned().into(), &keys_objects)?;
|
|
274
|
+
|
|
275
|
+
Ok(js_object.into())
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
#[wasm_bindgen(js_name=getModifiedDataIds)]
|
|
279
|
+
pub fn get_modified_data_ids(&self) -> Vec<JsValue> {
|
|
280
|
+
let ids = self.0.get_modified_data_ids();
|
|
281
|
+
|
|
282
|
+
ids.into_iter()
|
|
283
|
+
.map(|id| {
|
|
284
|
+
<IdentifierWrapper as std::convert::From<Identifier>>::from(id.clone()).into()
|
|
285
|
+
})
|
|
286
|
+
.collect()
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
#[wasm_bindgen(js_name=isDataContractStateTransition)]
|
|
290
|
+
pub fn is_data_contract_state_transition(&self) -> bool {
|
|
291
|
+
self.0.is_data_contract_state_transition()
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
#[wasm_bindgen(js_name=isDocumentStateTransition)]
|
|
295
|
+
pub fn is_document_state_transition(&self) -> bool {
|
|
296
|
+
self.0.is_document_state_transition()
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
#[wasm_bindgen(js_name=isIdentityStateTransition)]
|
|
300
|
+
pub fn is_identity_state_transition(&self) -> bool {
|
|
301
|
+
self.0.is_identity_state_transition()
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
#[wasm_bindgen(js_name=setExecutionContext)]
|
|
305
|
+
pub fn set_execution_context(&mut self, context: &StateTransitionExecutionContextWasm) {
|
|
306
|
+
self.0.set_execution_context(context.into())
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
#[wasm_bindgen(js_name=getExecutionContext)]
|
|
310
|
+
pub fn get_execution_context(&mut self) -> StateTransitionExecutionContextWasm {
|
|
311
|
+
self.0.get_execution_context().into()
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
#[wasm_bindgen(js_name=signByPrivateKey)]
|
|
315
|
+
pub fn sign_by_private_key(
|
|
316
|
+
&mut self,
|
|
317
|
+
private_key: Vec<u8>,
|
|
318
|
+
key_type: u8,
|
|
319
|
+
bls: JsBlsAdapter,
|
|
320
|
+
) -> Result<(), JsValue> {
|
|
321
|
+
let bls_adapter = BlsAdapter(bls);
|
|
322
|
+
let key_type = key_type
|
|
323
|
+
.try_into()
|
|
324
|
+
.map_err(|e: anyhow::Error| e.to_string())?;
|
|
325
|
+
|
|
326
|
+
self.0
|
|
327
|
+
.sign_by_private_key(private_key.as_slice(), key_type, &bls_adapter)
|
|
328
|
+
.map_err(from_dpp_err)
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
#[wasm_bindgen(js_name=getSignature)]
|
|
332
|
+
pub fn get_signature(&self) -> Buffer {
|
|
333
|
+
Buffer::from_bytes(self.0.get_signature())
|
|
334
|
+
}
|
|
335
|
+
}
|