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
@@ -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
+ }
@@ -7,19 +7,77 @@ use dpp::version::v5::PLATFORM_V5;
7
7
  use dpp::version::v6::PLATFORM_V6;
8
8
  use dpp::version::v7::PLATFORM_V7;
9
9
  use dpp::version::v8::PLATFORM_V8;
10
+ use wasm_bindgen::JsValue;
10
11
  use wasm_bindgen::prelude::wasm_bindgen;
11
12
 
12
13
  #[wasm_bindgen(js_name = "PlatformVersionWASM")]
13
14
  #[allow(non_camel_case_types)]
14
15
  pub enum PlatformVersionWASM {
15
- PLATFORM_V1,
16
- PLATFORM_V2,
17
- PLATFORM_V3,
18
- PLATFORM_V4,
19
- PLATFORM_V5,
20
- PLATFORM_V6,
21
- PLATFORM_V7,
22
- PLATFORM_V8,
16
+ PLATFORM_V1 = 0,
17
+ PLATFORM_V2 = 1,
18
+ PLATFORM_V3 = 2,
19
+ PLATFORM_V4 = 3,
20
+ PLATFORM_V5 = 4,
21
+ PLATFORM_V6 = 5,
22
+ PLATFORM_V7 = 6,
23
+ PLATFORM_V8 = 7,
24
+ }
25
+
26
+ impl TryFrom<JsValue> for PlatformVersionWASM {
27
+ type Error = JsValue;
28
+ fn try_from(value: JsValue) -> Result<PlatformVersionWASM, Self::Error> {
29
+ match value.is_string() {
30
+ true => match value.as_string() {
31
+ None => Err(JsValue::from("cannot read value from enum")),
32
+ Some(enum_val) => match enum_val.to_lowercase().as_str() {
33
+ "platform_v1" => Ok(PlatformVersionWASM::PLATFORM_V1),
34
+ "platform_v2" => Ok(PlatformVersionWASM::PLATFORM_V2),
35
+ "platform_v3" => Ok(PlatformVersionWASM::PLATFORM_V3),
36
+ "platform_v4" => Ok(PlatformVersionWASM::PLATFORM_V4),
37
+ "platform_v5" => Ok(PlatformVersionWASM::PLATFORM_V5),
38
+ "platform_v6" => Ok(PlatformVersionWASM::PLATFORM_V6),
39
+ "platform_v7" => Ok(PlatformVersionWASM::PLATFORM_V7),
40
+ "platform_v8" => Ok(PlatformVersionWASM::PLATFORM_V8),
41
+ _ => Err(JsValue::from(format!(
42
+ "unknown platform version value: {}",
43
+ enum_val
44
+ ))),
45
+ },
46
+ },
47
+ false => match value.as_f64() {
48
+ None => Err(JsValue::from("cannot read value from enum")),
49
+ Some(enum_val) => match enum_val as u8 {
50
+ 0 => Ok(PlatformVersionWASM::PLATFORM_V1),
51
+ 1 => Ok(PlatformVersionWASM::PLATFORM_V2),
52
+ 2 => Ok(PlatformVersionWASM::PLATFORM_V3),
53
+ 3 => Ok(PlatformVersionWASM::PLATFORM_V4),
54
+ 4 => Ok(PlatformVersionWASM::PLATFORM_V5),
55
+ 5 => Ok(PlatformVersionWASM::PLATFORM_V6),
56
+ 6 => Ok(PlatformVersionWASM::PLATFORM_V7),
57
+ 7 => Ok(PlatformVersionWASM::PLATFORM_V8),
58
+ _ => Err(JsValue::from(format!(
59
+ "unknown platform version value: {}",
60
+ enum_val
61
+ ))),
62
+ },
63
+ },
64
+ }
65
+ }
66
+ }
67
+
68
+ impl From<PlatformVersionWASM> for String {
69
+ fn from(version: PlatformVersionWASM) -> String {
70
+ match version {
71
+ PlatformVersionWASM::PLATFORM_V1 => String::from("PLATFORM_V1"),
72
+ PlatformVersionWASM::PLATFORM_V2 => String::from("PLATFORM_V2"),
73
+ PlatformVersionWASM::PLATFORM_V3 => String::from("PLATFORM_V3"),
74
+ PlatformVersionWASM::PLATFORM_V4 => String::from("PLATFORM_V4"),
75
+ PlatformVersionWASM::PLATFORM_V5 => String::from("PLATFORM_V5"),
76
+ PlatformVersionWASM::PLATFORM_V6 => String::from("PLATFORM_V6"),
77
+ PlatformVersionWASM::PLATFORM_V7 => String::from("PLATFORM_V7"),
78
+ PlatformVersionWASM::PLATFORM_V8 => String::from("PLATFORM_V8"),
79
+ }
80
+ }
23
81
  }
