pshenmic-dpp 1.0.5 → 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.
Files changed (118) hide show
  1. package/.github/workflows/build.yml +1 -1
  2. package/.github/workflows/publish.yml +1 -1
  3. package/Cargo.lock +147 -49
  4. package/Cargo.toml +13 -7
  5. package/README.md +10 -1
  6. package/dist/wasm/index.d.ts +52 -0
  7. package/dist/wasm/pshenmic_dpp.d.ts +962 -0
  8. package/dist/wasm/pshenmic_dpp.js +3342 -875
  9. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  10. package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
  11. package/docs/AssetLockProof.md +107 -0
  12. package/docs/Building.md +50 -0
  13. package/docs/ChainLockProof.md +63 -0
  14. package/docs/CoreScript.md +17 -0
  15. package/docs/DataContract.md +192 -0
  16. package/docs/DataContractCreateTransition.md +84 -0
  17. package/docs/DataContractUpdateTransition.md +84 -0
  18. package/docs/Document.md +396 -0
  19. package/docs/DocumentBaseTransition.md +111 -0
  20. package/docs/DocumentCreateTransition.md +132 -0
  21. package/docs/DocumentDeleteTransition.md +82 -0
  22. package/docs/DocumentPurchaseTransition.md +109 -0
  23. package/docs/DocumentReplaceTransition.md +112 -0
  24. package/docs/DocumentTransferTransition.md +96 -0
  25. package/docs/DocumentTransition.md +125 -0
  26. package/docs/DocumentUpdatePriceTransition.md +109 -0
  27. package/docs/DocumentsBatch.md +133 -0
  28. package/docs/Enums.md +103 -0
  29. package/docs/Home.md +28 -0
  30. package/docs/Identifier.md +37 -0
  31. package/docs/Identity.md +140 -0
  32. package/docs/IdentityCreateTransition.md +155 -0
  33. package/docs/IdentityCreditTransfer.md +187 -0
  34. package/docs/IdentityCreditWithdrawalTransition.md +244 -0
  35. package/docs/IdentityPublicKey.md +348 -0
  36. package/docs/IdentityPublicKeyInCreation.md +141 -0
  37. package/docs/IdentityTopUpTransition.md +166 -0
  38. package/docs/IdentityUpdateTransition.md +234 -0
  39. package/docs/InstantAssetLockProof.md +117 -0
  40. package/docs/InstantLock.md +100 -0
  41. package/docs/OutPoint.md +80 -0
  42. package/docs/PrefundedVotingBalance.md +48 -0
  43. package/docs/PrivateKey.md +112 -0
  44. package/docs/TxOut.md +93 -0
  45. package/package.json +3 -3
  46. package/packages/asset_lock_proof/Cargo.toml +19 -0
  47. package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
  48. package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
  49. package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
  50. package/packages/asset_lock_proof/src/lib.rs +133 -0
  51. package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
  52. package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
  53. package/packages/cbor_conversation/Cargo.toml +1 -1
  54. package/packages/core_script/Cargo.toml +13 -0
  55. package/packages/core_script/src/lib.rs +69 -0
  56. package/packages/data_contract/Cargo.toml +2 -1
  57. package/packages/data_contract/src/lib.rs +34 -30
  58. package/packages/data_contract_transitions/Cargo.toml +1 -1
  59. package/packages/data_contract_transitions/src/create/mod.rs +3 -3
  60. package/packages/data_contract_transitions/src/update/mod.rs +3 -3
  61. package/packages/document/Cargo.toml +2 -1
  62. package/packages/document/src/lib.rs +13 -12
  63. package/packages/document/src/methods/mod.rs +41 -38
  64. package/packages/documents_batch/Cargo.toml +2 -1
  65. package/packages/documents_batch/src/document_base_transition/mod.rs +16 -20
  66. package/packages/documents_batch/src/document_transition/mod.rs +9 -9
  67. package/packages/documents_batch/src/lib.rs +23 -16
  68. package/packages/documents_batch/src/transitions/create/mod.rs +5 -2
  69. package/packages/documents_batch/src/transitions/transfer/mod.rs +9 -11
  70. package/packages/enums/Cargo.toml +1 -1
  71. package/packages/enums/src/batch/batch_enum.rs +2 -2
  72. package/packages/enums/src/lib.rs +2 -0
  73. package/packages/enums/src/lock_types/mod.rs +65 -0
  74. package/packages/enums/src/platform/mod.rs +2 -0
  75. package/packages/enums/src/withdrawal/mod.rs +72 -0
  76. package/packages/identifier/Cargo.toml +9 -0
  77. package/packages/identifier/src/lib.rs +105 -0
  78. package/packages/identity/Cargo.toml +2 -1
  79. package/packages/identity/src/lib.rs +13 -18
  80. package/packages/identity_public_key/Cargo.toml +1 -1
  81. package/packages/identity_transitions/Cargo.toml +7 -3
  82. package/packages/identity_transitions/src/create_transition/mod.rs +99 -36
  83. package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
  84. package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
  85. package/packages/identity_transitions/src/lib.rs +6 -1
  86. package/packages/identity_transitions/src/{create_transition/public_key_in_creation → public_key_in_creation}/mod.rs +67 -20
  87. package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
  88. package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
  89. package/packages/private_key/Cargo.toml +1 -1
  90. package/packages/state_transition/Cargo.toml +2 -1
  91. package/packages/state_transition/src/lib.rs +3 -2
  92. package/packages/utils/Cargo.toml +2 -2
  93. package/packages/utils/src/lib.rs +0 -3
  94. package/scripts/build-js.sh +16 -0
  95. package/scripts/build.sh +5 -1
  96. package/src/lib.rs +1 -0
  97. package/tests/AssetLockProof.spec.js +80 -0
  98. package/tests/ChainLockProof.spec.js +69 -0
  99. package/tests/CoreScript.spec.js +37 -0
  100. package/tests/DataContract.spec.js +17 -14
  101. package/tests/Document.spec.js +14 -8
  102. package/tests/DocumentBatchTransition.spec.js +11 -11
  103. package/tests/DocumentTransition.spec.js +4 -4
  104. package/tests/DocumentsTransitions.spec.js +22 -22
  105. package/tests/Identifier.spec.js +84 -0
  106. package/tests/Identity.spec.js +1 -1
  107. package/tests/IdentityCreateTransition.spec.js +93 -0
  108. package/tests/IdentityCreditTransferTransition.spec.js +146 -0
  109. package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
  110. package/tests/IdentityTopUpTransition.spec.js +131 -0
  111. package/tests/IdentityUpdateTransition.spec.js +147 -0
  112. package/tests/InstantLockProof.spec.js +97 -0
  113. package/tests/OutPoint.spec.js +55 -0
  114. package/tests/PublicKeyInCreation.spec.js +258 -0
  115. package/tests/TxOut.spec.js +76 -0
  116. package/tests/mocks/Locks/index.js +5 -0
  117. package/tests/mocks/PublicKey/index.js +1 -1
  118. package/typings/index.d.ts +52 -0
