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,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,79 @@ 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")]
14
+ #[derive(Default)]
13
15
  #[allow(non_camel_case_types)]
14
16
  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,
17
+ #[default]
18
+ PLATFORM_V1 = 0,
19
+ PLATFORM_V2 = 1,
20
+ PLATFORM_V3 = 2,
21
+ PLATFORM_V4 = 3,
22
+ PLATFORM_V5 = 4,
23
+ PLATFORM_V6 = 5,
24
+ PLATFORM_V7 = 6,
25
+ PLATFORM_V8 = 7,
26
+ }
27
+
28
+ impl TryFrom<JsValue> for PlatformVersionWASM {
29
+ type Error = JsValue;
30
+ fn try_from(value: JsValue) -> Result<PlatformVersionWASM, Self::Error> {
31
+ match value.is_string() {
32
+ true => match value.as_string() {
33
+ None => Err(JsValue::from("cannot read value from enum")),
34
+ Some(enum_val) => match enum_val.to_lowercase().as_str() {
35
+ "platform_v1" => Ok(PlatformVersionWASM::PLATFORM_V1),
36
+ "platform_v2" => Ok(PlatformVersionWASM::PLATFORM_V2),
37
+ "platform_v3" => Ok(PlatformVersionWASM::PLATFORM_V3),
38
+ "platform_v4" => Ok(PlatformVersionWASM::PLATFORM_V4),
39
+ "platform_v5" => Ok(PlatformVersionWASM::PLATFORM_V5),
40
+ "platform_v6" => Ok(PlatformVersionWASM::PLATFORM_V6),
41
+ "platform_v7" => Ok(PlatformVersionWASM::PLATFORM_V7),
42
+ "platform_v8" => Ok(PlatformVersionWASM::PLATFORM_V8),
43
+ _ => Err(JsValue::from(format!(
44
+ "unknown platform version value: {}",
45
+ enum_val
46
+ ))),
47
+ },
48
+ },
49
+ false => match value.as_f64() {
50
+ None => Err(JsValue::from("cannot read value from enum")),
51
+ Some(enum_val) => match enum_val as u8 {
52
+ 0 => Ok(PlatformVersionWASM::PLATFORM_V1),
53
+ 1 => Ok(PlatformVersionWASM::PLATFORM_V2),
54
+ 2 => Ok(PlatformVersionWASM::PLATFORM_V3),
55
+ 3 => Ok(PlatformVersionWASM::PLATFORM_V4),
56
+ 4 => Ok(PlatformVersionWASM::PLATFORM_V5),
57
+ 5 => Ok(PlatformVersionWASM::PLATFORM_V6),
58
+ 6 => Ok(PlatformVersionWASM::PLATFORM_V7),
59
+ 7 => Ok(PlatformVersionWASM::PLATFORM_V8),
60
+ _ => Err(JsValue::from(format!(
61
+ "unknown platform version value: {}",
62
+ enum_val
63
+ ))),
64
+ },
65
+ },
66
+ }
67
+ }
68
+ }
69
+
70
+ impl From<PlatformVersionWASM> for String {
71
+ fn from(version: PlatformVersionWASM) -> String {
72
+ match version {
73
+ PlatformVersionWASM::PLATFORM_V1 => String::from("PLATFORM_V1"),
74
+ PlatformVersionWASM::PLATFORM_V2 => String::from("PLATFORM_V2"),
75
+ PlatformVersionWASM::PLATFORM_V3 => String::from("PLATFORM_V3"),
76
+ PlatformVersionWASM::PLATFORM_V4 => String::from("PLATFORM_V4"),
77
+ PlatformVersionWASM::PLATFORM_V5 => String::from("PLATFORM_V5"),
78
+ PlatformVersionWASM::PLATFORM_V6 => String::from("PLATFORM_V6"),
79
+ PlatformVersionWASM::PLATFORM_V7 => String::from("PLATFORM_V7"),
80
+ PlatformVersionWASM::PLATFORM_V8 => String::from("PLATFORM_V8"),
81
+ }
82
+ }
23
83
  }
24
84
 
