pshenmic-dpp 1.0.3 → 1.0.5

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 (83) hide show
  1. package/.github/workflows/build.yml +8 -0
  2. package/.github/workflows/publish.yml +8 -0
  3. package/Cargo.lock +89 -28
  4. package/Cargo.toml +22 -18
  5. package/README.md +66 -23
  6. package/babel.config.json +19 -0
  7. package/dist/wasm/pshenmic_dpp.js +2992 -402
  8. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  9. package/package.json +13 -6
  10. package/packages/{cbor-conversation → cbor_conversation}/Cargo.toml +1 -5
  11. package/packages/data_contract/Cargo.toml +3 -7
  12. package/packages/data_contract/src/lib.rs +234 -47
  13. package/packages/{document_batch → data_contract_transitions}/Cargo.toml +6 -14
  14. package/packages/data_contract_transitions/src/create/mod.rs +161 -0
  15. package/packages/data_contract_transitions/src/lib.rs +2 -0
  16. package/packages/data_contract_transitions/src/update/mod.rs +144 -0
  17. package/packages/document/Cargo.toml +2 -7
  18. package/packages/document/src/lib.rs +1 -1
  19. package/packages/document/src/methods/mod.rs +370 -2
  20. package/packages/documents_batch/Cargo.toml +19 -0
  21. package/packages/documents_batch/src/document_base_transition/mod.rs +92 -0
  22. package/packages/documents_batch/src/document_transition/mod.rs +166 -0
  23. package/packages/documents_batch/src/generators.rs +122 -0
  24. package/packages/documents_batch/src/lib.rs +188 -0
  25. package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
  26. package/packages/documents_batch/src/transitions/create/mod.rs +123 -0
  27. package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
  28. package/packages/documents_batch/src/transitions/mod.rs +6 -0
  29. package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
  30. package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
  31. package/packages/documents_batch/src/transitions/transfer/mod.rs +86 -0
  32. package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
  33. package/packages/enums/Cargo.toml +2 -5
  34. package/packages/enums/src/batch/batch_enum.rs +75 -10
  35. package/packages/enums/src/keys/key_type.rs +46 -0
  36. package/packages/enums/src/keys/purpose.rs +55 -0
  37. package/packages/enums/src/keys/security_level.rs +46 -0
  38. package/packages/enums/src/lib.rs +1 -0
  39. package/packages/enums/src/network/mod.rs +67 -0
  40. package/packages/enums/src/platform/mod.rs +66 -8
  41. package/packages/identity/Cargo.toml +2 -7
  42. package/packages/identity/src/lib.rs +25 -14
  43. package/packages/{public_key → identity_public_key}/Cargo.toml +2 -6
  44. package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
  45. package/packages/identity_transitions/Cargo.toml +3 -7
  46. package/packages/identity_transitions/src/create_transition/mod.rs +5 -3
  47. package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +25 -21
  48. package/packages/mock_bls/Cargo.toml +2 -6
  49. package/packages/private_key/Cargo.toml +2 -5
  50. package/packages/private_key/src/lib.rs +44 -6
  51. package/packages/state_transition/Cargo.toml +4 -7
  52. package/packages/state_transition/src/lib.rs +106 -40
  53. package/packages/utils/Cargo.toml +1 -6
  54. package/packages/utils/src/lib.rs +17 -15
  55. package/scripts/build-js.sh +8 -6
  56. package/scripts/build.sh +22 -1
  57. package/src/lib.rs +8 -1
  58. package/tests/DataContract.spec.js +175 -0
  59. package/tests/DataContractCreateStateTransition.spec.js +109 -0
  60. package/tests/DataContractUpdateStateTransition.spec.js +109 -0
  61. package/tests/Document.spec.js +232 -0
  62. package/tests/DocumentBatchTransition.spec.js +109 -0
  63. package/tests/DocumentTransition.spec.js +97 -0
  64. package/tests/DocumentsTransitions.spec.js +705 -0
  65. package/tests/Identity.spec.js +113 -0
  66. package/tests/IdentityPublicKey.spec.js +132 -0
  67. package/tests/PrivateKey.spec.js +73 -0
  68. package/tests/mocks/DataContract/DataContract.json +153 -0
  69. package/tests/mocks/DataContract/index.js +6 -0
  70. package/tests/mocks/Document/DataContract.json +23 -0
  71. package/tests/mocks/Document/document.json +3 -0
  72. package/tests/mocks/Document/document2.json +3 -0
  73. package/tests/mocks/Document/index.js +11 -0
  74. package/tests/mocks/Identity/index.js +7 -0
  75. package/tests/mocks/PrivateKey/index.js +5 -0
  76. package/tests/mocks/PublicKey/index.js +14 -0
  77. package/tests/utils/hex.js +15 -0
  78. package/tests/utils/wasm.js +14 -0
  79. package/packages/document/src/methods/js.rs +0 -260
  80. package/packages/document/src/methods/rust.rs +0 -92
  81. package/packages/document_batch/src/generators.rs +0 -63
  82. package/packages/document_batch/src/lib.rs +0 -228
  83. /package/packages/{cbor-conversation → cbor_conversation}/src/lib.rs +0 -0
