pshenmic-dpp 1.0.4 → 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 (81) hide show
  1. package/.github/workflows/build.yml +8 -0
  2. package/.github/workflows/publish.yml +8 -0
  3. package/Cargo.lock +79 -31
  4. package/Cargo.toml +20 -17
  5. package/README.md +66 -23
  6. package/babel.config.json +19 -0
  7. package/dist/wasm/pshenmic_dpp.js +2487 -355
  8. package/dist/wasm/pshenmic_dpp_bg.js +1 -1
  9. package/package.json +13 -6
  10. package/packages/cbor_conversation/Cargo.toml +1 -1
  11. package/packages/data_contract/Cargo.toml +2 -2
  12. package/packages/data_contract/src/lib.rs +195 -23
  13. package/packages/data_contract_transitions/Cargo.toml +1 -1
  14. package/packages/data_contract_transitions/src/create/mod.rs +23 -16
  15. package/packages/data_contract_transitions/src/update/mod.rs +21 -12
  16. package/packages/document/Cargo.toml +1 -1
  17. package/packages/document/src/lib.rs +1 -1
  18. package/packages/document/src/methods/mod.rs +370 -2
  19. package/packages/{document_batch → documents_batch}/Cargo.toml +6 -4
  20. package/packages/documents_batch/src/document_base_transition/mod.rs +92 -0
  21. package/packages/documents_batch/src/document_transition/mod.rs +166 -0
  22. package/packages/documents_batch/src/generators.rs +122 -0
  23. package/packages/documents_batch/src/lib.rs +188 -0
  24. package/packages/documents_batch/src/prefunded_voting_balance/mod.rs +45 -0
  25. package/packages/documents_batch/src/transitions/create/mod.rs +123 -0
  26. package/packages/documents_batch/src/transitions/delete/mod.rs +67 -0
  27. package/packages/documents_batch/src/transitions/mod.rs +6 -0
  28. package/packages/documents_batch/src/transitions/purchase/mod.rs +91 -0
  29. package/packages/documents_batch/src/transitions/replace/mod.rs +93 -0
  30. package/packages/documents_batch/src/transitions/transfer/mod.rs +86 -0
  31. package/packages/documents_batch/src/transitions/update_price/mod.rs +75 -0
  32. package/packages/enums/Cargo.toml +3 -3
  33. package/packages/enums/src/batch/batch_enum.rs +75 -10
  34. package/packages/enums/src/keys/key_type.rs +46 -0
  35. package/packages/enums/src/keys/purpose.rs +55 -0
  36. package/packages/enums/src/keys/security_level.rs +46 -0
  37. package/packages/enums/src/lib.rs +1 -0
  38. package/packages/enums/src/network/mod.rs +67 -0
  39. package/packages/enums/src/platform/mod.rs +66 -8
  40. package/packages/identity/Cargo.toml +3 -4
  41. package/packages/identity/src/lib.rs +25 -14
  42. package/packages/{public_key → identity_public_key}/Cargo.toml +1 -1
  43. package/packages/{public_key → identity_public_key}/src/lib.rs +74 -27
  44. package/packages/identity_transitions/Cargo.toml +2 -2
  45. package/packages/identity_transitions/src/create_transition/mod.rs +3 -1
  46. package/packages/identity_transitions/src/create_transition/public_key_in_creation/mod.rs +25 -21
  47. package/packages/mock_bls/Cargo.toml +1 -1
  48. package/packages/private_key/Cargo.toml +3 -2
  49. package/packages/private_key/src/lib.rs +44 -6
  50. package/packages/state_transition/Cargo.toml +5 -4
  51. package/packages/state_transition/src/lib.rs +101 -36
  52. package/packages/utils/Cargo.toml +1 -2
  53. package/packages/utils/src/lib.rs +17 -15
  54. package/scripts/build-js.sh +6 -5
  55. package/scripts/build.sh +22 -1
  56. package/src/lib.rs +7 -1
  57. package/tests/DataContract.spec.js +175 -0
  58. package/tests/DataContractCreateStateTransition.spec.js +109 -0
  59. package/tests/DataContractUpdateStateTransition.spec.js +109 -0
  60. package/tests/Document.spec.js +232 -0
  61. package/tests/DocumentBatchTransition.spec.js +109 -0
  62. package/tests/DocumentTransition.spec.js +97 -0
  63. package/tests/DocumentsTransitions.spec.js +705 -0
  64. package/tests/Identity.spec.js +113 -0
  65. package/tests/IdentityPublicKey.spec.js +132 -0
  66. package/tests/PrivateKey.spec.js +73 -0
  67. package/tests/mocks/DataContract/DataContract.json +153 -0
  68. package/tests/mocks/DataContract/index.js +6 -0
  69. package/tests/mocks/Document/DataContract.json +23 -0
  70. package/tests/mocks/Document/document.json +3 -0
  71. package/tests/mocks/Document/document2.json +3 -0
  72. package/tests/mocks/Document/index.js +11 -0
  73. package/tests/mocks/Identity/index.js +7 -0
  74. package/tests/mocks/PrivateKey/index.js +5 -0
  75. package/tests/mocks/PublicKey/index.js +14 -0
  76. package/tests/utils/hex.js +15 -0
  77. package/tests/utils/wasm.js +14 -0
  78. package/packages/document/src/methods/js.rs +0 -260
  79. package/packages/document/src/methods/rust.rs +0 -92
  80. package/packages/document_batch/src/generators.rs +0 -63
  81. package/packages/document_batch/src/lib.rs +0 -228