24
82
 
25
83
  impl From<PlatformVersionWASM> for PlatformVersion {
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_identity"
3
- version = "0.1.0"
3
+ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
@@ -11,10 +11,5 @@ wasm-bindgen = { version = "=0.2.100", features = ["serde-serialize"] }
11
11
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
12
12
  "identity-serialization"
13
13
  ]}
14
- serde-wasm-bindgen = { git = "https://github.com/QuantumExplorer/serde-wasm-bindgen", branch = "feat/not_human_readable" }
15
- pshenmic_dpp_public_key = { path = "../public_key" }
14
+ pshenmic_dpp_public_key = { path = "../identity_public_key" }
16
15
  pshenmic_dpp_utils = { path = "../utils" }
17
-
18
- [profile.release]
19
- lto = true
20
- opt-level = 'z'
@@ -2,10 +2,12 @@ use dpp::identifier::Identifier;
2
2
  use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0};
3
3
  use dpp::identity::{Identity, KeyID};
4
4
  use dpp::platform_value::string_encoding::Encoding::Base58;
5
+ use dpp::prelude::IdentityPublicKey;
5
6
  use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
6
7
  use dpp::version::PlatformVersion;
7
8
  use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
8
- use pshenmic_dpp_utils::WithJsError;
9
+ use pshenmic_dpp_utils::{WithJsError, identifier_from_js_value};
10
+ use std::collections::BTreeMap;
9
11
  use wasm_bindgen::JsValue;
10
12
  use wasm_bindgen::prelude::wasm_bindgen;
11
13
 
@@ -29,10 +31,10 @@ impl IdentityWASM {
29
31
  }
30
32
 
31
33
  #[wasm_bindgen(js_name = "setId")]
32
- pub fn set_id(&mut self, js_identifier: String) {
33
- let identifier = Identifier::from_string(&*js_identifier, Base58).unwrap();
34
+ pub fn set_id(&mut self, js_identifier: JsValue) -> Result<(), JsValue> {
35
+ let identifier = identifier_from_js_value(&js_identifier)?;
34
36
 
35
- self.0.set_id(identifier);
37
+ Ok(self.0.set_id(identifier))
36
38
  }
37
39
 
38
40
  #[wasm_bindgen(js_name = "setBalance")]
@@ -46,17 +48,15 @@ impl IdentityWASM {
46
48
  }
47
49
 
48
50
  #[wasm_bindgen(js_name = "addPublicKey")]
49
- pub fn set_public_key(&mut self, public_key: IdentityPublicKeyWASM) {
50
- self.0.add_public_key(public_key.into());
51
+ pub fn add_public_key(&mut self, public_key: &IdentityPublicKeyWASM) {
52
+ self.0.add_public_key(public_key.clone().into());
51
53
  }
52
54
 
53
55
  // GETTERS
54
56
 
55
57
  #[wasm_bindgen(js_name = "getId")]
56
- pub fn get_id(&self) -> String {
57
- let id = self.0.id();
58
-
59
- id.to_string(Base58)
58
+ pub fn get_id(&self) -> Vec<u8> {
59
+ self.0.id().to_vec()
60
60
  }
61
61
 
62
62
  #[wasm_bindgen(js_name = "getBalance")]
@@ -76,10 +76,15 @@ impl IdentityWASM {
76
76
  }
77
77
 
78
78
  #[wasm_bindgen(js_name = "getPublicKeys")]
79
- pub fn get_public_keys(&self) -> JsValue {
80
- let keys = self.0.public_keys();
81
-
82
- serde_wasm_bindgen::to_value(keys).unwrap()
79
+ pub fn get_public_keys(&self) -> Vec<IdentityPublicKeyWASM> {
80
+ let keys = self
81
+ .0
82
+ .public_keys()
83
+ .iter()
84
+ .map(|(_index, key)| IdentityPublicKeyWASM::from(key.clone()))
85
+ .collect();
86
+
87
+ keys
83
88
  }
84
89
 
85
90
  #[wasm_bindgen(js_name = "toBytes")]
@@ -95,3 +100,9 @@ impl IdentityWASM {
95
100
  }
96
101
  }
97
102
  }
103
+
104
+ impl IdentityWASM {
105
+ pub fn get_rs_public_keys(&self) -> BTreeMap<KeyID, IdentityPublicKey> {
106
+ self.0.public_keys().clone()
107
+ }
108
+ }
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_public_key"
3
- version = "0.1.0"
3
+ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
@@ -12,8 +12,4 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
12
12
  "identity-value-conversion",
13
13
  ]}