@@ -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
+ }
@@ -1 +1,6 @@
1
- mod create_transition;
1
+ pub mod create_transition;
2
+ pub mod credit_withdrawal_transition;
3
+ pub mod identity_credit_transfer_transition;
4
+ pub mod public_key_in_creation;
5
+ pub mod top_up_transition;
6
+ pub mod update_transition;
@@ -11,9 +11,11 @@ use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
11
11
  use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
12
12
  use pshenmic_dpp_enums::keys::security_level::SecurityLevelWASM;
13
13
  use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
14
+ use pshenmic_dpp_utils::IntoWasm;
14
15
  use wasm_bindgen::JsValue;
15
16
  use wasm_bindgen::prelude::wasm_bindgen;
16
17
 
18
+ #[derive(Clone)]
17
19
  #[wasm_bindgen(js_name = "IdentityPublicKeyInCreationWASM")]
18
20
  pub struct IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation);
19
21
 
@@ -29,6 +31,16 @@ impl From<IdentityPublicKeyInCreationWASM> for IdentityPublicKeyInCreation {
29
31
  }
30
32
  }
31
33
 
34
+ impl TryFrom<JsValue> for IdentityPublicKeyInCreationWASM {
35
+ type Error = JsValue;
36
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
37
+ let value =
38
+ value.to_wasm::<IdentityPublicKeyInCreationWASM>("IdentityPublicKeyInCreationWASM")?;
39
+
40
+ Ok(value.clone())
41
+ }
42
+ }
43
+
32
44
  impl From<IdentityPublicKeyInCreationWASM> for IdentityPublicKey {
33
45
  fn from(value: IdentityPublicKeyInCreationWASM) -> Self {
34
46
  let contract_bounds = match value.0.contract_bounds() {
@@ -54,15 +66,19 @@ impl IdentityPublicKeyInCreationWASM {
54
66
  #[wasm_bindgen(constructor)]
55
67
  pub fn new(
56
68
  id: u32,
57
- purpose: PurposeWASM,
58
- security_level: SecurityLevelWASM,
59
- key_type: KeyTypeWASM,
69
+ js_purpose: JsValue,
70
+ js_security_level: JsValue,
71
+ js_key_type: JsValue,
60
72
  read_only: bool,
61
73
  binary_data: Vec<u8>,
62
74
  signature: Vec<u8>,
63
- ) -> IdentityPublicKeyInCreationWASM {
64
- IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation::V0(
65
- IdentityPublicKeyInCreationV0 {
75
+ ) -> Result<IdentityPublicKeyInCreationWASM, JsValue> {
76
+ let purpose = PurposeWASM::try_from(js_purpose)?;
77
+ let security_level = SecurityLevelWASM::try_from(js_security_level)?;
78
+ let key_type = KeyTypeWASM::try_from(js_key_type)?;
79
+
80
+ Ok(IdentityPublicKeyInCreationWASM(
81
+ IdentityPublicKeyInCreation::V0(IdentityPublicKeyInCreationV0 {
66
82
  id,
67
83
  key_type: KeyType::from(key_type),
68
84
  purpose: Purpose::from(purpose),
@@ -71,7 +87,7 @@ impl IdentityPublicKeyInCreationWASM {
71
87
  read_only,
72
88
  data: BinaryData::from(binary_data),
73
89
  signature: BinaryData::from(signature),
74
- },
90
+ }),
75
91
  ))
76
92
  }
77
93
 
@@ -88,48 +104,53 @@ impl IdentityPublicKeyInCreationWASM {
88
104
  )
89
105
  }
90
106
 
91
- #[wasm_bindgen(js_name = getKeyId)]
107
+ #[wasm_bindgen(getter = keyId)]
92
108
  pub fn get_key_id(&self) -> u32 {
93
109
  self.0.id()
94
110
  }
95
111
 
96
- #[wasm_bindgen(js_name = getPurpose)]
112
+ #[wasm_bindgen(getter = purpose)]
97
113
  pub fn get_purpose(&self) -> String {
98
114
  PurposeWASM::from(self.0.purpose()).into()
99
115
  }
100
116
 
101
- #[wasm_bindgen(js_name = getSecurityLevel)]
117
+ #[wasm_bindgen(getter = securityLevel)]
102
118
  pub fn get_security_level(&self) -> String {
103
119
  SecurityLevelWASM::from(self.0.security_level()).into()
104
120
  }
105
121
 
106
- #[wasm_bindgen(js_name = getKeyType)]
122
+ #[wasm_bindgen(getter = keyType)]
107
123
  pub fn get_key_type(&self) -> String {
108
124
  KeyTypeWASM::from(self.0.key_type()).into()
109
125
  }
110
126
 
111
- #[wasm_bindgen(js_name = getReadOnly)]
127
+ #[wasm_bindgen(getter = readOnly)]
112
128
  pub fn get_read_only(&self) -> bool {
113
129
  self.0.read_only()
114
130
  }
115
131
 
116
- #[wasm_bindgen(js_name = getData)]
117
- pub fn get_data(&self) -> String {
118
- self.0.data().to_string(Hex)
132
+ #[wasm_bindgen(getter = data)]
133
+ pub fn get_data(&self) -> Vec<u8> {
134
+ self.0.data().to_vec()
135
+ }
136
+
137
+ #[wasm_bindgen(getter = signature)]
138
+ pub fn get_signature(&self) -> Vec<u8> {
139
+ self.0.signature().to_vec()
119
140
  }
120
141
 
121
- #[wasm_bindgen(js_name = setKeyId)]
142
+ #[wasm_bindgen(setter = keyId)]
122
143
  pub fn set_key_id(&mut self, key_id: u32) {
123
144
  self.0.set_id(key_id)
124
145
  }
125
146
 
126
- #[wasm_bindgen(js_name = setPurpose)]
147
+ #[wasm_bindgen(setter = purpose)]
127
148
  pub fn set_purpose(&mut self, js_purpose: JsValue) -> Result<(), JsValue> {
128
149
  let purpose = PurposeWASM::try_from(js_purpose)?;
129
150
  Ok(self.0.set_purpose(Purpose::from(purpose)))
130
151
  }
131
152
 
132
- #[wasm_bindgen(js_name = setSecurityLevel)]
153
+ #[wasm_bindgen(setter = securityLevel)]
133
154
  pub fn set_security_level(&mut self, js_security_level: JsValue) -> Result<(), JsValue> {
134
155
  let security_level = SecurityLevelWASM::try_from(js_security_level)?;
135
156
  Ok(self
@@ -137,14 +158,40 @@ impl IdentityPublicKeyInCreationWASM {
137
158
  .set_security_level(SecurityLevel::from(security_level)))
138
159
  }
139
160
 
140
- #[wasm_bindgen(js_name = setReadOnly)]
161
+ #[wasm_bindgen(setter = keyType)]
162
+ pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> {
163
+ let key_type = KeyTypeWASM::try_from(key_type)?;
164
+ self.0.set_type(key_type.into());
165
+ Ok(())
166
+ }
167
+
168
+ #[wasm_bindgen(setter = readOnly)]
141
169
  pub fn set_read_only(&mut self, read_only: bool) {
142
170
  self.0.set_read_only(read_only)
143
171
  }
144
172
 
145
- #[wasm_bindgen(js_name = setData)]
173
+ #[wasm_bindgen(setter = data)]
146
174
  pub fn set_data(&mut self, binary_data: Vec<u8>) {
147
175
  let data = BinaryData::from(binary_data);
148
176
  self.0.set_data(data)
149
177
  }
178
+
179
+ #[wasm_bindgen(setter = signature)]
180
+ pub fn set_signature(&mut self, binary_data: Vec<u8>) {
181
+ let signature = BinaryData::from(binary_data);
182
+ self.0.set_signature(signature)
183
+ }
184
+ }
185
+
186
+ impl IdentityPublicKeyInCreationWASM {
187
+ pub fn vec_from_js_value(
188
+ js_add_public_keys: &js_sys::Array,
189
+ ) -> Result<Vec<IdentityPublicKeyInCreationWASM>, JsValue> {
190
+ let add_public_keys: Vec<IdentityPublicKeyInCreationWASM> = js_add_public_keys
191
+ .iter()
192
+ .map(|key| IdentityPublicKeyInCreationWASM::try_from(key))
193
+ .collect::<Result<Vec<IdentityPublicKeyInCreationWASM>, JsValue>>()?;
194
+
195
+ Ok(add_public_keys)
196
+ }
150
197
  }