@@ -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,5 +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",
13
- ]}
12
+ "state-transitions"
13
+ ]}
@@ -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 {
@@ -1,4 +1,5 @@
1
1
  use dpp::identity::SecurityLevel;
2
+ use wasm_bindgen::JsValue;
2
3
  use wasm_bindgen::prelude::wasm_bindgen;
3
4
 
4
5
  #[wasm_bindgen(js_name = SecurityLevel)]
@@ -9,6 +10,51 @@ pub enum SecurityLevelWASM {
9
10
  MEDIUM = 3,
10
11
  }
11
12
 
13
+ impl TryFrom<JsValue> for SecurityLevelWASM {
14
+ type Error = JsValue;
15
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
16
+ match value.is_string() {
17
+ true => match value.as_string() {
18
+ None => Err(JsValue::from("cannot read value from enum")),
19
+ Some(enum_val) => match enum_val.to_lowercase().as_str() {
20
+ "master" => Ok(SecurityLevelWASM::MASTER),
21
+ "critical" => Ok(SecurityLevelWASM::CRITICAL),
22
+ "high" => Ok(SecurityLevelWASM::HIGH),
23
+ "medium" => Ok(SecurityLevelWASM::MEDIUM),
24
+ _ => Err(JsValue::from(format!(
25
+ "unsupported security level value ({})",
26
+ enum_val
27
+ ))),
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(SecurityLevelWASM::MASTER),
34
+ 1 => Ok(SecurityLevelWASM::CRITICAL),
35
+ 2 => Ok(SecurityLevelWASM::HIGH),
36
+ 3 => Ok(SecurityLevelWASM::MEDIUM),
37
+ _ => Err(JsValue::from(format!(
38
+ "unsupported security level value ({})",
39
+ enum_val
40
+ ))),
41
+ },
42
+ },
43
+ }
44
+ }
45
+ }
46
+
47
+ impl From<SecurityLevelWASM> for String {
48
+ fn from(level: SecurityLevelWASM) -> String {
49
+ match level {
50
+ SecurityLevelWASM::MASTER => String::from("MASTER"),
51
+ SecurityLevelWASM::CRITICAL => String::from("CRITICAL"),
52
+ SecurityLevelWASM::HIGH => String::from("HIGH"),
53
+ SecurityLevelWASM::MEDIUM => String::from("MEDIUM"),
54
+ }
55
+ }
56
+ }
57
+
12
58
  impl From<SecurityLevelWASM> for SecurityLevel {
13
59
  fn from(security_level: SecurityLevelWASM) -> Self {
14
60
  match security_level {
@@ -1,3 +1,4 @@
1
1
  pub mod batch;
2
2
  pub mod keys;
3
+ pub mod network;
3
4
  pub mod platform;
@@ -0,0 +1,67 @@
1
+ use dpp::dashcore::network::constants::Network;
2
+ use wasm_bindgen::JsValue;
3
+ use wasm_bindgen::prelude::wasm_bindgen;
4
+ #[wasm_bindgen(js_name = "NetworkWASM")]
5
+ #[allow(non_camel_case_types)]
6
+ pub enum NetworkWASM {
7
+ Mainnet = 0,
8
+ Testnet = 1,
9
+ Devnet = 2,
10
+ Regtest = 3,
11
+ }
12
+
13
+ impl TryFrom<JsValue> for NetworkWASM {
14
+ type Error = JsValue;
15
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
16
+ match value.is_string() {
17
+ true => match value.as_string() {
18
+ None => Err(JsValue::from("cannot read value from enum")),
19
+ Some(enum_val) => match enum_val.to_lowercase().as_str() {
20
+ "mainnet" => Ok(NetworkWASM::Mainnet),
21
+ "testnet" => Ok(NetworkWASM::Testnet),
22
+ "devnet" => Ok(NetworkWASM::Devnet),
23
+ "regtest" => Ok(NetworkWASM::Regtest),
24
+ _ => Err(JsValue::from(format!(
25
+ "unsupported network name ({})",
26
+ enum_val
27
+ ))),
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(NetworkWASM::Mainnet),
34
+ 1 => Ok(NetworkWASM::Testnet),
35
+ 2 => Ok(NetworkWASM::Devnet),
36
+ 3 => Ok(NetworkWASM::Regtest),
37
+ _ => Err(JsValue::from(format!(
38
+ "unsupported network name ({})",
39
+ enum_val
40
+ ))),
41
+ },
42
+ },
43
+ }
44
+ }
45
+ }
46
+
47
+ impl From<NetworkWASM> for String {
48
+ fn from(value: NetworkWASM) -> Self {
49
+ match value {
50
+ NetworkWASM::Mainnet => "Mainnet".to_string(),
51
+ NetworkWASM::Testnet => "Testnet".to_string(),
52
+ NetworkWASM::Devnet => "Devnet".to_string(),
53
+ NetworkWASM::Regtest => "Regtest".to_string(),
54
+ }
55
+ }
56
+ }
57
+
58
+ impl From<NetworkWASM> for Network {
59
+ fn from(network: NetworkWASM) -> Self {
60
+ match network {
61
+ NetworkWASM::Mainnet => Network::Dash,
62
+ NetworkWASM::Testnet => Network::Testnet,
63
+ NetworkWASM::Devnet => Network::Devnet,
64
+ NetworkWASM::Regtest => Network::Regtest,
65
+ }
66
+ }
67
+ }