14
14
  pshenmic_dpp_enums = {path = "../enums"}
15
- pshenmic_dpp_utils = {path = "../utils"}
16
-
17
- [profile.release]
18
- lto = true
19
- opt-level = 'z'
15
+ pshenmic_dpp_utils = {path = "../utils"}
@@ -1,3 +1,6 @@
1
+ use dpp::dashcore::Network;
2
+ use dpp::dashcore::secp256k1::hashes::hex::{Case, DisplayHex};
3
+ use dpp::identity::hash::IdentityPublicKeyHashMethodsV0;
1
4
  use dpp::identity::identity_public_key::accessors::v0::{
2
5
  IdentityPublicKeyGettersV0, IdentityPublicKeySettersV0,
3
6
  };
@@ -9,6 +12,7 @@ use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
9
12
  use pshenmic_dpp_enums::keys::key_type::KeyTypeWASM;
10
13
  use pshenmic_dpp_enums::keys::purpose::PurposeWASM;
11
14
  use pshenmic_dpp_enums::keys::security_level::SecurityLevelWASM;
15
+ use pshenmic_dpp_enums::network::NetworkWASM;
12
16
  use pshenmic_dpp_utils::WithJsError;
13
17
  use wasm_bindgen::JsValue;
14
18
  use wasm_bindgen::prelude::wasm_bindgen;
@@ -34,46 +38,69 @@ impl IdentityPublicKeyWASM {
34
38
  #[wasm_bindgen(constructor)]
35
39
  pub fn new(
36
40
  id: u32,
37
- purpose: PurposeWASM,
38
- security_level: SecurityLevelWASM,
39
- key_type: KeyTypeWASM,
41
+ js_purpose: JsValue,
42
+ js_security_level: JsValue,
43
+ js_key_type: JsValue,
40
44
  read_only: bool,
41
45
  binary_data: &str,
42
46
  disabled_at: Option<TimestampMillis>,
43
- ) -> Self {
44
- IdentityPublicKeyWASM(IdentityPublicKey::from(IdentityPublicKeyV0 {
45
- id,
46
- purpose: Purpose::from(purpose),
47
- security_level: SecurityLevel::from(security_level),
48
- contract_bounds: None,
49
- key_type: KeyType::from(key_type),
50
- read_only: read_only,
51
- data: BinaryData::from_string(binary_data, Hex).unwrap(),
52
- disabled_at,
53
- }))
47
+ ) -> Result<Self, JsValue> {
48
+ let purpose = PurposeWASM::try_from(js_purpose)?;
49
+ let security_level = SecurityLevelWASM::try_from(js_security_level)?;
50
+ let key_type = KeyTypeWASM::try_from(js_key_type)?;
51
+
52
+ Ok(IdentityPublicKeyWASM(IdentityPublicKey::from(
53
+ IdentityPublicKeyV0 {
54
+ id,
55
+ purpose: Purpose::from(purpose),
56
+ security_level: SecurityLevel::from(security_level),
57
+ contract_bounds: None,
58
+ key_type: KeyType::from(key_type),
59
+ read_only,
60
+ data: BinaryData::from_string(binary_data, Hex).unwrap(),
61
+ disabled_at,
62
+ },
63
+ )))
54
64
  }
55
65
  }
