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.
Files changed (152) hide show
  1. package/.github/workflows/build.yml +9 -1
  2. package/.github/workflows/publish.yml +9 -1
  3. package/Cargo.lock +222 -76
  4. package/Cargo.toml +28 -19
  5. package/README.md +75 -23
  6. package/babel.config.json +19 -0
  7. package/dist/wasm/index.d.ts +52 -0
  8. package/dist/wasm/pshenmic_dpp.d.ts +962 -0
  9. package/dist/wasm/pshenmic_dpp.js +5565 -966
  10. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  11. package/dist/wasm/pshenmic_dpp_bg.wasm.d.ts +440 -0
  12. package/docs/AssetLockProof.md +107 -0
  13. package/docs/Building.md +50 -0
  14. package/docs/ChainLockProof.md +63 -0
  15. package/docs/CoreScript.md +17 -0
  16. package/docs/DataContract.md +192 -0
  17. package/docs/DataContractCreateTransition.md +84 -0
  18. package/docs/DataContractUpdateTransition.md +84 -0
  19. package/docs/Document.md +396 -0
  20. package/docs/DocumentBaseTransition.md +111 -0
  21. package/docs/DocumentCreateTransition.md +132 -0
  22. package/docs/DocumentDeleteTransition.md +82 -0
  23. package/docs/DocumentPurchaseTransition.md +109 -0
  24. package/docs/DocumentReplaceTransition.md +112 -0
  25. package/docs/DocumentTransferTransition.md +96 -0
  26. package/docs/DocumentTransition.md +125 -0
  27. package/docs/DocumentUpdatePriceTransition.md +109 -0
  28. package/docs/DocumentsBatch.md +133 -0
  29. package/docs/Enums.md +103 -0
  30. package/docs/Home.md +28 -0
  31. package/docs/Identifier.md +37 -0
  32. package/docs/Identity.md +140 -0
  33. package/docs/IdentityCreateTransition.md +155 -0
  34. package/docs/IdentityCreditTransfer.md +187 -0
  35. package/docs/IdentityCreditWithdrawalTransition.md +244 -0
  36. package/docs/IdentityPublicKey.md +348 -0
  37. package/docs/IdentityPublicKeyInCreation.md +141 -0
  38. package/docs/IdentityTopUpTransition.md +166 -0
  39. package/docs/IdentityUpdateTransition.md +234 -0
  40. package/docs/InstantAssetLockProof.md +117 -0
  41. package/docs/InstantLock.md +100 -0
  42. package/docs/OutPoint.md +80 -0
  43. package/docs/PrefundedVotingBalance.md +48 -0
  44. package/docs/PrivateKey.md +112 -0
  45. package/docs/TxOut.md +93 -0
  46. package/package.json +15 -8
  47. package/packages/asset_lock_proof/Cargo.toml +19 -0
  48. package/packages/asset_lock_proof/src/chain/mod.rs +79 -0
  49. package/packages/asset_lock_proof/src/instant/instant_lock.rs +111 -0
  50. package/packages/asset_lock_proof/src/instant/mod.rs +115 -0
  51. package/packages/asset_lock_proof/src/lib.rs +133 -0
  52. package/packages/asset_lock_proof/src/outpoint/mod.rs +79 -0
  53. package/packages/asset_lock_proof/src/tx_out/mod.rs +80 -0
  54. package/packages/cbor_conversation/Cargo.toml +2 -2
  55. package/packages/core_script/Cargo.toml +13 -0
  56. package/packages/core_script/src/lib.rs +69 -0
  57. package/packages/data_contract/Cargo.toml +4 -3
  58. package/packages/data_contract/src/lib.rs +209 -33
  59. package/packages/data_contract_transitions/Cargo.toml +2 -2
  60. package/packages/data_contract_transitions/src/create/mod.rs +23 -16
  61. package/packages/data_contract_transitions/src/update/mod.rs +21 -12
  62. package/packages/document/Cargo.toml +3 -2
  63. package/packages/document/src/lib.rs +14 -13
  64. package/packages/document/src/methods/mod.rs +373 -2
  65. package/packages/{document_batch → documents_batch}/Cargo.toml +7 -4
  66. package/packages/documents_batch/src/document_base_transition/mod.rs +88 -0
  67. package/packages/documents_batch/src/document_transition/mod.rs +166 -0
  68. package/packages/documents_batch/src/generators.rs +122 -0
  69. package/packages/documents_batch/src/lib.rs +195 -0
  70. package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
  71. package/packages/documents_batch/src/transitions/create/mod.rs +126 -0
  72. package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
  73. package/packages/documents_batch/src/transitions/mod.rs +6 -0
  74. package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
  75. package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
  76. package/packages/documents_batch/src/transitions/transfer/mod.rs +84 -0
  77. package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
  78. package/packages/enums/Cargo.toml +4 -4
  79. package/packages/enums/src/batch/batch_enum.rs +75 -10
  80. package/packages/enums/src/keys/key_type.rs +46 -0
  81. package/packages/enums/src/keys/purpose.rs +55 -0
  82. package/packages/enums/src/keys/security_level.rs +46 -0
  83. package/packages/enums/src/lib.rs +3 -0
  84. package/packages/enums/src/lock_types/mod.rs +65 -0
  85. package/packages/enums/src/network/mod.rs +67 -0
  86. package/packages/enums/src/platform/mod.rs +68 -8
  87. package/packages/enums/src/withdrawal/mod.rs +72 -0
  88. package/packages/identifier/Cargo.toml +9 -0
  89. package/packages/identifier/src/lib.rs +105 -0
  90. package/packages/identity/Cargo.toml +5 -5
  91. package/packages/identity/src/lib.rs +31 -25
  92. package/packages/{public_key → identity_public_key}/Cargo.toml +2 -2
  93. package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
  94. package/packages/identity_transitions/Cargo.toml +8 -4
  95. package/packages/identity_transitions/src/create_transition/mod.rs +102 -37
  96. package/packages/identity_transitions/src/credit_withdrawal_transition/mod.rs +212 -0
  97. package/packages/identity_transitions/src/identity_credit_transfer_transition/mod.rs +169 -0
  98. package/packages/identity_transitions/src/lib.rs +6 -1
  99. package/packages/identity_transitions/src/public_key_in_creation/mod.rs +197 -0
  100. package/packages/identity_transitions/src/top_up_transition/mod.rs +141 -0
  101. package/packages/identity_transitions/src/update_transition/mod.rs +213 -0
  102. package/packages/mock_bls/Cargo.toml +1 -1
  103. package/packages/private_key/Cargo.toml +4 -3
  104. package/packages/private_key/src/lib.rs +44 -6
  105. package/packages/state_transition/Cargo.toml +6 -4
  106. package/packages/state_transition/src/lib.rs +102 -36
  107. package/packages/utils/Cargo.toml +3 -4
  108. package/packages/utils/src/lib.rs +17 -18
  109. package/scripts/build-js.sh +22 -5
  110. package/scripts/build.sh +27 -2
  111. package/src/lib.rs +8 -1
  112. package/tests/AssetLockProof.spec.js +80 -0
  113. package/tests/ChainLockProof.spec.js +69 -0
  114. package/tests/CoreScript.spec.js +37 -0
  115. package/tests/DataContract.spec.js +178 -0
  116. package/tests/DataContractCreateStateTransition.spec.js +109 -0
  117. package/tests/DataContractUpdateStateTransition.spec.js +109 -0
  118. package/tests/Document.spec.js +238 -0
  119. package/tests/DocumentBatchTransition.spec.js +109 -0
  120. package/tests/DocumentTransition.spec.js +97 -0
  121. package/tests/DocumentsTransitions.spec.js +705 -0
  122. package/tests/Identifier.spec.js +84 -0
  123. package/tests/Identity.spec.js +113 -0
  124. package/tests/IdentityCreateTransition.spec.js +93 -0
  125. package/tests/IdentityCreditTransferTransition.spec.js +146 -0
  126. package/tests/IdentityCreditWithdrawalTransition.spec.js +192 -0
  127. package/tests/IdentityPublicKey.spec.js +132 -0
  128. package/tests/IdentityTopUpTransition.spec.js +131 -0
  129. package/tests/IdentityUpdateTransition.spec.js +147 -0
  130. package/tests/InstantLockProof.spec.js +97 -0
  131. package/tests/OutPoint.spec.js +55 -0
  132. package/tests/PrivateKey.spec.js +73 -0
  133. package/tests/PublicKeyInCreation.spec.js +258 -0
  134. package/tests/TxOut.spec.js +76 -0
  135. package/tests/mocks/DataContract/DataContract.json +153 -0
  136. package/tests/mocks/DataContract/index.js +6 -0
  137. package/tests/mocks/Document/DataContract.json +23 -0
  138. package/tests/mocks/Document/document.json +3 -0
  139. package/tests/mocks/Document/document2.json +3 -0
  140. package/tests/mocks/Document/index.js +11 -0
  141. package/tests/mocks/Identity/index.js +7 -0
  142. package/tests/mocks/Locks/index.js +5 -0
  143. package/tests/mocks/PrivateKey/index.js +5 -0
  144. package/tests/mocks/PublicKey/index.js +14 -0
  145. package/tests/utils/hex.js +15 -0
  146. package/tests/utils/wasm.js +14 -0
  147. package/typings/index.d.ts +52 -0
  148. package/packages/document/src/methods/js.rs +0 -260
  149. package/packages/document/src/methods/rust.rs +0 -92
  150. package/packages/document_batch/src/generators.rs +0 -63
  151. package/packages/document_batch/src/lib.rs +0 -228
  152. package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +0 -146