@@ -0,0 +1,67 @@
1
+ use crate::document_base_transition::DocumentBaseTransitionWASM;
2
+ use crate::document_transition::DocumentTransitionWASM;
3
+ use crate::generators::generate_delete_transition;
4
+ use dpp::prelude::IdentityNonce;
5
+ use dpp::state_transition::documents_batch_transition::DocumentDeleteTransition;
6
+ use dpp::state_transition::documents_batch_transition::document_delete_transition::v0::v0_methods::DocumentDeleteTransitionV0Methods;
7
+ use dpp::state_transition::documents_batch_transition::document_transition::DocumentTransition;
8
+ use pshenmic_dpp_document::DocumentWASM;
9
+ use wasm_bindgen::JsValue;
10
+ use wasm_bindgen::prelude::wasm_bindgen;
11
+
12
+ #[wasm_bindgen(js_name = "DocumentDeleteTransitionWASM")]
13
+ pub struct DocumentDeleteTransitionWASM(DocumentDeleteTransition);
14
+
15
+ impl From<DocumentDeleteTransition> for DocumentDeleteTransitionWASM {
16
+ fn from(document_delete_transition: DocumentDeleteTransition) -> Self {
17
+ DocumentDeleteTransitionWASM(document_delete_transition)
18
+ }
19
+ }
20
+
21
+ impl From<DocumentDeleteTransitionWASM> for DocumentDeleteTransition {
22
+ fn from(document_delete_transition: DocumentDeleteTransitionWASM) -> Self {
23
+ document_delete_transition.0
24
+ }
25
+ }
26
+
27
+ #[wasm_bindgen]
28
+ impl DocumentDeleteTransitionWASM {
29
+ #[wasm_bindgen(constructor)]
30
+ pub fn new(
31
+ document: &DocumentWASM,
32
+ identity_contract_nonce: IdentityNonce,
33
+ document_type_name: String,
34
+ ) -> Result<DocumentDeleteTransitionWASM, JsValue> {
35
+ let rs_delete_transition = generate_delete_transition(
36
+ document.clone(),
37
+ identity_contract_nonce,
38
+ document_type_name.to_string(),
39
+ );
40
+
41
+ Ok(DocumentDeleteTransitionWASM(rs_delete_transition))
42
+ }
43
+
44
+ #[wasm_bindgen(getter = "base")]
45
+ pub fn get_base(&self) -> DocumentBaseTransitionWASM {
46
+ self.0.base().clone().into()
47
+ }
48
+
49
+ #[wasm_bindgen(setter = "base")]
50
+ pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) {
51
+ self.0.set_base(base.clone().into())
52
+ }
53
+
54
+ #[wasm_bindgen(js_name = "toDocumentTransition")]
55
+ pub fn to_document_transition(&self) -> DocumentTransitionWASM {
56
+ let rs_transition = DocumentTransition::from(self.0.clone());
57
+
58
+ DocumentTransitionWASM::from(rs_transition)
59
+ }
60
+
61
+ #[wasm_bindgen(js_name = "fromDocumentTransition")]
62
+ pub fn from_document_transition(
63
+ js_transition: DocumentTransitionWASM,
64
+ ) -> Result<DocumentDeleteTransitionWASM, JsValue> {
65
+ js_transition.get_delete_transition()
66
+ }
67
+ }
@@ -0,0 +1,6 @@
1
+ pub mod create;
2
+ pub mod delete;
3
+ pub mod purchase;
4
+ pub mod replace;
5
+ pub mod transfer;
6
+ pub mod update_price;
@@ -0,0 +1,91 @@
1
+ use dpp::fee::Credits;
2
+ use dpp::prelude::{IdentityNonce, Revision};
3
+ use dpp::state_transition::documents_batch_transition::document_transition::document_purchase_transition::v0::v0_methods::DocumentPurchaseTransitionV0Methods;
4
+ use dpp::state_transition::documents_batch_transition::document_transition::{DocumentPurchaseTransition, DocumentTransition};
5
+ use wasm_bindgen::JsValue;
6
+ use wasm_bindgen::prelude::wasm_bindgen;
7
+ use pshenmic_dpp_document::DocumentWASM;
8
+ use crate::document_base_transition::DocumentBaseTransitionWASM;
9
+ use crate::document_transition::DocumentTransitionWASM;
10
+ use crate::generators::generate_purchase_transition;
11
+
12
+ #[wasm_bindgen(js_name = "DocumentPurchaseTransitionWASM")]
13
+ pub struct DocumentPurchaseTransitionWASM(DocumentPurchaseTransition);
14
+
15
+ impl From<DocumentPurchaseTransitionWASM> for DocumentPurchaseTransition {
16
+ fn from(transition: DocumentPurchaseTransitionWASM) -> Self {
17
+ transition.0
18
+ }
19
+ }
20
+
21
+ impl From<DocumentPurchaseTransition> for DocumentPurchaseTransitionWASM {
22
+ fn from(transition: DocumentPurchaseTransition) -> Self {
23
+ DocumentPurchaseTransitionWASM(transition)
24
+ }
25
+ }
26
+
27
+ #[wasm_bindgen]
28
+ impl DocumentPurchaseTransitionWASM {
29
+ #[wasm_bindgen(constructor)]
30
+ pub fn new(
31
+ document: &DocumentWASM,
32
+ identity_contract_nonce: IdentityNonce,
33
+ document_type_name: String,
34
+ amount: Credits,
35
+ ) -> Result<DocumentPurchaseTransitionWASM, JsValue> {
36
+ let rs_purchase_transition = generate_purchase_transition(
37
+ document.clone(),
38
+ identity_contract_nonce,
39
+ document_type_name,
40
+ amount,
41
+ );
42
+
43
+ Ok(DocumentPurchaseTransitionWASM(rs_purchase_transition))
44
+ }
45
+
46
+ #[wasm_bindgen(getter = "base")]
47
+ pub fn get_base(&self) -> DocumentBaseTransitionWASM {
48
+ self.0.base().clone().into()
49
+ }
50
+
51
+ #[wasm_bindgen(getter = "price")]
52
+ pub fn get_price(&self) -> Credits {
53
+ self.0.price()
54
+ }
55
+
56
+ #[wasm_bindgen(getter = "revision")]
57
+ pub fn get_revision(&self) -> Revision {
58
+ self.0.revision()
59
+ }
60
+
61
+ #[wasm_bindgen(setter = "base")]
62
+ pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) {
63
+ self.0.set_base(base.clone().into())
64
+ }
65
+
66
+ #[wasm_bindgen(setter = "price")]
67
+ pub fn set_price(&mut self, price: Credits) {
68
+ match self.0 {
69
+ DocumentPurchaseTransition::V0(ref mut v0) => v0.price = price,
70
+ }
71
+ }
72
+
73
+ #[wasm_bindgen(setter = "revision")]
74
+ pub fn set_revision(&mut self, revision: Revision) {
75
+ self.0.set_revision(revision);
76
+ }
77
+
78
+ #[wasm_bindgen(js_name = "toDocumentTransition")]
79
+ pub fn to_document_transition(&self) -> DocumentTransitionWASM {
80
+ let rs_transition = DocumentTransition::from(self.0.clone());
81
+
82
+ DocumentTransitionWASM::from(rs_transition)
83
+ }
84
+
85
+ #[wasm_bindgen(js_name = "fromDocumentTransition")]
86
+ pub fn from_document_transition(
87
+ js_transition: DocumentTransitionWASM,
88
+ ) -> Result<DocumentPurchaseTransitionWASM, JsValue> {
89
+ js_transition.get_purchase_transition()
90
+ }
91
+ }
@@ -0,0 +1,93 @@
1
+ use dpp::dashcore::hashes::serde::Serialize;
2
+ use dpp::prelude::{IdentityNonce, Revision};
3
+ use dpp::state_transition::documents_batch_transition::document_replace_transition::v0::v0_methods::DocumentReplaceTransitionV0Methods;
4
+ use dpp::state_transition::documents_batch_transition::document_transition::DocumentTransition;
5
+ use dpp::state_transition::documents_batch_transition::DocumentReplaceTransition;
6
+ use wasm_bindgen::JsValue;
7
+ use wasm_bindgen::prelude::wasm_bindgen;
8
+ use pshenmic_dpp_document::DocumentWASM;
9
+ use pshenmic_dpp_utils::ToSerdeJSONExt;
10
+ use crate::document_base_transition::DocumentBaseTransitionWASM;
11
+ use crate::generators::generate_replace_transition;
12
+ use crate::document_transition::DocumentTransitionWASM;
13
+
14
+ #[wasm_bindgen(js_name = "DocumentReplaceTransitionWASM")]
15
+ pub struct DocumentReplaceTransitionWASM(DocumentReplaceTransition);
16
+
17
+ impl From<DocumentReplaceTransition> for DocumentReplaceTransitionWASM {
18
+ fn from(document_replace: DocumentReplaceTransition) -> Self {
19
+ DocumentReplaceTransitionWASM(document_replace)
20
+ }
21
+ }
22
+
23
+ impl From<DocumentReplaceTransitionWASM> for DocumentReplaceTransition {
24
+ fn from(document_replace: DocumentReplaceTransitionWASM) -> Self {
25
+ document_replace.0
26
+ }
27
+ }
28
+
29
+ #[wasm_bindgen]
30
+ impl DocumentReplaceTransitionWASM {
31
+ #[wasm_bindgen(constructor)]
32
+ pub fn new(
33
+ document: &DocumentWASM,
34
+ identity_contract_nonce: IdentityNonce,
35
+ document_type_name: String,
36
+ ) -> Result<DocumentReplaceTransitionWASM, JsValue> {
37
+ let rs_update_transition = generate_replace_transition(
38
+ document.clone(),
39
+ identity_contract_nonce,
40
+ document_type_name.to_string(),
41
+ );
42
+
43
+ Ok(DocumentReplaceTransitionWASM(rs_update_transition))
44
+ }
45
+
46
+ #[wasm_bindgen(getter = "data")]
47
+ pub fn get_data(&self) -> Result<JsValue, JsValue> {
48
+ let serializer = serde_wasm_bindgen::Serializer::json_compatible();
49
+
50
+ self.0.data().serialize(&serializer).map_err(JsValue::from)
51
+ }
52
+
53
+ #[wasm_bindgen(getter = "base")]
54
+ pub fn get_base(&self) -> DocumentBaseTransitionWASM {
55
+ self.0.base().clone().into()
56
+ }
57
+
58
+ #[wasm_bindgen(getter = "revision")]
59
+ pub fn get_revision(&self) -> Revision {
60
+ self.0.revision()
61
+ }
62
+
63
+ #[wasm_bindgen(setter = "data")]
64
+ pub fn set_data(&mut self, js_data: JsValue) -> Result<(), JsValue> {
65
+ let data = js_data.with_serde_to_platform_value_map()?;
66
+
67
+ Ok(self.0.set_data(data))
68
+ }
69
+
70
+ #[wasm_bindgen(setter = "base")]
71
+ pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) {
72
+ self.0.set_base(base.clone().into())
73
+ }
74
+
75
+ #[wasm_bindgen(setter = "revision")]
76
+ pub fn set_revision(&mut self, revision: Revision) {
77
+ self.0.set_revision(revision);
78
+ }
79
+
80
+ #[wasm_bindgen(js_name = "toDocumentTransition")]
81
+ pub fn to_document_transition(&self) -> DocumentTransitionWASM {
82
+ let rs_transition = DocumentTransition::from(self.0.clone());
83
+
84
+ DocumentTransitionWASM::from(rs_transition)
85
+ }
86
+
87
+ #[wasm_bindgen(js_name = "fromDocumentTransition")]
88
+ pub fn from_document_transition(
89
+ js_transition: DocumentTransitionWASM,
90
+ ) -> Result<DocumentReplaceTransitionWASM, JsValue> {
91
+ js_transition.get_replace_transition()
92
+ }
93
+ }
@@ -0,0 +1,86 @@
1
+ use dpp::prelude::IdentityNonce;
2
+ use dpp::state_transition::documents_batch_transition::document_transition::document_transfer_transition::v0::v0_methods::DocumentTransferTransitionV0Methods;
3
+ use dpp::state_transition::documents_batch_transition::document_transition::{DocumentTransferTransition, DocumentTransition};
4
+ use wasm_bindgen::JsValue;
5
+ use wasm_bindgen::prelude::wasm_bindgen;
6
+ use pshenmic_dpp_document::DocumentWASM;
7
+ use pshenmic_dpp_utils::identifier_from_js_value;
8
+ use crate::document_base_transition::DocumentBaseTransitionWASM;
9
+ use crate::document_transition::DocumentTransitionWASM;
10
+ use crate::generators::generate_transfer_transition;
11
+
12
+ #[wasm_bindgen(js_name = "DocumentTransferTransitionWASM")]
13
+ pub struct DocumentTransferTransitionWASM(DocumentTransferTransition);
14
+
15
+ impl From<DocumentTransferTransition> for DocumentTransferTransitionWASM {
16
+ fn from(transition: DocumentTransferTransition) -> Self {
17
+ DocumentTransferTransitionWASM(transition)
18
+ }
19
+ }
20
+
21
+ impl From<DocumentTransferTransitionWASM> for DocumentTransferTransition {
22
+ fn from(transition: DocumentTransferTransitionWASM) -> Self {
23
+ transition.0
24
+ }
25
+ }
26
+
27
+ #[wasm_bindgen]
28
+ impl DocumentTransferTransitionWASM {
29
+ #[wasm_bindgen(constructor)]
30
+ pub fn new(
31
+ document: &DocumentWASM,
32
+ identity_contract_nonce: IdentityNonce,
33
+ document_type_name: String,
34
+ js_recipient_owner_id: JsValue,
35
+ ) -> Result<DocumentTransferTransitionWASM, JsValue> {
36
+ let recipient_owner_id = identifier_from_js_value(&js_recipient_owner_id)?;
37
+
38
+ let rs_transfer_transition = generate_transfer_transition(
39
+ document.clone(),
40
+ identity_contract_nonce,
41
+ document_type_name,
42
+ recipient_owner_id,
43
+ );
44
+
45
+ Ok(DocumentTransferTransitionWASM(rs_transfer_transition))
46
+ }
47
+
48
+ #[wasm_bindgen(getter = "base")]
49
+ pub fn get_base(&self) -> DocumentBaseTransitionWASM {
50
+ self.0.base().clone().into()
51
+ }
52
+
53
+ #[wasm_bindgen(getter = "recipientId")]
54
+ pub fn get_recipient_owner_id(&self) -> Vec<u8> {
55
+ self.0.recipient_owner_id().to_vec()
56
+ }
57
+
58
+ #[wasm_bindgen(setter = "base")]
59
+ pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) {
60
+ self.0.set_base(base.clone().into())
61
+ }
62
+
63
+ #[wasm_bindgen(setter = "recipientId")]
64
+ pub fn set_recipient_owner_id(
65
+ &mut self,
66
+ js_recipient_owner_id: JsValue,
67
+ ) -> Result<(), JsValue> {
68
+ let recipient_owner_id = identifier_from_js_value(&js_recipient_owner_id)?;
69
+
70
+ Ok(self.0.set_recipient_owner_id(recipient_owner_id))
71
+ }
72
+
73
+ #[wasm_bindgen(js_name = "toDocumentTransition")]
74
+ pub fn to_document_transition(&self) -> DocumentTransitionWASM {
75
+ let rs_transition = DocumentTransition::from(self.0.clone());
76
+
77
+ DocumentTransitionWASM::from(rs_transition)
78
+ }
79
+
80
+ #[wasm_bindgen(js_name = "fromDocumentTransition")]
81
+ pub fn from_document_transition(
82
+ js_transition: DocumentTransitionWASM,
83
+ ) -> Result<DocumentTransferTransitionWASM, JsValue> {
84
+ js_transition.get_transfer_transition()
85
+ }
86
+ }
@@ -0,0 +1,75 @@
1
+ use dpp::fee::Credits;
2
+ use dpp::prelude::IdentityNonce;
3
+ use dpp::state_transition::documents_batch_transition::document_transition::document_update_price_transition::v0::v0_methods::DocumentUpdatePriceTransitionV0Methods;
4
+ use dpp::state_transition::documents_batch_transition::document_transition::{DocumentTransition, DocumentUpdatePriceTransition};
5
+ use wasm_bindgen::JsValue;
6
+ use wasm_bindgen::prelude::wasm_bindgen;
7
+ use pshenmic_dpp_document::DocumentWASM;
8
+ use crate::document_base_transition::DocumentBaseTransitionWASM;
9
+ use crate::document_transition::DocumentTransitionWASM;
10
+ use crate::generators::generate_update_price_transition;
11
+
12
+ #[wasm_bindgen(js_name = "DocumentUpdatePriceTransitionWASM")]
13
+ pub struct DocumentUpdatePriceTransitionWASM(DocumentUpdatePriceTransition);
14
+
15
+ impl From<DocumentUpdatePriceTransition> for DocumentUpdatePriceTransitionWASM {
16
+ fn from(document_update_price_transition: DocumentUpdatePriceTransition) -> Self {
17
+ DocumentUpdatePriceTransitionWASM(document_update_price_transition)
18
+ }
19
+ }
20
+
21
+ #[wasm_bindgen]
22
+ impl DocumentUpdatePriceTransitionWASM {
23
+ #[wasm_bindgen(constructor)]
24
+ pub fn new(
25
+ document: &DocumentWASM,
26
+ identity_contract_nonce: IdentityNonce,
27
+ document_type_name: String,
28
+ price: Credits,
29
+ ) -> Result<DocumentUpdatePriceTransitionWASM, JsValue> {
30
+ let rs_document_update_price_transition = generate_update_price_transition(
31
+ document.clone(),
32
+ identity_contract_nonce,
33
+ document_type_name,
34
+ price,
35
+ );
36
+
37
+ Ok(DocumentUpdatePriceTransitionWASM(
38
+ rs_document_update_price_transition,
39
+ ))
40
+ }
41
+
42
+ #[wasm_bindgen(getter = "base")]
43
+ pub fn get_base(&self) -> DocumentBaseTransitionWASM {
44
+ self.0.base().clone().into()
45
+ }
46
+
47
+ #[wasm_bindgen(getter = "price")]
48
+ pub fn get_price(&self) -> Credits {
49
+ self.0.price()
50
+ }
51
+
52
+ #[wasm_bindgen(setter = "base")]
53
+ pub fn set_base(&mut self, base: &DocumentBaseTransitionWASM) {
54
+ self.0.set_base(base.clone().into())
55
+ }
56
+
57
+ #[wasm_bindgen(setter = "price")]
58
+ pub fn set_price(&mut self, price: Credits) {
59
+ self.0.set_price(price)
60
+ }
61
+
62
+ #[wasm_bindgen(js_name = "toDocumentTransition")]
63
+ pub fn to_document_transition(&self) -> DocumentTransitionWASM {
64
+ let rs_transition = DocumentTransition::from(self.0.clone());
65
+
66
+ DocumentTransitionWASM::from(rs_transition)
67
+ }
68
+
69
+ #[wasm_bindgen(js_name = "fromDocumentTransition")]
70
+ pub fn from_document_transition(
71
+ js_transition: DocumentTransitionWASM,
72
+ ) -> Result<DocumentUpdatePriceTransitionWASM, JsValue> {
73
+ js_transition.get_update_price_transition()
74
+ }
75
+ }
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_enums"
3
- version = "0.1.0"
3
+ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
@@ -9,8 +9,5 @@ crate-type = ["cdylib", "lib"]
9
9
  [dependencies]