25
85
  impl From<PlatformVersionWASM> for PlatformVersion {
@@ -0,0 +1,72 @@
1
+ use dpp::withdrawal::Pooling;
2
+ use wasm_bindgen::JsValue;
3
+ use wasm_bindgen::prelude::wasm_bindgen;
4
+
5
+ #[wasm_bindgen]
6
+ pub enum PoolingWASM {
7
+ Never = 0,
8
+ IfAvailable = 1,
9
+ Standard = 2,
10
+ }
11
+
12
+ impl From<PoolingWASM> for Pooling {
13
+ fn from(pooling: PoolingWASM) -> Self {
14
+ match pooling {
15
+ PoolingWASM::Never => Pooling::Never,
16
+ PoolingWASM::IfAvailable => Pooling::IfAvailable,
17
+ PoolingWASM::Standard => Pooling::Standard,
18
+ }
19
+ }
20
+ }
21
+
22
+ impl From<Pooling> for PoolingWASM {
23
+ fn from(pooling: Pooling) -> Self {
24
+ match pooling {
25
+ Pooling::Never => PoolingWASM::Never,
26
+ Pooling::IfAvailable => PoolingWASM::IfAvailable,
27
+ Pooling::Standard => PoolingWASM::Standard,
28
+ }
29
+ }
30
+ }
31
+
32
+ impl TryFrom<JsValue> for PoolingWASM {
33
+ type Error = JsValue;
34
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
35
+ match value.is_string() {
36
+ true => match value.as_string() {
37
+ None => Err(JsValue::from("cannot read value from enum")),
38
+ Some(enum_val) => match enum_val.to_lowercase().as_str() {
39
+ "never" => Ok(PoolingWASM::Never),
40
+ "ifavailable" => Ok(PoolingWASM::IfAvailable),
41
+ "standard" => Ok(PoolingWASM::Standard),
42
+ _ => Err(JsValue::from(format!(
43
+ "unsupported pooling value ({})",
44
+ enum_val
45
+ ))),
46
+ },
47
+ },
48
+ false => match value.as_f64() {
49
+ None => Err(JsValue::from("cannot read value from enum")),
50
+ Some(enum_val) => match enum_val as u8 {
51
+ 0 => Ok(PoolingWASM::Never),
52
+ 1 => Ok(PoolingWASM::IfAvailable),
53
+ 2 => Ok(PoolingWASM::Standard),
54
+ _ => Err(JsValue::from(format!(
55
+ "unsupported pooling value ({})",
56
+ enum_val
57
+ ))),
58
+ },
59
+ },
60
+ }
61
+ }
62
+ }
63
+
64
+ impl From<PoolingWASM> for String {
65
+ fn from(pooling_wasm: PoolingWASM) -> String {
66
+ match pooling_wasm {
67
+ PoolingWASM::Never => String::from("Never"),
68
+ PoolingWASM::IfAvailable => String::from("IfAvailable"),
69
+ PoolingWASM::Standard => String::from("Standard"),
70
+ }
71
+ }
72
+ }
@@ -0,0 +1,9 @@
1
+ [package]
2
+ name = "pshenmic_dpp_identifier"
3
+ version = "0.1.0"
4
+ edition = "2024"
5
+
6
+ [dependencies]
7
+ wasm-bindgen = { version = "=0.2.100", default-features = false, features = ["serde-serialize"] }
8
+ dpp = { git = "https://github.com/dashpay/platform", branch = "master", default-features = false, features = []}
9
+ pshenmic_dpp_utils = { path = "../utils" }
@@ -0,0 +1,105 @@
1
+ use dpp::platform_value::string_encoding::Encoding::{Base58, Base64, Hex};
2
+ use dpp::prelude::Identifier;
3
+ use pshenmic_dpp_utils::{IntoWasm, get_class_name, identifier_from_js_value};
4
+ use wasm_bindgen::prelude::*;
5
+
6
+ #[derive(Copy, Clone)]
7
+ #[wasm_bindgen(js_name = "IdentifierWASM")]
8
+ pub struct IdentifierWASM(Identifier);
9
+
10
+ impl From<IdentifierWASM> for Identifier {
11
+ fn from(identifier: IdentifierWASM) -> Self {
12
+ identifier.0
13
+ }
14
+ }
15
+
16
+ impl From<Identifier> for IdentifierWASM {
17
+ fn from(identifier: Identifier) -> Self {
18
+ IdentifierWASM(identifier)
19
+ }
20
+ }
21
+
22
+ impl From<&IdentifierWASM> for Identifier {
23
+ fn from(identifier: &IdentifierWASM) -> Self {
24
+ identifier.clone().into()
25
+ }
26
+ }
27
+
28
+ impl TryFrom<JsValue> for IdentifierWASM {
29
+ type Error = JsValue;
30
+ fn try_from(value: JsValue) -> Result<Self, Self::Error> {
31
+ let identifier = match get_class_name(&value).as_str() {
32
+ "IdentifierWASM" => value.to_wasm::<IdentifierWASM>("IdentifierWASM")?.clone(),
33
+ _ => identifier_from_js_value(&value)?.into(),
34
+ };
35
+
36
+ Ok(identifier)
37
+ }
38
+ }
39
+
40
+ impl TryFrom<&JsValue> for IdentifierWASM {
41
+ type Error = JsValue;
42
+ fn try_from(value: &JsValue) -> Result<Self, Self::Error> {
43
+ IdentifierWASM::try_from(value.clone())
44
+ }
45
+ }
46
+
47
+ #[wasm_bindgen]
48
+ impl IdentifierWASM {
49
+ #[wasm_bindgen(constructor)]
50
+ pub fn new(js_identifier: &JsValue) -> Result<IdentifierWASM, JsValue> {
51
+ IdentifierWASM::try_from(js_identifier)
52
+ }
53
+
54
+ #[wasm_bindgen(js_name = "base58")]
55
+ pub fn get_base58(&self) -> String {
56
+ self.0.to_string(Base58)
57
+ }
58
+
59
+ #[wasm_bindgen(js_name = "base64")]
60
+ pub fn get_base64(&self) -> String {
61
+ self.0.to_string(Base64)
62
+ }
63
+
64
+ #[wasm_bindgen(js_name = "hex")]
65
+ pub fn get_hex(&self) -> String {
66
+ self.0.to_string(Hex)
67
+ }
68
+
69
+ #[wasm_bindgen(js_name = "bytes")]
70
+ pub fn get_bytes(&self) -> Vec<u8> {
71
+ self.0.to_vec()
72
+ }
73
+
74
+ #[wasm_bindgen(js_name = "fromBase58")]
75
+ pub fn from_base58(base58: String) -> Result<IdentifierWASM, JsValue> {
76
+ let identitfier = Identifier::from_string(base58.as_str(), Base58)
77
+ .map_err(|err| JsValue::from(err.to_string()))?;
78
+
79
+ Ok(IdentifierWASM(identitfier))
80
+ }
81
+
82
+ #[wasm_bindgen(js_name = "fromBase64")]
83
+ pub fn from_base64(base64: String) -> Result<IdentifierWASM, JsValue> {
84
+ let identitfier = Identifier::from_string(base64.as_str(), Base64)
85
+ .map_err(|err| JsValue::from(err.to_string()))?;
86
+
87
+ Ok(IdentifierWASM(identitfier))
88
+ }
89
+
90
+ #[wasm_bindgen(js_name = "fromHex")]
91
+ pub fn from_hex(hex: String) -> Result<IdentifierWASM, JsValue> {
92
+ let identitfier = Identifier::from_string(hex.as_str(), Hex)
93
+ .map_err(|err| JsValue::from(err.to_string()))?;
94
+
95
+ Ok(IdentifierWASM(identitfier))
96
+ }
97
+
98
+ #[wasm_bindgen(js_name = "fromBytes")]
99
+ pub fn from_bytes(bytes: Vec<u8>) -> Result<IdentifierWASM, JsValue> {
100
+ let identifier =
101
+ Identifier::from_vec(bytes).map_err(|err| JsValue::from(err.to_string()))?;
102
+
103
+ Ok(IdentifierWASM(identifier))
104
+ }
105
+ }
@@ -1,16 +1,16 @@
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]
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-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" }
16
- pshenmic_dpp_utils = { path = "../utils" }
14
+ pshenmic_dpp_public_key = { path = "../identity_public_key" }
15
+ pshenmic_dpp_identifier = { path = "../identifier" }
16
+ pshenmic_dpp_utils = { path = "../utils" }
@@ -1,11 +1,12 @@
1
- use dpp::identifier::Identifier;
2
1
  use dpp::identity::accessors::{IdentityGettersV0, IdentitySettersV0};