@@ -0,0 +1,197 @@
1
+ use dpp::identity::identity_public_key::v0::IdentityPublicKeyV0;
2
+ use dpp::identity::{IdentityPublicKey, KeyType, Purpose, SecurityLevel};
3
+ use dpp::platform_value::BinaryData;
4
+ use dpp::platform_value::string_encoding::Encoding::Hex;
5
+ use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation;
6
+ use dpp::state_transition::public_key_in_creation::accessors::{
7
+ IdentityPublicKeyInCreationV0Getters, IdentityPublicKeyInCreationV0Setters,
8
+ };
9
+ use dpp::state_transition::public_key_in_creation::v0::IdentityPublicKeyInCreationV0;
10
+ use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
11
+ use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
12
+ use pshenmic_dpp_enums::keys::security_level::SecurityLevelWASM;
13
+ use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
14
+ use pshenmic_dpp_utils::IntoWasm;
15
+ use wasm_bindgen::JsValue;
16
+ use wasm_bindgen::prelude::wasm_bindgen;
17
+
18
+ #[derive(Clone)]
19
+ #[wasm_bindgen(js_name = "IdentityPublicKeyInCreationWASM")]
20
+ pub struct IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation);
21
+
22
+ impl From<IdentityPublicKeyInCreation> for IdentityPublicKeyInCreationWASM {
23
+ fn from(value: IdentityPublicKeyInCreation) -> Self {
24
+ IdentityPublicKeyInCreationWASM(value)
25
+ }
26
+ }
27
+
28
+ impl From<IdentityPublicKeyInCreationWASM> for IdentityPublicKeyInCreation {
29
+ fn from(value: IdentityPublicKeyInCreationWASM) -> Self {
30
+ value.0
31
+ }
32
+ }
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
+
44
+ impl From<IdentityPublicKeyInCreationWASM> for IdentityPublicKey {
45
+ fn from(value: IdentityPublicKeyInCreationWASM) -> Self {
46
+ let contract_bounds = match value.0.contract_bounds() {
47
+ None => None,
48
+ Some(bounds) => Some(bounds.clone()),
49
+ };
50
+
51
+ IdentityPublicKey::V0(IdentityPublicKeyV0 {
52
+ id: value.0.id(),
53
+ purpose: value.0.purpose(),
54
+ security_level: value.0.security_level(),
55
+ contract_bounds,
56
+ key_type: value.0.key_type(),
57
+ read_only: value.0.read_only(),
58
+ data: value.0.data().clone(),
59
+ disabled_at: None,
60
+ })
61
+ }
62
+ }
63
+
64
+ #[wasm_bindgen]
65
+ impl IdentityPublicKeyInCreationWASM {
66
+ #[wasm_bindgen(constructor)]
67
+ pub fn new(
68
+ id: u32,
69
+ js_purpose: JsValue,
70
+ js_security_level: JsValue,
71
+ js_key_type: JsValue,
72
+ read_only: bool,
73
+ binary_data: Vec<u8>,
74
+ signature: Vec<u8>,
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 {
82
+ id,
83
+ key_type: KeyType::from(key_type),
84
+ purpose: Purpose::from(purpose),
85
+ security_level: SecurityLevel::from(security_level),
86
+ contract_bounds: None,
87
+ read_only,
88
+ data: BinaryData::from(binary_data),
89
+ signature: BinaryData::from(signature),
90
+ }),
91
+ ))
92
+ }
93
+
94
+ #[wasm_bindgen(js_name = toIdentityPublicKey)]
95
+ pub fn to_identity_public_key(&self) -> Result<IdentityPublicKeyWASM, JsValue> {
96
+ IdentityPublicKeyWASM::new(
97
+ self.0.id(),
98
+ JsValue::from(PurposeWASM::from(self.0.purpose())),
99
+ JsValue::from(SecurityLevelWASM::from(self.0.security_level())),
100
+ JsValue::from(KeyTypeWASM::from(self.0.key_type())),
101
+ self.0.read_only(),
102
+ self.0.data().to_string(Hex).as_str(),
103
+ None,
104
+ )
105
+ }
106
+
107
+ #[wasm_bindgen(getter = keyId)]
108
+ pub fn get_key_id(&self) -> u32 {
109
+ self.0.id()
110
+ }
111
+
112
+ #[wasm_bindgen(getter = purpose)]
113
+ pub fn get_purpose(&self) -> String {
114
+ PurposeWASM::from(self.0.purpose()).into()
115
+ }
116
+
117
+ #[wasm_bindgen(getter = securityLevel)]
118
+ pub fn get_security_level(&self) -> String {
119
+ SecurityLevelWASM::from(self.0.security_level()).into()
120
+ }
121
+
122
+ #[wasm_bindgen(getter = keyType)]
123
+ pub fn get_key_type(&self) -> String {
124
+ KeyTypeWASM::from(self.0.key_type()).into()
125
+ }
126
+
127
+ #[wasm_bindgen(getter = readOnly)]
128
+ pub fn get_read_only(&self) -> bool {
129
+ self.0.read_only()
130
+ }
131
+
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()
140
+ }
141
+
142
+ #[wasm_bindgen(setter = keyId)]
143
+ pub fn set_key_id(&mut self, key_id: u32) {
144
+ self.0.set_id(key_id)
145
+ }
146
+
147
+ #[wasm_bindgen(setter = purpose)]
148
+ pub fn set_purpose(&mut self, js_purpose: JsValue) -> Result<(), JsValue> {
149
+ let purpose = PurposeWASM::try_from(js_purpose)?;
150
+ Ok(self.0.set_purpose(Purpose::from(purpose)))
151
+ }
152
+
153
+ #[wasm_bindgen(setter = securityLevel)]
154
+ pub fn set_security_level(&mut self, js_security_level: JsValue) -> Result<(), JsValue> {
155
+ let security_level = SecurityLevelWASM::try_from(js_security_level)?;
156
+ Ok(self
157
+ .0
158
+ .set_security_level(SecurityLevel::from(security_level)))
159
+ }
160
+
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)]
169
+ pub fn set_read_only(&mut self, read_only: bool) {
170
+ self.0.set_read_only(read_only)
171
+ }
172
+
173
+ #[wasm_bindgen(setter = data)]
174
+ pub fn set_data(&mut self, binary_data: Vec<u8>) {
175
+ let data = BinaryData::from(binary_data);
176
+ self.0.set_data(data)
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
+ }
197
+ }
@@ -0,0 +1,141 @@
1
+ use dpp::identifier::Identifier;
2
+ use dpp::identity::state_transition::{AssetLockProved, OptionallyAssetLockProved};
3
+ use dpp::prelude::UserFeeIncrease;
4
+ use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable};
5
+ use dpp::state_transition::identity_topup_transition::IdentityTopUpTransition;
6
+ use dpp::state_transition::identity_topup_transition::accessors::IdentityTopUpTransitionAccessorsV0;
7
+ use dpp::state_transition::identity_topup_transition::v0::IdentityTopUpTransitionV0;
8
+ use dpp::state_transition::{StateTransition, StateTransitionLike};
9
+ use pshenmic_dpp_asset_lock_proof::AssetLockProofWASM;
10
+ use pshenmic_dpp_identifier::IdentifierWASM;
11
+ use pshenmic_dpp_state_transition::StateTransitionWASM;
12
+ use pshenmic_dpp_utils::WithJsError;
13
+ use wasm_bindgen::JsValue;
14
+ use wasm_bindgen::prelude::wasm_bindgen;
15
+
16
+ #[wasm_bindgen(js_name = "IdentityTopUpTransitionWASM")]
17
+ #[derive(Clone)]
18
+ pub struct IdentityTopUpTransitionWASM(IdentityTopUpTransition);
19
+
20
+ #[wasm_bindgen]
21
+ impl IdentityTopUpTransitionWASM {
22
+ #[wasm_bindgen(constructor)]
23
+ pub fn new(
24
+ asset_lock_proof: &AssetLockProofWASM,
25
+ js_identity_id: JsValue,
26
+ user_fee_increase: UserFeeIncrease,
27
+ ) -> Result<IdentityTopUpTransitionWASM, JsValue> {
28
+ let identity_id: Identifier = IdentifierWASM::try_from(js_identity_id)?.into();
29
+
30
+ Ok(IdentityTopUpTransitionWASM(IdentityTopUpTransition::V0(
31
+ IdentityTopUpTransitionV0 {
32
+ asset_lock_proof: asset_lock_proof.clone().into(),
33
+ identity_id,
34
+ user_fee_increase,
35
+ signature: Default::default(),
36
+ },
37
+ )))
38
+ }
39
+
40
+ #[wasm_bindgen(js_name = "getModifiedDataIds")]
41
+ pub fn get_modified_data_ids(&self) -> Vec<IdentifierWASM> {
42
+ self.0
43
+ .modified_data_ids()
44
+ .iter()
45
+ .map(|id| id.clone().into())
46
+ .collect()
47
+ }
48
+
49
+ #[wasm_bindgen(js_name = "getOptionalAssetLockProof")]
50
+ pub fn get_optional_asset_lock_proof(&self) -> JsValue {
51
+ match self.0.optional_asset_lock_proof() {
52
+ Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())),
53
+ None => JsValue::null(),
54
+ }
55
+ }
56
+
57
+ #[wasm_bindgen(getter = "userFeeIncrease")]
58
+ pub fn get_user_fee_increase(&self) -> UserFeeIncrease {
59
+ self.0.user_fee_increase()
60
+ }
61
+
62
+ #[wasm_bindgen(getter = "identityIdentifier")]
63
+ pub fn get_identity_identifier(&self) -> IdentifierWASM {
64
+ self.0.identity_id().clone().into()
65
+ }
66
+
67
+ #[wasm_bindgen(getter = "assetLockProof")]
68
+ pub fn get_asset_lock_proof(&self) -> AssetLockProofWASM {
69
+ self.0.asset_lock_proof().clone().into()
70
+ }
71
+
72
+ #[wasm_bindgen(setter = "userFeeIncrease")]
73
+ pub fn set_user_fee_increase(&mut self, user_fee_increase: UserFeeIncrease) {
74
+ self.0.set_user_fee_increase(user_fee_increase);
75
+ }
76
+
77
+ #[wasm_bindgen(setter = "identityIdentifier")]
78
+ pub fn set_identity_identifier(
79
+ &mut self,
80
+ js_identity_identifier: &JsValue,
81
+ ) -> Result<(), JsValue> {
82
+ let identity_identifier: Identifier =
83
+ IdentifierWASM::try_from(js_identity_identifier)?.into();
84
+ Ok(self.0.set_identity_id(identity_identifier.clone().into()))
85
+ }
86
+
87
+ #[wasm_bindgen(setter = "assetLockProof")]
88
+ pub fn set_asset_lock_proof(
89
+ &mut self,
90
+ asset_lock_proof: &AssetLockProofWASM,
91
+ ) -> Result<(), JsValue> {
92
+ self.0
93
+ .set_asset_lock_proof(asset_lock_proof.clone().into())
94
+ .with_js_error()
95
+ }
96
+
97
+ #[wasm_bindgen(getter = "signature")]
98
+ pub fn get_signature(&self) -> Vec<u8> {
99
+ self.0.signature().to_vec()
100
+ }
101
+
102
+ #[wasm_bindgen(js_name = "getSignableBytes")]
103
+ pub fn get_signable_bytes(&self) -> Result<Vec<u8>, JsValue> {
104
+ self.0.signable_bytes().with_js_error()
105
+ }
106
+
107
+ #[wasm_bindgen(setter = "signature")]
108
+ pub fn set_signature(&mut self, signature: Vec<u8>) {
109
+ self.0.set_signature_bytes(signature)
110
+ }
111
+
112
+ #[wasm_bindgen(js_name = "toBytes")]
113
+ pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
114
+ self.0.serialize_to_bytes().with_js_error()
115
+ }
116
+
117
+ #[wasm_bindgen(js_name = "fromBytes")]
118
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityTopUpTransitionWASM, JsValue> {
119
+ let rs_transition =
120
+ IdentityTopUpTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?;
121
+
122
+ Ok(IdentityTopUpTransitionWASM(rs_transition))
123
+ }
124
+
125
+ #[wasm_bindgen(js_name = "toStateTransition")]
126
+ pub fn to_state_transition(&self) -> StateTransitionWASM {
127
+ StateTransitionWASM::from(StateTransition::from(self.0.clone()))
128
+ }
129
+
130
+ #[wasm_bindgen(js_name = "fromStateTransition")]
131
+ pub fn from_state_transition(
132
+ st: StateTransitionWASM,
133
+ ) -> Result<IdentityTopUpTransitionWASM, JsValue> {
134
+ let rs_st: StateTransition = st.into();
135
+
136
+ match rs_st {
137
+ StateTransition::IdentityTopUp(st) => Ok(IdentityTopUpTransitionWASM(st)),
138
+ _ => Err(JsValue::from_str(&"Invalid state transition type)")),
139
+ }
140
+ }
141
+ }
@@ -0,0 +1,213 @@
1
+ use crate::public_key_in_creation::IdentityPublicKeyInCreationWASM;
2
+ use dpp::identity::KeyID;
3
+ use dpp::identity::state_transition::OptionallyAssetLockProved;
4
+ use dpp::prelude::{IdentityNonce, Revision, UserFeeIncrease};
5
+ use dpp::serialization::{PlatformDeserializable, PlatformSerializable, Signable};
6
+ use dpp::state_transition::identity_update_transition::IdentityUpdateTransition;
7
+ use dpp::state_transition::identity_update_transition::accessors::IdentityUpdateTransitionAccessorsV0;
8
+ use dpp::state_transition::identity_update_transition::v0::IdentityUpdateTransitionV0;
9
+ use dpp::state_transition::public_key_in_creation::IdentityPublicKeyInCreation;
10
+ use dpp::state_transition::{StateTransition, StateTransitionIdentitySigned, StateTransitionLike};
11
+ use pshenmic_dpp_asset_lock_proof::AssetLockProofWASM;
12
+ use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
13
+ use pshenmic_dpp_identifier::IdentifierWASM;
14
+ use pshenmic_dpp_state_transition::StateTransitionWASM;
15
+ use pshenmic_dpp_utils::WithJsError;
16
+ use wasm_bindgen::JsValue;
17
+ use wasm_bindgen::prelude::wasm_bindgen;
18
+
19
+ #[wasm_bindgen(js_name = "IdentityUpdateTransitionWASM")]
20
+ #[derive(Clone)]
21
+ pub struct IdentityUpdateTransitionWASM(IdentityUpdateTransition);
22
+
23
+ #[wasm_bindgen]
24
+ impl IdentityUpdateTransitionWASM {
25
+ #[wasm_bindgen(constructor)]
26
+ pub fn new(
27
+ js_identity_id: &JsValue,
28
+ revision: Revision,
29
+ nonce: IdentityNonce,
30
+ user_fee_increase: Option<UserFeeIncrease>,
31
+ js_add_public_keys: &js_sys::Array,
32
+ disable_public_keys: Vec<KeyID>,
33
+ ) -> Result<IdentityUpdateTransitionWASM, JsValue> {
34
+ let identity_id = IdentifierWASM::try_from(js_identity_id)?;
35
+
36
+ let add_public_keys: Vec<IdentityPublicKeyInCreationWASM> =
37
+ IdentityPublicKeyInCreationWASM::vec_from_js_value(js_add_public_keys)?;
38
+
39
+ Ok(IdentityUpdateTransitionWASM(IdentityUpdateTransition::V0(
40
+ IdentityUpdateTransitionV0 {
41
+ identity_id: identity_id.into(),
42
+ revision,
43
+ nonce,
44
+ add_public_keys: add_public_keys
45
+ .clone()
46
+ .iter()
47
+ .map(|key| key.clone().into())
48
+ .collect(),
49
+ disable_public_keys,
50
+ user_fee_increase: user_fee_increase.unwrap_or(0),
51
+ signature_public_key_id: 0,
52
+ signature: Default::default(),
53
+ },
54
+ )))
55
+ }
56
+
57
+ #[wasm_bindgen(getter = "revision")]
58
+ pub fn get_revision(&self) -> Revision {
59
+ self.0.revision()
60
+ }
61
+
62
+ #[wasm_bindgen(getter = "nonce")]
63
+ pub fn get_nonce(&self) -> IdentityNonce {
64
+ self.0.nonce()
65
+ }
66
+
67
+ #[wasm_bindgen(getter = "identityIdentifier")]
68
+ pub fn get_identity_identifier(&self) -> IdentifierWASM {
69
+ self.0.identity_id().into()
70
+ }
71
+
72
+ #[wasm_bindgen(js_name = "getPurposeRequirement")]
73
+ pub fn get_purpose_requirement(&self) -> Vec<String> {
74
+ self.0
75
+ .purpose_requirement()
76
+ .iter()
77
+ .map(|purpose| PurposeWASM::from(purpose.clone()).into())
78
+ .collect()
79
+ }
80
+
81
+ #[wasm_bindgen(js_name = "getModifiedDataIds")]
82
+ pub fn get_modified_data_ids(&self) -> Vec<IdentifierWASM> {
83
+ self.0
84
+ .modified_data_ids()
85
+ .iter()
86
+ .map(|id| id.clone().into())
87
+ .collect()
88
+ }
89
+
90
+ #[wasm_bindgen(js_name = "getOptionalAssetLockProof")]
91
+ pub fn get_optional_asset_lock_proof(&self) -> JsValue {
92
+ match self.0.optional_asset_lock_proof() {
93
+ Some(asset_lock) => JsValue::from(AssetLockProofWASM::from(asset_lock.clone())),
94
+ None => JsValue::null(),
95
+ }
96
+ }
97
+
98
+ #[wasm_bindgen(getter = "publicKeyIdsToDisable")]
99
+ pub fn get_public_key_ids_to_disable(&self) -> Vec<KeyID> {
100
+ self.0.public_key_ids_to_disable().to_vec()
101
+ }
102
+
103
+ #[wasm_bindgen(getter = "publicKeyIdsToAdd")]
104
+ pub fn get_public_key_ids_to_add(&self) -> Vec<IdentityPublicKeyInCreationWASM> {
105
+ self.0
106
+ .public_keys_to_add()
107
+ .to_vec()
108
+ .iter()
109
+ .map(|id| id.clone().into())
110
+ .collect()
111
+ }
112
+
113
+ #[wasm_bindgen(getter = "userFeeIncrease")]
114
+ pub fn get_user_fee_increase(&self) -> UserFeeIncrease {
115
+ self.0.user_fee_increase()
116
+ }
117
+
118
+ #[wasm_bindgen(setter = "revision")]
119
+ pub fn set_revision(&mut self, revision: Revision) {
120
+ self.0.set_revision(revision);
121
+ }
122
+
123
+ #[wasm_bindgen(setter = "nonce")]
124
+ pub fn set_nonce(&mut self, nonce: IdentityNonce) {
125
+ self.0.set_nonce(nonce);
126
+ }
127
+
128
+ #[wasm_bindgen(setter = "identityIdentifier")]
129
+ pub fn set_identity_identifier(&mut self, js_identity_id: &JsValue) -> Result<(), JsValue> {
130
+ let identity_id = IdentifierWASM::try_from(js_identity_id)?;
131
+ self.0.set_identity_id(identity_id.clone().into());
132
+ Ok(())
133
+ }
134
+
135
+ #[wasm_bindgen(setter = "publicKeyIdsToAdd")]
136
+ pub fn set_public_key_ids_to_add(
137
+ &mut self,
138
+ js_add_public_keys: &js_sys::Array,
139
+ ) -> Result<(), JsValue> {
140
+ let add_public_keys: Vec<IdentityPublicKeyInCreationWASM> =
141
+ IdentityPublicKeyInCreationWASM::vec_from_js_value(js_add_public_keys)?;
142
+
143
+ let keys: Vec<IdentityPublicKeyInCreation> =
144
+ add_public_keys.iter().map(|id| id.clone().into()).collect();
145
+
146
+ Ok(self.0.set_public_keys_to_add(keys))
147
+ }
148
+
149
+ #[wasm_bindgen(setter = "publicKeyIdsToDisable")]
150
+ pub fn set_public_key_ids_to_disable(&mut self, public_keys: Vec<KeyID>) {
151
+ self.0.set_public_key_ids_to_disable(public_keys)
152
+ }
153
+
154
+ #[wasm_bindgen(setter = "userFeeIncrease")]
155
+ pub fn set_user_fee_increase(&mut self, user_fee_increase: UserFeeIncrease) {
156
+ self.0.set_user_fee_increase(user_fee_increase)
157
+ }
158
+
159
+ #[wasm_bindgen(getter = "signature")]
160
+ pub fn get_signature(&self) -> Vec<u8> {
161
+ self.0.signature().to_vec()
162
+ }
163
+
164
+ #[wasm_bindgen(js_name = "getSignableBytes")]
165
+ pub fn get_signable_bytes(&self) -> Result<Vec<u8>, JsValue> {
166
+ self.0.signable_bytes().with_js_error()
167
+ }
168
+
169
+ #[wasm_bindgen(getter = "signaturePublicKeyId")]
170
+ pub fn get_signature_public_key_id(&self) -> KeyID {
171
+ self.0.signature_public_key_id()
172
+ }
173
+
174
+ #[wasm_bindgen(setter = "signature")]
175
+ pub fn set_signature(&mut self, signature: Vec<u8>) {
176
+ self.0.set_signature_bytes(signature)
177
+ }
178
+
179
+ #[wasm_bindgen(setter = "signaturePublicKeyId")]
180
+ pub fn set_signature_public_key_id(&mut self, signature_public_key_id: KeyID) {
181
+ self.0.set_signature_public_key_id(signature_public_key_id)
182
+ }
183
+
184
+ #[wasm_bindgen(js_name = "toBytes")]
185
+ pub fn to_bytes(&self) -> Result<Vec<u8>, JsValue> {
186
+ self.0.serialize_to_bytes().with_js_error()
187
+ }
188
+
189
+ #[wasm_bindgen(js_name = "fromBytes")]
190
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentityUpdateTransitionWASM, JsValue> {
191
+ let rs_transition =
192
+ IdentityUpdateTransition::deserialize_from_bytes(bytes.as_slice()).with_js_error()?;
193
+
194
+ Ok(IdentityUpdateTransitionWASM(rs_transition))
195
+ }
196
+
197
+ #[wasm_bindgen(js_name = "toStateTransition")]
198
+ pub fn to_state_transition(&self) -> StateTransitionWASM {
199
+ StateTransitionWASM::from(StateTransition::from(self.0.clone()))
200
+ }
201
+
202
+ #[wasm_bindgen(js_name = "fromStateTransition")]
203
+ pub fn from_state_transition(
204
+ st: StateTransitionWASM,
205
+ ) -> Result<IdentityUpdateTransitionWASM, JsValue> {
206
+ let rs_st: StateTransition = st.into();
207
+
208
+ match rs_st {
209
+ StateTransition::IdentityUpdate(st) => Ok(IdentityUpdateTransitionWASM(st)),
210
+ _ => Err(JsValue::from_str(&"Invalid state transition type)")),
211
+ }
212
+ }
213
+ }
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_mock_bls"
3
- version = "0.1.0"
3
+ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
@@ -1,13 +1,14 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_private_key"
3
- version = "0.1.0"
3
+ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
7
7
  crate-type = ["cdylib", "lib"]