10
10
  wasm-bindgen = "0.2.100"
11
11
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
- "identity-value-conversion",
12
+ "state-transitions"
13
13
  ]}
14
- [profile.release]
15
- lto = true
16
- opt-level = 'z'
@@ -1,19 +1,84 @@
1
+ use dpp::state_transition::documents_batch_transition::document_transition::action_type::DocumentTransitionActionType;
2
+ use wasm_bindgen::JsValue;
1
3
  use wasm_bindgen::prelude::wasm_bindgen;
2
4
 
3
5
  #[wasm_bindgen(js_name = "BatchType")]
4
- pub enum BatchType {
5
- CREATE,
6
- REPLACE,
7
- DELETE,
6
+ pub enum BatchTypeWASM {
7
+ Create,
8
+ Replace,
9
+ Delete,
10
+ Transfer,
11
+ Purchase,
12
+ UpdatePrice,
13
+ IgnoreWhileBumpingRevision,
8
14
  }
9
15
 
10
- impl From<u8> for BatchType {
11
- fn from(value: u8) -> Self {
16
+ impl TryFrom<JsValue> for BatchTypeWASM {
17
+ type Error = JsValue;
18
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
19
+ match value.is_string() {
20
+ true => match value.as_string() {
21
+ None => Err(JsValue::from("cannot read value from enum")),
22
+ Some(enum_val) => match enum_val.to_lowercase().as_str() {
23
+ "create" => Ok(BatchTypeWASM::Create),
24
+ "replace" => Ok(BatchTypeWASM::Replace),
25
+ "delete" => Ok(BatchTypeWASM::Delete),
26
+ "transfer" => Ok(BatchTypeWASM::Transfer),
27
+ "purchase" => Ok(BatchTypeWASM::Purchase),
28
+ "updatePrice" => Ok(BatchTypeWASM::UpdatePrice),
29
+ "ignoreWhileBumpingRevision" => Ok(BatchTypeWASM::IgnoreWhileBumpingRevision),
30
+ _ => Err(JsValue::from(format!(
31
+ "unknown batch type value: {}",
32
+ enum_val
33
+ ))),
34
+ },
35
+ },
36
+ false => match value.as_f64() {
37
+ None => Err(JsValue::from("cannot read value from enum")),
38
+ Some(enum_val) => match enum_val as u8 {
39
+ 0 => Ok(BatchTypeWASM::Create),
40
+ 1 => Ok(BatchTypeWASM::Replace),
41
+ 2 => Ok(BatchTypeWASM::Delete),
42
+ 3 => Ok(BatchTypeWASM::Transfer),
43
+ 4 => Ok(BatchTypeWASM::Purchase),
44
+ 5 => Ok(BatchTypeWASM::UpdatePrice),
45
+ 6 => Ok(BatchTypeWASM::IgnoreWhileBumpingRevision),
46
+ _ => Err(JsValue::from(format!(
47
+ "unknown batch type value: {}",
48
+ enum_val
49
+ ))),
50
+ },
51
+ },
52
+ }
53
+ }
54
+ }
55
+
56
+ impl From<BatchTypeWASM> for String {
57
+ fn from(value: BatchTypeWASM) -> Self {
12
58
  match value {
13
- 0 => BatchType::CREATE,
14
- 1 => BatchType::REPLACE,
15
- 2 => BatchType::DELETE,
16
- _ => panic!("Invalid BatchType"),
59
+ BatchTypeWASM::Create => String::from("create"),
60
+ BatchTypeWASM::Replace => String::from("replace"),
61
+ BatchTypeWASM::Delete => String::from("delete"),
62
+ BatchTypeWASM::Transfer => String::from("transfer"),
63
+ BatchTypeWASM::Purchase => String::from("purchase"),
64
+ BatchTypeWASM::UpdatePrice => String::from("updatePrice"),
65
+ BatchTypeWASM::IgnoreWhileBumpingRevision => String::from("ignoreWhileBumpingRevision"),
66
+ }
67
+ }
68
+ }
69
+
70
+ impl From<DocumentTransitionActionType> for BatchTypeWASM {
71
+ fn from(action_type: DocumentTransitionActionType) -> Self {
72
+ match action_type {
73
+ DocumentTransitionActionType::Create => BatchTypeWASM::Create,
74
+ DocumentTransitionActionType::Replace => BatchTypeWASM::Replace,
75
+ DocumentTransitionActionType::Delete => BatchTypeWASM::Delete,
76
+ DocumentTransitionActionType::Transfer => BatchTypeWASM::Transfer,
77
+ DocumentTransitionActionType::Purchase => BatchTypeWASM::Purchase,
78
+ DocumentTransitionActionType::UpdatePrice => BatchTypeWASM::UpdatePrice,
79
+ DocumentTransitionActionType::IgnoreWhileBumpingRevision => {
80
+ BatchTypeWASM::IgnoreWhileBumpingRevision
81
+ }
17
82
  }
18
83
  }
19
84
  }
@@ -1,4 +1,5 @@
1
1
  use dpp::identity::KeyType;
2
+ use wasm_bindgen::JsValue;
2
3
  use wasm_bindgen::prelude::wasm_bindgen;
3
4
 
4
5
  #[allow(non_camel_case_types)]
@@ -11,6 +12,51 @@ pub enum KeyTypeWASM {
11
12
  EDDSA_25519_HASH160 = 4,
12
13
  }
13
14
 
15
+ impl TryFrom<JsValue> for KeyTypeWASM {
16
+ type Error = JsValue;
17
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
18
+ match value.is_string() {
19
+ true => match value.as_string() {
20
+ None => Err(JsValue::from("cannot read value from enum")),
21
+ Some(enum_val) => match enum_val.to_lowercase().as_str() {
22
+ "ecdsa_secp256k1" => Ok(KeyTypeWASM::ECDSA_SECP256K1),
23
+ "bls12_381" => Ok(KeyTypeWASM::BLS12_381),
24
+ "ecdsa_hash160" => Ok(KeyTypeWASM::ECDSA_HASH160),
25
+ "bip13_script_hash" => Ok(KeyTypeWASM::BIP13_SCRIPT_HASH),
26
+ "eddsa_25519_hash160" => Ok(KeyTypeWASM::EDDSA_25519_HASH160),
27
+ _ => Err(JsValue::from(format!("unsupported key type {}", enum_val))),
28
+ },
29
+ },
30
+ false => match value.as_f64() {
31
+ None => Err(JsValue::from("cannot read value from enum")),
32
+ Some(enum_val) => match enum_val as u8 {
33
+ 0 => Ok(KeyTypeWASM::ECDSA_SECP256K1),
34
+ 1 => Ok(KeyTypeWASM::BLS12_381),
35
+ 2 => Ok(KeyTypeWASM::ECDSA_HASH160),
36
+ 3 => Ok(KeyTypeWASM::BIP13_SCRIPT_HASH),
37
+ 4 => Ok(KeyTypeWASM::EDDSA_25519_HASH160),
38
+ _ => Err(JsValue::from(format!(
39
+ "unsupported key type ({})",
40
+ enum_val
41
+ ))),
42
+ },
43
+ },
44
+ }
45
+ }
46
+ }
47
+
48
+ impl From<KeyTypeWASM> for String {
49
+ fn from(value: KeyTypeWASM) -> Self {
50
+ match value {
51
+ KeyTypeWASM::ECDSA_SECP256K1 => String::from("ECDSA_SECP256K1"),
52
+ KeyTypeWASM::BLS12_381 => String::from("BLS12_381"),
53
+ KeyTypeWASM::ECDSA_HASH160 => String::from("ECDSA_HASH160"),
54
+ KeyTypeWASM::BIP13_SCRIPT_HASH => String::from("BIP13_SCRIPT_HASH"),
55
+ KeyTypeWASM::EDDSA_25519_HASH160 => String::from("EDDSA_25519_HASH160"),
56
+ }
57
+ }
58
+ }
59
+
14
60
  impl From<KeyTypeWASM> for KeyType {
15
61
  fn from(key_type: KeyTypeWASM) -> Self {
16
62
  match key_type {
@@ -1,4 +1,5 @@
1
1
  use dpp::identity::Purpose;
2
+ use wasm_bindgen::JsValue;
2
3
  use wasm_bindgen::prelude::wasm_bindgen;
3
4
 
4
5
  #[wasm_bindgen(js_name = "Purpose")]
@@ -12,6 +13,60 @@ pub enum PurposeWASM {
12
13
  OWNER = 6,
13
14
  }
14
15
 
16
+ impl TryFrom<JsValue> for PurposeWASM {
17
+ type Error = JsValue;
18
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
19
+ match value.is_string() {
20
+ true => match value.as_string() {
21
+ None => Err(JsValue::from("cannot read value from enum")),
22
+ Some(enum_val) => match enum_val.to_lowercase().as_str() {
23
+ "authentication" => Ok(PurposeWASM::AUTHENTICATION),
24
+ "encryption" => Ok(PurposeWASM::ENCRYPTION),
25
+ "decryption" => Ok(PurposeWASM::DECRYPTION),
26
+ "transfer" => Ok(PurposeWASM::TRANSFER),
27
+ "system" => Ok(PurposeWASM::SYSTEM),
28
+ "voting" => Ok(PurposeWASM::VOTING),
29
+ "owner" => Ok(PurposeWASM::OWNER),
30
+ _ => Err(JsValue::from(format!(
31
+ "unsupported purpose value ({})",
32
+ enum_val
33
+ ))),
34
+ },
35
+ },
36
+ false => match value.as_f64() {
37
+ None => Err(JsValue::from("cannot read value from enum")),
38
+ Some(enum_val) => match enum_val as u8 {
39
+ 0 => Ok(PurposeWASM::AUTHENTICATION),
40
+ 1 => Ok(PurposeWASM::ENCRYPTION),
41
+ 2 => Ok(PurposeWASM::DECRYPTION),
42
+ 3 => Ok(PurposeWASM::TRANSFER),
43
+ 4 => Ok(PurposeWASM::SYSTEM),
44
+ 5 => Ok(PurposeWASM::VOTING),
45
+ 6 => Ok(PurposeWASM::OWNER),
46
+ _ => Err(JsValue::from(format!(
47
+ "unsupported purpose value ({})",
48
+ enum_val
49
+ ))),
50
+ },
51
+ },
52
+ }
53
+ }
54
+ }
55
+
56
+ impl From<PurposeWASM> for String {
57
+ fn from(value: PurposeWASM) -> Self {
58
+ match value {
59
+ PurposeWASM::AUTHENTICATION => String::from("AUTHENTICATION"),
60
+ PurposeWASM::ENCRYPTION => String::from("ENCRYPTION"),
61
+ PurposeWASM::DECRYPTION => String::from("DECRYPTION"),
62
+ PurposeWASM::TRANSFER => String::from("TRANSFER"),
63
+ PurposeWASM::SYSTEM => String::from("SYSTEM"),
64
+ PurposeWASM::VOTING => String::from("VOTING"),
65
+ PurposeWASM::OWNER => String::from("OWNER"),
66
+ }
67
+ }
68
+ }
69
+
15
70
  impl From<PurposeWASM> for Purpose {
16
71
  fn from(purpose: PurposeWASM) -> Self {
17
72
  match purpose {