56
66
 
57
67
  #[wasm_bindgen]
58
68
  impl IdentityPublicKeyWASM {
69
+ #[wasm_bindgen(js_name = "validatePrivateKey")]
70
+ pub fn validate_private_key(
71
+ &self,
72
+ js_private_key_bytes: Vec<u8>,
73
+ js_network: JsValue,
74
+ ) -> Result<bool, JsValue> {
75
+ let mut private_key_bytes = [0u8; 32];
76
+ let len = js_private_key_bytes.len().min(32);
77
+ private_key_bytes[..len].copy_from_slice(&js_private_key_bytes[..len]);
78
+
79
+ let network = Network::from(NetworkWASM::try_from(js_network)?);
80
+
81
+ self.0
82
+ .validate_private_key_bytes(&private_key_bytes, network)
83
+ .with_js_error()
84
+ }
85
+
59
86
  #[wasm_bindgen(js_name = getKeyId)]
60
87
  pub fn get_key_id(&self) -> u32 {
61
88
  self.0.id()
62
89
  }
63
90
 
64
91
  #[wasm_bindgen(js_name = getPurpose)]
65
- pub fn get_purpose(&self) -> PurposeWASM {
66
- PurposeWASM::from(self.0.purpose())
92
+ pub fn get_purpose(&self) -> String {
93
+ PurposeWASM::from(self.0.purpose()).into()
67
94
  }
68
95
 
69
96
  #[wasm_bindgen(js_name = getSecurityLevel)]
70
- pub fn get_security_level(&self) -> SecurityLevelWASM {
71
- SecurityLevelWASM::from(self.0.security_level())
97
+ pub fn get_security_level(&self) -> String {
98
+ SecurityLevelWASM::from(self.0.security_level()).into()
72
99
  }
73
100
 
74
101
  #[wasm_bindgen(js_name = getKeyType)]
75
- pub fn get_key_type(&self) -> KeyTypeWASM {
76
- KeyTypeWASM::from(self.0.key_type())
102
+ pub fn get_key_type(&self) -> String {
103
+ KeyTypeWASM::from(self.0.key_type()).into()
77
104
  }
78
105
 
79
106
  #[wasm_bindgen(js_name = getReadOnly)]
@@ -97,19 +124,26 @@ impl IdentityPublicKeyWASM {
97
124
  }
98
125
 
99
126
  #[wasm_bindgen(js_name = setPurpose)]
100
- pub fn set_purpose(&mut self, purpose: PurposeWASM) {
101
- self.0.set_purpose(Purpose::from(purpose))
127
+ pub fn set_purpose(&mut self, purpose: JsValue) -> Result<(), JsValue> {
128
+ Ok(self
129
+ .0
130
+ .set_purpose(Purpose::from(PurposeWASM::try_from(purpose)?)))
102
131
  }
103
132
 
104
133
  #[wasm_bindgen(js_name = setSecurityLevel)]
105
- pub fn set_security_level(&mut self, security_level: SecurityLevelWASM) {
106
- self.0
107
- .set_security_level(SecurityLevel::from(security_level))
134
+ pub fn set_security_level(&mut self, security_level: JsValue) -> Result<(), JsValue> {
135
+ Ok(self
136
+ .0
137
+ .set_security_level(SecurityLevel::from(SecurityLevelWASM::try_from(
138
+ security_level,
139
+ )?)))
108
140
  }
109
141
 
110
142
  #[wasm_bindgen(js_name = setKeyType)]
111
- pub fn set_key_type(&mut self, key_type: KeyTypeWASM) {
112
- self.0.set_key_type(KeyType::from(key_type))
143
+ pub fn set_key_type(&mut self, key_type: JsValue) -> Result<(), JsValue> {
144
+ Ok(self
145
+ .0
146
+ .set_key_type(KeyType::from(KeyTypeWASM::try_from(key_type)?)))
113
147
  }
114
148
 
115
149
  #[wasm_bindgen(js_name = setReadOnly)]
@@ -120,6 +154,7 @@ impl IdentityPublicKeyWASM {
120
154
  #[wasm_bindgen(js_name = setData)]
121
155
  pub fn set_data(&mut self, binary_data: &str) {
122
156
  let data = BinaryData::from_string(binary_data, Hex).unwrap();
157
+
123
158
  self.0.set_data(data)
124
159
  }
125
160
 
@@ -128,6 +163,18 @@ impl IdentityPublicKeyWASM {
128
163
  self.0.set_disabled_at(disabled_at)
129
164
  }
130
165
 
166
+ #[wasm_bindgen(js_name = "getPublicKeyHash")]
167
+ pub fn public_key_hash(&self) -> Result<String, JsValue> {
168
+ let hash = self
169
+ .0
170
+ .public_key_hash()
171
+ .with_js_error()
172
+ .map(|slice| slice.to_vec())?
173
+ .to_hex_string(Case::Lower);
174
+
175
+ Ok(hash)
176
+ }
177
+
131
178
  #[wasm_bindgen(js_name = toBytes)]
132
179
  pub fn to_byes(&self) -> Result<Vec<u8>, JsValue> {
133
180
  self.0.serialize_to_bytes().with_js_error()
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_identity_transitions"
3
- version = "0.1.0"
3
+ version.workspace = true
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
@@ -12,10 +12,6 @@ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-
12
12
  "state-transition-signing"
13
13
  ]}
14
14
  pshenmic_dpp_utils = {path = "../utils"}
15
- pshenmic_dpp_public_key = {path = "../public_key"}
15
+ pshenmic_dpp_public_key = {path = "../identity_public_key" }
16
16
  pshenmic_dpp_state_transition = {path = "../state_transition"}
17
- pshenmic_dpp_enums = {path = "../enums"}
18
-
19
- [profile.release]
20
- lto = true
21
- opt-level = 'z'
17
+ pshenmic_dpp_enums = {path = "../enums"}
@@ -76,13 +76,15 @@ impl IdentityCreateTransitionWASM {
76
76
 
77
77
  #[wasm_bindgen(js_name = "fromStateTransition")]
78
78
  pub fn from_state_transition(
79
- st: StateTransitionWASM,
79
+ st: &StateTransitionWASM,
80
80
  ) -> Result<IdentityCreateTransitionWASM, JsValue> {
81
- let rs_st: StateTransition = st.into();
81
+ let rs_st: StateTransition = st.clone().into();
82
82
 
83
83
  match rs_st {
84
84
  StateTransition::IdentityCreate(st) => Ok(IdentityCreateTransitionWASM(st)),
85
- _ => Err(JsValue::from_str(&"Invalid state transition type)")),
85
+ _ => Err(JsValue::from_str(
86
+ &"Invalid state document_transition type)",
87
+ )),
86
88
  }
87
89
  }
88
90
 
@@ -11,6 +11,7 @@ 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 wasm_bindgen::JsValue;
14
15
  use wasm_bindgen::prelude::wasm_bindgen;
15
16
 
16
17
  #[wasm_bindgen(js_name = "IdentityPublicKeyInCreationWASM")]
@@ -57,8 +58,8 @@ impl IdentityPublicKeyInCreationWASM {
57
58
  security_level: SecurityLevelWASM,
58
59
  key_type: KeyTypeWASM,
59
60
  read_only: bool,
60
- binary_data: &str,
61
- signature: &str,
61
+ binary_data: Vec<u8>,
62
+ signature: Vec<u8>,
62
63
  ) -> IdentityPublicKeyInCreationWASM {
63
64
  IdentityPublicKeyInCreationWASM(IdentityPublicKeyInCreation::V0(
64
65
  IdentityPublicKeyInCreationV0 {
@@ -68,19 +69,19 @@ impl IdentityPublicKeyInCreationWASM {
68
69
  security_level: SecurityLevel::from(security_level),
69
70
  contract_bounds: None,
70
71
  read_only,
71
- data: BinaryData::from_string(binary_data, Hex).unwrap(),
72
- signature: BinaryData::from_string(signature, Hex).unwrap(),
72
+ data: BinaryData::from(binary_data),
73
+ signature: BinaryData::from(signature),
73
74
  },
74
75
  ))
75
76
  }
76
77
 
77
78
  #[wasm_bindgen(js_name = toIdentityPublicKey)]
78
- pub fn to_identity_public_key(&self) -> IdentityPublicKeyWASM {
79
+ pub fn to_identity_public_key(&self) -> Result<IdentityPublicKeyWASM, JsValue> {
79
80
  IdentityPublicKeyWASM::new(
80
81
  self.0.id(),
81
- self.0.purpose().into(),
82
- self.0.security_level().into(),
83
- self.0.key_type().into(),
82
+ JsValue::from(PurposeWASM::from(self.0.purpose())),
83
+ JsValue::from(SecurityLevelWASM::from(self.0.security_level())),
84
+ JsValue::from(KeyTypeWASM::from(self.0.key_type())),
84
85
  self.0.read_only(),
85
86
  self.0.data().to_string(Hex).as_str(),
86
87
  None,
@@ -93,18 +94,18 @@ impl IdentityPublicKeyInCreationWASM {
93
94
  }
94
95
 
95
96
  #[wasm_bindgen(js_name = getPurpose)]
96
- pub fn get_purpose(&self) -> PurposeWASM {
97
- PurposeWASM::from(self.0.purpose())
97
+ pub fn get_purpose(&self) -> String {
98
+ PurposeWASM::from(self.0.purpose()).into()
98
99
  }
99
100
 
100
101
  #[wasm_bindgen(js_name = getSecurityLevel)]
101
- pub fn get_security_level(&self) -> SecurityLevelWASM {
102
- SecurityLevelWASM::from(self.0.security_level())
102
+ pub fn get_security_level(&self) -> String {
103
+ SecurityLevelWASM::from(self.0.security_level()).into()
103
104
  }
104
105
 
105
106
  #[wasm_bindgen(js_name = getKeyType)]
106
- pub fn get_key_type(&self) -> KeyTypeWASM {
107
- KeyTypeWASM::from(self.0.key_type())
107
+ pub fn get_key_type(&self) -> String {
108
+ KeyTypeWASM::from(self.0.key_type()).into()
108
109
  }
109
110
 
110
111
  #[wasm_bindgen(js_name = getReadOnly)]
@@ -123,14 +124,17 @@ impl IdentityPublicKeyInCreationWASM {
123
124
  }
124
125
 
125
126
  #[wasm_bindgen(js_name = setPurpose)]
126
- pub fn set_purpose(&mut self, purpose: PurposeWASM) {
127
- self.0.set_purpose(Purpose::from(purpose))
127
+ pub fn set_purpose(&mut self, js_purpose: JsValue) -> Result<(), JsValue> {
128
+ let purpose = PurposeWASM::try_from(js_purpose)?;
129
+ Ok(self.0.set_purpose(Purpose::from(purpose)))
128
130
  }
129
131
 
130
132
  #[wasm_bindgen(js_name = setSecurityLevel)]
131
- pub fn set_security_level(&mut self, security_level: SecurityLevelWASM) {
132
- self.0
133
- .set_security_level(SecurityLevel::from(security_level))
133
+ pub fn set_security_level(&mut self, js_security_level: JsValue) -> Result<(), JsValue> {
134
+ let security_level = SecurityLevelWASM::try_from(js_security_level)?;
135
+ Ok(self
136
+ .0
137
+ .set_security_level(SecurityLevel::from(security_level)))
134
138
  }
135
139
 
136
140
  #[wasm_bindgen(js_name = setReadOnly)]
@@ -139,8 +143,8 @@ impl IdentityPublicKeyInCreationWASM {
139
143
  }
140
144
 
141
145
  #[wasm_bindgen(js_name = setData)]
142
- pub fn set_data(&mut self, binary_data: &str) {
143
- let data = BinaryData::from_string(binary_data, Hex).unwrap();
146
+ pub fn set_data(&mut self, binary_data: Vec<u8>) {
147
+ let data = BinaryData::from(binary_data);
144
148
  self.0.set_data(data)
145
149
  }
146
150
  }
@@ -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]
@@ -9,8 +9,4 @@ crate-type = ["cdylib", "lib"]
9
9
  [dependencies]
10
10
  dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = [
11
11
  "bls-signatures",
12
- ]}
13
-
14
- [profile.release]
15
- lto = true
16
- opt-level = 'z'
12
+ ]}