8
8
 
9
9
  [dependencies]
10
- wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
10
+ wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
11
11
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
12
  "identity-value-conversion",
13
- ]}
13
+ ]}
14
+ pshenmic_dpp_enums = {path = "../enums"}
@@ -1,4 +1,8 @@
1
1
  use dpp::dashcore::PrivateKey;
2
+ use dpp::dashcore::hashes::hex::FromHex;
3
+ use dpp::dashcore::key::Secp256k1;
4
+ use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex};
5
+ use pshenmic_dpp_enums::network::NetworkWASM;
2
6
  use wasm_bindgen::JsValue;
3
7
  use wasm_bindgen::prelude::wasm_bindgen;
4
8
 
@@ -7,8 +11,8 @@ pub struct PrivateKeyWASM(PrivateKey);
7
11
 
8
12
  #[wasm_bindgen]
9
13
  impl PrivateKeyWASM {
10
- #[wasm_bindgen(constructor)]
11
- pub fn new(wif: &str) -> Result<Self, JsValue> {
14
+ #[wasm_bindgen(js_name = "fromWIF")]
15
+ pub fn from_wif(wif: &str) -> Result<Self, JsValue> {
12
16
  let pk = PrivateKey::from_wif(wif).map_err(|err| JsValue::from_str(&*err.to_string()));
13
17
 
14
18
  match pk {
@@ -16,17 +20,51 @@ impl PrivateKeyWASM {
16
20
  Err(err) => Err(err),
17
21
  }
18
22
  }
23
+
24
+ #[wasm_bindgen(js_name = "fromBytes")]
25
+ pub fn from_bytes(bytes: Vec<u8>, js_network: JsValue) -> Result<Self, JsValue> {
26
+ let network = NetworkWASM::try_from(js_network)?;
27
+
28
+ let pk = PrivateKey::from_slice(bytes.as_slice(), network.into())
29
+ .map_err(|err| JsValue::from_str(&*err.to_string()))?;
30
+
31
+ Ok(PrivateKeyWASM(pk))
32
+ }
33
+
34
+ #[wasm_bindgen(js_name = "fromHex")]
35
+ pub fn from_hex(hex_key: &str, js_network: JsValue) -> Result<Self, JsValue> {
36
+ let network = NetworkWASM::try_from(js_network)?;
37
+
38
+ let bytes = Vec::from_hex(hex_key).map_err(|err| JsValue::from(err.to_string()))?;
39
+
40
+ let pk = PrivateKey::from_slice(bytes.as_slice(), network.into())
41
+ .map_err(|err| JsValue::from_str(&*err.to_string()))?;
42
+
43
+ Ok(PrivateKeyWASM(pk))
44
+ }
19
45
  }
20
46
 
21
47
  #[wasm_bindgen]
22
48
  impl PrivateKeyWASM {
23
- #[wasm_bindgen(js_name = "getKeyWIF")]
24
- pub fn get_key_wif(&self) -> String {
49
+ #[wasm_bindgen(js_name = "getWIF")]
50
+ pub fn get_wif(&self) -> String {
25
51
  self.0.to_wif()
26
52
  }
27
53
 
28
- #[wasm_bindgen(js_name = "getKeyBytes")]
29
- pub fn get_key_bytes(&self) -> Vec<u8> {
54
+ #[wasm_bindgen(js_name = "getBytes")]
55
+ pub fn get_bytes(&self) -> Vec<u8> {
30
56
  self.0.to_bytes()
31
57
  }
58
+
59
+ #[wasm_bindgen(js_name = "getHex")]
60
+ pub fn get_hex(&self) -> String {
61
+ self.0.to_bytes().to_hex_string(Case::Upper)
62
+ }
63
+
64
+ #[wasm_bindgen(js_name = "getPublicKeyHash")]
65
+ pub fn get_public_key_hash(&self) -> String {
66
+ let secp = Secp256k1::new();
67
+
68
+ self.0.public_key(&secp).pubkey_hash().to_hex()
69
+ }
32
70
  }
@@ -1,18 +1,20 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_state_transition"
3
- version = "0.1.0"
3
+ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
7
7
  crate-type = ["cdylib", "lib"]
8
8
 
9
9
  [dependencies]
10
- wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
- pshenmic_dpp_public_key = {path = "../public_key"}
10
+ wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
11
+ pshenmic_dpp_public_key = {path = "../identity_public_key" }
12
12
  pshenmic_dpp_private_key = {path = "../private_key"}
13
13
  pshenmic_dpp_utils = {path = "../utils"}
14
+ pshenmic_dpp_identifier = {path = "../identifier"}
14
15
  pshenmic_dpp_mock_bls = {path = "../mock_bls"}
15
16
  pshenmic_dpp_enums = {path = "../enums"}
16
17
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
17
18
  "state-transition-signing"
18
- ]}
19
+ ]}
20
+ sha2 = "0.10.8"