pshenmic-dpp 1.0.4 → 1.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/build.yml +9 -1
- package/.github/workflows/publish.yml +9 -1
- package/Cargo.lock +222 -76
- package/Cargo.toml +28 -19
- package/README.md +75 -23
- package/babel.config.json +19 -0
- package/dist/wasm/index.d.ts +52 -0
- package/dist/wasm/pshenmic_dpp.d.ts +962 -0
- package/dist/wasm/pshenmic_dpp.js +5565 -966
- package/dist/wasm/pshenmic_dpp_bg.js +1 -1
- package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
- package/docs/AssetLockProof.md +107 -0
- package/docs/Building.md +50 -0
- package/docs/ChainLockProof.md +63 -0
- package/docs/CoreScript.md +17 -0
- package/docs/DataContract.md +192 -0
- package/docs/DataContractCreateTransition.md +84 -0
- package/docs/DataContractUpdateTransition.md +84 -0
- package/docs/Document.md +396 -0
- package/docs/DocumentBaseTransition.md +111 -0
- package/docs/DocumentCreateTransition.md +132 -0
- package/docs/DocumentDeleteTransition.md +82 -0
- package/docs/DocumentPurchaseTransition.md +109 -0
- package/docs/DocumentReplaceTransition.md +112 -0
- package/docs/DocumentTransferTransition.md +96 -0
- package/docs/DocumentTransition.md +125 -0
- package/docs/DocumentUpdatePriceTransition.md +109 -0
- package/docs/DocumentsBatch.md +133 -0
- package/docs/Enums.md +103 -0
- package/docs/Home.md +28 -0
- package/docs/Identifier.md +37 -0
- package/docs/Identity.md +140 -0
- package/docs/IdentityCreateTransition.md +155 -0
- package/docs/IdentityCreditTransfer.md +187 -0
- package/docs/IdentityCreditWithdrawalTransition.md +244 -0
- package/docs/IdentityPublicKey.md +348 -0
- package/docs/IdentityPublicKeyInCreation.md +141 -0
- package/docs/IdentityTopUpTransition.md +166 -0
- package/docs/IdentityUpdateTransition.md +234 -0
- package/docs/InstantAssetLockProof.md +117 -0
- package/docs/InstantLock.md +100 -0
- package/docs/OutPoint.md +80 -0
- package/docs/PrefundedVotingBalance.md +48 -0
- package/docs/PrivateKey.md +112 -0
- package/docs/TxOut.md +93 -0
- package/package.json +15 -8
- package/packages/asset_lock_proof/Cargo.toml +19 -0
- package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
- package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
- package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
- package/packages/asset_lock_proof/src/lib.rs +133 -0
- package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
- package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
- package/packages/cbor_conversation/Cargo.toml +2 -2
- package/packages/core_script/Cargo.toml +13 -0
- package/packages/core_script/src/lib.rs +69 -0
- package/packages/data_contract/Cargo.toml +4 -3
- package/packages/data_contract/src/lib.rs +209 -33
- package/packages/data_contract_transitions/Cargo.toml +2 -2
- package/packages/data_contract_transitions/src/create/mod.rs +23 -16
- package/packages/data_contract_transitions/src/update/mod.rs +21 -12
- package/packages/document/Cargo.toml +3 -2
- package/packages/document/src/lib.rs +14 -13
- package/packages/document/src/methods/mod.rs +373 -2
- package/packages/{document_batch → documents_batch}/Cargo.toml +7 -4
- package/packages/documents_batch/src/document_base_transition/mod.rs +88 -0
- package/packages/documents_batch/src/document_transition/mod.rs +166 -0
- package/packages/documents_batch/src/generators.rs +122 -0
- package/packages/documents_batch/src/lib.rs +195 -0
- package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
- package/packages/documents_batch/src/transitions/create/mod.rs +126 -0
- package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
- package/packages/documents_batch/src/transitions/mod.rs +6 -0
- package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
- package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
- package/packages/documents_batch/src/transitions/transfer/mod.rs +84 -0
- package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
- package/packages/enums/Cargo.toml +4 -4
- package/packages/enums/src/batch/batch_enum.rs +75 -10
- package/packages/enums/src/keys/key_type.rs +46 -0
- package/packages/enums/src/keys/purpose.rs +55 -0
- package/packages/enums/src/keys/security_level.rs +46 -0
- package/packages/enums/src/lib.rs +3 -0
- package/packages/enums/src/lock_types/mod.rs +65 -0
- package/packages/enums/src/network/mod.rs +67 -0
- package/packages/enums/src/platform/mod.rs +68 -8
- package/packages/enums/src/withdrawal/mod.rs +72 -0
- package/packages/identifier/Cargo.toml +9 -0
- package/packages/identifier/src/lib.rs +105 -0
- package/packages/identity/Cargo.toml +5 -5
- package/packages/identity/src/lib.rs +31 -25
- package/packages/{public_key → identity_public_key}/Cargo.toml +2 -2
- package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
- package/packages/identity_transitions/Cargo.toml +8 -4
- package/packages/identity_transitions/src/create_transition/mod.rs +102 -37
- package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
- package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
- package/packages/identity_transitions/src/lib.rs +6 -1
- package/packages/identity_transitions/src/public_key_in_creation/mod.rs +197 -0
- package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
- package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
- package/packages/mock_bls/Cargo.toml +1 -1
- package/packages/private_key/Cargo.toml +4 -3
- package/packages/private_key/src/lib.rs +44 -6
- package/packages/state_transition/Cargo.toml +6 -4
- package/packages/state_transition/src/lib.rs +102 -36
- package/packages/utils/Cargo.toml +3 -4
- package/packages/utils/src/lib.rs +17 -18
- package/scripts/build-js.sh +22 -5
- package/scripts/build.sh +27 -2
- package/src/lib.rs +8 -1
- package/tests/AssetLockProof.spec.js +80 -0
- package/tests/ChainLockProof.spec.js +69 -0
- package/tests/CoreScript.spec.js +37 -0
- package/tests/DataContract.spec.js +178 -0
- package/tests/DataContractCreateStateTransition.spec.js +109 -0
- package/tests/DataContractUpdateStateTransition.spec.js +109 -0
- package/tests/Document.spec.js +238 -0
- package/tests/DocumentBatchTransition.spec.js +109 -0
- package/tests/DocumentTransition.spec.js +97 -0
- package/tests/DocumentsTransitions.spec.js +705 -0
- package/tests/Identifier.spec.js +84 -0
- package/tests/Identity.spec.js +113 -0
- package/tests/IdentityCreateTransition.spec.js +93 -0
- package/tests/IdentityCreditTransferTransition.spec.js +146 -0
- package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
- package/tests/IdentityPublicKey.spec.js +132 -0
- package/tests/IdentityTopUpTransition.spec.js +131 -0
- package/tests/IdentityUpdateTransition.spec.js +147 -0
- package/tests/InstantLockProof.spec.js +97 -0
- package/tests/OutPoint.spec.js +55 -0
- package/tests/PrivateKey.spec.js +73 -0
- package/tests/PublicKeyInCreation.spec.js +258 -0
- package/tests/TxOut.spec.js +76 -0
- package/tests/mocks/DataContract/DataContract.json +153 -0
- package/tests/mocks/DataContract/index.js +6 -0
- package/tests/mocks/Document/DataContract.json +23 -0
- package/tests/mocks/Document/document.json +3 -0
- package/tests/mocks/Document/document2.json +3 -0
- package/tests/mocks/Document/index.js +11 -0
- package/tests/mocks/Identity/index.js +7 -0
- package/tests/mocks/Locks/index.js +5 -0
- package/tests/mocks/PrivateKey/index.js +5 -0
- package/tests/mocks/PublicKey/index.js +14 -0
- package/tests/utils/hex.js +15 -0
- package/tests/utils/wasm.js +14 -0
- package/typings/index.d.ts +52 -0
- package/packages/document/src/methods/js.rs +0 -260
- package/packages/document/src/methods/rust.rs +0 -92
- package/packages/document_batch/src/generators.rs +0 -63
- package/packages/document_batch/src/lib.rs +0 -228
- package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +0 -146
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
use dpp::platform_value::
|
|
4
|
-
use dpp::
|
|
1
|
+
use crate::public_key_in_creation::IdentityPublicKeyInCreationWASM;
|
|
2
|
+
use dpp::identity::state_transition::AssetLockProved;
|
|
3
|
+
use dpp::platform_value::BinaryData;
|
|
4
|
+
use dpp::prelude::UserFeeIncrease;
|
|
5
|
+
use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable};
|
|
5
6
|
use dpp::state_transition::identity_create_transition::IdentityCreateTransition;
|
|
6
7
|
use dpp::state_transition::identity_create_transition::accessors::IdentityCreateTransitionAccessorsV0;
|
|
8
|
+
use dpp::state_transition::identity_create_transition::v0::IdentityCreateTransitionV0;
|
|
9
|
+
use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation;
|
|
7
10
|
use dpp::state_transition::{StateTransition, StateTransitionLike};
|
|
8
|
-
use
|
|
11
|
+
use pshenmic_dpp_asset_lock_proof::AssetLockProofWASM;
|
|
12
|
+
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
13
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
9
14
|
use pshenmic_dpp_state_transition::StateTransitionWASM;
|
|
10
15
|
use pshenmic_dpp_utils::WithJsError;
|
|
11
|
-
use public_key_in_creation::IdentityPublicKeyInCreationWASM;
|
|
12
16
|
use wasm_bindgen::JsValue;
|
|
13
17
|
use wasm_bindgen::prelude::wasm_bindgen;
|
|
14
18
|
|
|
15
|
-
#[wasm_bindgen(js_name = IdentityCreateTransitionWASM)]
|
|
19
|
+
#[wasm_bindgen(js_name = "IdentityCreateTransitionWASM")]
|
|
16
20
|
#[derive(Clone)]
|
|
17
21
|
pub struct IdentityCreateTransitionWASM(IdentityCreateTransition);
|
|
18
22
|
|
|
@@ -31,16 +35,51 @@ impl From<IdentityCreateTransitionWASM> for IdentityCreateTransition {
|
|
|
31
35
|
#[wasm_bindgen]
|
|
32
36
|
impl IdentityCreateTransitionWASM {
|
|
33
37
|
#[wasm_bindgen(constructor)]
|
|
34
|
-
pub fn new(
|
|
35
|
-
|
|
36
|
-
|
|
38
|
+
pub fn new(
|
|
39
|
+
js_public_keys: &js_sys::Array,
|
|
40
|
+
asset_lock: &AssetLockProofWASM,
|
|
41
|
+
user_fee_increase: UserFeeIncrease,
|
|
42
|
+
signature: Option<Vec<u8>>,
|
|
43
|
+
js_identity_id: &JsValue,
|
|
44
|
+
) -> Result<IdentityCreateTransitionWASM, JsValue> {
|
|
45
|
+
let public_keys: Vec<IdentityPublicKeyInCreationWASM> =
|
|
46
|
+
IdentityPublicKeyInCreationWASM::vec_from_js_value(js_public_keys)?;
|
|
47
|
+
let identity_id = IdentifierWASM::try_from(js_identity_id)?;
|
|
48
|
+
|
|
49
|
+
Ok(IdentityCreateTransitionWASM(IdentityCreateTransition::V0(
|
|
50
|
+
IdentityCreateTransitionV0 {
|
|
51
|
+
public_keys: public_keys.iter().map(|key| key.clone().into()).collect(),
|
|
52
|
+
asset_lock_proof: asset_lock.clone().into(),
|
|
53
|
+
user_fee_increase,
|
|
54
|
+
signature: BinaryData::from(signature.unwrap_or(vec![])),
|
|
55
|
+
identity_id: identity_id.into(),
|
|
56
|
+
},
|
|
57
|
+
)))
|
|
58
|
+
}
|
|
37
59
|
|
|
38
|
-
|
|
60
|
+
#[wasm_bindgen(js_name = "default")]
|
|
61
|
+
pub fn default(js_platform_version: JsValue) -> Result<IdentityCreateTransitionWASM, JsValue> {
|
|
62
|
+
let platform_version = PlatformVersionWASM::try_from(js_platform_version)?;
|
|
63
|
+
|
|
64
|
+
IdentityCreateTransition::default_versioned(&platform_version.into())
|
|
39
65
|
.map(Into::into)
|
|
40
66
|
.map_err(|err| JsValue::from_str(&*err.to_string()))
|
|
41
67
|
}
|
|
42
68
|
|
|
43
|
-
#[wasm_bindgen(js_name = "
|
|
69
|
+
#[wasm_bindgen(js_name = "toBytes")]
|
|
70
|
+
pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
71
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
75
|
+
pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityCreateTransitionWASM, JsValue> {
|
|
76
|
+
let rs_transition =
|
|
77
|
+
IdentityCreateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?;
|
|
78
|
+
|
|
79
|
+
Ok(IdentityCreateTransitionWASM(rs_transition))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#[wasm_bindgen(getter = "publicKeys")]
|
|
44
83
|
pub fn get_public_keys(&self) -> Vec<IdentityPublicKeyInCreationWASM> {
|
|
45
84
|
self.0
|
|
46
85
|
.public_keys()
|
|
@@ -50,28 +89,63 @@ impl IdentityCreateTransitionWASM {
|
|
|
50
89
|
}
|
|
51
90
|
|
|
52
91
|
#[wasm_bindgen(js_name = "getIdentifier")]
|
|
53
|
-
pub fn get_identity_id(&self) ->
|
|
54
|
-
self.0.identity_id().
|
|
92
|
+
pub fn get_identity_id(&self) -> IdentifierWASM {
|
|
93
|
+
self.0.identity_id().into()
|
|
55
94
|
}
|
|
56
95
|
|
|
57
|
-
#[wasm_bindgen(
|
|
96
|
+
#[wasm_bindgen(getter = "userFeeIncrease")]
|
|
58
97
|
pub fn get_user_fee_increase(&self) -> u16 {
|
|
59
98
|
self.0.user_fee_increase()
|
|
60
99
|
}
|
|
61
100
|
|
|
62
|
-
#[wasm_bindgen(js_name = "
|
|
63
|
-
pub fn
|
|
64
|
-
|
|
101
|
+
#[wasm_bindgen(js_name = "getSignature")]
|
|
102
|
+
pub fn get_signature(&self) -> Vec<u8> {
|
|
103
|
+
self.0.signature().to_vec()
|
|
65
104
|
}
|
|
66
105
|
|
|
67
|
-
#[wasm_bindgen(js_name = "
|
|
68
|
-
pub fn
|
|
69
|
-
|
|
106
|
+
#[wasm_bindgen(js_name = "getSignableBytes")]
|
|
107
|
+
pub fn get_signable_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
108
|
+
self.0.signable_bytes().with_js_error()
|
|
109
|
+
}
|
|
70
110
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
111
|
+
#[wasm_bindgen(getter = "assetLock")]
|
|
112
|
+
pub fn get_asset_lock_proof(&self) -> AssetLockProofWASM {
|
|
113
|
+
AssetLockProofWASM::from(self.0.asset_lock_proof().clone())
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
#[wasm_bindgen(setter = "publicKeys")]
|
|
117
|
+
pub fn set_public_keys(&mut self, js_public_keys: &js_sys::Array) -> Result<(), JsValue> {
|
|
118
|
+
let public_keys: Vec<IdentityPublicKeyInCreationWASM> =
|
|
119
|
+
IdentityPublicKeyInCreationWASM::vec_from_js_value(js_public_keys)?;
|
|
120
|
+
|
|
121
|
+
self.0.set_public_keys(
|
|
122
|
+
public_keys
|
|
123
|
+
.iter()
|
|
124
|
+
.map(|key| IdentityPublicKeyInCreation::from(key.clone()))
|
|
125
|
+
.collect(),
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
Ok(())
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#[wasm_bindgen(setter = "userFeeIncrease")]
|
|
132
|
+
pub fn set_user_fee_increase(&mut self, amount: u16) {
|
|
133
|
+
self.0.set_user_fee_increase(amount)
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
#[wasm_bindgen(js_name = "setSignature")]
|
|
137
|
+
pub fn set_signature(&mut self, signature: Vec<u8>) {
|
|
138
|
+
self.0.set_signature_bytes(signature)
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
#[wasm_bindgen(setter = "assetLock")]
|
|
142
|
+
pub fn set_asset_lock_proof(&mut self, proof: AssetLockProofWASM) -> Result<(), JsValue> {
|
|
143
|
+
self.0.set_asset_lock_proof(proof.into()).with_js_error()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
#[wasm_bindgen(js_name = "toStateTransition")]
|
|
147
|
+
pub fn to_state_transition(&self) -> StateTransitionWASM {
|
|
148
|
+
StateTransitionWASM::from(StateTransition::IdentityCreate(self.clone().0))
|
|
75
149
|
}
|
|
76
150
|
|
|
77
151
|
#[wasm_bindgen(js_name = "fromStateTransition")]
|
|
@@ -82,18 +156,9 @@ impl IdentityCreateTransitionWASM {
|
|
|
82
156
|
|
|
83
157
|
match rs_st {
|
|
84
158
|
StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWASM(st)),
|
|
85
|
-
_ => Err(JsValue::from_str(
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
#[wasm_bindgen(js_name = "fromBytes")]
|
|
90
|
-
pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityCreateTransitionWASM, JsValue> {
|
|
91
|
-
let rs_transition =
|
|
92
|
-
IdentityCreateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error();
|
|
93
|
-
|
|
94
|
-
match rs_transition {
|
|
95
|
-
Ok(rs_st) => Ok(IdentityCreateTransitionWASM(rs_st)),
|
|
96
|
-
Err(err) => Err(err),
|
|
159
|
+
_ => Err(JsValue::from_str(
|
|
160
|
+
&"Invalid state document_transition type)",
|
|
161
|
+
)),
|
|
97
162
|
}
|
|
98
163
|
}
|
|
99
164
|
}
|
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
use dpp::identity::KeyID;
|
|
2
|
+
use dpp::identity::state_transition::OptionallyAssetLockProved;
|
|
3
|
+
use dpp::platform_value::Identifier;
|
|
4
|
+
use dpp::prelude::{IdentityNonce, UserFeeIncrease};
|
|
5
|
+
use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable};
|
|
6
|
+
use dpp::state_transition::identity_credit_withdrawal_transition::IdentityCreditWithdrawalTransition;
|
|
7
|
+
use dpp::state_transition::identity_credit_withdrawal_transition::accessors::IdentityCreditWithdrawalTransitionAccessorsV0;
|
|
8
|
+
use dpp::state_transition::identity_credit_withdrawal_transition::v0::IdentityCreditWithdrawalTransitionV0;
|
|
9
|
+
use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike};
|
|
10
|
+
use pshenmic_dpp_asset_lock_proof::AssetLockProofWASM;
|
|
11
|
+
use pshenmic_dpp_core_script::CoreScriptWASM;
|
|
12
|
+
use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
|
|
13
|
+
use pshenmic_dpp_enums::withdrawal::PoolingWASM;
|
|
14
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
15
|
+
use pshenmic_dpp_state_transition::StateTransitionWASM;
|
|
16
|
+
use pshenmic_dpp_utils::{IntoWasm, WithJsError};
|
|
17
|
+
use wasm_bindgen::JsValue;
|
|
18
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
19
|
+
|
|
20
|
+
#[wasm_bindgen(js_name = "IdentityCreditWithdrawalTransitionWASM")]
|
|
21
|
+
pub struct IdentityCreditWithdrawalTransitionWASM(IdentityCreditWithdrawalTransition);
|
|
22
|
+
|
|
23
|
+
#[wasm_bindgen]
|
|
24
|
+
impl IdentityCreditWithdrawalTransitionWASM {
|
|
25
|
+
#[wasm_bindgen(constructor)]
|
|
26
|
+
pub fn new(
|
|
27
|
+
js_identity_id: JsValue,
|
|
28
|
+
amount: u64,
|
|
29
|
+
core_fee_per_byte: u32,
|
|
30
|
+
js_pooling: JsValue,
|
|
31
|
+
output_script: &CoreScriptWASM,
|
|
32
|
+
nonce: Option<IdentityNonce>,
|
|
33
|
+
user_fee_increase: Option<UserFeeIncrease>,
|
|
34
|
+
) -> Result<IdentityCreditWithdrawalTransitionWASM, JsValue> {
|
|
35
|
+
let pooling = PoolingWASM::try_from(js_pooling)?;
|
|
36
|
+
let identity_id: Identifier = IdentifierWASM::try_from(js_identity_id)?.into();
|
|
37
|
+
|
|
38
|
+
Ok(IdentityCreditWithdrawalTransitionWASM(
|
|
39
|
+
IdentityCreditWithdrawalTransition::V0(IdentityCreditWithdrawalTransitionV0 {
|
|
40
|
+
identity_id,
|
|
41
|
+
amount,
|
|
42
|
+
core_fee_per_byte,
|
|
43
|
+
pooling: pooling.into(),
|
|
44
|
+
output_script: output_script.clone().into(),
|
|
45
|
+
nonce: nonce.unwrap_or(0),
|
|
46
|
+
user_fee_increase: user_fee_increase.unwrap_or(0),
|
|
47
|
+
signature_public_key_id: 0,
|
|
48
|
+
signature: Default::default(),
|
|
49
|
+
}),
|
|
50
|
+
))
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
#[wasm_bindgen(getter = "outputScript")]
|
|
54
|
+
pub fn get_output_script(&self) -> Option<CoreScriptWASM> {
|
|
55
|
+
match self.0.output_script() {
|
|
56
|
+
None => None,
|
|
57
|
+
Some(script) => Some(script.into()),
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#[wasm_bindgen(getter = "pooling")]
|
|
62
|
+
pub fn get_pooling(&self) -> String {
|
|
63
|
+
PoolingWASM::from(self.0.pooling()).into()
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#[wasm_bindgen(getter = "identityId")]
|
|
67
|
+
pub fn get_identity_id(&self) -> IdentifierWASM {
|
|
68
|
+
IdentifierWASM::from(self.0.identity_id())
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
#[wasm_bindgen(getter = "userFeeIncrease")]
|
|
72
|
+
pub fn get_user_fee_increase(&self) -> UserFeeIncrease {
|
|
73
|
+
self.0.user_fee_increase()
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[wasm_bindgen(getter = "nonce")]
|
|
77
|
+
pub fn get_nonce(&self) -> IdentityNonce {
|
|
78
|
+
self.0.nonce()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
#[wasm_bindgen(getter = "amount")]
|
|
82
|
+
pub fn get_amount(&self) -> u64 {
|
|
83
|
+
self.0.amount()
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
#[wasm_bindgen(js_name = "getPurposeRequirement")]
|
|
87
|
+
pub fn get_purpose_requirement(&self) -> Vec<String> {
|
|
88
|
+
self.0
|
|
89
|
+
.purpose_requirement()
|
|
90
|
+
.iter()
|
|
91
|
+
.map(|purpose| PurposeWASM::from(purpose.clone()).into())
|
|
92
|
+
.collect()
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
#[wasm_bindgen(js_name = "getModifiedDataIds")]
|
|
96
|
+
pub fn get_modified_data_ids(&self) -> Vec<IdentifierWASM> {
|
|
97
|
+
self.0
|
|
98
|
+
.modified_data_ids()
|
|
99
|
+
.iter()
|
|
100
|
+
.map(|id| id.clone().into())
|
|
101
|
+
.collect()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
#[wasm_bindgen(js_name = "getOptionalAssetLockProof")]
|
|
105
|
+
pub fn get_optional_asset_lock_proof(&self) -> JsValue {
|
|
106
|
+
match self.0.optional_asset_lock_proof() {
|
|
107
|
+
Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())),
|
|
108
|
+
None => JsValue::null(),
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#[wasm_bindgen(setter = "outputScript")]
|
|
113
|
+
pub fn set_output_script(&mut self, js_script: &JsValue) -> Result<(), JsValue> {
|
|
114
|
+
match js_script.is_undefined() {
|
|
115
|
+
true => self.0.set_output_script(None),
|
|
116
|
+
false => {
|
|
117
|
+
let script: CoreScriptWASM = js_script
|
|
118
|
+
.to_wasm::<CoreScriptWASM>("CoreScriptWASM")?
|
|
119
|
+
.clone();
|
|
120
|
+
self.0.set_output_script(Some(script.clone().into()))
|
|
121
|
+
}
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
Ok(())
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#[wasm_bindgen(setter = "pooling")]
|
|
128
|
+
pub fn set_pooling(&mut self, js_pooling: JsValue) -> Result<(), JsValue> {
|
|
129
|
+
let pooling: PoolingWASM = PoolingWASM::try_from(js_pooling)?;
|
|
130
|
+
Ok(self.0.set_pooling(pooling.into()))
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#[wasm_bindgen(setter = "identityId")]
|
|
134
|
+
pub fn set_identity_id(&mut self, js_identity_id: JsValue) -> Result<(), JsValue> {
|
|
135
|
+
let identity_id = IdentifierWASM::try_from(js_identity_id)?;
|
|
136
|
+
|
|
137
|
+
Ok(self.0.set_identity_id(identity_id.into()))
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
#[wasm_bindgen(setter = "userFeeIncrease")]
|
|
141
|
+
pub fn set_user_fee_increase(&mut self, user_fee_increase: UserFeeIncrease) {
|
|
142
|
+
self.0.set_user_fee_increase(user_fee_increase);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
#[wasm_bindgen(setter = "nonce")]
|
|
146
|
+
pub fn set_nonce(&mut self, nonce: IdentityNonce) {
|
|
147
|
+
self.0.set_nonce(nonce)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#[wasm_bindgen(setter = "amount")]
|
|
151
|
+
pub fn set_amount(&mut self, amount: u64) {
|
|
152
|
+
self.0.set_amount(amount)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
#[wasm_bindgen(getter = "signature")]
|
|
156
|
+
pub fn get_signature(&self) -> Vec<u8> {
|
|
157
|
+
self.0.signature().to_vec()
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
#[wasm_bindgen(js_name = "getSignableBytes")]
|
|
161
|
+
pub fn get_signable_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
162
|
+
self.0.signable_bytes().with_js_error()
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#[wasm_bindgen(getter = "signaturePublicKeyId")]
|
|
166
|
+
pub fn get_signature_public_key_id(&self) -> KeyID {
|
|
167
|
+
self.0.signature_public_key_id()
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
#[wasm_bindgen(setter = "signature")]
|
|
171
|
+
pub fn set_signature(&mut self, signature: Vec<u8>) {
|
|
172
|
+
self.0.set_signature_bytes(signature)
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#[wasm_bindgen(setter = "signaturePublicKeyId")]
|
|
176
|
+
pub fn set_signature_public_key_id(&mut self, signature_public_key_id: KeyID) {
|
|
177
|
+
self.0.set_signature_public_key_id(signature_public_key_id)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
#[wasm_bindgen(js_name = "toBytes")]
|
|
181
|
+
pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
182
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
186
|
+
pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityCreditWithdrawalTransitionWASM, JsValue> {
|
|
187
|
+
let rs_transition =
|
|
188
|
+
IdentityCreditWithdrawalTransition::deserialize_from_bytes(bytes.as_slice())
|
|
189
|
+
.with_js_error()?;
|
|
190
|
+
|
|
191
|
+
Ok(IdentityCreditWithdrawalTransitionWASM(rs_transition))
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
#[wasm_bindgen(js_name = "toStateTransition")]
|
|
195
|
+
pub fn to_state_transition(&self) -> StateTransitionWASM {
|
|
196
|
+
StateTransitionWASM::from(StateTransition::from(self.0.clone()))
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
#[wasm_bindgen(js_name = "fromStateTransition")]
|
|
200
|
+
pub fn from_state_transition(
|
|
201
|
+
st: StateTransitionWASM,
|
|
202
|
+
) -> Result<IdentityCreditWithdrawalTransitionWASM, JsValue> {
|
|
203
|
+
let rs_st: StateTransition = st.into();
|
|
204
|
+
|
|
205
|
+
match rs_st {
|
|
206
|
+
StateTransition::IdentityCreditWithdrawal(st) => {
|
|
207
|
+
Ok(IdentityCreditWithdrawalTransitionWASM(st))
|
|
208
|
+
}
|
|
209
|
+
_ => Err(JsValue::from_str(&"Invalid state transition type)")),
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
use dpp::platform_value::BinaryData;
|
|
2
|
+
use dpp::prelude::Identifier;
|
|
3
|
+
use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable};
|
|
4
|
+
use dpp::state_transition::identity_credit_transfer_transition::IdentityCreditTransferTransition;
|
|
5
|
+
use dpp::state_transition::identity_credit_transfer_transition::accessors::IdentityCreditTransferTransitionAccessorsV0;
|
|
6
|
+
use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike};
|
|
7
|
+
use pshenmic_dpp_enums::platform::PlatformVersionWASM;
|
|
8
|
+
use pshenmic_dpp_identifier::IdentifierWASM;
|
|
9
|
+
use pshenmic_dpp_state_transition::StateTransitionWASM;
|
|
10
|
+
use pshenmic_dpp_utils::WithJsError;
|
|
11
|
+
use wasm_bindgen::JsValue;
|
|
12
|
+
use wasm_bindgen::prelude::wasm_bindgen;
|
|
13
|
+
|
|
14
|
+
#[wasm_bindgen(js_name = IdentityCreditTransferWASM)]
|
|
15
|
+
#[derive(Clone)]
|
|
16
|
+
pub struct IdentityCreditTransferWASM(IdentityCreditTransferTransition);
|
|
17
|
+
|
|
18
|
+
#[wasm_bindgen]
|
|
19
|
+
impl IdentityCreditTransferWASM {
|
|
20
|
+
#[wasm_bindgen(constructor)]
|
|
21
|
+
pub fn new(
|
|
22
|
+
amount: u64,
|
|
23
|
+
js_sender: &JsValue,
|
|
24
|
+
js_recipient: &JsValue,
|
|
25
|
+
nonce: u64,
|
|
26
|
+
js_platform_version_wasm: &JsValue,
|
|
27
|
+
) -> Result<IdentityCreditTransferWASM, JsValue> {
|
|
28
|
+
let platform_version_wasm = match js_platform_version_wasm.is_undefined() {
|
|
29
|
+
true => PlatformVersionWASM::PLATFORM_V1,
|
|
30
|
+
false => PlatformVersionWASM::try_from(js_platform_version_wasm.clone())?,
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
let rs_transfer_transition_creation =
|
|
34
|
+
IdentityCreditTransferTransition::default_versioned(&platform_version_wasm.into())
|
|
35
|
+
.with_js_error();
|
|
36
|
+
|
|
37
|
+
let mut rs_transition = match rs_transfer_transition_creation {
|
|
38
|
+
Ok(rs_transition) => rs_transition,
|
|
39
|
+
Err(err) => wasm_bindgen::throw_val(err),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
let sender: Identifier = IdentifierWASM::try_from(js_sender)?.into();
|
|
43
|
+
|
|
44
|
+
let recipient: Identifier = IdentifierWASM::try_from(js_recipient)?.into();
|
|
45
|
+
|
|
46
|
+
rs_transition.set_recipient_id(recipient);
|
|
47
|
+
rs_transition.set_identity_id(sender);
|
|
48
|
+
rs_transition.set_amount(amount);
|
|
49
|
+
rs_transition.set_nonce(nonce);
|
|
50
|
+
|
|
51
|
+
Ok(IdentityCreditTransferWASM(rs_transition))
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
#[wasm_bindgen(js_name = "toBytes")]
|
|
55
|
+
pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
56
|
+
self.0.serialize_to_bytes().with_js_error()
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
#[wasm_bindgen(js_name = "fromBytes")]
|
|
60
|
+
pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityCreditTransferWASM, JsValue> {
|
|
61
|
+
let rs_transition =
|
|
62
|
+
IdentityCreditTransferTransition::deserialize_from_bytes(bytes.as_slice())
|
|
63
|
+
.with_js_error()?;
|
|
64
|
+
|
|
65
|
+
Ok(IdentityCreditTransferWASM(rs_transition))
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
#[wasm_bindgen(setter = "recipientId")]
|
|
69
|
+
pub fn set_recipient_id(&mut self, js_recipient: &JsValue) -> Result<(), JsValue> {
|
|
70
|
+
let recipient: Identifier = IdentifierWASM::try_from(js_recipient)?.into();
|
|
71
|
+
|
|
72
|
+
Ok(self.0.set_recipient_id(recipient))
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
#[wasm_bindgen(setter = "senderId")]
|
|
76
|
+
pub fn set_sender_id(&mut self, js_sender: &JsValue) -> Result<(), JsValue> {
|
|
77
|
+
let sender: Identifier = IdentifierWASM::try_from(js_sender)?.into();
|
|
78
|
+
|
|
79
|
+
Ok(self.0.set_identity_id(sender))
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
#[wasm_bindgen(setter = "amount")]
|
|
83
|
+
pub fn set_amount(&mut self, amount: u64) {
|
|
84
|
+
self.0.set_amount(amount)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
#[wasm_bindgen(setter = "nonce")]
|
|
88
|
+
pub fn set_nonce(&mut self, nonce: u64) {
|
|
89
|
+
self.0.set_nonce(nonce)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
#[wasm_bindgen(setter = "signature")]
|
|
93
|
+
pub fn set_signature(&mut self, signature: Vec<u8>) {
|
|
94
|
+
self.0.set_signature_bytes(signature)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
#[wasm_bindgen(setter = "signaturePublicKeyId")]
|
|
98
|
+
pub fn set_signature_public_key_id(&mut self, public_key_id: u32) {
|
|
99
|
+
self.0.set_signature_public_key_id(public_key_id)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
#[wasm_bindgen(setter = "userFeeIncrease")]
|
|
103
|
+
pub fn set_user_fee_increase(&mut self, amount: u16) {
|
|
104
|
+
self.0.set_user_fee_increase(amount)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
#[wasm_bindgen(getter = "signature")]
|
|
108
|
+
pub fn get_signature(&self) -> Vec<u8> {
|
|
109
|
+
self.0.signature().to_vec()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
#[wasm_bindgen(js_name = "getSignableBytes")]
|
|
113
|
+
pub fn get_signable_bytes(&self) -> Result<Vec<u8>, JsValue> {
|
|
114
|
+
self.0.signable_bytes().with_js_error()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
#[wasm_bindgen(getter = "signaturePublicKeyId")]
|
|
118
|
+
pub fn get_signature_public_key_id(&self) -> u32 {
|
|
119
|
+
self.0.signature_public_key_id()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
#[wasm_bindgen(getter = "userFeeIncrease")]
|
|
123
|
+
pub fn get_user_fee_increase(&self) -> u16 {
|
|
124
|
+
self.0.user_fee_increase()
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
#[wasm_bindgen(getter = "recipientId")]
|
|
128
|
+
pub fn get_recipient_id(&self) -> IdentifierWASM {
|
|
129
|
+
self.0.recipient_id().into()
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#[wasm_bindgen(getter = "senderId")]
|
|
133
|
+
pub fn get_identity_id(&self) -> IdentifierWASM {
|
|
134
|
+
self.0.identity_id().into()
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
#[wasm_bindgen(getter = "amount")]
|
|
138
|
+
pub fn get_amount(&self) -> u64 {
|
|
139
|
+
self.0.amount()
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
#[wasm_bindgen(getter = "nonce")]
|
|
143
|
+
pub fn get_nonce(&self) -> u64 {
|
|
144
|
+
self.0.nonce()
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
#[wasm_bindgen(js_name = "toStateTransition")]
|
|
148
|
+
pub fn to_state_transition(&self) -> StateTransitionWASM {
|
|
149
|
+
StateTransitionWASM::from(StateTransition::from(self.0.clone()))
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
#[wasm_bindgen(js_name = "fromStateTransition")]
|
|
153
|
+
pub fn from_state_transition(
|
|
154
|
+
st: StateTransitionWASM,
|
|
155
|
+
) -> Result<IdentityCreditTransferWASM, JsValue> {
|
|
156
|
+
let rs_st: StateTransition = st.into();
|
|
157
|
+
|
|
158
|
+
match rs_st {
|
|
159
|
+
StateTransition::IdentityCreditTransfer(st) => Ok(IdentityCreditTransferWASM(st)),
|
|
160
|
+
_ => Err(JsValue::from_str(&"Invalid state transition type)")),
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
impl IdentityCreditTransferWASM {
|
|
166
|
+
pub fn set_signature_binary_data(&mut self, data: BinaryData) {
|
|
167
|
+
self.0.set_signature(data)
|
|
168
|
+
}
|
|
169
|
+
}
|