3
2
  use dpp::identity::{Identity, KeyID};
4
- use dpp::platform_value::string_encoding::Encoding::Base58;
3
+ use dpp::prelude::IdentityPublicKey;
5
4
  use dpp::serialization::{PlatformDeserializable, PlatformSerializable};
6
5
  use dpp::version::PlatformVersion;
6
+ use pshenmic_dpp_identifier::IdentifierWASM;
7
7
  use pshenmic_dpp_public_key::IdentityPublicKeyWASM;
8
8
  use pshenmic_dpp_utils::WithJsError;
9
+ use std::collections::BTreeMap;
9
10
  use wasm_bindgen::JsValue;
10
11
  use wasm_bindgen::prelude::wasm_bindgen;
11
12
 
@@ -15,24 +16,20 @@ pub struct IdentityWASM(Identity);
15
16
  #[wasm_bindgen]
16
17
  impl IdentityWASM {
17
18
  #[wasm_bindgen(constructor)]
18
- pub fn new(js_identifier: String) -> Result<IdentityWASM, JsValue> {
19
- let identifier = Identifier::from_string(&*js_identifier, Base58);
19
+ pub fn new(js_identifier: &JsValue) -> Result<IdentityWASM, JsValue> {
20
+ let identifier: IdentifierWASM = js_identifier.try_into()?;
20
21
 
21
- let identity =
22
- Identity::create_basic_identity(identifier.unwrap(), PlatformVersion::first())
23
- .with_js_error();
22
+ let identity = Identity::create_basic_identity(identifier.into(), PlatformVersion::first())
23
+ .with_js_error()?;
24
24
 
25
- match identity {
26
- Ok(identity) => Ok(IdentityWASM(identity)),
27
- Err(err) => Err(err),
28
- }
25
+ Ok(IdentityWASM(identity))
29
26
  }
30
27
 
31
28
  #[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
-
35
- self.0.set_id(identifier);
29
+ pub fn set_id(&mut self, js_identifier: &JsValue) -> Result<(), JsValue> {
30
+ Ok(self
31
+ .0
32
+ .set_id(IdentifierWASM::try_from(js_identifier)?.into()))
36
33
  }
37
34
 
38
35
  #[wasm_bindgen(js_name = "setBalance")]
@@ -46,17 +43,15 @@ impl IdentityWASM {
46
43
  }
47
44
 
48
45
  #[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());
46
+ pub fn add_public_key(&mut self, public_key: &IdentityPublicKeyWASM) {
47
+ self.0.add_public_key(public_key.clone().into());
51
48
  }
52
49
 
53
50
  // GETTERS
54
51
 
55
52
  #[wasm_bindgen(js_name = "getId")]
56
- pub fn get_id(&self) -> String {
57
- let id = self.0.id();
58
-
59
- id.to_string(Base58)
53
+ pub fn get_id(&self) -> IdentifierWASM {
54
+ self.0.id().into()
60
55
  }
61
56
 
62
57
  #[wasm_bindgen(js_name = "getBalance")]
@@ -76,10 +71,15 @@ impl IdentityWASM {
76
71
  }
77
72
 
78
73
  #[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()
74
+ pub fn get_public_keys(&self) -> Vec<IdentityPublicKeyWASM> {
75
+ let keys = self
76
+ .0
77
+ .public_keys()
78
+ .iter()
79
+ .map(|(_index, key)| IdentityPublicKeyWASM::from(key.clone()))
80
+ .collect();
81
+
82
+ keys
83
83
  }
84
84
 
85
85
  #[wasm_bindgen(js_name = "toBytes")]
@@ -95,3 +95,9 @@ impl IdentityWASM {
95
95
  }
96
96
  }
97
97
  }
98
+
99
+ impl IdentityWASM {
100
+ pub fn get_rs_public_keys(&self) -> BTreeMap<KeyID, IdentityPublicKey> {
101
+ self.0.public_keys().clone()
102
+ }
103
+ }
@@ -1,13 +1,13 @@
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]
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
  ]}
@@ -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,17 +1,21 @@
1
1
  [package]
2
2
  name = "pshenmic_dpp_identity_transitions"
3
- version = "0.1.0"
4
3
  edition = "2024"
4
+ version.workspace = true
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
  "state-transition-signing"
13
13
  ]}
14
+ js-sys = "0.3.53"
14
15
  pshenmic_dpp_utils = {path = "../utils"}
15
- pshenmic_dpp_public_key = {path = "../public_key"}
16
+ pshenmic_dpp_core_script = {path = "../core_script"}
17
+ pshenmic_dpp_public_key = {path = "../identity_public_key" }
18
+ pshenmic_dpp_identifier = {path = "../identifier" }
16
19
  pshenmic_dpp_state_transition = {path = "../state_transition"}
17
- pshenmic_dpp_enums = {path = "../enums"}
20
+ pshenmic_dpp_enums = {path = "../enums"}
21
+ pshenmic_dpp_asset_lock_proof = {path = "../asset_lock_proof"}